Fast blit using GDI and PBO

Started by
5 comments, last by AndyEsser 14 years, 8 months ago
This seems like the most appropriate place to ask this question, though it involved two different APIs, OpenGL and Windows GDI. I'm attempting to improve speed in a custom operation that I'm doing. The speed of my implementation is fast, but at the resolution it's a bit too slow. Using a unseen OpenGL context to render my scene, reading back the data with glReadPixels into a DIB, then using that to BitBlt to a window. - Render scene - glReadPixels into DIB data - BitBlit into window For a 2560x1600 size the glReadPixels takes about 33ms and the BitBlit takes 3-4ms. I did some research and learned that PBO might be able to speed up my operation. I tested the speed and the actual readback was about 10ms faster, but the problem is that the PBO puts the data into it's own memory location. I can copy the data from here to the DIB, but then I loose the speed up I just gained. I would copy the PBO data directly to the window, but the GDI does not seem to give a good function to do so. So here are some specific questions I have to anyone who might know. - Is there a way to have a PBO map into my own allocated memory? I assume not. - Is there a better way to blit the data to the window? - Is there a way to directly change the bits pointer of a DIB bitmap? Is so this might also solve the issue, as I can intelligently change them around.
Advertisement
Why not use OpenGL to render direct into the Window?
Setup a child window and use opengl on that like you would making any other opengl application. Check out frame buffer objects, I beleive they do rpetty much the same thing just faster.

Interested in Fractals? Check out my App, Fractal Scout, free on the Google Play store.

Note that you can have OpenGL render to anything with an HWND. This includes Pictureboxes and many other Windows Controls.
Quote:Original post by AndyEsser
Why not use OpenGL to render direct into the Window?


Good question. I wish that were possible for my situation, as it would make things much simpler. I will be happy to explain.

- The offscreen OpenGL context is being used for rendering different scenes to multiple windows. This is a requirement of the application.

- Some Non-OpenGL windows in the application are created with WS_EX_LAYERED. Which I was disturbed to find does not interact well with standard OpenGL windows. You get horrible flickering and incorrect layering of windows when the two touch each other.

Quote:Setup a child window and use opengl on that like you would making any other opengl application. Check out frame buffer objects, I beleive they do rpetty much the same thing just faster.


The child window idea wouldn't work for what I need. The issue is not embedding OpenGL in another window, but instead of transferring the data more efficiently.

Frame buffer objects allow you to render OpenGL to a offscreen buffer of memory on the GPU. I actually already use them in the application, but not for the purpose above. At the end of the day I still need to abstractly get the data from the GPU and into the CPU.

Quote:Note that you can have OpenGL render to anything with an HWND. This includes Pictureboxes and many other Windows Controls.


Maybe I'm confused on your response, though I'm unsure how that would help. Rendering to a window is not an issue. There are several reasons I'm unable to use the standard WGL implementation.
Quote:Original post by KiroNeem
- Is there a way to have a PBO map into my own allocated memory? I assume not.


No, but you can create the buffer, glBufferData it with a NULL pointer (which creates the GPU side backing store), write the data to the buffer using glReadPixels, and then map the buffer (glMapBuffer) which will give you a pointer to give to GDI to draw to the window. That's only 1 data copy.

Thanks for responding to my questions.

Just a thought. You can create a memory DC and have OpenGL render into that (which would effectively render into RAM), and then read the contents.

Not sure if that would work at all, but would avoid any copies.

This topic is closed to new replies.

Advertisement