32 bit value with glCopyTexSubImage2D


im trying to do a two pass renderer. so the first pass, the shaders send the texture coordinate (u and v) and two other values. both represented by float value. the second pass will process the rest of the action, not that important.

now since the fist pass will pass the coordinate, i would like it to have more than an 8 bit value like in standard color value passed by shaders.

i already set my texture to be a 32 bit texture like this:

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, width, height, 0, GL_RGBA, GL_FLOAT, NULL);

and after the first pass, i save the buffer to texture by using this command:

glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, width, height);

now my question is is it possible to do that? how can I pass 4 32 bit value with RGBA and save it in a texture?

thanks in advance

You need to render the first pass to a floating point FBO (sorry can’t help for details on this).
Otherwise the values will be converted to 8bit, way before the copy.

To fill in more on what zbuffer wrote.

If you draw to the default framebuffer, then what is drawn is what the GLX (or WGL or whatever) you got from the config list. Typically, on desktop this is GL_GRBA8, 8bits per channel, fixed point valid values are in the range [0,1].

To render to a floating point texture you need to use FBO’s (which you should always use if you wish to save render data to a texture).

The basic setup is this:


//create texture:
glGenTextures, glBindTexture, 
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, width, height, 0, GL_RGBA, GL_FLOAT, NULL);

//Create Framebuffer object:

//bind to manipulate it:

//attach your texture:

//optionally (if you need depth and stencil buffers) attach
//depth/stencil texture of renderbuffer(s):
Renderbuffer commands: glGenRenderbuffers, glBindRenderbuffer, glRenderBufferStorage

If you need a depth and/or stencil buffer on the render to texture pass, I highly recommend that you use a packed depth stencil texture and attach that the the FBO.

render loop:


//now your texture holds the results of the above rendering.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.