Just a quick question:
I have a lot of clones of a gui node, all have an image texture loaded when on-screen and the texture deleted when off-screen in order to decrease memory/cpu usage.
Would loading all textures once and then simply disabling the off-screen nodes instead of deleting the texture reduce memory usage/cpu usage in a similar way?
How many images? And what size? You could potentially run out of memory is you have all of them loaded but disabled.
Hi there @britzl, thank you for your reply.
Lorryloads - about 200 of them.
They are fairly large because there will be a close-up view of the paintings later in the app. The paintings vary in their format, some are portrait, some landscape. I was thinking about 1024 px width or height. I have compressed the images as far as possible, they weigh between 40 and 100 kb.
For the slider: the box is about 230x230 px.
I think your reply has answered my question: simply disabling a node is not enough.
So this is what I do at the moment in the slider script (in a loop):
-- node comes on-screen:
loadimage = sys.load_resource("/images/paintings/"..i..".png")
img = image.load(loadimage)
gui.new_texture("painting"..i, img.width, img.height, img.type, img.buffer, false)
gui.set_texture(imagebox_clones[i], "painting"..i)
gui.set_enabled(imagebox_clones[i], true)
-- node leaves the screen:
local texture = gui.get_texture(imagebox_clones[i])
if texture == hash("painting"..i) then
gui.delete_texture(texture)
gui.set_texture(imagebox_clones[i], "transparent")
gui.set_enabled(imagebox_clones[i], false)
end
Does this sound ok to you?
Well, you need to tell us some more, like the rough sizes of the images.
E.g. 200 1x1 px images doesn’t occupy that much memory.
Also, are you talking about atlases, or the images inside the atlases?
Hello @Mathias_Westerdahl,
the images are not housed in atlases, I use sys.load_resource. I aim to use fairly high-res images of 1024 px either width or height (the paintings aren’t square), they are heavily compressed to about 40 -100 kb each. The gui scene in question is a slider, I clone a box of 230x230 px and load the texture when the clone comes on-screen and delete it when it leaves the screen. My code at the moment: see above.
Here is an image of the slider prototype at various window sizes I shared with @britzl the other day:
When loaded into graphics memory, you won’t have them compressed.
We upload the full RGBA when you create a new texture.
Doing a quick estimate:
200 * (1024 * 1024 * 4) == 800mb
It’s up to you to decide if that’s ok, depending on the target devices you want to support
Aha, that’s good to know.
So, when I use gui.delete_texture, the images are still in memory? Then it would probably be better to choose another approach and dynamically create nodes only when they are about to enter the window and destroy again them when they leave it? So much maths!
I don’t think so?
I recommend using the profiler, and also task manager (though I think you use a Mac so it might be called something else) to verify what difference one approach makes over another!
I had similar concerns to you. For me it was about keeping dozens of wav music tracks loaded in memory. I simply checked the RAM usage in the task manager to see the difference.
Hi @Alex_8BitSkull - you are right. I did look at it. My initial thought, that’s why I asked, was to just disable off-screen nodes and get away with it. This doesn’t seem to be the case. I also wasn’t aware that compressing images doesn’t make a difference. So once more I learned stuff in the forum I didn’t know before. It’s a great place to be.