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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#include "Headers/SceneGraph.h"

#include "Scenes/Headers/SceneState.h"
#include "Core/Math/Headers/Transform.h"
#include "Geometry/Shapes/Headers/Object3D.h"
#include "Geometry/Material/Headers/Material.h"
#include "Geometry/Shapes/Headers/SkinnedSubMesh.h"
#include "Environment/Water/Headers/Water.h"
#include "Environment/Terrain/Headers/Terrain.h"
#include "Hardware/Video/Shaders/Headers/ShaderProgram.h"

#pragma message("TODO (Prio 1): - Bake transforms inside vbs for STATIC nodes")
#pragma message("               - assert if 'getTransform()' is called for such nodes. Use default identity matrix for static nodes")
#pragma message("               - premultiply positions AND normals AND tangents AND bitangets to avoid artifacts")
#pragma message("               - Ionut")

SceneGraphNode::SceneGraphNode(SceneGraph* const sg, SceneNode* const node) : GUIDWrapper(),
                                                  _sceneGraph(sg),
                                                  _node(node),
                                                  _elapsedTime(0ULL),
                                                  _parent(nullptr),
                                                  _transform(nullptr),
                                                  _transformPrevious(nullptr),
                                                  _loaded(true),
                                                  _wasActive(true),
                                                  _active(true),
                                                  _inView(false),
                                                  _selected(false),
                                                  _isSelectable(false),
                                                  _noDefaultTransform(false),
                                                  _sorted(false),
                                                  _silentDispose(false),
                                                  _boundingBoxDirty(true),
                                                  _shouldDelete(false),
                                                  _isReady(false),
                                                  _castsShadows(true),
                                                  _receiveShadows(true),
                                                  _updateTimer(GETMSTIME()),
                                                  _childQueue(0),
                                                  _bbAddExclusionList(0),
                                                  _usageContext(NODE_DYNAMIC)
{
    assert(_node != nullptr);

    _components[SGNComponent::SGN_COMP_ANIMATION]  = nullptr;
    _components[SGNComponent::SGN_COMP_NAVIGATION] = New NavigationComponent(this);
    _components[SGNComponent::SGN_COMP_PHYSICS]    = New PhysicsComponent(this);
    _instanceID = node->getReferenceCount();
    memset(_trackedBools, false, 10 * sizeof(bool));
}

///If we are destroying the current graph node
SceneGraphNode::~SceneGraphNode(){
    unload();

    PRINT_FN(Locale::get("DELETE_SCENEGRAPH_NODE"), getName().c_str());
    //delete children nodes recursively
    FOR_EACH(NodeChildren::value_type it, _children){
        SAFE_DELETE(it.second);
    }
    FOR_EACH(NodeComponents::value_type it, _components){
        SAFE_DELETE(it.second);
    }
    //and delete the transform bound to this node
    SAFE_DELETE(_transform);
    _children.clear();
    _components.clear();
}

void SceneGraphNode::addBoundingBox(const BoundingBox& bb, const SceneNodeType& type) {
    if(!bitCompare(_bbAddExclusionList, type)){
        _boundingBox.Add(bb);
        if(_parent) _parent->getBoundingBox().setComputed(false);
    }
}

SceneGraphNode* SceneGraphNode::getRoot() const {
    return _sceneGraph->getRoot();
}

void SceneGraphNode::getBBoxes(vectorImpl<BoundingBox >& boxes ) const {
    FOR_EACH(const NodeChildren::value_type& it, _children){
        it.second->getBBoxes(boxes);
    }

    boxes.push_back(_boundingBox);
}

void SceneGraphNode::getShadowCastersAndReceivers(vectorImpl<const SceneGraphNode* >& casters, vectorImpl<const SceneGraphNode* >& receivers, bool visibleOnly) const {
   FOR_EACH(const NodeChildren::value_type& it, _children){
       it.second->getShadowCastersAndReceivers(casters, receivers, visibleOnly);
    }

    if (!visibleOnly || visibleOnly && _inView) {
        if (getCastsShadows())    casters.push_back(this);
        if (getReceivesShadows()) receivers.push_back(this);
    }
}

