// Class: openfl.display.OpenGLRenderer

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;
var $extend = require("./../../extend_stub").default;
function openfl_display_DisplayObjectRenderer() {return require("./../../openfl/display/DisplayObjectRenderer");}
function lime_math__$Matrix4_Matrix4_$Impl_$() {return require("./../../lime/math/_Matrix4/Matrix4_Impl_");}
function openfl_geom_Matrix() {return require("./../../openfl/geom/Matrix");}
function openfl_geom_Rectangle() {return require("./../../openfl/geom/Rectangle");}
function lime_utils__$DataPointer_DataPointer_$Impl_$() {return require("./../../lime/utils/_DataPointer/DataPointer_Impl_");}
function openfl_display_Graphics() {return require("./../../openfl/display/Graphics");}
function openfl_display_CanvasRenderer() {return require("./../../openfl/display/CanvasRenderer");}
function lime_graphics_RendererType() {return require("./../../lime/graphics/RendererType");}
function openfl_display_DisplayObjectShader() {return require("./../../openfl/display/DisplayObjectShader");}
function openfl_display_GraphicsShader() {return require("./../../openfl/display/GraphicsShader");}
function openfl__$internal_renderer_opengl_GLMaskShader() {return require("./../../openfl/_internal/renderer/opengl/GLMaskShader");}

// Constructor

var OpenGLRenderer = function(gl,defaultRenderTarget) {
	(openfl_display_DisplayObjectRenderer().default).call(this);
	this.gl = gl.__context;
	this.__defaultRenderTarget = defaultRenderTarget;
	this.__flipped = this.__defaultRenderTarget == null;
	this.__gl = gl;
	if((openfl_display_Graphics().default).maxTextureWidth == null) {
		(openfl_display_Graphics().default).maxTextureWidth = (openfl_display_Graphics().default).maxTextureHeight = this.__gl.getInteger(this.__gl.MAX_TEXTURE_SIZE);
	}
	this.__matrix = (lime_math__$Matrix4_Matrix4_$Impl_$().default)._new();
	this.__values = [];
	this.__softwareRenderer = new (openfl_display_CanvasRenderer().default)(null);
	this.__type = (lime_graphics_RendererType().default).OPENGL;
	this.__setBlendMode("normal");
	this.__gl.enable(this.__gl.BLEND);
	this.__clipRects = [];
	this.__maskObjects = [];
	this.__numClipRects = 0;
	this.__stencilReference = 0;
	this.__tempRect = new (openfl_geom_Rectangle().default)();
	this.__defaultDisplayShader = new (openfl_display_DisplayObjectShader().default)();
	this.__defaultGraphicsShader = new (openfl_display_GraphicsShader().default)();
	this.__defaultShader = this.__defaultDisplayShader;
	this.__initShader(this.__defaultShader);
	this.__maskShader = new (openfl__$internal_renderer_opengl_GLMaskShader().default)();
}

// Meta

