QOpenGLFunctions的使用(2)
QOpenGLFunctions的使用(2)
前一小结请参考:QOpenglFuncations(1) www.icmzn.com
本小节介绍相关的类:
1. The QGLContext class
The QGLContext class包装了OpenGL的渲染环境类,即所有的QOpengl的绘制都在该环境中进行。
An OpenGL rendering context is a complete set of OpenGL state variables. The rendering context's format is set in the constructor, but it can also be set later with setFormat(). The format options that are actually set are returned by format(); the options you asked for are returned by requestedFormat(). Note that after a QGLContext object has been constructed, the actual OpenGL context must be created by explicitly calling the create() function. ThemakeCurrent() function makes this context the current rendering context. You can make no context current using doneCurrent(). The reset() function will reset the context and make it invalid.
OpenGL渲染换金,就是一个完整的OpenGL的状态变量集合。 在构造函数中QGLContext::QGLContext(const QGLFormat & format)需要指定渲染的格式,也可以通过setFormat()来进行后续的设置。实际设置的format options可以通过format()返回。而options则通过requestFormat()来返回。注意: 一旦QGLComtext 环境对象构造完毕,则需要通过显示调用create()函数来创建Opengl的实际的环境变量、
inline QGLContext* createOpenGLContext()
{
QOpenGLContext *context = new QOpenGLContext();
QSurfaceFormat format;
format.setVersion(,);
format.setProfile(QSurfaceFormat::CompatibilityProfile);
context->setFormat(format);
QGLContext *result = QGLContext::fromOpenGLContext(context);
result->create();
return result;
}
makeCurrent() 函数作用就是将该环境变量作为当前的渲染环境变量,这样所有的GL函数都可以在该环境变量下操作。可以在非main UI 线程之外的线程调用这个方法,从而确保从UI线程中将该环境变量设置为相关的线程中,从而在线程中完成相应的绘制。void QGLContext::moveToThread(QThread * thread)。
可以通过使用doneCurrent()函数来设置当前环境中空的GL环境变量。正常情况下不需要调用该函数,QGLContext会自动调用。
If you're using double buffering you can swap the screen contents with the off-screen buffer using swapBuffers().
如果使用双缓存方式来使用OpenGGL,则在off-screen 缓存中使用swapBuffers()函数。void QGLContext::swapBuffers() const,作用是完成OpenGL 一帧数据的渲染,确保再次调用makeCurrent(),然后在开始新的绘制。
注意:QGLContext 不是线程安全的。
2. The QSurface class
The QSurface class is an abstraction of renderable surfaces in Qt.
The size of the surface is accessible with the size() function。即返回Surface的像素数量size。The rendering specific attributes of the surface are accessible through the format() function.通过format来设置其格式。
(1)The QSurfaceFormat class
即表示QSurface的格式。The format includes the size of the color buffers, red, green, and blue; the size of the alpha buffer; the size of the depth and stencil buffers; and number of samples per pixel for multisampling. In addition, the format contains surface configuration parameters such as OpenGL profile and version for rendering, whether or not to enable stereo buffers, and swap behaviour.
格式包括颜色缓冲的大小,rgb, 透明缓冲的大小。 深度缓存代销。 每个像素多采样的数量。 另外, 也包含surface配置参数,如Opengl的profile,以及版本来渲染。以及是否双缓存。等。
默认的 QSurfaceFormat. 是Opengl 2.0版本,因为其提供了最高的跨平台移植性,以及Opengl的实现。
3. QOpenGLContext
The QOpenGLContext class represents a native OpenGL context, enabling OpenGL rendering on a QSurface.
QOpenGLContex类表征了native OpenGl Contex, 保证OpenGl渲染在QSurface。
QOpenGLContext represents the OpenGL state of an underlying OpenGL context. To set up a context, set its screen and format such that they match those of the surface or surfaces with which the context is meant to be used, if necessary make it share resources with other contexts withsetShareContext(), and finally call create(). Use the return value or isValid() to check if the context was successfully initialized.
QOpenGLContext 表征了Opengl的环境的状态。
A context can be made current against a given surface by calling makeCurrent(). When OpenGL rendering is done, call swapBuffers() to swap the front and back buffers of the surface, so that the newly rendered content becomes visible. To be able to support certain platforms, QOpenGLContextrequires that you call makeCurrent() again before starting rendering a new frame, after calling swapBuffers().
通过makeCurrent()来使OpenGL环境称为当前相应的OpenGL, 当OpenGL渲染完毕,调用swapBuffers()来交换前后Surface的缓存。这样,新渲染的内容就可以显示出来。在支持某些平台下,调用swapBuffers()之后,QOpenglContex还要求再次此调用makeCurrent()在开始渲染一新的内容之前。
If the context is temporarily not needed, such as when the application is not rendering, it can be useful to delete it in order to free resources. You can connect to the aboutToBeDestroyed() signal to clean up any resources that have been allocated with different ownership from the QOpenGLContextitself.
当contex暂时没有使用个,如应用没有渲染操作,可以delete 来释放资源。通过连接 aboutToBeDestroyed() 信号 来清理资源,即这些资源是被不同的QOpenGLContex创建的。
Once a QOpenGLContext has been made current, you can render to it in a platform independent way by using Qt's OpenGL enablers such asQOpenGLFunctions, QOpenGLBuffer, QOpenGLShaderProgram, and QOpenGLFramebufferObject. It is also possible to use the platform's OpenGL API directly, without using the Qt enablers, although potentially at the cost of portability. The latter is necessary when wanting to use OpenGL 1.x or OpenGL ES 1.x.
一旦,QOpenGLContex称为当前的环境,则就可以渲染,且以平台无关的方式来使用Qt的OpenGL,如QOpenglFunctions,QOpenglBuffer,QOpenglShaderPro等等。同时,也能够直接使用平台相关的OpenGL的API来直接绘制渲染,这样,就会损失移植性的代价。
可以查看OpenGL Window 的例子,其中使用了QOpenGLContex的用法。
(1)线程相关性
QOpenglContex的环境实例可以移到任意其他不同的线程中 moveToThread()。 不要从QOpenglContext对象所属的不同的其他线程中调用makeCurrent().一个contex只能够存在一个当前线程中,且相应的surface。并且注意:一个线程只能够有一个contgext实例。
(2)Context Resource Sharing环境资源共享
Resources, such as framebuffer objects, textures, and vertex buffer objects can be shared between contexts. Use setShareContext() before callingcreate() to specify that the contexts should share these resources. QOpenGLContext internally keeps track of a QOpenGLContextGroup object which can be accessed with shareGroup(), and which can be used to find all the contexts in a given share group. A share group consists of all contexts that have been successfully initialized and are sharing with an existing context in the share group. A non-sharing context has a share group consisting of a single context.
资源,如缓存对象,纹理,顶点缓存对象能够共享,在不同的QOpenglContext实例之间。 在调用create()之前调用setShareContext()从而可以指定该context共享这些资源。QOpenglContext内部保持跟踪QOpenglContextGroup对象,即通过shareGroup() 组合在一个组中,则可以在一个共享的组中公用查找相应的资源。共享组由成功初始化后的其他context,并且共享一个共享组中的现存的context。 非共享context则只有一个context的共享组。
(3)Default Framebuffer 默认的框架缓存
On certain platforms, a framebuffer other than 0 might be the default frame buffer depending on the current surface. Instead of calling glBindFramebuffer(0), it is recommended that you use glBindFramebuffer(ctx->defaultFramebufferObject()), to ensure that your application is portable between different platforms. However, if you use QOpenGLFunctions::glBindFramebuffer(), this is done automatically for you.
在某一类的平台下, 框架缓存依赖于当前的surface。不调用glBindFrameBuffer(0), 但是,推荐使用glBindFramebuffer(ctx->defaultFramebufferObject()) 的方式,来确保应用程序可移植性。然而,如果使用 QOpenGLFunctions::glBindFramebuffer(),,则自动执行处理。
bool QOpenGLContext::create()
以当前的配置来创建OpenGL环境。当前配置包括: format,sharecontext, screen。
If the OpenGL implementation on your system does not support the requested version of OpenGL context, then QOpenGLContext will try to create the closest matching version. The actual created context properties can be queried using the QSurfaceFormat returned by the format() function. For example, if you request a context that supports OpenGL 4.3 Core profile but the driver and/or hardware only supports version 3.2 Core profile contexts then you will get a 3.2 Core profile context.
如果平台上的Opengl 实现不支持请求的Opengl版本,则QOpenglContext会视图创建一个最接近的版本实现的环境实例。这样实际创建的版本可以通过format()来查看。如,如果请求支持OpenGl 4.3 Core 的版本,但是驱动或者硬件只支持 3.2Core的版本,这样,实际创建的就是3.2 Core版本的环境。
endl;
QOpenGLFunctions的使用(2)的更多相关文章
- QOpenGLFunctions的相关的使用(1)
QOpenGLFunctions的使用 1. QOpenGLFunctions 说明 QOpenGLFunctions 类提供了跨平台的OpenGl ES2.0 API版本. OpenGL 2. ...
- Qt5 新特性
Qt 5 已经临近发布,其最大的特点就是模块化.将原来庞大的模块更细分为不同的部分,同时,一个大版本的升级,当然少不了添加.删除各个功能类.文本简单介绍 Qt5 的特性,其具体内容来自 Qt5 官方 ...
- qt5_qml_Opengl_shader 第一弹----------------------openglunderqml的简化及介绍
最近得知opengl可以通过纹理贴图来渲染yuv的数据,这就免去了yuv-rgb,这个过程在arm上还是很耗时间的,于是就接触了opengl. 写这篇文章的目的是方便初学者使用qml来调用opengl ...
- 【Qt for Android】OpenGL ES 绘制彩色立方体
Qt 内置对OpenGL ES的支持.选用Qt进行OpenGL ES的开发是很方便的,很多辅助类都已经具备.从Qt 5.0開始添加了一个QWindow类,该类既能够使用OpenGL绘制3D图形,也能够 ...
- Qt5 OpenGL框架
#ifndef MYRENDERER_H #define MYRENDERER_H #include <QOpenGLContext> #include <QOpenGLFuncti ...
- Qt5.6.0+OpenGL 纹理贴图首战告捷
重要的话写在前面~~通过今晚的实验,知道了EBO是不能随便release的~~~一直不要release就可以了,否则vao会失效 Display.h #ifndef DISPLAYWIDGET_H # ...
- Qt 使用openGL 渲染YUV420P格式的视频
代码如下 YUV420P_Render.h #ifndef YUV420P_RENDER_H #define YUV420P_RENDER_H #include <QObject> #in ...
- Qt 使用openGL 渲染NV12格式的视频
直接上代码 Nv12Render.h #ifndef NV12RENDER_H #define NV12RENDER_H #include <QOpenGLFunctions> #incl ...
- qt 5.2.1类和模块的关系图
QT│ ├─ActiveQt│ │ ActiveQt│ │ ActiveQtDepends│ │ ActiveQtVersion│ │ QAxAggregated│ │ QAxB ...
随机推荐
- OKI系列针式打印机更换色带图解教程
色带一直换不好,今天找到一个带图的教程,收藏一下 打开新色带的包装后,我们可以仔细观察一下新色带,找到里面带有一段“扭曲”色带的位置,这段色带就是:“莫比乌斯带”结构. 找到“莫比乌斯带”结构(就是有 ...
- UIDatePicker 时间选择器
NSDate *currentTime = [NSDate date]; datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, ...
- refused to Connection
两种情况: .数据库账号密码错误 .mysql挂了
- Spring 注解驱动(一)基本使用规则
Spring 注解驱动(一)基本使用规则 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html) 一.基本使用 @Configur ...
- python -u
标准错误(std.err):直接打印到屏幕 标准输出(std.out):需要缓存后再输出到屏幕 sys.stdout.write("stdout1") sys.stderr.wri ...
- linux代码常用查询!!!!!!!!!!!!
字符串: echo "a b c d e f"|cut -d ' ' -f1 输出a echo "a b c d e f"|cut -d ...
- tomcat+bean例子
C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\app\WEB-INF\classes\文件夹下 建立beanTestPa ...
- javascript的use strict(使用严格模式)
上一篇博文学习变量声明带var和不带的区别.搜索相关的文章. 引出了另一个概念. "use strict" 使用严格模式 对于一个使用者而不是概念研究者,我觉得没有意义争论或者讨论 ...
- jvm层面锁优化+一般锁的优化策略
偏向锁: 首先了解对象头MARK指针(对象头标记,32位): 存储GC标记,对象年龄,对象Hash,锁信息(锁记录的指针,偏向锁线程的ID) 大部分情况是没有竞争的,所以可以通过偏向来提高性能 所谓的 ...
- [ASP.NET]使用Oracle.ManagedDataAccess的OracleParameter参数化和OracleDataAdapter模糊查询
今天写个查询员工的信息的demo遇到了2个问题 问题1.使用Oracle.ManagedDataAccess的OracleParameter参数化 OracleParameter 的使用(参数名要以: ...