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
28QT_BEGIN_NAMESPACE
29
30class QSurface;
31class QSize;
32class QScreen;
33class QOpenGLTexture;
34class QMouseEvent;
35class QKeyEvent;
36class QRhi;
37class QRhiRenderTarget;
38class QRhiCommandBuffer;
39
40namespace Qt3DCore {
41class QAbstractFrameAdvanceService;
42class QAbstractAspectJobManager;
43class QServiceLocator;
44class QAspectManager;
45}
46
47namespace Qt3DRender {
48
49class QRenderAspect;
50struct GraphicsApiFilterData;
51
52namespace Render {
53
54class NodeManagers;
55class Entity;
56class FrameGraphNode;
57class RenderSettings;
58class BackendNode;
59class OffscreenSurfaceHelper;
60class Shader;
61class RenderBackendResourceAccessor;
62class Q_3DRENDERSHARED_PRIVATE_EXPORT AbstractRenderer
63{
64public:
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
170private:
171 QHash<QByteArray, QByteArray> m_cachedGeneratedShaderGraphes;
172};
173
174Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractRenderer::BackendNodeDirtySet)
175
176} // Render
177
178} // Qt3DRender
179
180QT_END_NAMESPACE
181
182#endif // QT3DRENDER_RENDER_ABSTRACTRENDERER_P_H
183
184

source code of qt3d/src/render/backend/abstractrenderer_p.h