Speed difference between single-buffer and double buffer mode?

Hi,
i found that the speed of single-buffer mode is more slower than double-buffer mode in my app,is anyway to improve the speed of single-buffer mode?

single-buffer mode : Render the scene to bitmap,then draw the result bitmap to window by GDI or GDI+;
double-buffer mode : Render the scene to window directly ,using SwapBuffers() function.

i found the single-buffer mode cost 10 times time than double-buffer mode while doing the same rendering work!

help,thanks.

captain wens

Rendering to a bitmap uses the Microsoft software rendering, whereas double buffered rendering uses the available hardware and will be considerably faster.

What problem are you trying to solve? There may be a better solution which allows hardware acceleration. For example, if your goal is to render to a texture, you can achieve this with the EXT_framebuffer_object extension.

Thanks.
my problem is that, i 've a lot huge data to be render(maybe more than 10000000 triangles and quads and other complex objects), and the rendering process of render the whole data will be a time-costing task, so i want to render the data block by block( each block have 10000 obejcts.etc.),once each block finished rendering, then draw the result to window , so that users can see the dynamic rendering process without wasting time for waiting. it ’ s so called “step by step rendering”.
if i use the double buffer mode , swapbuffers function, the window will be flickering violently , it 's unacceptable. the reason of flickering is that i send render commands to opengl after swapbuffer command as following code,

draw a block.....
swapbuffers;
            draw another block....
swapbuffers;
.....

if i use single buffer mode, the speed will be slowly. code as follow,

draw a block....
draw the result bitmap to window;
draw another block....
draw the result bitmap to window;

help,thanks

Captain wens

For the swap buffers method to work you must have selected a pixelformat which is copying the back buffer to the front buffer.
Check the PIXELFORMATDESCRIPTOR flags for PFD_SWAP_COPY manually.
You could of course just switch glDrawBuffer(GL_FRONT) and render to the front buffer with OpenGL directly without swapping.
You could issue a glFlush after each object to start the rendering. You must do this at the very end of front buffered rendering or some data might not be drawn (still buffered in the OpenGL command queue).

I agree, if your goal is to show progress while rendering, just request a single buffered window, or render to the front buffer. Too many flushes will slow down the rendering, but if you flush a few times per second you can show interactive rendering without thrashing.

Double buffered rendering is for smooth animation, or anytime you don’t want the user to see a partial frame. If your goal is to show a partial frame, double buffering works against you. :slight_smile:

If you do want to render to the backbuffer, you can always perform periodic blits from the backbuffer to the frontbuffer:

    ReadBuffer(BACK);
    DrawBuffer(FRONT);
    CopyPixels()

This will work regardless of the window’s swap semantics (flip vs blit).

Thanks,

i tried the way you metioned above but the windows is still flickering.
the point is that,the data is so huge that i can not render them all within a short time(rendering time for all data is about 900 ms), so i used quadering-tree struct to store and query data , once a node of quadering-tree finished rendering,draw the result to window(use swapbuffers() function or drawbuffer() function), just like the famous GoogleEarth,users can see the dynamic rendering process.
the problem of window flickering had disturbed me for so long time,help.
thanks.

captain wens

If you did exactly what was proposed this must not flicker.
You don’t call clear more than once, right?
You’re calling a WM_PAINT message handler to do the SwapBuffers?
Important: Make sure you have a WM_ERASEBKGND message handler which does nothing except return 1. This will keep the Windows GDI from automatically clearing your window with the window’s workspace color.
After that all rendering should be done by your OpenGL calls and the should be absolutely no flickering.
It will flicker if the pixelformat is using a swap exchange method for the SwapBuffers.
Check the dwFlags in your PIXELFORMATDESCRIPTOR after having called DescribePixelFormat().
Select one which has PFD_SWAP_COPY set or use the glCopyPixels method mentioned above instead.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.