Search code examples
texturessdl

How can I get around the texture and video memory limitations in SDL2?


I tested the max texture size and the max number of textures I can have in SDL2 and it's limited to 23 textures of 16384 x 16384 pixels. After that it runs out of video memory, as per the SDL_GetError() message I get.

Surely AAA games are displaying more than 23 textures of 16384 x 16384 pixels in the game world, every frame. So how do they do that without running out of video memory? They can't be constantly loading from disk. It has to be saved to video ram already when the game loads. So why is SDL2 limiting me to 23 textures of 16384 x 16384 pixels? Is there a way around that?

I am programming a 2d game and would like to load the entire game world from the start, so that the player does not have a load screen once they start playing.

Currently, the work around I'm thinking of programming is to have only the large game background textures recomposed every time the player enters a new area but the rest of the game elements will all be loaded at the start of the game. That way there will only be a fraction of a second of black screen during which the large textures are recomposed for the new area. But still I would like to not have to load or blackout anything at all during gameplay, given the type of game I am making. I am trying to make a fully immersive sim game.


Solution

  • I have just implemented and tested rendering tiles each frame. That's 5100 tiles to render in the camera view per layer, for 2 layers, each frame. So 10200 tiles (textures) to render on screen each frame. It brought the frame rate down to 20 compared to 60 and above using my method of pre-rendered large textures. So this proves my point, that CPUs are not fast enough to iterate through that many elements, even though each tile is a texture already loaded in vram. It is much faster to render an area of 1 large texture to the screen, compared to rendering 5100 smaller textures, each frame, even when these textures are all located in the same file that is loaded into one texture before the main game loop. Which is the point I was trying to make in my discussion with HolyBlackCat.

    So this circles back to my original question on this post: How can I get around the texture and video memory limitations in SDL2?

    The video memory limitation does not seem to be related to SDL2 but to the hardware (the graphics card), which makes sense. So I will stick with my solution of splitting the game world into areas and every time the player enters a new area, the large textures for it will be pre-rendered.