sampler2D存储什么? [英] What does sampler2D store?
问题描述
我已经在OpenGL 2.1
中阅读了一个纹理示例.片段着色器如下所示:
I've read a texture example in OpenGL 2.1
. The fragment shader looks like this:
#version 120
uniform sampler2D texture;
varying vec2 texcoord;
void main(void)
{
gl_FragColor = texture2D(texture, texcoord);
}
texcoord
是从顶点着色器传递的.
The texcoord
is passed from vertex shader.
使用以下C ++渲染代码:
The following C++ rendering code is used:
void render()
{
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture_id);
glUniform1i(unf_texture, 0);
}
我对某些事情感到困惑.我有一个问题:
I am confused about some things. I have some question:
-
在片段着色器中,纹理传递了一个零值(通过
glUniform1i()
).该值真的为零吗?价值还有其他吗?
In the fragment shader, the texture is passed a zero value (by
glUniform1i()
). Is the value really zero? Is the value something else?
真的需要glActiveTexture()
通话吗?
为什么在glUniform1i()
中传递零值?
推荐答案
The sampler2D
is bound to a texture unit. The glUniform
call binds it to texture unit zero. The glActiveTexture()
call is only needed if you are going to use multiple texture units (because GL_TEXTURE0
is the default anyway).
这篇关于sampler2D存储什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!