Should layout quantifier (location) differ between uniform/in/out?

南笙酒味 提交于 2019-12-01 09:18:48

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.

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.

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

Respectively see OpenGL 4.6 API Core Profile Specification - 7.3.1 Program Interfaces.

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.

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!