Hello.
I've recently been attempting to render 3D textures in a compute shader for an upcoming project of mine. However, I have met an unexpected issue I cannot solve. No matter what I tried the texture was not written to. In order to ascertain what is causing the defect I set up a simple test case consisting of an all red 16x16 texture being created on a compute shader and then rendered to the screen using a full-screen quad. Yet the issue persists. I'm not too sure where to go next. I've tried substituting glTexImage2D(...) with glTexStorage2D(...) to no avail. I am at a loss here so any help would be very much appreciated.
Relevant Code:
compute shader:
#version 450 core
layout(local_size_x = 1, local_size_y = 1) in;
layout(rgba32f) uniform image2D destination;
void main(void)
{
ivec2 index = ivec2(gl_GlobalInvocationID.xy);
imageStore(destination, index, vec4(1.0f, 0.0f, 0.0f, 1.0f));
}
compute shader dispatch method:
void draw_texture(GLuint *texture_handle, GLuint draw_program)
{
GLuint tex;
glGenTextures(1, &tex);
glActiveTexture(GL_TEXTURE0 + 0);
glBindTexture(GL_TEXTURE_2D, tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 16, 16, 0, GL_RGBA, GL_FLOAT, NULL);
glUseProgram(draw_program);
glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
GLuint uniform_location = glGetUniformLocation(draw_program, "destination");
glBindImageTexture(uniform_location, tex, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA32F);
glDispatchCompute(16, 16, 1);
glUseProgram(0);
glBindTexture(0);
*texture_handle = tex;
} Thanks for your time!