PySide6.QtOpenGL.QOpenGLPaintDevice

class QOpenGLPaintDevice

QOpenGLPaintDevice 类允许使用 QPainter 在 OpenGL 上下文中进行绘制。更多

PySide6.QtOpenGL.QOpenGLPaintDevice 的继承图

概要

方法

虚拟方法

注意

本文档可能包含从C++自动翻译到Python的代码片段。我们始终欢迎对代码片段翻译的贡献。如果您发现翻译问题,您也可以通过在我们的https:/bugreports.qt.io/projects/PYSIDE上创建工单来告知我们。

详细描述

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 窗口示例

__init__()

构造一个QOpenGLPaintDevice

QOpenGLPaintDevice 仅对当前上下文有效。

另请参阅

currentContext()

__init__(size)
Parameters:

大小QSize

使用给定的size构造一个QOpenGLPaintDevice

QOpenGLPaintDevice 仅对当前上下文有效。

另请参阅

currentContext()

__init__(width, height)
Parameters:
  • width – int

  • height – int

使用给定的widthheight构造一个QOpenGLPaintDevice

QOpenGLPaintDevice 仅对当前上下文有效。

另请参阅

currentContext()

context()
Return type:

QOpenGLContext

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

dotsPerMeterX()
Return type:

浮点数

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

另请参阅

setDotsPerMeterX()

dotsPerMeterY()
Return type:

浮点数

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

另请参阅

setDotsPerMeterY()

ensureActiveTarget()

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

beginNativePainting() 也会触发此方法。

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

paintFlipped()
Return type:

布尔

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

另请参阅

setPaintFlipped()

setDevicePixelRatio(devicePixelRatio)
Parameters:

devicePixelRatio – 浮点数

将绘制设备的设备像素比设置为 devicePixelRatio

setDotsPerMeterX(dpmx)
Parameters:

dpmx – 浮点数

设置每米水平像素数为 dpmx

另请参阅

dotsPerMeterX()

setDotsPerMeterY(dpmy)
Parameters:

dpmy – 浮点数

设置每米垂直像素数为 dpmy

另请参阅

dotsPerMeterY()

setPaintFlipped(flipped)
Parameters:

flipped – 布尔值

设置绘画是否应该围绕Y轴翻转至flipped

另请参阅

paintFlipped()

setSize(size)
Parameters:

大小QSize

设置绘图设备的像素大小为 size

另请参阅

size()

size()
Return type:

QSize

返回绘图设备的像素大小。

另请参阅

setSize()