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/SceneNode.cpp

Diff revisions: vs.
  @@ -12,8 +12,8 @@
12 12 SceneNode::SceneNode(const SceneNodeType& type) : Resource(),
13 13 _material(NULL),
14 14 _customShader(NULL),
15 - _selected(false),
16 15 _refreshMaterialData(true),
16 + _isSelectable(false),
17 17 _type(type),
18 18 _lodLevel(0),
19 19 _LODcount(1), ///<Defaults to 1 LOD level
  @@ -24,75 +24,77 @@
24 24 SceneNode::SceneNode(const std::string& name,const SceneNodeType& type) : Resource(name),
25 25 _material(NULL),
26 26 _customShader(NULL),
27 - _selected(false),
28 27 _refreshMaterialData(true),
28 + _isSelectable(false),
29 29 _type(type),
30 30 _lodLevel(0),
31 31 _LODcount(1), ///<Defaults to 1 LOD level
32 32 _physicsAsset(NULL)
33 33 {
34 + U8 i = 0, j = 0;
35 + for(; i < Material::TEXTURE_UNIT0; ++i)
36 + sprintf_s(_textureOperationUniformSlots[i], "textureOperation%d", Material::TEXTURE_UNIT0 + i);
37 +
38 + for(i = Material::TEXTURE_UNIT0; i < Config::MAX_TEXTURE_STORAGE; ++i)
39 + sprintf_s(_textureOperationUniformSlots[i], "textureOperation%d", j++);
34 40 }
35 41
36 42 SceneNode::~SceneNode() {
37 43 SAFE_DELETE(_physicsAsset);
38 44 }
39 45
40 - void SceneNode::sceneUpdate(const U32 sceneTime,SceneGraphNode* const sgn){
41 - if(!_material) return;
46 + void SceneNode::sceneUpdate(const U32 sceneTime, SceneGraphNode* const sgn, SceneState& sceneState){
47 + if(!_material)
48 + return;
49 +
42 50 _refreshMaterialData = _material->isDirty();
43 51 _material->clean();
44 52 }
45 53
46 54 void SceneNode::onDraw(const RenderStage& currentStage){
47 55 Material* mat = getMaterial();
48 - if(mat){
49 - mat->computeShader(false);
50 - mat->computeShader(false,DEPTH_STAGE);
51 - }
56 +
57 + if(!mat)
58 + return;
59 +
60 + mat->computeShader(false);
61 + mat->computeShader(false,DEPTH_STAGE);
52 62 }
53 63
54 64 void SceneNode::preFrameDrawEnd(SceneGraphNode* const sgn){
55 65 //draw bounding box if needed and only in the final stage to prevent Shadow/PostFX artifacts
56 - BoundingBox& bb = sgn->getBoundingBox();
57 66 //Draw the bounding box if it's always on or if the scene demands it
58 - if(bb.getVisibility() || GET_ACTIVE_SCENE()->renderState()->drawBBox()){
67 + if(sgn->getBoundingBox().getVisibility() || GET_ACTIVE_SCENE()->renderState().drawBBox()){
59 68 drawBoundingBox(sgn);
60 69 }
61 70 }
62 71
63 - bool SceneNode::isInView(const bool distanceCheck,const BoundingBox& boundingBox,const BoundingSphere& sphere){
72 + bool SceneNode::isInView(const BoundingBox& boundingBox,const BoundingSphere& sphere, const bool distanceCheck){
64 73 Frustum& frust = Frustum::getInstance();
65 - Scene* activeScene = GET_ACTIVE_SCENE();
66 - vec3<F32> center = sphere.getCenter();
67 - F32 radius = sphere.getRadius();
68 - F32 halfExtent = boundingBox.getHalfExtent().length();
69 - vec3<F32> eyeToNode = center - frust.getEyePos();
74 +
75 + const vec3<F32>& center = sphere.getCenter();
76 + vec3<F32> eyeToNode = center - frust.getEyePos();
70 77 F32 cameraDistance = eyeToNode.length();
71 78
72 - if(distanceCheck){
73 - if((cameraDistance + halfExtent) > activeScene->state()->getGeneralVisibility()){
79 + if(distanceCheck &&
80 + cameraDistance + boundingBox.getHalfExtent().length() > GET_ACTIVE_SCENE()->state().getGeneralVisibility())
74 81 return false;
75 - }
76 - }
77 -
78 - U8 lod = 0;
79 - if(cameraDistance > SCENE_NODE_LOD0) lod = 2;
80 - else if(cameraDistance > SCENE_NODE_LOD1) lod = 1;
81 - _lodLevel = lod;
82 +
82 83
83 - const vec3<F32>& eye = frust.getEyePos();
84 - if(!boundingBox.ContainsPoint(eye)){
85 - I8 resSphereInFrustum = frust.ContainsSphere(center, radius);
86 - switch(resSphereInFrustum) {
84 + if(!boundingBox.ContainsPoint(frust.getEyePos())){
85 + switch(frust.ContainsSphere(center, sphere.getRadius())) {
87 86 case FRUSTUM_OUT: return false;
88 87 case FRUSTUM_INTERSECT: {
89 - I8 resBoxInFrustum = frust.ContainsBoundingBox(boundingBox);
90 - switch(resBoxInFrustum) {
91 - case FRUSTUM_OUT: return false;
92 - }
88 + if(!frust.ContainsBoundingBox(boundingBox)) return false;
93 89 }
94 90 }
95 91 }
92 +
93 + U8 lod = 0;
94 + if(cameraDistance > Config::SCENE_NODE_LOD0) lod = 2;
95 + else if(cameraDistance > Config::SCENE_NODE_LOD1) lod = 1;
96 + _lodLevel = lod;
97 +
96 98 return true;
97 99 }
98 100
  @@ -140,39 +142,29 @@
140 142
141 143 void SceneNode::prepareMaterial(SceneGraphNode* const sgn){
142 144 //UpgradableReadLock ur_lock(_materialLock);
143 - if(!_material) return;
145 + if(!_material)
146 + return;
144 147
145 - if(GFX_DEVICE.isCurrentRenderStage(REFLECTION_STAGE)){
148 + if(GFX_DEVICE.isCurrentRenderStage(REFLECTION_STAGE))
146 149 SET_STATE_BLOCK(_material->getRenderState(REFLECTION_STAGE));
147 - }else{
150 + else
148 151 SET_STATE_BLOCK(_material->getRenderState(FINAL_STAGE));
149 - }
150 -
152 +
151 153 ShaderProgram* s = _material->getShaderProgram();
152 154 Scene* activeScene = GET_ACTIVE_SCENE();
153 155 LightManager& lightMgr = LightManager::getInstance();
154 156
155 - Texture2D* baseTexture = _material->getTexture(Material::TEXTURE_BASE);
156 - Texture2D* bumpTexture = _material->getTexture(Material::TEXTURE_BUMP);
157 - Texture2D* secondTexture = _material->getTexture(Material::TEXTURE_SECOND);
158 - Texture2D* opacityMap = _material->getTexture(Material::TEXTURE_OPACITY);
159 - Texture2D* specularMap = _material->getTexture(Material::TEXTURE_SPECULAR);
160 -
161 157 s->bind();
162 158
163 - if(baseTexture) {
164 - baseTexture->Bind(Material::FIRST_TEXTURE_UNIT);
165 - s->Uniform("texDiffuse0Op", (I32)_material->getTextureOperation(Material::TEXTURE_BASE));
166 - }
167 - if(secondTexture){
168 - secondTexture->Bind(Material::SECOND_TEXTURE_UNIT);
169 - s->Uniform("texDiffuse1Op", (I32)_material->getTextureOperation(Material::TEXTURE_SECOND));
170 - }
159 + Texture2D* texture = NULL;
160 + for(U16 i = 0; i < Config::MAX_TEXTURE_STORAGE; ++i)
161 + if((texture = _material->getTexture(i)) != NULL){
162 + texture->Bind(i);
163 +
164 + if(i >= Material::TEXTURE_UNIT0)
165 + s->Uniform(_textureOperationUniformSlots[i], (I32)_material->getTextureOperation(i));
166 + }
171 167
172 - if(bumpTexture) bumpTexture->Bind(Material::BUMP_TEXTURE_UNIT);
173 - if(opacityMap) opacityMap->Bind(Material::OPACITY_TEXTURE_UNIT);
174 - if(specularMap) specularMap->Bind(Material::SPECULAR_TEXTURE_UNIT);
175 -
176 168 s->Uniform("material",_material->getMaterialMatrix());
177 169 s->Uniform("opacity", _material->getOpacityValue());
178 170 s->Uniform("textureCount",_material->getTextureCount());
  @@ -190,8 +182,8 @@
190 182 s->Uniform("dvd_lightEnabled", lightMgr.getLightsEnabledForCurrentNode());
191 183 s->Uniform("dvd_lightCastsShadows",lightMgr.getShadowCastingLightsForCurrentNode());
192 184
193 - s->Uniform("windDirection",vec2<F32>(activeScene->state()->getWindDirX(),activeScene->state()->getWindDirZ()));
194 - s->Uniform("windSpeed", activeScene->state()->getWindSpeed());
185 + s->Uniform("windDirection",vec2<F32>(activeScene->state().getWindDirX(),activeScene->state().getWindDirZ()));
186 + s->Uniform("windSpeed", activeScene->state().getWindSpeed());
195 187
196 188 if(!sgn->animationTransforms().empty()){
197 189 s->Uniform("hasAnimations", true);
  @@ -205,21 +197,16 @@
205 197 //UpgradableReadLock ur_lock(_materialLock);
206 198 if(!_material) return;
207 199
208 - Texture2D* baseTexture = _material->getTexture(Material::TEXTURE_BASE);
209 - Texture2D* bumpTexture = _material->getTexture(Material::TEXTURE_BUMP);
210 - Texture2D* secondTexture = _material->getTexture(Material::TEXTURE_SECOND);
211 - Texture2D* opacityMap = _material->getTexture(Material::TEXTURE_OPACITY);
212 - Texture2D* specularMap = _material->getTexture(Material::TEXTURE_SPECULAR);
213 -
214 - if(specularMap) specularMap->Unbind(4);
215 - if(opacityMap) opacityMap->Unbind(3);
216 - if(bumpTexture) bumpTexture->Unbind(2);
217 - if(secondTexture) secondTexture->Unbind(1);
218 - if(baseTexture) baseTexture->Unbind(0);
200 + Texture2D* texture = NULL;
201 + for(U16 i = 0; i < Config::MAX_TEXTURE_STORAGE; ++i)
202 + if((texture = _material->getTexture(i)) != NULL)
203 + texture->Unbind(i);
219 204 }
220 205
221 206 void SceneNode::prepareDepthMaterial(SceneGraphNode* const sgn){
222 - if(getType() != TYPE_OBJECT3D && getType() != TYPE_TERRAIN) return;
207 + if(getType() != TYPE_OBJECT3D && getType() != TYPE_TERRAIN)
208 + return;
209 +
223 210 //UpgradableReadLock ur_lock(_materialLock);
224 211 // general depth descriptor for objects without material
225 212 if(!_material) {
  @@ -235,7 +222,8 @@
235 222
236 223 Texture2D* opacityMap = _material->getTexture(Material::TEXTURE_OPACITY);
237 224
238 - if(opacityMap) opacityMap->Bind(Material::OPACITY_TEXTURE_UNIT );
225 + if(opacityMap)
226 + opacityMap->Bind(Material::TEXTURE_OPACITY);
239 227
240 228 s->Uniform("opacity", _material->getOpacityValue());
241 229
  @@ -249,9 +237,12 @@
249 237
250 238 void SceneNode::releaseDepthMaterial(){
251 239 //UpgradableReadLock ur_lock(_materialLock);
252 - if(!_material) return;
240 + if(!_material)
241 + return;
242 +
253 243 Texture2D* opacityMap = _material->getTexture(Material::TEXTURE_OPACITY);
254 - if(opacityMap) opacityMap->Unbind(0);
244 + if(opacityMap)
245 + opacityMap->Unbind(Material::TEXTURE_OPACITY);
255 246 }
256 247
257 248 bool SceneNode::computeBoundingBox(SceneGraphNode* const sgn) {
  @@ -271,12 +262,12 @@
271 262 }
272 263
273 264 void SceneNode::drawBoundingBox(SceneGraphNode* const sgn){
274 - BoundingBox& bb = sgn->getBoundingBox();
275 - mat4<F32> boundingBoxTransformMatrix;
276 - /*Transform* tempTransform = sgn->getTransform();
265 + const BoundingBox& bb = sgn->getBoundingBox();
266 + /*mat4<F32> boundingBoxTransformMatrix;
267 + Transform* tempTransform = sgn->getTransform();
277 268 if(tempTransform){
278 269 boundingBoxTransformMatrix = tempTransform->getGlobalMatrix();
279 270 }*/
280 271
281 - GFX_DEVICE.drawBox3D(bb.getMin(),bb.getMax(),boundingBoxTransformMatrix);
272 + GFX_DEVICE.drawBox3D(bb.getMin(),bb.getMax(),/*boundingBoxTransformMatrix*/mat4<F32>());
282 273 }