aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/GLWorld.js
diff options
context:
space:
mode:
authorValerio Virgillito2012-02-09 13:41:45 -0800
committerValerio Virgillito2012-02-09 13:41:45 -0800
commitf5193cd04a2597051d88fced878efbc4802ea64c (patch)
treedc343dc98fa9f99133d9882bd9b92cfe81296d1a /js/helper-classes/RDGE/GLWorld.js
parente2539230b8a297fa972af6d53fe9de3ef2ad43fa (diff)
parent666ae3e9119410cbf7fa974274d95336aaff091c (diff)
downloadninja-f5193cd04a2597051d88fced878efbc4802ea64c.tar.gz
Merge branch 'refs/heads/master' into components
Diffstat (limited to 'js/helper-classes/RDGE/GLWorld.js')
-rw-r--r--js/helper-classes/RDGE/GLWorld.js229
1 files changed, 200 insertions, 29 deletions
diff --git a/js/helper-classes/RDGE/GLWorld.js b/js/helper-classes/RDGE/GLWorld.js
index 59f0bda0..b86d9715 100644
--- a/js/helper-classes/RDGE/GLWorld.js
+++ b/js/helper-classes/RDGE/GLWorld.js
@@ -65,6 +65,11 @@ function GLWorld( canvas, use3D )
65 65
66 this._camera; 66 this._camera;
67 67
68 // keep a flag indicating whether a render has been completed.
69 // this allows us to turn off automatic updating if there are
70 // no animated materials
71 this._firstRender = true;
72
68 /////////////////////////////////////////////////////////////////////// 73 ///////////////////////////////////////////////////////////////////////
69 // Property accessors 74 // Property accessors
70 /////////////////////////////////////////////////////////////////////// 75 ///////////////////////////////////////////////////////////////////////
@@ -103,6 +108,8 @@ function GLWorld( canvas, use3D )
103 108
104 this.isWebGL = function() { return this._useWebGL; } 109 this.isWebGL = function() { return this._useWebGL; }
105 110
111 this.getRenderer = function() { return this.renderer; }
112
106 //////////////////////////////////////////////////////////////////////////////////// 113 ////////////////////////////////////////////////////////////////////////////////////
107 // RDGE 114 // RDGE
108 // local variables 115 // local variables
@@ -114,6 +121,10 @@ function GLWorld( canvas, use3D )
114 this.strokeShader = null; 121 this.strokeShader = null;
115 this.renderer = null; 122 this.renderer = null;
116 123
124 // keep an array of texture maps that need to be loaded
125 this._texMapsToLoad = [];
126 this._allMapsLoaded = true;
127
117 // this is the node to which objects get hung 128 // this is the node to which objects get hung
118 this._rootNode; 129 this._rootNode;
119 130
@@ -214,18 +225,159 @@ function GLWorld( canvas, use3D )
214 { 225 {
215 if (this._useWebGL) 226 if (this._useWebGL)
216 { 227 {
217 var ctx = g_Engine.getContext(); 228 if (this._allMapsLoaded)
218 //console.log( "RDGE state: " + ctx.ctxStateManager.currentState().name); 229 {
219 230 var ctx = g_Engine.getContext();
220 var renderer = ctx.renderer; 231 //console.log( "RDGE state: " + ctx.ctxStateManager.currentState().name);
221 renderer.disableCulling(); 232
222 this.myScene.render(); 233 /////////////////////////////
234 var ctx1 = g_Engine.ctxMan.handleToObject(this._canvas.rdgeCtxHandle);
235 if (ctx1 != ctx) console.log( "***** different contexts (2) *****" );
236 var aRenderer = ctx1.renderer;
237 //////////////////////////////////////////
238
239 var renderer = ctx.renderer;
240 if (renderer != aRenderer) console.log( "***** DIFFERENT RENDERERS *****" );
241 renderer.disableCulling();
242 this.myScene.render();
243 //console.log( "render" );
244
245 if (this._firstRender)
246 {
247 this._firstRender = false;
248
249 if (!this.hasAnimatedMaterials())
250 {
251 //this.myScene.render();
252 //this._canvas.task.stop();
253 this._renderCount = 10;
254 }
255 }
256 else if (this._renderCount >= 0)
257 {
258 this._renderCount--;
259 if (this._renderCount <= 0)
260 this._canvas.task.stop();
261 }
262
263 }
223 } 264 }
224 else 265 else
225 { 266 {
226 this.render(); 267 this.render();
227 } 268 }
228 } 269 }
270
271 this.onRunState = function()
272 {
273 console.log( "GLWorld.onRunState" );
274 this.restartRenderLoop();
275 }
276
277 this.onLoadState = function()
278 {
279 console.log( "GLWorld.onLoadState" );
280 }
281
282 this.textureToLoad = function( texture )
283 {
284 if (!texture.previouslyReferenced)
285 {
286 var name = texture.lookUpName;
287 texture._world = this;
288 texture.callback = this.textureMapLoaded;
289 this._texMapsToLoad[name] = true;
290 this._allMapsLoaded = false;
291
292 // stop the draw loop until all textures have been loaded
293 this._canvas.task.stop();
294 }
295 }
296
297 this.textureMapLoaded = function( texture )
298 {
299 var world = texture._world;
300 if (!world)
301 {
302 console.log( "**** loaded texture does not have world defined ****" );
303 return;
304 }
305
306 var name = texture.lookUpName;
307 if (!world._texMapsToLoad[name])
308 {
309 console.log( "loaded an unregistered texture map: " + name );
310 }
311 else
312 {
313 //console.log( "loaded a registered texture map: " + name );
314 world._texMapsToLoad[name] = undefined;
315 }
316
317 // check if all the texture maps are loaded. if so, resume the render loop
318 world._allMapsLoaded = world.allTextureMapsLoaded();
319 if (world._allMapsLoaded)
320 world._canvas.task.start();
321 }
322
323 this.allTextureMapsLoaded = function()
324 {
325 for (var name in this._texMapsToLoad)
326 {
327 var needsLoad = this._texMapsToLoad[name];
328 if (needsLoad) return false;
329 }
330
331 return true;
332 }
333
334 this.textureLoadedCallback = function( name )
335 {
336 console.log( "*** material texture loaded: " + name );
337
338 var world = this._world;
339 if (!world)
340 console.log( "**** world not defined for loaded texture map: " + name );
341 else
342 world.textureMapLoaded( name );
343 }
344
345 this.hasAnimatedMaterials = function()
346 {
347 var root = this.getGeomRoot();
348 var rtnVal = false;
349 if (root)
350 rtnVal = this.hHasAnimatedMaterials( root );
351
352 return rtnVal;
353 }
354
355 this.hHasAnimatedMaterials = function( obj )
356 {
357 if (obj)
358 {
359 if (obj.getFillMaterial())
360 {
361 if (obj.getFillMaterial().isAnimated()) return true;
362 }
363
364 if (obj.getStrokeMaterial())
365 {
366 if (obj.getStrokeMaterial().isAnimated()) return true;
367 }
368
369
370 // do the sibling
371 var hasAnim = false;
372 if (obj.getNext()) hasAnim = this.hHasAnimatedMaterials( obj.getNext() );
373 if (hasAnim) return true;
374 if (obj.getChild()) hasAnim = this.hHasAnimatedMaterials( obj.getChild() );
375 if (hasAnim) return true;
376 }
377
378 return false;
379 }
380
229 381
230 // END RDGE 382 // END RDGE
231 //////////////////////////////////////////////////////////////////////////////////// 383 ////////////////////////////////////////////////////////////////////////////////////
@@ -233,23 +385,18 @@ function GLWorld( canvas, use3D )
233 385
234 // start RDGE passing your runtime object, and false to indicate we don't need a an initialization state 386 // start RDGE passing your runtime object, and false to indicate we don't need a an initialization state
235 // in the case of a procedurally built scene an init state is not needed for loading data 387 // in the case of a procedurally built scene an init state is not needed for loading data
236 //if (this._useWebGL) 388 if (this._useWebGL)
237 { 389 {
238 if (this._useWebGL) 390 rdgeStarted = true;
239 {
240 rdgeStarted = true;
241 391
242 // TODO - temporary fix for RDGE id's 392 // TODO - temporary fix for RDGE id's