QQuickCPainterRenderer Class
The QQuickCPainterRenderer handles all painting for a QQuickCPainterItem. More...
| Header: | #include <QQuickCPainterRenderer> |
| Inherits: | QQuickRhiItemRenderer |
Public Functions
| QQuickCPainterRenderer() | |
| virtual | ~QQuickCPainterRenderer() override |
| QColor | fillColor() const |
| bool | hasSharedPainter() const |
| float | height() const |
| QCPainter * | painter() const |
| void | setSharedPainter(bool enable) |
| float | width() const |
Protected Functions
| void | beginCanvasPainting(QCOffscreenCanvas &canvas) |
| void | endCanvasPainting() |
| void | grabCanvas(const QCOffscreenCanvas &canvas, std::function<void (const QImage &)> callback) |
| virtual void | initializeResources(QCPainter *painter) |
| virtual void | paint(QCPainter *painter) |
| virtual void | prePaint(QCPainter *painter) |
| virtual void | synchronize(QQuickCPainterItem *item) |
Reimplemented Protected Functions
| virtual void | initialize(QRhiCommandBuffer *cb) override |
| virtual void | render(QRhiCommandBuffer *cb) override |
| virtual void | synchronize(QQuickRhiItem *item) override |
Detailed Description
Implement the paint() method to perform the rendering.
Member Function Documentation
[explicit] QQuickCPainterRenderer::QQuickCPainterRenderer()
Constructs a QQuickCPainterRenderer.
[override virtual noexcept] QQuickCPainterRenderer::~QQuickCPainterRenderer()
Destroys the QQuickCPainterRenderer.
[protected] void QQuickCPainterRenderer::beginCanvasPainting(QCOffscreenCanvas &canvas)
Starts recording QCPainter draw commands targeting canvas.
Note: This function should only be called from prePaint().
beginCanvasPainting() must always be followed by corresponding endCanvasPainting() before returning from prePaint().
[protected] void QQuickCPainterRenderer::endCanvasPainting()
Indicates the end of the drawing targeting the canvas specified in beginCanvasPainting().
Note: This function should only be called from prePaint().
beginCanvasPainting() must always be followed by corresponding endCanvasPainting() before returning from prePaint().
QColor QQuickCPainterRenderer::fillColor() const
Return the current fill color of the item. This can be set by the parent QQuickCPainterItem.
[protected] void QQuickCPainterRenderer::grabCanvas(const QCOffscreenCanvas &canvas, std::function<void (const QImage &)> callback)
Issues a texture readback request for canvas.
callback is invoked either before the function returns, or later, depending on the underlying QRhi and 3D API implementation. Reading back texture contents may involve a GPU->CPU copy, depending on the GPU architecture.
bool QQuickCPainterRenderer::hasSharedPainter() const
Returns true if this item renderer uses a shared painter.
See also setSharedPainter.
float QQuickCPainterRenderer::height() const
Returns the height of the painted area. This is usually the same as the painter item height, but if QQuickRhiItem::fixedColorBufferHeight has been set, height equals to this buffer height (with the device pixel ratio taken into account).
[virtual protected] void QQuickCPainterRenderer::initializeResources(QCPainter *painter)
Reimplement this method to initialize resources using painter. This will be called once before the first synchronize() and when ever resources have been dropped and need to be initialized / added again.
See also QCPainter::addImage.
[virtual protected] void QQuickCPainterRenderer::paint(QCPainter *painter)
Reimplement this method to paint using painter.
This will get called after the item has been filled with fillColor().
Paint is called from renderer thread, to access item data do it in synchronize().
See also synchronize().
QCPainter *QQuickCPainterRenderer::painter() const
Returns the painter attached to this painter item.
[virtual protected] void QQuickCPainterRenderer::prePaint(QCPainter *painter)
This function is called at the start of rendering using painter. This function is called for every frame, before the paint engine is initialized.
See also beginCanvasPainting() and endCanvasPainting().
void QQuickCPainterRenderer::setSharedPainter(bool enable)
Disable painter sharing if enable is false.
Painter sharing is enabled by default.
When painter sharing is enabled, all painter items inside the same QQuickWindow will use the same QCPainter.
If disabling painter sharing is desired, this function must be called early enough, for example from the derived class' constructor. Changing it afterwards, when the item has already initialized for painting, will have no effect.
If two items use dedicated, non-shared painters, each other's graphics resources, such as the ones backing QCImage or QOffscreenCanvas, will not be visible to them. Whereas if the items are in the same window, and sharing is enabled, they can use images or canvases created by the other item, because they both use the same QCPainter.
Note: Even when enable is true, painters are not shared when between items belonging to different QQuickWindow instances, and by extension, to different scene graphs.
See also hasSharedPainter.
[virtual protected] void QQuickCPainterRenderer::synchronize(QQuickCPainterItem *item)
Reimplement this method to synchronize data between item and item painter instances. This will be called before paint() each time item needs to be repainted.
This method is the only place where it is safe for the painter and the item to read and write each others variables.
Usually you should static_cast item to your real item type, and then exchange the data.
float QQuickCPainterRenderer::width() const
Returns the width of the painted area. This is usually the same as the painter item width, but if QQuickRhiItem::fixedColorBufferWidth has been set, width equals to this buffer width (with the device pixel ratio taken into account).