UNPKG

starling-framework

Version:

A fast, productive library for 2D cross-platform development.

228 lines (212 loc) 7.24 kB
// Class: starling.display.MeshBatch var $global = typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this $global.Object.defineProperty(exports, "__esModule", {value: true}); var __map_reserved = {}; // Imports var $hxClasses = require("./../../hxClasses_stub").default; var $hxEnums = require("./../../hxEnums_stub").default; var $import = require("./../../import_stub").default; var $extend = require("./../../extend_stub").default; function starling_display_Mesh() {return require("./../../starling/display/Mesh");} function Type() {return require("./../../Type");} function starling_utils_MatrixUtil() {return require("./../../starling/utils/MatrixUtil");} function starling_utils_MeshSubset() {return require("./../../starling/utils/MeshSubset");} function starling_rendering_VertexData() {return require("./../../starling/rendering/VertexData");} function starling_rendering_IndexData() {return require("./../../starling/rendering/IndexData");} // Constructor var MeshBatch = function() { var vertexData = new (starling_rendering_VertexData().default)(); var indexData = new (starling_rendering_IndexData().default)(); (starling_display_Mesh().default).call(this,vertexData,indexData); } // Meta MeshBatch.__name__ = "starling.display.MeshBatch"; MeshBatch.__isInterface__ = false; MeshBatch.__super__ = (starling_display_Mesh().default); MeshBatch.prototype = $extend((starling_display_Mesh().default).prototype, { dispose: function() { if(this.__effect != null) { this.__effect.dispose(); } (starling_display_Mesh().default).prototype.dispose.call(this); }, setVertexDataChanged: function() { this.__vertexSyncRequired = true; (starling_display_Mesh().default).prototype.setVertexDataChanged.call(this); }, setIndexDataChanged: function() { this.__indexSyncRequired = true; (starling_display_Mesh().default).prototype.setIndexDataChanged.call(this); }, __setVertexAndIndexDataChanged: function() { this.__vertexSyncRequired = this.__indexSyncRequired = true; }, __syncVertexBuffer: function() { this.__effect.uploadVertexData(this.__vertexData); this.__vertexSyncRequired = false; }, __syncIndexBuffer: function() { this.__effect.uploadIndexData(this.__indexData); this.__indexSyncRequired = false; }, clear: function() { if(this.__parent != null) { this.setRequiresRedraw(); } this.__vertexData.set_numVertices(0); this.__indexData.set_numIndices(0); this.__vertexSyncRequired = true; this.__indexSyncRequired = true; }, addMesh: function(mesh,matrix,alpha,subset,ignoreTransformations) { if(ignoreTransformations == null) { ignoreTransformations = false; } if(alpha == null) { alpha = 1.0; } this.addMeshAt(mesh,-1,-1,matrix,alpha,subset,ignoreTransformations); }, addMeshAt: function(mesh,indexID,vertexID,matrix,alpha,subset,ignoreTransformations) { if(ignoreTransformations == null) { ignoreTransformations = false; } if(alpha == null) { alpha = 1.0; } if(vertexID == null) { vertexID = -1; } if(indexID == null) { indexID = -1; } if(ignoreTransformations) { matrix = null; } else if(matrix == null) { matrix = mesh.get_transformationMatrix(); } if(subset == null) { subset = MeshBatch.sFullMeshSubset; } var oldNumVertices = this.__vertexData.get_numVertices(); var targetVertexID = vertexID >= 0 ? vertexID : oldNumVertices; var targetIndexID = indexID >= 0 ? indexID : this.__indexData.get_numIndices(); var meshStyle = mesh.__style; if(oldNumVertices == 0) { this.__setupFor(mesh); } meshStyle.batchVertexData(this.__style,targetVertexID,matrix,subset.vertexID,subset.numVertices); meshStyle.batchIndexData(this.__style,targetIndexID,targetVertexID - subset.vertexID,subset.indexID,subset.numIndices); if(alpha != 1.0) { this.__vertexData.scaleAlphas("color",alpha,targetVertexID,subset.numVertices); } if(this.__parent != null) { this.setRequiresRedraw(); } this.__indexSyncRequired = this.__vertexSyncRequired = true; }, __setupFor: function(mesh) { var meshStyle = mesh.__style; var meshStyleType = meshStyle.get_type(); if(this.__style.get_type() != meshStyleType) { var newStyle = (Type().default).createInstance(meshStyleType,[]); newStyle.copyFrom(meshStyle); this.setStyle(newStyle,false); } else { this.__style.copyFrom(meshStyle); } }, canAddMesh: function(mesh,numVertices) { if(numVertices == null) { numVertices = -1; } var currentNumVertices = this.__vertexData.get_numVertices(); if(currentNumVertices == 0) { return true; } if(numVertices < 0) { numVertices = mesh.get_numVertices(); } if(numVertices == 0) { return true; } if(numVertices + currentNumVertices > 65535) { return false; } return this.__style.canBatchWith(mesh.__style); }, render: function(painter) { if(this.__vertexData.get_numVertices() == 0) { return; } if(this.__pixelSnapping) { (starling_utils_MatrixUtil().default).snapToPixels(painter.get_state().get_modelviewMatrix(),painter.get_pixelSize()); } if(this.__batchable) { painter.batchMesh(this); } else { painter.finishMeshBatch(); var _g = painter; _g.set_drawCount(_g.get_drawCount() + 1); painter.prepareToDraw(); painter.excludeFromCache(this); if(this.__vertexSyncRequired) { this.__syncVertexBuffer(); } if(this.__indexSyncRequired) { this.__syncIndexBuffer(); } this.__style.updateEffect(this.__effect,painter.get_state()); this.__effect.render(0,this.__indexData.get_numTriangles()); } }, setStyle: function(meshStyle,mergeWithPredecessor) { if(mergeWithPredecessor == null) { mergeWithPredecessor = true; } var _gthis = this; (starling_display_Mesh().default).prototype.setStyle.call(this,meshStyle,mergeWithPredecessor); if(this.__effect != null) { this.__effect.dispose(); } this.__effect = this.get_style().createEffect(); this.__effect.set_onRestore(function(effect) { _gthis.__setVertexAndIndexDataChanged(); }); this.__setVertexAndIndexDataChanged(); }, set_numVertices: function(value) { if(this.__vertexData.get_numVertices() != value) { this.__vertexData.set_numVertices(value); this.__vertexSyncRequired = true; this.setRequiresRedraw(); } return value; }, set_numIndices: function(value) { if(this.__indexData.get_numIndices() != value) { this.__indexData.set_numIndices(value); this.__indexSyncRequired = true; this.setRequiresRedraw(); } return value; }, get_batchable: function() { return this.__batchable; }, set_batchable: function(value) { if(this.__batchable != value) { this.__batchable = value; this.setRequiresRedraw(); } return value; } }); MeshBatch.prototype.__class__ = MeshBatch.prototype.constructor = $hxClasses["starling.display.MeshBatch"] = MeshBatch; // Init Object.defineProperties(MeshBatch.prototype,{ batchable : { get : function () { return this.get_batchable (); }, set : function (v) { return this.set_batchable (v); }}}); // Statics MeshBatch.MAX_NUM_VERTICES = 65535 MeshBatch.sFullMeshSubset = new (starling_utils_MeshSubset().default)() // Export exports.default = MeshBatch;