Skip to content

Commit e10a752

Browse files
committed
Allow releasing of Textures
1 parent 329d2c6 commit e10a752

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

manimlib/camera/camera.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -440,21 +440,28 @@ def refresh_perspective_uniforms(self):
440440
}
441441

442442
def init_textures(self):
443-
self.path_to_texture_id = {}
443+
self.n_textures = 0
444+
self.path_to_texture = {}
444445

445446
def get_texture_id(self, path):
446-
if path not in self.path_to_texture_id:
447-
# A way to increase tid's sequentially
448-
tid = len(self.path_to_texture_id)
447+
if path not in self.path_to_texture:
448+
tid = self.n_textures
449+
self.n_textures += 1
449450
im = Image.open(path).convert("RGBA")
450451
texture = self.ctx.texture(
451452
size=im.size,
452453
components=len(im.getbands()),
453454
data=im.tobytes(),
454455
)
455456
texture.use(location=tid)
456-
self.path_to_texture_id[path] = tid
457-
return self.path_to_texture_id[path]
457+
self.path_to_texture[path] = (tid, texture)
458+
return self.path_to_texture[path][0]
459+
460+
def release_texture(self, path):
461+
tid_and_texture = self.path_to_texture.pop(path, None)
462+
if tid_and_texture:
463+
tid_and_texture[1].release()
464+
return self
458465

459466

460467
# Mostly just defined so old scenes don't break

0 commit comments

Comments
 (0)