/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.25/esri/copyright.txt for details. */ import{isNone as t,isSome as e}from"../../core/maybe.js";import{getContextTypes as r,ContextType as s,createContext as o}from"./context-util.js";let n,a;function l(t){const e=r(t);for(;e.length>1;){const t=u(e.shift());if(t.available)return t}return u(e.shift())}function u(t){switch(t){case s.WEBGL1:return i();case s.WEBGL2:return f()}}function i(){return n||(n=d()),n}function f(){return a||(a=x()),a}class p{constructor(){this.available=!1,this.majorPerformanceCaveat=!1,this.maxTextureSize=0,this.supportsVertexShaderSamplers=!1,this.supportsHighPrecisionFragment=!1,this.supportsElementIndexUint=!1,this.supportsStandardDerivatives=!1,this.supportsInstancedArrays=!1,this.supportsTextureFloat=!1,this.supportsTextureHalfFloat=!1,this.supportsColorBufferFloat=!1,this.supportsColorBufferFloatBlend=!1,this.supportsColorBufferHalfFloat=!1}}class c extends p{constructor(){super(...arguments),this.type=s.WEBGL1}}class E extends p{constructor(){super(...arguments),this.type=s.WEBGL2,this.supportsElementIndexUint=!0,this.supportsStandardDerivatives=!0,this.supportsInstancedArrays=!0,this.supportsTextureFloat=!0,this.supportsTextureHalfFloat=!0}}function _(r,n){if(r===s.WEBGL1&&"undefined"==typeof WebGLRenderingContext||r===s.WEBGL2&&"undefined"==typeof WebGL2RenderingContext)return null;const a=document.createElement("canvas");if(!a)return null;let l=o(a,r,{failIfMajorPerformanceCaveat:!0});if(t(l)&&(l=o(a,r),e(l)&&(n.majorPerformanceCaveat=!0)),t(l))return l;if(r===s.WEBGL1){const t=l.getParameter(l.VERSION)?.match(/^WebGL\s+([\d.]*)/);if(t){const e=parseFloat(t[1]);n.available=e>=.94}}else n.available=!0;n.maxTextureSize=l.getParameter(l.MAX_TEXTURE_SIZE),n.supportsVertexShaderSamplers=l.getParameter(l.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0;const u=l.getShaderPrecisionFormat(l.FRAGMENT_SHADER,l.HIGH_FLOAT);return u&&(n.supportsHighPrecisionFragment=u.precision>0),l}function d(){const e=new c,r=_(s.WEBGL1,e);return t(r)||(e.supportsElementIndexUint=null!==r.getExtension("OES_element_index_uint"),e.supportsStandardDerivatives=null!==r.getExtension("OES_standard_derivatives"),e.supportsInstancedArrays=null!==r.getExtension("ANGLE_instanced_arrays"),e.supportsTextureFloat=null!==r.getExtension("OES_texture_float"),e.supportsTextureHalfFloat=null!==r.getExtension("OES_texture_half_float"),e.supportsColorBufferFloat=null!==r.getExtension("WEBGL_color_buffer_float"),e.supportsColorBufferFloatBlend=null!==r.getExtension("EXT_float_blend"),e.supportsColorBufferHalfFloat=null!==r.getExtension("EXT_color_buffer_half_float")),e}function x(){const e=new E,r=_(s.WEBGL2,e);return t(r)||(e.supportsColorBufferFloat=null!==r.getExtension("EXT_color_buffer_float"),e.supportsColorBufferFloatBlend=null!==r.getExtension("EXT_float_blend"),e.supportsColorBufferHalfFloat=e.supportsColorBufferFloat||null!==r.getExtension("EXT_color_buffer_half_float")),e}export{i as getWebGL1Capabilities,f as getWebGL2Capabilities,l as getWebGLCapabilities,u as getWebGLVersionCapabilities};