glFlush
glFlush
glFlush()是OpenGL中的函數,用於強制刷新緩衝,保證繪圖命令將被執行,而不是存儲在緩衝區中等待其他的OpenGL命令。
簡單地說glFlush()就是強制刷新,OpenGL是使用一條渲染管線線性處理命令的,一般情況下,我們提交給OpenGL的指令並不是馬上送到驅動程序里執行的,而是放到一個緩衝區裡面,等這個緩衝區滿了再一次過發到驅動程序里執行;很多時候只有幾條指令是填充不滿那個緩衝區的,就是說這些指令根本沒有被發送到驅動里,所以我們要調用glFlush來強制把這些指令送到驅動里進行處理。
glFlush
The glFlush function forces execution of OpenGL functions in finite time.
void glFlush( void );
Parameters
This function has no parameters.
Remarks
Different OpenGL implementations buffer commands in several different locations, including network buffers and the graphics accelerator itself. The glFlush function Empties all these buffers, causing all issued commands to be executed as quickly as they are accepted by the actual rendering engine. Though this execution may not be completed in any particular time period, it does complete in a finite amount of time.
Because any OpenGL program might be executed over a network, or on an accelerator that buffers commands, be sure to call glFlush in any programs requiring that all of their previously issued commands have been completed. For example, call glFlush before waiting for user input that depends on the generated image.
The glFlush function can return at any time. It does not wait until the execution of all previously issued OpenGL functions is complete.
SwapBuffers
The SwapBuffers function exchanges the front and back buffers if the current pixel format for the window referenced by the specified device context includes a back buffer.
BOOL SwapBuffers(
HDC hdc // device context whose buffers get swapped
);
Parameters
Specifies a device context. If the current pixel format for the window referenced by this device context includes a back buffer, the function exchanges the front and back buffers.
Return Values
If the function succeeds, the return value is TRUE.
If the function fails, the return value is FALSE. To get extended error information, call GetLastError.
Remarks
If the current pixel format for the window referenced by the device context does not include a back buffer, this call has no effect and the content of the back buffer is undefined when the function returns.
With multithread applications, flush the drawing commands in any other threads drawing to the same window before calling SwapBuffers.