Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsgdefaultrendercontext_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QSGDEFAULTRENDERCONTEXT_H
5#define QSGDEFAULTRENDERCONTEXT_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtQuick/private/qsgcontext_p.h>
19#include <rhi/qshader.h>
20
22
23class QRhi;
24class QRhiCommandBuffer;
25class QRhiRenderPassDescriptor;
26class QRhiResourceUpdateBatch;
27class QRhiTexture;
28class QRhiRenderBuffer;
29class QSGMaterialShader;
30class QSurface;
31class QSGDefaultRenderContext;
32
34 class Manager;
35}
36
38{
39public:
41 QSGDepthStencilBuffer(QRhiRenderBuffer *ds) : ds(ds) { }
43 QRhiRenderBuffer *ds = nullptr;
44 QSGDefaultRenderContext *rc = nullptr;
45};
46
47class Q_QUICK_EXPORT QSGDefaultRenderContext : public QSGRenderContext
48{
49 Q_OBJECT
50public:
51 QSGDefaultRenderContext(QSGContext *context);
52
53 QRhi *rhi() const override { return m_rhi; }
54 bool isValid() const override { return m_rhi != nullptr; }
55
56 static const int INIT_PARAMS_MAGIC = 0x50E;
57 struct InitParams : public QSGRenderContext::InitParams {
58 int sType = INIT_PARAMS_MAGIC; // help discovering broken code passing something else as 'context'
59 QRhi *rhi = nullptr;
60 int sampleCount = 1; // 1, 4, 8, ...
61 // only used as a hint f.ex. in the texture atlas init
62 QSize initialSurfacePixelSize;
63 // The first window that will be used with this rc, if available.
64 // Only a hint, to help picking better values for atlases.
65 QSurface *maybeSurface = nullptr;
66 };
67
68 void initialize(const QSGRenderContext::InitParams *params) override;
69 void invalidate() override;
70
71 void prepareSync(qreal devicePixelRatio,
72 QRhiCommandBuffer *cb,
73 const QQuickGraphicsConfiguration &config) override;
74
75 void beginNextFrame(QSGRenderer *renderer, const QSGRenderTarget &renderTarget,
76 RenderPassCallback mainPassRecordingStart,
77 RenderPassCallback mainPassRecordingEnd,
78 void *callbackUserData) override;
79 void renderNextFrame(QSGRenderer *renderer) override;
80 void endNextFrame(QSGRenderer *renderer) override;
81
82 void preprocess() override;
83 void invalidateGlyphCaches() override;
84 void flushGlyphCaches() override;
85 QSGDistanceFieldGlyphCache *distanceFieldGlyphCache(const QRawFont &font, int renderTypeQuality) override;
86 QSGCurveGlyphAtlas *curveGlyphAtlas(const QRawFont &font) override;
87
88 QSGTexture *createTexture(const QImage &image, uint flags) const override;
89 QSGRenderer *createRenderer(QSGRendererInterface::RenderMode renderMode = QSGRendererInterface::RenderMode2D) override;
90 QSGTexture *compressedTextureForFactory(const QSGCompressedTextureFactory *factory) const override;
91
92 virtual void initializeRhiShader(QSGMaterialShader *shader, QShader::Variant shaderVariant);
93
94 int maxTextureSize() const override { return m_maxTextureSize; }
95 bool useDepthBufferFor2D() const { return m_useDepthBufferFor2D; }
96 int msaaSampleCount() const { return m_initParams.sampleCount; }
97
98 QRhiCommandBuffer *currentFrameCommandBuffer() const {
99 // may be null if not in an active frame, but returning null is valid then
100 return m_currentFrameCommandBuffer;
101 }
102 QRhiRenderPassDescriptor *currentFrameRenderPass() const {
103 // may be null if not in an active frame, but returning null is valid then
104 return m_currentFrameRenderPass;
105 }
106
107 qreal currentDevicePixelRatio() const
108 {
109 // Valid starting from QQuickWindow::syncSceneGraph(). This takes the
110 // redirections, e.g. QQuickWindow::setRenderTarget(), into account.
111 // This calculation logic matches what the renderer does, so this is
112 // the same value that gets exposed in RenderState::devicePixelRatio()
113 // to material shaders. This getter is useful to perform dpr-related
114 // operations in the sync phase (in updatePaintNode()).
115 return m_currentDevicePixelRatio;
116 }
117
118 QRhiResourceUpdateBatch *maybeGlyphCacheResourceUpdates();
119 QRhiResourceUpdateBatch *glyphCacheResourceUpdates();
120 void deferredReleaseGlyphCacheTexture(QRhiTexture *texture);
121 void resetGlyphCacheResources();
122
123 QSharedPointer<QSGDepthStencilBuffer> getDepthStencilBuffer(const QSize &size, int sampleCount);
124 void addDepthStencilBuffer(const QSharedPointer<QSGDepthStencilBuffer> &ds);
125
126protected:
127 InitParams m_initParams;
128 QRhi *m_rhi;
129 int m_maxTextureSize;
130 QSGRhiAtlasTexture::Manager *m_rhiAtlasManager;
131 QRhiCommandBuffer *m_currentFrameCommandBuffer;
132 QRhiRenderPassDescriptor *m_currentFrameRenderPass;
133 qreal m_currentDevicePixelRatio;
134 bool m_useDepthBufferFor2D;
135 QRhiResourceUpdateBatch *m_glyphCacheResourceUpdates;
136 QSet<QRhiTexture *> m_pendingGlyphCacheTextures;
137 QHash<FontKey, QSGCurveGlyphAtlas *> m_curveGlyphAtlases;
138 QHash<std::pair<QSize, int>, QWeakPointer<QSGDepthStencilBuffer>> m_depthStencilBuffers;
139
140 friend class QSGDepthStencilBuffer;
141};
142
143QT_END_NAMESPACE
144
145#endif // QSGDEFAULTRENDERCONTEXT_H
QSGDepthStencilBuffer(QRhiRenderBuffer *ds)
QSGDefaultRenderContext * rc
static QFontEngine * fontEngineOfRawFont(const QRawFont &font)