///When unloading the current graph node
bool SceneGraphNode::unload(){
    if (!_loaded) return true;

    //Unload every sub node recursively
    FOR_EACH(NodeChildren::value_type& it, _children){
        it.second->unload();
    }
    //Some debug output ...
    if(!_silentDispose && getParent() && _node){
        PRINT_FN(Locale::get("REMOVE_SCENEGRAPH_NODE"),_node->getName().c_str(), getName().c_str());
    }
    //if not root
    if (_node && getParent()){
        _node->decReferenceCount();
        if(_node->getReferenceCount() == 0) {
            RemoveResource(_node);
        }
    }
    _loaded = false;
    return true;
}

///Change current SceneGraphNode's parent
void SceneGraphNode::setParent(SceneGraphNode* const parent) {
    assert(parent != nullptr);
    assert(parent->getGUID() != getGUID());

    if(_parent){
        if (_parent->getGUID() == parent->getGUID())
            return;
        //Remove us from the old parent's children map
        NodeChildren::iterator it = _parent->getChildren().find(getName());
        _parent->getChildren().erase(it);
    }
    //Set the parent pointer to the new parent
    _parent = parent;
    //Add ourselves in the new parent's children map
    //Time to add it to the children map
    std::pair<Unordered_map<std::string, SceneGraphNode*>::iterator, bool > result;
    //Try and add it to the map
    result = _parent->getChildren().insert(std::make_pair(getName(),this));
    //If we had a collision (same name?)
    if(!result.second){
        ///delete the old SceneGraphNode and add this one instead
        SAFE_UPDATE((result.first)->second,this);
    }
    //That's it. Parent Transforms will be updated in the next render pass;
}

///Add a new SceneGraphNode to the current node's child list based on a SceneNode
SceneGraphNode* SceneGraphNode::addNode(SceneNode* const node,const std::string& name){
    //Create a new SceneGraphNode with the SceneNode's info
    SceneGraphNode* sceneGraphNode = New SceneGraphNode(_sceneGraph, node);
    //Validate it to be safe
    assert(sceneGraphNode);
    //We need to name the new SceneGraphNode
    //If we did not supply a custom name use the SceneNode's name
    std::string sgName(name.empty() ? node->getName() : name);
    //Name the new SceneGraphNode
    sceneGraphNode->setName(sgName);
     //Get the new node's transform
    Transform* nodeTransform = sceneGraphNode->getTransform();
    //If the current node and the new node have transforms,
    //Update the relationship between the 2
    Transform* currentTransform = getTransform();
    if(nodeTransform && currentTransform){
        //The child node's parent transform is our current transform matrix
        nodeTransform->setParentTransform(currentTransform);
    }
    //Set the current node as the new node's parent
    sceneGraphNode->setParent(this);
    node->incReferenceCount();
    //Do all the post load operations on the SceneNode
    //Pass a reference to the newly created SceneGraphNode in case we need transforms or bounding boxes
    node->postLoad(sceneGraphNode);
    //return the newly created node
    return sceneGraphNode;
}

//Remove a child node from this Node
void SceneGraphNode::removeNode(SceneGraphNode* node){
    //find the node in the children map
    NodeChildren::iterator it = _children.find(node->getName());
    //If we found the node we are looking for
    if(it != _children.end()) {
        //Remove it from the map
        _children.erase(it);
    }else{
        for(U8 i = 0; i < _children.size(); ++i)
            removeNode(node);
    }
    //Beware. Removing a node, does no unload it!
    //Call delete on the SceneGraphNode's pointer to do that
}

//Finding a node based on the name of the SceneGraphNode or the SceneNode it holds
//Switching is done by setting sceneNodeName to false if we pass a SceneGraphNode name
//or to true if we search by a SceneNode's name
SceneGraphNode* SceneGraphNode::findNode(const std::string& name, bool sceneNodeName){
    //Null return value as default
    SceneGraphNode* returnValue = nullptr;
     //Make sure a name exists
    if (!name.empty()){
        //check if it is the name we are looking for
        if ((sceneNodeName && _node->getName().compare(name) == 0) || getName().compare(name) == 0){
            // We got the node!
            return this;
        }

        //The current node isn't the one we wan't, so recursively check all children
        FOR_EACH(NodeChildren::value_type& it, _children){
            returnValue = it.second->findNode(name);
            // if it is not nullptr it is the node we are looking for so just pass it through
            if(returnValue != nullptr)
                return returnValue;
        }
    }

    // no children's name matches or there are no more children
    // so return nullptr, indicating that the node was not found yet
    return nullptr;
}

