Correct WebGL context handling
This commit is contained in:
@@ -1,50 +0,0 @@
|
|||||||
goog.provide('ol.webgl.GLObject');
|
|
||||||
|
|
||||||
goog.require('goog.Disposable');
|
|
||||||
goog.require('ol.webgl.IGLObject');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @constructor
|
|
||||||
* @extends {goog.Disposable}
|
|
||||||
* @implements {ol.webgl.IGLObject}
|
|
||||||
*/
|
|
||||||
ol.webgl.GLObject = function() {
|
|
||||||
|
|
||||||
goog.base(this);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @type {WebGLRenderingContext}
|
|
||||||
*/
|
|
||||||
this.gl_ = null;
|
|
||||||
|
|
||||||
};
|
|
||||||
goog.inherits(ol.webgl.GLObject, goog.Disposable);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
ol.webgl.GLObject.prototype.disposeInternal = function() {
|
|
||||||
this.setGL(null);
|
|
||||||
goog.base(this, 'disposeInternal');
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
ol.webgl.GLObject.prototype.getGL = function() {
|
|
||||||
goog.asserts.assert(!goog.isNull(this.gl_));
|
|
||||||
return this.gl_;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
ol.webgl.GLObject.prototype.setGL = function(gl) {
|
|
||||||
this.gl_ = gl;
|
|
||||||
};
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
goog.provide('ol.webgl.IGLObject');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @interface
|
|
||||||
*/
|
|
||||||
ol.webgl.IGLObject = function() {};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return {WebGLRenderingContext} GL.
|
|
||||||
*/
|
|
||||||
ol.webgl.IGLObject.prototype.getGL = function() {};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {WebGLRenderingContext} gl GL.
|
|
||||||
*/
|
|
||||||
ol.webgl.IGLObject.prototype.setGL = function(gl) {};
|
|
||||||
+6
-27
@@ -8,7 +8,6 @@ goog.require('goog.webgl');
|
|||||||
goog.require('ol.Layer');
|
goog.require('ol.Layer');
|
||||||
goog.require('ol.Map');
|
goog.require('ol.Map');
|
||||||
goog.require('ol.TileLayer');
|
goog.require('ol.TileLayer');
|
||||||
goog.require('ol.webgl.IGLObject');
|
|
||||||
goog.require('ol.webgl.TileLayerRenderer');
|
goog.require('ol.webgl.TileLayerRenderer');
|
||||||
|
|
||||||
|
|
||||||
@@ -25,7 +24,6 @@ ol.webgl.WebGLContextEventType = {
|
|||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
* @extends {ol.Map}
|
* @extends {ol.Map}
|
||||||
* @implements {ol.webgl.IGLObject}
|
|
||||||
* @param {!HTMLDivElement} target Target.
|
* @param {!HTMLDivElement} target Target.
|
||||||
* @param {Object.<string, *>=} opt_values Values.
|
* @param {Object.<string, *>=} opt_values Values.
|
||||||
*/
|
*/
|
||||||
@@ -100,12 +98,10 @@ ol.webgl.Map.prototype.disposeInternal = function() {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @return {WebGLRenderingContext} GL.
|
||||||
*/
|
*/
|
||||||
ol.webgl.Map.prototype.getGL = function() {
|
ol.webgl.Map.prototype.getGL = function() {
|
||||||
var gl = this.gl_;
|
return this.gl_;
|
||||||
goog.asserts.assert(!goog.isNull(gl));
|
|
||||||
return gl;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -183,6 +179,10 @@ ol.webgl.Map.prototype.handleWebGLContextLost = function(event) {
|
|||||||
* @protected
|
* @protected
|
||||||
*/
|
*/
|
||||||
ol.webgl.Map.prototype.handleWebGLContextRestored = function() {
|
ol.webgl.Map.prototype.handleWebGLContextRestored = function() {
|
||||||
|
var gl = this.gl_;
|
||||||
|
gl.clearColor(1, 0, 0, 1);
|
||||||
|
gl.disable(goog.webgl.CULL_FACE);
|
||||||
|
gl.disable(goog.webgl.SCISSOR_TEST);
|
||||||
var layers = this.getLayers();
|
var layers = this.getLayers();
|
||||||
layers.forEach(function(layer) {
|
layers.forEach(function(layer) {
|
||||||
var layerRenderer = this.createLayerRenderer(layer);
|
var layerRenderer = this.createLayerRenderer(layer);
|
||||||
@@ -203,24 +203,3 @@ ol.webgl.Map.prototype.redraw_ = function() {
|
|||||||
gl.clear(goog.webgl.COLOR_BUFFER_BIT);
|
gl.clear(goog.webgl.COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
ol.webgl.Map.prototype.setGL = function(gl) {
|
|
||||||
if (!goog.isNull(this.gl_)) {
|
|
||||||
this.gl_ = null;
|
|
||||||
}
|
|
||||||
this.gl_ = gl;
|
|
||||||
if (!goog.isNull(gl)) {
|
|
||||||
gl.clearColor(1, 0, 0, 1);
|
|
||||||
gl.disable(goog.webgl.CULL_FACE);
|
|
||||||
gl.disable(goog.webgl.DEPTH_TEST);
|
|
||||||
gl.disable(goog.webgl.SCISSOR_TEST);
|
|
||||||
this.forEachLayerRenderer(function(layerRenderer) {
|
|
||||||
layerRenderer.setGL(gl);
|
|
||||||
});
|
|
||||||
this.redraw_();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|||||||
Reference in New Issue
Block a user