# Clever Texture Lookup suggestions...

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

## Recommended Posts

Hey all, Just a general GPGPU question. I am currently using the GPU to simulate a collection of bees, something I've described a bit in my previous posts if anyone is interested. However - what I'm doing is not that important. More important is, in my Cg programs I use texRECT() to make a texture lookup in my cg programs. Given a single number I'd like to look up that pixel in a texture. Previously I've done this by passing the texture size to the Cg program as a parameter and writing a function that calculates its position. Something like this (where the tex size is known to be 64):

float4 fetchData(int dataArrayPosition, samplerRECT textureData)

{
float intTextureCoordX, intTextureCoordY, rgbaIndex, returnNr;

intTextureCoordY = dataArrayPosition/64;
intTextureCoordY = floor(intTextureCoordY);
intTextureCoordX = fmod((float) dataArrayPosition,64);

}


I'm basically interested in better ways of doing this. Perhaps Cg can wrap texcoordinates for me or something? I don't honestly know :) If anybody has any suggestions like alternatives or improvements, please let me know... Regards, Gazoo

##### Share on other sites
surely u only need to do

##### Share on other sites
Uhhhh no?

Using your method the lookup will never actually perform lookups outside the "bottom" row of a texture where Y is 0. At least that has been my experience with your suggestion...

I believe I'll stick with my own solution, unless someone else has anything to add?

Regards,

Gazoo

##### Share on other sites
You could do the division in the vertex shader and just use the interpolated values there. As for the modulo thing, you can actually setup wrapping in the GL using glTexParameter. Same goes for the rounding, which should be equivalent to using GL_NEAREST filtering. The manpage on the opengl.org site is quite insightful if you need any more help.

##### Share on other sites
It should be possible to pull his off without shaders even. Just turn off filtering, turn on wrapping, and set your tex coords to [dataArrayPosition, dataArrayPosition / 64].