【OpenGL】glFinish()和glFlush()函数详解-[转]
通常情况下,OpenGL指令不是立即执行的。它们首先被送到指令缓冲区,然后才被送到硬件执行。glFinish和glFlush都是强制将命令缓冲区的内容提交给硬件执行。
一、glFinish()函数
OenGL手册上关于glFinish:
Name
glFinish — block until all GL execution is complete
C Specification
void glFinish(void);
Description
glFinish does not return until the effects of all previously called GL commands are complete. Such effects include all changes to GL state, all changes to connection state, and all changes to the frame buffer contents.
Notes
glFinish requires a round trip to the server.
Errors
GL_INVALID_OPERATION is generated if glFinish is executed between the execution of glBegin and the corresponding execution of glEnd.
glFinish()将缓冲区的指令立即送往硬件执行,但是要一直等到硬件执行完这些指令之后才返回。
如果直接绘制到前缓冲,那么在你想保存屏幕截图之前,就需要调用这个函数,确保绘制完毕。
如果使用双缓冲,则这个函数不会有太大作用。
二、glFlush()
Name
glFlush — force execution of GL commands in finite time
C Specification
void glFlush();
Description
Different GL implementations buffer commands in several different locations, including network buffers and the graphics accelerator itself. glFlush empties all of 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 finite time.
Because any GL program might be executed over a network, or on an accelerator that buffers commands, all programs should call glFlush whenever they count on having all of their previously issued commands completed. For example, call glFlush before waiting for user input that depends on the generated image.
Notes
glFlush can return at any time. It does not wait until the execution of all previously issued GL commands is complete.
Errors
GL_INVALID_OPERATION is generated if glFlush is executed between the execution of glBegin and the corresponding execution of glEnd.
glFlush()清空缓冲区,将指令送往缓硬件立即执行,但是它是将命令传送完毕之后立即返回,不会等待指令执行完毕。这些指令会在有限时间内执行完毕。
如果直接绘制到前缓冲,那么OpenGL的绘制将不会有任何延迟。设想有一个复杂的场景,有很多物体需要绘制。当调用glFlush时,物体会一个一个地出现在屏幕上。但是,如果使用双缓冲,这个函数将不会有什么影响,因为直到交换缓冲区的时候变化才显现出来。
如果你使用的是双缓冲,那么可能这两个函数都不需要用到。缓冲区交换操作会隐式将命令送去执行。
三、glFinish和glFlush的区别
看起来这两个函数很相似,但是仍然是有区别的。
一般,使用glFlush的目的是确保在调用之后,CPU没有OpenGL相关的事情需要做-命令会送到硬件执行。调用glFinish的目的是确保当返回之后,没有相关工作留下需要继续做。
glFinish会造成性能下降
如果调用glFinish,通常会带来性能上的损失。因为它会是的GPU和CPU之间的并行性丧失。
一般,我们提交给驱动的任务被分组,然后被送到硬件上(在缓冲区交换的时候)。如果调用glFinish,就强制驱动将命令送到GPU。然后CPU等待直到被传送的命令全部执行完毕。这样在GPU工作的整个期间内,CPU没有工作(至少在这个线程上)。而在CPU工作时(通常是在对命令分组),GPU没有工作。因此造成性能上的下降。
因此,应该尽量减少使用此函数。此函数的一个应用是:调试bug。如果我传输到硬件的某条命令造成了GPU的崩溃,找出使得GPU崩溃的那条指令的简单方法是在每个绘制操作之后调用这个函数。这样就可以准确找出造成崩溃的命令。
另外,Direct3D不支持Finish概念。
转自:http://blog.csdn.net/xiajun07061225/article/details/7756187
【OpenGL】glFinish()和glFlush()函数详解-[转]的更多相关文章
- OpenGL的glOrtho平行投影函数详解[转]
glortho函数可以将当前的可视空间设置为正投影空间.基参数的意义如图,如果绘制的图空间本身就是二维的,可以使gluOrtho2D.他的使用类似于glOrtho 原型是: void glOrtho( ...
- # OpenGL常用函数详解(持续更新)
OpenGL常用函数详解(持续更新) 初始化 void glutInit(int* argc,char** argv)初始化GULT库,对应main函数的两个参数 void gultInitWindo ...
- OpenGL的glTranslatef平移变换函数详解
OpenGL的glTranslatef平移变换函数详解 glTranslated()和glTranslatef()这两个函数是定义一个平移矩阵,该矩阵与当前矩阵相乘,使后续的图形进行平移变换. 我们先 ...
- OpenGL的glRotatef旋转变换函数详解
OpenGL的glRotatef旋转变换函数详解 先看一下函数定义:void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLflo ...
- malloc 与 free函数详解<转载>
malloc和free函数详解 本文介绍malloc和free函数的内容. 在C中,对内存的管理是相当重要.下面开始介绍这两个函数: 一.malloc()和free()的基本概念以及基本用法: 1 ...
- NSSearchPathForDirectoriesInDomains函数详解
NSSearchPathForDirectoriesInDomains函数详解 #import "NSString+FilePath.h" @implementation ...
- JavaScript正则表达式详解(二)JavaScript中正则表达式函数详解
二.JavaScript中正则表达式函数详解(exec, test, match, replace, search, split) 1.使用正则表达式的方法去匹配查找字符串 1.1. exec方法详解 ...
- Linux C popen()函数详解
表头文件 #include<stdio.h> 定义函数 FILE * popen( const char * command,const char * type); 函数说明 popen( ...
- kzalloc 函数详解(转载)
用kzalloc申请内存的时候, 效果等同于先是用 kmalloc() 申请空间 , 然后用 memset() 来初始化 ,所有申请的元素都被初始化为 0. view plain /** * kzal ...
随机推荐
- SAS9.4 安装注意事项
OS:Windows Server 2012 R2 SAS:9.4 TS1M1 SAS9.4的安装需要注意的地方: 一. 注意开启Shortname(装了N遍,最容易忘记的地方) SAS安装使用Sho ...
- exp/imp使用
[sql]view plaincopy 1.EXP: 1.完全: EXP SYSTEM/MANAGER BUFFER=64000 FILE=C:\FULL.DMP FULL=Y 如果要执行完 ...
- RAC 之 RMAN 恢复
RAC 下的RMAN 讲究的是备份和还原的策略要一致.备份策略的不同,会导致备份结果的分步不同,进而影响恢复的策略和步骤.一般情况下,恢复策略和备份策略必须是对应的.如果备份策略进行了修改,那么恢复也 ...
- Javascript模块化编程(三):require.js的用法 (转)
转自:http://my.oschina.net/u/1390066/blog/213769 一.为什么要用require.js? 最早的时候,所有Javascript代码都写在一个文件里面,只要加载 ...
- 用vs2012的命令利用xsd文件生成对应的C#类,把xml的string类型映射到生成的类
输入命令: xsd d:\TDDOWNLOAD\atom-author-link.xsd /c /language:C# /outputdir:d:\ 含义: 将d:\TDDOWNLOAD\atom- ...
- jQuery Mobile中文手册:开发入门
jQuery Mobile 以“Write Less, Do More”作为目标,为所有的主流移动操作系统平台提供了高度统一的 UI 框架:jQuery 的移动框架可以让你为所有流行的移动平台设计一个 ...
- iOS 开发者必不可少的 75 个工具,你都会了吗
如果你去到一位熟练的木匠的工作室,你总是能发现他/她有一堆工具来完成不同的任务. 软件开发同样如此.你可以从软件开发者如何使用工具中看出他水准如何.有经验的开发者精于使用工具.对你目前所使用的工具不断 ...
- 利用命令控制台cmd进入某个硬盘的某个文件夹的命令是什么?
在命令行窗口中输入F:后回车就可以切换到F盘,如果想查看F盘的内容,可以再输入dir后回车 (输入“F”后要再输入一个“ :”再回车才行哦)
- 有关loading share object file libjvm.so: xxxxx 的那些问题
今天在跑一个有关postgresql产品的测试,要测试postgresql的有关Mirroring Controller的功能. 在执行mc_ctl命令的时候,报错:error while loadi ...
- Cracking the Code Interview 4.3 Array to Binary Tree
Given a sorted (increasing order) array, write an algorithm to create a binary tree with minimal hei ...