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

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

// Meta

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

// Init



// Statics

GLVideo.render = function(video,renderSession) {
	if(!video.__renderable || video.__worldAlpha <= 0 || video.__stream == null) {
		return;
	}
	if(video.__stream.__video != null) {
		var renderer = renderSession.renderer;
		var gl = renderSession.gl;
		renderSession.blendModeManager.setBlendMode(video.__worldBlendMode);
		renderSession.maskManager.pushObject(video);
		renderSession.filterManager.pushObject(video);
		var shader = renderSession.shaderManager.initShader(video.shader);
		renderSession.shaderManager.setShader(shader);
		shader.get_data().uMatrix.value = renderer.getMatrix(video.__renderTransform);
		var useColorTransform = !video.__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.bindTexture(gl.TEXTURE_2D,video.__getTexture(gl));
		if(video.smoothing) {
			gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.LINEAR);
			gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.LINEAR);
		} else {
			gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.NEAREST);
			gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.NEAREST);
		}
		gl.bindBuffer(gl.ARRAY_BUFFER,video.__getBuffer(gl,video.__worldAlpha,video.__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(video);
		renderSession.maskManager.popObject(video);
	}
}
GLVideo.renderMask = function(video,renderSession) {
	if(video.__stream == null) {
		return;
	}
	if(video.__stream.__video != 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().uMatrix.value = renderer.getMatrix(video.__renderTransform);
		renderSession.shaderManager.updateShader(shader);
		gl.bindTexture(gl.TEXTURE_2D,video.__getTexture(gl));
		gl.bindBuffer(gl.ARRAY_BUFFER,video.__getBuffer(gl,video.__worldAlpha,video.__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 = GLVideo;