Skip to content

Commit

Permalink
webgl: Remove objects from binding points on object deletion.
Browse files Browse the repository at this point in the history
We keep bindings that shadow what's mapped in the GL state currently,
and so we need to remove the objects from our binding points when they
get implicitly removed from the GL binding points during object deletion.
  • Loading branch information
anholt committed Aug 26, 2016
1 parent 6ec2c41 commit db9fe23
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
29 changes: 24 additions & 5 deletions components/script/dom/webglrenderingcontext.rs
Expand Up @@ -61,6 +61,24 @@ macro_rules! handle_potential_webgl_error {
};
}

// From the GLES 2.0.25 spec, page 85:
//
// "If a texture that is currently bound to one of the targets
// TEXTURE_2D, or TEXTURE_CUBE_MAP is deleted, it is as though
// BindTexture had been executed with the same target and texture
// zero."
//
// and similar text occurs for other object types.
macro_rules! handle_object_deletion {
($binding:expr, $object:ident) => {
if let Some(bound_object) = $binding.get() {
if bound_object.id() == $object.id() {
$binding.set(None);
}
}
};
}

/// Set of bitflags for texture unpacking (texImage2d, etc...)
bitflags! {
#[derive(HeapSizeOf, JSTraceable)]
Expand Down Expand Up @@ -1101,18 +1119,16 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.5
fn DeleteBuffer(&self, buffer: Option<&WebGLBuffer>) {
if let Some(buffer) = buffer {
handle_object_deletion!(self.bound_buffer_array, buffer);
handle_object_deletion!(self.bound_buffer_element_array, buffer);
buffer.delete()
}
}

// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.6
fn DeleteFramebuffer(&self, framebuffer: Option<&WebGLFramebuffer>) {
if let Some(framebuffer) = framebuffer {
if let Some(bound_fb) = self.bound_framebuffer.get() {
if bound_fb.id() == framebuffer.id() {
self.bound_framebuffer.set(None);
}
}
handle_object_deletion!(self.bound_framebuffer, framebuffer);
framebuffer.delete()
}
}
Expand All @@ -1127,13 +1143,16 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8
fn DeleteTexture(&self, texture: Option<&WebGLTexture>) {
if let Some(texture) = texture {
handle_object_deletion!(self.bound_texture_2d, texture);
handle_object_deletion!(self.bound_texture_cube_map, texture);
texture.delete()
}
}

// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
fn DeleteProgram(&self, program: Option<&WebGLProgram>) {
if let Some(program) = program {
handle_object_deletion!(self.current_program, program);
program.delete()
}
}
Expand Down
Expand Up @@ -68,9 +68,6 @@
[WebGL test #48: getError expected: NO_ERROR. Was INVALID_ENUM : after evaluating: gl.bindTexture(gl.TEXTURE_2D, t)]
expected: FAIL

[WebGL test #52: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)]
expected: FAIL

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

Expand Down

0 comments on commit db9fe23

Please sign in to comment.