gl.Texture no cache

gl.Texture no cache

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

gl.Texture no cache

Post by gajop »

Is there any way to disable gl.Texture caching?
My use case is:

Code: Select all

-- user loads texture
gl.Texture(path)
gl.RenderToTexture(fboTex, function() ... end)
gl.Texture(false)

-- user saves texture
os.remove(path) -- remove old texture
gl.RenderToTexture(fboTex, gl.SaveImage, 0, 0, texSize, texSize, path)

-- user loads texture again
gl.Texture(path)
gl.RenderToTexture(fboTex, function() ... end)
gl.Texture(false)
Problem happens when I load a texture again from the same path even though the texture has changed in the meanwhile. It will still give me the cached texture instead of the new texture. Is there any option to disable the caching and enforce that it loads it from the disk?
Thanks.
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: gl.Texture no cache

Post by gajop »

To offer one (ugly) solution myself is:
gl.Texture(":"..os.clock()..":" .. path)
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: gl.Texture no cache

Post by jK »

use gl.DeleteTexture
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: gl.Texture no cache

Post by gajop »

OK, so are supposed to gl.DeleteTexture those that we haven't gl.CreateTexture-d or is it just to enforce no caching?
Also, what does gl.DeleteTextureFBO do? delete the FBO of a texture fbo=true texture or delete the texture+fbo of a fbo=true texture?
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: gl.Texture no cache

Post by jK »

with gl.DeleteTexture you can delete named textures (that's the name of them), too.
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: gl.Texture no cache

Post by gajop »

Right, I got that now.
1. The next question is whether this (deleting named textures) is something we should do to prevent memory leaks?
From what I understand Lua textures (gl.CreateTexture) are one of the rare few things that we need to explicitly delete in Lua.
And:
2.
Also, what does gl.DeleteTextureFBO do? delete the FBO of a texture fbo=true texture or delete the texture+fbo of a fbo=true texture?
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: gl.Texture no cache

Post by jK »

@1: when you load a huge loadscreen texture in LuaIntro and later never need it again, then yes you should delete it in :Shutdown()

@2: you got the source
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: gl.Texture no cache

Post by gajop »

jK wrote:@1: when you load a huge loadscreen texture in LuaIntro and later never need it again, then yes you should delete it in :Shutdown()
I understand that I should sometimes delete it, but the question was really whether named textures will be deleted automatically after some time or not. That is, will gl.Texture(path) remain in memory forever until gl.DeleteTexture(path) or would they be removed by Spring?
jK wrote: @2: you got the source
:P

PS: Another question: Is there a way to monitor widget/gadget memory usage, including the use of textures which doesn't fall in the 800~ish MBs allocated to Lua?
Post Reply

Return to “Lua Scripts”