mirror of
https://github.com/3b1b/manim.git
synced 2025-09-01 00:48:45 +00:00
Allow releasing of Textures
This commit is contained in:
parent
329d2c6eae
commit
e10a752c00
1 changed files with 13 additions and 6 deletions
|
@ -440,12 +440,13 @@ class Camera(object):
|
|||
}
|
||||
|
||||
def init_textures(self):
|
||||
self.path_to_texture_id = {}
|
||||
self.n_textures = 0
|
||||
self.path_to_texture = {}
|
||||
|
||||
def get_texture_id(self, path):
|
||||
if path not in self.path_to_texture_id:
|
||||
# A way to increase tid's sequentially
|
||||
tid = len(self.path_to_texture_id)
|
||||
if path not in self.path_to_texture:
|
||||
tid = self.n_textures
|
||||
self.n_textures += 1
|
||||
im = Image.open(path).convert("RGBA")
|
||||
texture = self.ctx.texture(
|
||||
size=im.size,
|
||||
|
@ -453,8 +454,14 @@ class Camera(object):
|
|||
data=im.tobytes(),
|
||||
)
|
||||
texture.use(location=tid)
|
||||
self.path_to_texture_id[path] = tid
|
||||
return self.path_to_texture_id[path]
|
||||
self.path_to_texture[path] = (tid, texture)
|
||||
return self.path_to_texture[path][0]
|
||||
|
||||
def release_texture(self, path):
|
||||
tid_and_texture = self.path_to_texture.pop(path, None)
|
||||
if tid_and_texture:
|
||||
tid_and_texture[1].release()
|
||||
return self
|
||||
|
||||
|
||||
# Mostly just defined so old scenes don't break
|
||||
|
|
Loading…
Add table
Reference in a new issue