aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/GLWorld.js
diff options
context:
space:
mode:
authorEric Guzman2012-02-13 10:30:26 -0800
committerEric Guzman2012-02-13 10:30:26 -0800
commit672e6f61647b1b8a5f6f5831284fa44bcb7be883 (patch)
tree0c15656f1f82f194bfcab68634a88f68fd3d42cb /js/helper-classes/RDGE/GLWorld.js
parent586c3f7bbea04e62638e5ed8cdce9933e88c0b67 (diff)
parente142611e22718b1f1d1696902ad9161ec5f33f98 (diff)
downloadninja-672e6f61647b1b8a5f6f5831284fa44bcb7be883.tar.gz
Merge branch 'refs/heads/master' into PresetsPanel
Diffstat (limited to 'js/helper-classes/RDGE/GLWorld.js')
-rw-r--r--js/helper-classes/RDGE/GLWorld.js248
1 files changed, 219 insertions, 29 deletions
diff --git a/js/helper-classes/RDGE/GLWorld.js b/js/helper-classes/RDGE/GLWorld.js
index 59f0bda0..c8327064 100644
--- a/js/helper-classes/RDGE/GLWorld.js
+++ b/js/helper-classes/RDGE/GLWorld.js
@@ -14,6 +14,7 @@ var fragmentShaderSource = "";
14var rdgeStarted = false; 14var rdgeStarted = false;
15 15
16var nodeCounter = 0; 16var nodeCounter = 0;
17var worldCounter = 0;
17 18
18 19
19/////////////////////////////////////////////////////////////////////// 20///////////////////////////////////////////////////////////////////////
@@ -65,6 +66,14 @@ function GLWorld( canvas, use3D )
65 66
66 this._camera; 67 this._camera;
67 68
69 // keep a flag indicating whether a render has been completed.
70 // this allows us to turn off automatic updating if there are
71 // no animated materials
72 this._firstRender = true;
73
74 this._worldCount = worldCounter;
75 worldCounter++;
76
68 /////////////////////////////////////////////////////////////////////// 77 ///////////////////////////////////////////////////////////////////////
69 // Property accessors 78 // Property accessors
70 /////////////////////////////////////////////////////////////////////// 79 ///////////////////////////////////////////////////////////////////////
@@ -103,6 +112,8 @@ function GLWorld( canvas, use3D )
103 112
104 this.isWebGL = function() { return this._useWebGL; } 113 this.isWebGL = function() { return this._useWebGL; }
105 114
115 this.getRenderer = function() { return this.renderer; }
116
106 //////////////////////////////////////////////////////////////////////////////////// 117 ////////////////////////////////////////////////////////////////////////////////////
107 // RDGE 118 // RDGE
108 // local variables 119 // local variables
@@ -114,6 +125,10 @@ function GLWorld( canvas, use3D )
114 this.strokeShader = null; 125 this.strokeShader = null;
115 this.renderer = null; 126 this.renderer = null;
116 127
128 // keep an array of texture maps that need to be loaded
129 this._texMapsToLoad = [];
130 this._allMapsLoaded = true;
131
117 // this is the node to which objects get hung 132 // this is the node to which objects get hung
118 this._rootNode; 133 this._rootNode;
119 134
@@ -136,6 +151,7 @@ function GLWorld( canvas, use3D )
136 ctx2 = g_Engine.getContext(); 151 ctx2 = g_Engine.getContext();
137 if (ctx1 != ctx2) console.log( "***** different contexts *****" ); 152 if (ctx1 != ctx2) console.log( "***** different contexts *****" );
138 this.renderer = ctx1.renderer; 153 this.renderer = ctx1.renderer;
154 this.renderer._world = this;
139 155
140 // create a camera, set its perspective, and then point it at the origin 156 // create a camera, set its perspective, and then point it at the origin
141 var cam = new camera(); 157 var cam = new camera();
@@ -214,18 +230,160 @@ function GLWorld( canvas, use3D )
214 { 230 {
215 if (this._useWebGL) 231 if (this._useWebGL)
216 { 232 {
233 g_Engine.setContext( this._canvas.uuid );
217 var ctx = g_Engine.getContext(); 234 var ctx = g_Engine.getContext();
218 //console.log( "RDGE state: " + ctx.ctxStateManager.currentState().name); 235 var ctx1 = g_Engine.ctxMan.handleToObject(this._canvas.rdgeCtxHandle);
219 236 if (ctx1 != ctx)
237 console.log( "***** different contexts (2) *****" );
238 var aRenderer = ctx1.renderer;
220 var renderer = ctx.renderer; 239 var renderer = ctx.renderer;
221 renderer.disableCulling(); 240 if (renderer != aRenderer)
222 this.myScene.render(); 241 {
242 console.log( "***** DIFFERENT RENDERERS *****" );
243 renderer = aRenderer;
244 }
245
246 if (renderer.unloadedTextureCount <= 0)
247 {
248 renderer.disableCulling();
249 //console.log( "GLWorld.draw " + renderer._world._worldCount );
250 this.myScene.render();
251
252 if (this._firstRender)
253 {
254 this._firstRender = false;
255
256 if (!this.hasAnimatedMaterials())
257 {
258 //this.myScene.render();
259 this._canvas.task.stop();
260 //this._renderCount = 10;
261 }
262 }
263 else if (this._renderCount >= 0)
264 {
265 this._renderCount--;
266 if (this._renderCount <= 0)
267 this._canvas.task.stop();
268 }
269 }
223 } 270 }
224 else 271 else
225 { 272 {
226 this.render(); 273 this.render();
227 } 274 }
228 } 275 }
276
277 this.onRunState = function()
278 {
279// console.log( "GLWorld.onRunState" );
280 this.restartRenderLoop();
281 }
282
283 this.onLoadState = function()
284 {
285// console.log( "GLWorld.onLoadState" );
286 }
287
288 this.textureToLoad = function( texture )
289 {
290 if (!texture.previouslyReferenced)
291 {
292 var name = texture.lookUpName;
293 texture._world = this;
294 texture.callback = this.textureMapLoaded;
295 this._texMapsToLoad[name] = true;
296 this._allMapsLoaded = false;
297
298 // stop the draw loop until all textures have been loaded
299 this._canvas.task.stop();
300 }
301 }
302
303 this.textureMapLoaded = function( texture )
304 {
305 var world = texture._world;
306 if (!world)
307 {
308 console.log( "**** loaded texture does not have world defined ****" );
309 return;
310 }
311
312 var name = texture.lookUpName;
313 if (!world._texMapsToLoad[name])
314 {
315 console.log( "loaded an unregistered texture map: " + name );
316 }
317 else
318 {
319 //console.log( "loaded a registered texture map: " + name );
320 world._texMapsToLoad[name] = undefined;
321 }
322
323 // check if all the texture maps are loaded. if so, resume the render loop
324 world._allMapsLoaded = world.allTextureMapsLoaded();
325 if (world._allMapsLoaded)
326 world._canvas.task.start();
327 }
328
329 this.allTextureMapsLoaded = function()
330 {
331 for (var name in this._texMapsToLoad)
332 {
333 var needsLoad = this._texMapsToLoad[name];
334 if (needsLoad) return false;
335 }
336
337 return true;
338 }
339
340 this.textureLoadedCallback = function( name )
341 {
342// console.log( "*** material texture loaded: " + name );
343
344 var world = this._world;
345 if (!world)
346 console.log( "**** world not defined for loaded texture map: " + name );
347 else
348 world.textureMapLoaded( name );
349 }
350
351 this.hasAnimatedMaterials = function()
352 {
353 var root = this.getGeomRoot();
354 var rtnVal = false;
355 if (root)
356 rtnVal = this.hHasAnimatedMaterials( root );
357
358 return rtnVal;
359 }
360
361 this.hHasAnimatedMaterials = function( obj )
362 {
363 if (obj)
364 {
365 if (obj.getFillMaterial())
366 {
367 if (obj.getFillMaterial().isAnimated()) return true;
368 }
369
370 if (obj.getStrokeMaterial())
371 {
372 if (obj.getStrokeMaterial().isAnimated()) return true;
373 }
374
375
376 // do the sibling
377 var hasAnim = false;
378 if (obj.getNext()) hasAnim = this.hHasAnimatedMaterials( obj.getNext() );
379 if (hasAnim) return true;
380 if (obj.getChild()) hasAnim = this.hHasAnimatedMaterials( obj.getChild() );
381 if (hasAnim) return true;