// Class: openfl._internal.renderer.ShaderBuffer

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 $import = require("./../../../import_stub").default;

// Constructor

var ShaderBuffer = function() {
	this.inputRefs = [];
	this.inputFilter = [];
	this.inputMipFilter = [];
	this.inputs = [];
	this.inputWrap = [];
	this.overrideNames = [];
	this.overrideValues = [];
	this.paramLengths = [];
	this.paramPositions = [];
	this.paramRefs_Bool = [];
	this.paramRefs_Float = [];
	this.paramRefs_Int = [];
	this.paramTypes = [];
}

// Meta

ShaderBuffer.__name__ = ["openfl","_internal","renderer","ShaderBuffer"];
ShaderBuffer.prototype = {
	addOverride: function(name,values) {
		this.overrideNames[this.overrideCount] = name;
		this.overrideValues[this.overrideCount] = values;
		this.overrideCount++;
	},
	clearOverride: function() {
		this.overrideCount = 0;
	},
	update: function(shader) {
		this.inputCount = 0;
		this.overrideCount = 0;
		this.paramBoolCount = 0;
		this.paramCount = 0;
		this.paramDataLength = 0;
		this.paramFloatCount = 0;
		this.paramIntCount = 0;
		this.shader = null;
		if(shader == null) {
			return;
		}
		shader.__init();
		this.inputCount = shader.__inputBitmapData.length;
		var input;
		var _g1 = 0;
		var _g = this.inputCount;
		while(_g1 < _g) {
			var i = _g1++;
			input = shader.__inputBitmapData[i];
			this.inputs[i] = input.input;
			this.inputFilter[i] = input.filter;
			this.inputMipFilter[i] = input.mipFilter;
			this.inputRefs[i] = input;
			this.inputWrap[i] = input.wrap;
		}
		var boolCount = shader.__paramBool.length;
		var floatCount = shader.__paramFloat.length;
		var intCount = shader.__paramInt.length;
		this.paramCount = boolCount + floatCount + intCount;
		this.paramBoolCount = boolCount;
		this.paramFloatCount = floatCount;
		this.paramIntCount = intCount;
		var paramLength = 0;
		var length = 0;
		var p = 0;
		var param;
		var _g11 = 0;
		var _g2 = boolCount;
		while(_g11 < _g2) {
			var i1 = _g11++;
			param = shader.__paramBool[i1];
			this.paramPositions[p] = this.paramDataLength;
			if(param.value != null) {
				length = param.value.length;
			} else {
				length = 0;
			}
			this.paramLengths[p] = length;
			this.paramDataLength += length;
			this.paramTypes[p] = 0;
			this.paramRefs_Bool[i1] = param;
			++p;
		}
		var param1;
		var _g12 = 0;
		var _g3 = floatCount;
		while(_g12 < _g3) {
			var i2 = _g12++;
			param1 = shader.__paramFloat[i2];
			this.paramPositions[p] = this.paramDataLength;
			if(param1.value != null) {
				length = param1.value.length;
			} else {
				length = 0;
			}
			this.paramLengths[p] = length;
			this.paramDataLength += length;
			this.paramTypes[p] = 1;
			this.paramRefs_Float[i2] = param1;
			++p;
		}
		var param2;
		var _g13 = 0;
		var _g4 = intCount;
		while(_g13 < _g4) {
			var i3 = _g13++;
			param2 = shader.__paramInt[i3];
			this.paramPositions[p] = this.paramDataLength;
			if(param2.value != null) {
				length = param2.value.length;
			} else {
				length = 0;
			}
			this.paramLengths[p] = length;
			this.paramDataLength += length;
			this.paramTypes[p] = 2;
			this.paramRefs_Int[i3] = param2;
			++p;
		}
		if(this.paramDataLength > 0) {
			if(this.paramData == null) {
				var elements = this.paramDataLength;
				var this1;
				if(elements != null) {
					this1 = new Float32Array(elements);
				} else {
					this1 = null;
				}
				this.paramData = this1;
			} else if(this.paramDataLength > this.paramData.length) {
				var elements1 = this.paramDataLength;
				var this2;
				if(elements1 != null) {
					this2 = new Float32Array(elements1);
				} else {
					this2 = null;
				}
				var data = this2;
				data.set(this.paramData);
				this.paramData = data;
			}
		}
		var boolIndex = 0;
		var floatIndex = 0;
		var intIndex = 0;
		var paramPosition = 0;
		var boolParam;
		var floatParam;
		var intParam;
		var length1;
		var _g14 = 0;
		var _g5 = this.paramCount;
		while(_g14 < _g5) {
			var i4 = _g14++;
			length1 = this.paramLengths[i4];
			if(i4 < boolCount) {
				boolParam = this.paramRefs_Bool[boolIndex];
				++boolIndex;
				var _g31 = 0;
				var _g21 = length1;
				while(_g31 < _g21) {
					var j = _g31++;
					this.paramData[paramPosition] = boolParam.value[j] ? 1 : 0;
					++paramPosition;
				}
			} else if(i4 < boolCount + floatCount) {
				floatParam = this.paramRefs_Float[floatIndex];
				++floatIndex;
				var _g32 = 0;
				var _g22 = length1;
				while(_g32 < _g22) {
					var j1 = _g32++;
					this.paramData[paramPosition] = floatParam.value[j1];
					++paramPosition;
				}
			} else {
				intParam = this.paramRefs_Int[intIndex];
				++intIndex;
				var _g33 = 0;
				var _g23 = length1;
				while(_g33 < _g23) {
					var j2 = _g33++;
					this.paramData[paramPosition] = intParam.value[j2];
					++paramPosition;
				}
			}
		}
		this.shader = shader;
	}
};
ShaderBuffer.prototype.__class__ = $hxClasses["openfl._internal.renderer.ShaderBuffer"] = ShaderBuffer;

// Init



// Statics




// Export

exports.default = ShaderBuffer;