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 <Qt3DCore/qaspectjob.h>
58#include <Qt3DCore/qnodeid.h>
59#include <QtGui/qsurfaceformat.h>
60
61#include <QtGui/qopenglcontext.h>
62
63QT_BEGIN_NAMESPACE
64
65class QSurface;
66class QSize;
67
68namespace Qt3DCore {
69class QAbstractFrameAdvanceService;
70class QBackendNodeFactory;
71class QEventFilterService;
72class QAbstractAspectJobManager;
73class QServiceLocator;
74}
75
76namespace Qt3DRender {
77
78class QRenderAspect;
79
80namespace Render {
81
82class NodeManagers;
83class Entity;
84class FrameGraphNode;
85class RenderSettings;
86class BackendNode;
87class OffscreenSurfaceHelper;
88class Shader;
89
90class Q_3DRENDERSHARED_PRIVATE_EXPORT AbstractRenderer
91{
92public:
93 virtual ~AbstractRenderer() {}
94
95 enum API {
96 OpenGL,
97 Vulkan,
98 DirectX
99 };
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 EntityHierarchyDirty= 1 << 14,
118 LightsDirty = 1 << 15,
119 AllDirty = 0xffffff
120 };
121 Q_DECLARE_FLAGS(BackendNodeDirtySet, BackendNodeDirtyFlag)
122
123 virtual void dumpInfo() const = 0;
124
125 virtual API api() const = 0;
126
127 virtual qint64 time() const = 0;
128 virtual void setTime(qint64 time) = 0;
129
130 virtual void setNodeManagers(NodeManagers *managers) = 0;
131 virtual void setServices(Qt3DCore::QServiceLocator *services) = 0;
132 virtual void setSurfaceExposed(bool exposed) = 0;
133
134 virtual NodeManagers *nodeManagers() const = 0;
135 virtual Qt3DCore::QServiceLocator *services() const = 0;
136
137 virtual void initialize() = 0;
138 virtual void shutdown() = 0;
139 virtual void releaseGraphicsResources() = 0;
140
141 // Threaded renderer
142 virtual void render() = 0;
143 // Synchronous renderer
144 virtual void doRender(bool scene3dBlocking = false) = 0;
145
146 virtual void cleanGraphicsResources() = 0;
147
148 virtual bool isRunning() const = 0;
149
150 virtual void markDirty(BackendNodeDirtySet changes, BackendNode *node) = 0;
151 virtual BackendNodeDirtySet dirtyBits() = 0;
152#if defined(QT_BUILD_INTERNAL)
153 virtual void clearDirtyBits(BackendNodeDirtySet changes) = 0;
154#endif
155 virtual bool shouldRender() = 0;
156 virtual void skipNextFrame() = 0;
157
158 virtual QVector<Qt3DCore::QAspectJobPtr> preRenderingJobs() = 0;
159 virtual QVector<Qt3DCore::QAspectJobPtr> renderBinJobs() = 0;
160 virtual Qt3DCore::QAspectJobPtr pickBoundingVolumeJob() = 0;
161 virtual Qt3DCore::QAspectJobPtr rayCastingJob() = 0;
162 virtual Qt3DCore::QAspectJobPtr syncLoadingJobs() = 0;
163 virtual Qt3DCore::QAspectJobPtr expandBoundingVolumeJob() = 0;
164
165 virtual void setSceneRoot(Qt3DCore::QBackendNodeFactory *factory, Entity *root) = 0;
166
167 virtual Entity *sceneRoot() const = 0;
168 virtual FrameGraphNode *frameGraphRoot() const = 0;
169
170 virtual Qt3DCore::QAbstractFrameAdvanceService *frameAdvanceService() const = 0;
171 virtual void registerEventFilter(Qt3DCore::QEventFilterService *service) = 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
179 virtual void setOpenGLContext(QOpenGLContext *ctx) = 0;
180
181 virtual void setOffscreenSurfaceHelper(OffscreenSurfaceHelper *helper) = 0;
182 virtual QSurfaceFormat format() = 0;
183 virtual QOpenGLContext *shareContext() const = 0;
184
185
186 // These commands are executed in a dedicated command thread
187 // More will be added later
188 virtual void loadShader(Shader *shader, Qt3DRender::Render::HShader shaderHandle) = 0;
189};
190
191Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractRenderer::BackendNodeDirtySet)
192
193} // Render
194
195} // Qt3DRender
196
197QT_END_NAMESPACE
198
199#endif // QT3DRENDER_RENDER_ABSTRACTRENDERER_P_H
200
201