From 416ce9d4954e0a7f4ee7b9afe43bf691fdb276f4 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Fri, 6 Apr 2012 05:18:48 -0700 Subject: texture notifications --- js/lib/rdge/materials/material.js | 7 +++++++ js/lib/rdge/materials/pulse-material.js | 14 ++++++++++++++ js/lib/rdge/materials/uber-material.js | 24 ++++++++++++++++++++++++ js/lib/rdge/texture.js | 25 +++++++++++++++++++++---- 4 files changed, 66 insertions(+), 4 deletions(-) (limited to 'js/lib/rdge') diff --git a/js/lib/rdge/materials/material.js b/js/lib/rdge/materials/material.js index a81ca18f..bc4c8e6b 100755 --- a/js/lib/rdge/materials/material.js +++ b/js/lib/rdge/materials/material.js @@ -257,6 +257,13 @@ var Material = function GLMaterial( world ) { return tex; }; + this.updateTextures = function() + { + // this function is called whenever a world that generates textuers for + // the current world changes in some way. Sub-classes with textures + // should override this function. + } + this.export = function() { // this function should be overridden by subclasses var exportStr = "material: " + this.getShaderName() + "\n" + "endMaterial\n"; diff --git a/js/lib/rdge/materials/pulse-material.js b/js/lib/rdge/materials/pulse-material.js index 276f7de6..0a7a5dd8 100644 --- a/js/lib/rdge/materials/pulse-material.js +++ b/js/lib/rdge/materials/pulse-material.js @@ -150,6 +150,20 @@ var PulseMaterial = function PulseMaterial() } }; + + this.updateTextures = function() + { + if (this._glTex) + { + if (!this._glTex.isAnimated()) + { + this._glTex.rerender(); + this.updateTexture(); + } + } + } + + this.update = function( time ) { var material = this._materialNode; diff --git a/js/lib/rdge/materials/uber-material.js b/js/lib/rdge/materials/uber-material.js index ca244629..71354216 100755 --- a/js/lib/rdge/materials/uber-material.js +++ b/js/lib/rdge/materials/uber-material.js @@ -286,6 +286,30 @@ var UberMaterial = function UberMaterial() { } }; + + this.updateTextures = function() + { + var material = this._materialNode; + if (material) + { + var technique = material.shaderProgram.defaultTechnique; + var renderer = g_Engine.getContext().renderer; + if (renderer && technique) + { + if (this._diffuseTexture) + { + if (!this._diffuseTexture.isAnimated()) + { + this._diffuseTexture.rerender(); + var tex = this._diffuseTexture.getTexture(); + technique.s_diffuseMap.set( tex ); + } + } + } + } + } + + this.updateSpecularMap = function() { var value = this._propValues[ "specularMap" ]; this._specularMapOb.texture = value; diff --git a/js/lib/rdge/texture.js b/js/lib/rdge/texture.js index d2f66efa..f1448195 100644 --- a/js/lib/rdge/texture.js +++ b/js/lib/rdge/texture.js @@ -6,6 +6,8 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot var Material = require("js/lib/rdge/materials/material").Material; +var __textureCounter = 0; + /////////////////////////////////////////////////////////////////////// // Class GLTexture // GL representation of a texture. @@ -38,6 +40,9 @@ function Texture( dstWorld, texMapName, wrap, mips ) // the destination world that will use the texture map this._dstWorld = dstWorld; + this._texCount = __textureCounter; + __textureCounter++; + /////////////////////////////////////////////////////////////////////// // Property Accessors /////////////////////////////////////////////////////////////////////// @@ -89,7 +94,8 @@ function Texture( dstWorld, texMapName, wrap, mips ) console.log( "texture callback, type: " + type ); if (calleeData.srcWorld) { - var srcWorld = calleeData.srcWorld; + var srcWorld = callbackObj.getSrcWorld(); + var dstWorld = callbackObj.getDstWorld(); var notifier = srcWorld._notifier; var texture = this.callbackObj; if (texture) @@ -103,9 +109,20 @@ function Texture( dstWorld, texMapName, wrap, mips ) break; case notifier.OBJECT_CHANGE: - if (!texture.isAnimated()) - texture.rerender(); - texture.getDstWorld().restartRenderLoop(); +// this._isAnimated = srcWorld._hasAnimatedMaterials; +// if (!srcWorld.hasAnimatedMaterials()) +// srcWorld.restartRenderLoop(); +// else if (!dstWorld.hasAnimatedMaterials()) +// { +// dstWorld.refreshTextures(); +// dstWorld.restartRenderLoop(); +// } + break; + + case notifier.FIRST_RENDER: + texture._isAnimated = srcWorld.hasAnimatedMaterials(); + dstWorld.refreshTextures(); + dstWorld.restartRenderLoop(); break; default: -- cgit v1.2.3