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
QSGMapboxGLRenderNode Class Reference

#include <qsgmapboxglnode.h>

+ Inheritance diagram for QSGMapboxGLRenderNode:
+ Collaboration diagram for QSGMapboxGLRenderNode:

Public Member Functions

 QSGMapboxGLRenderNode (const QMapboxGLSettings &, const QSize &, qreal pixelRatio, QGeoMapMapboxGL *geoMap)
 
QMapboxGL * map () const
 
void render (const RenderState *state) override
 This function is called by the renderer and should paint this node with directly invoking commands in the graphics API (OpenGL, Direct3D, etc.) currently in use.
 
StateFlags changedStates () const override
 When the underlying rendering API is OpenGL, this function should return a mask where each bit represents graphics states changed by the \l render() function:
 
- Public Member Functions inherited from QSGRenderNode
 QSGRenderNode ()
 
 ~QSGRenderNode () override
 Destructs the render node.
 
virtual void prepare ()
 Called from the frame preparation phase.
 
virtual void releaseResources ()
 This function is called when all custom graphics resources allocated by this node have to be freed immediately.
 
virtual RenderingFlags flags () const
 
virtual QRectF rect () const
 
const QMatrix4x4projectionMatrix () const
 
const QMatrix4x4projectionMatrix (int index) const
 
const QMatrix4x4matrix () const
 
const QSGClipNodeclipList () const
 
qreal inheritedOpacity () const
 
QRhiRenderTargetrenderTarget () const
 
QRhiCommandBuffercommandBuffer () const
 
- Public Member Functions inherited from QSGNode
 QSGNode ()
 Constructs a new node.
 
virtual ~QSGNode ()
 Destroys the node.
 
QSGNodeparent () const
 Returns the parent node of this node.
 
void removeChildNode (QSGNode *node)
 Removes node from this node's list of children.
 
void removeAllChildNodes ()
 Removes all child nodes from this node's list of children.
 
void prependChildNode (QSGNode *node)
 Prepends node to this node's the list of children.
 
void appendChildNode (QSGNode *node)
 Appends node to this node's list of children.
 
void insertChildNodeBefore (QSGNode *node, QSGNode *before)
 Inserts node to this node's list of children before the node specified with before.
 
void insertChildNodeAfter (QSGNode *node, QSGNode *after)
 Inserts node to this node's list of children after the node specified with after.
 
void reparentChildNodesTo (QSGNode *newParent)
 
int childCount () const
 Returns the number of child nodes.
 
QSGNodechildAtIndex (int i) const
 Returns the child at index i.
 
QSGNodefirstChild () const
 Returns the first child of this node.
 
QSGNodelastChild () const
 Returns the last child of this node.
 
QSGNodenextSibling () const
 Returns the node after this in the parent's list of children.
 
QSGNodepreviousSibling () const
 Returns the node before this in the parent's list of children.
 
NodeType type () const
 Returns the type of this node.
 
QT_DEPRECATED void clearDirty ()
 
void markDirty (DirtyState bits)
 Notifies all connected renderers that the node has dirty bits.
 
QT_DEPRECATED DirtyState dirtyState () const
 
virtual bool isSubtreeBlocked () const
 Returns whether this node and its subtree is available for use.
 
Flags flags () const
 Returns the set of flags for this node.
 
void setFlag (Flag, bool=true)
 Sets the flag f on this node if enabled is true; otherwise clears the flag.
 
void setFlags (Flags, bool=true)
 Sets the flags f on this node if enabled is true; otherwise clears the flags.
 
virtual void preprocess ()
 Override this function to do processing on the node before it is rendered.
 

Additional Inherited Members

- Public Types inherited from QSGRenderNode
enum  StateFlag {
  DepthState = 0x01 , StencilState = 0x02 , ScissorState = 0x04 , ColorState = 0x08 ,
  BlendState = 0x10 , CullState = 0x20 , ViewportState = 0x40 , RenderTargetState = 0x80
}
 This enum is a bit mask identifying several states. More...
 
enum  RenderingFlag { BoundedRectRendering = 0x01 , DepthAwareRendering = 0x02 , OpaqueRendering = 0x04 , NoExternalRendering = 0x08 }
 Possible values for the bitmask returned from flags(). More...
 
