PDA

View Full Version : 32 bit value with glCopyTexSubImage2D



jos_t_tarigan
01-14-2011, 03:14 PM
hi,

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

ZbuffeR
01-14-2011, 03:34 PM
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.

kRogue
01-25-2011, 04:31 AM
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:

Init:


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

//Create Framebuffer object:
glGenFramebuffers

//bind to manipulate it:
glBindFramebuffer

//attach your texture:
glFramebufferTexture

//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:



glBindFramebuffer(fbo);
render_to_texture_commands();

glBindFramebuffer(0);
//now your texture holds the results of the above rendering.
render_to_screen_commands();