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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/*
   Copyright (c) 2014 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 _SCENE_GRAPH_NODE_H_
#define _SCENE_GRAPH_NODE_H_

#define SCENE_GRAPH_PROCESS(pointer) DELEGATE_BIND(&SceneGraph::process(),pointer)

#include "SceneNode.h"
#include <boost/atomic.hpp>
#include "Utility/Headers/StateTracker.h"
#include "Graphs/Components/Headers/SGNComponent.h"
#include "Graphs/Components/Headers/PhysicsComponent.h"
#include "Graphs/Components/Headers/AnimationComponent.h"
#include "Graphs/Components/Headers/NavigationComponent.h"

class Transform;
class SceneGraph;
class SceneState;
// This is the scene root node. All scene node's are added to it as child nodes
class SceneRoot : public SceneNode{
public:
    SceneRoot() : SceneNode("root",TYPE_ROOT)
    {
        _renderState.useDefaultMaterial(false);
        setState(RES_LOADED);
    }

    bool onDraw(SceneGraphNode* const sgn, const RenderStage& currentStage)       { return true; }
    bool unload()                                      {return true;}
    bool load(const std::string& name)                 {return true;}
    bool computeBoundingBox(SceneGraphNode* const sgn);

protected:
    void render(SceneGraphNode* const sgn, const SceneRenderState& sceneRenderState, const RenderStage& currentRenderStage) {}
    void postLoad(SceneGraphNode* const sgn)           { SceneNode::postLoad(sgn); }
};

// Add as many SceneTransform nodes are needed as parent nodes for any scenenode to create complex transforms in the scene
class SceneTransform : public SceneNode {
public:
    SceneTransform() : SceneNode(TYPE_TRANSFORM)
    {
        _renderState.useDefaultMaterial(false);
        setState(RES_LOADED);
    }
    
    void render(SceneGraphNode* const sgn, const SceneRenderState& sceneRenderState, const RenderStage& currentRenderStage) {}
    void postLoad(SceneGraphNode* const sgn)           {return;}
    bool onDraw(const RenderStage& currentStage)       {return true;}
    bool unload()                                      {return true;}
    bool load(const std::string& name)                 {return true;}
    bool computeBoundingBox(SceneGraphNode* const sgn) {return true;}
};

class SceneGraphNode : public GUIDWrapper, private boost::noncopyable{
public:
    typedef Unordered_map<std::string, SceneGraphNode*> NodeChildren;
    typedef Unordered_map<SGNComponent::ComponentType, SGNComponent* > NodeComponents;

     ///Usage context affects lighting, navigation, physics, etc
    enum UsageContext {
        NODE_DYNAMIC = 0,
        NODE_STATIC
    };

    SceneGraphNode(SceneGraph* const sg, SceneNode* const node);
    ~SceneGraphNode();

    bool unload();
    /// Draw the current scene graph node
    void render(const SceneRenderState& sceneRenderState, const RenderStage& currentRenderStage);
    /// Update bounding boxes
    void checkBoundingBoxes();
    /// Apply current transform to the node's BB
    void updateBoundingBoxTransform(const mat4<F32>& transform);
    /// Called from SceneGraph "sceneUpdate"
    void sceneUpdate(const U64 deltaTime, SceneState& sceneState);
    /// Called when the camera updates the view matrix and/or the projection matrix
    void onCameraChange();
    /*Node Management*/
    template<class T = SceneNode>
    ///Always use the level of redirection needed to reduce virtual function overhead
    ///Use getNode<SceneNode> if you need material properties for ex. or getNode<SubMesh> for animation transforms
    inline T* getNode() const {assert(_node != nullptr); return dynamic_cast<T*>(_node);}

    SceneGraphNode* addNode(SceneNode* const node,const std::string& name = "");
    void			removeNode(SceneGraphNode* node);
    ///Find a node in the graph based on the SceneGraphNode's name
    ///If sceneNodeName = true, find a node in the graph based on the SceneNode's name
    SceneGraphNode* findNode(const std::string& name, bool sceneNodeName = false);
    ///Find the graph nodes whom's bounding boxes intersects the given ray
    void Intersect(const Ray& ray, F32 start, F32 end, vectorImpl<SceneGraphNode* >& selectionHits);

    ///Selection helper functions
           void setSelected(bool state);
    inline bool isSelected()	                const {return _selected;}
    inline bool isSelectable()                  const {return _isSelectable;}
    inline void setSelectable(const bool state)       {_isSelectable = state;}

    const  std::string& getName() const {return _name;}
    /*Node Management*/

    /*Parent <-> Children*/
                SceneGraphNode*  getRoot()        const;
    inline      SceneGraphNode*  getParent()      const {return _parent;}
    inline      NodeChildren&    getChildren()          {return _children;}
                void             setParent(SceneGraphNode* const parent);
    /*Parent <-> Children*/

    /*Bounding Box Management*/
    void setInitialBoundingBox(const BoundingBox& initialBoundingBox);

    inline       BoundingBox&     getBoundingBox()                {return _boundingBox;}
    inline const BoundingBox&     getBoundingBoxConst()    const  {return _boundingBox;}
    inline       BoundingSphere&  getBoundingSphere()             {return _boundingSphere;}
    inline const BoundingSphere&  getBoundingSphereConst() const  {return _boundingSphere; }
    inline const BoundingBox&     getInitialBoundingBox()  const  {return _initialBoundingBox; }

    void getBBoxes(vectorImpl<BoundingBox >& boxes) const;
    /*Bounding Box Management*/

    /*Transform management*/
    Transform* const getTransform();
               void	 setTransform(Transform* const t);

    Transform* const getPrevTransform();
               void  setPrevTransform(Transform* const t);

    inline     void  silentDispose(const bool state)       {_silentDispose = state;}
    inline     void  useDefaultTransform(const bool state) {_noDefaultTransform = !state;}

    /*Transform management*/

    /*Node State*/
    inline void setActive(bool state) {_wasActive = _active; _active = state;}
    inline void restoreActive()       {_active = _wasActive;}
    inline void	scheduleDeletion()    {_shouldDelete = true;}

    inline bool inView()   const {return _inView;}
    inline bool isReady()  const {return _isReady;}
    inline bool isActive() const {return _active;}
    /*Node State*/

    inline void setCastsShadows(const bool state)    {_castsShadows = state;}
    inline void setReceivesShadows(const bool state) {_receiveShadows = state;}

    bool getCastsShadows()    const;
    bool getReceivesShadows() const;

    void getShadowCastersAndReceivers(vectorImpl<const SceneGraphNode* >& casters, vectorImpl<const SceneGraphNode* >& receivers, bool visibleOnly = false) const;

    inline U32  getInstanceID() const {return _instanceID;}
    inline U32  getChildQueue() const {return _childQueue;}
    inline void incChildQueue()       {_childQueue++;}
    inline void decChildQueue()       {_childQueue--;}

    inline const UsageContext&      getUsageContext()          const {return _usageContext;}
    inline void  setUsageContext(const UsageContext& newContext)           {_usageContext = newContext;}

    void addBoundingBox(const BoundingBox& bb, const SceneNodeType& type);
    void setBBExclusionMask(U32 bbExclusionMask) {_bbAddExclusionList = bbExclusionMask;}

    inline U64 getElapsedTime() const {return _elapsedTime;}

    inline void setComponent(SGNComponent::ComponentType type, SGNComponent* component) { SAFE_UPDATE(_components[type], component); }

    template<class T>
    inline T* getComponent() { assert(false && "INVALID COMPONENT"); return nullptr; }
    template<>
    inline AnimationComponent* getComponent() { return dynamic_cast<AnimationComponent*>(_components[SGNComponent::SGN_COMP_ANIMATION]); }
    template<>
    inline NavigationComponent* getComponent() { return dynamic_cast<NavigationComponent*>(_components[SGNComponent::SGN_COMP_NAVIGATION]); }
    template<>
    inline PhysicsComponent* getComponent() { return dynamic_cast<PhysicsComponent*>(_components[SGNComponent::SGN_COMP_PHYSICS]); }
    
    inline StateTracker<bool>& getTrackedBools() { return _trackedBools; }

    inline const mat4<F32>& getMaterialColorMatrix()    const { return _materialColorMatrix; }
    inline const mat4<F32>& getMaterialPropertyMatrix() const { return _materialPropertyMatrix; }

