布局量词(位置)在统一/输入/输出之间是否应有所不同? [英] Should layout quantifier (location) differ between uniform/in/out?

查看:237
本文介绍了布局量词(位置)在统一/输入/输出之间是否应有所不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在为我的GLSL着色器设置布局量词(位置).这个问题使我感到震惊,这些量词ID是否需要彼此不同.

I am now setting up layout quantifier (location) for my GLSL shaders. And this question hits me whether those quantifier ID need differ with each other.

必须是:

layout (location = 0) uniform vec3 v1;
layout (location = 1) in vec3 v2;
layout (location = 2) uniform vec3 v3;
layout (location = 3) in vec3 v4;

或者可以是(因为位置可以指定为制服或输入):

Or it can be (as the location can be specified as uniforms or inputs):

layout (location = 0) uniform vec3 v1;
layout (location = 0) in vec3 v2;
layout (location = 1) uniform vec3 v3;
layout (location = 1) in vec3 v4;

谢谢.

推荐答案

对于顶点着色器属性,布局位置是属性索引, 统一变量的布局位置是统一位置. 这些是不同的东西.

While for vertex shader attributes the layout location is the attribute index, the layout location for uniform variables is the uniform location. These are different things.

如果未设置显式的布局位置并在链接着色器程序后读取了位置,则可以看到它们可以在同一范围内. 这可以通过 glGetAttribLocation 来完成. 和 glGetUniformLocation

If you do not set explicit layout locations and read the locations after linking the shader program, you can see that they can be both in the same range. This can be done by glGetAttribLocation and glGetUniformLocation

您的两种变体都是正确且可能的. 属性位置必须唯一,统一位置必须唯一. 但是除了位置索引类型之外,它们不必是明确的.

Both of your variants are correct and possible. Attribute locations must be unique and uniform locations must be unique. But they don't have to be unambiguous, beyond the location index type.

有关布局限定符的更多详细信息,我建议Khronos集团的OGL和GLSL文档: 布局限定符(GLSL)

For more detailed information on layout qualifier, I recommend the OGL and GLSL documentation of the Khronos Group: Layout Qualifier (GLSL)

分别参见 OpenGL 4.6 API核心配置文件规范-7.3.1程序接口.

活动资源列表中用于接口的每个条目都被分配唯一的无符号整数索引,范围从零到N − 1,其中N是条目数在活动资源列表中.

Each entry in the active resource list for an interface is assigned a unique unsigned integer index in the range zero to N − 1, where N is the number of entries in the active resource list.

统一变量的接口类型为UNIFORM,而属性的类型为PROGRAM_INPUT.可以使用 glGetProgramResourceLocation 的程序界面类型和名称.

While the interface type for uniform variables is UNIFORM, the type for attributes is PROGRAM_INPUT. The location of the different program resources can be get with the instruction glGetProgramResourceLocation by its program interface type and name.

这篇关于布局量词(位置)在统一/输入/输出之间是否应有所不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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