在OpenGL中同时绑定1D和2D纹理时,正确的行为是什么? [英] What is the correct behavior when both a 1D and a 2D texture are bound in OpenGL?

查看:91
本文介绍了在OpenGL中同时绑定1D和2D纹理时,正确的行为是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说你有这样的东西:

glBindTexture(GL_TEXTURE_2D, my2dTex);
glBindTexture(GL_TEXTURE_1D, my1dTex);
glBegin...

正确的OpenGL行为是什么?要绘制1d纹理,是绘制2d还是同时绘制两个纹理?对于每个活动纹理,实际上是否可以同时绑定多个纹理(例如1d,2d,3d立方体贴图等)?

What is the correct OpenGL behavior? To draw the 1d texture, the 2d or both? For each active texture are there actually multiple textures that can be bound to it at the same time (i.e. a 1d, 2d, 3d cube map, etc.)?

推荐答案

绑定的GL状态是每个目标一个 纹理名称(即1D/2D/3D/cube).因此,在致电

The GL state for the bindings is one texture name per target (i.e. 1D/2D/3D/cube). So when calling

glBindTexture(GL_TEXTURE_2D, my2dTex)
glBindTexture(GL_TEXTURE_1D, my1dTex)

GL将记住这两个设置.

the GL will remember both settings.

现在,一个GL将使用的答案取决于您是否启用了着色器.

Now, the answer of which one GL will use depends on whether you have a shader on.

如果启用了着色器,则GL将使用该着色器要使用的任何内容. (基于sampler1d/sampler2d ...).

If a shader is on, the GL will use whatever the shader says to use. (based on sampler1d/sampler2d...).

如果没有打开任何着色器,则首先取决于进行了哪个glEnable调用.

If no shader is on, then it first depends on which glEnable call has been made.

glEnable(GL_TEXTURE_2D)
glEnable(GL_TEXTURE_1D)

如果同时启用了,则规范中将存在静态优先级规则(GL 1.5规范中的"3.8.15 Texture Application").

If both are enabled, there is a static priority rule in the spec (3.8.15 Texture Application in the GL 1.5 spec).

Cube > 3D > 2D > 1D

因此,在您的情况下,如果同时启用了两个纹理目标,则将使用2D纹理.

So in your case, if both your texture targets are enabled, the 2D one will be used.

作为旁注,请注意着色器不在乎 是否已启用纹理目标...

As a side note, notice how a shader does not care whether or not the texture target is Enabled...

编辑以添加:

对于真正想了解详细细节的人们,您总是始终为每个目标*每个单元绑定一个纹理.名称0(绑定状态的默认名称)对应于一系列纹理对象,每个目标一个. glBindTexture(GL_TEXTURE_2D, 0)glBindTexture(GL_TEXTURE_1D, 0)都绑定了一个纹理,但是不相同.

And for the people who really want to get to the gritty details, you always have a texture bound for each target * each unit. The name 0 (the default for the binding state) corresponds to a series of texture objects, one per target. glBindTexture(GL_TEXTURE_2D, 0) and glBindTexture(GL_TEXTURE_1D, 0) both bind a texture, but not the same one...

这是历史记录,被指定为与GL 1.0的行为匹配,在该情况下纹理对象尚不存在.不过,我不确定GL3.0中的弃用功能是什么.

This is historical, specified to match the behavior of GL 1.0, where texture objects did not exist yet. I am not sure what the deprecation in GL3.0 did with this, though.

这篇关于在OpenGL中同时绑定1D和2D纹理时,正确的行为是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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