summaryrefslogtreecommitdiffstats
path: root/src/runtimerender/Qt3DSRenderContextCore.h
blob: c239d788cbb17f16501c36c58439ebfbbfc360f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/****************************************************************************
**
** Copyright (C) 2008-2012 NVIDIA Corporation.
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt 3D Studio.
**
** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#pragma once
#ifndef QT3DS_RENDER_CONTEXT_CORE_H
#define QT3DS_RENDER_CONTEXT_CORE_H
#include "Qt3DSRender.h"
#include "foundation/Qt3DSAllocatorCallback.h"
#include "foundation/Qt3DSRefCounted.h"
#include "foundation/StringTable.h"
#include "Qt3DSRenderPresentation.h"

#include <QtCore/qpair.h>
#include <QtCore/qsize.h>

namespace qt3ds {
namespace render {
    struct ScaleModes
    {
        enum Enum {
            ExactSize = 0, // Ensure the viewport is exactly same size as application
            ScaleToFit = 1, // Resize viewport keeping aspect ratio
            ScaleToFill = 2, // Resize viewport to entire window
            FitSelected = 3, // Resize presentation to fit into viewport
        };
    };

    // Supported (sterescopic) rendering modes. Default Mono.
    struct StereoModes
    {
        enum Enum {
            Mono,
            TopBottom,
            LeftRight,
            AnaglyphRedCyan,
            AnaglyphGreenMagenta
        };
    };

    // Currently rendered (stereoscopic) view / camera. Default Mono.
    struct StereoViews
    {
        enum Enum {
            Mono,
            Left,
            Right
        };
    };

    // Part of render context that does not require the render system.
    class IQt3DSRenderContextCore : public NVRefCounted
    {
    public:
        virtual IStringTable &GetStringTable() = 0;
        virtual NVFoundationBase &GetFoundation() = 0;
        virtual NVAllocatorCallback &GetAllocator() = 0;
        virtual IInputStreamFactory &GetInputStreamFactory() = 0;
        virtual IThreadPool &GetThreadPool() = 0;
        virtual IDynamicObjectSystemCore &GetDynamicObjectSystemCore() = 0;
        virtual ICustomMaterialSystemCore &GetMaterialSystemCore() = 0;
        virtual IEffectSystemCore &GetEffectSystemCore() = 0;
        virtual IPerfTimer &GetPerfTimer() = 0;
        virtual IBufferLoader &GetBufferLoader() = 0;
        virtual IRenderPluginManagerCore &GetRenderPluginCore() = 0;
        virtual IPathManagerCore &GetPathManagerCore() = 0;
        // Text renderers may be provided by clients at runtime.
        virtual void SetTextRendererCore(ITextRendererCore &inRenderer) = 0;
        virtual ITextRendererCore *GetTextRendererCore() = 0;
        virtual void setDistanceFieldRenderer(ITextRendererCore &inRenderer) = 0;
        virtual ITextRendererCore *getDistanceFieldRenderer() = 0;
        // this is our default 2D text onscreen renderer
        virtual void SetOnscreenTextRendererCore(ITextRendererCore &inRenderer) = 0;
        virtual ITextRendererCore *GetOnscreenTextRendererCore() = 0;
        // The render context maintains a reference to this object.
        virtual IQt3DSRenderContext &CreateRenderContext(NVRenderContext &inContext,
                                                         const char8_t *inPrimitivesDirectory,
                                                         bool delayedLoading) = 0;

        static IQt3DSRenderContextCore &Create(NVFoundationBase &fnd, IStringTable &strt);
        static bool distanceFieldEnabled();
    };

    class IQt3DSRenderContext : public NVRefCounted
    {
    protected:
        virtual ~IQt3DSRenderContext() {}
    public:
        virtual IStringTable &GetStringTable() = 0;
        virtual NVFoundationBase &GetFoundation() = 0;
        virtual NVAllocatorCallback &GetAllocator() = 0;
        virtual IQt3DSRenderer &GetRenderer() = 0;
        virtual IRenderWidgetContext &GetRenderWidgetContext() = 0;
        virtual IBufferManager &GetBufferManager() = 0;
        virtual IResourceManager &GetResourceManager() = 0;
        virtual NVRenderContext &GetRenderContext() = 0;
        virtual IOffscreenRenderManager &GetOffscreenRenderManager() = 0;
        virtual IInputStreamFactory &GetInputStreamFactory() = 0;
        virtual IEffectSystem &GetEffectSystem() = 0;
        virtual IShaderCache &GetShaderCache() = 0;
        virtual IThreadPool &GetThreadPool() = 0;
        virtual IImageBatchLoader &GetImageBatchLoader() = 0;
        virtual IRenderPluginManager &GetRenderPluginManager() = 0;
        virtual IDynamicObjectSystem &GetDynamicObjectSystem() = 0;
        virtual ICustomMaterialSystem &GetCustomMaterialSystem() = 0;
        virtual IPixelGraphicsRenderer &GetPixelGraphicsRenderer() = 0;
        virtual IPerfTimer &GetPerfTimer() = 0;
        virtual ITextTextureCache *GetTextureCache() = 0;
        virtual ITextRenderer *GetTextRenderer() = 0;
        virtual ITextRenderer *getDistanceFieldRenderer() = 0;
        virtual IRenderList &GetRenderList() = 0;
        virtual IPathManager &GetPathManager() = 0;
        virtual IShaderProgramGenerator &GetShaderProgramGenerator() = 0;
        virtual IDefaultMaterialShaderGenerator &GetDefaultMaterialShaderGenerator() = 0;
        virtual ICustomMaterialShaderGenerator &GetCustomMaterialShaderGenerator() = 0;
        // The memory used for the per frame allocator is released as the first step in BeginFrame.
        // This is useful for short lived objects and datastructures.
        virtual NVAllocatorCallback &GetPerFrameAllocator() = 0;
        // Get the number of times EndFrame has been called
        virtual QT3DSU32 GetFrameCount() = 0;

        // Get fps
        virtual QPair<QT3DSF32, int> GetFPS() = 0;
        // Set fps by higher level, etc application
        virtual void SetFPS(QPair<QT3DSF32, int> inFPS) = 0;
        virtual void SetFrameTime(QT3DSF32 time) = 0;
        virtual QVector<QT3DSF32> GetFrameTimes() const = 0;

        // Currently there are a few things that need to work differently
        // in authoring mode vs. runtime.  The particle effects, for instance
        // need to be framerate-independent at runtime but framerate-dependent during
        // authoring time assuming virtual 16 ms frames.
        // Defaults to falst.
        virtual bool IsAuthoringMode() = 0;
        virtual void SetAuthoringMode(bool inMode) = 0;

        // This one is setup by the runtime binding
        virtual ITextRenderer *GetOnscreenTextRenderer() = 0;
        virtual ITextTextureAtlas *GetTextureAtlas() = 0;

        // Sub presentations change the rendering somewhat.
        virtual bool isSubPresentationRenderInLayer() = 0;
        virtual void setSubPresentationRenderInLayer(bool inValue) = 0;
        virtual void SetSceneColor(Option<QT3DSVec4> inSceneColor) = 0;
        virtual void SetMatteColor(Option<QT3DSVec4> inMatteColor) = 0;
        virtual void setMatteEnabled(bool enable) = 0;

        // Render screen aligned 2D text at x,y
        virtual void RenderText2D(QT3DSF32 x, QT3DSF32 y, qt3ds::foundation::Option<qt3ds::QT3DSVec3> inColor,
                                  const char *text) = 0;
        // render Gpu profiler values
        virtual void RenderGpuProfilerStats(QT3DSF32 x, QT3DSF32 y,
                                            qt3ds::foundation::Option<qt3ds::QT3DSVec3> inColor) = 0;

        // The reason you can set both window dimensions and an overall viewport is that the mouse
        // needs to be inverted
        // which requires the window height, and then the rest of the system really requires the
        // viewport.
        virtual void SetWindowDimensions(const QSize &inWindowDimensions) = 0;
        virtual QSize GetWindowDimensions() = 0;

        virtual NVRenderRect GetContextViewport() const = 0;
        // Only valid between calls to Begin,End.
        virtual NVRenderRect GetPresentationViewport() const = 0;

        virtual void SetScaleMode(ScaleModes::Enum inMode) = 0;
        virtual ScaleModes::Enum GetScaleMode() = 0;

        virtual bool IsStereoscopic() const = 0;
        virtual void SetStereoMode(StereoModes::Enum inMode) = 0;
        virtual StereoModes::Enum GetStereoMode() const = 0;
        virtual void SetStereoView(StereoViews::Enum inView) = 0;
        virtual StereoViews::Enum GetStereoView() const = 0;
        virtual void SetStereoEyeSeparation(double separation) = 0;
        virtual double GetStereoEyeSeparation() const = 0;
        virtual void SetStereoProgressiveEnabled(bool enabled) = 0;
        virtual bool GetStereoProgressiveEnabled() const = 0;
        virtual void SetSkipFramesInterval(int interval) = 0;
        virtual int GetSkipFramesInterval() const = 0;

        virtual void SetWireframeMode(bool inEnable) = 0;
        virtual bool GetWireframeMode() = 0;

        // Return the viewport the system is using to render data to.  This gives the the dimensions
        // of the rendered system.  It is dependent on but not equal to the viewport.
        virtual NVRenderRectF GetDisplayViewport() const = 0;

        // Layers require the current presentation dimensions in order to render.
        virtual void
        SetPresentationDimensions(const QSize &inPresentationDimensions) = 0;
        virtual QSize GetCurrentPresentationDimensions() const = 0;

        virtual void SetRenderRotation(RenderRotationValues::Enum inRotation) = 0;
        virtual RenderRotationValues::Enum GetRenderRotation() const = 0;

        virtual QT3DSVec2 GetMousePickViewport() const = 0;
        virtual QT3DSVec2 GetMousePickMouseCoords(const QT3DSVec2 &inMouseCoords) const = 0;

        // Valid during and just after prepare for render.
        virtual QT3DSVec2 GetPresentationScaleFactor() const = 0;

        // Steps needed to render:
        // 1.  BeginFrame - sets up new target in render graph
        // 2.  Add everything you need to the render graph
        // 3.  RunRenderGraph - runs the graph, rendering things to main render target
        // 4.  Render any additional stuff to main render target on top of previously rendered
        // information
        // 5.  EndFrame

        // Clients need to call this every frame in order for various subsystems to release
        // temporary per-frame allocated objects.
        // Also sets up the viewport according to SetViewportInfo
        // and the topmost presentation dimensions.  Expects there to be exactly one presentation
        // dimension pushed at this point.
        // This also starts a render target in the render graph.
        virtual void BeginFrame(bool firstFrame) = 0;

        // This runs through the added tasks in reverse order.  This is used to render dependencies
        // before rendering to the main render target.
        virtual void RunRenderTasks() = 0;
        // Now you can render to the main render target if you want to render over the top
        // of everything.
        // Next call end frame.
        virtual void EndFrame() = 0;
    };
}
}

#endif