gpt4 book ai didi

opengl - GLSL 统一布局绑定(bind)和纹理

转载 作者:行者123 更新时间:2023-12-03 17:09:57 25 4
gpt4 key购买 nike

当制服使用布局绑定(bind)时,我对绑定(bind)纹理的正确方法有点困惑。

layout(binding = 0, std140) uniform uCommon
{
mat4 projectionMatrix;
mat4 viewMatrix;
};

layout(binding = 1, std140) uniform uModel
{
mat4 modelViewProjectionMatrix;
};

layout(binding = 3) uniform sampler2D uTexture;

要绑定(bind)我的第一个纹理,我应该使用“GL_TEXTURE0 + 3”吗?

glActiveTexture(GL_TEXTURE0 + 3);
glBindTexture(GL_TEXTURE_2D, textureId);

这是正确的方法吗?

编辑: 或者采样器使用与其他制服不同的绑定(bind)?我可以使用:

layout(binding = 0) uniform sampler2D uTexture;

还在使用

layout(binding = 0, std140) uniform uCommon

最佳答案

统一 block 绑定(bind)索引与采样器绑定(bind)位置无关。这些是不同的东西。

用于指定绑定(bind)点或单元的整数常量表达式在关键字binding<的所有用法中不必是唯一的/strong>.


参见 OpenGL Shading Language 4.60 Specification; 4.4.5 Uniform and Shader Storage Block Layout Qualifiers; page 77

The binding identifier specifies the uniform buffer binding point corresponding to the uniform or shader storage block, which will be used to obtain the values of the member variables of the block.


参见 OpenGL Shading Language 4.60 Specification; 4.4.6 Opaque-Uniform Layout Qualifiers; page 79

Image and sampler types both take the uniform layout qualifier identifier for binding:

layout-qualifier-id :
binding = integer-constant-expression

The identifier binding specifies which unit will be bound.

关于opengl - GLSL 统一布局绑定(bind)和纹理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49097947/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com