void SceneGraphNode::Intersect(const Ray& ray, F32 start, F32 end, vectorImpl<SceneGraphNode* >& selectionHits){

    if (isSelectable() && _boundingBox.Intersect(ray, start, end))
        selectionHits.push_back(this);

    FOR_EACH(NodeChildren::value_type& it, _children)
        it.second->Intersect(ray,start,end,selectionHits);
}

//This updates the SceneGraphNode's transform by deleting the old one first
void SceneGraphNode::setTransform(Transform* const t) {
    SAFE_UPDATE(_transform, t);
    // Update children
    FOR_EACH(NodeChildren::value_type& it, _children){
        Transform* nodeTransform = it.second->getTransform();
        if(nodeTransform)
            nodeTransform->setParentTransform(_transform);
    }
}

void SceneGraphNode::setPrevTransform(Transform* const t) {
    if(!t && _transformPrevious) {
        SAFE_DELETE(_transformPrevious);
        return;
    }

    if(!t) return;

    if(!_transformPrevious){
        _transformPrevious = New Transform();
        assert(_transformPrevious);
    }

    _transformPrevious->clone(t);
}

Transform* const SceneGraphNode::getPrevTransform(){
    if(!_noDefaultTransform && !_transformPrevious){
        _transformPrevious = New Transform();
        assert(_transformPrevious);
        _transformPrevious->clone(getTransform());
    }

    return _transformPrevious;
}

//Get the node's transform
Transform* const SceneGraphNode::getTransform(){
    //A node does not necessarily have a transform. If this is the case, we can either create a default one or return nullptr.
    //When creating a node we can specify if we do not want a default transform
    if(!_noDefaultTransform && !_transform){
        _transform = New Transform();
        assert(_transform);
        _isReady = true;
    }
    return _transform;
}

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

Diff revisions: vs.
Revision Author Commited Message
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]]

262 Diff Diff k1ngp1n picture k1ngp1n Tue 06 May, 2014 21:04:00 +0000

[Ionut] [[BR]]
- Some AI refactoring (basic AIEntity <-> AESOP interoperability) [[BR]]
- Some render batch sorting code refactored and fixed (wasn’t properly sorted in FINAL_STAGE) [[BR]]
- Simplified RenderStateBlockDescriptor and deferred hash value calculation [[BR]]
- Basic draw call count implementation [[BR]]
- Renamed some classes [[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 Diff Diff 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

256 Diff Diff k1ngp1n picture k1ngp1n Fri 11 Apr, 2014 17:23:24 +0000

[Ionut] [[BR]]
- Performance optimizations: [[BR]]
— Call SceneGraph::Update only once per frame (instead of once per draw call, as it was stupidly done now) [[BR]]
— Improve Shader programs' uniform system to allow better caching systems [[BR]]
— Use better caching system for Shader programs [[BR]]
— Use LOD for particle emitters (reduce count with distance for now) [[BR]]
- Every TrackedObject gets a GUID now [[BR]]
- Cleanup in SceneGraphNode class and SceneNode class (with derived classes as well) [[BR]]
- Some const-correctness fixes [[BR]]

254 Diff Diff k1ngp1n picture k1ngp1n Wed 09 Apr, 2014 15:25:42 +0000

[Ionut] [[BR]]
- Fixed a bug from previous commit with stringstream clearing [[BR]]
- Extended the SceneGraphNode component system to include navigation and physics components [[BR]]
- Code cleanups [[BR]]

253 Diff Diff k1ngp1n picture k1ngp1n Wed 09 Apr, 2014 11:30:54 +0000

[Ionut] [[BR]]
- Split SceneAnimator in global and per-instance data (SceneAnimator and AnimatorComponent) respectively [[BR]]
— Each SceneNode, sharing the same skinned mesh can have different animations with different timings now [[BR]]
- Fixed particle systems' billboarding issues [[BR]]
- More cleaning up of the Material class [[BR]]

250 k1ngp1n picture k1ngp1n Wed 02 Apr, 2014 12:36:36 +0000

[Ionut] [[BR]]
- More C++11 work [[BR]]
- Renamed “for_each” macro to “FOR_EACH” to avoid name conflicts with the C++11 function [[BR]]