Subversion Repository Public Repository

Divide-Framework

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

Diff Revisions 167 vs 168 for /trunk/Source Code/Graphs/SGNRenderCalls.cpp

Diff revisions: vs.
  @@ -1,5 +1,6 @@
1 1 #include "Headers/SceneGraphNode.h"
2 2
3 + #include "Scenes/Headers/SceneState.h"
3 4 #include "Core/Math/Headers/Transform.h"
4 5 #include "Managers/Headers/SceneManager.h"
5 6 #include "Geometry/Shapes/Headers/Mesh.h"
  @@ -7,6 +8,14 @@
7 8 #include "Geometry/Material/Headers/Material.h"
8 9 #include "Rendering/RenderPass/Headers/RenderQueue.h"
9 10
11 + bool SceneRoot::computeBoundingBox(SceneGraphNode* const sgn) {
12 + sgn->getBoundingBox().reset();
13 + for_each(SceneGraphNode::NodeChildren::value_type& s, sgn->getChildren()){
14 + sgn->addBoundingBox(s.second->getBoundingBoxTransformed(), s.second->getNode<SceneNode>()->getType());
15 + }
16 + return true;
17 + }
18 +
10 19 ///Please call in MAIN THREAD! Nothing is thread safe here (for now) -Ionut
11 20 void SceneGraphNode::checkBoundingBoxes(){
12 21 //Update order is very important!
  @@ -15,64 +24,61 @@
15 24 for_each(NodeChildren::value_type& it, _children){
16 25 it.second->checkBoundingBoxes();
17 26 }
18 - // don't update root;
19 - if(!getParent()) return;
20 27
21 - if(_node->getState() != RES_LOADED) return;
28 + if(_node->getState() != RES_LOADED)
29 + return;
30 +
22 31 //Compute the BoundingBox if it isn't already
23 32 if(!_boundingBox.isComputed()){
24 33 _node->computeBoundingBox(this);
25 34 _boundingSphere.fromBoundingBox(_boundingBox);
26 35 }
27 - if(_node->getDrawState()) {
28 - getRoot()->addBoundingBox(_boundingBox,_node->getType());
29 - }
30 - ///Recreate bounding boxes for current frame
36 +
37 + //Recreate bounding boxes for current frame
31 38 _node->updateBBatCurrentFrame(this);
32 39 }
33 40
34 41 //This function eats up a lot of processing power
35 - //It compute's the BoundingBoxes of all transformed nodes and updates transforms
42 + //It computes the BoundingBoxes of all transformed nodes and updates transforms
36 43 void SceneGraphNode::updateTransforms(){
37 44 //Better version: move to new thread with DoubleBuffering?
38 45 //Get our transform and our parent's as well
39 46 Transform* transform = getTransform();
40 - if(transform && _parent && _parent->getTransform()){
41 - Transform* parentTransform = _parent->getTransform();
42 - //If we have a transform and a parent's transform
43 - //Update the relationship between the two
44 - if(transform->getParentMatrix() != parentTransform->getMatrix()){
45 - transform->setParentMatrix(parentTransform->getMatrix());
46 - }
47 - updateBoundingBoxTransform();
47 + Transform* parentTransform = NULL;
48 + if(transform){
49 + parentTransform = (_parent != NULL ? _parent->getTransform() : NULL);
50 + transform->setParentTransform(parentTransform);
51 + if(_transform->isDirty() || (parentTransform && parentTransform->isDirty()))
52 + updateBoundingBoxTransform(_transform->getGlobalMatrix());
48 53 }
49 54
55 + _node->updateTransform(this);
56 +
50 57 for_each(NodeChildren::value_type& it, _children){
51 58 it.second->updateTransforms();
52 59 }
53 60 }
54 61
55 - void SceneGraphNode::updateBoundingBoxTransform(){
56 - //Transform the bounding box if we have a new transform
57 - if(_transform->isDirty()){
58 - _node->updateTransform(this);
62 + void SceneGraphNode::updateBoundingBoxTransform(const mat4<F32>& transform){
63 + if(!getParent())
64 + return;
59 65
60 - WriteLock w_lock(_queryLock);
61 - _boundingBox.Transform(_initialBoundingBox,_transform->getGlobalMatrix());
62 - //Update the bounding sphere
63 - _boundingSphere.fromBoundingBox(_boundingBox);
64 - }
66 + //Transform the bounding box if we have a new transform
67 + WriteLock w_lock(_queryLock);
68 + _boundingBox.Transform(_initialBoundingBox,transform);
69 + //Update the bounding sphere
70 + _boundingSphere.fromBoundingBox(_boundingBox);
65 71 }
66 72
67 73 ///Another resource hungry subroutine
68 74 ///After all bounding boxes and transforms have been updated,
69 75 ///perform Frustum Culling on the entire scene.
70 76 void SceneGraphNode::updateVisualInformation(){
71 - //Hold a pointer to the current active scene
72 - Scene* curentScene = GET_ACTIVE_SCENE();
73 77 //No point in updating visual information if the scene disabled object rendering
74 78 //or rendering of their bounding boxes
75 - if(!curentScene->renderState()->drawObjects() && !curentScene->renderState()->drawBBox()) return;
79 + if(!_currentSceneState->getRenderState().drawObjects() && !_currentSceneState->getRenderState().drawBBox())
80 + return;
81 +
76 82 //Bounding Boxes should be updated, so we can early cull now.
77 83 bool skipChildren = false;
78 84 //Skip all of this for inactive nodes.
  @@ -84,14 +90,14 @@
84 90 switch(GFX_DEVICE.getRenderStage()){
85 91 default: {
86 92 //Perform visibility test on current node
87 - _inView = _node->isInView(true,getBoundingBox(),getBoundingSphere());
93 + _inView = _node->isInView(getBoundingBox(),getBoundingSphere());
88 94 } break;
89 95
90 96 case SHADOW_STAGE: {
91 97 _inView = false;
92 98 if(_node->getMaterial()){
93 99 if(_node->getMaterial()->getCastsShadows()){
94 - _inView = _node->isInView(true,getBoundingBox(),getBoundingSphere());
100 + _inView = _node->isInView(getBoundingBox(),getBoundingSphere());
95 101 }
96 102 }
97 103 }break;
  @@ -106,6 +112,7 @@
106 112 //If the current node is visible, add it to the render queue
107 113 RenderQueue::getInstance().addNodeToQueue(this);
108 114 }
115 +
109 116 }
110 117 //If we don't need to skip child testing
111 118 if(!skipChildren){
  @@ -115,15 +122,23 @@
115 122 }
116 123 }
117 124
118 - void SceneGraphNode::sceneUpdate(const U32 sceneTime) {
125 + void SceneGraphNode::sceneUpdate(const U32 sceneTime, SceneState& sceneState) {
119 126 for_each(NodeChildren::value_type& it, _children){
120 - it.second->sceneUpdate(sceneTime);
127 + it.second->sceneUpdate(sceneTime, sceneState);
121 128 }
122 129
123 - if(_node){
124 - _node->sceneUpdate(sceneTime,this);
125 - }
126 - if(_shouldDelete){
127 - GET_ACTIVE_SCENE()->getSceneGraph()->addToDeletionQueue(this);
128 - }
130 + _currentSceneState = &sceneState;
131 +
132 + if(_node)
133 + _node->sceneUpdate(sceneTime, this, sceneState);
134 +
135 + if(_shouldDelete)
136 + GET_ACTIVE_SCENEGRAPH()->addToDeletionQueue(this);
137 +
138 + }
139 +
140 + void SceneGraphNode::setSelected(const bool state) {
141 + _selected = state;
142 + WriteLock w_lock(_queryLock);
143 + _boundingBox.setVisibility(_selected);
129 144 }