Welcome,
Guest
. Please
login
or
register
. Did you miss your
activation email?
French forum
Home
Help
Search
Login
Register
SFML community forums
»
Help
»
Graphics
»
Should I use sf::Texture or sf::Image
Print
Pages: [
1
]
Author
Topic: Should I use sf::Texture or sf::Image (Read 4085 times)
0 Members and 1 Guest are viewing this topic.
FloweyTF
Newbie
Posts: 8
Should I use sf::Texture or sf::Image
«
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)
Logged
Hapax
Hero Member
Posts: 3379
My number of posts is shown in hexadecimal.
Re: Should I use sf::Texture or sf::Image
«
Reply #1 on:
June 22, 2020, 10:11:31 pm »
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.
Logged
Selba Ward
-SFML drawables
Cheese Map
-Drawable Layered Tile Map
Kairos
-Timing Library
Grambol
*
Hapaxia Links
*
FloweyTF
Newbie
Posts: 8
Re: Should I use sf::Texture or sf::Image
«
Reply #2 on:
June 23, 2020, 05:28:11 am »
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
Logged
Stauricus
Sr. Member
Posts: 369
Re: Should I use sf::Texture or sf::Image
«
Reply #3 on:
June 23, 2020, 01:33:37 pm »
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.
Logged
Visit my game site (and hopefully help funding it?
)
Website
|
IndieDB
Hapax
Hero Member
Posts: 3379
My number of posts is shown in hexadecimal.
Re: Should I use sf::Texture or sf::Image
«
Reply #4 on:
June 23, 2020, 09:01:24 pm »
Leave in sf::Texture. Transferring data between RAM and graphics memory is "expensive".
Logged
Selba Ward
-SFML drawables
Cheese Map
-Drawable Layered Tile Map
Kairos
-Timing Library
Grambol
*
Hapaxia Links
*
FloweyTF
Newbie
Posts: 8
Re: Should I use sf::Texture or sf::Image
«
Reply #5 on:
June 23, 2020, 09:43:02 pm »
I’m just worried about running out of gpu ram (because as far as I know, it’s not virtual memory)
Logged
Laurent
Administrator
Hero Member
Posts: 32498
Re: Should I use sf::Texture or sf::Image
«
Reply #6 on:
June 23, 2020, 10:09:04 pm »
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.
Logged
Laurent Gomila - SFML developer
FloweyTF
Newbie
Posts: 8
Re: Should I use sf::Texture or sf::Image
«
Reply #7 on:
June 24, 2020, 05:46:14 am »
I load all textures at once (size is 16*16), and I have about 1000 of the textures
Logged
Laurent
Administrator
Hero Member
Posts: 32498
Re: Should I use sf::Texture or sf::Image
«
Reply #8 on:
June 24, 2020, 08:26:29 am »
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.
Logged
Laurent Gomila - SFML developer
FloweyTF
Newbie
Posts: 8
Re: Should I use sf::Texture or sf::Image
«
Reply #9 on:
June 24, 2020, 04:10:50 pm »
Yeah, your right, it shouldn’t be that much of an issue
Logged
Print
Pages: [
1
]
SFML community forums
»
Help
»
Graphics
»
Should I use sf::Texture or sf::Image