Jump to content
  • Advertisement
Sign in to follow this  
fsforall

OpenGL FBO-Problem

This topic is 4061 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

Hello, here is an updated to my previous post. Let me explain again what I have to do. I have a game which creates a bitmap in RAM. I need to draw with OpenGL on it. I can draw with PFD_DRAW_TO_BITMAP, but it is way too slow. That is why I need to create a FBO and then render to it. Since I can not create a FBO on the bitmap because OpenGL is initialised in software mode, so without extensions, I create a hidden window and initialise the FBO in there. I make the context of the window current, I then render to the FBO, I make the bitmap context current (software only, unfortunately) and then I draw the FBO as a texture in there using a quad. I do not use a depth buffer, just a simple FBO with only one bitmap, no mipmaps. This results in the quad being all white. However, the code works perfectly. If I do not make the context of the bitmap current, I draw on the window (which I can unhide) and the exact same code works perfectly, but it just fails on the bitmap. Is this a limitation ? Can somebody please help me ? Thank you very much in advance. Here is the code : //Start wglMakeCurrent(hDC,hRC); //Make current the window where the pbuffer is created glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); glPushAttrib(GL_VIEWPORT_BIT); glViewport(0,0,width,height); glClearColor(0.0f, 0.0f, 0.0f, 0.5f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer glLoadIdentity(); /////////// //Draw Something /////////// glPopAttrib(); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); aa = wglMakeCurrent(hdc,hrcb);//Make current the bitmap where we want this to be drawn glClearColor(0.0f, 0.0f, 0.2f, 0.5f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer glLoadIdentity(); glBindTexture(GL_TEXTURE_2D, img); glEnable(GL_TEXTURE_2D); glTranslatef(0.0f,0.0f,-2.0f); glColor4f(1.0f,1.0f,1.0f,1.0f); ////// //Draw a quad with the texture data, as described above ////// glDisable(GL_TEXTURE_2D); glFlush(); //END

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by fsforall
I make the context of the window current, I then render to the FBO, I make the bitmap context current (software only, unfortunately) and then I draw the FBO as a texture in there using a quad.
This doesn't work because the textures (and other OpenGL objects) are specific to the context they were created in. You can use wglShareLists to share the display list space (includes all OpenGL objects, not just display lists) between one or more contexts, however in this case I'm pretty sure you won't be able to do that because of the following line from the Remarks section...
Quote:
Rendering contexts can share display lists only if they use the same implementation of OpenGL functions.
... and one of your contexts uses your graphics driver's implementation while the other uses Microsoft's.

Unfortunately, I don't think you'll be able to do any better than manually reading the data from the FBO and copying it to the bitmap. But hey, I've been wrong before! [grin]

Share this post


Link to post
Share on other sites
Kalidor,

Thank you for your reply. Unless there is somebody else that can point to a solution, the only alternative is to read the FBO pixel by pixel.

I know and I can use the function glReadPixels without a problem, but it is way too slow for what I am trying to do. For a 512*512 bitmap, it takes about 12ms, which is way too much.

Is there any alternative to get the pixel data from a FBO ? Are there any faster functions ?

Thank you in advance.

Share this post


Link to post
Share on other sites
Quote:
Original post by fsforall
Kalidor,

Thank you for your reply. Unless there is somebody else that can point to a solution, the only alternative is to read the FBO pixel by pixel.

I know and I can use the function glReadPixels without a problem, but it is way too slow for what I am trying to do. For a 512*512 bitmap, it takes about 12ms, which is way too much.

Is there any alternative to get the pixel data from a FBO ? Are there any faster functions ?

Thank you in advance.
Reading the data from the FBO pixel by pixel will be much worse than reading the entire thing in one glReadPixels call. You may be able to use the GL_ARB_pixel_buffer_object (PBO) extension to speed it up a bit however, if your card supports it.

For your purposes it is essentially an asynchronous glReadPixels. So instead of the pipeline stall usually involved with glReadPixels and then having to wait for the data to actually be returned before your application continues, you issue one (or more) glReadPixels commands and then continue on doing something else with your application, then when the transfer is finished you copy it over to the bitmap. Speed-ups from this depend on what else you're doing in your app (ie: if you issue the async glReadPixels then immediately try to use the results it doesn't gain you anything).

If you can live with the image in your bitmap being a frame or two behind what's in the FBO you can probably get a decent speed-up with multiple PBOs. The idea here is do your rendering as usual, then issue an async read with one PBO, then continue onto rendering the next frame, then do another async read with a second PBO, then get the results from the first PBO and send that to your bitmap, then continue onto the next frame, etc. You can buffer that even more if you use more PBOs and wait more frames before sending the results to the bitmap.

For more information check out Fast Texture Transfers.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!