1 | // Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB). |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | #ifndef QT3DRENDER_RENDER_ABSTRACTRENDERER_P_H |
4 | #define QT3DRENDER_RENDER_ABSTRACTRENDERER_P_H |
5 | |
6 | // |
7 | // W A R N I N G |
8 | // ------------- |
9 | // |
10 | // This file is not part of the Qt API. It exists for the convenience |
11 | // of other Qt classes. This header file may change from version to |
12 | // version without notice, or even be removed. |
13 | // |
14 | // We mean it. |
15 | // |
16 | |
17 | #include <QtCore/qflags.h> |
18 | #include <QtCore/qmutex.h> |
19 | #include <Qt3DRender/private/qt3drender_global_p.h> |
20 | #include <Qt3DRender/private/handle_types_p.h> |
21 | #include <Qt3DRender/qrenderapi.h> |
22 | #include <Qt3DCore/qaspectjob.h> |
23 | #include <Qt3DCore/qnodeid.h> |
24 | #include <QtGui/qsurfaceformat.h> |
25 | |
26 | #include <qopenglcontext.h> |
27 | |
28 | QT_BEGIN_NAMESPACE |
29 | |
30 | class QSurface; |
31 | class QSize; |
32 | class QScreen; |
33 | class QOpenGLTexture; |
34 | class QMouseEvent; |
35 | class QKeyEvent; |
36 | class QRhi; |
37 | class QRhiRenderTarget; |
38 | class QRhiCommandBuffer; |
39 | |
40 | namespace Qt3DCore { |
41 | class QAbstractFrameAdvanceService; |
42 | class QAbstractAspectJobManager; |
43 | class QServiceLocator; |
44 | class QAspectManager; |
45 | } |
46 | |
47 | namespace Qt3DRender { |
48 | |
49 | class QRenderAspect; |
50 | struct GraphicsApiFilterData; |
51 | |
52 | namespace Render { |
53 | |
54 | class NodeManagers; |
55 | class Entity; |
56 | class FrameGraphNode; |
57 | class RenderSettings; |
58 | class BackendNode; |
59 | class OffscreenSurfaceHelper; |
60 | class Shader; |
61 | class RenderBackendResourceAccessor; |
62 | class Q_3DRENDERSHARED_PRIVATE_EXPORT AbstractRenderer |
63 | { |
64 | public: |
65 | virtual ~AbstractRenderer() {} |
66 | |
67 | // Changes made to backend nodes are reported to the Renderer |
68 | enum BackendNodeDirtyFlag { |
69 | TransformDirty = 1 << 0, |
70 | MaterialDirty = 1 << 1, |
71 | GeometryDirty = 1 << 2, |
72 | ComputeDirty = 1 << 3, |
73 | ParameterDirty = 1 << 4, |
74 | FrameGraphDirty = 1 << 5, |
75 | EntityEnabledDirty = 1 << 6, |
76 | BuffersDirty = 1 << 7, |
77 | TexturesDirty = 1 << 8, |
78 | ShadersDirty = 1 << 9, |
79 | SkeletonDataDirty = 1 << 10, |
80 | JointDirty = 1 << 11, |
81 | LayersDirty = 1 << 12, |
82 | TechniquesDirty = 1 << 13, |
83 | LightsDirty = 1 << 15, |
84 | AllDirty = 0xffffff |
85 | }; |
86 | Q_DECLARE_FLAGS(BackendNodeDirtySet, BackendNodeDirtyFlag) |
87 | |
88 | enum RenderDriver { |
89 | Qt3D, |
90 | Scene3D, |
91 | }; |
92 | |
93 | virtual void dumpInfo() const = 0; |
94 | |
95 | virtual API api() const = 0; |
96 | virtual void setRenderDriver(RenderDriver driver) = 0; |
97 | virtual RenderDriver renderDriver() const = 0; |
98 | |
99 | virtual qint64 time() const = 0; |
100 | virtual void setTime(qint64 time) = 0; |
101 | virtual void setJobsInLastFrame(int jobsInLastFrame) = 0; |
102 | |
103 | virtual void setAspect(QRenderAspect *aspect) = 0; |
104 | virtual void setNodeManagers(NodeManagers *managers) = 0; |
105 | virtual void setServices(Qt3DCore::QServiceLocator *services) = 0; |
106 | virtual void setSurfaceExposed(bool exposed) = 0; |
107 | |
108 | virtual QRenderAspect *aspect() const = 0; |
109 | virtual NodeManagers *nodeManagers() const = 0; |
110 | virtual Qt3DCore::QServiceLocator *services() const = 0; |
111 | |
112 | virtual void initialize() = 0; |
113 | virtual void shutdown() = 0; |
114 | virtual void releaseGraphicsResources() = 0; |
115 | |
116 | virtual void render(bool swapBuffers) = 0; |
117 | |
118 | virtual void cleanGraphicsResources() = 0; |
119 | |
120 | virtual bool isRunning() const = 0; |
121 | |
122 | virtual void markDirty(BackendNodeDirtySet changes, BackendNode *node) = 0; |
123 | virtual BackendNodeDirtySet dirtyBits() = 0; |
124 | #if defined(QT_BUILD_INTERNAL) |
125 | virtual void clearDirtyBits(BackendNodeDirtySet changes) = 0; |
126 | #endif |
127 | virtual bool shouldRender() const = 0; |
128 | virtual void skipNextFrame() = 0; |
129 | virtual void jobsDone(Qt3DCore::QAspectManager *manager) = 0; |
130 | |
131 | virtual bool processMouseEvent(QObject *object, QMouseEvent *event) = 0; |
132 | virtual bool processKeyEvent(QObject *object, QKeyEvent *event) = 0; |
133 | |
134 | virtual std::vector<Qt3DCore::QAspectJobPtr> preRenderingJobs() = 0; |
135 | virtual std::vector<Qt3DCore::QAspectJobPtr> renderBinJobs() = 0; |
136 | |
137 | virtual void setSceneRoot(Entity *root) = 0; |
138 | |
139 | virtual Entity *sceneRoot() const = 0; |
140 | virtual FrameGraphNode *frameGraphRoot() const = 0; |
141 | |
142 | virtual Qt3DCore::QAbstractFrameAdvanceService *frameAdvanceService() const = 0; |
143 | |
144 | virtual void setSettings(RenderSettings *settings) = 0; |
145 | virtual RenderSettings *settings() const = 0; |
146 | |
147 | virtual QVariant executeCommand(const QStringList &args) = 0; |
148 | |
149 | // For QtQuick rendering (Scene3D/2D) |
150 | virtual void setOpenGLContext(QOpenGLContext *ctx) = 0; |
151 | virtual void setRHIContext(QRhi *ctx) = 0; |
152 | virtual void setDefaultRHIRenderTarget(QRhiRenderTarget *defaultTarget) = 0; |
153 | virtual void setRHICommandBuffer(QRhiCommandBuffer *commandBuffer) = 0; |
154 | virtual void setScreen(QScreen *) {} |
155 | virtual QScreen *screen() const { return nullptr; } |
156 | virtual bool accessOpenGLTexture(Qt3DCore::QNodeId nodeId, QOpenGLTexture **texture, QMutex **lock, bool readonly) = 0; |
157 | virtual QSharedPointer<RenderBackendResourceAccessor> resourceAccessor() const = 0; |
158 | |
159 | virtual void setOffscreenSurfaceHelper(OffscreenSurfaceHelper *helper) = 0; |
160 | virtual QSurfaceFormat format() = 0; |
161 | virtual QOpenGLContext *shareContext() const = 0; |
162 | virtual const GraphicsApiFilterData *contextInfo() const = 0; |
163 | |
164 | // Runtime Cache for Generated Shader Graph |
165 | bool containsGeneratedShaderGraph(const QByteArray &key) const { return m_cachedGeneratedShaderGraphes.contains(key); }; |
166 | QByteArray cachedGeneratedShaderGraph(const QByteArray &key) const { return m_cachedGeneratedShaderGraphes.value(key); }; |
167 | void insertGeneratedShaderGraph(const QByteArray &key, const QByteArray shaderCode) { m_cachedGeneratedShaderGraphes.insert(key, value: shaderCode); } |
168 | void removeGeneratedShaderGraph(const QByteArray &key) { m_cachedGeneratedShaderGraphes.remove(key); }; |
169 | |
170 | private: |
171 | QHash<QByteArray, QByteArray> m_cachedGeneratedShaderGraphes; |
172 | }; |
173 | |
174 | Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractRenderer::BackendNodeDirtySet) |
175 | |
176 | } // Render |
177 | |
178 | } // Qt3DRender |
179 | |
180 | QT_END_NAMESPACE |
181 | |
182 | #endif // QT3DRENDER_RENDER_ABSTRACTRENDERER_P_H |
183 | |
184 | |