GLSL 统一布局绑定和纹理
GLSL Uniform layout binding and textures
当制服使用布局绑定时,我对绑定纹理的正确方法有点困惑。
layout(binding = 0, std140) uniform uCommon
{
mat4 projectionMatrix;
mat4 viewMatrix;
};
layout(binding = 1, std140) uniform uModel
{
mat4 modelViewProjectionMatrix;
};
layout(binding = 3) uniform sampler2D uTexture;
要绑定我的第一个纹理,我应该使用 "GL_TEXTURE0 + 3"?
glActiveTexture(GL_TEXTURE0 + 3);
glBindTexture(GL_TEXTURE_2D, textureId);
这是正确的方法吗?
编辑: 或者采样器使用与其他制服不同的绑定?我可以使用:
layout(binding = 0) uniform sampler2D uTexture;
还在使用
layout(binding = 0, std140) uniform uCommon
统一块绑定索引与采样器绑定位置无关。这些是不同的东西。
用于指定绑定点或单元的integer-constant-expression在关键字[=的所有用法中不必是唯一的11=].
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.
当制服使用布局绑定时,我对绑定纹理的正确方法有点困惑。
layout(binding = 0, std140) uniform uCommon
{
mat4 projectionMatrix;
mat4 viewMatrix;
};
layout(binding = 1, std140) uniform uModel
{
mat4 modelViewProjectionMatrix;
};
layout(binding = 3) uniform sampler2D uTexture;
要绑定我的第一个纹理,我应该使用 "GL_TEXTURE0 + 3"?
glActiveTexture(GL_TEXTURE0 + 3);
glBindTexture(GL_TEXTURE_2D, textureId);
这是正确的方法吗?
编辑: 或者采样器使用与其他制服不同的绑定?我可以使用:
layout(binding = 0) uniform sampler2D uTexture;
还在使用
layout(binding = 0, std140) uniform uCommon
统一块绑定索引与采样器绑定位置无关。这些是不同的东西。
用于指定绑定点或单元的integer-constant-expression在关键字[=的所有用法中不必是唯一的11=].
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.