// Class: openfl._internal.renderer.opengl.GLShape

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 openfl__$internal_renderer_canvas_CanvasGraphics() {return require("./../../../../openfl/_internal/renderer/canvas/CanvasGraphics");}
function lime_utils__$DataPointer_DataPointer_$Impl_$() {return require("./../../../../lime/utils/_DataPointer/DataPointer_Impl_");}
function openfl__$internal_renderer_opengl_GLMaskManager() {return require("./../../../../openfl/_internal/renderer/opengl/GLMaskManager");}

// Constructor

var GLShape = function(){}

// Meta

GLShape.__name__ = ["openfl","_internal","renderer","opengl","GLShape"];
GLShape.prototype = {
	
};
GLShape.prototype.__class__ = $hxClasses["openfl._internal.renderer.opengl.GLShape"] = GLShape;

// Init



// Statics

GLShape.render = function(shape,renderSession) {
	if(!shape.__renderable || shape.__worldAlpha <= 0) {
		return;
	}
	var graphics = shape.__graphics;
	if(graphics != null) {
		(openfl__$internal_renderer_canvas_CanvasGraphics().default).render(graphics,renderSession,shape.__renderTransform);
		var bounds = graphics.__bounds;
		if(graphics.__bitmap != null && graphics.__visible) {
			var renderer = renderSession.renderer;
			var gl = renderSession.gl;
			renderSession.blendModeManager.setBlendMode(shape.__worldBlendMode);
			renderSession.maskManager.pushObject(shape);
			var shader = renderSession.filterManager.pushObject(shape);
			renderSession.shaderManager.setShader(shader);
			shader.get_data().uImage0.input = graphics.__bitmap;
			shader.get_data().uImage0.smoothing = renderSession.allowSmoothing;
			shader.get_data().uMatrix.value = renderer.getMatrix(graphics.__worldTransform);
			var useColorTransform = !shape.__worldColorTransform.__isDefault();
			if(shader.get_data().uColorTransform.value == null) {
				shader.get_data().uColorTransform.value = [];
			}
			shader.get_data().uColorTransform.value[0] = useColorTransform;
			renderSession.shaderManager.updateShader(shader);
			gl.bindBuffer(gl.ARRAY_BUFFER,graphics.__bitmap.getBuffer(gl,shape.__worldAlpha,shape.__worldColorTransform));
			gl.vertexAttribPointer(shader.get_data().aPosition.index,3,gl.FLOAT,false,104,(lime_utils__$DataPointer_DataPointer_$Impl_$().default).fromInt(0));
			gl.vertexAttribPointer(shader.get_data().aTexCoord.index,2,gl.FLOAT,false,104,(lime_utils__$DataPointer_DataPointer_$Impl_$().default).fromInt(12));
			gl.vertexAttribPointer(shader.get_data().aAlpha.index,1,gl.FLOAT,false,104,(lime_utils__$DataPointer_DataPointer_$Impl_$().default).fromInt(20));
			gl.vertexAttribPointer(shader.get_data().aColorMultipliers0.index,4,gl.FLOAT,false,104,(lime_utils__$DataPointer_DataPointer_$Impl_$().default).fromInt(24));
			gl.vertexAttribPointer(shader.get_data().aColorMultipliers1.index,4,gl.FLOAT,false,104,(lime_utils__$DataPointer_DataPointer_$Impl_$().default).fromInt(40));
			gl.vertexAttribPointer(shader.get_data().aColorMultipliers2.index,4,gl.FLOAT,false,104,(lime_utils__$DataPointer_DataPointer_$Impl_$().default).fromInt(56));
			gl.vertexAttribPointer(shader.get_data().aColorMultipliers3.index,4,gl.FLOAT,false,104,(lime_utils__$DataPointer_DataPointer_$Impl_$().default).fromInt(72));
			gl.vertexAttribPointer(shader.get_data().aColorOffsets.index,4,gl.FLOAT,false,104,(lime_utils__$DataPointer_DataPointer_$Impl_$().default).fromInt(88));
			gl.drawArrays(gl.TRIANGLE_STRIP,0,4);
			renderSession.filterManager.popObject(shape);
			renderSession.maskManager.popObject(shape);
		}
	}
}
GLShape.renderMask = function(shape,renderSession) {
	var graphics = shape.__graphics;
	if(graphics != null) {
		(openfl__$internal_renderer_canvas_CanvasGraphics().default).render(graphics,renderSession,shape.__renderTransform);
		var bounds = graphics.__bounds;
		if(graphics.__bitmap != null) {
			var renderer = renderSession.renderer;
			var gl = renderSession.gl;
			var shader = (openfl__$internal_renderer_opengl_GLMaskManager().default).maskShader;
			renderSession.shaderManager.setShader(shader);
			shader.get_data().uImage0.input = graphics.__bitmap;
			shader.get_data().uImage0.smoothing = renderSession.allowSmoothing;
			shader.get_data().uMatrix.value = renderer.getMatrix(graphics.__worldTransform);
			renderSession.shaderManager.updateShader(shader);
			gl.bindBuffer(gl.ARRAY_BUFFER,graphics.__bitmap.getBuffer(gl,shape.__worldAlpha,shape.__worldColorTransform));
			gl.vertexAttribPointer(shader.get_data().aPosition.index,3,gl.FLOAT,false,104,(lime_utils__$DataPointer_DataPointer_$Impl_$().default).fromInt(0));
			gl.vertexAttribPointer(shader.get_data().aTexCoord.index,2,gl.FLOAT,false,104,(lime_utils__$DataPointer_DataPointer_$Impl_$().default).fromInt(12));
			gl.drawArrays(gl.TRIANGLE_STRIP,0,4);
		}
	}
}


// Export

exports.default = GLShape;