I’m working on implementing a single pass depth-peeling algorithm by using atomic textures in OpenGL 4.2. I wrote the following fragment program:
#version 420 core
layout(r32i) coherent uniform iimage2D img2D_0;
uniform iimage2D img2D_1;
in vec3 pos;
vec4 insert(vec4 data, float new_data) {
if (new_data<data.x) return vec4( new_data,data.xyz);
else if (new_data<data.y) return vec4(data.x,new_data,data.yz);
else if (new_data<data.z) return vec4(data.xy,new_data,data.z);
else if (new_data<data.w) return vec4(data.xyz,new_data );
else return data;
}
void main() {
ivec2 coord = ivec2(gl_FragCoord.xy);
while (imageAtomicCompSwap(img2D_0,coord,0,1)==1);
vec4 depths = imageLoad(img2D_1,coord);
depths = insert(depths,gl_FragCoord.z);
imageStore(img2D_1,coord,depths);
memoryBarrier();
imageAtomicExchange(img2D_0,coord,0);
}
However, I get the following errors:
Fragment info
-------------
0(15) : error C1115: unable to find compatible overloaded function "imageLoad(struct iimage2D, ivec2)"
0(17) : error C1115: unable to find compatible overloaded function "imageStore(struct iimage2D, ivec2, vec4)
I note that I am using #version 420 in the shader, and I checked the functions’ declarations in the documentation (imageLoad, imageStore) and they seem to match. Curiously, imageAtomicCompSwap, memoryBarrier, and imageAtomicExchange seem to be defined. Why could these errors occur?
This is not a valid image definition. You must use
layout()to define its image format, unless you have declared itwriteonly. It should have errored out on this line, but it interpreted it as some kind of struct definition. So it errored out later when you tried to use it.