Hi! I use a texture bound to an image and I create the texture like this :
glCheck(glGenTextures(1, &frameBufferTex));
glCheck(glBindTexture(GL_TEXTURE_2D, frameBufferTex));
glCheck(glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA32F, window.getView().getSize().x, window.getView().getSize().y));
glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
glCheck(glBindImageTexture(0, frameBufferTex, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32F));
glCheck(glBindTexture(GL_TEXTURE_2D, 0));
I clear the texture with a pixel buffer before drawing to it :
glCheck(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, clearBuf));
glCheck(glBindTexture(GL_TEXTURE_2D, frameBufferTex));
glCheck(glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, view.getSize().x, view.getSize().y, GL_RGBA,
GL_FLOAT, NULL));
glCheck(glBindTexture(GL_TEXTURE_2D, 0));
glCheck(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0));
The problem is when I want to write to the image in the shader, all the pixels of the texture are in the same colour, by example here, when I want to write the pixel at location (0,0) to red, all the texture is red.
imageStore(img_output, ivec2(0, 0), vec4(1, 0, 0, 1);
This is really strange I tried to change the pixel buffer to clearing the texture with different colours but same problem all pixels of the texture are white :
std::vector<GLfloat> texClearBuf(window.getView().getSize().x*window.getView().getSize().y*4, 0);
for (unsigned int i = 0; i < 100; i++) {
for (unsigned int j = 0; j < 100; j++) {
texClearBuf[j*window.getView().getSize().x+i*4] = 1.f;
texClearBuf[j*window.getView().getSize().x+i*4+1] = 1.f;
texClearBuf[j*window.getView().getSize().x+i*4+2] = 1.f;
texClearBuf[j*window.getView().getSize().x+i*4+3] = 1.f;
}
}
glCheck(glGenBuffers(1, &clearBuf));
glCheck(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, clearBuf));
glCheck(glBufferData(GL_PIXEL_UNPACK_BUFFER, texClearBuf.size() * sizeof(GLfloat),
&texClearBuf[0], GL_STATIC_COPY));
glCheck(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0));
Why all the pixels of the texture have the same colour and not only the pixels at the position I want ?
Thanks.