简体   繁体   English

在OpenGL中绑定零纹理

[英]Binding a zero texture in OpenGL

In my program I use 2 textures: t0 and t1. 在我的程序中,我使用2个纹理:t0和t1。 t1 is additional, needed only in some cases: t1是附加的,仅在某些情况下需要:

.....
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. 假设使用glBindTexture(..,0)返回零纹理(0,0,0,0),但在将NVidia驱动程序更新为314.07之后,我的代码生成黑屏,就像glBindTexture(..,0)返回(0,0) ,0,1)纹理。

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. 我在旧驱动程序(296,306)上获得绿色屏幕,在新驱动程序上获得红色。 I tested it on 2 computers with Win 7 (GeForce 210) and win XP (GTX 260). 我用2台电脑用Win 7(GeForce 210)测试了它,并赢得了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? 所以我的问题是:使用带有0作为第二个参数的glBindTexture是正确的,以及如何使用新驱动程序实现相同的结果(0000纹理)?

All the following refers to the core profile 3.2, but generally applies to all versions of GL. 以下所有内容均指核心配置文件3.2,但通常适用于所有版本的GL。

The name 0 corresponds to the default texture objects (one per texture target: 1d, 2d, ... See 3.8.14, last paragraph). 名称0对应于默认纹理对象(每个纹理目标一个:1d,2d,...见3.8.14,最后一段)。

So glBindtexture(2D, 0); 所以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). 现在规范说(3.9.2,纹理访问段落)从不完整的纹理采样将返回(0,0,0,1)。

So your older drivers didn't behave according to the spec. 所以你的老司机没有按照规范行事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM