// Class: openfl.display3D.Context3D

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;
var $extend = require("./../../extend_stub").default;
function openfl_events_EventDispatcher() {return require("./../../openfl/events/EventDispatcher");}
function openfl__$internal_stage3D_opengl_GLContext3D() {return require("./../../openfl/_internal/stage3D/opengl/GLContext3D");}
function openfl_display3D_textures_CubeTexture() {return require("./../../openfl/display3D/textures/CubeTexture");}
function openfl_display3D_IndexBuffer3D() {return require("./../../openfl/display3D/IndexBuffer3D");}
function openfl_display3D_Program3D() {return require("./../../openfl/display3D/Program3D");}
function openfl_display3D_textures_RectangleTexture() {return require("./../../openfl/display3D/textures/RectangleTexture");}
function openfl_display3D_textures_Texture() {return require("./../../openfl/display3D/textures/Texture");}
function openfl_display3D_VertexBuffer3D() {return require("./../../openfl/display3D/VertexBuffer3D");}
function openfl_display3D_textures_VideoTexture() {return require("./../../openfl/display3D/textures/VideoTexture");}
function js__$Boot_HaxeError() {return require("./../../js/_Boot/HaxeError");}
function openfl_errors_IllegalOperationError() {return require("./../../openfl/errors/IllegalOperationError");}
function openfl__$internal_stage3D_Context3DStateCache() {return require("./../../openfl/_internal/stage3D/Context3DStateCache");}

// Constructor

var Context3D = function(stage3D,renderSession) {
	this.totalGPUMemory = 0;
	this.profile = "baseline";
	this.driverInfo = "OpenGL (Direct blitting)";
	this.backBufferWidth = 0;
	this.backBufferHeight = 0;
	(openfl_events_EventDispatcher().default).call(this);
	this.__stage3D = stage3D;
	this.__renderSession = renderSession;
	(openfl__$internal_stage3D_opengl_GLContext3D().default).create(this);
}

// Meta

