Fix some textures not being destroyed when it should.
This commit is contained in:
parent
01229cc2b5
commit
1640040f93
|
@ -406,7 +406,7 @@ when compileOption("threads"):
|
|||
proc workerThreadProc() {.thread.} =
|
||||
# TODO: handle errors
|
||||
while true:
|
||||
let to_decode = decode_chan.recv()
|
||||
var to_decode = decode_chan.recv()
|
||||
if to_decode.tex == nil:
|
||||
break
|
||||
proc cb(tex: Texture, data: SliceMem[byte]) =
|
||||
|
@ -415,7 +415,7 @@ when compileOption("threads"):
|
|||
compressed_return_chan.send((callback: to_decode.callback_compressed, tex: tex, data: data, refdata: refdata))
|
||||
let cb_out = if to_decode.callback_uncompressed != nil: cb else: nil
|
||||
let cbc_out = if to_decode.callback_compressed != nil: cbc else: nil
|
||||
loadOptimized(to_decode.tex, to_decode.slices, cb_out, cbc_out,
|
||||
loadOptimized(move to_decode.tex, to_decode.slices, cb_out, cbc_out,
|
||||
to_decode.flip, to_decode.min_channels)
|
||||
|
||||
decode_chan.open()
|
||||
|
|
|
@ -260,7 +260,7 @@ proc bind_it*(texture: Texture, reserve_slot: static[int32] = -1, needs_active_t
|
|||
# if old_tex.sampler_object != 0:
|
||||
# glBindSampler(cast[GLuint](bound_unit), 0)
|
||||
bound_textures[bound_unit] = nil
|
||||
glBindTexture(texture.storage.target, texture.storage.tex.GLuint)
|
||||
glBindTexture(texture.storage.target, GLuint(texture.storage.tex))
|
||||
# if texture.sampler_object != 0:
|
||||
# glBindSampler(bound_unit.GLuint, texture.sampler_object)
|
||||
bound_textures[bound_unit] = texture
|
||||
|
@ -554,8 +554,8 @@ proc getTexturePixels*(self: Texture): TexturePixels =
|
|||
proc setMipmapRange*(self: Texture, first = 0, last = 1000) {.gcsafe.} =
|
||||
self.bind_it(needs_active_texture=true)
|
||||
self.mipmap_range = (first, last)
|
||||
glTexParameteri(self.storage.target.GLenum, GL_TEXTURE_BASE_LEVEL, first.GLint);
|
||||
glTexParameteri(self.storage.target.GLenum, GL_TEXTURE_MAX_LEVEL, last.GLint);
|
||||
glTexParameteri(self.storage.target, GL_TEXTURE_BASE_LEVEL, first.GLint);
|
||||
glTexParameteri(self.storage.target, GL_TEXTURE_MAX_LEVEL, last.GLint);
|
||||
|
||||
func vec3size*(self: Texture, mip_level = -1): Vec3 =
|
||||
let depth = if self.tex_type == Tex2DArray: 1 else: self.depth
|
||||
|
|
|
@ -342,6 +342,13 @@ proc set_objects_auto_update_matrix*(self: Scene, objects: seq[GameObject], auto
|
|||
self.children_are_ordered = false
|
||||
|
||||
proc destroy*(self: Scene) =
|
||||
# This may not be necessary. TODO: test
|
||||
for ob in self.children:
|
||||
if ob.is_mesh:
|
||||
for m in ob.get_mesh.materials:
|
||||
if m != nil:
|
||||
for tex in m.textures.mvalues:
|
||||
tex.destroy()
|
||||
for ob in reversed(self.children):
|
||||
ob.destroy(recursive=false)
|
||||
self.world.destroy()
|
||||
|
@ -357,6 +364,7 @@ proc destroy*(self: Scene) =
|
|||
cube.destroy()
|
||||
self.cubemaps = @[]
|
||||
self.engine.scenes.del(self.name)
|
||||
self.engine.new_scenes.del(self.name)
|
||||
# bound textures can linger
|
||||
unbindAllTextures()
|
||||
# probably none of this is actually necessary
|
||||
|
|
Loading…
Reference in a new issue