脚本宝典收集整理的这篇文章主要介绍了QOpenGLWindow,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
QOpenGLWindow类是QWindow的一个方便的子类,用于执行OpenGL绘制。
QOpenGLWindow是一个增强的QWindow,它允许轻松创建使用与QOpenGLWidget兼容且类似于传统QGLWidget的API执行OpenGL渲染的窗口。与QOpenGLWidget不同,QopenglWindows不依赖于widgets模块,并提供更好的性能。
典型应用程序将QOpenGLWindow子类化,并重新实现以下虚拟功能:
1、initializeGL()执行OpenGL资源初始化
2、resizeGL()用于设置转换矩阵和其他依赖于窗口大小的资源
3、paintGL()发出OpenGL命令或使用QPaint绘制
要计划重新绘制,请调用update()函数。请注意,这不会立即导致调用paintGL()。在一行中多次调用update()不会以任何方式改变行为。
这是一个插槽,因此它可以连接到QTimer::timeout()信号以执行动画。然而,请注意,在现代OpenGL世界中,依靠与显示器垂直刷新率的同步是一个更好的选择。有关交换间隔的说明,请参阅setSwapInterval()。交换间隔为1(大多数系统默认情况下都是如此)时,每次重新绘制后由QOpenGLWindow内部执行的swapBuffers()调用将阻塞并等待vsync。这意味着无论何时交换完成,都可以通过调用update()再次安排更新,而不依赖于计时器。
要请求上下文的特定配置,请像对任何其他QWindow一样使用setFormat()。除其他外,这允许请求给定的OpenGL版本和配置文件,或启用深度和模具缓冲区。
与QWindow不同,QOpenGLWindow允许在自身上打开画师并执行基于QPainter的绘图。
QOpenGLWindow支持多种更新行为。默认情况下,NoPartialUpdate相当于基于OpenGL的常规QWindow或传统QGLWidget。相比之下,PartialUpdateBlit和PartialUpdateBlend更符合QOpenGLWidget的工作方式,在QOpenGLWidget中始终存在一个额外的专用帧缓冲区对象。通过牺牲一些性能,这些模式允许在每幅绘画上只重绘一个较小的区域,并保留前一帧的其余内容。这对于应用程序来说比使用QPaint进行增量渲染更有用,因为这样它们就不必在每次调用paintGL()时重新绘制整个窗口内容。
与QOpenGLWidget类似,QopenglWindows支持Qt::AA_ShareOpenGLContexts属性。启用后,所有QOpenGLWindow实例的OpenGL上下文将彼此共享。这允许访问彼此可共享的OpenGL资源。
有关Qt中图形的更多信息,请参见图形。
Header: | #include <QOpenGLWindow> |
qmake: | QT += gui |
Since: | Qt 5.4 |
Inherits: | QPaintDeviceWindow |
enum UpdateBehavior { NoPartialUpdate, PartialUpdateBlit, PartialUpdateBlend }
QOpenGLWindow(QOpenGLWindow::UpdateBehavior updateBehavior = NoPartialUpdate, QWindow *parent = nullptr) | |
QOpenGLWindow(QOpenGLContext *shareContext, QOpenGLWindow::UpdateBehavior updateBehavior = NoPartialUpdate, QWindow *parent = nullptr) | |
virtual | ~QOpenGLWindow() |
QOpenGLContext * | context() const |
GLuint | defaultFramebufferObject() const |
void | doneCurrent() |
QImage | grabFramebuffer() |
bool | isValid() const |
void | makeCurrent() |
QOpenGLContext * | shareContext() const |
QOpenGLWindow::UpdateBehavior | updateBehavior() const |
void | frameSwapped() |
virtual void | initializeGL() |
virtual void | paintGL() |
virtual void | paintOverGL() |
virtual void | paintUnderGL() |
virtual void | resizeGL(int w, int h) |
virtual void | paintEvent(QPaintEvent *event) override |
virtual void | resizeEvent(QResizeEvent *event) override |
##########################################
以上是脚本宝典为你收集整理的QOpenGLWindow全部内容,希望文章能够帮你解决QOpenGLWindow所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。