到目前为止,我依靠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,可以吗?感谢您的帮助,谢谢!
vec4 texture = texture(txa, vec3(tc, tex_id));
然后,变量texture
的名称等于内置函数texture
的名称。重命名变量以解决问题。例如:
texture