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