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

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_graphics_opengl_GLContextType() {return require("./../../../../lime/graphics/opengl/GLContextType");}
function openfl__$internal_stage3D_GLCompressedTextureFormats() {return require("./../../../../openfl/_internal/stage3D/GLCompressedTextureFormats");}
function lime_graphics_utils_ImageCanvasUtil() {return require("./../../../../lime/graphics/utils/ImageCanvasUtil");}
function lime_graphics_ImageType() {return require("./../../../../lime/graphics/ImageType");}
function openfl__$internal_stage3D_GLUtils() {return require("./../../../../openfl/_internal/stage3D/GLUtils");}

// Constructor

var GLTextureBase = function(){}

// Meta

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

// Init



// Statics

GLTextureBase.create = function(textureBase,renderer) {
	var gl = renderer.__gl;
	textureBase.__textureID = gl.createTexture();
	textureBase.__textureContext = gl;
	if(GLTextureBase.__supportsBGRA == null) {
		GLTextureBase.__textureInternalFormat = gl.RGBA;
		var bgraExtension = null;
		if(bgraExtension != null) {
			GLTextureBase.__supportsBGRA = true;
			GLTextureBase.__textureFormat = bgraExtension.BGRA_EXT;
			if(gl.type == (lime_graphics_opengl_GLContextType().default).GLES) {
				GLTextureBase.__textureInternalFormat = bgraExtension.BGRA_EXT;
			}
		} else {
			GLTextureBase.__supportsBGRA = false;
			GLTextureBase.__textureFormat = gl.RGBA;
		}
	}
	if(GLTextureBase.__compressedTextureFormats == null) {
		GLTextureBase.__compressedTextureFormats = new (openfl__$internal_stage3D_GLCompressedTextureFormats().default)(gl);
	}
	textureBase.__internalFormat = GLTextureBase.__textureInternalFormat;
	textureBase.__format = GLTextureBase.__textureFormat;
}
GLTextureBase.dispose = function(textureBase,renderer) {
	var gl = renderer.__gl;
	if(textureBase.__alphaTexture != null) {
		textureBase.__alphaTexture.dispose();
	}
	gl.deleteTexture(textureBase.__textureID);
}
GLTextureBase.getImage = function(textureBase,renderer,bitmapData) {
	var image = bitmapData.image;
	if(!bitmapData.__isValid || image == null) {
		return null;
	}
	(lime_graphics_utils_ImageCanvasUtil().default).sync(image,false);
	var gl = renderer.__gl;
	if(image.type != (lime_graphics_ImageType().default).DATA && !image.get_premultiplied()) {
		gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL,1);
	} else if(!image.get_premultiplied() && image.get_transparent()) {
		gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL,0);
		image = image.clone();
		image.set_premultiplied(true);
	}
	if(image.get_format() != 0) {
		image = image.clone();
		image.set_format(0);
		image.buffer.premultiplied = true;
	}
	return image;
}
GLTextureBase.setSamplerState = function(textureBase,renderer,state) {
	if(!state.equals(textureBase.__samplerState)) {
		var gl = renderer.__gl;
		gl.bindTexture(textureBase.__textureTarget,textureBase.__textureID);
		(openfl__$internal_stage3D_GLUtils().default).CheckGLError();
		gl.texParameteri(textureBase.__textureTarget,gl.TEXTURE_MIN_FILTER,state.minFilter);
		(openfl__$internal_stage3D_GLUtils().default).CheckGLError();
		gl.texParameteri(textureBase.__textureTarget,gl.TEXTURE_MAG_FILTER,state.magFilter);
		(openfl__$internal_stage3D_GLUtils().default).CheckGLError();
		gl.texParameteri(textureBase.__textureTarget,gl.TEXTURE_WRAP_S,state.wrapModeS);
		(openfl__$internal_stage3D_GLUtils().default).CheckGLError();
		gl.texParameteri(textureBase.__textureTarget,gl.TEXTURE_WRAP_T,state.wrapModeT);
		(openfl__$internal_stage3D_GLUtils().default).CheckGLError();
		var tmp = state.lodBias != 0.0;
		textureBase.__samplerState = state;
		textureBase.__samplerState.__samplerDirty = false;
	}
}
GLTextureBase.__supportsBGRA = null
GLTextureBase.__compressedTextureFormats = null

// Export

exports.default = GLTextureBase;