summaryrefslogtreecommitdiffstats
path: root/src/Runtime/Source/Qt3DSRuntimeRender/RendererImpl/Qt3DSRendererImplLayerRenderData.h
blob: 4e237b0b3fbd956cf71420daff316d57f91aa64f (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
/****************************************************************************
**
** 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_RENDERER_IMPL_LAYER_RENDER_DATA_H
#define QT3DS_RENDERER_IMPL_LAYER_RENDER_DATA_H
#include "Qt3DSRender.h"
#include "Qt3DSRendererImplLayerRenderPreparationData.h"
#include "Qt3DSRenderResourceBufferObjects.h"

namespace qt3ds {
namespace render {

struct AdvancedBlendModes
{
    enum Enum {
        None = 0,
        Overlay,
        ColorBurn,
        ColorDodge
    };
};
    struct QT3DS_AUTOTEST_EXPORT SLayerRenderData : public SLayerRenderPreparationData
    {

        // Layers can be rendered offscreen for many reasons; effects, progressive aa,
        // or just because a flag forces it.  If they are rendered offscreen we can then
        // cache the result so we don't render the layer again if it isn't dirty.
        CResourceTexture2D m_LayerTexture;
        CResourceTexture2D m_TemporalAATexture;
        // Sometimes we need to render our depth buffer to a depth texture.
        CResourceTexture2D m_LayerDepthTexture;
        CResourceTexture2D m_LayerPrepassDepthTexture;
        CResourceTexture2D m_LayerWidgetTexture;
        CResourceTexture2D m_LayerSsaoTexture;
        // if we render multisampled we need resolve buffers
        CResourceTexture2D m_LayerMultisampleTexture;
        CResourceTexture2D m_LayerMultisamplePrepassDepthTexture;
        CResourceTexture2D m_LayerMultisampleWidgetTexture;
        // the texture contains the render result inclusive post effects
        NVRenderTexture2D *m_LayerCachedTexture;

        NVRenderTexture2D *m_AdvancedBlendDrawTexture;
        NVRenderTexture2D *m_AdvancedBlendBlendTexture;
        qt3ds::render::NVRenderFrameBuffer *m_AdvancedModeDrawFB;
        qt3ds::render::NVRenderFrameBuffer *m_AdvancedModeBlendFB;

        // True if this layer was rendered offscreen.
        // If this object has no value then this layer wasn't rendered at all.
        SOffscreenRendererEnvironment m_LastOffscreenRenderEnvironment;

        // GPU profiler per layer
        NVScopedRefCounted<IRenderProfiler> m_LayerProfilerGpu;

        SCamera m_SceneCamera;
        QT3DSVec2 m_SceneDimensions;

        // ProgressiveAA algorithm details.
        QT3DSU32 m_ProgressiveAAPassIndex;
        // Increments every frame regardless to provide appropriate jittering
        QT3DSU32 m_TemporalAAPassIndex;
        // Ensures we don't stop on an in-between frame; we will run two frames after the dirty flag
        // is clear.
        QT3DSU32 m_NonDirtyTemporalAAPassIndex;
        QT3DSF32 m_TextScale;

        volatile QT3DSI32 mRefCount;
        Option<QT3DSVec3> m_BoundingRectColor;
        NVRenderTextureFormats::Enum m_DepthBufferFormat;

        QSize m_previousDimensions;

        SLayerRenderData(SLayer &inLayer, Qt3DSRendererImpl &inRenderer);

        virtual ~SLayerRenderData();

        void PrepareForRender();

        // Internal Call
        void PrepareForRender(const QSize &inViewportDimensions) override;

        NVRenderTextureFormats::Enum GetDepthBufferFormat();
        NVRenderFrameBufferAttachments::Enum
        GetFramebufferDepthAttachmentFormat(NVRenderTextureFormats::Enum depthFormat);

        // Render this layer assuming viewport and RT are setup.  Just renders exactly this item
        // no effects.
        void RenderDepthPass(bool inEnableTransparentDepthWrite = false);
        void RenderAoPass();
        void RenderFakeDepthMapPass(NVRenderTexture2D *theDepthTex,
                                    NVRenderTextureCube *theDepthCube);
        void RenderShadowMapPass(CResourceFrameBuffer *theFB);
        void RenderShadowCubeBlurPass(CResourceFrameBuffer *theFB, NVRenderTextureCube *target0,
                                      NVRenderTextureCube *target1, QT3DSF32 filterSz, QT3DSF32 clipFar);
        void RenderShadowMapBlurPass(CResourceFrameBuffer *theFB, NVRenderTexture2D *target0,
                                     NVRenderTexture2D *target1, QT3DSF32 filterSz, QT3DSF32 clipFar);

        void Render(CResourceFrameBuffer *theFB = NULL);
        void ResetForFrame() override;

        void CreateGpuProfiler();
        void StartProfiling(CRegisteredString &nameID, bool sync);
        void EndProfiling(CRegisteredString &nameID);
        void StartProfiling(const char *nameID, bool sync);
        void EndProfiling(const char *nameID);
        void AddVertexCount(QT3DSU32 count);

        void RenderToViewport();
        // Render this layer's data to a texture.  Required if we have any effects,
        // prog AA, or if forced.
        void RenderToTexture();

        void ApplyLayerPostEffects();

        void RunnableRenderToViewport(qt3ds::render::NVRenderFrameBuffer *theFB);

        void AddLayerRenderStep();

        void RenderRenderWidgets();

#ifdef ADVANCED_BLEND_SW_FALLBACK
        void BlendAdvancedEquationSwFallback(NVRenderTexture2D *drawTexture,
                                             NVRenderTexture2D *m_LayerTexture,
                                             AdvancedBlendModes::Enum blendMode);
#endif
        // test method to render this layer to a given view projection without running the entire
        // layer setup system.  This assumes the client has setup the viewport, scissor, and render
        // target
        // the way they want them.
        void PrepareAndRender(const QT3DSMat44 &inViewProjection);

        SOffscreenRendererEnvironment CreateOffscreenRenderEnvironment() override;
        IRenderTask &CreateRenderToTextureRunnable() override;

        void addRef();
        void release();

    protected:
        // Used for both the normal passes and the depth pass.
        // When doing the depth pass, we disable blending completely because it does not really make
        // sense
        // to write blend equations into
        void RunRenderPass(TRenderRenderableFunction renderFn, bool inEnableBlending,
                           bool inEnableDepthWrite, bool inEnableTransparentDepthWrite,
                           QT3DSU32 indexLight, const SCamera &inCamera,
                           CResourceFrameBuffer *theFB = NULL);
#ifdef ADVANCED_BLEND_SW_FALLBACK
        //Functions for advanced blending mode fallback
        void SetupDrawFB(bool depthEnabled);
        void BlendAdvancedToFB(DefaultMaterialBlendMode::Enum blendMode, bool depthEnabled,
                               CResourceFrameBuffer *theFB);
#endif
    };
}
}
#endif