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

Author Topic: I'm having trouble staying within the bounds of the texture size limitation.  (Read 1924 times)

0 Members and 2 Guests are viewing this topic.

Me-Myself-And-I

  • Jr. Member
  • **
  • Posts: 93
    • View Profile
Hello all.

I know I have asked about this before but I still haven't found a solution. My biggest problem is trying to load dimentionally large animations into a game without causing performance lagging or having an overabundance of texture objects. If I put any large dimention animations into a spritesheet its too large to load to texture. Recently I heard something about it being possible to load large textures using vertices. Is this correct? If so, How? My game isn't so dimentionally large.Its only 960x540 at most. There must be a way to display large frames without hitting performance issues. If I split up an animation thats large into dimentionally small frame rects and save each as files,and load each into the game,it still requires either loading a lot into memory or lloading from file as its needed. Loading from file as needed definitely causes lag I know.  Would it be possible to create several textures when they are needed for preloading and delete them after its done playing the animation?Or would this still cause lag?Also I know that each texture is loaded into memory anyways so why can't it treat one large image as memory the same way that it treats several loaded images as the same amount of memory?
« Last Edit: January 17, 2024, 05:22:44 am by Me-Myself-And-I »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
You can have multiple textures and switch between them as and when required. The one you use shouldn't cause any lag if it's still just one at a time (instead of multiple textures just for the player, for example) although if may not be as optimised as using the same texture as the objects drawn before and after it; it also reduces ability to batch stuff.

So, yes, you can just change which texture to use. You can use different textures for different things if needed.

If you have a limit of how many textures you can have at once (for whatever reason), you could store images and swap textures in and out. Note that this is slower and should only be done occasionally.

I heard something about it being possible to load large textures using vertices. Is this correct?
I'm not exactly sure what this means so to clarify:
  • Images are a pixel array stored in memory. This holds the data of the image (pixel colours). This is limited only be size of RAM.
  • Textures are similar to Images but are stored on the graphics card's memory. This can be accessed by drawing operations. The limit to the size of a Texture is determined by the graphics card.*
  • Sprites (or other Vertex arrays that show textures) show a part of a texture. For a Sprite, this is rectangular. Their appearance's size is limitless. For a Sprite, you change its size using its Scale.

So, a texture is a rectangular image that is stored on the graphics card that can be used while drawing.

One issue that sometimes occurs is that you may want to show an image larger than you can store in any one image. For this, you can use multiple textures and stitch them together; basically, it's just drawing multiple things together. The Thor library can do this automatically for you.

However, it doesn't sound like you're trying to draw a large texture, rather can't fit all frames of an animation on the same texture. This is absolutely not an issue; you can simply put some frames on one texture and some on another and just change which texture to use when you draw it. For example, with a Sprite, you'd just set its texture at the time when you set its texture rectangle.



*To determine the largest possible texture that you graphics card can use, you can use SFML:
const unsigned int maxTextureSize{ sf::Texture::getMaximumSize() };
Note that this is a one-dimensional length. The texture size is a square area with this length for both dimensions; its size is (maxTextureSize x maxTextureSize).

This can help you determine the size of the images you create externally but be aware that this can be different for different devices so may need to account for different sizes if you intend for others to use it.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Me-Myself-And-I

  • Jr. Member
  • **
  • Posts: 93
    • View Profile
Thankyou for your help.

Me-Myself-And-I

  • Jr. Member
  • **
  • Posts: 93
    • View Profile
I thought I should mention what solved my problem in case anyone wants to know. The solution was to load the entire picture into an sf::image then to load the necessary rect from that into the amount of textures needed.  That way the texture doesn't have to be loading a rect directly from file and instead make the texture reusable by allowing the rect to change as its loading from the memory of sf::image. I don't know if this is a dummy solution or not but hey, it works. :P