protected:
    friend class RenderPassCuller;
    inline void inView(const bool isInView) { _inView = isInView; isInViewCallback(); }

private:
    inline void setName(const std::string& name){_name = name;}
    inline void scheduleDrawReset(RenderStage currentStage) { _drawReset[currentStage] = true; }
           void isInViewCallback();

    /// Called if the current node is in view and is about to be rendered
    bool onDraw(RenderStage renderStage); 
    /// Called after the current node was rendered
    void postDraw(RenderStage renderStage);

private:
    SceneNode* _node;
    NodeChildren _children;
    SceneGraphNode *_parent;
    SceneGraph     *_sceneGraph;
    boost::atomic<bool> _active;
    boost::atomic<bool> _loaded;
    boost::atomic<bool> _inView;
    //Used to skip certain BB's (sky, lights, etc);
    U32 _bbAddExclusionList;
    bool _selected;
    bool _isSelectable;
    bool _wasActive;
    bool _noDefaultTransform;
    bool _sorted;
    bool _silentDispose;
    bool _castsShadows;
    bool _receiveShadows;
    boost::atomic<bool> _boundingBoxDirty;
    boost::atomic<bool> _isReady; //<is created and has a valid transform
    bool _shouldDelete;
    ///_initialBoundingBox is a copy of the initialy calculate BB for transformation
    ///it should be copied in every computeBoungingBox call;
    BoundingBox _initialBoundingBox, _initialBoundingBoxCache;
    BoundingBox _boundingBox;
    BoundingSphere _boundingSphere; ///<For faster visibility culling

    Transform*	_transform;
    Transform*  _transformPrevious;
    mat4<F32>   _transformGlobalMatrixCache;

    U32 _instanceID;
    U32 _childQueue;
    D32 _updateTimer;
    U64 _elapsedTime;//< the total amount of time that passed since this node was created
    std::string _name;

    UsageContext _usageContext;
    NodeComponents _components;

    Unordered_map<RenderStage, bool> _drawReset;

    StateTracker<bool> _trackedBools;

    mat4<F32> _materialColorMatrix;
    mat4<F32> _materialPropertyMatrix;

};

