Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
ExampleRhiItemRenderer Class Reference

[0] More...

+ Inheritance diagram for ExampleRhiItemRenderer:
+ Collaboration diagram for ExampleRhiItemRenderer:

Public Member Functions

void initialize (QRhiCommandBuffer *cb) override
 Called when the item is initialized for the first time, when the associated texture's size, format, or sample count changes, or when the QRhi or texture change for any reason.
 
void synchronize (QQuickRhiItem *item) override
 This function is called on the render thread, if there is one, while the main/GUI thread is blocked.
 
void render (QRhiCommandBuffer *cb) override
 Called when the backing color buffer's contents needs updating.
 
- Public Member Functions inherited from QQuickRhiItemRenderer
 QQuickRhiItemRenderer ()
 Constructs a new renderer.
 
virtual ~QQuickRhiItemRenderer ()
 The Renderer is automatically deleted when the scene graph resources for the QQuickRhiItem item are cleaned up.
 

Additional Inherited Members

- Protected Member Functions inherited from QQuickRhiItemRenderer
void update ()
 Call this function when the content of the offscreen color buffer should be updated.
 
QRhirhi () const
 
QRhiTexturecolorTexture () const
 
QRhiRenderBuffermsaaColorBuffer () const
 
QRhiTextureresolveTexture () const
 
QRhiRenderBufferdepthStencilBuffer () const
 
QRhiRenderTargetrenderTarget () const
 

Detailed Description

[0]

Definition at line 8 of file qquickrhiitem_intro.cpp.

Member Function Documentation

◆ initialize()

void ExampleRhiItemRenderer::initialize ( QRhiCommandBuffer * cb)
overridevirtual

Called when the item is initialized for the first time, when the associated texture's size, format, or sample count changes, or when the QRhi or texture change for any reason.

The function is expected to maintain (create if not yet created, adjust and rebuild if the size has changed) the graphics resources used by the rendering code in render().

To query the QRhi, QRhiTexture, and other related objects, call rhi(), colorTexture(), depthStencilBuffer(), and renderTarget().

When the item size changes, the QRhi object, the color buffer texture, and the depth stencil buffer objects are all the same instances (so the getters return the same pointers) as before, but the color and depth/stencil buffers will likely have been rebuilt, meaning the \l{QRhiTexture::pixelSize()}{size} and the underlying native texture resource may be different than in the last invocation.

Reimplementations should also be prepared that the QRhi object and the color buffer texture may change between invocations of this function. For example, when the item is reparented so that it belongs to a new QQuickWindow, the the QRhi and all related resources managed by the QQuickRhiItem will be different instances than before in the subsequent call to this function. Is is then important that all existing QRhi resources previously created by the subclass are destroyed because they belong to the previous QRhi that should not be used anymore.

When \l {QQuickRhiItem::}{autoRenderTarget} is true, which is the default, a depth-stencil QRhiRenderBuffer and a QRhiTextureRenderTarget associated with the colorTexture() (or msaaColorBuffer()) and the depth-stencil buffer are created and managed automatically. Reimplementations of initialize() and render() can query those objects via depthStencilBuffer() and renderTarget(). When \l {QQuickRhiItem::}{autoRenderTarget} is set to false, these objects are no longer created and managed automatically. Rather, it will be up the the initialize() implementation to create buffers and set up the render target as it sees fit. When manually managing additional color or depth-stencil attachments for the render target, their size and sample count must always follow the size and sample count of colorTexture() (or msaaColorBuffer()), otherwise rendering or 3D API validation errors may occur.

The subclass-created graphics resources are expected to be released in the destructor implementation of the subclass.

cb is the QRhiCommandBuffer for the current frame. The function is called with a frame being recorded, but without an active render pass. The command buffer is provided primarily to allow enqueuing \l{QRhiCommandBuffer::resourceUpdate()}{resource updates} without deferring to render().

This function is called on the render thread, if there is one.

See also
render()

Implements QQuickRhiItemRenderer.

Definition at line 78 of file qquickrhiitem_intro.cpp.

References cb, QRhi::clipSpaceCorrMatrix(), QRhiBuffer::Dynamic, QRhiVertexInputAttribute::Float2, QRhiVertexInputAttribute::Float3, QRhiShaderStage::Fragment, getShader(), QSize::height(), QRhiBuffer::Immutable, QRhi::newBuffer(), QRhi::newGraphicsPipeline(), QRhi::newShaderResourceBindings(), QRhi::nextResourceUpdateBatch(), QMatrix4x4::perspective(), QRhiRenderTarget::pixelSize(), QRhiRenderTarget::renderPassDescriptor(), QQuickRhiItemRenderer::renderTarget(), QQuickRhiItemRenderer::rhi(), QRhiVertexInputLayout::setAttributes(), QRhiVertexInputLayout::setBindings(), QMatrix4x4::translate(), QRhiShaderResourceBinding::uniformBuffer(), QRhiBuffer::UniformBuffer, QRhiResourceUpdateBatch::uploadStaticBuffer(), QRhiShaderStage::Vertex, QRhiBuffer::VertexBuffer, vertexData, QRhiShaderResourceBinding::VertexStage, and QSize::width().

+ Here is the call graph for this function:

◆ render()

void ExampleRhiItemRenderer::render ( QRhiCommandBuffer * cb)
overridevirtual

Called when the backing color buffer's contents needs updating.

There is always at least one call to initialize() before this function is called.

To request updates, call \l QQuickItem::update() when calling from QML or from C++ code on the main/GUI thread (e.g. when in a property setter), or \l update() when calling from within a QQuickRhiItemRenderer callback. Calling QQuickRhiItemRenderer's update() from within render() will lead to triggering updates continuously.

cb is the QRhiCommandBuffer for the current frame. The function is called with a frame being recorded, but without an active render pass.

This function is called on the render thread, if there is one.

See also
initialize(), synchronize()

Implements QQuickRhiItemRenderer.

Definition at line 127 of file qquickrhiitem_intro.cpp.

References cb, QColor::fromRgbF(), QSize::height(), QRhi::nextResourceUpdateBatch(), QRhiRenderTarget::pixelSize(), QQuickRhiItemRenderer::renderTarget(), QMatrix4x4::rotate(), and QSize::width().

+ Here is the call graph for this function:

◆ synchronize()

void ExampleRhiItemRenderer::synchronize ( QQuickRhiItem * item)
overridevirtual

This function is called on the render thread, if there is one, while the main/GUI thread is blocked.

It is called from \l{QQuickItem::updatePaintNode()}{the {item}'s synchronize step}, and allows reading and writing data belonging to the main and render threads. Typically property values stored in the QQuickRhiItem are copied into the QQuickRhiItemRenderer, so that they can be safely read afterwards in render() when the render and main threads continue to work in parallel.

See also
initialize(), render()

Implements QQuickRhiItemRenderer.

Definition at line 59 of file qquickrhiitem_intro.cpp.

References item.


The documentation for this class was generated from the following file: