SFML community forums
Help => Graphics => Topic started by: FloweyTF on June 22, 2020, 06:05:11 am
-
So, I’m writing a game, and there are a lot of different textures. Should I use a sf::Texture to store it or a sf::Image? There might be a issue with running out of graphics memory, but ram can be swapped (to my understanding you can’t swap gpu memory)
-
An sf::Texture is stored in graphics memory and an sf::Image is stored on the heap (in RAM).
To be able to apply an image to a shape to render it to a target, it must first be in graphics memory.
To clarify a little bit, an sf::Image is pixel data in memory that you can manipulate directly but to be able to render it, it must first be copied to an sf::Texture. All bitmap data for use by the graphics card are textures and need to be stored in their own memory.
If there is a possibility that the graphics card may run out of memory for storing textures, you should also provide lower resolution versions to use instead for lower memory cards.
One thing to note is that "a lot of different textures" could also mean "a lot of different bitmaps/images" so I should mention that you can store multiple images in a single texture and use a texture rectangle/the texture co-ordinates to select which part to use.
-
Yes, I understand the difference, but due to concerns about taking up too much gpu memory, should I :
1) store texture in ram (sf::Image), then load to texture for drawing
2) store texture in gpu ram (sf::Texture), then draw directly
-
there is no sense in doing the first, since you'll need to load it in a texture anyway.
sf::Image is ONLY for when you want to modify that image (like drawing), for everything else use a Texture.
-
Leave in sf::Texture. Transferring data between RAM and graphics memory is "expensive".
-
I’m just worried about running out of gpu ram (because as far as I know, it’s not virtual memory)
-
We could talk about this for hours, but we still know nothing about your problem. We could be much more efficient in helping you, if you told us a little bit more about what you're trying to achieve.
How much RAM are we talking about? Do you need all these GB of textures all at once? Is each texture small or big? etc.
-
I load all textures at once (size is 16*16), and I have about 1000 of the textures
-
It's just 1 MB of data... Nothing to worry about. You could even combine them all into a single texture, tu speed up drawing.
-
Yeah, your right, it shouldn’t be that much of an issue