Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

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
/*
Copyright (c) 2015 DIVIDE-Studio
Copyright (c) 2009 Ionut Cava

This file is part of DIVIDE Framework.

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software
and associated documentation files (the "Software"), to deal in the Software
without restriction,
including without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software
is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

*/

#ifndef _RENDERING_COMPONENT_H_
#define _RENDERING_COMPONENT_H_

#include "SGNComponent.h"
#include "Core/Math/Headers/MathMatrices.h"
#include "Platform/Video/Headers/GFXDevice.h"

namespace Divide {

class Sky;
class Material;
class GFXDevice;
class RenderBin;
class ImpostorBox;
class ShaderProgram;
class SceneGraphNode;
class ParticleEmitter;

namespace Attorney {
    class RenderingCompGFXDevice;
    class RenderingCompSceneGraph;
    class RenderingCompRenderBin;
    class RenderingCompPassCuller;
    class RenderingCompSceneNode;
};

class RenderingComponent : public SGNComponent {
    friend class Attorney::RenderingCompGFXDevice;
    friend class Attorney::RenderingCompSceneGraph;
    friend class Attorney::RenderingCompRenderBin;
    friend class Attorney::RenderingCompPassCuller;
    friend class Attorney::RenderingCompSceneNode;

   public:
    bool onDraw(RenderStage currentStage);
    void update(const U64 deltaTime);

    void renderGeometry(const bool state);
    void renderWireframe(const bool state);
    void renderBoundingBox(const bool state);
    void renderSkeleton(const bool state);

    inline bool renderGeometry() const { return _renderGeometry; }
    inline bool renderWireframe() const { return _renderWireframe; }
    inline bool renderBoundingBox() const { return _renderBoundingBox; }
    inline bool renderSkeleton() const { return _renderSkeleton; }

    void castsShadows(const bool state);
    void receivesShadows(const bool state);

    bool castsShadows() const;
    bool receivesShadows() const;

    U8 lodLevel() const;
    void lodLevel(U8 LoD);

    inline U32 drawOrder() const { return _drawOrder; }

    inline U32 commandIndex() const { return _commandIndex; }

    ShaderProgram* const getDrawShader(
        RenderStage renderStage = RenderStage::DISPLAY);

    U32 getDrawStateHash(RenderStage renderStage);

    void getMaterialColorMatrix(mat4<F32>& matOut) const;

    void getMaterialPropertyMatrix(mat4<F32>& matOut) const;

    inline Material* const getMaterialInstance() const { return _materialInstance; }

    void registerShaderBuffer(ShaderBufferLocation slot,
                              vec2<U32> bindRange,
                              ShaderBuffer& shaderBuffer);

    void unregisterShaderBuffer(ShaderBufferLocation slot);


    void registerTextureDependency(const TextureData& additionalTexture);
    void removeTextureDependency(const TextureData& additionalTexture);

#ifdef _DEBUG
    void drawDebugAxis();
#endif

    void setActive(const bool state);

    inline ImpostorBox* const getImpostor() const { return _impostor; }

   protected:
    friend class SceneGraphNode;
    RenderingComponent(Material* const materialInstance,
                       SceneGraphNode& parentSGN);
    ~RenderingComponent();

   protected:
    void boundingBoxUpdatedCallback();

    bool canDraw(const SceneRenderState& sceneRenderState,
                 RenderStage renderStage);

    bool preDraw(const SceneRenderState& renderState,
                 RenderStage renderStage) const;

    /// Called after the parent node was rendered
    void postDraw(const SceneRenderState& sceneRenderState,
                  RenderStage renderStage);

    GFXDevice::RenderPackage& getDrawPackage(const SceneRenderState& sceneRenderState,
                                             RenderStage renderStage);

    GFXDevice::RenderPackage& getDrawPackage(RenderStage renderStage);

    inline void drawOrder(U32 index) { _drawOrder = index; }

    inline void commandIndex(U32 index) { _commandIndex = index; }

   protected:
    Material* _materialInstance;
    /// LOD level is updated at every visibility check
    /// (SceneNode::isInView(...));
    U8  _lodLevel;  ///<Relative to camera distance
    U32 _drawOrder;
    U32 _commandIndex;
    /// System level check for shadowing
    bool _shadowMappingEnabled;
    bool _castsShadows;
    bool _receiveShadows;
    bool _renderGeometry;
    bool _renderWireframe;
    bool _renderBoundingBox;
    bool _renderSkeleton;
    bool _nodeSkinned;
    bool _isSubMesh;
    bool _impostorDirty;
    TextureDataContainer _textureDependencies;
    std::array<GFXDevice::RenderPackage, to_const_uint(RenderStage::COUNT)> _renderData;
    
    IMPrimitive* _boundingBoxPrimitive;
    IMPrimitive* _skeletonPrimitive;
    ImpostorBox* _impostor;

#ifdef _DEBUG
    vectorImpl<Line> _axisLines;
    IMPrimitive* _axisGizmo;
#endif
};

namespace Attorney {
class RenderingCompSceneNode {
    private:
        static GFXDevice::RenderPackage& getDrawPackage(RenderingComponent& renderable,
                                                        RenderStage renderStage) {
            return renderable.getDrawPackage(renderStage);
        }

