使用采样器而不传递值 [英] Use sampler without passing through value

查看:64
本文介绍了使用采样器而不传递值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用片段着色器处理纹理,我使用sampler2D来获取2D纹理,但是我没有在OpenGL程序中传递值.但是,那个sampler2D的值是正确的.

I'm dealing with texture in fragment shader and I use a sampler2D to get the 2D texture but I do not pass through the value in OpenGL program. However, the value of that sampler2D is correct.

我对此感到很困惑,对此有任何解释吗?

I feel really confused about this and any explanation about this?

推荐答案

采样器变量的默认值为0.根据GLSL 3.30规范的"4.3.5制服"部分:

The default value of a sampler variable is 0. From the GLSL 3.30 spec, section "4.3.5 Uniforms":

链接时间初始值是变量的初始值设定项(如果存在)的值,或者如果不存在初始值设定项,则为0.采样器类型不能具有初始化程序.

The link time initial value is either the value of the variable's initializer, if present, or 0 if no initializer is present. Sampler types cannot have initializers.

由于值为0表示它是从纹理单位0采样的,因此只要将纹理绑定到单位0,它就不会设置该值.

Since a value of 0 means that it's sampling from texture unit 0, it will work without ever setting the value as long as you bind your textures to unit 0. This is well defined behavior.

由于直到您使用GL_TEXTURE0以外的值调用glActiveTexture()时,纹理单位0也是默认值,所以只要着色器不需要多个纹理,始终使用单位0是很常见的.这意味着通常情况下,设置采样器制服对于简单应用是多余的.

Since texture unit 0 is also the default until you call glActiveTexture() with a value other than GL_TEXTURE0, it's very common to always use unit 0 as long as shaders do not need more than one texture. Which means that often times, setting the sampler uniforms is redundant for simple applications.

我仍然希望始终设置这些值.如果没有其他说明,那么所有阅读您的代码的人都可以清楚地知道,您真正要从纹理单元0进行采样,而不仅仅是忘记设置该值.

I would still prefer to always set the values. If nothing else, it makes it clear to anybody reading your code that you really mean to sample from texture unit 0, and did not just forget to set the value.

这篇关于使用采样器而不传递值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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