Add constant ol.has.WEBGL_MAX_TEXTURE_SIZE

This commit is contained in:
tsauerwein
2014-11-06 10:24:14 +01:00
parent 7618c96c29
commit 581b372c6a
2 changed files with 32 additions and 14 deletions

View File

@@ -113,27 +113,42 @@ ol.has.POINTER = 'PointerEvent' in goog.global;
ol.has.MSPOINTER = !!(goog.global.navigator.msPointerEnabled); ol.has.MSPOINTER = !!(goog.global.navigator.msPointerEnabled);
/**
* The maximum supported WebGL texture size in pixels. If WebGL is not
* supported, the value is set to `-1`.
* @const
* @type {number}
*/
ol.has.WEBGL_MAX_TEXTURE_SIZE;
/** /**
* True if browser supports WebGL. * True if browser supports WebGL.
* @const * @const
* @type {boolean} * @type {boolean}
* @api stable * @api stable
*/ */
ol.has.WEBGL = ol.ENABLE_WEBGL && ( ol.has.WEBGL;
/**
* @return {boolean} WebGL supported.
*/ (function() {
function() { if (ol.ENABLE_WEBGL) {
if (!('WebGLRenderingContext' in goog.global)) { var hasWebGL = false, textureSize = -1;
return false; if ('WebGLRenderingContext' in goog.global) {
}
try { try {
var canvas = /** @type {HTMLCanvasElement} */ var canvas = /** @type {HTMLCanvasElement} */
(goog.dom.createElement(goog.dom.TagName.CANVAS)); (goog.dom.createElement(goog.dom.TagName.CANVAS));
return !goog.isNull(ol.webgl.getContext(canvas, { var gl = ol.webgl.getContext(canvas, {
failIfMajorPerformanceCaveat: true failIfMajorPerformanceCaveat: true
})); });
} catch (e) { if (!goog.isNull(gl)) {
return false; hasWebGL = true;
textureSize = /** @type {number} */
(gl.getParameter(gl.MAX_TEXTURE_SIZE));
} }
})(); } catch (e) {}
}
ol.has.WEBGL = hasWebGL;
ol.has.WEBGL_MAX_TEXTURE_SIZE = textureSize;
}
})();

View File

@@ -23,6 +23,9 @@ ol.renderer.webgl.AtlasInfo;
* atlas. After that, when new atlases are created, they will have * atlas. After that, when new atlases are created, they will have
* twice the size as the latest atlas (until `maxSize` is reached.) * twice the size as the latest atlas (until `maxSize` is reached.)
* *
* It is recommended to use `ol.has.WEBGL_MAX_TEXTURE_SIZE` as
* `maxSize` value.
*
* @constructor * @constructor
* @struct * @struct
* @param {number=} opt_size The size in pixels of the first atlas image * @param {number=} opt_size The size in pixels of the first atlas image