Jump to content
  • Advertisement
Sign in to follow this  
Gazoo101

OpenGL Referencing smaller textures within a big one

This topic is 2591 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey GameDev,

I have texture related question I'm unsure can be solved without modifying my current data. So - I basically have quite a large array - approximately 1024 * 64 (* 3 for RGB), where each of the 64 parts represent a small 8 by 8 texture. I wish to visualize 1024 quads, each with its own unique tiny texture on it. Now, the data is stored sequentially, so one complete 8x8(x3) Texture followed by another. If I were to upload each texture separately, this could be accomplished quite easily by just pointing to the correct place in the array and then specifying a height/width of 8 to OpenGl and voila, a small square texture. However, this would result in a total of 1024 textures on the card. What's more is that I will be increasing the number of quad textures up to 16384...

I am assuming its unfeasible to upload that many textures, so instead uploading a huge texture with all of them in it might be better? But it seems to be that I must restructure the data so it's no longer sequential, but in "blocks" next to each other, so I can use the texture coordinates to properly isolate one proper texture to each small quad...

Does this sound wise? I would prefer not to have to restructure the data, but right now I am unsure if it is at all possible without re-touching the data...

Regards,
Gazoo

Share this post


Link to post
Share on other sites
Advertisement
Using a texture atlas: 1024 patches arranged in a square makes a 32 x 32 patch layout. Each patch has 8 x 8 texels, making a total texture size of 256 x 256 texels; that is no problem. OpenGL supports some juggling by using the glPixelStore command w/ the GL_UNPACK_* set of parameters. However, I'm under the impression that those isn't sufficient for you to avoid reordering the data (but you should check it yourself). However, couldn't you do the reordering programmatically after loading the data from mass storage and before uploading it to the GPU? You have to adapt the texture co-ordinates anyway. But be aware that such a dense pacing of patches into a texture atlas may produce visible artifacts (e.g. seams) in situations where you enforce the texture sampler to sample texels of neighbored patches (may happen e.g. if you use rotated quads).

Another possibility is to use texture arrays. AFAIK your current data layout is okay for such a texture. However, support for texture arrays isn't guaranteed these days. And you still have to adapt the texture co-ordinates, this time not in the u,v dimensions but you have to add a 3rd coefficient to address the texture's slice.

Share this post


Link to post
Share on other sites
It depends. Are you going to render with those 16384 at the same time. If the answer is no and you'll only use some of them then there will be no performance problem.

If the answer is yes, then you can do as you say. Texture Atlas. If you will use mipmapping, then it can be a problem on lower mipmaps. You would have to prepare mipmaps yourself and not use glGenerateMipmap (GL 3.0) (or the GL 1.4 equivalent).

Then there is texture arrays but I'm not sure what the depth of a texture array is these days. This requires GL 3.0.

Share this post


Link to post
Share on other sites
Hey haegarr and V-man,

Thanks for taking your valuable to render me a reply. I appreciate it! I will not need to render them all at the same time, but after thinking about it for a short while, it hit me - why not just treat the entire texture as a 3D texture? I will always be rendering a small sub portion in a raw (non-mipmapped) format. It's excellent. That way I get the benefit of a Texture atlas without the need to restructure my data. Yay!

Gonna get right on implementing that...

Regards,
Gazoo

Share this post


Link to post
Share on other sites
I am not sure if I understand your question correctly, but in my 2D engine I render smaller tiles from a bigger tilemap texture by generating texture coordinates that represent each tile in the map. I then use these coordinates to render each tile (quad) of the map.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!