I implemented a CPU code that copies the projected texture into a large texture onto a 3d object, a “baking decal” if you want, but now I need to implement it on the GPU. For this, I hope to use compute shader, since it is quite difficult to add FBO to my current setup.
Sample image from my current implementation
This question relates to the use of Compute shaders, but for everyone who is interested, the idea is based on the answer received from the user jozxyqk, here: https://stackoverflow.com/a/2129178/
The text that is written-in is in my code called _texture , and the projected one is _textureProj
Simple Computing Shader
const char *csSrc[] = { "#version 440\n", "layout (binding = 0, rgba32f) uniform image2D destTex;\ layout (local_size_x = 16, local_size_y = 16) in;\ void main() {\ ivec2 storePos = ivec2(gl_GlobalInvocationID.xy);\ imageStore(destTex, storePos, vec4(0.0,0.0,1.0,1.0));\ }" };
As you can see, I just want the texture to be updated to some arbitrary (blue) color.
Update function
void updateTex(){ glUseProgram(_computeShader); const GLint location = glGetUniformLocation(_computeShader, "destTex"); if (location == -1){ printf("Could not locate uniform location for texture in CS"); }
Problem If I call updateTex() outside my main program object, I see a null effect, whereas if I call it in my scope like this:
glUseProgram(_id);
Then after visualization, I see the following:

Question: I understand that setting the update method within the main area of the program object is not the right way to do this, however it is the only way to get any visual results. It seems to me that what happens is that it pretty much eliminates fragmentshader and draws screens ...
What can I do to make this work properly? (my main focus is being able to write texture and update something)
Please let me know if more code is required to publish.