Hi,
I recently implemented a simple algorithm that uses the function imageAtomicAdd from the image_load_store extension. However, when I retrieve the image values from the GPU, the values are far from what I expected.
This is how I create my texture:
glActiveTexture(GL_TEXTURE0);
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_R32UI, width, height, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, 0);
glBindTexture(GL_TEXTURE_2D, 0);
Then I bind the image:
glUniform1i(m_loc_countfragments_imgtable, 1);
glActiveTexture(GL_TEXTURE0 + 1);
glBindImageTexture(1, tex, 0, false, 0, GL_READ_WRITE, GL_R32UI);
I use the following simple fragment shader to render my scene:
//[FRAGMENT SHADER]
#version 420
#extension GL_ARB_shader_image_load_store : enable
uniform volatile layout(r32ui) uimage2D img;
void main()
{
imageAtomicAdd(img, ivec2(0, 0), 1);
}
I then retrieve my texture:
m_uibuffer = new GLuint[800*800];
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, m_img_fragtable);
glGetTexImage(GL_TEXTURE_2D, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, m_uibuffer);
glBindTexture(GL_TEXTURE_2D, 0);
glPopAttrib();
I expected my array to be filled with zeroes, except for one position (0,0), that was suppose to contain a number grater than zero. Instead, I got an array with strange values, ranging from 0 to 100000000. Am I doing something wrong here? Am I suppose to bind my image or my texture when I call glGetTexImage?
thank you