在OpenGL中绑定零纹理 [英] Binding a zero texture in OpenGL

查看:168
本文介绍了在OpenGL中绑定零纹理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的程序中,我使用2个纹理:t0和t1. t1是额外的,仅在某些情况下需要:

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 );

用于绘制的着色器:

.....
vec4 c1 = texture( textureId0, uv );
vec4 c2 = texture( textureId1, gridUV );
float a = c2.a;
gl_FragColor = ( 1.0 - a )*c1 + a*c2;

效果很好:需要时,第二个纹理首先重叠.假设使用glBindTexture(..,0)返回零纹理(0,0,0,0),但是在将NVidia驱动程序更新为314.07之后,我的代码处理了黑屏,例如glBindTexture(..,0)返回(0,0 ,0,1)纹理.

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;

我在旧驱动程序(296、306)上显示绿屏,在新驱动程序上显示红色.我在Win 7(GeForce 210)和Win XP(GTX 260)的两台计算机上对其进行了测试.

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).

所以我的问题是:使用glBindTexture和0作为第二个参数是正确的,以及如何使用新的驱动程序获得相同的结果(0000 texture)?

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?

推荐答案

以下所有内容均指核心配置文件3.2,但通常适用于所有版本的GL.

All the following refers to the core profile 3.2, but generally applies to all versions of GL.

名称0对应于默认纹理对象(每个纹理目标一个:1d,2d,...请参见最后一段3.8.14).

The name 0 corresponds to the default texture objects (one per texture target: 1d, 2d, ... See 3.8.14, last paragraph).

因此,glBindtexture(2D, 0);为您提供默认的纹理对象.它不是不是意思是禁用纹理化.现在,从默认对象进行纹理化将导致通常的操作,只是对尚未创建的纹理对象进行操作.初始纹理对象最初是不完整的,因此除非您对其进行修改,否则它将遵循不完整"规则.

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.

现在,规范说(3.9.2,纹理访问"段落),从不完整的纹理采样将返回(0,0,0,1).

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.

这篇关于在OpenGL中绑定零纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