sampler2D存储什么? [英] What does sampler2D store?

查看:188
本文介绍了sampler2D存储什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在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:

  1. 在片段着色器中,纹理传递了一个零值(通过glUniform1i()).该值真的为零吗?价值还有其他吗?

  1. 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()中传递零值?

推荐答案

sampler2D绑定到

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屋!

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