SFML community forums

Help => Graphics => Topic started by: danikaze on December 01, 2012, 10:57:33 pm

Title: [SOLVED] Multiple textures vs bigger single texture
Post 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!
Title: Re: Multiple textures vs bigger single texture
Post by: FRex on December 01, 2012, 11:23:16 pm
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.
Title: Re: Multiple textures vs bigger single texture
Post by: danikaze on December 02, 2012, 03:50:46 am
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?
Title: Re: Multiple textures vs bigger single texture
Post by: FRex on December 02, 2012, 03:56:06 am
GPU dependant. Texture has a static function to check that. I'd imagine 1024x1024 is small enough to fit even on semi-ancient cards.
Title: Re: Multiple textures vs bigger single texture
Post by: masskiller on December 02, 2012, 09:19:26 pm
Quote
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.
Title: Re: Multiple textures vs bigger single texture
Post by: Predator106 on December 03, 2012, 02:13:56 am
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.
Title: Re: Multiple textures vs bigger single texture
Post by: danikaze on December 04, 2012, 01:42:56 am
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?):

Title: Re: Multiple textures vs bigger single texture
Post by: thePyro_13 on December 04, 2012, 03:33:24 am
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.
Title: Re: Multiple textures vs bigger single texture
Post by: danikaze on December 04, 2012, 04:00:21 am
thanks!
Title: Re: Multiple textures vs bigger single texture
Post by: Laurent on December 04, 2012, 08:21:47 am
Quote
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 ;)
Title: Re: Multiple textures vs bigger single texture
Post by: danikaze on December 04, 2012, 04:06:25 pm
Quote
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.
Title: Re: Multiple textures vs bigger single texture
Post by: Laurent on December 04, 2012, 04:23:07 pm
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.
Title: Re: Multiple textures vs bigger single texture
Post by: danikaze on December 04, 2012, 05:13:10 pm
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!