#endif

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

Diff revisions: vs.
Revision Author Commited Message
286 Diff Diff IonutCava picture IonutCava Fri 18 Jul, 2014 16:32:03 +0000

[Ionut] [[BR]]

    • very buggy commit ** [[BR]]

- New rendering pipeline: [[BR]]
— Bumped OpenGL version to 4.4 [[BR]]
— Command based rendering. GFXDevice dispatches rendering commands to their respective buffers [[BR]]
— State changing is exclusively controlled by the GFXDevice class [[BR]]
— Material properties and transform matrices are stored in shader storage buffers that are updated after culling and uploaded once per RenderPass. Objects use drawIDs to index data in shaders [[BR]]
— Removed all custom matrices and other, per shader, bind data [[BR]]
— Removed per node light data. Light culling and shader buffers will replace the old light management system [[BR]]
— Framebuffers now use the Texture class for attachments [[BR]]
— Sampler objects now work like RenderStateBlocks. GL_API handles them and stores them in a hash indexed map [[BR]]
— Removed “prepareMaterial” calls. Pre-draw material setup is now only limited to texture binding [[BR]]
— Moved immediate mode emulation and primitive rendering from API level to GFXDevice level [[BR]]
— Framebuffer rendering must be completed with a call to end() to ensure proper MSAA resolve (asserts, otherwise) [[BR]]
- Fixed hash code generation for RenderStateBlock (and now, glSamplerObject) using boost::hash_combine [[BR]]
- Temporarily disabled XML caching for materials [[BR]]

