aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/GLWorld.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/RDGE/GLWorld.js')
-rw-r--r--js/helper-classes/RDGE/GLWorld.js221
1 files changed, 196 insertions, 25 deletions
diff --git a/js/helper-classes/RDGE/GLWorld.js b/js/helper-classes/RDGE/GLWorld.js
index 59f0bda0..afd61c8a 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
@@ -215,17 +230,153 @@ function GLWorld( canvas, use3D )
215 if (this._useWebGL) 230 if (this._useWebGL)
216 { 231 {
217 var ctx = g_Engine.getContext(); 232 var ctx = g_Engine.getContext();
218 //console.log( "RDGE state: " + ctx.ctxStateManager.currentState().name); 233 var ctx1 = g_Engine.ctxMan.handleToObject(this._canvas.rdgeCtxHandle);
219 234 if (ctx1 != ctx) console.log( "***** different contexts (2) *****" );
235 var aRenderer = ctx1.renderer;
220 var renderer = ctx.renderer; 236 var renderer = ctx.renderer;
221 renderer.disableCulling(); 237 if (renderer != aRenderer) console.log( "***** DIFFERENT RENDERERS *****" );
222 this.myScene.render(); 238
239 if (renderer.unloadedTextureCount <= 0)
240 {
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 }
223 } 263 }
224 else 264 else
225 { 265 {
226 this.render(); 266 this.render();
227 } 267 }
228 } 268 }
269
270 this.onRunState = function()
271 {
272 console.log( "GLWorld.onRunState" );
273 this.restartRenderLoop();
274 }
275
276 this.onLoadState = function()
277 {
278 console.log( "GLWorld.onLoadState" );
279 }
280
281 this.textureToLoad = function( texture )
282 {
283 if (!texture.previouslyReferenced)
284 {
285 var name = texture.lookUpName;
286 texture._world = this;
287 texture.callback = this.textureMapLoaded;
288 this._texMapsToLoad[name] = true;
289 this._allMapsLoaded = false;
290
291 // stop the draw loop until all textures have been loaded
292 this._canvas.task.stop();
293 }
294 }
295
296 this.textureMapLoaded = function( texture )
297 {
298 var world = texture._world;
299 if (!world)
300 {
301 console.log( "**** loaded texture does not have world defined ****" );
302 return;
303 }
304
305 var name = texture.lookUpName;
306 if (!world._texMapsToLoad[name])
307 {
308 console.log( "loaded an unregistered texture map: " + name );
309 }
310 else
311 {
312 //console.log( "loaded a registered texture map: " + name );
313 world._texMapsToLoad[name] = undefined;
314 }
315
316 // check if all the texture maps are loaded. if so, resume the render loop
317 world._allMapsLoaded = world.allTextureMapsLoaded();
318 if (world._allMapsLoaded)
319 world._canvas.task.start();
320 }
321
322 this.allTextureMapsLoaded = function()
323 {
324 for (var name in this._texMapsToLoad)
325 {
326 var needsLoad = this._texMapsToLoad[name];
327 if (needsLoad) return false;
328 }
329
330 return true;
331 }
332
333 this.textureLoadedCallback = function( name )
334 {
335 console.log( "*** material texture loaded: " + name );
336
337 var world = this._world;
338 if (!world)
339 console.log( "**** world not defined for loaded texture map: " + name );
340 else
341 world.textureMapLoaded( name );
342 }
343
344 this.hasAnimatedMaterials = function()
345 {
346 var root = this.getGeomRoot();
347 var rtnVal = false;
348 if (root)
349 rtnVal = this.hHasAnimatedMaterials( root );
350
351 return rtnVal;
352 }
353
354 this.hHasAnimatedMaterials = function( obj )
355 {
356 if (obj)
357 {
358 if (obj.getFillMaterial())
359 {
360 if (obj.getFillMaterial().isAnimated()) return true;
361 }
362
363 if (obj.getStrokeMaterial())
364 {
365 if (obj.getStrokeMaterial().isAnimated()) return true;
366 }
367
368
369 // do the sibling
370 var hasAnim = false;
371 if (obj.getNext()) hasAnim = this.hHasAnimatedMaterials( obj.getNext() );
372 if (hasAnim) return true;
373 if (obj.getChild()) hasAnim = this.hHasAnimatedMaterials( obj.getChild() );
374 if (hasAnim) return true;
375 }
376
377 return false;
378 }
379
229 380
230 // END RDGE 381 // END RDGE
231 //////////////////////////////////////////////////////////////////////////////////// 382 ////////////////////////////////////////////////////////////////////////////////////
@@ -233,23 +384,19 @@ function GLWorld( canvas, use3D )
233 384
234 // start RDGE passing your runtime object, and false to indicate we don't need a an initialization state 385 // 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 386 // in the case of a procedurally built scene an init state is not needed for loading data
236 //if (this._useWebGL) 387 if (this._useWebGL)
237 { 388 {
238 if (this._useWebGL) 389 rdgeStarted = true;
239 {
240 rdgeStarted = true;
241 390
242 // TODO - temporary fix for RDGE id's