6#include <private/qqmlglobal_p.h>
7#include <private/qsgrenderer_p.h>
8#include <private/qsgdefaultrendercontext_p.h>
15 , m_dirtyTexture(true)
16 , m_multisampling(
false)
18 , m_mirrorHorizontal(
false)
19 , m_mirrorVertical(true)
22 m_rhi = m_context->
rhi();
69 bool doGrab = (m_live || m_grab) && m_dirtyTexture;
82 if (mipmap == m_mipmap)
86 if (m_mipmap && m_texture)
98 if (m_live && !m_item)
106 if (logicalRect == m_logicalRect)
109 m_logicalRect = logicalRect;
115 if (pixelSize == m_pixelSize)
118 m_pixelSize = pixelSize;
120 if (m_live && m_pixelSize.
isNull())
140 if (rhiFormat == m_format)
144 m_format = rhiFormat;
147 qWarning(
"QSGRhiLayer: Attempted to set unsupported texture format %d",
int(rhiFormat));
158 if (m_live && (!m_item || m_pixelSize.
isNull()))
176 m_recursive = recursive;
181 m_mirrorHorizontal = mirror;
186 m_mirrorVertical = mirror;
191 m_dirtyTexture =
true;
192 if (m_live || m_grab)
196void QSGRhiLayer::releaseResources()
207 delete m_msaaColorBuffer;
208 m_msaaColorBuffer =
nullptr;
213 delete m_secondaryTexture;
214 m_secondaryTexture =
nullptr;
217void QSGRhiLayer::grab()
219 if (!m_item || m_pixelSize.
isEmpty()) {
221 m_dirtyTexture =
false;
225 int effectiveSamples = m_samples;
227 if (effectiveSamples <= 1)
230 const bool needsNewRt = !m_rt || m_rt->
pixelSize() != m_pixelSize || (m_recursive && !m_secondaryTexture) || (m_texture && m_texture->
format() != m_format);
232 const bool msaaSettingChanged = (effectiveSamples > 1 && !m_msaaColorBuffer) || (effectiveSamples <= 1 && m_msaaColorBuffer);
234 if (needsNewRt ||mipmapSettingChanged || msaaSettingChanged) {
235 if (effectiveSamples <= 1) {
236 m_multisampling =
false;
239 if (!m_multisampling)
240 qWarning(
"Layer requested %d samples but multisample renderbuffers are not supported", effectiveSamples);
256 if (m_multisampling) {
259 if (!m_msaaColorBuffer->
create()) {
260 qWarning(
"Failed to build multisample color buffer for layer of size %dx%d, sample count %d",
261 m_pixelSize.
width(), m_pixelSize.
height(), effectiveSamples);
265 m_texture = m_rhi->
newTexture(m_format, m_pixelSize, 1, textureFlags);
266 if (!m_texture->
create()) {
267 qWarning(
"Failed to build texture for layer of size %dx%d", m_pixelSize.
width(), m_pixelSize.
height());
271 if (depthBufferEnabled) {
274 qWarning(
"Failed to build depth-stencil buffer for layer");
281 color0.setResolveTexture(m_texture);
283 if (depthBufferEnabled)
284 desc.setDepthStencilBuffer(m_ds);
288 qWarning(
"Failed to build render pass descriptor for layer");
294 qWarning(
"Failed to build texture render target for layer");
300 m_texture = m_rhi->
newTexture(m_format, m_pixelSize, 1, textureFlags);
301 if (!m_texture->
create()) {
302 qWarning(
"Failed to build texture for layer of size %dx%d", m_pixelSize.
width(), m_pixelSize.
height());
306 if (depthBufferEnabled) {
309 qWarning(
"Failed to build depth-stencil buffer for layer");
318 m_secondaryTexture = m_rhi->
newTexture(m_format, m_pixelSize, 1, textureFlags);
319 if (!m_secondaryTexture->
create()) {
320 qWarning(
"Failed to build texture for layer of size %dx%d", m_pixelSize.
width(), m_pixelSize.
height());
324 color0.setTexture(m_secondaryTexture);
326 if (depthBufferEnabled)
332 qWarning(
"Failed to build render pass descriptor for layer");
338 qWarning(
"Failed to build texture render target for layer");
365 m_dirtyTexture =
false;
372 mirrored =
QRectF(m_mirrorHorizontal ? m_logicalRect.
right() : m_logicalRect.
left(),
373 m_mirrorVertical ? m_logicalRect.
bottom() : m_logicalRect.
top(),
374 m_mirrorHorizontal ? -m_logicalRect.
width() : m_logicalRect.
width(),
375 m_mirrorVertical ? -m_logicalRect.
height() : m_logicalRect.
height());
377 mirrored =
QRectF(m_mirrorHorizontal ? m_logicalRect.
right() : m_logicalRect.
left(),
378 m_mirrorVertical ? m_logicalRect.
top() : m_logicalRect.
bottom(),
379 m_mirrorHorizontal ? -m_logicalRect.
width() : m_logicalRect.
width(),
380 m_mirrorVertical ? m_logicalRect.
height() : -m_logicalRect.
height());
382 QSGAbstractRenderer::MatrixTransformFlags matrixFlags;
392 if (m_multisampling) {
397 if (!resourceUpdates)
399 resourceUpdates->
copyTexture(m_texture, m_secondaryTexture);
406 if (!resourceUpdates)
434 cb->resourceUpdate(resourceUpdates);
441 if (
result.data.isEmpty()) {
460 return QRectF(m_mirrorHorizontal ? 1 : 0,
461 m_mirrorVertical ? 0 : 1,
462 m_mirrorHorizontal ? -1 : 1,
463 m_mirrorVertical ? 1 : -1);
466#include "moc_qsgrhilayer_p.cpp"
Format
The following image formats are available in Qt.
@ Format_RGBA32FPx4_Premultiplied
@ Format_RGBA8888_Premultiplied
@ Format_RGBA16FPx4_Premultiplied
QImage mirrored(bool horizontally=false, bool vertically=true) const &
\inmodule QtCore\reentrant
constexpr qreal right() const noexcept
Returns the x-coordinate of the rectangle's right edge.
void resourceUpdate(QRhiResourceUpdateBatch *resourceUpdates)
Sometimes committing resource updates is necessary or just more convenient without starting a render ...
virtual bool create()=0
Creates the corresponding native graphics resources.
void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc)
Sets the QRhiRenderPassDescriptor desc for use with this render target.
virtual QSize pixelSize() const =0
void generateMips(QRhiTexture *tex)
Enqueues a mipmap generation operation for the specified texture tex.
void readBackTexture(const QRhiReadbackDescription &rb, QRhiReadbackResult *result)
Enqueues a texture-to-host copy operation as described by rb.
void copyTexture(QRhiTexture *dst, QRhiTexture *src, const QRhiTextureCopyDescription &desc=QRhiTextureCopyDescription())
Enqueues a texture-to-texture copy operation from src into dst as described by desc.
virtual QRhiRenderPassDescriptor * newCompatibleRenderPassDescriptor()=0
virtual bool create()=0
Creates the corresponding native graphics resources.
virtual bool create()=0
Creates the corresponding native graphics resources.
Format
Specifies the texture format.
bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags={}) const
bool isYUpInFramebuffer() const
bool isFeatureSupported(QRhi::Feature feature) const
QRhiRenderBuffer * newRenderBuffer(QRhiRenderBuffer::Type type, const QSize &pixelSize, int sampleCount=1, QRhiRenderBuffer::Flags flags={}, QRhiTexture::Format backingFormatHint=QRhiTexture::UnknownFormat)
QRhi::FrameOpResult finish()
Waits for any work on the graphics queue (where applicable) to complete, then executes all deferred o...
QRhiTextureRenderTarget * newTextureRenderTarget(const QRhiTextureRenderTargetDescription &desc, QRhiTextureRenderTarget::Flags flags={})
QRhiTexture * newTexture(QRhiTexture::Format format, const QSize &pixelSize, int sampleCount=1, QRhiTexture::Flags flags={})
@ MultisampleRenderBuffer
QRhiResourceUpdateBatch * nextResourceUpdateBatch()
void setViewportRect(const QRect &rect)
Sets rect as the geometry of the viewport to render on the surface.
void setProjectionMatrixToRect(const QRectF &rect)
Convenience method that calls setProjectionMatrix() with an orthographic matrix generated from rect.
void setDeviceRect(const QRect &rect)
Sets rect as the geometry of the surface being rendered to.
void setClearColor(const QColor &color)
Use color to clear the framebuffer when clearMode() is set to QSGAbstractRenderer::ClearColorBuffer.
void setRootNode(QSGRootNode *node)
Sets the node as the root of the QSGNode scene that you want to render.
int msaaSampleCount() const
QSGRenderer * createRenderer(QSGRendererInterface::RenderMode renderMode=QSGRendererInterface::RenderMode2D) override
bool useDepthBufferFor2D() const
QRhi * rhi() const override
void renderNextFrame(QSGRenderer *renderer) override
QRhiCommandBuffer * currentFrameCommandBuffer() const
void scheduledUpdateCompleted()
\group qtquick-scenegraph-nodes \title Qt Quick Scene Graph Node classes
QSGNode * firstChild() const
Returns the first child of this node.
void markDirty(DirtyState bits)
Notifies all connected renderers that the node has dirty bits.
NodeType type() const
Returns the type of this node.
RenderMode
\value RenderMode2D Normal 2D rendering \value RenderMode2DNoDepthBuffer Normal 2D rendering with dep...
@ RenderMode2DNoDepthBuffer
void setRenderTarget(const QSGRenderTarget &rt)
void nodeChanged(QSGNode *node, QSGNode::DirtyState state) override
Updates internal data structures and emits the sceneGraphChanged() signal.
void setDevicePixelRatio(qreal ratio)
void setRect(const QRectF &logicalRect) override
bool hasMipmaps() const override
Returns true if the texture data contains mipmap levels.
bool hasAlphaChannel() const override
Returns true if the texture data contains an alpha channel.
void setLive(bool live) override
void setItem(QSGNode *item) override
void setFormat(Format format) override
void commitTextureOperations(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates) override
Call this function to enqueue image upload operations to resourceUpdates, in case there are any pendi...
QImage toImage() const override
qint64 comparisonKey() const override
Returns a key suitable for comparing textures.
void setMirrorVertical(bool mirror) override
void setMirrorHorizontal(bool mirror) override
void scheduleUpdate() override
void setRecursive(bool recursive) override
void invalidated() override
void markDirtyTexture() override
QSGRhiLayer(QSGRenderContext *context)
bool updateTexture() override
Call this function to explicitly update the dynamic texture.
QRectF normalizedTextureSubRect() const override
Returns the rectangle inside textureSize() that this texture represents in normalized coordinates.
void setSize(const QSize &pixelSize) override
QRhiTexture * rhiTexture() const override
void setHasMipmaps(bool mipmap) override
The QSGRootNode is the toplevel root of any scene graph.
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
constexpr bool isNull() const noexcept
Returns true if both the width and height is 0; otherwise returns false.
constexpr bool isEmpty() const noexcept
Returns true if either of the width and height is less than or equal to 0; otherwise returns false.
GLint GLsizei GLsizei height
GLdouble GLdouble GLdouble GLdouble top
GLint GLsizei GLsizei GLenum format
SSL_CTX int(* cb)(SSL *ssl, unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg)
Q_CORE_EXPORT bool qEnvironmentVariableIsEmpty(const char *varName) noexcept
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)