285 Diff Diff IonutCava picture IonutCava Wed 02 Jul, 2014 18:33:25 +0000

[Ionut][[BR]]
- Per SGN shader data implementation part 1.75 / 2 [[BR]]
— Upload node data into a SSBO in one single call [[BR]]
- Re-factored LightManager to upload light info and shadow info in single upload calls [[BR]]
- Improved GUIConsole load performance by using a boost::circular_buffer for initial messages [[BR]]

284 Diff Diff IonutCava picture IonutCava Tue 01 Jul, 2014 20:54:08 +0000

[Ionut][[BR]]
- Per SGN shader data implementation part 1 / 2 [[BR]]
— Gather node info and transforms into custom struct for visible nodes and store them in a GFXDevice local vector [[BR]]
- Removed “prepareDepthMaterial” and added depthPass flag to “prepareMaterial” [[BR]]

281 Diff Diff IonutCava picture IonutCava Sat 28 Jun, 2014 20:55:30 +0000

[Ionut] [[BR]]
- Added a basic and primitive state tracking class [[BR]]

280 Diff Diff IonutCava picture IonutCava Sat 28 Jun, 2014 19:11:37 +0000

[Ionut] [[BR]]
- Improve ClipPlane management (bunch equations into the matrix shader buffer) [[BR]]
- Immediate mode emulation primitives set their own state based on specified hash instead of relying on state functions to be defined [[BR]]
- updateStates() function is now called right before the actual draw call to facilitate future batching work [[BR]]
- added tracked bool values (similar to those in ShaderInfo) to SGN class to fix selection bug. [[BR]]
— will probably create a “stateTracker” class to allow multiple classes to use tracked variables without all of the code duplication [[BR]]

273 Diff Diff IonutCava picture IonutCava Wed 11 Jun, 2014 20:34:00 +0000

[Ionut] [[BR]]
- Improved batching part2: [[BR]]
— Moved all bone transformation matrices upload from uniform functions in SceneNode to Shader Storage Buffers in AnimationController class with updates controlled by SceneGraphNode’s AnimationComponent [[BR]]
-— No double-buffering or efficient mapping of data yet. Just raw buffer updates [[BR]]
— Replaced all RenderStateBlock* pointers with I64 hash values [[BR]]
-— Will be used later in draw commands as per-shader state hash [[BR]]
— Moved getShaderProgram from Material to Material::ShaderInfo [[BR]]
-— Improved redundant uniform checks [[BR]]
— Improved texture unit changing in case of redundant texture bind case (i.e. skip changing the texture unit) [[BR]]
[[BR]]
- Improved float and double comparison functions using algorithms described in http://randomascii.wordpress.com/2012/02/13/dont-store-that-in-a-float/ [[BR]]
- Added a new utility function, DIVIDE_ASSERT, to more easily bind an assert check with a specific message [[BR]]
- Added missing files from Forward+ renderer’s initial code [[BR]]

264 Diff Diff k1ngp1n picture k1ngp1n Tue 27 May, 2014 13:04:38 +0000

