mirror of
https://github.com/servo/servo.git
synced 2025-08-02 20:20:14 +01:00
webgl: Remove objects from binding points on object deletion.
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.
This commit is contained in:
parent
6ec2c41df8
commit
db9fe23903
2 changed files with 24 additions and 8 deletions
|
@ -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)]
|
||||
|
@ -1101,6 +1119,8 @@ 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()
|
||||
}
|
||||
}
|
||||
|
@ -1108,11 +1128,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
|||
// 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()
|
||||
}
|
||||
}
|
||||
|
@ -1127,6 +1143,8 @@ 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()
|
||||
}
|
||||
}
|
||||
|
@ -1134,6 +1152,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
|||
// 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()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue