I’m having problems getting the NV_texture_barrier extension working on my ATI Radeon HD 5570 (Catalyst 10.12, Win7x64). I tried to do the following:
- Create an FBO and bind it to a 2D integer texture rectangle whose contents have been randomly generated.
GLuint texture,fbo;
glGenFramebuffers(1,&fbo);
glBindFramebuffer(GL_FRAMEBUFFER,fbo);
glGenTextures(1,&texture);
unsigned short data[512*512] = {0};
for (int i=0;i<512*512;i++){
data[i] = rand();
data[i] = (rand()%2)<<15 + data[i];
}
glTextureImage2DEXT(texture,GL_TEXTURE_RECTANGLE,0,GL_R16UI,512,512,0,GL_RED_INTEGER,GL_UNSIGNED_SHORT,data);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE, texture, 0);
2)Proceed to render a colored rectangle to the FBO, but attempt to read the contents of the fbo/rendertarget and make changes to the final color. The fragment shader that I use looks like this:
#version 330
in vec4 fcolor;
out uint FragColor;
uniform usampler2DRect rt_texture;
uint ConvertFloat4ToR16(const in vec4 color)
{
ivec4 bias = ivec4(color * 31.0f);
uint r = (bias.b<<10)|(bias.g<<5)|(bias.r);
return r;
}
void main()
{
uint srccol = ConvertFloat4ToR16(fcolor);
uint destcol = texelFetch( rt_texture, ivec2(gl_FragCoord.xy)).r;
FragColor = destcol+srccol;
}
According to the specification of NV_texture_barrier, texelFetch2DRect could be used, but I get the following shader compiler errors:
ERROR: 0:14: error(#202) No matching overloaded function found texelFetch2DRect
ERROR: 0:14: error(#160) Cannot convert from ‘const float’ to ‘unsigned int’
thus, I use texelFetch instead. However, destcol is always zero when I test its value. Am I misunderstanding the texture barrier spec or is this simply a bug in ATI’s implementation?