UNPKG

starling-framework

Version:

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

903 lines (888 loc) 31.4 kB
// Class: starling.rendering.VertexData 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; function js__$Boot_HaxeError() {return require("./../../js/_Boot/HaxeError");} function openfl_errors_ArgumentError() {return $import(require("openfl/errors/ArgumentError"));} function openfl_errors_IllegalOperationError() {return $import(require("openfl/errors/IllegalOperationError"));} function Std() {return require("./../../Std");} function starling_utils_StringUtil() {return require("./../../starling/utils/StringUtil");} function openfl_geom_Point() {return $import(require("openfl/geom/Point"));} function openfl_geom_Vector3D() {return $import(require("openfl/geom/Vector3D"));} function _$UInt_UInt_$Impl_$() {return require("./../../_UInt/UInt_Impl_");} function openfl_geom_Rectangle() {return $import(require("openfl/geom/Rectangle"));} function starling_utils_MatrixUtil() {return require("./../../starling/utils/MatrixUtil");} function starling_utils_MathUtil() {return require("./../../starling/utils/MathUtil");} function starling_core_Starling() {return require("./../../starling/core/Starling");} function starling_errors_MissingContextError() {return require("./../../starling/errors/MissingContextError");} function openfl_utils_ByteArray() {return $import(require("openfl/utils/ByteArray"));} function starling_styles_MeshStyle() {return require("./../../starling/styles/MeshStyle");} function starling_rendering_VertexDataFormat() {return require("./../../starling/rendering/VertexDataFormat");} // Constructor var VertexData = function(format,initialCapacity) { if(initialCapacity == null) { initialCapacity = 32; } this._tinted = false; if(format == null) { this._format = (starling_styles_MeshStyle().default).VERTEX_FORMAT; } else if(((format) instanceof (starling_rendering_VertexDataFormat().default))) { this._format = format; } else if(typeof(format) == "string") { this._format = (starling_rendering_VertexDataFormat().default).fromString((Std().default).string(format)); } else { throw new (js__$Boot_HaxeError().default)(new (openfl_errors_ArgumentError().default)("'format' must be String or VertexDataFormat")); } this._attributes = this._format.get_attributes(); this._numAttributes = this._attributes.length; this._posOffset = this._format.hasAttribute("position") ? this._format.getOffset("position") : 0; this._colOffset = this._format.hasAttribute("color") ? this._format.getOffset("color") : 0; this._vertexSize = this._format.get_vertexSize(); this._numVertices = 0; this._premultipliedAlpha = true; this._rawData = new (openfl_utils_ByteArray().default)(); this._rawData.set_endian(VertexData.sBytes.set_endian("littleEndian")); this._rawData.length = initialCapacity * this._vertexSize; this._rawData.length = 0; } // Meta VertexData.__name__ = "starling.rendering.VertexData"; VertexData.__isInterface__ = false; VertexData.prototype = { clear: function() { this._rawData.clear(); this._numVertices = 0; this._tinted = false; }, clone: function() { var clone = new VertexData(this._format,this._numVertices); clone._rawData.writeBytes(this._rawData); clone._numVertices = this._numVertices; clone._premultipliedAlpha = this._premultipliedAlpha; clone._tinted = this._tinted; return clone; }, copyTo: function(target,targetVertexID,matrix,vertexID,numVertices) { if(numVertices == null) { numVertices = -1; } if(vertexID == null) { vertexID = 0; } if(targetVertexID == null) { targetVertexID = 0; } if(numVertices < 0 || vertexID + numVertices > this._numVertices) { numVertices = this._numVertices - vertexID; } if(this._format == target._format) { if(target._numVertices < targetVertexID + numVertices) { target._numVertices = targetVertexID + numVertices; } target._tinted = target._tinted || this._tinted; var targetRawData = target._rawData; targetRawData.position = targetVertexID * this._vertexSize; targetRawData.writeBytes(this._rawData,vertexID * this._vertexSize,numVertices * this._vertexSize); if(matrix != null) { var x; var y; var pos = targetVertexID * this._vertexSize + this._posOffset; var endPos = pos + numVertices * this._vertexSize; while(pos < endPos) { targetRawData.position = pos; x = targetRawData.readFloat(); y = targetRawData.readFloat(); targetRawData.position = pos; targetRawData.writeFloat(matrix.a * x + matrix.c * y + matrix.tx); targetRawData.writeFloat(matrix.d * y + matrix.b * x + matrix.ty); pos += this._vertexSize; } } } else { if(target._numVertices < targetVertexID + numVertices) { target.set_numVertices(targetVertexID + numVertices); } var _g = 0; var _g1 = this._numAttributes; while(_g < _g1) { var i = _g++; var srcAttr = this._attributes[i]; var tgtAttr = target.getAttribute(srcAttr.name); if(tgtAttr != null) { if(srcAttr.offset == this._posOffset) { this.copyAttributeTo_internal(target,targetVertexID,matrix,srcAttr,tgtAttr,vertexID,numVertices); } else { this.copyAttributeTo_internal(target,targetVertexID,null,srcAttr,tgtAttr,vertexID,numVertices); } } } } }, copyAttributeTo: function(target,targetVertexID,attrName,matrix,vertexID,numVertices) { if(numVertices == null) { numVertices = -1; } if(vertexID == null) { vertexID = 0; } var sourceAttribute = this.getAttribute(attrName); var targetAttribute = target.getAttribute(attrName); if(sourceAttribute == null) { throw new (js__$Boot_HaxeError().default)(new (openfl_errors_ArgumentError().default)("Attribute '" + attrName + "' not found in source data")); } if(targetAttribute == null) { throw new (js__$Boot_HaxeError().default)(new (openfl_errors_ArgumentError().default)("Attribute '" + attrName + "' not found in target data")); } if(sourceAttribute.isColor) { target._tinted = target._tinted || this._tinted; } this.copyAttributeTo_internal(target,targetVertexID,matrix,sourceAttribute,targetAttribute,vertexID,numVertices); }, copyAttributeTo_internal: function(target,targetVertexID,matrix,sourceAttribute,targetAttribute,vertexID,numVertices) { if(sourceAttribute.format != targetAttribute.format) { throw new (js__$Boot_HaxeError().default)(new (openfl_errors_IllegalOperationError().default)("Attribute formats differ between source and target")); } if(numVertices < 0 || vertexID + numVertices > this._numVertices) { numVertices = this._numVertices - vertexID; } if(target._numVertices < targetVertexID + numVertices) { target._numVertices = targetVertexID + numVertices; } var i; var j; var x; var y; var sourceData = this._rawData; var targetData = target._rawData; var sourceDelta = this._vertexSize - sourceAttribute.size; var targetDelta = target._vertexSize - targetAttribute.size; var attributeSizeIn32Bits = (Std().default).int(sourceAttribute.size / 4); sourceData.position = vertexID * this._vertexSize + sourceAttribute.offset; targetData.position = targetVertexID * target._vertexSize + targetAttribute.offset; if(matrix != null) { var _g = 0; var _g1 = numVertices; while(_g < _g1) { var i1 = _g++; x = sourceData.readFloat(); y = sourceData.readFloat(); targetData.writeFloat(matrix.a * x + matrix.c * y + matrix.tx); targetData.writeFloat(matrix.d * y + matrix.b * x + matrix.ty); sourceData.position = sourceData.position + sourceDelta; targetData.position = targetData.position + targetDelta; } } else { var _g2 = 0; var _g11 = numVertices; while(_g2 < _g11) { var i2 = _g2++; var _g3 = 0; var _g12 = attributeSizeIn32Bits; while(_g3 < _g12) { var j1 = _g3++; targetData.writeUnsignedInt(sourceData.readUnsignedInt()); } sourceData.position = sourceData.position + sourceDelta; targetData.position = targetData.position + targetDelta; } } }, trim: function() { var numBytes = this._numVertices * this._vertexSize; VertexData.sBytes.length = numBytes; VertexData.sBytes.position = 0; VertexData.sBytes.writeBytes(this._rawData,0,numBytes); this._rawData.clear(); this._rawData.length = numBytes; this._rawData.writeBytes(VertexData.sBytes); VertexData.sBytes.length = 0; }, toString: function() { return (starling_utils_StringUtil().default).format("[VertexData format=\"{0}\" numVertices={1}]",[this._format.get_formatString(),this._numVertices]); }, getUnsignedInt: function(vertexID,attrName) { this._rawData.position = vertexID * this._vertexSize + this.getAttribute(attrName).offset; return this._rawData.readUnsignedInt(); }, setUnsignedInt: function(vertexID,attrName,value) { if(this._numVertices < vertexID + 1) { this.set_numVertices(vertexID + 1); } this._rawData.position = vertexID * this._vertexSize + this.getAttribute(attrName).offset; this._rawData.writeUnsignedInt(value); }, getFloat: function(vertexID,attrName) { this._rawData.position = vertexID * this._vertexSize + this.getAttribute(attrName).offset; return this._rawData.readFloat(); }, setFloat: function(vertexID,attrName,value) { if(this._numVertices < vertexID + 1) { this.set_numVertices(vertexID + 1); } this._rawData.position = vertexID * this._vertexSize + this.getAttribute(attrName).offset; this._rawData.writeFloat(value); }, getPoint: function(vertexID,attrName,out) { if(out == null) { out = new (openfl_geom_Point().default)(); } var offset = attrName == "position" ? this._posOffset : this.getAttribute(attrName).offset; this._rawData.position = vertexID * this._vertexSize + offset; out.x = this._rawData.readFloat(); out.y = this._rawData.readFloat(); return out; }, setPoint: function(vertexID,attrName,x,y) { if(this._numVertices < vertexID + 1) { this.set_numVertices(vertexID + 1); } var offset = attrName == "position" ? this._posOffset : this.getAttribute(attrName).offset; this._rawData.position = vertexID * this._vertexSize + offset; this._rawData.writeFloat(x); this._rawData.writeFloat(y); }, getPoint3D: function(vertexID,attrName,out) { if(out == null) { out = new (openfl_geom_Vector3D().default)(); } this._rawData.position = vertexID * this._vertexSize + this.getAttribute(attrName).offset; out.x = this._rawData.readFloat(); out.y = this._rawData.readFloat(); out.z = this._rawData.readFloat(); return out; }, setPoint3D: function(vertexID,attrName,x,y,z) { if(this._numVertices < vertexID + 1) { this.set_numVertices(vertexID + 1); } this._rawData.position = vertexID * this._vertexSize + this.getAttribute(attrName).offset; this._rawData.writeFloat(x); this._rawData.writeFloat(y); this._rawData.writeFloat(z); }, getPoint4D: function(vertexID,attrName,out) { if(out == null) { out = new (openfl_geom_Vector3D().default)(); } this._rawData.position = vertexID * this._vertexSize + this.getAttribute(attrName).offset; out.x = this._rawData.readFloat(); out.y = this._rawData.readFloat(); out.z = this._rawData.readFloat(); out.w = this._rawData.readFloat(); return out; }, setPoint4D: function(vertexID,attrName,x,y,z,w) { if(w == null) { w = 1.0; } if(this._numVertices < vertexID + 1) { this.set_numVertices(vertexID + 1); } this._rawData.position = vertexID * this._vertexSize + this.getAttribute(attrName).offset; this._rawData.writeFloat(x); this._rawData.writeFloat(y); this._rawData.writeFloat(z); this._rawData.writeFloat(w); }, getColor: function(vertexID,attrName) { if(attrName == null) { attrName = "color"; } var offset = attrName == "color" ? this._colOffset : this.getAttribute(attrName).offset; this._rawData.position = vertexID * this._vertexSize + offset; var rgba = VertexData.switchEndian(this._rawData.readUnsignedInt()); if(this._premultipliedAlpha) { rgba = VertexData.unmultiplyAlpha(rgba); } return rgba >>> 8 & 16777215; }, setColor: function(vertexID,attrName,color) { if(this._numVertices < vertexID + 1) { this.set_numVertices(vertexID + 1); } var alpha = this.getAlpha(vertexID,attrName); this.colorize(attrName,color,alpha,vertexID,1); }, getAlpha: function(vertexID,attrName) { if(attrName == null) { attrName = "color"; } var offset = attrName == "color" ? this._colOffset : this.getAttribute(attrName).offset; this._rawData.position = vertexID * this._vertexSize + offset; var rgba = VertexData.switchEndian(this._rawData.readUnsignedInt()); return (_$UInt_UInt_$Impl_$().default).toFloat(rgba & 255) / 255.0; }, setAlpha: function(vertexID,attrName,alpha) { if(this._numVertices < vertexID + 1) { this.set_numVertices(vertexID + 1); } var color = this.getColor(vertexID,attrName); this.colorize(attrName,color,alpha,vertexID,1); }, getBounds: function(attrName,matrix,vertexID,numVertices,out) { if(numVertices == null) { numVertices = -1; } if(vertexID == null) { vertexID = 0; } if(attrName == null) { attrName = "position"; } if(out == null) { out = new (openfl_geom_Rectangle().default)(); } if(numVertices < 0 || vertexID + numVertices > this._numVertices) { numVertices = this._numVertices - vertexID; } if(numVertices == 0) { if(matrix == null) { out.setEmpty(); } else { (starling_utils_MatrixUtil().default).transformCoords(matrix,0,0,VertexData.sHelperPoint); out.setTo(VertexData.sHelperPoint.x,VertexData.sHelperPoint.y,0,0); } } else { var minX = 1.79e+308; var maxX = -1.79e+308; var minY = 1.79e+308; var maxY = -1.79e+308; var offset = attrName == "position" ? this._posOffset : this.getAttribute(attrName).offset; var position = vertexID * this._vertexSize + offset; var x; var y; var i; if(matrix == null) { var _g = 0; var _g1 = numVertices; while(_g < _g1) { var i1 = _g++; this._rawData.position = position; x = this._rawData.readFloat(); y = this._rawData.readFloat(); position += this._vertexSize; if(minX > x) { minX = x; } if(maxX < x) { maxX = x; } if(minY > y) { minY = y; } if(maxY < y) { maxY = y; } } } else { var _g2 = 0; var _g11 = numVertices; while(_g2 < _g11) { var i2 = _g2++; this._rawData.position = position; x = this._rawData.readFloat(); y = this._rawData.readFloat(); position += this._vertexSize; (starling_utils_MatrixUtil().default).transformCoords(matrix,x,y,VertexData.sHelperPoint); if(minX > VertexData.sHelperPoint.x) { minX = VertexData.sHelperPoint.x; } if(maxX < VertexData.sHelperPoint.x) { maxX = VertexData.sHelperPoint.x; } if(minY > VertexData.sHelperPoint.y) { minY = VertexData.sHelperPoint.y; } if(maxY < VertexData.sHelperPoint.y) { maxY = VertexData.sHelperPoint.y; } } } out.setTo(minX,minY,maxX - minX,maxY - minY); } return out; }, getBoundsProjected: function(attrName,matrix,camPos,vertexID,numVertices,out) { if(numVertices == null) { numVertices = -1; } if(vertexID == null) { vertexID = 0; } if(out == null) { out = new (openfl_geom_Rectangle().default)(); } if(camPos == null) { throw new (js__$Boot_HaxeError().default)(new (openfl_errors_ArgumentError().default)("camPos must not be null")); } if(numVertices < 0 || vertexID + numVertices > this._numVertices) { numVertices = this._numVertices - vertexID; } if(numVertices == 0) { if(matrix != null) { (starling_utils_MatrixUtil().default).transformCoords3D(matrix,0,0,0,VertexData.sHelperPoint3D); } else { VertexData.sHelperPoint3D.setTo(0,0,0); } (starling_utils_MathUtil().default).intersectLineWithXYPlane(camPos,VertexData.sHelperPoint3D,VertexData.sHelperPoint); out.setTo(VertexData.sHelperPoint.x,VertexData.sHelperPoint.y,0,0); } else { var minX = 1.79e+308; var maxX = -1.79e+308; var minY = 1.79e+308; var maxY = -1.79e+308; var offset = attrName == "position" ? this._posOffset : this.getAttribute(attrName).offset; var position = vertexID * this._vertexSize + offset; var x; var y; var i; var _g = 0; var _g1 = numVertices; while(_g < _g1) { var i1 = _g++; this._rawData.position = position; x = this._rawData.readFloat(); y = this._rawData.readFloat(); position += this._vertexSize; if(matrix != null) { (starling_utils_MatrixUtil().default).transformCoords3D(matrix,x,y,0,VertexData.sHelperPoint3D); } else { VertexData.sHelperPoint3D.setTo(x,y,0); } (starling_utils_MathUtil().default).intersectLineWithXYPlane(camPos,VertexData.sHelperPoint3D,VertexData.sHelperPoint); if(minX > VertexData.sHelperPoint.x) { minX = VertexData.sHelperPoint.x; } if(maxX < VertexData.sHelperPoint.x) { maxX = VertexData.sHelperPoint.x; } if(minY > VertexData.sHelperPoint.y) { minY = VertexData.sHelperPoint.y; } if(maxY < VertexData.sHelperPoint.y) { maxY = VertexData.sHelperPoint.y; } } out.setTo(minX,minY,maxX - minX,maxY - minY); } return out; }, get_premultipliedAlpha: function() { return this._premultipliedAlpha; }, set_premultipliedAlpha: function(value) { this.setPremultipliedAlpha(value,false); return value; }, setPremultipliedAlpha: function(value,updateData) { if(updateData && value != this._premultipliedAlpha) { var _g = 0; var _g1 = this._numAttributes; while(_g < _g1) { var i = _g++; var attribute = this._attributes[i]; if(attribute.isColor) { var pos = attribute.offset; var oldColor; var newColor; var _g2 = 0; var _g11 = this._numVertices; while(_g2 < _g11) { var j = _g2++; this._rawData.position = pos; oldColor = VertexData.switchEndian(this._rawData.readUnsignedInt()); newColor = value ? VertexData.premultiplyAlpha(oldColor) : VertexData.unmultiplyAlpha(oldColor); this._rawData.position = pos; this._rawData.writeUnsignedInt(VertexData.switchEndian(newColor)); pos += this._vertexSize; } } } } this._premultipliedAlpha = value; }, updateTinted: function(attrName) { if(attrName == null) { attrName = "color"; } var pos = attrName == "color" ? this._colOffset : this.getAttribute(attrName).offset; this._tinted = false; var white = -1; var _g = 0; var _g1 = this._numVertices; while(_g < _g1) { var i = _g++; this._rawData.position = pos; if(this._rawData.readUnsignedInt() != white) { this._tinted = true; break; } pos += this._vertexSize; } return this._tinted; }, transformPoints: function(attrName,matrix,vertexID,numVertices) { if(numVertices == null) { numVertices = -1; } if(vertexID == null) { vertexID = 0; } if(numVertices < 0 || vertexID + numVertices > this._numVertices) { numVertices = this._numVertices - vertexID; } var x; var y; var offset = attrName == "position" ? this._posOffset : this.getAttribute(attrName).offset; var pos = vertexID * this._vertexSize + offset; var endPos = pos + numVertices * this._vertexSize; while(pos < endPos) { this._rawData.position = pos; x = this._rawData.readFloat(); y = this._rawData.readFloat(); this._rawData.position = pos; this._rawData.writeFloat(matrix.a * x + matrix.c * y + matrix.tx); this._rawData.writeFloat(matrix.d * y + matrix.b * x + matrix.ty); pos += this._vertexSize; } }, translatePoints: function(attrName,deltaX,deltaY,vertexID,numVertices) { if(numVertices == null) { numVertices = -1; } if(vertexID == null) { vertexID = 0; } if(numVertices < 0 || vertexID + numVertices > this._numVertices) { numVertices = this._numVertices - vertexID; } var x; var y; var offset = attrName == "position" ? this._posOffset : this.getAttribute(attrName).offset; var pos = vertexID * this._vertexSize + offset; var endPos = pos + numVertices * this._vertexSize; while(pos < endPos) { this._rawData.position = pos; x = this._rawData.readFloat(); y = this._rawData.readFloat(); this._rawData.position = pos; this._rawData.writeFloat(x + deltaX); this._rawData.writeFloat(y + deltaY); pos += this._vertexSize; } }, scaleAlphas: function(attrName,factor,vertexID,numVertices) { if(numVertices == null) { numVertices = -1; } if(vertexID == null) { vertexID = 0; } if(factor == 1.0) { return; } if(numVertices < 0 || vertexID + numVertices > this._numVertices) { numVertices = this._numVertices - vertexID; } this._tinted = true; var i; var offset = attrName == "color" ? this._colOffset : this.getAttribute(attrName).offset; var colorPos = vertexID * this._vertexSize + offset; var alphaPos; var alpha; var rgba; var _g = 0; var _g1 = numVertices; while(_g < _g1) { var i1 = _g++; alphaPos = colorPos + 3; alpha = this._rawData.get(alphaPos) / 255.0 * factor; if(alpha > 1.0) { alpha = 1.0; } else if(alpha < 0.0) { alpha = 0.0; } if(alpha == 1.0 || !this._premultipliedAlpha) { this._rawData.set(alphaPos,(Std().default).int(alpha * 255.0)); } else { this._rawData.position = colorPos; rgba = VertexData.unmultiplyAlpha(VertexData.switchEndian(this._rawData.readUnsignedInt())); rgba = rgba & -256 | (Std().default).int(alpha * 255.0) & 255; rgba = VertexData.premultiplyAlpha(rgba); this._rawData.position = colorPos; this._rawData.writeUnsignedInt(VertexData.switchEndian(rgba)); } colorPos += this._vertexSize; } }, colorize: function(attrName,color,alpha,vertexID,numVertices) { if(numVertices == null) { numVertices = -1; } if(vertexID == null) { vertexID = 0; } if(alpha == null) { alpha = 1.0; } if(color == null) { color = 16777215; } if(attrName == null) { attrName = "color"; } if(numVertices < 0 || vertexID + numVertices > this._numVertices) { numVertices = this._numVertices - vertexID; } var offset = attrName == "color" ? this._colOffset : this.getAttribute(attrName).offset; var pos = vertexID * this._vertexSize + offset; var endPos = pos + numVertices * this._vertexSize; if(alpha > 1.0) { alpha = 1.0; } else if(alpha < 0.0) { alpha = 0.0; } var rgba = color << 8 & -256 | (Std().default).int(alpha * 255.0) & 255; if(rgba == -1 && numVertices == this._numVertices) { this._tinted = false; } else if(rgba != -1) { this._tinted = true; } if(this._premultipliedAlpha && alpha != 1.0) { rgba = VertexData.premultiplyAlpha(rgba); } this._rawData.position = vertexID * this._vertexSize + offset; this._rawData.writeUnsignedInt(VertexData.switchEndian(rgba)); while(pos < endPos) { this._rawData.position = pos; this._rawData.writeUnsignedInt(VertexData.switchEndian(rgba)); pos += this._vertexSize; } }, getFormat: function(attrName) { return this.getAttribute(attrName).format; }, getSize: function(attrName) { return this.getAttribute(attrName).size; }, getSizeIn32Bits: function(attrName) { return (Std().default).int(this.getAttribute(attrName).size / 4); }, getOffset: function(attrName) { return this.getAttribute(attrName).offset; }, getOffsetIn32Bits: function(attrName) { return (Std().default).int(this.getAttribute(attrName).offset / 4); }, hasAttribute: function(attrName) { return this.getAttribute(attrName) != null; }, createVertexBuffer: function(upload,bufferUsage) { if(bufferUsage == null) { bufferUsage = "staticDraw"; } if(upload == null) { upload = false; } var context = (starling_core_Starling().default).get_current().get_context(); if(context == null) { throw new (js__$Boot_HaxeError().default)(new (starling_errors_MissingContextError().default)()); } if(this._numVertices == 0) { return null; } var buffer = context.createVertexBuffer(this._numVertices,(Std().default).int(this._vertexSize / 4),bufferUsage); if(upload) { this.uploadToVertexBuffer(buffer); } return buffer; }, uploadToVertexBuffer: function(buffer,vertexID,numVertices) { if(numVertices == null) { numVertices = -1; } if(vertexID == null) { vertexID = 0; } if(numVertices < 0 || vertexID + numVertices > this._numVertices) { numVertices = this._numVertices - vertexID; } if(numVertices > 0) { buffer.uploadFromByteArray(this._rawData,0,vertexID,numVertices); } }, getAttribute: function(attrName) { var i; var attribute; var _g = 0; var _g1 = this._numAttributes; while(_g < _g1) { var i1 = _g++; attribute = this._attributes[i1]; if(attribute.name == attrName) { return attribute; } } return null; }, get_numVertices: function() { return this._numVertices; }, set_numVertices: function(value) { if(value > this._numVertices) { var oldLength = this._numVertices * this.get_vertexSize(); var newLength = value * this._vertexSize; if((_$UInt_UInt_$Impl_$().default).gt(this._rawData.length,oldLength)) { this._rawData.position = oldLength; while(this._rawData.get_bytesAvailable() != 0) this._rawData.writeUnsignedInt(0); } if((_$UInt_UInt_$Impl_$().default).gt(newLength,this._rawData.length)) { this._rawData.length = newLength; } var _g = 0; var _g1 = this._numAttributes; while(_g < _g1) { var i = _g++; var attribute = this._attributes[i]; if(attribute.isColor) { var pos = this._numVertices * this._vertexSize + attribute.offset; var _g2 = this._numVertices; var _g11 = value; while(_g2 < _g11) { var j = _g2++; this._rawData.position = pos; this._rawData.writeUnsignedInt(-1); pos += this._vertexSize; } } } } if(value == 0) { this._tinted = false; } this._numVertices = value; return value; }, get_rawData: function() { return this._rawData; }, get_format: function() { return this._format; }, set_format: function(value) { if(this._format == value) { return value; } var a; var i; var pos; var srcVertexSize = this._format.get_vertexSize(); var tgtVertexSize = value.get_vertexSize(); var numAttributes = value.get_numAttributes(); var tmp = value.get_vertexSize(); VertexData.sBytes.length = tmp * this._numVertices; var _g = 0; var _g1 = numAttributes; while(_g < _g1) { var a1 = _g++; var tgtAttr = value.get_attributes()[a1]; var srcAttr = this.getAttribute(tgtAttr.name); if(srcAttr != null) { pos = tgtAttr.offset; var _g2 = 0; var _g11 = this._numVertices; while(_g2 < _g11) { var i1 = _g2++; VertexData.sBytes.position = pos; VertexData.sBytes.writeBytes(this._rawData,srcVertexSize * i1 + srcAttr.offset,srcAttr.size); pos += tgtVertexSize; } } else if(tgtAttr.isColor) { pos = tgtAttr.offset; var _g3 = 0; var _g12 = this._numVertices; while(_g3 < _g12) { var i2 = _g3++; VertexData.sBytes.position = pos; VertexData.sBytes.writeUnsignedInt(-1); pos += tgtVertexSize; } } } if(value.get_vertexSize() > this._format.get_vertexSize()) { this._rawData.clear(); } this._rawData.position = 0; this._rawData.length = VertexData.sBytes.length; this._rawData.writeBytes(VertexData.sBytes); VertexData.sBytes.length = 0; this._format = value; this._attributes = this._format.get_attributes(); this._numAttributes = this._attributes.length; this._vertexSize = this._format.get_vertexSize(); this._posOffset = this._format.hasAttribute("position") ? this._format.getOffset("position") : 0; this._colOffset = this._format.hasAttribute("color") ? this._format.getOffset("color") : 0; return value; }, get_tinted: function() { return this._tinted; }, set_tinted: function(value) { return this._tinted = value; }, get_formatString: function() { return this._format.get_formatString(); }, get_vertexSize: function() { return this._vertexSize; }, get_vertexSizeIn32Bits: function() { return (Std().default).int(this._vertexSize / 4); }, get_size: function() { return (Std().default).int(this._numVertices * this._vertexSize); }, get_sizeIn32Bits: function() { return (Std().default).int(this._numVertices * this._vertexSize / 4); } }; VertexData.prototype.__class__ = VertexData.prototype.constructor = $hxClasses["starling.rendering.VertexData"] = VertexData; // Init Object.defineProperties(VertexData.prototype,{ premultipliedAlpha : { get : function () { return this.get_premultipliedAlpha (); }, set : function (v) { return this.set_premultipliedAlpha (v); }}, numVertices : { get : function () { return this.get_numVertices (); }, set : function (v) { return this.set_numVertices (v); }}, rawData : { get : function () { return this.get_rawData (); }}, format : { get : function () { return this.get_format (); }, set : function (v) { return this.set_format (v); }}, tinted : { get : function () { return this.get_tinted (); }, set : function (v) { return this.set_tinted (v); }}, formatString : { get : function () { return this.get_formatString (); }}, vertexSize : { get : function () { return this.get_vertexSize (); }}, vertexSizeIn32Bits : { get : function () { return this.get_vertexSizeIn32Bits (); }}, size : { get : function () { return this.get_size (); }}, sizeIn32Bits : { get : function () { return this.get_sizeIn32Bits (); }}}); // Statics VertexData.switchEndian = function(value) { return (value & 255) << 24 | (value >>> 8 & 255) << 16 | (value >>> 16 & 255) << 8 | value >>> 24 & 255; } VertexData.premultiplyAlpha = function(rgba) { var alpha = rgba & 255; if(alpha == 255) { return rgba; } else { var factor = (_$UInt_UInt_$Impl_$().default).toFloat(alpha) / 255.0; var r = (Std().default).int((_$UInt_UInt_$Impl_$().default).toFloat(rgba >>> 24 & 255) * factor); var g = (Std().default).int((_$UInt_UInt_$Impl_$().default).toFloat(rgba >>> 16 & 255) * factor); var b = (Std().default).int((_$UInt_UInt_$Impl_$().default).toFloat(rgba >>> 8 & 255) * factor); return (r & 255) << 24 | (g & 255) << 16 | (b & 255) << 8 | alpha; } } VertexData.unmultiplyAlpha = function(rgba) { var alpha = rgba & 255; if(alpha == 255 || alpha == 0) { return rgba; } else { var factor = (_$UInt_UInt_$Impl_$().default).toFloat(alpha) / 255.0; var r = (Std().default).int((_$UInt_UInt_$Impl_$().default).toFloat(rgba >>> 24 & 255) / factor); var g = (Std().default).int((_$UInt_UInt_$Impl_$().default).toFloat(rgba >>> 16 & 255) / factor); var b = (Std().default).int((_$UInt_UInt_$Impl_$().default).toFloat(rgba >>> 8 & 255) / factor); return (r & 255) << 24 | (g & 255) << 16 | (b & 255) << 8 | alpha; } } VertexData.sHelperPoint = new (openfl_geom_Point().default)() VertexData.sHelperPoint3D = new (openfl_geom_Vector3D().default)() VertexData.sBytes = new (openfl_utils_ByteArray().default)() // Export exports.default = VertexData;