Compute shader does not change texture

I am currently trying to change the color of the texture to black using a compute shader, but it is not working and I cannot find why. There is no problem with compiling the shaders, nor with the program binding, so I think the problem is with the shader update. Here's my code:

Update:

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);

      

Shader:

#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: The texture used here is an image loaded with soil, but does it matter?

+3


source to share





All Articles