// Class: openfl._internal.stage3D.opengl.GLRectangleTexture

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_stage3D_GLUtils() {return require("./../../../../openfl/_internal/stage3D/GLUtils");}
function lime_graphics__$WebGLRenderContext_WebGLRenderContext_$Impl_$() {return require("./../../../../lime/graphics/_WebGLRenderContext/WebGLRenderContext_Impl_");}
function openfl_utils__$ByteArray_ByteArray_$Impl_$() {return require("./../../../../openfl/utils/_ByteArray/ByteArray_Impl_");}
function openfl_display3D_Context3D() {return require("./../../../../openfl/display3D/Context3D");}
function openfl__$internal_stage3D_opengl_GLTextureBase() {return require("./../../../../openfl/_internal/stage3D/opengl/GLTextureBase");}

// Constructor

var GLRectangleTexture = function(){}

// Meta

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

// Init



// Statics

GLRectangleTexture.create = function(rectangleTexture,renderer) {
	var gl = renderer.__context.webgl;
	rectangleTexture.__textureTarget = gl.TEXTURE_2D;
	GLRectangleTexture.uploadFromTypedArray(rectangleTexture,renderer,null);
}
GLRectangleTexture.uploadFromBitmapData = function(rectangleTexture,renderer,source) {
	if(source == null) {
		return;
	}
	var image = rectangleTexture.__getImage(source);
	if(image == null) {
		return;
	}
	if(image.buffer != null && image.buffer.data == null && image.buffer.get_src() != null) {
		var gl = renderer.__context.webgl;
		gl.bindTexture(rectangleTexture.__textureTarget,rectangleTexture.__textureID);
		(openfl__$internal_stage3D_GLUtils().default).CheckGLError();
		(lime_graphics__$WebGLRenderContext_WebGLRenderContext_$Impl_$().default).texImage2D(gl,rectangleTexture.__textureTarget,0,rectangleTexture.__internalFormat,rectangleTexture.__format,gl.UNSIGNED_BYTE,image.buffer.get_src());
		(openfl__$internal_stage3D_GLUtils().default).CheckGLError();
		gl.bindTexture(rectangleTexture.__textureTarget,null);
		(openfl__$internal_stage3D_GLUtils().default).CheckGLError();
		return;
	}
	GLRectangleTexture.uploadFromTypedArray(rectangleTexture,renderer,image.get_data());
}
GLRectangleTexture.uploadFromByteArray = function(rectangleTexture,renderer,data,byteArrayOffset) {
	if(byteArrayOffset == 0) {
		GLRectangleTexture.uploadFromTypedArray(rectangleTexture,renderer,data.b);
		return;
	}
	var buffer = (openfl_utils__$ByteArray_ByteArray_$Impl_$().default).toArrayBuffer(data);
	var this1;
	if(buffer != null) {
		this1 = new Uint8Array(buffer,byteArrayOffset);
	} else {
		this1 = null;
	}
	GLRectangleTexture.uploadFromTypedArray(rectangleTexture,renderer,this1);
}
GLRectangleTexture.uploadFromTypedArray = function(rectangleTexture,renderer,data) {
	var gl = renderer.__context.webgl;
	gl.bindTexture(rectangleTexture.__textureTarget,rectangleTexture.__textureID);
	(openfl__$internal_stage3D_GLUtils().default).CheckGLError();
	(lime_graphics__$WebGLRenderContext_WebGLRenderContext_$Impl_$().default).texImage2D(gl,rectangleTexture.__textureTarget,0,rectangleTexture.__internalFormat,rectangleTexture.__width,rectangleTexture.__height,0,rectangleTexture.__format,gl.UNSIGNED_BYTE,data);
	(openfl__$internal_stage3D_GLUtils().default).CheckGLError();
	gl.bindTexture(rectangleTexture.__textureTarget,null);
	(openfl__$internal_stage3D_GLUtils().default).CheckGLError();
}
GLRectangleTexture.setSamplerState = function(rectangleTexture,renderer,state) {
	if(!state.equals(rectangleTexture.__samplerState)) {
		var gl = renderer.__context.webgl;
		if(state.maxAniso != 0.0) {
			gl.texParameterf(gl.TEXTURE_2D,(openfl_display3D_Context3D().default).TEXTURE_MAX_ANISOTROPY_EXT,state.maxAniso);
			(openfl__$internal_stage3D_GLUtils().default).CheckGLError();
		}
	}
	(openfl__$internal_stage3D_opengl_GLTextureBase().default).setSamplerState(rectangleTexture,renderer,state);
}


// Export

exports.default = GLRectangleTexture;