[Ionut] [[BR]]
- New camera system: [[BR]]
— Stack based (push/pop active camera) [[BR]]
— Per camera frustum [[BR]]
— Per camera projection [[BR]]
— Shadow mapping now uses the new camera system (each light has a shadow camera) [[BR]]
[[BR]]
- New terrain, water and vegetation system: [[BR]]
— Direct import of terrain from L3DT both as 8-bit grayscale and 16-bit raw formats [[BR]]
— Multiple alpha maps for texture splatting support [[BR]]
— Per texture detail map support [[BR]]
— Transform feedback based visibility culling for vegetation [[BR]]
— Alpha-map based vegetation placing on terrain [[BR]]
— Water now uses a refraction map instead of alpha blending for better refraction effects [[BR]]
[[BR]]
- SceneGraph improvements: [[BR]]
— Better bounding box updates from child to parent [[BR]]
— Better onDraw / postDraw implementation [[BR]]
[[BR]]
- Performance improvements: [[BR]]
— Batch 2D rendering tasks together as much as possible[[BR]]
— Improve renderStateBlock hash generation for better sorting [[BR]]
— Move most state related gfx changes from API implementation to the GFXDevice class [[BR]]
— Move viewport stack to the GFXDevice class [[BR]]
— Added various performance counters (frame duration with round-robin query system, draw call count, etc) [[BR]]
— Fixed and improved clip plane management [[BR]]
— Delete client-side texture data after GPU upload [[BR]]
[[BR]]
- New features: [[BR]]
— Added callback support to the Task class so that a specific task may call a function in the main thread upon completion [[BR]]
— Added mouse-wheel zoom support to Orbit/ThirdPerson cameras [[BR]]
— Added 2D Texture Array support (e.g. used for terrain textures) [[BR]]

260 Diff Diff k1ngp1n picture k1ngp1n Sat 03 May, 2014 19:33:41 +0000

[Ionut] [[BR]]
- More work on CSM. Reverted back to VSM to allow easier blurring and filtering [[BR]]
- Rewrote FrameBuffer classes to fix MSAA and memory leaks that occurred on resize (double creation of textures) [[BR]]
— Removed FBType. FrameBuffer types depend only on attachment types and if it’s MSAA enabled or not [[BR]]
- Rewrote RenderState classes to be API agnostic [[BR]]
- Bug fixes in math classes [[BR]]
- Changed “resolution change” logic [[BR]]
- Simplified some options in config.xml [[BR]]
- Improved per-light shadow options [[BR]]

259 Diff Diff k1ngp1n picture k1ngp1n Sun 27 Apr, 2014 18:24:52 +0000

[Ionut][[BR]]
- Implemented Exponential Stable Cascaded Shadow Maps for directional lights (still buggy, but basically working) [[BR]]
— CSM settings (resolution, number of splits, etc) are part of the scene render state [[BR]]
- SGN can skip rendering for the current frame if they are not ready (e.g. OnDraw can now return false or materials can fail to bind) [[BR]]
- Frustum class is now using the Plane class [[BR]]
- Removed Math SIMD implementation as the compiler generated code will always be faster and safer [[BR]]
- Added a “STUBBED” macro for outputing to the error stream of important messages (instead of using #pragma message) [[BR]]
- Added “freeze time” logic to pause/resume updates with or without freezing the GUI too [[BR]]
- Added “processGUI” method the every Scene class to separate time-sensitive GUI updates from game logic loop [[BR]]
- GLSL <-> Vertex Buffer bind locations are automatically set for every vertex shader [[BR]]
- Added basic support for compute shaders [[BR]]
- Removed most OS define checks to make porting to a new platform easier [[BR]]
- Texture transparency check per-pixel is now using OpenMP [[BR]]
- Texture samplers can now set a border color for CLAMP_TO_BORDER wrap mode [[BR]]
- Removed “Object” suffix from GFX Classes (pixel buffer, vertex buffer, frame buffer, etc) [[BR]]
- Stop processing scene input when application looses focus [[BR]]
- SceneGraphNode class is now responsible for updating SGNComponents on draw and calling its _node’s OnDraw method [[BR]]
- UBOs can now list all of the active uniforms inside a block with info such as type and offset [[BR]]
- Removed deprecated ‘GLCheck’ macro [[BR]]
- A lot of bug fixes and performance improvements in various places [[BR]]

258 k1ngp1n picture k1ngp1n Tue 15 Apr, 2014 15:26:22 +0000

[Ionut]
- Bumped minimum OpenGL required version to 4.3 (any Fermi and GCN 1.1 GPU)
- Fixed an issue with opacity maps
- Improved loading times by optimizing console output system and various optimizations in DVDConverter
- Create GUIConsole when needed (not on load)
- Moved common control code to the Scene class