我正在尝试使用计算着色器将纹理的颜色更改为黑色,但它不起作用,我找不到原因。着色器编译没有问题,也没有程序链接,所以我认为问题在于着色器的更新。这是我的代码:
更新:
glUseProgram(m_programID);
int location = glGetUniformLocation(m_programID, "img_out");
glUniform1i(location, 0);
glBindImageTexture(0, texID, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA32F);
glDispatchCompute(1024, 1024, 1);
glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
int format;
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &format);
unsigned char* img = new unsigned char[1024 * 1024 * 4];
glGetTexImage(GL_TEXTURE_2D, 0, format, GL_UNSIGNED_BYTE, img);
int i = SOIL_save_image("img.bmp", SOIL_SAVE_TYPE_BMP, 1024, 1024, 4, img);
std::cout << SOIL_last_result() << std::endl;
delete[] img;
glUseProgram(0);
着色器:
#version 450 core
layout(local_size_x = 1, local_size_y = 1) in;
layout(binding = 0, RGBA32F) uniform image2D img_out;
void main()
{
ivec2 pos = ivec2(gl_GlobalInvocationID.xy);
imageStore(img_out, pos, vec4(0.f, 0.f, 0.f, 1.f));
}
ps:这里使用的纹理是一个装满土壤的图像,但这有关系吗?