Howdy, Stranger!
It looks like you're new here. If you want to get involved, click one of these buttons!
Categories
- All Discussions1,524
- General534
- Graphics109
- GPU Computing419
- Mobile141
- Pro Graphics163
- Tools158
In this Discussion
- atuyo60 January 23
Tags in this Discussion
- opengl 81
- cg 46
- shader 30
- texture-tools 8
OpenGL 3.3 Sampler Objects with CG Fragment Shader
-
Hi, I have been trying to get my CG fragment shader working with the sampler objects introduced in OpenGL 3.3 but the shader does not seem to be associating my OpenGL sampler with the texture unit.
I generate my sampler during initialisation as followsGLuint glsampler = 0;
glGenSamplers (1, &glsampler);
glSamplerParameteri (glsampler, GL_TEXTURE_WRAP_S, GL_REPEAT);
glSamplerParameteri (glsampler, GL_TEXTURE_WRAP_T, GL_REPEAT);
glSamplerParameteri (glsampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glSamplerParameteri (glsampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
I have tried using cgGLSetTextureParameter and cgGLEnableTextureParameter as well but they do not work and my understanding is that if I do not set these and if I just call glBindTexture(GL_TEXTURE_2D, gltexture); it will bind to the appropriate uniform sampler2D on my fragment program. In my rendering loop, I followed the OpenGL way of binding my texture to the proper texture image unit:glActiveTexture(GL_TEXTURE0 + 0);
glBindTexture(GL_TEXTURE_2D, gltexture);
glBindSampler(0, glsampler);
My fragment shader is just:struct FragOutput
{
float4 color : COLOR0;
};
void main (float4 color : COLOR0, float2 texcoord : TEXCOORD0, uniform sampler2D decal : TEXUNIT0, out FragOutputoutput)
{
output.color = tex2D(decal, texcoord);
}
As seen above I have bounded my uniform sampler2D to TEXUNIT0 hoping that it would read my OpenGL sampler object from the texture unit but it does not and no filtering is done. My initial code did not include TEXUNIT0 semantic and it also failed to work.
I have been searching for a solution for 2 days and all I could find were old examples and code for GLSL which I tried porting and did not work. Could someone explain to me how should I be associating OpenGL sampler objects with my shader uniforms so that the appropriate filtering is done? Thank you! -
1 Comment sorted by
-
Ok I think it is working but only if I call glGenerateMipmaps. I do not really understand this because my sampler is not using any of the mipmap filters. Anyone can explain to me or am I doing something wrong here?