12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.24/esri/copyright.txt for details.
- */
- import"../../core/has.js";import{isSome as e}from"../../core/maybe.js";import{ShaderType as t}from"./enums.js";import r from"./reservedWordsGLSL3.js";import{shaderTranspiler as a}from"./testUtils.js";var o,n={exports:{}};void 0!==(o=["precision","highp","mediump","lowp","attribute","const","uniform","varying","break","continue","do","for","while","if","else","in","out","inout","float","int","void","bool","true","false","discard","return","mat2","mat3","mat4","vec2","vec3","vec4","ivec2","ivec3","ivec4","bvec2","bvec3","bvec4","sampler1D","sampler2D","sampler3D","samplerCube","sampler1DShadow","sampler2DShadow","struct","asm","class","union","enum","typedef","template","this","packed","goto","switch","default","inline","noinline","volatile","public","static","extern","external","interface","long","short","double","half","fixed","unsigned","input","output","hvec2","hvec3","hvec4","dvec2","dvec3","dvec4","fvec2","fvec3","fvec4","sampler2DRect","sampler3DRect","sampler2DRectShadow","sizeof","cast","namespace","using"])&&(n.exports=o);const i=n.exports;var l,s={exports:{}};l=s,function(e){var t=["<<=",">>=","++","--","<<",">>","<=",">=","==","!=","&&","||","+=","-=","*=","/=","%=","&=","^^","^=","|=","(",")","[","]",".","!","~","*","/","%","+","-","<",">","&","^","|","?",":","=",",",";","{","}"];void 0!==t&&(l.exports=t)}();const c=s.exports;var d={exports:{}};!function(e){!function(t){var r=function(){return["abs","acos","all","any","asin","atan","ceil","clamp","cos","cross","dFdx","dFdy","degrees","distance","dot","equal","exp","exp2","faceforward","floor","fract","gl_BackColor","gl_BackLightModelProduct","gl_BackLightProduct","gl_BackMaterial","gl_BackSecondaryColor","gl_ClipPlane","gl_ClipVertex","gl_Color","gl_DepthRange","gl_DepthRangeParameters","gl_EyePlaneQ","gl_EyePlaneR","gl_EyePlaneS","gl_EyePlaneT","gl_Fog","gl_FogCoord","gl_FogFragCoord","gl_FogParameters","gl_FragColor","gl_FragCoord","gl_FragData","gl_FragDepth","gl_FragDepthEXT","gl_FrontColor","gl_FrontFacing","gl_FrontLightModelProduct","gl_FrontLightProduct","gl_FrontMaterial","gl_FrontSecondaryColor","gl_LightModel","gl_LightModelParameters","gl_LightModelProducts","gl_LightProducts","gl_LightSource","gl_LightSourceParameters","gl_MaterialParameters","gl_MaxClipPlanes","gl_MaxCombinedTextureImageUnits","gl_MaxDrawBuffers","gl_MaxFragmentUniformComponents","gl_MaxLights","gl_MaxTextureCoords","gl_MaxTextureImageUnits","gl_MaxTextureUnits","gl_MaxVaryingFloats","gl_MaxVertexAttribs","gl_MaxVertexTextureImageUnits","gl_MaxVertexUniformComponents","gl_ModelViewMatrix","gl_ModelViewMatrixInverse","gl_ModelViewMatrixInverseTranspose","gl_ModelViewMatrixTranspose","gl_ModelViewProjectionMatrix","gl_ModelViewProjectionMatrixInverse","gl_ModelViewProjectionMatrixInverseTranspose","gl_ModelViewProjectionMatrixTranspose","gl_MultiTexCoord0","gl_MultiTexCoord1","gl_MultiTexCoord2","gl_MultiTexCoord3","gl_MultiTexCoord4","gl_MultiTexCoord5","gl_MultiTexCoord6","gl_MultiTexCoord7","gl_Normal","gl_NormalMatrix","gl_NormalScale","gl_ObjectPlaneQ","gl_ObjectPlaneR","gl_ObjectPlaneS","gl_ObjectPlaneT","gl_Point","gl_PointCoord","gl_PointParameters","gl_PointSize","gl_Position","gl_ProjectionMatrix","gl_ProjectionMatrixInverse","gl_ProjectionMatrixInverseTranspose","gl_ProjectionMatrixTranspose","gl_SecondaryColor","gl_TexCoord","gl_TextureEnvColor","gl_TextureMatrix","gl_TextureMatrixInverse","gl_TextureMatrixInverseTranspose","gl_TextureMatrixTranspose","gl_Vertex","greaterThan","greaterThanEqual","inversesqrt","length","lessThan","lessThanEqual","log","log2","matrixCompMult","max","min","mix","mod","normalize","not","notEqual","pow","radians","reflect","refract","sign","sin","smoothstep","sqrt","step","tan","texture2D","texture2DLod","texture2DProj","texture2DProjLod","textureCube","textureCubeLod","texture2DLodEXT","texture2DProjLodEXT","textureCubeLodEXT","texture2DGradEXT","texture2DProjGradEXT","textureCubeGradEXT"]}();void 0!==r&&(e.exports=r)}()}(d);const u=d.exports;var g=999,p=9999,f=0,_=1,h=2,x=3,m=4,y=5,w=6,M=7,v=8,T=9,b=10,P=11,E=["block-comment","line-comment","preprocessor","operator","integer","float","ident","builtin","keyword","whitespace","eof","integer"];function C(){var e,t,r,a=0,o=0,n=g,l=[],s=[],d=1,C=0,k=0,j=!1,D=!1,F="";return function(e){return s=[],null!==e?S(e.replace?e.replace(/\r\n/g,"\n"):e):R()};function L(e){e.length&&s.push({type:E[n],data:e,position:k,line:d,column:C})}function S(t){var i;for(a=0,r=(F+=t).length;e=F[a],a<r;){switch(i=a,n){case f:a=I();break;case _:a=G();break;case h:a=A();break;case x:a=O();break;case m:a=B();break;case P:a=q();break;case y:a=H();break;case p:a=N();break;case T:a=X();break;case g:a=V()}if(i!==a)if("\n"===F[i])C=0,++d;else++C}return o+=a,F=F.slice(a),s}function R(e){return l.length&&L(l.join("")),n=b,L("(eof)"),s}function V(){return l=l.length?[]:l,"/"===t&&"*"===e?(k=o+a-1,n=f,t=e,a+1):"/"===t&&"/"===e?(k=o+a-1,n=_,t=e,a+1):"#"===e?(n=h,k=o+a,a):/\s/.test(e)?(n=T,k=o+a,a):(j=/\d/.test(e),D=/[^\w_]/.test(e),k=o+a,n=j?m:D?x:p,a)}function X(){return/[^\s]/g.test(e)?(L(l.join("")),n=g,a):(l.push(e),t=e,a+1)}function A(){return"\r"!==e&&"\n"!==e||"\\"===t?(l.push(e),t=e,a+1):(L(l.join("")),n=g,a)}function G(){return A()}function I(){return"/"===e&&"*"===t?(l.push(e),L(l.join("")),n=g,a+1):(l.push(e),t=e,a+1)}function O(){if("."===t&&/\d/.test(e))return n=y,a;if("/"===t&&"*"===e)return n=f,a;if("/"===t&&"/"===e)return n=_,a;if("."===e&&l.length){for(;U(l););return n=y,a}if(";"===e||")"===e||"("===e){if(l.length)for(;U(l););return L(e),n=g,a+1}var r=2===l.length&&"="!==e;if(/[\w_\d\s]/.test(e)||r){for(;U(l););return n=g,a}return l.push(e),t=e,a+1}function U(e){for(var t,r,a=0;;){if(t=c.indexOf(e.slice(0,e.length+a).join("")),r=c[t],-1===t){if(a--+e.length>0)continue;r=e.slice(0,1).join("")}return L(r),k+=r.length,(l=l.slice(r.length)).length}}function q(){return/[^a-fA-F0-9]/.test(e)?(L(l.join("")),n=g,a):(l.push(e),t=e,a+1)}function B(){return"."===e||/[eE]/.test(e)?(l.push(e),n=y,t=e,a+1):"x"===e&&1===l.length&&"0"===l[0]?(n=P,l.push(e),t=e,a+1):/[^\d]/.test(e)?(L(l.join("")),n=g,a):(l.push(e),t=e,a+1)}function H(){return"f"===e&&(l.push(e),t=e,a+=1),/[eE]/.test(e)||"-"===e&&/[eE]/.test(t)?(l.push(e),t=e,a+1):/[^\d]/.test(e)?(L(l.join("")),n=g,a):(l.push(e),t=e,a+1)}function N(){if(/[^\d\w_]/.test(e)){var r=l.join("");return n=i.indexOf(r)>-1?v:u.indexOf(r)>-1?M:w,L(l.join("")),n=g,a}return l.push(e),t=e,a+1}}function k(e){var t=C(),r=[];return r=(r=r.concat(t(e))).concat(t(null))}function j(e){return k(e)}function D(e){return e.map((e=>"eof"!==e.type?e.data:"")).join("")}const F=["GL_OES_standard_derivatives","GL_EXT_frag_depth","GL_EXT_draw_buffers","GL_EXT_shader_texture_lod"];function L(e,t="100",r="300 es"){const a=/^\s*\#version\s+([0-9]+(\s+[a-zA-Z]+)?)\s*/;for(const o of e)if("preprocessor"===o.type){const e=a.exec(o.data);if(e){const a=e[1].replace(/\s\s+/g," ");if(a===r)return a;if(a===t)return o.data="#version "+r,t;throw new Error("unknown glsl version: "+a)}}return e.splice(0,0,{type:"preprocessor",data:"#version "+r},{type:"whitespace",data:"\n"}),null}function S(e,t){for(let r=t-1;r>=0;r--){const t=e[r];if("whitespace"!==t.type&&"block-comment"!==t.type){if("keyword"!==t.type)break;if("attribute"===t.data||"in"===t.data)return!0}}return!1}function R(e,t,r,a){a=a||r;for(const o of e)if("ident"===o.type&&o.data===r){a in t?t[a]++:t[a]=0;return R(e,t,a+"_"+t[a],a)}return r}function V(e,t,r="afterVersion"){function a(e,t){for(let r=t;r<e.length;r++){const t=e[r];if("operator"===t.type&&";"===t.data)return r}return null}function o(e){let t=-1,o=0,n=-1;for(let i=0;i<e.length;i++){const l=e[i];if("preprocessor"===l.type&&(l.data.match(/\#(if|ifdef|ifndef)\s+.+/)?++o:l.data.match(/\#endif\s*.*/)&&--o),"afterVersion"!==r&&"afterPrecision"!==r||"preprocessor"===l.type&&/^#version/.test(l.data)&&(n=Math.max(n,i)),"afterPrecision"===r&&"keyword"===l.type&&"precision"===l.data){const t=a(e,i);if(null===t)throw new Error("precision statement not followed by any semicolons!");n=Math.max(n,t)}t<n&&0===o&&(t=i)}return t+1}const n={data:"\n",type:"whitespace"},i=t=>t<e.length&&/[^\r\n]$/.test(e[t].data);let l=o(e);i(l-1)&&e.splice(l++,0,n);for(const s of t)e.splice(l++,0,s);i(l-1)&&i(l)&&e.splice(l,0,n)}function X(e,t,r,a="lowp"){V(e,[{type:"keyword",data:"out"},{type:"whitespace",data:" "},{type:"keyword",data:a},{type:"whitespace",data:" "},{type:"keyword",data:r},{type:"whitespace",data:" "},{type:"ident",data:t},{type:"operator",data:";"}],"afterPrecision")}function A(e,t,r,a,o="lowp"){V(e,[{type:"keyword",data:"layout"},{type:"operator",data:"("},{type:"keyword",data:"location"},{type:"whitespace",data:" "},{type:"operator",data:"="},{type:"whitespace",data:" "},{type:"integer",data:a.toString()},{type:"operator",data:")"},{type:"whitespace",data:" "},{type:"keyword",data:"out"},{type:"whitespace",data:" "},{type:"keyword",data:o},{type:"whitespace",data:" "},{type:"keyword",data:r},{type:"whitespace",data:" "},{type:"ident",data:t},{type:"operator",data:";"}],"afterPrecision")}function G(e,t){let r,a,o=-1;for(let n=t;n<e.length;n++){const t=e[n];if("operator"===t.type&&("["===t.data&&(r=n),"]"===t.data)){a=n;break}"integer"===t.type&&(o=parseInt(t.data,10))}return r&&a&&e.splice(r,a-r+1),o}function I(a,o){const n=U(a);if(e(n))return n;const i=j(a);if("300 es"===L(i,"100","300 es"))return a;let l=null,s=null;const c={},d={};for(let e=0;e<i.length;++e){const a=i[e];switch(a.type){case"keyword":o===t.VERTEX_SHADER&&"attribute"===a.data?a.data="in":"varying"===a.data&&(a.data=o===t.VERTEX_SHADER?"out":"in");break;case"builtin":if(/^texture(2D|Cube)(Proj)?(Lod|Grad)?(EXT)?$/.test(a.data.trim())&&(a.data=a.data.replace(/(2D|Cube|EXT)/g,"")),o===t.FRAGMENT_SHADER&&"gl_FragColor"===a.data&&(l||(l=R(i,c,"fragColor"),X(i,l,"vec4")),a.data=l),o===t.FRAGMENT_SHADER&&"gl_FragData"===a.data){const t=G(i,e+1),r=R(i,c,"fragData");A(i,r,"vec4",t,"mediump"),a.data=r}else o===t.FRAGMENT_SHADER&&"gl_FragDepthEXT"===a.data&&(s||(s=R(i,c,"gl_FragDepth")),a.data=s);break;case"ident":if(r.includes(a.data)){if(o===t.VERTEX_SHADER&&S(i,e))throw new Error("attribute in vertex shader uses a name that is a reserved word in glsl 300 es");a.data in d||(d[a.data]=R(i,c,a.data)),a.data=d[a.data]}}}for(let e=i.length-1;e>=0;--e){const t=i[e];if("preprocessor"===t.type){const r=t.data.match(/\#extension\s+(.*)\:/);if(r&&r[1]&&F.includes(r[1].trim())){const t=i[e+1];i.splice(e,t&&"whitespace"===t.type?2:1)}const a=t.data.match(/\#ifdef\s+(.*)/);a&&a[1]&&F.includes(a[1].trim())&&(t.data="#if 1");const o=t.data.match(/\#ifndef\s+(.*)/);o&&o[1]&&F.includes(o[1].trim())&&(t.data="#if 0")}}return q(a,D(i))}const O=new Map;function U(e){return a.enableCache?O.get(e):null}function q(e,t){return a.enableCache&&O.set(e,t),t}export{I as transpileShader};
|