- Public Types inherited from QSGNode
enum  NodeType {
  BasicNodeType , GeometryNodeType , TransformNodeType , ClipNodeType ,
  OpacityNodeType , RootNodeType , RenderNodeType
}
 Can be used to figure out the type of node. More...
 
enum  Flag {
  OwnedByParent = 0x0001 , UsePreprocess = 0x0002 , OwnsGeometry = 0x00010000 , OwnsMaterial = 0x00020000 ,
  OwnsOpaqueMaterial = 0x00040000 , IsVisitableNode = 0x01000000
}
 The QSGNode::Flag enum describes flags on the QSGNode. More...
 
enum  DirtyStateBit {
  DirtySubtreeBlocked = 0x0080 , DirtyMatrix = 0x0100 , DirtyNodeAdded = 0x0400 , DirtyNodeRemoved = 0x0800 ,
  DirtyGeometry = 0x1000 , DirtyMaterial = 0x2000 , DirtyOpacity = 0x4000 , DirtyForceUpdate = 0x8000 ,
  DirtyUsePreprocess = UsePreprocess , DirtyPropagationMask
}
 Used in QSGNode::markDirty() to indicate how the scene graph has changed. More...
 
- Protected Member Functions inherited from QSGNode
 QSGNode (NodeType type)
 Constructs a new node with the given node type.
 
 QSGNode (QSGNodePrivate &dd, NodeType type)
 Constructs a new node with the given node type.
 
- Protected Attributes inherited from QSGNode
QScopedPointer< QSGNodePrivated_ptr
 

Detailed Description

Definition at line 32 of file qsgmapboxglnode.h.

Constructor & Destructor Documentation

◆ QSGMapboxGLRenderNode()

QSGMapboxGLRenderNode::QSGMapboxGLRenderNode ( const QMapboxGLSettings & settings,
const QSize & size,
qreal pixelRatio,
QGeoMapMapboxGL * geoMap )

Definition at line 90 of file qsgmapboxglnode.cpp.

References QObject::connect(), QGeoMapMapboxGL::copyrightsChanged(), settings, and QGeoMap::sgNodeChanged().

+ Here is the call graph for this function:

Member Function Documentation

◆ changedStates()

QSGRenderNode::StateFlags QSGMapboxGLRenderNode::changedStates ( ) const
overridevirtual

When the underlying rendering API is OpenGL, this function should return a mask where each bit represents graphics states changed by the \l render() function:

\value DepthState depth write mask, depth test enabled, depth comparison function \value StencilState stencil write masks, stencil test enabled, stencil operations, stencil comparison functions \value ScissorState scissor enabled, scissor test enabled \value ColorState clear color, color write mask \value BlendState blend enabled, blend function \value CullState front face, cull face enabled \value ViewportState viewport \value RenderTargetState render target

With APIs other than OpenGL, the only relevant values are the ones that correspond to dynamic state changes recorded on the command list/buffer. For example, RSSetViewports, RSSetScissorRects, OMSetBlendState, OMSetDepthStencilState in case of D3D11, or vkCmdSetViewport, vkCmdSetScissor, vkCmdSetBlendConstants, vkCmdSetStencilRef in case of Vulkan, and only when such commands were added to the scenegraph's command list queried via the QSGRendererInterface::CommandList resource enum. States set in pipeline state objects do not need to be reported here. Similarly, draw call related settings (pipeline states, descriptor sets, vertex or index buffer bindings, root signature, descriptor heaps, etc.) are always set again by the scenegraph so render() can freely change them.

RenderTargetState is no longer supported with APIs like Vulkan. This is by nature. render() is invoked while the Qt Quick scenegraph's main command buffer is recording a renderpass, so there is no possibility of changing the target and starting another renderpass (on that command buffer at least). Therefore returning a value with RenderTargetState set is not sensible.

Note
The software backend exposes its QPainter and saves and restores before and after invoking render(). Therefore reporting any changed states from here is not necessary.

The function is called by the renderer so it can reset the states after rendering this node. This makes the implementation of render() simpler since it does not have to query and restore these states.

The default implementation returns 0, meaning no relevant state was changed in render().

