一个纹理数组的多个采样器

问题描述 投票:0回答:1
  • 如何为一个纹理数组创建多个采样器?

到目前为止,我依靠OpenGL来确定声明的uniform sampler2Darray txa采样器是指我绑定了glBindTexture的纹理数组。

glTexImage3D(GL_TEXTURE_2D_ARRAY, 0,  GL_RGBA8, width, height,
             layerCount,  0 GL_RGBA, GL_UNSIGNED_BYTE, texture_array);
...
glGenTextures(1,&texture_ID);
glBindTexture(GL_TEXTURE_2D_ARRAY, texture_ID); 
... 
                               //fragment shader
uniform sampler2Darray txa
...
vec2 tc;
tc.x = (1.0f - tex_coord.x) * tex_quad[0] + tex_coord.x * tex_quad[1];
tc.y = (1.0f - tex_coord.y) * tex_quad[2] + tex_coord.y * tex_quad[3];
vec4 sampled_color = texture(txa, vec3(tc, tex_id));

我尝试在片段着色器中指定两个采样器,但是片段着色器出现编译错误:

uniform sampler2DArray txa;
uniform sampler2DArray txa2;
...
vec4 texture = texture(txa, vec3(tc, tex_id));
vec4 texture2 = texture(txa2, vec3(tc2, tex_id));

我没想到这会起作用,但是,我不确定片段着色器编译器是否检查采样器是否分配了纹理,所以也许其他地方有问题。

我尝试生成并绑定采样器对象,但仍然出现片段着色器错误:

GLuint sampler_IDs[2];
glGenSamplers(2,sampler_IDs);
glBindSampler(texture_ID, sampler_IDs[0]);
glBindSampler(texture_ID, sampler_IDs[1]);

我想坚持使用较低版本的OpenGL,可以吗?感谢您的帮助,谢谢!

opengl textures fragment-shader
1个回答
1
投票

vec4 texture = texture(txa, vec3(tc, tex_id));

然后,变量texture的名称等于内置函数texture的名称。
重命名变量以解决问题。例如:

texture

© www.soinside.com 2019 - 2024. All rights reserved.