UNPKG

starling-framework

Version:

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

166 lines (151 loc) 5.86 kB
// Class: starling.rendering.VertexDataFormat 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 Std() {return require("./../../Std");} function starling_core_Starling() {return require("./../../starling/core/Starling");} function js__$Boot_HaxeError() {return require("./../../js/_Boot/HaxeError");} function openfl_errors_ArgumentError() {return $import(require("openfl/errors/ArgumentError"));} function starling_utils_StringUtil() {return require("./../../starling/utils/StringUtil");} function starling_rendering_VertexDataAttribute() {return require("./../../starling/rendering/VertexDataAttribute");} function openfl__$Vector_Vector_$Impl_$() {return require("./../../openfl/_Vector/Vector_Impl_");} function haxe_ds_StringMap() {return require("./../../haxe/ds/StringMap");} // Constructor var VertexDataFormat = function() { this._attributes = (openfl__$Vector_Vector_$Impl_$().default)._new(); } // Meta VertexDataFormat.__name__ = "starling.rendering.VertexDataFormat"; VertexDataFormat.__isInterface__ = false; VertexDataFormat.prototype = { extend: function(format) { return VertexDataFormat.fromString(this._format + ", " + 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); }, getFormat: function(attrName) { return this.getAttribute(attrName).format; }, getName: function(attrIndex) { return this._attributes[attrIndex].name; }, hasAttribute: function(attrName) { var numAttributes = this._attributes.length; var _g = 0; var _g1 = numAttributes; while(_g < _g1) { var i = _g++; if(this._attributes[i].name == attrName) { return true; } } return false; }, setVertexBufferAt: function(index,buffer,attrName) { var attribute = this.getAttribute(attrName); (starling_core_Starling().default).get_current().get_context().setVertexBufferAt(index,buffer,(Std().default).int(attribute.offset / 4),attribute.format); }, parseFormat: function(format) { if(format != null && format != "") { this._attributes.length = 0; this._format = ""; var parts = format.split(","); var numParts = parts.length; var offset = 0; var _g = 0; var _g1 = numParts; while(_g < _g1) { var i = _g++; var attrDesc = parts[i]; var attrParts = attrDesc.split(":"); if(attrParts.length != 2) { throw new (js__$Boot_HaxeError().default)(new (openfl_errors_ArgumentError().default)("Missing colon: " + attrDesc)); } var attrName = (starling_utils_StringUtil().default).trim(attrParts[0]); var attrFormat = (starling_utils_StringUtil().default).trim(attrParts[1]); if(attrName.length == 0 || attrFormat.length == 0) { throw new (js__$Boot_HaxeError().default)(new (openfl_errors_ArgumentError().default)("Invalid format string: " + attrDesc)); } var attribute = new (starling_rendering_VertexDataAttribute().default)(attrName,attrFormat,offset); offset += attribute.size; this._format += (i == 0 ? "" : ", ") + attribute.name + ":" + attribute.format; (openfl__$Vector_Vector_$Impl_$().default).set(this._attributes,this._attributes.length,attribute); } this._vertexSize = offset; } else { this._format = ""; } }, toString: function() { return this._format; }, getAttribute: function(attrName) { var i; var attribute; var numAttributes = this._attributes.length; var _g = 0; var _g1 = numAttributes; while(_g < _g1) { var i1 = _g++; attribute = this._attributes[i1]; if(attribute.name == attrName) { return attribute; } } return null; }, get_attributes: function() { return this._attributes; }, get_formatString: function() { return this._format; }, get_vertexSize: function() { return this._vertexSize; }, get_vertexSizeIn32Bits: function() { return (Std().default).int(this._vertexSize / 4); }, get_numAttributes: function() { return this._attributes.length; } }; VertexDataFormat.prototype.__class__ = VertexDataFormat.prototype.constructor = $hxClasses["starling.rendering.VertexDataFormat"] = VertexDataFormat; // Init Object.defineProperties(VertexDataFormat.prototype,{ attributes : { get : function () { return this.get_attributes (); }}, formatString : { get : function () { return this.get_formatString (); }}, vertexSize : { get : function () { return this.get_vertexSize (); }}, vertexSizeIn32Bits : { get : function () { return this.get_vertexSizeIn32Bits (); }}, numAttributes : { get : function () { return this.get_numAttributes (); }}}); // Statics VertexDataFormat.fromString = function(format) { if(format == null) { format = ""; } if(VertexDataFormat.sFormats.exists(format)) { return VertexDataFormat.sFormats.get(format); } else { var instance = new VertexDataFormat(); instance.parseFormat(format); var normalizedFormat = instance._format; if(VertexDataFormat.sFormats.exists(normalizedFormat)) { instance = VertexDataFormat.sFormats.get(normalizedFormat); } VertexDataFormat.sFormats.set(format,instance); VertexDataFormat.sFormats.set(normalizedFormat,instance); return instance; } } VertexDataFormat.sFormats = new (haxe_ds_StringMap().default)() // Export exports.default = VertexDataFormat;