OpenGLRenderer.__name__ = ["openfl","display","OpenGLRenderer"];
OpenGLRenderer.__super__ = (openfl_display_DisplayObjectRenderer().default);
OpenGLRenderer.prototype = $extend((openfl_display_DisplayObjectRenderer().default).prototype, {
	applyAlpha: function(alpha) {
		OpenGLRenderer.__alphaValue[0] = alpha;
		if(this.__currentShaderBuffer != null) {
			this.__currentShaderBuffer.addOverride("openfl_Alpha",OpenGLRenderer.__alphaValue);
		} else if(this.__currentShader != null) {
			if(this.__currentShader.__alpha != null) {
				this.__currentShader.__alpha.value = OpenGLRenderer.__alphaValue;
			}
		}
	},
	applyBitmapData: function(bitmapData,smooth,repeat) {
		if(repeat == null) {
			repeat = false;
		}
		if(this.__currentShaderBuffer != null) {
			if(bitmapData != null) {
				OpenGLRenderer.__textureSizeValue[0] = bitmapData.width;
				OpenGLRenderer.__textureSizeValue[1] = bitmapData.height;
				this.__currentShaderBuffer.addOverride("openfl_TextureSize",OpenGLRenderer.__textureSizeValue);
			}
		} else if(this.__currentShader != null) {
			if(this.__currentShader.__bitmap != null) {
				this.__currentShader.__bitmap.input = bitmapData;
				this.__currentShader.__bitmap.filter = smooth ? "linear" : "nearest";
				this.__currentShader.__bitmap.mipFilter = "mipnone";
				this.__currentShader.__bitmap.wrap = repeat ? "repeat" : "clamp";
			}
			if(this.__currentShader.__texture != null) {
				this.__currentShader.__texture.input = bitmapData;
				this.__currentShader.__texture.filter = smooth ? "linear" : "nearest";
				this.__currentShader.__texture.mipFilter = "mipnone";
				this.__currentShader.__texture.wrap = repeat ? "repeat" : "clamp";
			}
			if(this.__currentShader.__textureSize != null) {
				if(bitmapData != null) {
					OpenGLRenderer.__textureSizeValue[0] = bitmapData.width;
					OpenGLRenderer.__textureSizeValue[1] = bitmapData.height;
					this.__currentShader.__textureSize.value = OpenGLRenderer.__textureSizeValue;
				} else {
					this.__currentShader.__textureSize.value = null;
				}
			}
		}
	},
	applyColorTransform: function(colorTransform) {
		var enabled = colorTransform != null && !colorTransform.__isDefault();
		this.applyHasColorTransform(enabled);
		if(enabled) {
			colorTransform.__setArrays(OpenGLRenderer.__colorMultipliersValue,OpenGLRenderer.__colorOffsetsValue);
			if(this.__currentShaderBuffer != null) {
				this.__currentShaderBuffer.addOverride("openfl_ColorMultiplier",OpenGLRenderer.__colorMultipliersValue);
				this.__currentShaderBuffer.addOverride("openfl_ColorOffset",OpenGLRenderer.__colorOffsetsValue);
			} else if(this.__currentShader != null) {
				if(this.__currentShader.__colorMultiplier != null) {
					this.__currentShader.__colorMultiplier.value = OpenGLRenderer.__colorMultipliersValue;
				}
				if(this.__currentShader.__colorOffset != null) {
					this.__currentShader.__colorOffset.value = OpenGLRenderer.__colorOffsetsValue;
				}
			}
		} else if(this.__currentShaderBuffer != null) {
			this.__currentShaderBuffer.addOverride("openfl_ColorMultiplier",OpenGLRenderer.__emptyColorValue);
			this.__currentShaderBuffer.addOverride("openfl_ColorOffset",OpenGLRenderer.__emptyColorValue);
		} else if(this.__currentShader != null) {
			if(this.__currentShader.__colorMultiplier != null) {
				this.__currentShader.__colorMultiplier.value = OpenGLRenderer.__emptyColorValue;
			}
			if(this.__currentShader.__colorOffset != null) {
				this.__currentShader.__colorOffset.value = OpenGLRenderer.__emptyColorValue;
			}
		}
	},
	applyHasColorTransform: function(enabled) {
		OpenGLRenderer.__hasColorTransformValue[0] = enabled;
		if(this.__currentShaderBuffer != null) {
			this.__currentShaderBuffer.addOverride("openfl_HasColorTransform",OpenGLRenderer.__hasColorTransformValue);
		} else if(this.__currentShader != null) {
			if(this.__currentShader.__hasColorTransform != null) {
				this.__currentShader.__hasColorTransform.value = OpenGLRenderer.__hasColorTransformValue;
			}
		}
	},
	applyMatrix: function(matrix) {
		if(this.__currentShaderBuffer != null) {
			this.__currentShaderBuffer.addOverride("openfl_Matrix",matrix);
		} else if(this.__currentShader != null) {
			if(this.__currentShader.__matrix != null) {
				this.__currentShader.__matrix.value = matrix;
			}
		}
	},
	getMatrix: function(transform) {
		if(this.gl != null) {
			var values = this.__getMatrix(transform);
			var _g = 0;
			while(_g < 16) {
				var i = _g++;
				(lime_math__$Matrix4_Matrix4_$Impl_$().default).set(this.__matrix,i,values[i]);
			}
			return this.__matrix;
		} else {
			(lime_math__$Matrix4_Matrix4_$Impl_$().default).identity(this.__matrix);
			(lime_math__$Matrix4_Matrix4_$Impl_$().default).set(this.__matrix,0,transform.a);
			(lime_math__$Matrix4_Matrix4_$Impl_$().default).set(this.__matrix,1,transform.b);
			(lime_math__$Matrix4_Matrix4_$Impl_$().default).set(this.__matrix,4,transform.c);
			(lime_math__$Matrix4_Matrix4_$Impl_$().default).set(this.__matrix,5,transform.d);
			(lime_math__$Matrix4_Matrix4_$Impl_$().default).set(this.__matrix,12,transform.tx);
			(lime_math__$Matrix4_Matrix4_$Impl_$().default).set(this.__matrix,13,transform.ty);
			return this.__matrix;
		}
	},
	setShader: function(shader) {
		this.__currentShaderBuffer = null;
		if(this.__currentShader == shader) {
			return;
		}
		if(this.__currentShader != null) {
			this.__currentShader.__disable();
		}
		if(shader == null) {
			this.__currentShader = null;
			this.__gl.useProgram(null);
			return;
		} else {
			this.__currentShader = shader;
			this.__initShader(shader);
			this.__gl.useProgram(shader.glProgram);
			this.__currentShader.__enable();
		}
	},
	setViewport: function() {
		this.__gl.viewport(this.__offsetX,this.__offsetY,this.__displayWidth,this.__displayHeight);
	},
	updateShader: function() {
		if(this.__currentShader != null) {
			if(this.__currentShader.__position != null) {
				this.__currentShader.__position.__useArray = true;
			}
			if(this.__currentShader.__textureCoord != null) {
				this.__currentShader.__textureCoord.__useArray = true;
			}
			this.__currentShader.__update();
		}
	},
	useAlphaArray: function() {
		if(this.__currentShader != null) {
			if(this.__currentShader.__alpha != null) {
				this.__currentShader.__alpha.__useArray = true;
			}
		}
	},
	useColorTransformArray: function() {
		if(this.__currentShader != null) {
			if(this.__currentShader.__colorMultiplier != null) {
				this.__currentShader.__colorMultiplier.__useArray = true;
			}
			if(this.__currentShader.__colorOffset != null) {
				this.__currentShader.__colorOffset.__useArray = true;
			}
		}
	},
	__cleanup: function() {
		if(this.__stencilReference > 0) {
			this.__stencilReference = 0;
			this.__gl.disable(this.__gl.STENCIL_TEST);
		}
		if(this.__numClipRects > 0) {
			this.__numClipRects = 0;
			this.__scissorRect();
		}
	},
	__clear: function() {
		if(this.__stage == null || this.__stage.__transparent) {
			this.__gl.clearColor(0,0,0,0);
		} else {
			this.__gl.clearColor(this.__stage.__colorSplit[0],this.__stage.__colorSplit[1],this.__stage.__colorSplit[2],1);
		}
		this.__gl.clear(this.__gl.COLOR_BUFFER_BIT);
	},
	__clearShader: function() {
		if(this.__currentShader != null) {
			if(this.__currentShaderBuffer == null) {
				if(this.__currentShader.__bitmap != null) {
					this.__currentShader.__bitmap.input = null;
				}
			} else {
				this.__currentShaderBuffer.clearOverride();
			}
			if(this.__currentShader.__texture != null) {
				this.__currentShader.__texture.input = null;
			}
			if(this.__currentShader.__textureSize != null) {
				this.__currentShader.__textureSize.value = null;
			}
			if(this.__currentShader.__hasColorTransform != null) {
				this.__currentShader.__hasColorTransform.value = null;
			}
			if(this.__currentShader.__position != null) {
				this.__currentShader.__position.value = null;
			}
			if(this.__currentShader.__matrix != null) {
				this.__currentShader.__matrix.value = null;
			}
			this.__currentShader.__clearUseArray();
		}
	},
	__copyShader: function(other) {
		this.__currentShader = other.__currentShader;
		this.__currentShaderBuffer = other.__currentShaderBuffer;
		this.__currentDisplayShader = other.__currentDisplayShader;
		this.__currentGraphicsShader = other.__currentGraphicsShader;
	},
	__getMatrix: function(transform) {
		var _matrix = (openfl_geom_Matrix().default).__pool.get();
		_matrix.copyFrom(transform);
		_matrix.concat(this.__worldTransform);
		if(this.__roundPixels) {
			_matrix.tx = Math.round(_matrix.tx);
			_matrix.ty = Math.round(_matrix.ty);
		}
		(lime_math__$Matrix4_Matrix4_$Impl_$().default).identity(this.__matrix);
		(lime_math__$Matrix4_Matrix4_$Impl_$().default).set(this.__matrix,0,_matrix.a);
		(lime_math__$Matrix4_Matrix4_$Impl_$().default).set(this.__matrix,1,_matrix.b);
		(lime_math__$Matrix4_Matrix4_$Impl_$().default).set(this.__matrix,4,_matrix.c);
		(lime_math__$Matrix4_Matrix4_$Impl_$().default).set(this.__matrix,5,_matrix.d);
		(lime_math__$Matrix4_Matrix4_$Impl_$().default).set(this.__matrix,12,_matrix.tx);
		(lime_math__$Matrix4_Matrix4_$Impl_$().default).set(this.__matrix,13,_matrix.ty);
		(lime_math__$Matrix4_Matrix4_$Impl_$().default).append(this.__matrix,this.__flipped ? this.__projectionFlipped : this.__projection);
		var _g = 0;
		while(_g < 16) {
			var i = _g++;
			this.__values[i] = (lime_math__$Matrix4_Matrix4_$Impl_$().default).get(this.__matrix,i);
		}
		(openfl_geom_Matrix().default).__pool.release(_matrix);
		return this.__values;
	},
	__initShader: function(shader) {
		if(shader != null) {
			if(shader.gl == null) {
				shader.gl = this.__gl;
				shader.__init();
			}
			return shader;
		}
		return this.__defaultShader;
	},
	__initDisplayShader: function(shader) {
		if(shader != null) {
			if(shader.gl == null) {
				shader.gl = this.__gl;
				shader.__init();
			}
			return shader;
		}
		return this.__defaultDisplayShader;
	},
	__initGraphicsShader: function(shader) {
		if(shader != null) {
			if(shader.gl == null) {
				shader.gl = this.__gl;
				shader.__init();
			}
			return shader;
		}
		return this.__defaultGraphicsShader;
	},
	__initShaderBuffer: function(shaderBuffer) {
		if(shaderBuffer != null) {
			return this.__initGraphicsShader(shaderBuffer.shader);
		}
		return this.__defaultGraphicsShader;
	},
	__popMask: function() {
		if(this.__stencilReference == 0) {
			return;
		}
		if(this.__stencilReference > 1) {
			this.__gl.stencilOp(this.__gl.KEEP,this.__gl.KEEP,this.__gl.DECR);
			this.__gl.stencilFunc(this.__gl.EQUAL,this.__stencilReference,255);
			this.__gl.colorMask(false,false,false,false);
			var mask = this.__maskObjects.pop();
			mask.__renderGLMask(this);
			this.__stencilReference--;
			this.__gl.stencilOp(this.__gl.KEEP,this.__gl.KEEP,this.__gl.KEEP);
			this.__gl.stencilFunc(this.__gl.EQUAL,this.__stencilReference,255);
			this.__gl.colorMask(true,true,true,true);
		} else {
			this.__stencilReference = 0;
			this.__gl.disable(this.__gl.STENCIL_TEST);
		}
	},
	__popMaskObject: function(object,handleScrollRect) {
		if(handleScrollRect == null) {
			handleScrollRect = true;
		}
		if(object.__mask != null) {
			this.__popMask();
		}
		if(handleScrollRect && object.__scrollRect != null) {
			this.__popMaskRect();
		}
	},
	__popMaskRect: function() {
		if(this.__numClipRects > 0) {
			this.__numClipRects--;
			if(this.__numClipRects > 0) {
				this.__scissorRect(this.__clipRects[this.__numClipRects - 1]);
			} else {
				this.__scissorRect();
			}
		}
	},
	__pushMask: function(mask) {
		if(this.__stencilReference == 0) {
			this.__gl.enable(this.__gl.STENCIL_TEST);
			this.__gl.stencilMask(255);
			this.__gl.clear(this.__gl.STENCIL_BUFFER_BIT);
		}
		this.__gl.stencilOp(this.__gl.KEEP,this.__gl.KEEP,this.__gl.INCR);
		this.__gl.stencilFunc(this.__gl.EQUAL,this.__stencilReference,255);
		this.__gl.colorMask(false,false,false,false);
		mask.__renderGLMask(this);
		this.__maskObjects.push(mask);
		this.__stencilReference++;
		this.__gl.stencilOp(this.__gl.KEEP,this.__gl.KEEP,this.__gl.KEEP);
		this.__gl.stencilFunc(this.__gl.EQUAL,this.__stencilReference,255);
		this.__gl.colorMask(true,true,true,true);
	},
	__pushMaskObject: function(object,handleScrollRect) {
		if(handleScrollRect == null) {
			handleScrollRect = true;
		}
		if(handleScrollRect && object.__scrollRect != null) {
			this.__pushMaskRect(object.__scrollRect,object.__renderTransform);
		}
		if(object.__mask != null) {
			this.__pushMask(object.__mask);
		}
	},
	__pushMaskRect: function(rect,transform) {
		if(this.__numClipRects == this.__clipRects.length) {
			this.__clipRects[this.__numClipRects] = new (openfl_geom_Rectangle().default)();
		}
		var _matrix = (openfl_geom_Matrix().default).__pool.get();
		_matrix.copyFrom(transform);
		_matrix.concat(this.__worldTransform);
		var clipRect = this.__clipRects[this.__numClipRects];
		rect.__transform(clipRect,_matrix);
		if(this.__numClipRects > 0) {
			var parentClipRect = this.__clipRects[this.__numClipRects - 1];
			clipRect.__contract(parentClipRect.x,parentClipRect.y,parentClipRect.width,parentClipRect.height);
		}
		if(clipRect.height < 0) {
			clipRect.height = 0;
		}
		if(clipRect.width < 0) {
			clipRect.width = 0;
		}
		(openfl_geom_Matrix().default).__pool.release(_matrix);
		this.__scissorRect(clipRect);
		this.__numClipRects++;
	},
	__render: function(object) {
		if(this.__defaultRenderTarget == null) {
			this.__gl.viewport(this.__offsetX,this.__offsetY,this.__displayWidth,this.__displayHeight);
			this.__upscaled = this.__worldTransform.a != 1 || this.__worldTransform.d != 1;
			object.__renderGL(this);
			if(this.__offsetX > 0 || this.__offsetY > 0) {
				this.__gl.clearColor(0,0,0,1);
				this.__gl.enable(this.__gl.SCISSOR_TEST);
				if(this.__offsetX > 0) {
					this.__gl.scissor(0,0,this.__offsetX,this.__height);
					this.__gl.clear(this.__gl.COLOR_BUFFER_BIT);
					this.__gl.scissor(this.__offsetX + this.__displayWidth,0,this.__width,this.__height);
					this.__gl.clear(this.__gl.COLOR_BUFFER_BIT);
				}
				if(this.__offsetY > 0) {
					this.__gl.scissor(0,0,this.__width,this.__offsetY);
					this.__gl.clear(this.__gl.COLOR_BUFFER_BIT);
					this.__gl.scissor(0,this.__offsetY + this.__displayHeight,this.__width,this.__height);
					this.__gl.clear(this.__gl.COLOR_BUFFER_BIT);
				}
				this.__gl.disable(this.__gl.SCISSOR_TEST);
			}
		} else {
			this.__gl.viewport(this.__offsetX,this.__offsetY,this.__displayWidth,this.__displayHeight);
			var cacheMask = object.__mask;
			var cacheScrollRect = object.__scrollRect;
			object.__mask = null;
			object.__scrollRect = null;
			object.__renderGL(this);
			object.__mask = cacheMask;
			object.__scrollRect = cacheScrollRect;
		}
	},
	__renderFilterPass: function(source,shader,clear) {
		if(clear == null) {
			clear = true;
		}
		if(source == null || shader == null) {
			return;
		}
		if(this.__defaultRenderTarget == null) {
			return;
		}
		this.__gl.bindFramebuffer(this.__gl.FRAMEBUFFER,this.__defaultRenderTarget.__getFramebuffer(this.__gl));
		if(clear) {
			this.__gl.clearColor(0,0,0,0);
			this.__gl.clear(this.__gl.COLOR_BUFFER_BIT);
		}
		var shader1 = this.__initShader(shader);
		this.setShader(shader1);
		this.applyAlpha(1);
		this.applyBitmapData(source,false);
		this.applyColorTransform(null);
		this.applyMatrix(this.__getMatrix(source.__renderTransform));
		this.updateShader();
		this.__gl.bindBuffer(this.__gl.ARRAY_BUFFER,source.getBuffer(this.__gl));
		if(shader1.__position != null) {
			this.__gl.vertexAttribPointer(shader1.__position.index,3,this.__gl.FLOAT,false,56,(lime_utils__$DataPointer_DataPointer_$Impl_$().default).fromInt(0));
		}
		if(shader1.__textureCoord != null) {
			this.__gl.vertexAttribPointer(shader1.__textureCoord.index,2,this.__gl.FLOAT,false,56,(lime_utils__$DataPointer_DataPointer_$Impl_$().default).fromInt(12));
		}
		this.__gl.drawArrays(this.__gl.TRIANGLE_STRIP,0,4);
		this.__gl.bindFramebuffer(this.__gl.FRAMEBUFFER,null);
		this.__clearShader();
	},
	__renderStage3D: function(stage) {
		var _g = 0;
		var _g1 = stage.stage3Ds;
		while(_g < _g1.get_length()) {
			var stage3D = _g1.get(_g);
			++_g;
			stage3D.__renderGL(stage,this);
		}
	},
	__resize: function(width,height) {
		this.__width = width;
		this.__height = height;
		var w = this.__defaultRenderTarget == null ? this.__stage.stageWidth : this.__defaultRenderTarget.width;
		var h = this.__defaultRenderTarget == null ? this.__stage.stageHeight : this.__defaultRenderTarget.height;
		this.__offsetX = this.__defaultRenderTarget == null ? Math.round(this.__worldTransform.__transformX(0,0)) : 0;
		this.__offsetY = this.__defaultRenderTarget == null ? Math.round(this.__worldTransform.__transformY(0,0)) : 0;
		this.__displayWidth = this.__defaultRenderTarget == null ? Math.round(this.__worldTransform.__transformX(w,0) - this.__offsetX) : w;
		this.__displayHeight = this.__defaultRenderTarget == null ? Math.round(this.__worldTransform.__transformY(0,h) - this.__offsetY) : h;
		this.__projection = (lime_math__$Matrix4_Matrix4_$Impl_$().default).createOrtho(this.__offsetX,this.__displayWidth + this.__offsetX,this.__offsetY,this.__displayHeight + this.__offsetY,-1000,1000);
		this.__projectionFlipped = (lime_math__$Matrix4_Matrix4_$Impl_$().default).createOrtho(this.__offsetX,this.__displayWidth + this.__offsetX,this.__displayHeight + this.__offsetY,this.__offsetY,-1000,1000);
	},
	__resumeClipAndMask: function() {
		if(this.__stencilReference > 0) {
			this.__gl.enable(this.__gl.STENCIL_TEST);
		}
		if(this.__numClipRects > 0) {
			this.__scissorRect(this.__clipRects[this.__numClipRects - 1]);
		}
	},
	__scissorRect: function(clipRect) {
		if(clipRect != null) {
			this.__gl.enable(this.__gl.SCISSOR_TEST);
			var x = Math.floor(clipRect.x);
			var y = this.__flipped ? Math.floor(this.__height - clipRect.y - clipRect.height) : Math.floor(clipRect.y);
			var width = Math.ceil(clipRect.width);
			var height = Math.ceil(clipRect.height);
			if(width < 0) {
				width = 0;
			}
			if(height < 0) {
				height = 0;
			}
			this.__gl.scissor(x,y,width,height);
		} else {
			this.__gl.disable(this.__gl.SCISSOR_TEST);
		}
	},
	__setBlendMode: function(value) {
		if(this.__blendMode == value) {
			return;
		}
		this.__blendMode = value;
		switch(value) {
		case "add":
			this.__gl.blendEquation(this.__gl.FUNC_ADD);
			this.__gl.blendFunc(this.__gl.ONE,this.__gl.ONE);
			break;
		case "multiply":
			this.__gl.blendEquation(this.__gl.FUNC_ADD);
			this.__gl.blendFunc(this.__gl.DST_COLOR,this.__gl.ONE_MINUS_SRC_ALPHA);
			break;
		case "screen":
			this.__gl.blendEquation(this.__gl.FUNC_ADD);
			this.__gl.blendFunc(this.__gl.ONE,this.__gl.ONE_MINUS_SRC_COLOR);
			break;
		case "subtract":
			this.__gl.blendEquation(this.__gl.FUNC_REVERSE_SUBTRACT);
			this.__gl.blendFunc(this.__gl.ONE,this.__gl.ONE);
			break;
		default:
			this.__gl.blendEquation(this.__gl.FUNC_ADD);
			this.__gl.blendFunc(this.__gl.ONE,this.__gl.ONE_MINUS_SRC_ALPHA);
		}
	},
	__setRenderTarget: function(renderTarget) {
		this.__defaultRenderTarget = renderTarget;
		this.__flipped = renderTarget == null;
		if(renderTarget != null) {
			this.__resize(renderTarget.width,renderTarget.height);
		}
	},
	__setShaderBuffer: function(shaderBuffer) {
		this.setShader(shaderBuffer.shader);
		this.__currentShaderBuffer = shaderBuffer;
	},
	__suspendClipAndMask: function() {
		if(this.__stencilReference > 0) {
			this.__gl.disable(this.__gl.STENCIL_TEST);
		}
		if(this.__numClipRects > 0) {
			this.__scissorRect();
		}
	},
	__updateShaderBuffer: function() {
		if(this.__currentShader != null && this.__currentShaderBuffer != null) {
			this.__currentShader.__updateFromBuffer(this.__currentShaderBuffer);
		}
	}
});
OpenGLRenderer.prototype.__class__ = $hxClasses["openfl.display.OpenGLRenderer"] = OpenGLRenderer;

// Init



// Statics


OpenGLRenderer.__alphaValue = [1.]
OpenGLRenderer.__colorMultipliersValue = [0,0,0,0.]
OpenGLRenderer.__colorOffsetsValue = [0,0,0,0.]
OpenGLRenderer.__defaultColorMultipliersValue = [1,1,1,1.]
OpenGLRenderer.__emptyColorValue = [0,0,0,0.]
OpenGLRenderer.__emptyAlphaValue = [1.]
OpenGLRenderer.__hasColorTransformValue = [false]
OpenGLRenderer.__textureSizeValue = [0,0.]

// Export

exports.default = OpenGLRenderer;