QOpenGLPaintDevice Class

QOpenGLPaintDevice 类可使用QPainter 在 OpenGL 上下文中进行绘画。更多

头文件: #include <QOpenGLPaintDevice>
CMake: find_package(Qt6 REQUIRED COMPONENTS OpenGL)
target_link_libraries(mytarget PRIVATE Qt6::OpenGL)
qmake: QT += opengl
继承: QPaintDevice

公共函数

QOpenGLPaintDevice()
QOpenGLPaintDevice(const QSize &size)
QOpenGLPaintDevice(int width, int height)
virtual ~QOpenGLPaintDevice()
QOpenGLContext *context() const
qreal dotsPerMeterX() const
qreal dotsPerMeterY() const
virtual void ensureActiveTarget()
bool paintFlipped() const
void setDevicePixelRatio(qreal devicePixelRatio)
void setDotsPerMeterX(qreal dpmx)
void setDotsPerMeterY(qreal dpmy)
void setPaintFlipped(bool flipped)
void setSize(const QSize &size)
QSize size() const

重新实现的公共函数

virtual QPaintEngine *paintEngine() const override

重新实现的保护函数

virtual int metric(QPaintDevice::PaintDeviceMetric metric) const override

详细描述

QOpenGLPaintDevice 使用当前的QOpenGL 上下文来渲染QPainter 绘图命令。上下文在构建时被捕获。它要求支持 OpenGL (ES) 2.0 或更高版本。

性能

QOpenGLPaintDevice 几乎总是采用硬件加速,因此可能比软件光栅化快很多。不过,它对状态变化更为敏感,因此需要仔细排序绘图命令,以获得最佳性能。

反锯齿和质量

OpenGL 绘画引擎中的抗锯齿是通过多重采样实现的。大多数硬件都需要更多内存来进行多重采样,其质量也无法与软件绘画引擎相提并论。OpenGL 绘画引擎的优势在于性能,而非视觉渲染质量。

状态更改

当使用QPainter 向 QOpenGLPaintDevice 上色时,当前 OpenGL 上下文的状态将被上色引擎改变,以反映其需要。应用程序不应依赖于将 OpenGL 状态重置为原始状态,特别是当前着色器程序、OpenGL 视口、纹理单元和绘制模式。

混合使用 QPainter 和 OpenGL

在混合使用QPainter 和 OpenGL 时,重要的是要通知QPainter OpenGL 状态可能已经混乱,以便它能恢复内部状态。这可以通过在开始 OpenGL 渲染之前调用QPainter::beginNativePainting() 和在渲染结束后调用QPainter::endNativePainting() 来实现。

另请参阅 OpenGL 窗口示例

成员函数文档

QOpenGLPaintDevice::QOpenGLPaintDevice()

构造一个 QOpenGLPaintDevice。

QOpenGLPaintDevice 仅对当前上下文有效。

另请参阅 QOpenGLContext::currentContext().

[explicit] QOpenGLPaintDevice::QOpenGLPaintDevice(const QSize &size)

使用给定的size 构建一个 QOpenGLPaintDevice。

QOpenGLPaintDevice 仅对当前上下文有效。

另请参阅 QOpenGLContext::currentContext().

QOpenGLPaintDevice::QOpenGLPaintDevice(int width, int height)

使用给定的widthheight 构建一个 QOpenGLPaintDevice。

QOpenGLPaintDevice 仅对当前上下文有效。

另请参阅 QOpenGLContext::currentContext().

[virtual noexcept] QOpenGLPaintDevice::~QOpenGLPaintDevice()

摧毁QOpenGLPaintDevice.

QOpenGLContext *QOpenGLPaintDevice::context() const

返回与绘制设备相关联的 OpenGL 上下文。

qreal QOpenGLPaintDevice::dotsPerMeterX() const

返回水平方向上每米的像素数。

另请参阅 setDotsPerMeterX()。

qreal QOpenGLPaintDevice::dotsPerMeterY() const

返回垂直方向上每米的像素数。

另请参阅 setDotsPerMeterY()。

[virtual] void QOpenGLPaintDevice::ensureActiveTarget()

此虚拟方法作为回调提供,以便在不同QOpenGLPaintDevice 实例交替发出绘制调用时重新绑定目标帧缓冲区对象或上下文。

beginNativePainting() 也会触发此方法。

默认实现不执行任何操作。

[override virtual protected] int QOpenGLPaintDevice::metric(QPaintDevice::PaintDeviceMetric metric) const

重实现:QPaintDevice::metric(QPaintDevice::PaintDeviceMetric metric) const.

[override virtual] QPaintEngine *QOpenGLPaintDevice::paintEngine() const

重实现:QPaintDevice::paintEngine() const.

bool QOpenGLPaintDevice::paintFlipped() const

如果绘画围绕 Y 轴翻转,则返回true

另请参阅 setPaintFlipped().

void QOpenGLPaintDevice::setDevicePixelRatio(qreal devicePixelRatio)

将喷涂设备的设备像素比设置为devicePixelRatio

void QOpenGLPaintDevice::setDotsPerMeterX(qreal dpmx)

将水平方向上每米的像素数设置为dpmx

另请参阅 dotsPerMeterX() 。

void QOpenGLPaintDevice::setDotsPerMeterY(qreal dpmy)

将垂直方向上每米的像素数设置为dpmy

另请参阅 dotsPerMeterY() 。

void QOpenGLPaintDevice::setPaintFlipped(bool flipped)

设置绘画是否应围绕 Y 轴翻转,网址为flipped

另请参阅 paintFlipped() 。

void QOpenGLPaintDevice::setSize(const QSize &size)

将喷涂设备的像素大小设置为size

另请参阅 size() 。

QSize QOpenGLPaintDevice::size() const

返回喷涂设备的像素大小。

另请参见 setSize()。

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.