From 191cb96b3b4e1e5aa805211e5ab8dbd6aa075881 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Thu, 9 Feb 2012 10:09:13 -0800 Subject: Merging WebGL changes that allow users to modify different shape instances. Also, merging in changes that improve rendering performance by not updating static materials. Signed-off-by: Nivesh Rajbhandari --- js/helper-classes/RDGE/src/core/script/engine.js | 18 ++++++------ .../RDGE/src/core/script/init_state.js | 7 ++++- js/helper-classes/RDGE/src/core/script/jshader.js | 6 ++-- js/helper-classes/RDGE/src/core/script/renderer.js | 32 ++++++++++++++++++---- .../RDGE/src/core/script/run_state.js | 10 ++++++- js/helper-classes/RDGE/src/core/script/runtime.js | 2 +- 6 files changed, 55 insertions(+), 20 deletions(-) (limited to 'js/helper-classes/RDGE/src/core') diff --git a/js/helper-classes/RDGE/src/core/script/engine.js b/js/helper-classes/RDGE/src/core/script/engine.js index 6fe964c7..5bc9305c 100644 --- a/js/helper-classes/RDGE/src/core/script/engine.js +++ b/js/helper-classes/RDGE/src/core/script/engine.js @@ -377,13 +377,13 @@ Engine.prototype.getRDGEPanel=function(panelID) return panelObjectManager.handleToObject(panelID); } -Engine.prototype.registerCanvas = function(canvas, runState) { - if (canvas && this.getContext(canvas.id)) - return; - +Engine.prototype.registerCanvas = function(canvas, runState) { + if (canvas && this.getContext(canvas.rdgeid)) + return; + canvas.renderer = new _renderer(canvas); // create the renderer for the context - this.canvasToRendererMap[canvas.id] = canvas; // store the canvas in the context map - canvas.renderer.id = canvas.id; + this.canvasToRendererMap[canvas.rdgeid] = canvas; // store the canvas in the context map + canvas.renderer.id = canvas.rdgeid; // configure the state manager for this context var stateMan = new stateManager(); @@ -391,11 +391,11 @@ Engine.prototype.registerCanvas = function(canvas, runState) { // add this context to the contextManager and attach the handle to DOM canvas for user retrieval var context = new contextDef(); - context.id = canvas.id; + context.id = canvas.rdgeid; context.renderer = canvas.renderer; context.ctxStateManager = stateMan; context.startUpState; - context.fpsTracker = new fpsTracker(canvas.id); + context.fpsTracker = new fpsTracker(canvas.rdgeid); context.renderer.mvMatrix = mat4.identity(); context.renderer.invMvMatrix = mat4.identity(); @@ -471,7 +471,7 @@ Engine.prototype.registerCanvas = function(canvas, runState) { } Engine.prototype.unregisterCanvas = function(canvas) { - stat.closePage(canvas.id + "_fps"); + stat.closePage(canvas.rdgeid + "_fps"); contextManager.removeObject(canvas.rdgeCtxHandle); } diff --git a/js/helper-classes/RDGE/src/core/script/init_state.js b/js/helper-classes/RDGE/src/core/script/init_state.js index 8c69d218..4b97a4f4 100644 --- a/js/helper-classes/RDGE/src/core/script/init_state.js +++ b/js/helper-classes/RDGE/src/core/script/init_state.js @@ -42,11 +42,16 @@ LoadState.prototype.Init = function() if(this.sceneName) { this.loadScene("assets_web/mesh/" + this.sceneName + ".json", this.sceneName); - } + } + + if (this.hasUserState && this.userRunState && this.userRunState.onLoadState) + this.userRunState.onLoadState(); } LoadState.prototype.ReInit = function() { + if (this.hasUserState && this.userRunState && this.userRunState.onLoadState) + this.userRunState.onLoadState(); } LoadState.prototype.Resize = function() diff --git a/js/helper-classes/RDGE/src/core/script/jshader.js b/js/helper-classes/RDGE/src/core/script/jshader.js index f28219cf..36c5939e 100644 --- a/js/helper-classes/RDGE/src/core/script/jshader.js +++ b/js/helper-classes/RDGE/src/core/script/jshader.js @@ -173,7 +173,7 @@ jshader = function(addr) { // if the parameter does not exist in the shader cull it from the pass if (this.loc == null) { - window.console.log("ctx:" + ctx.canvas.id + ", technique: " + technique + ", uniform: " + name + " was not found, jshader param will have no affect"); + window.console.log("ctx:" + ctx.canvas.rdgeid + ", technique: " + technique + ", uniform: " + name + " was not found, jshader param will have no affect"); //return; } @@ -308,7 +308,7 @@ jshader = function(addr) { } } - program.ctxId = this.ctx.canvas.id; + program.ctxId = this.ctx.canvas.rdgeid; if (!program) { this.renderer.console.log("Build errors found in technique: " + t); this.def[t] = null; // remove bad technique @@ -322,7 +322,7 @@ jshader = function(addr) { var gp = new globalParam(this.ctx, p, rdgeGlobalParameters[p], program); if (gp.loc != null) { - gp.loc.ctxID = this.ctx.canvas.id; + gp.loc.ctxID = this.ctx.canvas.rdgeid; this[t].passes[i].defParams[p] = gp; this.global[p] = gp; } diff --git a/js/helper-classes/RDGE/src/core/script/renderer.js b/js/helper-classes/RDGE/src/core/script/renderer.js index 0c51d2cb..a50b8a68 100644 --- a/js/helper-classes/RDGE/src/core/script/renderer.js +++ b/js/helper-classes/RDGE/src/core/script/renderer.js @@ -335,14 +335,19 @@ _renderer = function(canvas) { var tex = this.textureMap[name]; - if (tex === undefined) { - - + if (tex === undefined) + { // load the texture tex = this.createTexture(name + ext, wrap, mips); this.textureMap[name] = tex; tex.lookUpName = name; + tex.previouslyReferenced = false; } + else + { + //console.log( "texture already loaded: " + name ); + tex.previouslyReferenced = true; + } return tex; @@ -354,9 +359,11 @@ _renderer = function(canvas) { * @param wrap - optional "CLAMP or "REPEAT", default is clamp * @param mips - optional true/false value to create mipmaps, the default is true */ + this.unloadedTextureCount = 0; _texparams = function(wrap, mips) { this.wrap = wrap, this.mips = mips }; this.createTexture = function(url, wrap, mips) { var texture = this.ctx.createTexture(); + this.unloadedTextureCount++; if (wrap === undefined) wrap = "CLAMP"; @@ -371,7 +378,20 @@ _renderer = function(canvas) { texture.image.onload = function() { var stateMan = this.context.ctxStateManager; stateMan.RDGEInitState.loadTexture(texture); + this.context.renderer.unloadedTextureCount--; + //console.log( "loaded texture: " + texture.lookUpName + ",to: " + this.context.renderer._world._worldCount + ", textures remaining to load: " + this.context.renderer.unloadedTextureCount ); + if (texture.callback) texture.callback( texture ); + if (this.context.renderer.unloadedTextureCount < 0) + console.log( "more textures loaded then created..." ); }; + texture.image.onerror = function() { + this.context.renderer.unloadedTextureCount--; + if (texture.callback) texture.callback( texture ); + //console.log( "Error loading texture: " + texture.image.src ); + if (this.context.renderer.unloadedTextureCount < 0) + console.log( "more textures loaded then created..." ); + } + } return texture; } @@ -544,8 +564,10 @@ _renderer = function(canvas) { */ rdgeDefaultShaderDefintion = { 'shaders': { - 'defaultVShader':"assets/shaders/test_vshader.glsl", - 'defaultFShader':"assets/shaders/test_fshader.glsl" + //'defaultVShader':"assets/shaders/test_vshader.glsl", + //'defaultFShader':"assets/shaders/test_fshader.glsl" + 'defaultVShader':"assets/shaders/Basic.vert.glsl", + 'defaultFShader':"assets/shaders/Basic.frag.glsl" }, 'techniques': { 'defaultTechnique':[{ diff --git a/js/helper-classes/RDGE/src/core/script/run_state.js b/js/helper-classes/RDGE/src/core/script/run_state.js index ad56d9ea..acdb6797 100644 --- a/js/helper-classes/RDGE/src/core/script/run_state.js +++ b/js/helper-classes/RDGE/src/core/script/run_state.js @@ -30,6 +30,9 @@ RunState.prototype.Init = function() this.userRunState.init(); } + if (this.hasUserState && this.userRunState && this.userRunState.onRunState) + this.userRunState.onRunState(); + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -94,6 +97,11 @@ RunState.prototype.ReInit = function() if(!this.initialized) { this.Init(); + } + else + { + if (this.hasUserState && this.userRunState && this.userRunState.onRunState) + this.userRunState.onRunState(); } } @@ -117,7 +125,7 @@ RunState.prototype.Draw = function () var width = this.renderer.vpWidth; var height = this.renderer.vpHeight; - this.renderer._clear(); +// this.renderer._clear(); this.userRunState.draw(); diff --git a/js/helper-classes/RDGE/src/core/script/runtime.js b/js/helper-classes/RDGE/src/core/script/runtime.js index 8d8fdf38..18b9b223 100644 --- a/js/helper-classes/RDGE/src/core/script/runtime.js +++ b/js/helper-classes/RDGE/src/core/script/runtime.js @@ -179,7 +179,7 @@ RDGERequestAnimationFrame = (function() { RDGETask = (function() { var tasks = {}; return function(canvas, startNow) { - this.id = canvas.id; + this.id = canvas.rdgeid; this.currTime = 0.0; this.lastTime = 0.0; this.running = false; -- cgit v1.2.3