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