    friend class Divide::Sky;
    friend class Divide::SubMesh;
    friend class Divide::ParticleEmitter;
};

class RenderingCompGFXDevice {
   private:
    static GFXDevice::RenderPackage& getDrawPackage(RenderingComponent& renderable,
                                                    const SceneRenderState& sceneRenderState,
                                                    RenderStage renderStage) {
        return renderable.getDrawPackage(sceneRenderState, renderStage);
    }

    static void commandIndex(RenderingComponent& renderable, U32 index) {
        renderable.commandIndex(index);
    }

    friend class Divide::GFXDevice;
};

class RenderingCompSceneGraph {
   private:
    static void boundingBoxUpdatedCallback(RenderingComponent& renderable) {
        renderable.boundingBoxUpdatedCallback();
    }

    friend class Divide::SceneGraphNode;
};

class RenderingCompRenderBin {
   private:
    static const GFXDevice::RenderPackage& getRenderData(RenderingComponent& renderable,
                                                         RenderStage renderStage) {
        return renderable._renderData[to_uint(renderStage)];
    }

    static void postDraw(RenderingComponent& renderable,
                         const SceneRenderState& sceneRenderState,
                         RenderStage renderStage) {
        renderable.postDraw(sceneRenderState, renderStage);
    }

    static void drawOrder(RenderingComponent& renderable, U32 index) {
        renderable.drawOrder(index);
    }

    friend class Divide::RenderBin;
};

class RenderingCompPassCuller {
   private:
    static bool canDraw(RenderingComponent& renderable,
                        const SceneRenderState& sceneRenderState,
                        RenderStage renderStage) {
        return renderable.canDraw(sceneRenderState, renderStage);
    }

    friend class Divide::RenderPassCuller;
};

};  // namespace Attorney
};  // namespace Divide
#endif

Commits for Divide-Framework/trunk/Source Code/Graphs/Components/Headers/RenderingComponent.h

Diff revisions: vs.
Revision Author Commited Message
557 Diff Diff IonutCava picture IonutCava Tue 10 Nov, 2015 12:00:20 +0000

[IonutCava]
- Gather all rendering calls from glVertexArray and glGenericVertexData into a single function in glResources: submitRenderCommand.
— This allows both classes to interpret GenericDrawCommands in the same way
- Use unsigned ints for all hasehs instead of size_t to avoid negative number hashes (useful for debugging)

551 Diff Diff IonutCava picture IonutCava Thu 05 Nov, 2015 17:08:03 +0000

[IonutCava]
- Streamline RenderPass/RenderBin/RenderPassCuller logic:
— Separate culling from updating nodes
— Improve sorting and batching
- Cleanups and sanity checks
- Replace some std::bind calls with lambdas

549 Diff Diff IonutCava picture IonutCava Wed 04 Nov, 2015 22:19:15 +0000

[IonutCava]
- Axis gizmo on/off toggle fixes
- Removed the manual call to makeTextureResident in RenderingComponent. Used registerTextureDependency instead
- Small cleanup in Material class

541 Diff Diff IonutCava picture IonutCava Thu 29 Oct, 2015 17:03:27 +0000

[IonutCava]
- Initial work on multi-threading the main loop (experimental. unstable):
— Multi-threaded frustum culling
— Multi-threaded particle update system

524 Diff Diff IonutCava picture IonutCava Thu 08 Oct, 2015 16:14:58 +0000

[IonutCava]
- Profiler guided optimizations:
— Replace most hashMaps with vectors where the common access pattern is linear (e.g. SceneGraphNode’s child list)
— Specify ShaderBuffer access patters at creation time to properly inform the rendering API
— Fix and optimise the LockManager & BufferLockManager classes
— Add a AtomicWrapper class that allows assignment and copy-constructions for atomic variables
-— This allows us to use vector of atomic bools for BB creation for SkinnedSubMesh objects

517 Diff Diff IonutCava picture IonutCava Wed 30 Sep, 2015 16:12:52 +0000

[IonutCava]
- Small performance optimizations

505 Diff Diff IonutCava picture IonutCava Tue 25 Aug, 2015 22:15:49 +0000

[IonutCava]
- Finish the draw command caching System
- Cleanup AnimationComponent class

504 Diff Diff IonutCava picture IonutCava Tue 25 Aug, 2015 16:17:38 +0000

[IonutCava]
- Better caching of draw commands (W.I.P.)
- Remove unused occlusion culling code. Will be replaced with Hi-Z based culling

484 Diff Diff IonutCava picture IonutCava Sun 09 Aug, 2015 13:48:51 +0000

[Ionut]
- Use explicit attribute locations with IMPrimitive objects (reducing the number of glGetAttribLocation calls to zero)
- Remove “renderCallback” system in scenes as it wasn’t used and caused unnecessary indirections
- A few cleanups and const correctness changes

475 IonutCava picture IonutCava Fri 19 Jun, 2015 16:12:42 +0000

[Ionut]
- More (hackish) occlusion query code