0
\$\begingroup\$

I am trying to render to an unsigned integer texture, with a blending function enable, so that in the end, the value in each texel will be the number of objects rendered on the texel. So I assume I cannot use normalized integers.

For example, if I have a 2x2 texture, and I render [ (0,0) (0,0) (0,1) (1,0) ], the texture result should be, [ 2 1 ; 1 0 ].

I am trying to set up the frameBuffer, but the call to glTexImage2D, causes the GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT when I use the formats I assume I need.

// this works
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1024, 768, 0, GL_RGB, GL_UNSIGNED_INT, 0);

// this causes GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
glTexImage2D(GL_TEXTURE_2D, 
             0, 
             GL_RGB32UI, 
             width, 
             height, 
             0, 
             GL_RGB_INTEGER, 
             GL_UNSIGNED_INT, 
             0 );

Is what I want to do even possible? If so, which settings do I need to use to accomplish this?

\$\endgroup\$
1
\$\begingroup\$

GL_RGB32UI <- Is this right? Each texel value is 4 32bit integers? The last time I did this and wrote a single 32bit integer to a texture, I used GL_R32I and GL_RED_INTEGER.

I've never had that error before but it seems reasonable if you're texture isn't big enough.

\$\endgroup\$
0
\$\begingroup\$

I was not able to get additive blending working with an integer buffer, however I did get it working with a single channel 32 bit float. I got the effect I was going for by outputting 1 / 2^30 in fragment the shader, with glBlendFunc( GL_ONE, GL_ONE ), then multiplying by 2^30 after reading back the pixels.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.