Hi,
I’m having some problems using the Image Load Store EXT. What I’m trying to do is very simple, its just clear the texels of a texture using imageStore, but when I check the texture values back in opengl, the values haven’t changed at all.
I’ll post the revelant part of the code:
//create a pointer to texture data, and initialize all texels with 5000.
_bufferCounter = new cBufferType[_fboHeight*_fboWidth];
for (int i=0; i<_fboHeight*_fboWidth; ++i) { _bufferCounter[i] = (cBufferType)5000;}
The cBufferType is type unsigned int. (I tried with some other types too, like float).
//gen a texture and bind it in a image unit
glGenTextures(1, &_textureId2);
glBindTexture(GL_TEXTURE_2D, _textureId2);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_R32UI, _fboWidth, _fboHeight, 0, GL_RED, GL_UNSIGNED_INT, _bufferCounter);
glBindImageTextureEXT(0, _textureId2, 0, GL_FALSE, 0, GL_READ_WRITE, GL_R32UI);
glBindTexture(GL_TEXTURE_2D, 0);
Tried some others combination here too (like GL_R32F, with GL_FLOAT), but is the same.
after bind the texture I send it to the shader in display func.
//display Func...
glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, _textureId2);
//Pass counter buff texture to shader
glProgramUniform1iEXT(_shaderProgram, glGetUniformLocation(_shaderProgram, "counterBuff"), 0);
glUseProgram(_shaderProgram);
glClearColor(0.f, 0.f, 0.f, 0.f);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
// draw to fbo color buffer
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
glColor4us(10,10,10,10);
glBegin(GL_QUADS);
glVertex2f(0.0f, 0.0f);
glVertex2f(1.0f, 0.0f);
glVertex2f(1.0f, 1.0f);
glVertex2f(0.0f, 1.0f);
glEnd();
Now the fragment Shader:
//-- FRAGMENT SHADER
#version 400
//-- enable opengl extentions
#extension GL_NV_gpu_shader5 : enable
#extension GL_EXT_shader_image_load_store : enable
//-- Whole number pixel offsets
layout(pixel_center_integer) in vec4 gl_FragCoord;
//-- fragment counter texture
coherent uniform layout(size1x32) uimage2D counterBuff;
void main(void){
//-- get coords
ivec2 coords = ivec2(gl_FragCoord.xy);
if(coords.x>=0 && coords.y>=0 && coords.x<512 && coords.y<512 ){
//clear texture
imageStore(counterBuff, coords, ivec4(0));
}
//-- nothing is written to the framebuffer
discard;
}
But when I read the texture back in OpenGL (The _bufferCounter), the values haven’t changed at all (still all 5000).
Not 0 as I expected.
I’m doing something wrong or missing something?
Thanks in advance.