Hi everybody.
I’m currently studing CG and I run into some weird OpenGL behaviour when using image_load_store functionalities.
In my test application I render a sphere using a shader that writes its outputs to four different locations:
- three different image2D (using imageStore);
- one texture2D that is attached to a color chanel of a framebuffer.
Here is the result of this setup ( Figure 1 ).
Everything goes fine with this setup, but when I try to NOT WRITE to the texture2D, I get unexpected results ( Figure 2 ).
The unexpeted result is that besides the texture2D not being writen, the imageStore operations appear to have no effect over the three image2D variables.
NOTE: In order to “try to NOT WRITE to the texture2D” I removed the line “gl_FragColor = vec4(1, 1, 1, 1);” from the shader and set “glDrawBuffer(GL_NONE);”.
After several tests I though: What if I masked the the “gl_FragColor = vec4(1, 1, 1, 1);” with a “discard;” command? I tried and it worked ( Figure 3 ).
Follows the Fragment Shader code that resulted from this test.
#version 420 core
layout(rgba8) coherent uniform image2D myImageA;
layout(rgba8) coherent uniform image2D myImageB;
layout(rgba8) coherent uniform image2D myImageC;
in vec4 gl_FragCoord;
out vec4 gl_FragColor;
void main()
{
// coordinates of this pixel
ivec2 coord = ivec2(gl_FragCoord.xy);
imageStore(myImageA, coord, vec4(0,1,0,1));
imageStore(myImageB, coord, vec4(0,0,1,1));
imageStore(myImageC, coord, vec4(1,0,0,1));
// used for debug
discard;
gl_FragColor = vec4(1, 1, 1, 1);
}
Although the code is providing the result I want, I still don’t know what dark-wizardry is behind all this unexpected (at least for me) behaviour.
I hope someone could shed some light over this subject.
I’m using an AMD 5470 Mobile with Catalyst 11.12.
Thanks in advance.