Texture Caching

Hi… I’m rendering some tiles over a terrain… I’d like to have all those tile textures cached into a big texture to bind it once. I’m storing the texture coordinates relative to that big texture so that I now where to get any tile from it,

__0.3__0.6___1
------------- 0
|000|111|222|
|000|111|222|
------------- 0.5 (texcoords)
|333|444|555|
|333|444|555|
------------- 1 <-- (6 tiles arranged in one big texture

tile_0.s = 0; tile_0.w = 0.3; // storing texture coordiates to reach tile 0.
tile_0.t = 0; tile_0.h = 0.5;

… and then I’m using the texture matrix to adjust the texture coordinates of a glquad to render just one tile that covers the entire quad. At first it seemed very simple and fast to me but… how could I repeat a tile over a single quad using this method? or, there is another method to store many tiles in one texture, and tile one of them over a single quad?

Well… thanks in advance for your help

_> Royconejo.

I don’t think it’s possible to repeat parts of a texture.

If you want to tile them in one direction only, say the S direction, you can put several textures in the T direction. But if you want to tile them in both directions, you are out of luck.

Originally posted by royconejo:
… and then I’m using the texture matrix to adjust the texture coordinates of a glquad to render just one tile that covers the entire quad. At first it seemed very simple and fast to me

I think your assumption about speed is wrong. Updating the texture matrix is a lot more expensive than a change in texture binding.

Uhm, are you sure about that? Seems fairly unlikely.

Binding a texture involves resource management, a whole bunch of states, texture cache fluches, etc. The texture matrix would just be a new matrix going into hardware registers. (Assuming hardware transform).

Originally posted by Jurjen Katsman:
[b]Uhm, are you sure about that? Seems fairly unlikely.

Binding a texture involves resource management, a whole bunch of states, texture cache fluches, etc. The texture matrix would just be a new matrix going into hardware registers. (Assuming hardware transform).[/b]

Yes… I’ve tested it and it’s way faster… I’m just doing 1 bind and could have as much as 256 64x64 tiles in a 1024x1024 texture (or 128 64x64 and 4 256x256 detail textures)… and I could have the tile cache bound in TU 0, and the shadow map cache on TU 1… but I have that fu@!# problem

well, it’s a shame this can’t be done :_(

but… some time ago I heared that the Quake2 engine has a similar cache layout… this is true? so how do they tile them??

I have to split the tile cache in unique textures? there’s no way around that?

_> Royconejo.

they use it for lightmappin, cause the lightmaps are only 8x8 pixels big (or 16x16 possibly…)

but they don’t need to GL_REPEAT the stuff as every triangle gets exactly its pixels mapped, wich are unique on the texture…

Thank you all for the replies

I’m going to resolve this using the suggestion from Bob… but copying several tiles in S and T… since I’m using quadtrees, actually the tiles are tiled in (for example) 32x32 tiles, 16x16 tiles, 8x8 and 4x4 (all quadtree levels)… so I don’t neet to make them tile using texcords at all.
In fact… I’m using tiles just to get a consistent rendering all over the different subdivisions of the quadtree terrain.

Thanks again

_> Royconejo.