// Class: openfl.display.ShaderParameter

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;
function lime_graphics__$WebGLRenderContext_WebGLRenderContext_$Impl_$() {return require("./../../lime/graphics/_WebGLRenderContext/WebGLRenderContext_Impl_");}
function Std() {return require("./../../Std");}
function StringTools() {return require("./../../StringTools");}

// Constructor

var ShaderParameter = function() {
	this.index = 0;
}

// Meta

ShaderParameter.__name__ = ["openfl","display","ShaderParameter"];
ShaderParameter.prototype = {
	__disableGL: function(context) {
		var gl = context.gl;
		if(!this.__isUniform) {
			var _g1 = 0;
			var _g = this.__arrayLength;
			while(_g1 < _g) {
				var i = _g1++;
				gl.disableVertexAttribArray(this.index + i);
			}
		}
	},
	__updateGL: function(context,overrideValue) {
		var gl = context.gl;
		var value = overrideValue != null ? overrideValue : this.value;
		var boolValue = this.__isBool ? value : null;
		var floatValue = this.__isFloat ? value : null;
		var intValue = this.__isInt ? value : null;
		if(this.__isUniform) {
			if(value != null && value.length >= this.__length) {
				var _g = this.type;
				switch(_g) {
				case "bool":
					gl.uniform1i(this.index,boolValue[0] ? 1 : 0);
					break;
				case "bool2":
					gl.uniform2i(this.index,boolValue[0] ? 1 : 0,boolValue[1] ? 1 : 0);
					break;
				case "bool3":
					gl.uniform3i(this.index,boolValue[0] ? 1 : 0,boolValue[1] ? 1 : 0,boolValue[2] ? 1 : 0);
					break;
				case "bool4":
					gl.uniform4i(this.index,boolValue[0] ? 1 : 0,boolValue[1] ? 1 : 0,boolValue[2] ? 1 : 0,boolValue[3] ? 1 : 0);
					break;
				case "float":
					gl.uniform1f(this.index,floatValue[0]);
					break;
				case "float2":
					gl.uniform2f(this.index,floatValue[0],floatValue[1]);
					break;
				case "float3":
					gl.uniform3f(this.index,floatValue[0],floatValue[1],floatValue[2]);
					break;
				case "float4":
					gl.uniform4f(this.index,floatValue[0],floatValue[1],floatValue[2],floatValue[3]);
					break;
				case "int":
					gl.uniform1i(this.index,intValue[0]);
					break;
				case "int2":
					gl.uniform2i(this.index,intValue[0],intValue[1]);
					break;
				case "int3":
					gl.uniform3i(this.index,intValue[0],intValue[1],intValue[2]);
					break;
				case "int4":
					gl.uniform4i(this.index,intValue[0],intValue[1],intValue[2],intValue[3]);
					break;
				case "matrix2x2":
					var _g1 = 0;
					while(_g1 < 4) {
						var i = _g1++;
						this.__uniformMatrix[i] = floatValue[i];
					}
					(lime_graphics__$WebGLRenderContext_WebGLRenderContext_$Impl_$().default).uniformMatrix2fv(gl,this.index,false,this.__uniformMatrix);
					break;
				case "matrix3x3":
					var _g2 = 0;
					while(_g2 < 9) {
						var i1 = _g2++;
						this.__uniformMatrix[i1] = floatValue[i1];
					}
					(lime_graphics__$WebGLRenderContext_WebGLRenderContext_$Impl_$().default).uniformMatrix3fv(gl,this.index,false,this.__uniformMatrix);
					break;
				case "matrix4x4":
					var _g3 = 0;
					while(_g3 < 16) {
						var i2 = _g3++;
						this.__uniformMatrix[i2] = floatValue[i2];
					}
					(lime_graphics__$WebGLRenderContext_WebGLRenderContext_$Impl_$().default).uniformMatrix4fv(gl,this.index,false,this.__uniformMatrix);
					break;
				default:
				}
			} else {
				var _g4 = this.type;
				switch(_g4) {
				case "bool":case "int":
					gl.uniform1i(this.index,0);
					break;
				case "bool2":case "int2":
					gl.uniform2i(this.index,0,0);
					break;
				case "float":
					gl.uniform1f(this.index,0);
					break;
				case "float2":
					gl.uniform2f(this.index,0,0);
					break;
				case "float3":
					gl.uniform3f(this.index,0,0,0);
					break;
				case "float4":
					gl.uniform4f(this.index,0,0,0,0);
					break;
				case "bool3":case "int3":
					gl.uniform3i(this.index,0,0,0);
					break;
				case "bool4":case "int4":
					gl.uniform4i(this.index,0,0,0,0);
					break;
				case "matrix2x2":
					var _g5 = 0;
					while(_g5 < 4) {
						var i3 = _g5++;
						this.__uniformMatrix[i3] = 0;
					}
					(lime_graphics__$WebGLRenderContext_WebGLRenderContext_$Impl_$().default).uniformMatrix2fv(gl,this.index,false,this.__uniformMatrix);
					break;
				case "matrix3x3":
					var _g6 = 0;
					while(_g6 < 9) {
						var i4 = _g6++;
						this.__uniformMatrix[i4] = 0;
					}
					(lime_graphics__$WebGLRenderContext_WebGLRenderContext_$Impl_$().default).uniformMatrix3fv(gl,this.index,false,this.__uniformMatrix);
					break;
				case "matrix4x4":
					var _g7 = 0;
					while(_g7 < 16) {
						var i5 = _g7++;
						this.__uniformMatrix[i5] = 0;
					}
					(lime_graphics__$WebGLRenderContext_WebGLRenderContext_$Impl_$().default).uniformMatrix4fv(gl,this.index,false,this.__uniformMatrix);
					break;
				default:
				}
			}
		} else if(!this.__useArray && (value == null || value.length == this.__length)) {
			var _g11 = 0;
			var _g8 = this.__arrayLength;
			while(_g11 < _g8) {
				var i6 = _g11++;
				gl.disableVertexAttribArray(this.index + i6);
			}
			if(value != null) {
				var _g9 = this.type;
				switch(_g9) {
				case "bool":
					gl.vertexAttrib1f(this.index,boolValue[0] ? 1 : 0);
					break;
				case "bool2":
					gl.vertexAttrib2f(this.index,boolValue[0] ? 1 : 0,boolValue[1] ? 1 : 0);
					break;
				case "bool3":
					gl.vertexAttrib3f(this.index,boolValue[0] ? 1 : 0,boolValue[1] ? 1 : 0,boolValue[2] ? 1 : 0);
					break;
				case "bool4":
					gl.vertexAttrib4f(this.index,boolValue[0] ? 1 : 0,boolValue[1] ? 1 : 0,boolValue[2] ? 1 : 0,boolValue[3] ? 1 : 0);
					break;
				case "float":
					gl.vertexAttrib1f(this.index,floatValue[0]);
					break;
				case "float2":
					gl.vertexAttrib2f(this.index,floatValue[0],floatValue[1]);
					break;
				case "float3":
					gl.vertexAttrib3f(this.index,floatValue[0],floatValue[1],floatValue[2]);
					break;
				case "float4":
					gl.vertexAttrib4f(this.index,floatValue[0],floatValue[1],floatValue[2],floatValue[3]);
					break;
				case "int":
					gl.vertexAttrib1f(this.index,intValue[0]);
					break;
				case "int2":
					gl.vertexAttrib2f(this.index,intValue[0],intValue[1]);
					break;
				case "int3":
					gl.vertexAttrib3f(this.index,intValue[0],intValue[1],intValue[2]);
					break;
				case "int4":
					gl.vertexAttrib4f(this.index,intValue[0],intValue[1],intValue[2],intValue[3]);
					break;
				case "matrix2x2":
					var _g10 = 0;
					while(_g10 < 2) {
						var i7 = _g10++;
						gl.vertexAttrib2f(this.index + i7,floatValue[i7 * 2],floatValue[i7 * 2 + 1]);
					}
					break;
				case "matrix3x3":
					var _g12 = 0;
					while(_g12 < 3) {
						var i8 = _g12++;
						gl.vertexAttrib3f(this.index + i8,floatValue[i8 * 3],floatValue[i8 * 3 + 1],floatValue[i8 * 3 + 2]);
					}
					break;
				case "matrix4x4":
					var _g13 = 0;
					while(_g13 < 4) {
						var i9 = _g13++;
						gl.vertexAttrib4f(this.index + i9,floatValue[i9 * 4],floatValue[i9 * 4 + 1],floatValue[i9 * 4 + 2],floatValue[i9 * 4 + 3]);
					}
					break;
				default:
				}
			} else {
				var _g14 = this.type;
				switch(_g14) {
				case "bool":case "float":case "int":
					gl.vertexAttrib1f(this.index,0);
					break;
				case "bool2":case "float2":case "int2":
					gl.vertexAttrib2f(this.index,0,0);
					break;
				case "bool3":case "float3":case "int3":
					gl.vertexAttrib3f(this.index,0,0,0);
					break;
				case "bool4":case "float4":case "int4":
					gl.vertexAttrib4f(this.index,0,0,0,0);
					break;
				case "matrix2x2":
					var _g15 = 0;
					while(_g15 < 2) {
						var i10 = _g15++;
						gl.vertexAttrib2f(this.index + i10,0,0);
					}
					break;
				case "matrix3x3":
					var _g16 = 0;
					while(_g16 < 3) {
						var i11 = _g16++;
						gl.vertexAttrib3f(this.index + i11,0,0,0);
					}
					break;
				case "matrix4x4":
					var _g17 = 0;
					while(_g17 < 4) {
						var i12 = _g17++;
						gl.vertexAttrib4f(this.index + i12,0,0,0,0);
					}
					break;
				default:
				}
			}
		} else {
			var _g18 = 0;
			var _g19 = this.__arrayLength;
			while(_g18 < _g19) {
				var i13 = _g18++;
				gl.enableVertexAttribArray(this.index + i13);
			}
		}
	},
	__updateGLFromBuffer: function(context,buffer,position,length,bufferOffset) {
		var gl = context.gl;
		if(this.__isUniform) {
			if(length >= this.__length) {
				var _g = this.type;
				switch(_g) {
				case "bool":case "int":
					gl.uniform1i(this.index,(Std().default)["int"](buffer[position]));
					break;
				case "bool2":case "int2":
					gl.uniform2i(this.index,(Std().default)["int"](buffer[position]),(Std().default)["int"](buffer[position + 1]));
					break;
				case "float":
					gl.uniform1f(this.index,buffer[position]);
					break;
				case "float2":
					gl.uniform2f(this.index,buffer[position],buffer[position + 1]);
					break;
				case "float3":
					gl.uniform3f(this.index,buffer[position],buffer[position + 1],buffer[position + 2]);
					break;
				case "float4":
					gl.uniform4f(this.index,buffer[position],buffer[position + 1],buffer[position + 2],buffer[position + 3]);
					break;
				case "bool3":case "int3":
					gl.uniform3i(this.index,(Std().default)["int"](buffer[position]),(Std().default)["int"](buffer[position + 1]),(Std().default)["int"](buffer[position + 2]));
					break;
				case "bool4":case "int4":
					gl.uniform4i(this.index,(Std().default)["int"](buffer[position]),(Std().default)["int"](buffer[position + 1]),(Std().default)["int"](buffer[position + 2]),(Std().default)["int"](buffer[position + 3]));
					break;
				case "matrix2x2":
					var _g1 = 0;
					while(_g1 < 4) {
						var i = _g1++;
						this.__uniformMatrix[i] = buffer[position + i];
					}
					(lime_graphics__$WebGLRenderContext_WebGLRenderContext_$Impl_$().default).uniformMatrix2fv(gl,this.index,false,this.__uniformMatrix);
					break;
				case "matrix3x3":
					var _g2 = 0;
					while(_g2 < 9) {
						var i1 = _g2++;
						this.__uniformMatrix[i1] = buffer[position + i1];
					}
					(lime_graphics__$WebGLRenderContext_WebGLRenderContext_$Impl_$().default).uniformMatrix3fv(gl,this.index,false,this.__uniformMatrix);
					break;
				case "matrix4x4":
					var _g3 = 0;
					while(_g3 < 16) {
						var i2 = _g3++;
						this.__uniformMatrix[i2] = buffer[position + i2];
					}
					(lime_graphics__$WebGLRenderContext_WebGLRenderContext_$Impl_$().default).uniformMatrix4fv(gl,this.index,false,this.__uniformMatrix);
					break;
				default:
				}
			}
		} else if(!(StringTools().default).startsWith(this.name,"openfl_") && (length == 0 || length == this.__length)) {
			var _g11 = 0;
			var _g4 = this.__arrayLength;
			while(_g11 < _g4) {
				var i3 = _g11++;
				gl.disableVertexAttribArray(this.index + i3);
			}
			if(length > 0) {
				var _g5 = this.type;
				switch(_g5) {
				case "bool":case "float":case "int":
					gl.vertexAttrib1f(this.index,buffer[position]);
					break;
				case "bool2":case "float2":case "int2":
					gl.vertexAttrib2f(this.index,buffer[position],buffer[position + 1]);
					break;
				case "bool3":case "float3":case "int3":
					gl.vertexAttrib3f(this.index,buffer[position],buffer[position + 1],buffer[position + 2]);
					break;
				case "bool4":case "float4":case "int4":
					gl.vertexAttrib4f(this.index,buffer[position],buffer[position + 1],buffer[position + 2],buffer[position + 3]);
					break;
				case "matrix2x2":
					var _g6 = 0;
					while(_g6 < 2) {
						var i4 = _g6++;
						gl.vertexAttrib2f(this.index + i4,buffer[position + i4 * 2],buffer[position + i4 * 2 + 1]);
					}
					break;
				case "matrix3x3":
					var _g7 = 0;
					while(_g7 < 3) {
						var i5 = _g7++;
						gl.vertexAttrib3f(this.index + i5,buffer[position + i5 * 3],buffer[position + i5 * 3 + 1],buffer[position + i5 * 3 + 2]);
					}
					break;
				case "matrix4x4":
					var _g8 = 0;
					while(_g8 < 4) {
						var i6 = _g8++;
						gl.vertexAttrib4f(this.index + i6,buffer[position + i6 * 4],buffer[position + i6 * 4 + 1],buffer[position + i6 * 4 + 2],buffer[position + i6 * 4 + 3]);
					}
					break;
				default:
				}
			} else {
				var _g9 = this.type;
				switch(_g9) {
				case "bool":case "float":case "int":
					gl.vertexAttrib1f(this.index,0);
					break;
				case "bool2":case "float2":case "int2":
					gl.vertexAttrib2f(this.index,0,0);
					break;
				case "bool3":case "float3":case "int3":
					gl.vertexAttrib3f(this.index,0,0,0);
					break;
				case "bool4":case "float4":case "int4":
					gl.vertexAttrib4f(this.index,0,0,0,0);
					break;
				case "matrix2x2":
					var _g10 = 0;
					while(_g10 < 2) {
						var i7 = _g10++;
						gl.vertexAttrib2f(this.index + i7,0,0);
					}
					break;
				case "matrix3x3":
					var _g12 = 0;
					while(_g12 < 3) {
						var i8 = _g12++;
						gl.vertexAttrib3f(this.index + i8,0,0,0);
					}
					break;
				case "matrix4x4":
					var _g13 = 0;
					while(_g13 < 4) {
						var i9 = _g13++;
						gl.vertexAttrib4f(this.index + i9,0,0,0,0);
					}
					break;
				default:
				}
			}
		} else {
			var type = gl.FLOAT;
			if(this.__isBool) {
				type = gl.INT;
			} else if(this.__isInt) {
				type = gl.INT;
			}
			var _g14 = 0;
			var _g15 = this.__arrayLength;
			while(_g14 < _g15) {
				var i10 = _g14++;
				gl.enableVertexAttribArray(this.index + i10);
			}
			if(length > 0) {
				var _g16 = 0;
				var _g17 = this.__arrayLength;
				while(_g16 < _g17) {
					var i11 = _g16++;
					gl.vertexAttribPointer(this.index + i11,this.__length,type,false,this.__length * 4,(position + bufferOffset * this.__length + i11 * this.__arrayLength) * 4);
				}
			}
		}
	}
};
ShaderParameter.prototype.__class__ = ShaderParameter.prototype.constructor = $hxClasses["openfl.display.ShaderParameter"] = ShaderParameter;

// Init



// Statics




// Export

exports.default = ShaderParameter;