// 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 openfl__$internal_renderer_opengl_GLMaskShader() {return require("./../../../../openfl/_internal/renderer/opengl/GLMaskShader");}

// Constructor

var GLVideo = function(){}

// Meta

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

// Init



// Statics

GLVideo.render = function(video,renderer) {
	if(!video.__renderable || video.__worldAlpha <= 0 || video.__stream == null) {
		return;
	}
	if(video.__stream.__video != null) {
		var gl = renderer.__context.webgl;
		renderer.__setBlendMode(video.__worldBlendMode);
		renderer.__pushMaskObject(video);
		var shader = renderer.__initDisplayShader(video.__worldShader);
		renderer.setShader(shader);
		renderer.applyBitmapData(null,renderer.__allowSmoothing,false);
		gl.bindTexture(gl.TEXTURE_2D,video.__getTexture(renderer.__context));
		renderer.applyMatrix(renderer.__getMatrix(video.__renderTransform));
		renderer.applyAlpha(video.__worldAlpha);
		renderer.applyColorTransform(video.__worldColorTransform);
		if(shader.__textureSize != null) {
			GLVideo.__textureSizeValue[0] = video.__stream != null ? video.__stream.__video.width : 0;
			GLVideo.__textureSizeValue[1] = video.__stream != null ? video.__stream.__video.height : 0;
			shader.__textureSize.value = GLVideo.__textureSizeValue;
		}
		renderer.updateShader();
		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(renderer.__context));
		if(shader.__position != null) {
			gl.vertexAttribPointer(shader.__position.index,3,gl.FLOAT,false,20,0);
		}
		if(shader.__textureCoord != null) {
			gl.vertexAttribPointer(shader.__textureCoord.index,2,gl.FLOAT,false,20,12);
		}
		gl.drawArrays(gl.TRIANGLE_STRIP,0,4);
		renderer.__clearShader();
		renderer.__popMaskObject(video);
	}
}
GLVideo.renderMask = function(video,renderer) {
	if(video.__stream == null) {
		return;
	}
	if(video.__stream.__video != null) {
		var gl = renderer.__context.webgl;
		var shader = renderer.__maskShader;
		renderer.setShader(shader);
		renderer.applyBitmapData((openfl__$internal_renderer_opengl_GLMaskShader().default).opaqueBitmapData,true);
		renderer.applyMatrix(renderer.__getMatrix(video.__renderTransform));
		renderer.updateShader();
		gl.bindBuffer(gl.ARRAY_BUFFER,video.__getBuffer(renderer.__context));
		gl.vertexAttribPointer(shader.__position.index,3,gl.FLOAT,false,20,0);
		gl.vertexAttribPointer(shader.__textureCoord.index,2,gl.FLOAT,false,20,12);
		gl.drawArrays(gl.TRIANGLE_STRIP,0,4);
		renderer.__clearShader();
	}
}
GLVideo.__textureSizeValue = [0,0.]

// Export

exports.default = GLVideo;