// Class: openfl.display.OpenGLView

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_display_DirectRenderer() {return require("./../../openfl/display/DirectRenderer");}
function openfl__$internal_renderer_dom_DOMRenderer() {return require("./../../openfl/_internal/renderer/dom/DOMRenderer");}
function openfl_geom_Rectangle() {return require("./../../openfl/geom/Rectangle");}
function lime_graphics_opengl_GL() {return require("./../../lime/graphics/opengl/GL");}
function js_Browser() {return require("./../../js/Browser");}

// Constructor

var OpenGLView = function() {
	(openfl_display_DirectRenderer().default).call(this,"OpenGLView");
}

// Meta

OpenGLView.__name__ = ["openfl","display","OpenGLView"];
OpenGLView.__super__ = (openfl_display_DirectRenderer().default);
OpenGLView.prototype = $extend((openfl_display_DirectRenderer().default).prototype, {
	__enterFrame: function(deltaTime) {
		if(this.__render != null) {
			this.__setRenderDirty();
		}
	},
	__renderCanvas: function(renderSession) {
	},
	__renderDOM: function(renderSession) {
		if(this.stage != null && this.__worldVisible && this.__renderable) {
			if(!this.__added) {
				renderSession.element.appendChild(this.__canvas);
				this.__added = true;
				(openfl__$internal_renderer_dom_DOMRenderer().default).initializeElement(this,this.__canvas,renderSession);
			}
			if(this.__context != null) {
				var rect = null;
				if(this.__scrollRect == null) {
					rect = new (openfl_geom_Rectangle().default)(0,0,this.stage.stageWidth,this.stage.stageHeight);
				} else {
					rect = new (openfl_geom_Rectangle().default)(this.get_x() + this.__scrollRect.x,this.get_y() + this.__scrollRect.y,this.__scrollRect.width,this.__scrollRect.height);
				}
				if(this.__render != null) {
					this.__render(rect);
				}
			}
		} else if(this.__added) {
			renderSession.element.removeChild(this.__canvas);
			this.__added = false;
		}
	},
	__renderGL: function(renderSession) {
		if(this.stage != null && this.__renderable) {
			var rect = null;
			if(this.__scrollRect == null) {
				rect = new (openfl_geom_Rectangle().default)(0,0,this.stage.stageWidth,this.stage.stageHeight);
			} else {
				rect = new (openfl_geom_Rectangle().default)(this.get_x() + this.__scrollRect.x,this.get_y() + this.__scrollRect.y,this.__scrollRect.width,this.__scrollRect.height);
			}
			renderSession.shaderManager.setShader(null);
			renderSession.blendModeManager.setBlendMode(null);
			if(this.__render != null) {
				this.__render(rect);
			}
		}
	},
	__renderGLMask: function(renderSession) {
	}
});
OpenGLView.prototype.__class__ = $hxClasses["openfl.display.OpenGLView"] = OpenGLView;

// Init



// Statics

OpenGLView.get_isSupported = function() {
	if(!window.WebGLRenderingContext) {
		return false;
	}
	if((lime_graphics_opengl_GL().default).context != null) {
		return true;
	} else {
		var canvas = (js_Browser().default).get_document().createElement("canvas");
		var context = canvas.getContext("webgl");
		if(context == null) {
			context = canvas.getContext("experimental-webgl");
		}
		return context != null;
	}
}
OpenGLView.CONTEXT_LOST = "glcontextlost"
OpenGLView.CONTEXT_RESTORED = "glcontextrestored"

// Export

exports.default = OpenGLView;