I have a very low res mobile game I'm working on that takes multiple rendering passes followed by a pass the composes them. Currently, I have a tex for each pass- each of which gets given to the shader for final composition.

I want to keep # of textures used low, and I'm only able to sample from so many textures per-shader anyways (esp. for mobile). So I'm thinking each render pass would instead render to a portion of a single, bigger texture. Then the composition pass would sample the same texture from multiple places. Are there any red flags that pop out regarding this strategy?

My biggest worry is it would totally thrash the texel cache (since every frame, every pixel samples the exact same texels for all the textures (each texture is a 1 to 1 mapping of the screen) = incredibly predictable/efficient caching. However, I really only have a very basic understanding of how that works so I could be totally wrong.

Also, note that my game is incredibly low resolution (128x256), so a single "giant" texture that could hold maybe 6 screens would still be pretty small at the end of the day.

Any insight is helpful! Thanks!

  • \$\begingroup\$ Have you actually tried to do it? I can assure you that the smaller your assets are and the bigger the tileset is, there will be rounding errors because texture coordinates are 0-1. On a 512x512 a 16x16 would be 0.00xxx. \$\endgroup\$ – Krythic Nov 20 '16 at 11:44
  • \$\begingroup\$ @Krythic texture coordinates are usually treated as single precision floats, with 23 bits of mantissa. That means your textures could be 8 million pixels across (thousands of times larger than the max supported on most mobile GPUs) and you'd still have enough precision to address any individual pixel. So, texture coordinate accuracy is unlikely to be the limiting factor here. \$\endgroup\$ – DMGregory Dec 20 '16 at 17:56
  • \$\begingroup\$ @DMGregory Ah, you again. I'm going to take pleasure in it this time. Do me a favor, write a float to a file and read it in, parsing it to a float, look at the loss of precision, and then come back and apologize to me, and delete your comment. \$\endgroup\$ – Krythic Dec 20 '16 at 18:09
  • 1
    \$\begingroup\$ @Krythic Done. Please see some sample code demonstrating this here. When correctly serializing a float to a game asset file there is no loss of precision necessary, as you can easily verify for yourself by running the code at the provided link, using either text or binary serialization as you so choose. If you're experiencing a loss of precision, then you may be inadvertently truncating or rounding your values when saving them. Please also try to keep the discussion here constructive - we're all learning together, so we don't need to take corrections personally. \$\endgroup\$ – DMGregory Dec 20 '16 at 19:06
  • \$\begingroup\$ @DMGregory I will look at your code shortly. \$\endgroup\$ – Krythic Dec 20 '16 at 21:41

Ok- so I've tried it out. So far, so good. No noticeable performance losses yet. The one hangup I hadn't considered was that I have to manually implement what was previously taken care of by GL_CLAMP regarding texture bleeding. So I think the answer so far is "yep, this is a good thing". (Unless this is just a ticking time bomb waiting to bite me in the butt...)


The fewer buffers you use, the better the performance will be but obviously it is more work to use fewer, larger buffers instead of smaller ones (as you are finding).

  • \$\begingroup\$ by "more work", do you mean for me (the programmer)? like, it requires more complex wrangling of figuring out which data goes where? or do you men more work for the GPU? would you have any insight on my texel-cache theory? will using a single buffer sampled from multiple places ruin any GPU caching? Thanks! \$\endgroup\$ – Phildo Sep 14 '16 at 14:55
  • \$\begingroup\$ I mean more work for you as a programmer. Look at the difference between drawing a GUI or text in an atlas as opposed to having it all in one texture. It has better performance but is kind of a pain. \$\endgroup\$ – Yudrist Sep 14 '16 at 15:39

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.