8000 graphics/gl: forget deleted textures in the binding cache by ricande · Pull Request #691 · not-fl3/miniquad · GitHub
[go: up one dir, main page]

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/graphics/gl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -911,12 +911,11 @@ impl RenderingBackend for GlContext {
}

fn delete_texture(&mut self, texture: TextureId) {
//self.cache.clear_texture_bindings();

let t = self.textures.get(texture);
match &t.raw {
TextureOrRenderbuffer::Texture(raw) => unsafe {
glDeleteTextures(1, raw as *const _);
self.cache.forget_texture(*raw);
},
TextureOrRenderbuffer::Renderbuffer(raw) => unsafe {
glDeleteRenderbuffers(1, raw as *const _);
Expand Down
19 changes: 19 additions & 0 deletions src/graphics/gl/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,25 @@ impl GlCache {
self.index_buffer = 0;
}

/// Forgets `texture` wherever the cache records it as bound. Deleting a
/// texture already rebinds those units to 0 in GL, so no GL call is
/// needed; but if the cache kept the name, a texture created later with
/// the same name would be taken as already bound and never be bound.
pub fn forget_texture(&mut self, texture: GLuint) {
for cached in &mut self.textures {
if cached.texture == texture {
*cached = CachedTexture {
target: 0,
texture: 0,
};
}
}
if self.stored_texture == texture {
self.stored_target = 0;
self.stored_texture = 0;
}
}

pub fn clear_texture_bindings(&mut self) {
for ix in 0..MAX_SHADERSTAGE_IMAGES {
if self.textures[ix].texture != 0 {
Expand Down
Loading
0