Non power-of-two textures and gl_TexCoord

Hello all,

I’m trying to do a YUV to RGB conversion on my frag shader…It looks something like:

uniform sampler2D texY, texU, texV;

void main()
{
float nx,ny,r,g,b,y,u,v;

nx=gl_TexCoord[0].x;
ny=gl_TexCoord[0].y;

y=texture2D(texY,vec2(nx,ny)).r;
u=texture2D(texU,vec2(nx/2.0,ny/2.0)).r;
v=texture2D(texV,vec2(nx/2.0,ny/2.0)).r;

y=1.1643*(y-0.0625);
u=u-0.5;
v=v-0.5;

r=y+1.5958*v;
g=y-0.39173*u-0.81290*v;
b=y+2.017*u;

gl_FragColor=vec4(r,g,b,1.0);

}

I’m passing the 3 textures in as luminance (and as you saw in the frag shader I’m only reading the r component). The 3 textures are passed in like this:

glActiveTexture(GL_TEXTURE0);
int sampler2D1 = glGetUniformLocation(mShaderProgram, “texY”);
glUniform1i(sampler2D1, 0);
glBindTexture(GL_TEXTURE_2D, mTexID_Y);
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width, height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, bufY);

Similar for U and V BUT with width being width/2 and height being height/2 (for both U and V).

To my knowledge, everything should work fine…When I just display the luminance, I see my texture the way it’s meant to look. But when I display my U and V, they look distorted.

Am I right to assume that with openGL 2.0 I can use non powe-of-two-textures? The texture in question is 240x176. Is gl_TexCoord going to behave the way it’s meant to for a 240x176 texture?

(I’m assuming yes because as I said earlier my luminance works fine…I just want to confirm before I carry on looking into what’s gone wrong)

cheers,
g.

OpenGL texture coordinates are in range [0…1], regardles of the texture actual size. Just remove that /2.0 in the shader.

Digging deeper, I found that it does have to do with the power-of-two thing after all…

Apparently you need to use sampler2DRect and texture2DRect, but I’ve yet to find a way for this to work on win & lin, for both NV & ATI.

For some wierd reasons (with an NV) under win you can use sampler2DRect but on lin you have to use samplerRECT. And there’s various differences between NV & ATI with the extensions as well…

If anyone knows how to do this cross-platofrm, cross graphics card, all help will be much appreciated.

cheers,
K.

Originally posted by g0l3m:
For some wierd reasons (with an NV) under win you can use sampler2DRect but on lin you have to use samplerRECT. And there’s various differences between NV & ATI with the extensions as well…
Really? It worked fine on NVidia/Linux when I tried it a year and a half or so ago, I’m sure. Do you have the latest drivers?

The latest ATI/Linux drivers appear also to support ARB_texture_rectangle, so I’d expect it to work “everywhere” now.

Prior to that, it was necessary on ATI/Windows/Linux to use OpenGL 2.0’s implicit support for non-power-of-two textures, being careful to stick to CLAMP_TO_EDGE and LINEAR to remain in hardware.

The Mac has supported ARB_texture_rectangle on ATI, NVidia and Intel since 10.4.3.

You don’t need to use the texture2DRect if you use NPOT textures - that is, TEXTURE_2D with NPOT dimensions. This should work both for ATI and NV letest cards, on each platform. Note that ATIs support for such textures is more limited (basically what OneSaidCookie said). Using ARB_texture_rectangle would make you shader very ugly.

What I posted above (even removing the /2.0) doesn’t work on a RADEON X800, and doesn’t work on a NV 5900. When you say “latest cards”, what do you mean? (I’ve got the latest drivers btw).

Min spec (although not 100% decided yet) is NV FX5500 (and the ATI equivalent).

In case it’s any relevant, the texture in question is 240x176 (but it could be any texture size really since these are textures captured from a video decoder).

cheers,
Kos.

NPOT is supported by Geforce 6 and up + Radeons X1xxx and up. You’ll have to stick to rectangle textures then.

/cries

Thx for the feedback guys.
Much appreciated.

WRT texture_rectangle_ARB ive installed new nvidia drivers ie 100.+
now im getting warning messages like (which werent there before, the shader works as expected though)

Fragment info

(5) : warning C7506: OpenGL does not define the global type samplerRect

heres my shader code

#extension GL_ARB_texture_rectangle : enable
uniform samplerRect tex9;

instead of samplerRect what should i use?

Zed, by any chance are you reading the texture unit from the sampler name? :wink:

By the way, I’ve gotten spurious warnings w.r.t. unsupported implicit conversions, which are now allowed, provided no information is lost. Probably just some leftover scaffolding from a previous compiler version.

ok it seems the correct syntax is sampler2DRect
samplerRECT is cg
they must of tightened up their behaviour

Hmmm, well the spec says it’s samplerRect and samplerRectShadow.

You’re right, though. In Cg it’s samplerRECT.

Anyhoo, I don’t use rects, so it’s all academic to me.

Hmmm, well the spec says it’s samplerRect and samplerRectShadow.
from the ARB_rect spec (seems there was a typo)

2/23/2005 - Fix the GLSL interaction: 1) GLSL functions require
a vector (not scalar) parameter for the texture coordinate set: 2)
The actual reserved types are sampler2DRect and sampler2DRectShadow
(not samplerRect and samplerRectShadow); and 3) the shadow functions
were missing.
seems like i was looking at the old spec when i implemented it (which it seems you have as well Leghorn, might wanna download a new version)

Actually I lazily googled it and hit an old 3DLabs link to an older version of the spec. Good to know that’s been changed, though I’m not sure why it was. I kinda like samplerRect better…

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.