1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB). |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt3D module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | #ifndef QT3DRENDER_RENDER_ABSTRACTRENDERER_P_H |
40 | #define QT3DRENDER_RENDER_ABSTRACTRENDERER_P_H |
41 | |
42 | // |
43 | // W A R N I N G |
44 | // ------------- |
45 | // |
46 | // This file is not part of the Qt API. It exists for the convenience |
47 | // of other Qt classes. This header file may change from version to |
48 | // version without notice, or even be removed. |
49 | // |
50 | // We mean it. |
51 | // |
52 | |
53 | #include <QtCore/qflags.h> |
54 | #include <QtCore/qmutex.h> |
55 | #include <Qt3DRender/private/qt3drender_global_p.h> |
56 | #include <Qt3DRender/private/handle_types_p.h> |
57 | #include <Qt3DRender/qrenderapi.h> |
58 | #include <Qt3DCore/qaspectjob.h> |
59 | #include <Qt3DCore/qnodeid.h> |
60 | #include <QtGui/qsurfaceformat.h> |
61 | |
62 | #include <qopenglcontext.h> |
63 | |
64 | QT_BEGIN_NAMESPACE |
65 | |
66 | class QSurface; |
67 | class QSize; |
68 | class QScreen; |
69 | class QOpenGLTexture; |
70 | class QMouseEvent; |
71 | class QKeyEvent; |
72 | |
73 | namespace Qt3DCore { |
74 | class QAbstractFrameAdvanceService; |
75 | class QEventFilterService; |
76 | class QAbstractAspectJobManager; |
77 | class QServiceLocator; |
78 | class QAspectManager; |
79 | } |
80 | |
81 | namespace Qt3DRender { |
82 | |
83 | class QRenderAspect; |
84 | struct GraphicsApiFilterData; |
85 | |
86 | namespace Render { |
87 | |
88 | class NodeManagers; |
89 | class Entity; |
90 | class FrameGraphNode; |
91 | class RenderSettings; |
92 | class BackendNode; |
93 | class OffscreenSurfaceHelper; |
94 | class Shader; |
95 | class RenderBackendResourceAccessor; |
96 | class Q_3DRENDERSHARED_PRIVATE_EXPORT AbstractRenderer |
97 | { |
98 | public: |
99 | virtual ~AbstractRenderer() {} |
100 | |
101 | // Changes made to backend nodes are reported to the Renderer |
102 | enum BackendNodeDirtyFlag { |
103 | TransformDirty = 1 << 0, |
104 | MaterialDirty = 1 << 1, |
105 | GeometryDirty = 1 << 2, |
106 | ComputeDirty = 1 << 3, |
107 | ParameterDirty = 1 << 4, |
108 | FrameGraphDirty = 1 << 5, |
109 | EntityEnabledDirty = 1 << 6, |
110 | BuffersDirty = 1 << 7, |
111 | TexturesDirty = 1 << 8, |
112 | ShadersDirty = 1 << 9, |
113 | SkeletonDataDirty = 1 << 10, |
114 | JointDirty = 1 << 11, |
115 | LayersDirty = 1 << 12, |
116 | TechniquesDirty = 1 << 13, |
117 | LightsDirty = 1 << 15, |
118 | AllDirty = 0xffffff |
119 | }; |
120 | Q_DECLARE_FLAGS(BackendNodeDirtySet, BackendNodeDirtyFlag) |
121 | |
122 | virtual void dumpInfo() const = 0; |
123 | |
124 | virtual API api() const = 0; |
125 | |
126 | virtual qint64 time() const = 0; |
127 | virtual void setTime(qint64 time) = 0; |
128 | virtual void setJobsInLastFrame(int jobsInLastFrame) = 0; |
129 | |
130 | virtual void setAspect(QRenderAspect *aspect) = 0; |
131 | virtual void setNodeManagers(NodeManagers *managers) = 0; |
132 | virtual void setServices(Qt3DCore::QServiceLocator *services) = 0; |
133 | virtual void setSurfaceExposed(bool exposed) = 0; |
134 | |
135 | virtual QRenderAspect *aspect() const = 0; |
136 | virtual NodeManagers *nodeManagers() const = 0; |
137 | virtual Qt3DCore::QServiceLocator *services() const = 0; |
138 | |
139 | virtual void initialize() = 0; |
140 | virtual void shutdown() = 0; |
141 | virtual void releaseGraphicsResources() = 0; |
142 | |
143 | // Threaded renderer |
144 | virtual void render() = 0; |
145 | // Synchronous renderer |
146 | virtual void doRender(bool swapBuffers) = 0; |
147 | |
148 | virtual void cleanGraphicsResources() = 0; |
149 | |
150 | virtual bool isRunning() const = 0; |
151 | |
152 | virtual void markDirty(BackendNodeDirtySet changes, BackendNode *node) = 0; |
153 | virtual BackendNodeDirtySet dirtyBits() = 0; |
154 | #if defined(QT_BUILD_INTERNAL) |
155 | virtual void clearDirtyBits(BackendNodeDirtySet changes) = 0; |
156 | #endif |
157 | virtual bool shouldRender() const = 0; |
158 | virtual void skipNextFrame() = 0; |
159 | virtual void jobsDone(Qt3DCore::QAspectManager *manager) = 0; |
160 | |
161 | virtual void setPendingEvents(const QList<QPair<QObject *, QMouseEvent>> &mouseEvents, const QList<QKeyEvent> &keyEvents) = 0; |
162 | |
163 | virtual QVector<Qt3DCore::QAspectJobPtr> preRenderingJobs() = 0; |
164 | virtual QVector<Qt3DCore::QAspectJobPtr> renderBinJobs() = 0; |
165 | |
166 | virtual void setSceneRoot(Entity *root) = 0; |
167 | |
168 | virtual Entity *sceneRoot() const = 0; |
169 | virtual FrameGraphNode *frameGraphRoot() const = 0; |
170 | |
171 | virtual Qt3DCore::QAbstractFrameAdvanceService *frameAdvanceService() const = 0; |
172 | |
173 | virtual void setSettings(RenderSettings *settings) = 0; |
174 | virtual RenderSettings *settings() const = 0; |
175 | |
176 | virtual QVariant executeCommand(const QStringList &args) = 0; |
177 | |
178 | // For QtQuick rendering (Scene2D) |
179 | virtual void setOpenGLContext(QOpenGLContext *ctx) = 0; |
180 | virtual void setScreen(QScreen *) {} |
181 | virtual QScreen *screen() const { return nullptr; } |
182 | virtual bool accessOpenGLTexture(Qt3DCore::QNodeId nodeId, QOpenGLTexture **texture, QMutex **lock, bool readonly) = 0; |
183 | virtual QSharedPointer<RenderBackendResourceAccessor> resourceAccessor() const = 0; |
184 | |
185 | virtual void setOffscreenSurfaceHelper(OffscreenSurfaceHelper *helper) = 0; |
186 | virtual QSurfaceFormat format() = 0; |
187 | virtual QOpenGLContext *shareContext() const = 0; |
188 | virtual const GraphicsApiFilterData *contextInfo() const = 0; |
189 | |
190 | // These commands are executed in a dedicated command thread |
191 | // More will be added later |
192 | virtual void loadShader(Shader *shader, Qt3DRender::Render::HShader shaderHandle) = 0; |
193 | |
194 | // Runtime Cache for Generated Shader Graph |
195 | bool containsGeneratedShaderGraph(const QByteArray &key) const { return m_cachedGeneratedShaderGraphes.contains(akey: key); }; |
196 | QByteArray cachedGeneratedShaderGraph(const QByteArray &key) const { return m_cachedGeneratedShaderGraphes.value(akey: key); }; |
197 | void insertGeneratedShaderGraph(const QByteArray &key, const QByteArray shaderCode) { m_cachedGeneratedShaderGraphes.insert(akey: key, avalue: shaderCode); } |
198 | void removeGeneratedShaderGraph(const QByteArray &key) { m_cachedGeneratedShaderGraphes.remove(akey: key); }; |
199 | |
200 | private: |
201 | QHash<QByteArray, QByteArray> m_cachedGeneratedShaderGraphes; |
202 | }; |
203 | |
204 | Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractRenderer::BackendNodeDirtySet) |
205 | |
206 | } // Render |
207 | |
208 | } // Qt3DRender |
209 | |
210 | QT_END_NAMESPACE |
211 | |
212 | #endif // QT3DRENDER_RENDER_ABSTRACTRENDERER_P_H |
213 | |
214 | |