我正在尝试将两个纹理绑定到我的computeshader。
关于我的纹理:
GLuint texOne;
glGenTextures(1, &texOne);
//glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, texOne);
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, w,h);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, bytes.data());
两个纹理都以这种方式初始化。
我的着色器看起来像这样:
#version 430 core
#extension GL_ARB_explicit_uniform_location : enable
#extension GL_ARB_separate_shader_objects : enable
layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout (location = 0, rgba8) uniform image2D imageSrc;
layout (location = 1, rgba8) uniform image2D imageDst;
void main()
{
vec4 imageData = imageLoad(imageSrc, ivec2(gl_GlobalInvocationID.xy));
imageStore(imageDst, ivec2(gl_GlobalInvocationID.xy), imageData);
}
我还尝试以以下样式将其他值存储到imageDst纹理中:vec4(0,1,1,1) 绑定以某种方式只能看到imageSrc而不是imageDst。仅使用一种纹理时,一切正常。
将纹理绑定到着色器
GLuint texOne;
glGenTextures(1, &texOne);
//glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, texOne);
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, w,h);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, bytes.data());
GLuint texTwo;
glGenTextures(1, &texTwo);
//glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, texTwo);
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, w,h);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
//bind textures
glBindImageTexture(0, texOne, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA8);
glBindImageTexture(1, texTwo, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA8);
//compute
glMemoryBarrier(GL_ALL_BARRIER_BITS);
glDispatchCompute(w,h,1);
glMemoryBarrier(GL_ALL_BARRIER_BITS);
我认为错误至少在glBindImageTexture行上某处... 该命令如何工作?
第一个参数是布局(位置)吗? 第二个参数是我的textureId吗?
提前谢谢