PDA

View Full Version : Texture Caching



royconejo
04-30-2002, 11:14 PM
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 http://www.opengl.org/discussion_boards/ubb/wink.gif

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 http://www.opengl.org/discussion_boards/ubb/smile.gif


_> Royconejo.

Bob
05-01-2002, 02:49 AM
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.

zeckensack
05-01-2002, 11:39 AM
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.

Jurjen Katsman
05-01-2002, 12:01 PM
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).

royconejo
05-01-2002, 07:52 PM
Originally posted by Jurjen Katsman:
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).

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 http://www.opengl.org/discussion_boards/ubb/frown.gif

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.

davepermen
05-01-2002, 10:38 PM
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..

royconejo
05-01-2002, 10:57 PM
Thank you all for the replies http://www.opengl.org/discussion_boards/ubb/smile.gif

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 http://www.opengl.org/discussion_boards/ubb/smile.gif


_> Royconejo.