SFML community forums
Help => Graphics => Topic started by: danikaze on December 01, 2012, 10:57:33 pm
-
I was wondering (and couldn't find any info in the forum :S), which way is better (talking about performance):
- load 1 texture for each image
- load 1 bigger texture containing all images (and then use a portion of it when loading sprites)
Is there any difference?
The question came to me viewing some directX (?, not sure) code, where all images are loaded into just one texture and then used from them. Probably to manage graphic cards things...
Thanks in advance!
-
Depends but more often than not 1 bigger texture will win because sfml will bind texture with open gl everytime before drawing and it's somewhat heavy operation but doesn't get called if few draw calls use same texture.
-
I see... so better manage sprites in only 1 texture with extra info in the SpriteManager...
Is there any size limit for textures? like 8k x 8k or something like that?
-
GPU dependant. Texture has a static function to check that. I'd imagine 1024x1024 is small enough to fit even on semi-ancient cards.
-
Is there any size limit for textures? like 8k x 8k or something like that?
My intel crappy GPU has 4096 as a limit size, so it's usually not a problem unless you want to deal with something extremely big.
-
I see... so better manage sprites in only 1 texture with extra info in the SpriteManager...
Is there any size limit for textures? like 8k x 8k or something like that?
yup, i think most are capped at 8k. but of course it's hw dependent. that's also a problem with multiple screens, because you can't treat it as 1 whole screen that way without it breaking horribly.
-
well, at least now I know it's better to load an image of 1024x1024 with lots of sprite frames than lots of images of... don't know... 40x80px :P and manage them apart.
Other question is (Maybe in a new thread would be better?):
- Use one sprite for a graphic entity (like a player) and use .setTexture to change the frame of each animation (so, that's one sf::Sprite::setTexture call for each entity every 2-3 millisecond)
- Use one sprite for each frame and draw only the visible one?
-
The consensus seems to be one sprite per entity with Sprite::setTextureRect to speicify different animation frames(all the frames for a single entity must be in a single texture though).
See thor's Animator class for an easy way to automate this.
-
thanks!
-
The consensus seems to be one sprite per entity
No need for a consensus, things are clear: less textures = best performances. So if you can put all your graphics into a single texture, do it ;)
-
The consensus seems to be one sprite per entity
No need for a consensus, things are clear: less textures = best performances. So if you can put all your graphics into a single texture, do it ;)
Actually, we were talking now about having just 1 sf::Sprite for a character, and then change its frame animations with sf::Sprite::setTexture, or having one sf::Sprite for each frame, and draw only the visible one.
The textures would be the same, because all them must be loaded into memory.
-
Oops, sorry.
One sprite per frame, or one textureRect per frame and one sprite, I don't think the difference would be significant. But the second solution (storing frames as rectangles, not as sprites) is more logical and probably easier to handle: all other properties of the sprite (position, rotation, scale, color, ...) don't depend on the animation frames. I don't see any good reason to use one sprite per animation frame.
-
all other properties of the sprite (position, rotation, scale, color, ...) don't depend on the animation frames. I don't see any good reason to use one sprite per animation frame.
Yeah, that's what I thought, but I was thinking on performance, and maybe setTexture could be a bit slower than the other solution.
Actually, having more Sprite objects should means in more memory usage...
Thanks!