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

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_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 GLBitmap = function(){}

// Meta

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

// Init



// Statics

GLBitmap.render = function(bitmap,renderSession) {
	if(!bitmap.__renderable || bitmap.__worldAlpha <= 0) {
		return;
	}
	if(bitmap.__bitmapData != null && bitmap.__bitmapData.__isValid) {
		var renderer = renderSession.renderer;
		var gl = renderSession.gl;
		renderSession.blendModeManager.setBlendMode(bitmap.__worldBlendMode);
		renderSession.maskManager.pushObject(bitmap);
		renderSession.filterManager.pushObject(bitmap);
		var shader = renderSession.shaderManager.initShader(bitmap.shader);
		renderSession.shaderManager.setShader(shader);
		shader.get_data().uImage0.input = bitmap.__bitmapData;
		var tmp = renderSession.allowSmoothing && (bitmap.smoothing || renderSession.upscaled);
		shader.get_data().uImage0.smoothing = tmp;
		shader.get_data().uMatrix.value = renderer.getMatrix(bitmap.__renderTransform);
		var useColorTransform = !bitmap.__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,bitmap.__bitmapData.getBuffer(gl,bitmap.__worldAlpha,bitmap.__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(bitmap);
		renderSession.maskManager.popObject(bitmap);
	}
}
GLBitmap.renderMask = function(bitmap,renderSession) {
	if(bitmap.__bitmapData != null && bitmap.__bitmapData.__isValid) {
		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 = bitmap.__bitmapData;
		var tmp = renderSession.allowSmoothing && (bitmap.smoothing || renderSession.upscaled);
		shader.get_data().uImage0.smoothing = tmp;
		shader.get_data().uMatrix.value = renderer.getMatrix(bitmap.__renderTransform);
		renderSession.shaderManager.updateShader(shader);
		gl.bindBuffer(gl.ARRAY_BUFFER,bitmap.__bitmapData.getBuffer(gl,bitmap.__worldAlpha,bitmap.__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 = GLBitmap;