Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

edwinnie

pixel buffer object

This topic is 5273 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hihi! i was wondering if pixel buffer object can be used to "render a texture to a vertex array". thx! Edwinz

Share this post


Link to post
Share on other sites
Advertisement

Well, you render your future vertex data into the framebuffer or a pbuffer. You create a generic buffer object, and bind it to a PIXEL_PACK_BUFFER target. Then you use glReadPixels() to copy the framebuffer or pbuffer contents to the buffer object (local on card copy, nothing is transfered over the AGP bus).

Now that your vertex data is in the buffer, you need to tell the driver that you''d like to access it as vertex data. To do so, you simply bind the buffer object (the same you bound to the PBO in the first step) to an ARRAY_BUFFER target, set the vertex array pointers as usual with VBO, and draw it.

There is an example code snippet at the end of the PBO extension spec.

Share this post


Link to post
Share on other sites
hihi Yann!
thx fer replying.

EDIT:
Must we always use the offscreen framebuffer (consequently we would always use glReadPixels)?

It is possible to do a render to texture instead, then bind that texture and re-render it to a vertex array?

thx!
Edwinz

[edited by - edwinnie on June 7, 2004 9:29:05 PM]

Share this post


Link to post
Share on other sites
If i am not wrong, uber-buffers should do that.
Dont know if those are available for public yet tho.

Alex



Share this post


Link to post
Share on other sites
hi ababkin!
thx fer replying!

unfortunately, i couldnt even get it to work even for the most simplest case which i followed from the pbo specs, perhaps i try to explain the procedure and hopefully anyone out there be kind enuff to spot any discrepanies.

Currently, my pbuffer works fine for both render-to-texture and readpixels. So, at the moment i jus want to inspect the buffer object, and see if the pixels got written into it by using the pixel buffer object, which i am having some problems...

//pseudo code(non optimised)
//INITIALISATION

//create a pixel buffer object

UINT bufferID;
glGenBuffersARB(1, &bufferID);
glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, bufferID);
glBufferDataARB(GL_PIXEL_PACK_BUFFER_EXT, 4 * sizeof(float) * 256, 0, GL_DYNAMIC_DRAW/*GL_STREAM_COPY*/);


//RENDER
2)activate pbuffer

3)bind vertex & fragment programs, enable Cg profile,enable gl drawing states, set to draw to offscreen back buffer

4)bind render target, draw render target (a quad of 4 vertices)

5)unbind vertex & fragment programs, cancel binding of current vertex buffer objects, disable gl states, disable Cg profile

6)at this point, the Image Debugger shows the correct render target results if i do not do any "render to vertex array"

//TIME to render to vertex array
7)not too sure if these pseudocode is correct

glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, bufferID);
glReadPixels(0, 0, 16, 16, GL_RGBA, GL_FLOAT, BUFFER_OFFSET(0));
glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, 0);

glBindBufferARB(GL_ARRAY_BUFFER_ARB, bufferID);
glEnableClientState(GL_VERTEX_ARRAY);

glVertexPointer(4, GL_FLOAT, 0, BUFFER_OFFSET(0));
glDrawArrays(type, 0, 256);

glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
glDisableClientState(GL_VERTEX_ARRAY);


EDIT:
funny thing is that:
1)breakpoints will screw up the debugging process

2)somehow i plug in the first render target jus to rasterise and check if the 2nd vertex & fragment programs were being used, they were.
(the checking was done by forcing the 2nd fragment program to output white color)

However, if the 2nd render target was used, the image debugger shows the result of 1st render target, which kinda made me think that the pixel buffer object wasnt "filled", and so no vertices were being input into the 2nd vertex program... darn!

3)juz wondering as well --> rather than using glReadPixels, how can we integrate render-to-texture and use the texture instead?

hopefully someone will be kind enuff to share how u did it...

thx!
Edwinz

[edited by - edwinnie on June 8, 2004 3:05:41 AM]

[edited by - edwinnie on June 8, 2004 7:15:04 AM]

[edited by - edwinnie on June 8, 2004 7:16:36 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by ababkin
If i am not wrong, uber-buffers should do that.
Dont know if those are available for public yet tho.



They are ALONG way off right now, the spec hasnt even been finished yet..

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!