Context3D.__name__ = ["openfl","display3D","Context3D"];
Context3D.__super__ = (openfl_events_EventDispatcher().default);
Context3D.prototype = $extend((openfl_events_EventDispatcher().default).prototype, {
	clear: function(red,green,blue,alpha,depth,stencil,mask) {
		if(mask == null) {
			mask = 7;
		}
		if(stencil == null) {
			stencil = 0;
		}
		if(depth == null) {
			depth = 1;
		}
		if(alpha == null) {
			alpha = 1;
		}
		if(blue == null) {
			blue = 0;
		}
		if(green == null) {
			green = 0;
		}
		if(red == null) {
			red = 0;
		}
		(openfl__$internal_stage3D_opengl_GLContext3D().default).clear(this,red,green,blue,alpha,depth,stencil,mask);
	},
	configureBackBuffer: function(width,height,antiAlias,enableDepthAndStencil,wantsBestResolution,wantsBestResolutionOnBrowserZoom) {
		if(wantsBestResolutionOnBrowserZoom == null) {
			wantsBestResolutionOnBrowserZoom = false;
		}
		if(wantsBestResolution == null) {
			wantsBestResolution = false;
		}
		if(enableDepthAndStencil == null) {
			enableDepthAndStencil = true;
		}
		(openfl__$internal_stage3D_opengl_GLContext3D().default).configureBackBuffer(this,width,height,antiAlias,enableDepthAndStencil,wantsBestResolution,wantsBestResolutionOnBrowserZoom);
	},
	createCubeTexture: function(size,format,optimizeForRenderToTexture,streamingLevels) {
		if(streamingLevels == null) {
			streamingLevels = 0;
		}
		return new (openfl_display3D_textures_CubeTexture().default)(this,size,format,optimizeForRenderToTexture,streamingLevels);
	},
	createIndexBuffer: function(numIndices,bufferUsage) {
		if(bufferUsage == null) {
			bufferUsage = "staticDraw";
		}
		return new (openfl_display3D_IndexBuffer3D().default)(this,numIndices,bufferUsage);
	},
	createProgram: function() {
		return new (openfl_display3D_Program3D().default)(this);
	},
	createRectangleTexture: function(width,height,format,optimizeForRenderToTexture) {
		return new (openfl_display3D_textures_RectangleTexture().default)(this,width,height,format,optimizeForRenderToTexture);
	},
	createTexture: function(width,height,format,optimizeForRenderToTexture,streamingLevels) {
		if(streamingLevels == null) {
			streamingLevels = 0;
		}
		return new (openfl_display3D_textures_Texture().default)(this,width,height,format,optimizeForRenderToTexture,streamingLevels);
	},
	createVertexBuffer: function(numVertices,data32PerVertex,bufferUsage) {
		if(bufferUsage == null) {
			bufferUsage = "staticDraw";
		}
		return new (openfl_display3D_VertexBuffer3D().default)(this,numVertices,data32PerVertex,bufferUsage);
	},
	createVideoTexture: function() {
		return new (openfl_display3D_textures_VideoTexture().default)(this);
	},
	dispose: function(recreate) {
		if(recreate == null) {
			recreate = true;
		}
		(openfl__$internal_stage3D_opengl_GLContext3D().default).dispose(this,recreate);
	},
	drawToBitmapData: function(destination) {
		if(destination == null) {
			return;
		}
		(openfl__$internal_stage3D_opengl_GLContext3D().default).drawToBitmapData(this,destination);
	},
	drawTriangles: function(indexBuffer,firstIndex,numTriangles) {
		if(numTriangles == null) {
			numTriangles = -1;
		}
		if(firstIndex == null) {
			firstIndex = 0;
		}
		if(this.__program == null) {
			return;
		}
		(openfl__$internal_stage3D_opengl_GLContext3D().default).drawTriangles(this,indexBuffer,firstIndex,numTriangles);
	},
	present: function() {
		(openfl__$internal_stage3D_opengl_GLContext3D().default).present(this);
	},
	setBlendFactors: function(sourceFactor,destinationFactor) {
		(openfl__$internal_stage3D_opengl_GLContext3D().default).setBlendFactors(this,sourceFactor,destinationFactor);
	},
	setColorMask: function(red,green,blue,alpha) {
		(openfl__$internal_stage3D_opengl_GLContext3D().default).setColorMask(this,red,green,blue,alpha);
	},
	setCulling: function(triangleFaceToCull) {
		(openfl__$internal_stage3D_opengl_GLContext3D().default).setCulling(this,triangleFaceToCull);
	},
	setDepthTest: function(depthMask,passCompareMode) {
		(openfl__$internal_stage3D_opengl_GLContext3D().default).setDepthTest(this,depthMask,passCompareMode);
	},
	setProgram: function(program) {
		if(program == null) {
			throw new (js__$Boot_HaxeError().default)(new (openfl_errors_IllegalOperationError().default)());
		}
		(openfl__$internal_stage3D_opengl_GLContext3D().default).setProgram(this,program);
	},
	setProgramConstantsFromByteArray: function(programType,firstRegister,numRegisters,data,byteArrayOffset) {
		if(numRegisters == 0) {
			return;
		}
		(openfl__$internal_stage3D_opengl_GLContext3D().default).setProgramConstantsFromByteArray(this,programType,firstRegister,numRegisters,data,byteArrayOffset);
	},
	setProgramConstantsFromMatrix: function(programType,firstRegister,matrix,transposedMatrix) {
		if(transposedMatrix == null) {
			transposedMatrix = false;
		}
		(openfl__$internal_stage3D_opengl_GLContext3D().default).setProgramConstantsFromMatrix(this,programType,firstRegister,matrix,transposedMatrix);
	},
	setProgramConstantsFromVector: function(programType,firstRegister,data,numRegisters) {
		if(numRegisters == null) {
			numRegisters = -1;
		}
		if(numRegisters == 0) {
			return;
		}
		(openfl__$internal_stage3D_opengl_GLContext3D().default).setProgramConstantsFromVector(this,programType,firstRegister,data,numRegisters);
	},
	setRenderToBackBuffer: function() {
		(openfl__$internal_stage3D_opengl_GLContext3D().default).setRenderToBackBuffer(this);
	},
	setRenderToTexture: function(texture,enableDepthAndStencil,antiAlias,surfaceSelector) {
		if(surfaceSelector == null) {
			surfaceSelector = 0;
		}
		if(antiAlias == null) {
			antiAlias = 0;
		}
		if(enableDepthAndStencil == null) {
			enableDepthAndStencil = false;
		}
		(openfl__$internal_stage3D_opengl_GLContext3D().default).setRenderToTexture(this,texture,enableDepthAndStencil,antiAlias,surfaceSelector);
	},
	setSamplerStateAt: function(sampler,wrap,filter,mipfilter) {
		(openfl__$internal_stage3D_opengl_GLContext3D().default).setSamplerStateAt(this,sampler,wrap,filter,mipfilter);
	},
	setScissorRectangle: function(rectangle) {
		(openfl__$internal_stage3D_opengl_GLContext3D().default).setScissorRectangle(this,rectangle);
	},
	setStencilActions: function(triangleFace,compareMode,actionOnBothPass,actionOnDepthFail,actionOnDepthPassStencilFail) {
		if(actionOnDepthPassStencilFail == null) {
			actionOnDepthPassStencilFail = "keep";
		}
		if(actionOnDepthFail == null) {
			actionOnDepthFail = "keep";
		}
		if(actionOnBothPass == null) {
			actionOnBothPass = "keep";
		}
		if(compareMode == null) {
			compareMode = "always";
		}
		if(triangleFace == null) {
			triangleFace = "frontAndBack";
		}
		(openfl__$internal_stage3D_opengl_GLContext3D().default).setStencilActions(this,triangleFace,compareMode,actionOnBothPass,actionOnDepthFail,actionOnDepthPassStencilFail);
	},
	setStencilReferenceValue: function(referenceValue,readMask,writeMask) {
		if(writeMask == null) {
			writeMask = 255;
		}
		if(readMask == null) {
			readMask = 255;
		}
		(openfl__$internal_stage3D_opengl_GLContext3D().default).setStencilReferenceValue(this,referenceValue,readMask,writeMask);
	},
	setTextureAt: function(sampler,texture) {
		(openfl__$internal_stage3D_opengl_GLContext3D().default).setTextureAt(this,sampler,texture);
	},
	setVertexBufferAt: function(index,buffer,bufferOffset,format) {
		if(format == null) {
			format = "float4";
		}
		if(bufferOffset == null) {
			bufferOffset = 0;
		}
		(openfl__$internal_stage3D_opengl_GLContext3D().default).setVertexBufferAt(this,index,buffer,bufferOffset,format);
	},
	__updateBackbufferViewport: function() {
		(openfl__$internal_stage3D_opengl_GLContext3D().default).__updateBackbufferViewportTEMP(this);
	},
	__updateBlendFactors: function() {
		(openfl__$internal_stage3D_opengl_GLContext3D().default).__updateBlendFactorsTEMP(this);
	},
	get_enableErrorChecking: function() {
		return this.__enableErrorChecking;
	},
	set_enableErrorChecking: function(value) {
		(openfl__$internal_stage3D_opengl_GLContext3D().default).setEnableErrorChecking(value);
		return this.__enableErrorChecking = value;
	}
});
Context3D.prototype.__class__ = $hxClasses["openfl.display3D.Context3D"] = Context3D;

// Init



// Statics


Context3D.supportsVideoTexture = true
Context3D.MAX_SAMPLERS = 8
Context3D.MAX_ATTRIBUTES = 16
Context3D.MAX_PROGRAM_REGISTERS = 128
Context3D.TEXTURE_MAX_ANISOTROPY_EXT = 0
Context3D.DEPTH_STENCIL = 0
Context3D.__stateCache = new (openfl__$internal_stage3D_Context3DStateCache().default)()

// Export

exports.default = Context3D;