Note
This function may be called before render().
With Qt 6 and QRhi-based rendering the only relevant values are ViewportState and ScissorState. Other values can be returned but are ignored in practice.

Reimplemented from QSGRenderNode.

Definition at line 121 of file qsgmapboxglnode.cpp.

References QSGRenderNode::BlendState, QSGRenderNode::ColorState, QSGRenderNode::DepthState, QSGRenderNode::RenderTargetState, QSGRenderNode::ScissorState, QSGRenderNode::StencilState, and QSGRenderNode::ViewportState.

◆ map()

QMapboxGL * QSGMapboxGLRenderNode::map ( ) const

Definition at line 99 of file qsgmapboxglnode.cpp.

◆ render()

void QSGMapboxGLRenderNode::render ( const RenderState * state)
overridevirtual

This function is called by the renderer and should paint this node with directly invoking commands in the graphics API (OpenGL, Direct3D, etc.) currently in use.

The effective opacity can be retrieved with \l inheritedOpacity().

The projection matrix is available through state, while the model-view matrix can be fetched with \l matrix(). The combined matrix is then the projection matrix times the model-view matrix. The correct stacking of the items in the scene is ensured by the projection matrix.

When using the provided matrices, the coordinate system for vertex data follows the usual QQuickItem conventions: top-left is (0, 0), bottom-right is the corresponding QQuickItem's width() and height() minus one. For example, assuming a two float (x-y) per vertex coordinate layout, a triangle covering half of the item can be specified as (width - 1, height - 1), (0, 0), (0, height - 1) using counter-clockwise direction.

Note
QSGRenderNode is provided as a means to implement custom 2D or 2.5D Qt Quick items. It is not intended for integrating true 3D content into the Qt Quick scene. That use case is better supported by QQuickFramebufferObject, QQuickWindow::beforeRendering(), or the equivalents of those for APIs other than OpenGL.
QSGRenderNode can perform significantly better than texture-based approaches (such as, QQuickFramebufferObject), especially on systems where the fragment processing power is limited. This is because it avoids rendering to a texture and then drawing a textured quad. Rather, QSGRenderNode allows recording draw calls in line with the scenegraph's other commands, avoiding an additional render target and the potentially expensive texturing and blending.

Clip information is calculated before the function is called. Implementations wishing to take clipping into account can set up scissoring or stencil based on the information in state. The stencil buffer is filled with the necessary clip shapes, but it is up to the implementation to enable stencil testing.

Some scenegraph backends, software in particular, use no scissor or stencil. There the clip region is provided as an ordinary QRegion.

When implementing a QSGRenderNode that uses QRhi to render, query the QRhi object from the QQuickWindow via \l{QQuickWindow::rhi()}. To get a QRhiCommandBuffer for submitting work to, call commandBuffer(). To query information about the active render target, call renderTarget(). See the \l{{Scene Graph - Custom QSGRenderNode}} example for details.

With Qt 6 and its QRhi-based scene graph renderer, no assumptions should be made about the active (OpenGL) state when this function is called, even when OpenGL is in use. Assume nothing about the pipelines and dynamic states bound on the command list/buffer when this function is called.

Note
Depth writes are expected to be disabled. Enabling depth writes can lead to unexpected results, depending on the scenegraph backend in use and the content in the scene, so exercise caution with this.
In Qt 6, \l changedStates() has limited use. See the documentation for changedStates() for more information.

With some graphics APIs, including when using QRhi directly, it can be necessary to reimplement prepare() in addition, or alternatively connect to the QQuickWindow::beforeRendering() signal. These are called/emitted before recording the beginning of a renderpass on the command buffer (vkCmdBeginRenderPass with Vulkan, or starting to encode via MTLRenderCommandEncoder in case of Metal. Recording copy operations cannot be done inside render() with such APIs. Rather, do such operations either in prepare() or the slot connected to beforeRendering (with DirectConnection).

See also
QSGRendererInterface, QQuickWindow::rendererInterface()

Implements QSGRenderNode.

Definition at line 104 of file qsgmapboxglnode.cpp.

References alignment, QOpenGLContext::currentContext(), GLint(), and state.

+ Here is the call graph for this function:

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