Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Opengl 在glsl中指定纹理数组的绑定_Opengl_Glsl_Shader - Fatal编程技术网

Opengl 在glsl中指定纹理数组的绑定

Opengl 在glsl中指定纹理数组的绑定,opengl,glsl,shader,Opengl,Glsl,Shader,在glsl 420中,添加了功能来指定着色器中的绑定,而不必调用glUniform1i。例如: layout(binding = 0) uniform sampler2D u_Texture; 但如何才能为阵列做到这一点 layout(binding ?) uniform sampler2D u_Textures[16]; 我希望绑定为0,1,2,…,15。如果没有任何glUniform调用,我是否无法在glsl中执行此操作?请参阅: 与OpenGL一起使用时,如果绑定限定符与作为数组实例化

在glsl 420中,添加了功能来指定着色器中的绑定,而不必调用
glUniform1i
。例如:

layout(binding = 0) uniform sampler2D u_Texture;
但如何才能为阵列做到这一点

layout(binding ?) uniform sampler2D u_Textures[16];
我希望绑定为0,1,2,…,15。如果没有任何
glUniform
调用,我是否无法在glsl中执行此操作?

请参阅:

与OpenGL一起使用时,如果绑定限定符与作为数组实例化的统一块或着色器存储块一起使用,数组的第一个元素采用指定的块绑定,每个后续元素采用下一个连续绑定点

这意味着您只需指定数组中第一个采样器的绑定点:

布局(绑定=0)均匀采样2D u_纹理[16];

但请注意,当采样器聚合到着色器中的数组中时,这些类型只能使用索引索引,否则纹理查找将导致未定义的值

我建议使用
sampler2DArray
(请参阅),而不要使用
sampler2D
数组

另请参见: