TextureMaterial: Cache getVariableIndex()

This commit is contained in:
Yaski
2012-05-16 13:36:11 +06:00
parent c0fae48fea
commit a38a0ef4f3
2 changed files with 8 additions and 20 deletions

View File

@@ -27,11 +27,6 @@ package alternativa.engine3d.materials {
*/ */
public class Material { public class Material {
/**
* @private
*/
alternativa3d function get canDrawInShadowMap():Boolean {return true}
/** /**
* Name of the material * Name of the material
*/ */

View File

@@ -42,13 +42,6 @@ package alternativa.engine3d.materials {
*/ */
public class TextureMaterial extends Material { 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 static var caches:Dictionary = new Dictionary(true);
private var cachedContext3D:Context3D; private var cachedContext3D:Context3D;
private var programsCache:Dictionary; private var programsCache:Dictionary;
@@ -216,7 +209,7 @@ package alternativa.engine3d.materials {
return program; 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 positionBuffer:VertexBuffer3D = geometry.getVertexBuffer(VertexAttributes.POSITION);
var uvBuffer:VertexBuffer3D = geometry.getVertexBuffer(VertexAttributes.TEXCOORDS[0]); 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); var drawUnit:DrawUnit = camera.renderer.createDrawUnit(object, program.program, geometry._indexBuffer, surface.indexBegin, surface.numTriangles, program);
// Streams // Streams
drawUnit.setVertexBufferAt(program.vertexShader.getVariableIndex("aPosition"), positionBuffer, geometry._attributesOffsets[VertexAttributes.POSITION], VertexAttributes.FORMATS[VertexAttributes.POSITION]); drawUnit.setVertexBufferAt(program.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.aUV, uvBuffer, geometry._attributesOffsets[VertexAttributes.TEXCOORDS[0]], VertexAttributes.FORMATS[VertexAttributes.TEXCOORDS[0]]);
//Constants //Constants
object.setTransformConstants(drawUnit, surface, program.vertexShader, camera); object.setTransformConstants(drawUnit, surface, program.vertexShader, camera);
drawUnit.setProjectionConstants(camera, program.vertexShader.getVariableIndex("cProjMatrix"), object.localToCameraTransform); drawUnit.setProjectionConstants(camera, program.cProjMatrix, object.localToCameraTransform);
drawUnit.setFragmentConstantsFromNumbers(program.fragmentShader.getVariableIndex("cThresholdAlpha"), alphaThreshold, 0, 0, alpha); drawUnit.setFragmentConstantsFromNumbers(program.cThresholdAlpha, alphaThreshold, 0, 0, alpha);
// Textures // Textures
drawUnit.setTextureAt(program.fragmentShader.getVariableIndex("sDiffuse"), diffuseMap._texture); drawUnit.setTextureAt(program.sDiffuse, diffuseMap._texture);
if (opacityMap != null) { if (opacityMap != null) {
drawUnit.setTextureAt(program.fragmentShader.getVariableIndex("sOpacity"), opacityMap._texture); drawUnit.setTextureAt(program.sOpacity, opacityMap._texture);
} }
return drawUnit; return drawUnit;
} }
@@ -268,7 +261,7 @@ package alternativa.engine3d.materials {
programsCache[object.transformProcedure] = optionsPrograms; programsCache[object.transformProcedure] = optionsPrograms;
} }
var program:ShaderProgram; var program:TextureMaterialProgram;
var drawUnit:DrawUnit; var drawUnit:DrawUnit;
// Opaque pass // Opaque pass
if (opaquePass && alphaThreshold <= alpha) { if (opaquePass && alphaThreshold <= alpha) {