Skip to content

Commit

Permalink
webgl: Add getters for other GL_*_BINDING enums.
Browse files Browse the repository at this point in the history
Fixes many subcases of object-deletion-behaviour.html.
  • Loading branch information
anholt committed Aug 26, 2016
1 parent db9fe23 commit e8b5f70
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 64 deletions.
42 changes: 31 additions & 11 deletions components/script/dom/webglrenderingcontext.rs
Expand Up @@ -79,6 +79,20 @@ macro_rules! handle_object_deletion {
};
}

macro_rules! object_binding_to_js_or_null {
($cx: expr, $binding:expr) => {
{
rooted!(in($cx) let mut rval = NullValue());
if let Some(bound_object) = $binding.get() {
unsafe {
bound_object.to_jsval($cx, rval.handle_mut());
}
}
rval.get()
}
};
}

/// Set of bitflags for texture unpacking (texImage2d, etc...)
bitflags! {
#[derive(HeapSizeOf, JSTraceable)]
Expand All @@ -101,6 +115,7 @@ pub struct WebGLRenderingContext {
last_error: Cell<Option<WebGLError>>,
texture_unpacking_settings: Cell<TextureUnpacking>,
bound_framebuffer: MutNullableHeap<JS<WebGLFramebuffer>>,
bound_renderbuffer: MutNullableHeap<JS<WebGLRenderbuffer>>,
bound_texture_2d: MutNullableHeap<JS<WebGLTexture>>,
bound_texture_cube_map: MutNullableHeap<JS<WebGLTexture>>,
bound_buffer_array: MutNullableHeap<JS<WebGLBuffer>>,
Expand Down Expand Up @@ -135,6 +150,7 @@ impl WebGLRenderingContext {
bound_texture_cube_map: MutNullableHeap::new(None),
bound_buffer_array: MutNullableHeap::new(None),
bound_buffer_element_array: MutNullableHeap::new(None),
bound_renderbuffer: MutNullableHeap::new(None),
current_program: MutNullableHeap::new(None),
current_vertex_attrib_0: Cell::new((0f32, 0f32, 0f32, 1f32)),
}
Expand Down Expand Up @@ -531,19 +547,22 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
#[allow(unsafe_code)]
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3
fn GetParameter(&self, cx: *mut JSContext, parameter: u32) -> JSVal {
// Handle the GL_FRAMEBUFFER_BINDING without going all the way
// Handle the GL_*_BINDING without going all the way
// to the GL, since we would just need to map back from GL's
// returned ID to the WebGLFramebuffer we're tracking.
// returned ID to the WebGL* object we're tracking.
match parameter {
constants::FRAMEBUFFER_BINDING => {
rooted!(in(cx) let mut rval = NullValue());
if let Some(bound_fb) = self.bound_framebuffer.get() {
unsafe {
bound_fb.to_jsval(cx, rval.handle_mut());
}
}
return rval.get()
}
constants::ARRAY_BUFFER_BINDING =>
return object_binding_to_js_or_null!(cx, &self.bound_buffer_array),
constants::ELEMENT_ARRAY_BUFFER_BINDING =>
return object_binding_to_js_or_null!(cx, &self.bound_buffer_element_array),
constants::FRAMEBUFFER_BINDING =>
return object_binding_to_js_or_null!(cx, &self.bound_framebuffer),
constants::RENDERBUFFER_BINDING =>
return object_binding_to_js_or_null!(cx, &self.bound_renderbuffer),
constants::TEXTURE_BINDING_2D =>
return object_binding_to_js_or_null!(cx, &self.bound_texture_2d),
constants::TEXTURE_BINDING_CUBE_MAP =>
return object_binding_to_js_or_null!(cx, &self.bound_texture_cube_map),
_ => {}
}

Expand Down Expand Up @@ -1136,6 +1155,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.7
fn DeleteRenderbuffer(&self, renderbuffer: Option<&WebGLRenderbuffer>) {
if let Some(renderbuffer) = renderbuffer {
handle_object_deletion!(self.bound_renderbuffer, renderbuffer);
renderbuffer.delete()
}
}
Expand Down
Expand Up @@ -23,9 +23,6 @@
[WebGL test #21: gl.isShader(fragmentShader) should be false. Threw exception TypeError: gl.isShader is not a function]
expected: FAIL

[WebGL test #28: gl.getParameter(gl.TEXTURE_BINDING_2D) should be [object WebGLTexture\]. Was null.]
expected: FAIL

[WebGL test #29: gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0) threw exception TypeError: gl.framebufferTexture2D is not a function]
expected: FAIL

Expand All @@ -35,9 +32,6 @@
[WebGL test #31: gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE) should be 5890. Threw exception TypeError: gl.getFramebufferAttachmentParameter is not a function]
expected: FAIL

[WebGL test #32: getError expected: NO_ERROR. Was INVALID_ENUM : after evaluating: gl.deleteTexture(tex)]
expected: FAIL

[WebGL test #33: gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE) should be 0. Threw exception TypeError: gl.getFramebufferAttachmentParameter is not a function]
expected: FAIL

Expand All @@ -47,43 +41,13 @@
[WebGL test #35: gl.isTexture(tex) should be false. Threw exception TypeError: gl.isTexture is not a function]
expected: FAIL

[WebGL test #37: getError expected: NO_ERROR. Was INVALID_ENUM : after evaluating: gl.bindTexture(gl.TEXTURE_2D, tex)]
expected: FAIL

[WebGL test #40: getError expected: NO_ERROR. Was INVALID_ENUM : after evaluating: gl.bindTexture(gl.TEXTURE_CUBE_MAP, texCubeMap)]
expected: FAIL

[WebGL test #41: gl.getParameter(gl.TEXTURE_BINDING_CUBE_MAP) should be [object WebGLTexture\]. Was null.]
expected: FAIL

[WebGL test #42: getError expected: NO_ERROR. Was INVALID_ENUM : after evaluating: gl.deleteTexture(texCubeMap)]
[WebGL test #37: getError expected: NO_ERROR. Was INVALID_OPERATION : after evaluating: gl.bindTexture(gl.TEXTURE_2D, tex)]
expected: FAIL

[WebGL test #43: gl.isTexture(texCubeMap) should be false. Threw exception TypeError: gl.isTexture is not a function]
expected: FAIL

[WebGL test #45: getError expected: NO_ERROR. Was INVALID_ENUM : after evaluating: gl.bindTexture(gl.TEXTURE_CUBE_MAP, texCubeMap)]
expected: FAIL

[WebGL test #48: getError expected: NO_ERROR. Was INVALID_ENUM : after evaluating: gl.bindTexture(gl.TEXTURE_2D, t)]
expected: FAIL

[WebGL test #56: gl.getParameter(gl.TEXTURE_BINDING_2D) should be [object WebGLTexture\]. Was null.]
expected: FAIL

[WebGL test #57: getError expected: NO_ERROR. Was INVALID_ENUM : after evaluating: gl.activeTexture(gl.TEXTURE1)]
expected: FAIL

[WebGL test #59: gl.getParameter(gl.TEXTURE_BINDING_2D) should be [object WebGLTexture\]. Was null.]
expected: FAIL

[WebGL test #60: getError expected: NO_ERROR. Was INVALID_ENUM : after evaluating: gl.deleteTexture(t2)]
expected: FAIL

[WebGL test #62: getError expected: NO_ERROR. Was INVALID_ENUM : after evaluating: gl.activeTexture(gl.TEXTURE0)]
expected: FAIL

[WebGL test #67: getError expected: NO_ERROR. Was INVALID_ENUM : after evaluating: gl.bindRenderbuffer(gl.RENDERBUFFER, rbo)]
[WebGL test #45: getError expected: NO_ERROR. Was INVALID_OPERATION : after evaluating: gl.bindTexture(gl.TEXTURE_CUBE_MAP, texCubeMap)]
expected: FAIL

[WebGL test #68: gl.getParameter(gl.RENDERBUFFER_BINDING) should be [object WebGLRenderbuffer\]. Was null.]
Expand All @@ -95,9 +59,6 @@
[WebGL test #70: gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME) should be [object WebGLRenderbuffer\]. Threw exception TypeError: gl.getFramebufferAttachmentParameter is not a function]
expected: FAIL

[WebGL test #71: getError expected: NO_ERROR. Was INVALID_ENUM : after evaluating: gl.deleteRenderbuffer(rbo)]
expected: FAIL

[WebGL test #72: gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE) should be 0. Threw exception TypeError: gl.getFramebufferAttachmentParameter is not a function]
expected: FAIL

Expand All @@ -107,24 +68,12 @@
[WebGL test #74: gl.isRenderbuffer(rbo) should be false. Threw exception TypeError: gl.isRenderbuffer is not a function]
expected: FAIL

[WebGL test #76: getError expected: NO_ERROR. Was INVALID_ENUM : after evaluating: gl.bindRenderbuffer(gl.RENDERBUFFER, rbo)]
expected: FAIL

[WebGL test #78: getError expected: NO_ERROR. Was INVALID_ENUM : after evaluating: gl.bindRenderbuffer(gl.RENDERBUFFER, rbo2)]
expected: FAIL

[WebGL test #79: gl.getParameter(gl.RENDERBUFFER_BINDING) should be [object WebGLRenderbuffer\]. Was null.]
expected: FAIL

[WebGL test #80: getError expected: NO_ERROR. Was INVALID_ENUM : after evaluating: gl.deleteRenderbuffer(rbo3)]
expected: FAIL

[WebGL test #81: gl.getParameter(gl.RENDERBUFFER_BINDING) should be [object WebGLRenderbuffer\]. Was null.]
expected: FAIL

[WebGL test #82: getError expected: NO_ERROR. Was INVALID_ENUM : after evaluating: gl.bindRenderbuffer(gl.RENDERBUFFER, rbo)]
expected: FAIL

[WebGL test #83: gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, 16, 16) threw exception TypeError: gl.renderbufferStorage is not a function]
expected: FAIL

Expand Down

0 comments on commit e8b5f70

Please sign in to comment.