Using a framebuffer as a vertex buffer without moving data to the CPU

Is there a way in OpenGL to use framebuffer data as vertex data without moving data through the CPU? Ideally, a framebuffer object can be processed as a vertex buffer object directly on the GPU. I would like to use a fragment shader to generate a mesh, and then render this mesh.

+6
opengl
source share
4 answers

Here are some ways you could decide the first one was already mentioned by spudd86 (except that you need to use GL_PIXEL_PACK_BUFFER , the one that was written with glReadPixels ).

Another is to use the framebuffer object and then read its texture in your vertex shader, matching it with the vertex identifier (which you must control) to the texture location. If this is a one-time operation, although I would go copying it to PBO, then GL_ARRAY_BUFFER to GL_ARRAY_BUFFER and then just use it as a VBO.

+3
source share

Just use the functions to make a copy, and let the driver understand how to do what you want, it is likely that as long as you copy directly to the vertex buffer, in fact, it will not make a copy, but simply make your VBO data reference.

The main thing to be careful is that some drivers may not like your use of what you said was vertex data with an operation for pixel data ...

Edit: maybe something like the following may or may not work ... (IIRC spec says it should)

 int vbo; glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, vbo); // use appropriate pixel formats and size glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, 0); glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0); glEnableClientState(GL_VERTEX_ARRAY); glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo); // draw stuff 

Edited to correct buffer bindings thanks to Phineas

+3
source share

The GL_pixel_buffer_object specification provides an example that demonstrates how to render an array of vertices in the Usage Examples section.

The following extensions are useful for solving this problem:

GL_texture_float - internal floating point formats for use in the color buffer application GL_color_buffer_float - disable automatic clip for fragment colors and glReadPixels GL_pixel_buffer_object - operations of transferring pixel data to buffer objects

+1
source share

If you can do your work in the vertex / geometry shader, you can use the conversion feedback to write directly to the buffer object. It also allows skipping rasterizer and shading fragments.

Conversion feedback is available as EXT_transform_feedback or the basic version with GL 3.0 (and the ARB equivalent).

+1
source share

All Articles