码迷,mamicode.com
首页 > 其他好文 > 详细

QOpenGLFunctions的使用(2)

时间:2017-08-19 12:43:34      阅读:1864      评论:0      收藏:0      [点我收藏+]

标签:配置   app   环境变量   sample   对象   完整   完成   name   buffers   

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(2,1);
    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.

 

endl;

QOpenGLFunctions的使用(2)

标签:配置   app   环境变量   sample   对象   完整   完成   name   buffers   

原文地址:http://www.cnblogs.com/icmzn/p/7395851.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!