aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/GLWorld.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/RDGE/GLWorld.js')
-rwxr-xr-x[-rw-r--r--]js/helper-classes/RDGE/GLWorld.js84
1 files changed, 49 insertions, 35 deletions
diff --git a/js/helper-classes/RDGE/GLWorld.js b/js/helper-classes/RDGE/GLWorld.js
index b86d9715..1edd5cff 100644..100755
--- 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///////////////////////////////////////////////////////////////////////
@@ -70,6 +71,9 @@ function GLWorld( canvas, use3D )
70 // no animated materials 71 // no animated materials
71 this._firstRender = true; 72 this._firstRender = true;
72 73
74 this._worldCount = worldCounter;
75 worldCounter++;
76
73 /////////////////////////////////////////////////////////////////////// 77 ///////////////////////////////////////////////////////////////////////
74 // Property accessors 78 // Property accessors
75 /////////////////////////////////////////////////////////////////////// 79 ///////////////////////////////////////////////////////////////////////
@@ -147,6 +151,7 @@ function GLWorld( canvas, use3D )
147 ctx2 = g_Engine.getContext(); 151 ctx2 = g_Engine.getContext();
148 if (ctx1 != ctx2) console.log( "***** different contexts *****" ); 152 if (ctx1 != ctx2) console.log( "***** different contexts *****" );
149 this.renderer = ctx1.renderer; 153 this.renderer = ctx1.renderer;
154 this.renderer._world = this;
150 155
151 // 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
152 var cam = new camera(); 157 var cam = new camera();
@@ -158,7 +163,7 @@ function GLWorld( canvas, use3D )
158 this.renderer.cameraManager().setActiveCamera(cam); 163 this.renderer.cameraManager().setActiveCamera(cam);
159 164
160 // change clear color 165 // change clear color
161 this.renderer.setClearFlags(g_Engine.getContext().DEPTH_BUFFER_BIT); 166 //this.renderer.setClearFlags(g_Engine.getContext().DEPTH_BUFFER_BIT);
162 this.renderer.setClearColor([1.0, 1.0, 1.0, 0.0]); 167 this.renderer.setClearColor([1.0, 1.0, 1.0, 0.0]);
163 //this.renderer.NinjaWorld = this; 168 //this.renderer.NinjaWorld = this;
164 169
@@ -201,6 +206,7 @@ function GLWorld( canvas, use3D )
201 { 206 {
202 if (!dt) dt = 0.2; 207 if (!dt) dt = 0.2;
203 208
209 dt = 0.01; // use our own internal throttle
204 this.elapsed += dt; 210 this.elapsed += dt;
205 211
206 if (this._useWebGL) 212 if (this._useWebGL)
@@ -225,41 +231,38 @@ function GLWorld( canvas, use3D )
225 { 231 {
226 if (this._useWebGL) 232 if (this._useWebGL)
227 { 233 {
228 if (this._allMapsLoaded) 234 g_Engine.setContext( this._canvas.uuid );
235 var ctx = g_Engine.getContext();
236 var renderer = ctx.renderer;
237 if (renderer.unloadedTextureCount <= 0)
229 { 238 {
230 var ctx = g_Engine.getContext();
231 //console.log( "RDGE state: " + ctx.ctxStateManager.currentState().name);
232
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(); 239 renderer.disableCulling();
240 //console.log( "GLWorld.draw " + renderer._world._worldCount );
241 renderer._clear();
242 this.myScene.render(); 242 this.myScene.render();
243 //console.log( "render" );
244 243
245 if (this._firstRender) 244 if (this._firstRender)
246 { 245 {
247 this._firstRender = false; 246 if (this._canvas.task)
248
249 if (!this.hasAnimatedMaterials())
250 { 247 {
251 //this.myScene.render(); 248 this._firstRender = false;
252 //this._canvas.task.stop(); 249
253 this._renderCount = 10; 250 if (!this.hasAnimatedMaterials())
251 {
252 this._canvas.task.stop();
253 //this._renderCount = 10;
254 }
254 } 255 }
255 } 256 }
256 else if (this._renderCount >= 0) 257 else if (this._renderCount >= 0)
257 { 258 {
258 this._renderCount--; 259 if (this._canvas.task)
259 if (this._renderCount <= 0) 260 {
260 this._canvas.task.stop(); 261 this._renderCount--;
262 if (this._renderCount <= 0)
263 this._canvas.task.stop();
264 }
261 } 265 }
262
263 } 266 }
264 } 267 }
265 else 268 else
@@ -270,13 +273,13 @@ function GLWorld( canvas, use3D )
270 273
271 this.onRunState = function() 274 this.onRunState = function()
272 { 275 {
273 console.log( "GLWorld.onRunState" ); 276// console.log( "GLWorld.onRunState" );
274 this.restartRenderLoop(); 277 this.restartRenderLoop();
275 } 278 }
276 279
277 this.onLoadState = function() 280 this.onLoadState = function()
278 { 281 {
279 console.log( "GLWorld.onLoadState" ); 282// console.log( "GLWorld.onLoadState" );
280 } 283 }
281 284
282 this.textureToLoad = function( texture ) 285 this.textureToLoad = function( texture )
@@ -333,7 +336,7 @@ function GLWorld( canvas, use3D )
333 336
334 this.textureLoadedCallback = function( name ) 337 this.textureLoadedCallback = function( name )
335 { 338 {
336 console.log( "*** material texture loaded: " + name ); 339// console.log( "*** material texture loaded: " + name );
337 340
338 var world = this._world; 341 var world = this._world;
339 if (!world) 342 if (!world)
@@ -388,9 +391,7 @@ function GLWorld( canvas, use3D )
388 if (this._useWebGL) 391 if (this._useWebGL)
389 { 392 {
390 rdgeStarted = true; 393 rdgeStarted = true;
391 394 this._canvas.rdgeid = this._canvas.uuid;
392 // TODO - temporary fix for RDGE id's
393 this._canvas.id = "rdge_" + this._canvas.uuid;
394 g_Engine.registerCanvas(this._canvas, this); 395 g_Engine.registerCanvas(this._canvas, this);
395 RDGEStart( this._canvas ); 396 RDGEStart( this._canvas );
396 397
@@ -508,16 +509,22 @@ GLWorld.prototype.addObject = function( obj )
508 509
509GLWorld.prototype.restartRenderLoop = function() 510GLWorld.prototype.restartRenderLoop = function()
510{ 511{
511 console.log( "restartRenderLoop" ); 512 //console.log( "restartRenderLoop" );
512 513
513 this._firstRender = true; 514 this._firstRender = true;
514 this._renderCount = -1; 515 this._renderCount = -1;
515 if (this._canvas.task) 516 if (this._canvas.task)
516 { 517 {
517 if (this._allMapsLoaded) 518 if (this._allMapsLoaded)
519 {
520 //console.log( "starting task" );
518 this._canvas.task.start(); 521 this._canvas.task.start();
522 }
519 else 523 else
524 {
525 //console.log( "stopping task" );
520 this._canvas.task.stop(); 526 this._canvas.task.stop();
527 }
521 } 528 }
522} 529}
523 530
@@ -757,7 +764,10 @@ GLWorld.prototype.render = function()
757 } 764 }
758 else 765 else
759 { 766 {
760 this.draw(); 767// console.log( "GLWorld.render, " + this._worldCount );
768 g_Engine.setContext( this._canvas.uuid );
769 //this.draw();
770 this.restartRenderLoop();
761 } 771 }
762} 772}
763 773
@@ -794,7 +804,7 @@ GLWorld.prototype.getShapeFromPoint = function( offsetX, offsetY )
794 var go = this._geomRoot; 804 var go = this._geomRoot;
795 if(go.collidesWithPoint(x,y)) 805 if(go.collidesWithPoint(x,y))
796 { 806 {
797 console.log("collision found"); 807// console.log("collision found");
798 return go; 808 return go;
799 } 809 }
800 while (go.getNext()) 810 while (go.getNext())
@@ -802,7 +812,7 @@ GLWorld.prototype.getShapeFromPoint = function( offsetX, offsetY )
802 go = go.getNext(); 812 go = go.getNext();
803 if(go.collidesWithPoint(x,y)) 813 if(go.collidesWithPoint(x,y))
804 {