diff --git a/src/ol/has.js b/src/ol/has.js index 1472c8b53c..63745b48ac 100644 --- a/src/ol/has.js +++ b/src/ol/has.js @@ -113,27 +113,42 @@ ol.has.POINTER = 'PointerEvent' in goog.global; 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. * @const * @type {boolean} * @api stable */ -ol.has.WEBGL = ol.ENABLE_WEBGL && ( - /** - * @return {boolean} WebGL supported. - */ - function() { - if (!('WebGLRenderingContext' in goog.global)) { - return false; - } +ol.has.WEBGL; + + +(function() { + if (ol.ENABLE_WEBGL) { + var hasWebGL = false, textureSize = -1; + if ('WebGLRenderingContext' in goog.global) { try { var canvas = /** @type {HTMLCanvasElement} */ (goog.dom.createElement(goog.dom.TagName.CANVAS)); - return !goog.isNull(ol.webgl.getContext(canvas, { + var gl = ol.webgl.getContext(canvas, { failIfMajorPerformanceCaveat: true - })); - } catch (e) { - return false; - } - })(); + }); + if (!goog.isNull(gl)) { + hasWebGL = true; + textureSize = /** @type {number} */ + (gl.getParameter(gl.MAX_TEXTURE_SIZE)); + } + } catch (e) {} + } + ol.has.WEBGL = hasWebGL; + ol.has.WEBGL_MAX_TEXTURE_SIZE = textureSize; + } +})(); diff --git a/src/ol/renderer/webgl/webglatlasmanager.js b/src/ol/renderer/webgl/webglatlasmanager.js index c43ff9dc69..a9cc08689d 100644 --- a/src/ol/renderer/webgl/webglatlasmanager.js +++ b/src/ol/renderer/webgl/webglatlasmanager.js @@ -23,6 +23,9 @@ ol.renderer.webgl.AtlasInfo; * atlas. After that, when new atlases are created, they will have * 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 * @struct * @param {number=} opt_size The size in pixels of the first atlas image