12
\$\begingroup\$

I recently added a texture packager to my project that will pack a certain amount of textures into a single one, like this:

Packed texture

So for example this one is 582x1023 pixels in size. The goal of adding these packed textures was obviously to improve performance so I wanted to look up the optimal texture size for OpenGL (using LWJGL) textures. The things I found were that a widely supported maximum texture size seems to be 1024x1024, according to this for example. This strikes me as odd because obviously a lot of textures alone would be larger than that, so what happens with those? I am pretty sure most graphics cards support textures bigger than that. Can I reasonably expect most graphics cards to handle e.g. 4096x4096 textures (or maybe even larger than that)?

To come to my second point (I hope this still counts as one question, but it essentially boils down to the same issue): Should textures be sized to a power of 2 (256x256, 512x512, 1024x1024, 2048x2048, ..) and should I pad packed textures smaller than that to the next power of 2? According to this question from 2011 it is not a requirement but can improve performance and avoid minor bugs and this one from 2012 says that you definitely should pad textures. So I realize that these questions have been asked before but they are reasonably dated for the answers to have changed and further they each only partially answer my question. How do other projects / handle this?

TL;DR: What textures sizes can I expect most graphics cards to handle? What are the optimal texture sizes (or are there)? Should I pad textures width to the next power of 2?

\$\endgroup\$
  • 4
    \$\begingroup\$ The GPU only deals in powers of 2. If you do not manually pad your textures, then the GPU (or your game engine of choice) does this for you, resulting in a slight delay at runtime per texture, which can add up. I can't offer any help on maximum/optimal texture sizes, though. \$\endgroup\$ – ketura Oct 4 '15 at 5:36
  • \$\begingroup\$ @ketura Ah I see, thanks. So say I got an image that is 513x10. Would it be faster to pad it to 1024x1024 and then transfer all these empty pixels or let the GPU do that? \$\endgroup\$ – flotothemoon Oct 4 '15 at 8:59
  • 4
    \$\begingroup\$ You wouldn't need to go that high. 1024 x 16 would work; it doesn't need to be SQUARE, just a power of 2 in each direction. Though in that case I would seriously consider if I couldn't spare a pixel and get it down to 512x16, lol. \$\endgroup\$ – ketura Oct 5 '15 at 2:04
6
\$\begingroup\$

I'm going to take a stab at answering this, though YMMV. I use the Steam Hardware Survey ( http://store.steampowered.com/hwsurvey?platform=pc ) to determine what is the video RAM (VRAM) available on most computers. Looking at the results as of 2015-10-13 (today), nearly 85% of people have 1024 MB VRAM.

Your question is very broad, since it doesn't state target hardware (console, PC, handheld, mobile devices?) I'm going to talk about PCs and you can extrapolate for other platforms based on hardware specs.

Assuming 32 bits of color+alpha per pixel i.e. 4 bypes per pixel, 1 GB VRAM can maximally hold ~256 million pixels. This equates to 256 1K by 1K textures. This assumes (incorrectly) that you only want to hold textures in your VRAM, while there will be a whole host of other things (e.g. mesh data, if you're working in 3D) that you need to leave space for. You also probably want to allow for some more space for mip-mapping of textures, which usually works best if your textures are powers of two.

Modern consoles (XBOX One and PS4) have 4-8 GB of unified RAM, most handhelds and mobile devices have 1 - 2 GB of unified RAM, with restrictions on how much you can allocate as VRAM.

I would typically create 2K textures so that it worked on most PCs, allowing for the option to scale down for lower end devices. If you're writing a 2D game and want to target higher resolution displays (4K, retina iPad, etc) you can use 4K textures for the background, but for most other parts, it may be overkill.

Hope this helped and didn't muddy the waters.

\$\endgroup\$
  • \$\begingroup\$ Thanks for the answer, definitely helps. As for the broadness, sorry about that, forgot to include some details: I am developing for PCs in 2D. What would happen if you use textures larger than the maximum supported texture size? Does it not work at all or just becomes slower? \$\endgroup\$ – flotothemoon Oct 16 '15 at 17:35
  • 1
    \$\begingroup\$ Looks like my answer was spot on. Checking other site forum posts 2k textures are what you should support for your game to work on most devices. Texture size limit depends on the specific hardware and the particular OpenGL-ES version. I'm not sure what the specific error message would be, but it would come from OpenGL-ES when you try to load the texture. Helpful links: answers.unity3d.com/questions/563094/… , forum.unity3d.com/threads/texture-sizes-and-videocards.281422 and feedback.wildfiregames.com/report/opengl/feature/… \$\endgroup\$ – Vijay Varadan Oct 16 '15 at 20:18
  • \$\begingroup\$ When I try to load or try to bind the texture? Or is that the same thing here? \$\endgroup\$ – flotothemoon Oct 17 '15 at 6:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.