From a38a0ef4f3b261b8e64630c2e7a4ae5c8d2fda14 Mon Sep 17 00:00:00 2001 From: Yaski Date: Wed, 16 May 2012 13:36:11 +0600 Subject: [PATCH] TextureMaterial: Cache getVariableIndex() --- .../engine3d/materials/Material.as | 5 ---- .../engine3d/materials/TextureMaterial.as | 23 +++++++------------ 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/src/alternativa/engine3d/materials/Material.as b/src/alternativa/engine3d/materials/Material.as index 47a34e3..03d4d7c 100644 --- a/src/alternativa/engine3d/materials/Material.as +++ b/src/alternativa/engine3d/materials/Material.as @@ -27,11 +27,6 @@ package alternativa.engine3d.materials { */ public class Material { - /** - * @private - */ - alternativa3d function get canDrawInShadowMap():Boolean {return true} - /** * Name of the material */ diff --git a/src/alternativa/engine3d/materials/TextureMaterial.as b/src/alternativa/engine3d/materials/TextureMaterial.as index 05e21e2..3504555 100644 --- a/src/alternativa/engine3d/materials/TextureMaterial.as +++ b/src/alternativa/engine3d/materials/TextureMaterial.as @@ -42,13 +42,6 @@ package alternativa.engine3d.materials { */ public class TextureMaterial extends Material { - /** - * @private - */ - alternativa3d override function get canDrawInShadowMap():Boolean { - return opaquePass && alphaThreshold == 0; - } - private static var caches:Dictionary = new Dictionary(true); private var cachedContext3D:Context3D; private var programsCache:Dictionary; @@ -216,7 +209,7 @@ package alternativa.engine3d.materials { return program; } - private function getDrawUnit(program:ShaderProgram, camera:Camera3D, surface:Surface, geometry:Geometry, opacityMap:TextureResource):DrawUnit { + private function getDrawUnit(program:TextureMaterialProgram, camera:Camera3D, surface:Surface, geometry:Geometry, opacityMap:TextureResource):DrawUnit { var positionBuffer:VertexBuffer3D = geometry.getVertexBuffer(VertexAttributes.POSITION); var uvBuffer:VertexBuffer3D = geometry.getVertexBuffer(VertexAttributes.TEXCOORDS[0]); @@ -226,16 +219,16 @@ package alternativa.engine3d.materials { var drawUnit:DrawUnit = camera.renderer.createDrawUnit(object, program.program, geometry._indexBuffer, surface.indexBegin, surface.numTriangles, program); // Streams - drawUnit.setVertexBufferAt(program.vertexShader.getVariableIndex("aPosition"), positionBuffer, geometry._attributesOffsets[VertexAttributes.POSITION], VertexAttributes.FORMATS[VertexAttributes.POSITION]); - drawUnit.setVertexBufferAt(program.vertexShader.getVariableIndex("aUV"), uvBuffer, geometry._attributesOffsets[VertexAttributes.TEXCOORDS[0]], VertexAttributes.FORMATS[VertexAttributes.TEXCOORDS[0]]); + drawUnit.setVertexBufferAt(program.aPosition, positionBuffer, geometry._attributesOffsets[VertexAttributes.POSITION], VertexAttributes.FORMATS[VertexAttributes.POSITION]); + drawUnit.setVertexBufferAt(program.aUV, uvBuffer, geometry._attributesOffsets[VertexAttributes.TEXCOORDS[0]], VertexAttributes.FORMATS[VertexAttributes.TEXCOORDS[0]]); //Constants object.setTransformConstants(drawUnit, surface, program.vertexShader, camera); - drawUnit.setProjectionConstants(camera, program.vertexShader.getVariableIndex("cProjMatrix"), object.localToCameraTransform); - drawUnit.setFragmentConstantsFromNumbers(program.fragmentShader.getVariableIndex("cThresholdAlpha"), alphaThreshold, 0, 0, alpha); + drawUnit.setProjectionConstants(camera, program.cProjMatrix, object.localToCameraTransform); + drawUnit.setFragmentConstantsFromNumbers(program.cThresholdAlpha, alphaThreshold, 0, 0, alpha); // Textures - drawUnit.setTextureAt(program.fragmentShader.getVariableIndex("sDiffuse"), diffuseMap._texture); + drawUnit.setTextureAt(program.sDiffuse, diffuseMap._texture); if (opacityMap != null) { - drawUnit.setTextureAt(program.fragmentShader.getVariableIndex("sOpacity"), opacityMap._texture); + drawUnit.setTextureAt(program.sOpacity, opacityMap._texture); } return drawUnit; } @@ -268,7 +261,7 @@ package alternativa.engine3d.materials { programsCache[object.transformProcedure] = optionsPrograms; } - var program:ShaderProgram; + var program:TextureMaterialProgram; var drawUnit:DrawUnit; // Opaque pass if (opaquePass && alphaThreshold <= alpha) {