问题
In my program I use 2 textures: t0 and t1. t1 is additional, needed only in some cases:
.....
glActiveTexture ( GL_TEXTURE1 );
if ( mDisplayMode == EDM_DEFAULT ){
glBindTexture( GL_TEXTURE_2D, 0 ); // In this case I don't need t1
}else{
glBindTexture( GL_TEXTURE_2D, mglDegreeTexture ); // In this case t1 will overlap t0
}
shader->setUniformValue( "textureId1", 1 );
Shader for drawing:
.....
vec4 c1 = texture( textureId0, uv );
vec4 c2 = texture( textureId1, gridUV );
float a = c2.a;
gl_FragColor = ( 1.0 - a )*c1 + a*c2;
It's works fine: second texture overlap first when needed. Assuming that using glBindTexture( .. , 0 ) return zero texture (0,0,0,0), but after updating NVidia drivers to 314.07, my code procude black screen, like glBindTexture( .. , 0 ) return (0,0,0,1) texture.
I perform some test: With shader
....
vec4 c1 = texture( textureId0, uv );
vec4 c2 = texture( textureId1, gridUV );
float a = c2.a;
if (a == 1){
gl_FragColor = vec4(1,0,0,0);
return;
}
if ( a == 0){
gl_FragColor = vec4(0,1,0,0);
return;
}
gl_FragColor = ( 1.0 - a )*c1 + a*c2;
I get green screen on old driver (296, 306), and red on a new one. I tested it on 2 computers with Win 7 (GeForce 210) and win XP (GTX 260).
So my question is: It is correct to use glBindTexture with 0 as second parameter, and how I can achieve same result ( 0000 texture ) with a new driver?
回答1:
All the following refers to the core profile 3.2, but generally applies to all versions of GL.
The name 0 corresponds to the default texture objects (one per texture target: 1d, 2d, ... See 3.8.14, last paragraph).
So glBindtexture(2D, 0);
gets you the default texture object. It does not mean disable texturing. Now texturing from the default object results in the usual operation, just on a texture object that you have not created yourself. The initial texture object is initially incomplete, so unless you modify it, it will behave following the "incomplete" rules.
Now the specification says (3.9.2, Texture Access paragraph) that sampling from an incomplete texture will return (0,0,0,1).
So your older drivers didn't behave according to the spec.
来源:https://stackoverflow.com/questions/15273674/binding-a-zero-texture-in-opengl