Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SOLVED] Multiple textures vs bigger single texture  (Read 7564 times)

0 Members and 1 Guest are viewing this topic.

danikaze

  • Newbie
  • *
  • Posts: 38
    • View Profile
    • Email
[SOLVED] Multiple textures vs bigger single texture
« 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!
« Last Edit: December 04, 2012, 06:50:30 pm by danikaze »

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Multiple textures vs bigger single texture
« Reply #1 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.
Back to C++ gamedev with SFML in May 2023

danikaze

  • Newbie
  • *
  • Posts: 38
    • View Profile
    • Email
Re: Multiple textures vs bigger single texture
« Reply #2 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?

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Multiple textures vs bigger single texture
« Reply #3 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.
Back to C++ gamedev with SFML in May 2023

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Re: Multiple textures vs bigger single texture
« Reply #4 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.
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!

Predator106

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: Multiple textures vs bigger single texture
« Reply #5 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.

danikaze

  • Newbie
  • *
  • Posts: 38
    • View Profile
    • Email
Re: Multiple textures vs bigger single texture
« Reply #6 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?):

  • 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?

thePyro_13

  • Full Member
  • ***
  • Posts: 156
    • View Profile
Re: Multiple textures vs bigger single texture
« Reply #7 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.

danikaze

  • Newbie
  • *
  • Posts: 38
    • View Profile
    • Email
Re: Multiple textures vs bigger single texture
« Reply #8 on: December 04, 2012, 04:00:21 am »
thanks!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Multiple textures vs bigger single texture
« Reply #9 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 ;)
Laurent Gomila - SFML developer

danikaze

  • Newbie
  • *
  • Posts: 38
    • View Profile
    • Email
Re: Multiple textures vs bigger single texture
« Reply #10 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Multiple textures vs bigger single texture
« Reply #11 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.
Laurent Gomila - SFML developer

danikaze

  • Newbie
  • *
  • Posts: 38
    • View Profile
    • Email
Re: Multiple textures vs bigger single texture
« Reply #12 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!