@gjsify/webgl 0.3.20 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/lib/esm/_virtual/_rolldown/runtime.js +1 -0
  2. package/lib/esm/conformance/attribs.spec.js +2 -2
  3. package/lib/esm/conformance/buffers.spec.js +1 -1
  4. package/lib/esm/conformance/context.spec.js +3 -3
  5. package/lib/esm/conformance/programs.spec.js +3 -3
  6. package/lib/esm/conformance/rendering-basic.spec.js +3 -3
  7. package/lib/esm/conformance/rendering.spec.js +6 -6
  8. package/lib/esm/conformance/setup.js +1 -1
  9. package/lib/esm/conformance/state.spec.js +1 -1
  10. package/lib/esm/conformance/textures.spec.js +3 -3
  11. package/lib/esm/conformance/uniforms.spec.js +1 -1
  12. package/lib/esm/conformance-test.js +1 -1
  13. package/lib/esm/context/buffer-binding.js +1 -0
  14. package/lib/esm/context/drawing.js +1 -0
  15. package/lib/esm/context/framebuffer.js +1 -0
  16. package/lib/esm/context/index.js +1 -0
  17. package/lib/esm/context/shader-program.js +8 -0
  18. package/lib/esm/context/state.js +1 -0
  19. package/lib/esm/context/texture-management.js +1 -0
  20. package/lib/esm/extensions/ext-blend-minmax.js +1 -1
  21. package/lib/esm/extensions/ext-color-buffer-float.js +1 -1
  22. package/lib/esm/extensions/ext-color-buffer-half-float.js +1 -1
  23. package/lib/esm/extensions/ext-texture-filter-anisotropic.js +1 -1
  24. package/lib/esm/extensions/oes-element-index-unit.js +1 -1
  25. package/lib/esm/extensions/oes-standard-derivatives.js +1 -1
  26. package/lib/esm/extensions/oes-texture-float-linear.js +1 -1
  27. package/lib/esm/extensions/oes-texture-float.js +1 -1
  28. package/lib/esm/extensions/oes-texture-half-float.js +1 -1
  29. package/lib/esm/extensions/stackgl-destroy-context.js +1 -1
  30. package/lib/esm/extensions/stackgl-resize-drawing-buffer.js +1 -1
  31. package/lib/esm/html-canvas-element.js +1 -1
  32. package/lib/esm/index.js +1 -1
  33. package/lib/esm/linkable.js +1 -1
  34. package/lib/esm/test-utils.js +4 -4
  35. package/lib/esm/test.js +1 -1
  36. package/lib/esm/utils.js +1 -1
  37. package/lib/esm/webgl-active-info.js +1 -1
  38. package/lib/esm/webgl-bridge.js +1 -1
  39. package/lib/esm/webgl-buffer.js +1 -1
  40. package/lib/esm/webgl-context-attributes.js +1 -1
  41. package/lib/esm/webgl-context-base.js +1 -8
  42. package/lib/esm/webgl-drawing-buffer-wrapper.js +1 -1
  43. package/lib/esm/webgl-framebuffer.js +1 -1
  44. package/lib/esm/webgl-program.js +1 -1
  45. package/lib/esm/webgl-query.js +1 -1
  46. package/lib/esm/webgl-renderbuffer.js +1 -1
  47. package/lib/esm/webgl-rendering-context.js +1 -1
  48. package/lib/esm/webgl-sampler.js +1 -1
  49. package/lib/esm/webgl-shader-precision-format.js +1 -1
  50. package/lib/esm/webgl-shader.js +1 -1
  51. package/lib/esm/webgl-sync.js +1 -1
  52. package/lib/esm/webgl-texture-unit.js +1 -1
  53. package/lib/esm/webgl-texture.js +1 -1
  54. package/lib/esm/webgl-transform-feedback.js +1 -1
  55. package/lib/esm/webgl-uniform-location.js +1 -1
  56. package/lib/esm/webgl-vertex-array-object.js +1 -1
  57. package/lib/esm/webgl-vertex-attribute.js +1 -1
  58. package/lib/esm/webgl1.spec.js +10 -10
  59. package/lib/esm/webgl2-rendering-context.js +1 -1
  60. package/lib/esm/webgl2.spec.js +22 -22
  61. package/lib/types/context/buffer-binding.d.ts +17 -0
  62. package/lib/types/context/drawing.d.ts +29 -0
  63. package/lib/types/context/framebuffer.d.ts +33 -0
  64. package/lib/types/context/index.d.ts +7 -0
  65. package/lib/types/context/shader-program.d.ts +67 -0
  66. package/lib/types/context/state.d.ts +60 -0
  67. package/lib/types/context/texture-management.d.ts +39 -0
  68. package/lib/types/index.d.ts +11 -0
  69. package/lib/types/webgl-context-base.d.ts +41 -198
  70. package/lib/types/webgl2-rendering-context.d.ts +1 -1
  71. package/package.json +8 -8
@@ -0,0 +1 @@
1
+ import"../_virtual/_rolldown/runtime.js";import{installStateMethods as e}from"./state.js";import{installBufferBindingMethods as t}from"./buffer-binding.js";import{installTextureManagementMethods as n}from"./texture-management.js";import{installFramebufferMethods as r}from"./framebuffer.js";import{installShaderProgramMethods as i}from"./shader-program.js";import{installDrawingMethods as a}from"./drawing.js";function installAllContextMethods(o){e(o),t(o),n(o),r(o),i(o),a(o)}export{installAllContextMethods};
@@ -0,0 +1,8 @@
1
+ import"../_virtual/_rolldown/runtime.js";import{WebGLUniformLocation as e}from"../webgl-uniform-location.js";import{checkObject as t,checkUniform as n,isValidString as r,listToArray as i,uniformTypeSize as a}from"../utils.js";import{WebGLProgram as o}from"../webgl-program.js";import{WebGLShader as s}from"../webgl-shader.js";import{WebGLActiveInfo as c}from"../webgl-active-info.js";import{WebGLShaderPrecisionFormat as l}from"../webgl-shader-precision-format.js";import u from"glsl-tokenizer/string";const d={createShader(e=0){if(e!==this.FRAGMENT_SHADER&&e!==this.VERTEX_SHADER)return this.setError(this.INVALID_ENUM),null;let t=this._gl.createShader(e);if(t<0)return null;let n=new s(t,this,e);return this._shaders[t]=n,n},deleteShader(e){this._deleteLinkable(`deleteShader`,e,s)},compileShader(e){if(!t(e))throw TypeError(`compileShader(WebGLShader)`);if(this._checkWrapper(e,s)&&this._checkShaderSource(e)){let t=this.getError();this._gl.compileShader(e._|0),e._needsRecompile=!1;let n=this.getError();e._compileStatus=!!this._gl.getShaderParameter(e._|0,this.COMPILE_STATUS),e._compileInfo=this._gl.getShaderInfoLog(e._|0)||`null`,this.getError(),this.setError(t||n)}},shaderSource(e,n){if(!t(e))throw TypeError(`shaderSource(WebGLShader, String)`);if(!e||!n&&typeof n!=`string`){this.setError(this.INVALID_VALUE);return}r(n)?this._checkWrapper(e,s)&&(n=this._wrapShader(e._type,n),this._gl.shaderSource(e._|0,n),e._source=n,e._needsRecompile=!0):this.setError(this.INVALID_VALUE)},getShaderInfoLog(e){if(!t(e))throw TypeError(`getShaderInfoLog(WebGLShader)`);return this._checkWrapper(e,s)?e._compileInfo:null},getShaderParameter(e,n=0){if(!t(e))throw TypeError(`getShaderParameter(WebGLShader, GLenum)`);if(this._checkWrapper(e,s)){switch(n){case this.DELETE_STATUS:return e._pendingDelete;case this.COMPILE_STATUS:return e._compileStatus;case this.SHADER_TYPE:return e._type}this.setError(this.INVALID_ENUM)}return null},getShaderPrecisionFormat(e=0,t=0){if(!(e===this.FRAGMENT_SHADER||e===this.VERTEX_SHADER)||!(t===this.LOW_FLOAT||t===this.MEDIUM_FLOAT||t===this.HIGH_FLOAT||t===this.LOW_INT||t===this.MEDIUM_INT||t===this.HIGH_INT))return this.setError(this.INVALID_ENUM),null;let n=this._gl.getShaderPrecisionFormat(e,t);return n?new l(n):null},getShaderSource(e){if(!t(e))throw TypeError(`Input to getShaderSource must be an object`);return this._checkWrapper(e,s)?e._source:null},attachShader(e,n){if(!t(e)||!t(n))throw TypeError(`attachShader(WebGLProgram, WebGLShader)`);if(!e||!n){this.setError(this.INVALID_VALUE);return}else if(e instanceof o&&n instanceof s&&this._checkOwns(e)&&this._checkOwns(n)&&!e._linked(n)){this._saveError(),this._gl.attachShader(e._|0,n._|0);let t=this.getError();this._restoreError(t),t===this.NO_ERROR&&e._link(n);return}this.setError(this.INVALID_OPERATION)},detachShader(e,n){if(!t(e)||!t(n))throw TypeError(`detachShader(WebGLProgram, WebGLShader)`);this._checkWrapper(e,o)&&this._checkWrapper(n,s)&&(e._linked(n)?(this._gl.detachShader(e._,n._),e._unlink(n)):this.setError(this.INVALID_OPERATION))},bindAttribLocation(e,n,i){if(!t(e)||typeof i!=`string`)throw TypeError(`bindAttribLocation(WebGLProgram, GLint, String)`);i+=``,!r(i)||i.length>256?this.setError(this.INVALID_VALUE):/^_?webgl_a/.test(i)?this.setError(this.INVALID_OPERATION):this._checkWrapper(e,o)&&this._gl.bindAttribLocation(e._|0,n|0,i)},createProgram(){let e=this._gl.createProgram();if(e<=0)return null;let t=new o(e,this);return this._programs[e]=t,t},deleteProgram(e){this._deleteLinkable(`deleteProgram`,e,o)},useProgram(e){if(!t(e))throw TypeError(`useProgram(WebGLProgram)`);if(e)this._checkWrapper(e,o)&&(this._activeProgram!==e&&(this._switchActiveProgram(this._activeProgram),this._activeProgram=e,e._refCount+=1),this._gl.useProgram(e._|0));else{this._switchActiveProgram(this._activeProgram),this._activeProgram=null,this._gl.useProgram(0);return}},linkProgram(e){if(!t(e))throw TypeError(`linkProgram(WebGLProgram)`);if(this._checkWrapper(e,o)){e._linkCount+=1,e._attributes=[];let t=this.getError();for(let t of e._references)t instanceof s&&t._needsRecompile&&(this._gl.compileShader(t._|0),t._needsRecompile=!1);this._gl.linkProgram(e._|0);let n=this.getError();n===this.NO_ERROR&&(e._linkStatus=this._fixupLink(e)),this.getError(),this.setError(t||n)}},validateProgram(e){if(this._checkWrapper(e,o)){this._gl.validateProgram(e._|0);let t=this.getError();t===this.NO_ERROR&&(e._linkInfoLog=this._gl.getProgramInfoLog(e._|0)),this.getError(),this.setError(t)}},getActiveAttrib(e,n){if(!t(e))throw TypeError(`getActiveAttrib(WebGLProgram)`);if(!e)throw TypeError(`getActiveAttrib(WebGLProgram, GLuint)`);if(this._checkWrapper(e,o)){if(n>=(e._linkStatus?e._attributes.length:this._gl.getProgramParameter(e._|0,this.ACTIVE_ATTRIBUTES)))return this._gl.getError(),this.setError(this.INVALID_VALUE),null;let t=this._gl.getActiveAttrib(e._|0,n|0);if(t)return new c(t)}return null},getActiveUniform(e,n){if(!t(e))throw TypeError(`getActiveUniform(WebGLProgram, GLint)`);if(!e)throw TypeError(`getActiveUniform(WebGLProgram, GLuint)`);if(this._checkWrapper(e,o)){if(n>=(e._linkStatus?e._uniforms.length:this._gl.getProgramParameter(e._|0,this.ACTIVE_UNIFORMS)))return this.setError(this.INVALID_VALUE),null;let t=this._gl.getActiveUniform(e._|0,n|0);if(t)return new c(t)}return null},getAttachedShaders(e){if(!t(e)||typeof e==`object`&&e&&!(e instanceof o))throw TypeError(`getAttachedShaders(WebGLProgram)`);if(!e)this.setError(this.INVALID_VALUE);else if(this._checkWrapper(e,o))return e._references.filter(e=>e instanceof s);return null},getAttribLocation(e,n){if(!t(e))throw TypeError(`getAttribLocation(WebGLProgram, String)`);if(n+=``,!r(n)||n.length>256)this.setError(this.INVALID_VALUE);else if(this._checkWrapper(e,o))return this._gl.getAttribLocation(e._|0,n+``);return-1},getUniform(e,r){if(!t(e)||!t(r))throw TypeError(`getUniform(WebGLProgram, WebGLUniformLocation)`);if(!e)return this.setError(this.INVALID_VALUE),null;if(!r)return null;if(this._checkWrapper(e,o)){if(!n(e,r))return this.setError(this.INVALID_OPERATION),null;let t=this._gl.getUniform(e._|0,r._|0);if(!t)return null;switch(r._activeInfo.type){case this.FLOAT:return t[0];case this.FLOAT_VEC2:return new Float32Array(t.slice(0,2));case this.FLOAT_VEC3:return new Float32Array(t.slice(0,3));case this.FLOAT_VEC4:return new Float32Array(t.slice(0,4));case this.INT:return t[0]|0;case this.INT_VEC2:return new Int32Array(t.slice(0,2));case this.INT_VEC3:return new Int32Array(t.slice(0,3));case this.INT_VEC4:return new Int32Array(t.slice(0,4));case this.BOOL:return!!t[0];case this.BOOL_VEC2:return[!!t[0],!!t[1]];case this.BOOL_VEC3:return[!!t[0],!!t[1],!!t[2]];case this.BOOL_VEC4:return[!!t[0],!!t[1],!!t[2],!!t[3]];case this.FLOAT_MAT2:return new Float32Array(t.slice(0,4));case this.FLOAT_MAT3:return new Float32Array(t.slice(0,9));case this.FLOAT_MAT4:return new Float32Array(t.slice(0,16));case this.SAMPLER_2D:case this.SAMPLER_CUBE:return t[0]|0;default:return null}}return null},getUniformLocation(n,i){if(!t(n))throw TypeError(`getUniformLocation(WebGLProgram, String)`);if(i+=``,!r(i))return this.setError(this.INVALID_VALUE),null;if(this._checkWrapper(n,o)){let t=this._gl.getUniformLocation(n._|0,i);if(t!==null&&t>=0){let r=i;/\[\d+\]$/.test(i)&&(r=i.replace(/\[\d+\]$/,`[0]`));let a=r+`[0]`,o=null;for(let e=0;e<n._uniforms.length;++e){let t=n._uniforms[e];if(t.name===r||t.name===a){o={size:t.size,type:t.type,name:t.name};break}}o||={name:r,type:0,size:1};let s=new e(t,n,o),c=i.match(/\[(\d+)\]$/),l=c?+c[1]:-1;if(/\[0\]$/.test(o.name)&&(l===-1||l===0)){let e=o.name.replace(/\[0\]$/,``),t=[];this._saveError();for(let r=0;this.getError()===this.NO_ERROR;++r){let i=this._gl.getUniformLocation(n._|0,e+`[`+r+`]`);if(this.getError()!==this.NO_ERROR||i==null||i<0)break;t.push(i)}this._restoreError(this.NO_ERROR),s._array=t}else if(l>0&&l>=o.size)return null;return s}}return null},getProgramInfoLog(e){if(!t(e))throw TypeError(`getProgramInfoLog(WebGLProgram)`);return this._checkWrapper(e,o)?e._linkInfoLog:null},getProgramParameter(e,n=0){if(!t(e))throw TypeError(`getProgramParameter(WebGLProgram, GLenum)`);if(this._checkWrapper(e,o)){switch(n){case this.DELETE_STATUS:return e._pendingDelete;case this.LINK_STATUS:return e._linkStatus;case this.VALIDATE_STATUS:return!!this._gl.getProgramParameter(e._,n);case this.ATTACHED_SHADERS:return this._gl.getProgramParameter(e._,n);case this.ACTIVE_ATTRIBUTES:return e._linkStatus?e._attributes.length:this._gl.getProgramParameter(e._,n);case this.ACTIVE_UNIFORMS:return e._linkStatus?e._uniforms.length:this._gl.getProgramParameter(e._,n)}this.setError(this.INVALID_ENUM)}return null},uniform1f(e,t){this._checkUniformValid(e,t,`uniform1f`,1,`f`)&&this._gl.uniform1f(e?._||0,t)},uniform1i(e,t){this._gl.uniform1i(e?._||0,t)},uniform2f(e,t,n){this._checkUniformValid(e,t,`uniform2f`,2,`f`)&&this._gl.uniform2f(e?._||0,t,n)},uniform2i(e,t,n){this._checkUniformValid(e,t,`uniform2i`,2,`i`)&&this._gl.uniform2i(e?._||0,t,n)},uniform3f(e,t,n,r){this._checkUniformValid(e,t,`uniform3f`,3,`f`)&&this._gl.uniform3f(e?._||0,t,n,r)},uniform3i(e,t,n,r){this._checkUniformValid(e,t,`uniform3i`,3,`i`)&&this._gl.uniform3i(e?._||0,t,n,r)},uniform4f(e,t,n,r,i){if(!this._checkUniformValid(e,t,`uniform4f`,4,`f`)){console.error(`uniform4f is not valid!`);return}this._gl.uniform4f(e?._||0,t,n,r,i)},uniform4i(e,t,n,r,i){this._checkUniformValid(e,t,`uniform4i`,4,`i`)&&this._gl.uniform4i(e?._||0,t,n,r,i)},uniform1fv(e,t){if(!(!e||!this._checkUniformValueValid(e,t,`uniform1fv`,1,`f`))){if(e?._array){let n=e._array;for(let e=0;e<n.length&&e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform1f(r,t[e])}return}this._gl.uniform1f(e?._|0,t[0])}},uniform1iv(e,t){if(this._checkUniformValueValid(e,t,`uniform1iv`,1,`i`)){if(e?._array){let n=e._array;for(let e=0;e<n.length&&e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform1i(r,t[e])}return}this.uniform1i(e,t[0])}},uniform2fv(e,t){if(this._checkUniformValueValid(e,t,`uniform2fv`,2,`f`)){if(e?._array){let n=e._array;for(let e=0;e<n.length&&2*e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform2f(r,t[2*e],t[2*e+1])}return}this._gl.uniform2f(e?._||0,t[0],t[1])}},uniform2iv(e,t){if(this._checkUniformValueValid(e,t,`uniform2iv`,2,`i`)){if(e?._array){let n=e._array;for(let e=0;e<n.length&&2*e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform2i(r,t[2*e],t[2*e+1])}return}this.uniform2i(e,t[0],t[1])}},uniform3fv(e,t){if(this._checkUniformValueValid(e,t,`uniform3fv`,3,`f`)){if(e?._array){let n=e._array;for(let e=0;e<n.length&&3*e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform3f(r,t[3*e],t[3*e+1],t[3*e+2])}return}this._gl.uniform3f(e?._||0,t[0],t[1],t[2])}},uniform3iv(e,t){if(this._checkUniformValueValid(e,t,`uniform3iv`,3,`i`)){if(e?._array){let n=e._array;for(let e=0;e<n.length&&3*e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform3i(r,t[3*e],t[3*e+1],t[3*e+2])}return}this.uniform3i(e,t[0],t[1],t[2])}},uniform4fv(e,t){if(this._checkUniformValueValid(e,t,`uniform4fv`,4,`f`)){if(e?._array){let n=e._array;for(let e=0;e<n.length&&4*e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform4f(r,t[4*e],t[4*e+1],t[4*e+2],t[4*e+3])}return}this._gl.uniform4f(e?._||0,t[0],t[1],t[2],t[3])}},uniform4iv(e,t){if(this._checkUniformValueValid(e,t,`uniform4iv`,4,`i`)){if(e?._array){let n=e._array;for(let e=0;e<n.length&&4*e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform4i(r,t[4*e],t[4*e+1],t[4*e+2],t[4*e+3])}return}this.uniform4i(e,t[0],t[1],t[2],t[3])}},uniformMatrix2fv(e,t,n){if(!this._checkUniformMatrix(e,t,n,`uniformMatrix2fv`,2))return;let r=new Float32Array(n);this._gl.uniformMatrix2fv(e?._||0,!!t,i(r))},uniformMatrix3fv(e,t,n){if(!this._checkUniformMatrix(e,t,n,`uniformMatrix3fv`,3))return;let r=new Float32Array(n);this._gl.uniformMatrix3fv(e?._||0,!!t,i(r))},uniformMatrix4fv(e,t,n){if(!this._checkUniformMatrix(e,t,n,`uniformMatrix4fv`,4))return;let r=new Float32Array(n);this._gl.uniformMatrix4fv(e?._||0,!!t,i(r))},_checkLocation(t){return t instanceof e?t._program._ctx!==this||t._linkCount!==t._program._linkCount?(this.setError(this.INVALID_OPERATION),!1):!0:(this.setError(this.INVALID_VALUE),!1)},_checkLocationActive(e){return e&&this._checkLocation(e)?e._program===this._activeProgram?!0:(this.setError(this.INVALID_OPERATION),!1):!1},_checkUniformValid(e,n,r,i,o){if(!t(e))throw TypeError(`${r}(WebGLUniformLocation, ...)`);if(!e)return!1;if(this._checkLocationActive(e)){let t=e._activeInfo.type;if(t===this.SAMPLER_2D||t===this.SAMPLER_CUBE){if(i!==1)return this.setError(this.INVALID_VALUE),!1;if(o!==`i`)return this.setError(this.INVALID_OPERATION),!1;if(n<0||n>=this._textureUnits.length)return this.setError(this.INVALID_VALUE),!1}return a(this,t)>i?(this.setError(this.INVALID_OPERATION),!1):!0}return!1},_checkUniformValueValid(e,n,r,i,o){if(!t(e)||!t(n))throw TypeError(`${r}v(WebGLUniformLocation, Array)`);if(!e||!this._checkLocationActive(e))return!1;if(typeof n!=`object`||!n||typeof n.length!=`number`)throw TypeError(`Second argument to ${r} must be array`);return a(this,e._activeInfo.type)>i?(this.setError(this.INVALID_OPERATION),!1):n.length>=i&&n.length%i===0?e._array||n.length===i?!0:(this.setError(this.INVALID_OPERATION),!1):(this.setError(this.INVALID_VALUE),!1)},_checkUniformMatrix(e,n,r,i,a){if(!t(e)||typeof r!=`object`)throw TypeError(i+`(WebGLUniformLocation, Boolean, Array)`);return n||typeof r!=`object`||!r||!r.length||r.length%a*a!==0?(this.setError(this.INVALID_VALUE),!1):!e||!this._checkLocationActive(e)?!1:r.length===a*a||e._array?!0:(this.setError(this.INVALID_VALUE),!1)},_checkShaderSource(e){let t=e._source,n=u(t),r=!1,i=[];for(let e=0;e<n.length;++e){let t=n[e];if(t)switch(t.type){case`ident`:this._validGLSLIdentifier(t.data)||(r=!0,i.push(t.line+`:`+t.column+` invalid identifier - `+t.data));break;case`preprocessor`:{let e=t.data.match(/^\s*#\s*(.*)$/);if(!e||e?.length<2)break;let n=u(e[1]);for(let e=0;e<n.length;++e){let a=n[e];(a.type===`ident`||a.type===void 0)&&(this._validGLSLIdentifier(a.data)||(r=!0,i.push(t.line+`:`+a.column+` invalid identifier - `+a.data)))}break}case`keyword`:switch(t.data){case`do`:r=!0,i.push(t.line+`:`+t.column+` do not supported`);break}break;case`builtin`:switch(t.data){case`dFdx`:case`dFdy`:case`fwidth`:!this._extensions.oes_standard_derivatives&&this._getGlslVersion(!0)===`100`&&(r=!0,i.push(t.line+`:`+t.column+` `+t.data+` not supported`));break}}}return r&&(e._compileInfo=i.join(`
2
+ `)),!r},_wrapShader(e,t){let n=t.startsWith(`#version`)||t.includes(`
3
+ #version`),r=``;if(!this._extensions.oes_standard_derivatives&&/#ifdef\s+GL_OES_standard_derivatives/.test(t)&&(r+=`#undef GL_OES_standard_derivatives
4
+ `),!this._extensions.webgl_draw_buffers&&!n&&(r+=`#define gl_MaxDrawBuffers 1
5
+ `),n){if(r){let e=t.indexOf(`
6
+ `);t=e===-1?t+`
7
+ `+r:t.slice(0,e+1)+r+t.slice(e+1)}}else if(this.canvas){let e=this.canvas.getGlArea().get_use_es(),n=/\b(attribute|varying)\b/.test(t)?e?`100`:`120`:this._getGlslVersion(e);n?t=`#version `+n+`
8
+ `+r+t:r&&(t=r+t)}else r&&(t=r+t);return t},_switchActiveProgram(e){e&&(--e._refCount,e._checkDelete())},_fixupLink(e){if(!this._gl.getProgramParameter(e._,this.LINK_STATUS))return e._linkInfoLog=this._gl.getProgramInfoLog(e._),!1;let t=this.getProgramParameter(e,this.ACTIVE_ATTRIBUTES),n=Array(t);e._attributes.length=t;for(let r=0;r<t;++r)n[r]=this.getActiveAttrib(e,r)?.name,e._attributes[r]=this.getAttribLocation(e,n[r])|0;for(let t=0;t<n.length;++t)if(n[t].length>256)return e._linkInfoLog=`attribute `+n[t]+` is too long`,!1;for(let r=0;r<t;++r)e._attributes[r]<0||this._gl.bindAttribLocation(e._|0,e._attributes[r],n[r]);if(this._gl.linkProgram(e._|0),!this._gl.getProgramParameter(e._|0,this.LINK_STATUS))return e._linkInfoLog=this._gl.getProgramInfoLog(e._),!1;let r=this.getProgramParameter(e,this.ACTIVE_UNIFORMS);e._uniforms.length=r;for(let t=0;t<r;++t){let n=this.getActiveUniform(e,t);n&&(e._uniforms[t]=n)}for(let t=0;t<e._uniforms.length;++t)if(e._uniforms[t].name.length>256)return e._linkInfoLog=`uniform `+e._uniforms[t].name+` is too long`,!1;return e._linkInfoLog=``,!0},_deleteLinkable(e,n,r){if(!t(n))throw TypeError(e+`(`+r.name+`)`);if(n instanceof r&&this._checkOwns(n)){n._pendingDelete=!0,n._checkDelete();return}this.setError(this.INVALID_OPERATION)}};function installShaderProgramMethods(e){Object.assign(e,d)}export{installShaderProgramMethods};
@@ -0,0 +1 @@
1
+ import"../_virtual/_rolldown/runtime.js";import{WebGLBuffer as e}from"../webgl-buffer.js";import{WebGLFramebuffer as t}from"../webgl-framebuffer.js";import{WebGLProgram as n}from"../webgl-program.js";import{WebGLRenderbuffer as r}from"../webgl-renderbuffer.js";import{WebGLShader as i}from"../webgl-shader.js";import{WebGLTexture as a}from"../webgl-texture.js";const o={enable(e=0){this._gl.enable(e)},disable(e=0){if(this._gl.disable(e),e===this.TEXTURE_2D||e===this.TEXTURE_CUBE_MAP){let t=this._getActiveTextureUnit();t._mode===e&&(t._mode=0)}},cullFace(e){this._gl.cullFace(e|0)},depthFunc(e){switch(e|=0,e){case this.NEVER:case this.LESS:case this.EQUAL:case this.LEQUAL:case this.GREATER:case this.NOTEQUAL:case this.GEQUAL:case this.ALWAYS:this._gl.depthFunc(e);return;default:this.setError(this.INVALID_ENUM)}},depthMask(e){this._gl.depthMask(!!e)},depthRange(e,t){if(e=+e,t=+t,e<=t){this._gl.depthRange(e,t);return}this.setError(this.INVALID_OPERATION)},frontFace(e=0){this._gl.frontFace(e)},lineWidth(e){if(isNaN(e)){this.setError(this.INVALID_VALUE);return}this._gl.lineWidth(+e)},polygonOffset(e,t){this._gl.polygonOffset(+e,+t)},sampleCoverage(e,t){this._gl.sampleCoverage(+e,!!t)},hint(e=0,t=0){if(!(e===this.GENERATE_MIPMAP_HINT||this._extensions.oes_standard_derivatives&&e===this._extensions.oes_standard_derivatives.FRAGMENT_SHADER_DERIVATIVE_HINT_OES)){this.setError(this.INVALID_ENUM);return}if(t!==this.FASTEST&&t!==this.NICEST&&t!==this.DONT_CARE){this.setError(this.INVALID_ENUM);return}this._gl.hint(e,t)},finish(){this._gl.finish()},flush(){this._gl.flush()},blendColor(e=0,t=0,n=0,r=0){this._gl.blendColor(+e,+t,+n,+r)},blendEquation(e=0){if(this._validBlendMode(e)){this._gl.blendEquation(e);return}this.setError(this.INVALID_ENUM)},blendEquationSeparate(e=0,t=0){if(this._validBlendMode(e)&&this._validBlendMode(t)){this._gl.blendEquationSeparate(e,t);return}this.setError(this.INVALID_ENUM)},blendFunc(e=0,t=0){if(!this._validBlendFunc(e)||!this._validBlendFunc(t)){this.setError(this.INVALID_ENUM);return}if(this._isConstantBlendFunc(e)&&this._isConstantBlendFunc(t)){this.setError(this.INVALID_OPERATION);return}this._gl.blendFunc(e,t)},blendFuncSeparate(e=0,t=0,n=0,r=0){if(!(this._validBlendFunc(e)&&this._validBlendFunc(t)&&this._validBlendFunc(n)&&this._validBlendFunc(r))){this.setError(this.INVALID_ENUM);return}if(this._isConstantBlendFunc(e)&&this._isConstantBlendFunc(t)||this._isConstantBlendFunc(n)&&this._isConstantBlendFunc(r)){this.setError(this.INVALID_OPERATION);return}this._gl.blendFuncSeparate(e,t,n,r)},clear(e=0){this._framebufferOk()&&this._gl.clear(e)},clearColor(e,t,n,r){this._gl.clearColor(+e,+t,+n,+r)},clearDepth(e){this._gl.clearDepth(+e)},clearStencil(e=0){this._checkStencil=!1,this._gl.clearStencil(e)},colorMask(e,t,n,r){this._gl.colorMask(!!e,!!t,!!n,!!r)},stencilFunc(e,t,n){this._checkStencil=!0,this._gl.stencilFunc(e|0,t|0,n|0)},stencilFuncSeparate(e,t,n,r){this._checkStencil=!0,this._gl.stencilFuncSeparate(e|0,t|0,n|0,r|0)},stencilMask(e){this._checkStencil=!0,this._gl.stencilMask(e>>>0)},stencilMaskSeparate(e,t){this._checkStencil=!0,this._gl.stencilMaskSeparate(e|0,t>>>0)},stencilOp(e,t,n){this._checkStencil=!0,this._gl.stencilOp(e|0,t|0,n|0)},stencilOpSeparate(e,t,n,r){this._checkStencil=!0,this._gl.stencilOpSeparate(e|0,t|0,n|0,r|0)},isEnabled(e=0){return this._gl.isEnabled(e)},isContextLost(){return!1},getError(){return this._gl.getError()},setError(e){this._gl.setError(e)},isBuffer(t){return this._isObject(t,`isBuffer`,e)?this._gl.isBuffer(t?._):!1},isFramebuffer(e){return this._isObject(e,`isFramebuffer`,t)?this._gl.isFramebuffer(e?._):!1},isProgram(e){return this._isObject(e,`isProgram`,n)?this._gl.isProgram(e?._):!1},isRenderbuffer(e){return this._isObject(e,`isRenderbuffer`,r)?this._gl.isRenderbuffer(e?._):!1},isShader(e){return this._isObject(e,`isShader`,i)?this._gl.isShader(e?._):!1},isTexture(e){return this._isObject(e,`isTexture`,a)?this._gl.isTexture(e?._):!1},generateMipmap(e=0){this._gl.generateMipmap(e)},_validBlendFunc(e){return e===this.ZERO||e===this.ONE||e===this.SRC_COLOR||e===this.ONE_MINUS_SRC_COLOR||e===this.DST_COLOR||e===this.ONE_MINUS_DST_COLOR||e===this.SRC_ALPHA||e===this.ONE_MINUS_SRC_ALPHA||e===this.DST_ALPHA||e===this.ONE_MINUS_DST_ALPHA||e===this.SRC_ALPHA_SATURATE||e===this.CONSTANT_COLOR||e===this.ONE_MINUS_CONSTANT_COLOR||e===this.CONSTANT_ALPHA||e===this.ONE_MINUS_CONSTANT_ALPHA},_validBlendMode(e){return e===this.FUNC_ADD||e===this.FUNC_SUBTRACT||e===this.FUNC_REVERSE_SUBTRACT||this._extensions.ext_blend_minmax&&(e===this._extensions.ext_blend_minmax.MIN_EXT||e===this._extensions.ext_blend_minmax.MAX_EXT)},_isConstantBlendFunc(e){return e===this.CONSTANT_COLOR||e===this.ONE_MINUS_CONSTANT_COLOR||e===this.CONSTANT_ALPHA||e===this.ONE_MINUS_CONSTANT_ALPHA},_saveError(){this._errorStack.push(this.getError())},_restoreError(e){let t=this._errorStack.pop();t===this.NO_ERROR?this.setError(e):t!==void 0&&this.setError(t)}};function installStateMethods(e){Object.assign(e,o)}export{installStateMethods};
@@ -0,0 +1 @@
1
+ import"../_virtual/_rolldown/runtime.js";import{Uint8ArrayToVariant as e,arrayToUint8Array as t,checkFormat as n,checkObject as r,convertPixels as i,extractImageData as a,formatSize as o,premultiplyAlpha as s,validCubeTarget as c}from"../utils.js";import{WebGLTexture as l}from"../webgl-texture.js";import*as u from"bit-twiddle";import d from"gi://GdkPixbuf?version=2.0";const f={activeTexture(e=0){let t=e-this.TEXTURE0;if(t>=0&&t<this._textureUnits.length){this._activeTextureUnit=t,this._gl.activeTexture(e);return}this.setError(this.INVALID_ENUM)},bindTexture(e=0,t){if(!r(t))throw TypeError(`bindTexture(GLenum, WebGLTexture)`);if(!this._validTextureTarget(e)){this.setError(this.INVALID_ENUM);return}let n=0;if(!t)t=null;else if(t instanceof l&&t._pendingDelete)return;else if(this._checkWrapper(t,l)){if(t._binding&&t._binding!==e){this.setError(this.INVALID_OPERATION);return}t._binding=e,t._complete&&(n=t._|0)}else return;this._saveError(),this._gl.bindTexture(e,n);let i=this.getError();if(this._restoreError(i),i!==this.NO_ERROR)return;let a=this._getActiveTextureUnit(),o=this._getActiveTexture(e);o!==t&&(o&&(--o._refCount,o._checkDelete()),t&&(t._refCount+=1)),e===this.TEXTURE_2D?a._bind2D=t:e===this.TEXTURE_CUBE_MAP&&(a._bindCube=t)},createTexture(){let e=this._gl.createTexture();if(e<=0)return null;let t=new l(e,this);return this._textures[e]=t,t},deleteTexture(e){if(!r(e))throw TypeError(`deleteTexture(WebGLTexture)`);if(e instanceof l){if(!this._checkOwns(e)){this.setError(this.INVALID_OPERATION);return}}else return;let t=this._activeTextureUnit;for(let t=0;t<this._textureUnits.length;++t){let n=this._textureUnits[t];n._bind2D===e?(this.activeTexture(this.TEXTURE0+t),this.bindTexture(this.TEXTURE_2D,null)):n._bindCube===e&&(this.activeTexture(this.TEXTURE0+t),this.bindTexture(this.TEXTURE_CUBE_MAP,null))}this.activeTexture(this.TEXTURE0+t);let n=this,i=this._activeFramebuffer,tryDetach=t=>{if(t&&t._linked(e)){let r=n._getAttachments();for(let i=0;i<r.length;++i){let a=r[i];t._attachments[a]===e&&n.framebufferTexture2D(n.FRAMEBUFFER,a,n.TEXTURE_2D,null)}}};tryDetach(i),e._pendingDelete=!0,e._checkDelete()},pixelStorei(e=0,t=0){if(typeof t==`boolean`&&(t=t===!1?0:1),e===this.UNPACK_ALIGNMENT)if(t===1||t===2||t===4||t===8)this._unpackAlignment=t;else{this.setError(this.INVALID_VALUE);return}else if(e===this.PACK_ALIGNMENT)if(t===1||t===2||t===4||t===8)this._packAlignment=t;else{this.setError(this.INVALID_VALUE);return}else if(e===this.UNPACK_COLORSPACE_CONVERSION_WEBGL){if(!(t===this.NONE||t===this.BROWSER_DEFAULT_WEBGL)){this.setError(this.INVALID_VALUE);return}}else if(e===this.UNPACK_FLIP_Y_WEBGL){this._unpackFlipY=!!t;return}else if(e===this.UNPACK_PREMULTIPLY_ALPHA_WEBGL){this._unpackPremultAlpha=!!t;return}this._gl.pixelStorei(e,t)},texImage2D(t=0,r=0,o=0,l=0,u=0,f=0,p=0,m=0,h){let g=0,_=0,v=0,y,b,x=0;if(arguments.length===6)if(m=u,v=l,f instanceof d.Pixbuf)b=f,g=b.get_width(),_=b.get_height(),h=b.get_pixels();else{y=f;let e=a(y);if(e==null)throw TypeError(`texImage2D(GLenum, GLint, GLenum, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)`);g=e.width,_=e.height,h=e.data}else arguments.length===9&&(g=l,_=u,x=f,v=p,m=m,h=h);if(typeof h!=`object`&&h!==void 0)throw TypeError(`texImage2D(GLenum, GLint, GLenum, GLint, GLint, GLint, GLenum, GLenum, Uint8Array)`);if(!n(this,v)||!n(this,o)){this.setError(this.INVALID_ENUM);return}if(m===this.FLOAT&&!this._extensions.oes_texture_float){this.setError(this.INVALID_ENUM);return}let S=this._getTexImage(t);if(!S||v!==o){this.setError(this.INVALID_OPERATION);return}let C=this._computePixelSize(m,v);if(C===0||!this._checkDimensions(t,g,_,r))return;let w=i(h),T=this._computeRowStride(g,C),E=T*_;if(w&&w.length<E){this.setError(this.INVALID_OPERATION);return}if(x!==0||c(this,t)&&g!==_){this.setError(this.INVALID_VALUE);return}if(this._unpackPremultAlpha&&w&&v===this.RGBA&&(w=s(w)),this._unpackFlipY&&w&&g>0&&_>0){let e=new Uint8Array(w.length);for(let t=0;t<_;t++){let n=t*T,r=(_-1-t)*T;e.set(w.subarray(n,n+T),r)}w=e}this._saveError(),this._gl.texImage2D(t,r,o,g,_,x,v,m,e(w));let D=this.getError();if(this._restoreError(D),D!==this.NO_ERROR)return;S._levelWidth[r]=g,S._levelHeight[r]=_,S._format=v,S._type=m;let O=this._activeFramebuffer;if(O){let e=!1,t=this._getAttachments();for(let n=0;n<t.length;++n)if(O._attachments[t[n]]===S){e=!0;break}e&&this._activeFramebuffer&&this._updateFramebufferAttachments(this._activeFramebuffer)}},texSubImage2D(t=0,n=0,r=0,o=0,c=0,l=0,u=0,f=0,p){let m=0,h=0,g=0,_,v;if(arguments.length===7)if(f=l,g=c,u instanceof d.Pixbuf)v=u,m=v.get_width(),h=v.get_height(),p=v.get_pixels();else{_=u;let e=a(_);if(e==null)throw TypeError(`texSubImage2D(GLenum, GLint, GLint, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)`);m=e.width,h=e.height,p=e.data}else m=c,h=l,g=u;if(typeof p!=`object`)throw TypeError(`texSubImage2D(GLenum, GLint, GLint, GLint, GLint, GLint, GLenum, GLenum, Uint8Array)`);if(!this._getTexImage(t)){this.setError(this.INVALID_OPERATION);return}if(f===this.FLOAT&&!this._extensions.oes_texture_float){this.setError(this.INVALID_ENUM);return}let y=this._computePixelSize(f,g);if(y===0||!this._checkDimensions(t,m,h,n))return;if(r<0||o<0){this.setError(this.INVALID_VALUE);return}let b=i(p),x=this._computeRowStride(m,y),S=x*h;if(!b||b.length<S){this.setError(this.INVALID_OPERATION);return}if(this._unpackPremultAlpha&&b&&g===this.RGBA&&(b=s(b)),this._unpackFlipY&&b&&m>0&&h>0){let e=new Uint8Array(b.length);for(let t=0;t<h;t++){let n=t*x,r=(h-1-t)*x;e.set(b.subarray(n,n+x),r)}b=e}this._gl.texSubImage2D(t,n,r,o,m,h,g,f,e(b))},copyTexImage2D(e=0,t=0,n=0,r=0,i=0,a=0,o=0,s=0){let c=this._getTexImage(e);if(!c){this.setError(this.INVALID_OPERATION);return}if(n!==this.RGBA&&n!==this.RGB&&n!==this.ALPHA&&n!==this.LUMINANCE&&n!==this.LUMINANCE_ALPHA){this.setError(this.INVALID_ENUM);return}if(t<0||a<0||o<0||s!==0){this.setError(this.INVALID_VALUE);return}if(t>0&&!(u.isPow2(a)&&u.isPow2(o))){this.setError(this.INVALID_VALUE);return}this._saveError(),this._gl.copyTexImage2D(e,t,n,r,i,a,o,s);let l=this.getError();this._restoreError(l),l===this.NO_ERROR&&(c._levelWidth[t]=a,c._levelHeight[t]=o,c._format=this.RGBA,c._type=this.UNSIGNED_BYTE)},copyTexSubImage2D(e=0,t=0,n=0,r=0,i=0,a=0,o=0,s=0){if(!this._getTexImage(e)){this.setError(this.INVALID_OPERATION);return}if(o<0||s<0||n<0||r<0||t<0){this.setError(this.INVALID_VALUE);return}this._gl.copyTexSubImage2D(e,t,n,r,i,a,o,s)},compressedTexImage2D(n,r,i,a,o,s,c){this._gl.compressedTexImage2D(n,r,i,a,o,s,e(t(c)))},compressedTexSubImage2D(n,r,i,a,o,s,c,l){this._gl.compressedTexSubImage2D(n,r,i,a,o,s,c,e(t(l)))},texParameterf(e=0,t=0,n){if(n=+n,this._checkTextureTarget(e)){switch(this._verifyTextureCompleteness(e,t,n),t){case this.TEXTURE_MIN_FILTER:case this.TEXTURE_MAG_FILTER:case this.TEXTURE_WRAP_S:case this.TEXTURE_WRAP_T:this._gl.texParameterf(e,t,n);return}if(this._extensions.ext_texture_filter_anisotropic&&t===this._extensions.ext_texture_filter_anisotropic.TEXTURE_MAX_ANISOTROPY_EXT){this._gl.texParameterf(e,t,n);return}this.setError(this.INVALID_ENUM)}},texParameteri(e=0,t=0,n=0){if(this._checkTextureTarget(e)){switch(this._verifyTextureCompleteness(e,t,n),t){case this.TEXTURE_MIN_FILTER:case this.TEXTURE_MAG_FILTER:case this.TEXTURE_WRAP_S:case this.TEXTURE_WRAP_T:this._gl.texParameteri(e,t,n);return}if(this._extensions.ext_texture_filter_anisotropic&&t===this._extensions.ext_texture_filter_anisotropic.TEXTURE_MAX_ANISOTROPY_EXT){this._gl.texParameteri(e,t,n);return}this.setError(this.INVALID_ENUM)}},getTexParameter(e=0,t=0){if(!this._checkTextureTarget(e))return null;let n=this._getActiveTextureUnit();if(e===this.TEXTURE_2D&&!n._bind2D||e===this.TEXTURE_CUBE_MAP&&!n._bindCube)return this.setError(this.INVALID_OPERATION),null;switch(t){case this.TEXTURE_MAG_FILTER:case this.TEXTURE_MIN_FILTER:case this.TEXTURE_WRAP_S:case this.TEXTURE_WRAP_T:return this._getTexParameterDirect(e,t)}return this._extensions.ext_texture_filter_anisotropic&&t===this._extensions.ext_texture_filter_anisotropic.TEXTURE_MAX_ANISOTROPY_EXT?this._getTexParameterDirect(e,t):(this.setError(this.INVALID_ENUM),null)},_getTexParameterDirect(e=0,t=0){return this._gl.getTexParameterx(e,t)?.unpack()},_getActiveTextureUnit(){return this._textureUnits[this._activeTextureUnit]},_getActiveTexture(e){let t=this._getActiveTextureUnit();return e===this.TEXTURE_2D?t._bind2D:e===this.TEXTURE_CUBE_MAP?t._bindCube:null},_getTexImage(e){let t=this._getActiveTextureUnit();return e===this.TEXTURE_2D?t._bind2D:c(this,e)?t._bindCube:(this.setError(this.INVALID_ENUM),null)},_checkTextureTarget(e){let t=this._getActiveTextureUnit(),n=null;if(e===this.TEXTURE_2D)n=t._bind2D;else if(e===this.TEXTURE_CUBE_MAP)n=t._bindCube;else return this.setError(this.INVALID_ENUM),!1;return n?!0:(this.setError(this.INVALID_OPERATION),!1)},_validTextureTarget(e){return e===this.TEXTURE_2D||e===this.TEXTURE_CUBE_MAP},_validCubeTarget(e){return e===this.TEXTURE_CUBE_MAP_POSITIVE_X||e===this.TEXTURE_CUBE_MAP_NEGATIVE_X||e===this.TEXTURE_CUBE_MAP_POSITIVE_Y||e===this.TEXTURE_CUBE_MAP_NEGATIVE_Y||e===this.TEXTURE_CUBE_MAP_POSITIVE_Z||e===this.TEXTURE_CUBE_MAP_NEGATIVE_Z},_verifyTextureCompleteness(e,t,n){let r=this._getActiveTextureUnit(),i=null;if(e===this.TEXTURE_2D?i=r._bind2D:this._validCubeTarget(e)&&(i=r._bindCube),this._extensions.oes_texture_float&&!this._extensions.oes_texture_float_linear&&i&&i._type===this.FLOAT&&(t===this.TEXTURE_MAG_FILTER||t===this.TEXTURE_MIN_FILTER)&&(n===this.LINEAR||n===this.LINEAR_MIPMAP_NEAREST||n===this.NEAREST_MIPMAP_LINEAR||n===this.LINEAR_MIPMAP_LINEAR)){i._complete=!1,this.bindTexture(e,i);return}i&&i._complete===!1&&(i._complete=!0,this.bindTexture(e,i))},_computePixelSize(e,t){let n=o(this,t);if(n===0)return this.setError(this.INVALID_ENUM),0;switch(e){case this.UNSIGNED_BYTE:return n;case this.UNSIGNED_SHORT_5_6_5:if(t!==this.RGB){this.setError(this.INVALID_OPERATION);break}return 2;case this.UNSIGNED_SHORT_4_4_4_4:case this.UNSIGNED_SHORT_5_5_5_1:if(t!==this.RGBA){this.setError(this.INVALID_OPERATION);break}return 2;case this.FLOAT:return 1}return this.setError(this.INVALID_ENUM),0},_computeRowStride(e,t){let n=e*t;return n%this._unpackAlignment&&(n+=this._unpackAlignment-n%this._unpackAlignment),n},_checkDimensions(e,t,n,r){if(r<0||t<0||n<0)return this.setError(this.INVALID_VALUE),!1;if(e===this.TEXTURE_2D){if(t>this._maxTextureSize||n>this._maxTextureSize||r>this._maxTextureLevel)return this.setError(this.INVALID_VALUE),!1}else if(this._validCubeTarget(e)){if(t>this._maxCubeMapSize||n>this._maxCubeMapSize||r>this._maxCubeMapLevel)return this.setError(this.INVALID_VALUE),!1}else return this.setError(this.INVALID_ENUM),!1;return!0}};function installTextureManagementMethods(e){Object.assign(e,f)}export{installTextureManagementMethods};
@@ -1 +1 @@
1
- var e=class{constructor(){this.MIN_EXT=32775,this.MAX_EXT=32776}};function t(t){let n=null,r=t.getSupportedExtensions();return r&&r.indexOf(`EXT_blend_minmax`)>=0&&(n=new e),n}export{e as EXTBlendMinMax,t as getEXTBlendMinMax};
1
+ import"../_virtual/_rolldown/runtime.js";var EXTBlendMinMax=class{constructor(){this.MIN_EXT=32775,this.MAX_EXT=32776}};function getEXTBlendMinMax(e){let t=null,n=e.getSupportedExtensions();return n&&n.indexOf(`EXT_blend_minmax`)>=0&&(t=new EXTBlendMinMax),t}export{EXTBlendMinMax,getEXTBlendMinMax};
@@ -1 +1 @@
1
- var e=class{};function t(t){let n=t.getSupportedExtensions();return n&&n.indexOf(`EXT_color_buffer_float`)>=0?new e:null}export{e as EXTColorBufferFloat,t as getEXTColorBufferFloat};
1
+ import"../_virtual/_rolldown/runtime.js";var EXTColorBufferFloat=class{};function getEXTColorBufferFloat(e){let t=e.getSupportedExtensions();return t&&t.indexOf(`EXT_color_buffer_float`)>=0?new EXTColorBufferFloat:null}export{EXTColorBufferFloat,getEXTColorBufferFloat};
@@ -1 +1 @@
1
- var e=class{};function t(t){let n=t.getSupportedExtensions();return n&&n.indexOf(`EXT_color_buffer_half_float`)>=0?new e:null}export{e as EXTColorBufferHalfFloat,t as getEXTColorBufferHalfFloat};
1
+ import"../_virtual/_rolldown/runtime.js";var EXTColorBufferHalfFloat=class{};function getEXTColorBufferHalfFloat(e){let t=e.getSupportedExtensions();return t&&t.indexOf(`EXT_color_buffer_half_float`)>=0?new EXTColorBufferHalfFloat:null}export{EXTColorBufferHalfFloat,getEXTColorBufferHalfFloat};
@@ -1 +1 @@
1
- var e=class{constructor(){this.TEXTURE_MAX_ANISOTROPY_EXT=34046,this.MAX_TEXTURE_MAX_ANISOTROPY_EXT=34047}};function t(t){let n=null,r=t.getSupportedExtensions();return r&&r.indexOf(`EXT_texture_filter_anisotropic`)>=0&&(n=new e),n}export{e as EXTTextureFilterAnisotropic,t as getEXTTextureFilterAnisotropic};
1
+ import"../_virtual/_rolldown/runtime.js";var EXTTextureFilterAnisotropic=class{constructor(){this.TEXTURE_MAX_ANISOTROPY_EXT=34046,this.MAX_TEXTURE_MAX_ANISOTROPY_EXT=34047}};function getEXTTextureFilterAnisotropic(e){let t=null,n=e.getSupportedExtensions();return n&&n.indexOf(`EXT_texture_filter_anisotropic`)>=0&&(t=new EXTTextureFilterAnisotropic),t}export{EXTTextureFilterAnisotropic,getEXTTextureFilterAnisotropic};
@@ -1 +1 @@
1
- var e=class{};function t(t){let n=null,r=t.getSupportedExtensions();return r&&r.indexOf(`OES_element_index_uint`)>=0&&(n=new e),n}export{e as OESElementIndexUint,t as getOESElementIndexUint};
1
+ import"../_virtual/_rolldown/runtime.js";var OESElementIndexUint=class{};function getOESElementIndexUint(e){let t=null,n=e.getSupportedExtensions();return n&&n.indexOf(`OES_element_index_uint`)>=0&&(t=new OESElementIndexUint),t}export{OESElementIndexUint,getOESElementIndexUint};
@@ -1 +1 @@
1
- var e=class{constructor(){this.FRAGMENT_SHADER_DERIVATIVE_HINT_OES=35723}};function t(t){let n=null,r=t.getSupportedExtensions();return r&&r.indexOf(`OES_standard_derivatives`)>=0&&(n=new e),n}export{e as OESStandardDerivatives,t as getOESStandardDerivatives};
1
+ import"../_virtual/_rolldown/runtime.js";var OESStandardDerivatives=class{constructor(){this.FRAGMENT_SHADER_DERIVATIVE_HINT_OES=35723}};function getOESStandardDerivatives(e){let t=null,n=e.getSupportedExtensions();return n&&n.indexOf(`OES_standard_derivatives`)>=0&&(t=new OESStandardDerivatives),t}export{OESStandardDerivatives,getOESStandardDerivatives};
@@ -1 +1 @@
1
- var e=class{};function t(t){let n=null,r=t.getSupportedExtensions();return r&&r.indexOf(`OES_texture_float_linear`)>=0&&(n=new e),n}export{e as OESTextureFloatLinear,t as getOESTextureFloatLinear};
1
+ import"../_virtual/_rolldown/runtime.js";var OESTextureFloatLinear=class{};function getOESTextureFloatLinear(e){let t=null,n=e.getSupportedExtensions();return n&&n.indexOf(`OES_texture_float_linear`)>=0&&(t=new OESTextureFloatLinear),t}export{OESTextureFloatLinear,getOESTextureFloatLinear};
@@ -1 +1 @@
1
- var e=class{};function t(t){let n=null,r=t.getSupportedExtensions();return r&&r.indexOf(`OES_texture_float`)>=0&&(n=new e),n}export{e as OESTextureFloat,t as getOESTextureFloat};
1
+ import"../_virtual/_rolldown/runtime.js";var OESTextureFloat=class{};function getOESTextureFloat(e){let t=null,n=e.getSupportedExtensions();return n&&n.indexOf(`OES_texture_float`)>=0&&(t=new OESTextureFloat),t}export{OESTextureFloat,getOESTextureFloat};
@@ -1 +1 @@
1
- var e=class{constructor(){this.HALF_FLOAT_OES=36193}};function t(t){let n=t.getSupportedExtensions();return n&&n.indexOf(`OES_texture_half_float`)>=0||t._native2?new e:null}export{e as OESTextureHalfFloat,t as getOESTextureHalfFloat};
1
+ import"../_virtual/_rolldown/runtime.js";var OESTextureHalfFloat=class{constructor(){this.HALF_FLOAT_OES=36193}};function getOESTextureHalfFloat(e){let t=e.getSupportedExtensions();return t&&t.indexOf(`OES_texture_half_float`)>=0||e._native2?new OESTextureHalfFloat:null}export{OESTextureHalfFloat,getOESTextureHalfFloat};
@@ -1 +1 @@
1
- var e=class{constructor(e){this.destroy=e.destroy.bind(e)}};function t(t){return new e(t)}export{e as STACKGLDestroyContext,t as getSTACKGLDestroyContext};
1
+ import"../_virtual/_rolldown/runtime.js";var STACKGLDestroyContext=class{constructor(e){this.destroy=e.destroy.bind(e)}};function getSTACKGLDestroyContext(e){return new STACKGLDestroyContext(e)}export{STACKGLDestroyContext,getSTACKGLDestroyContext};
@@ -1 +1 @@
1
- var e=class{constructor(e){this.resize=e.resize.bind(e)}};function t(t){return new e(t)}export{e as STACKGLResizeDrawingBuffer,t as getSTACKGLResizeDrawingBuffer};
1
+ import"../_virtual/_rolldown/runtime.js";var STACKGLResizeDrawingBuffer=class{constructor(e){this.resize=e.resize.bind(e)}};function getSTACKGLResizeDrawingBuffer(e){return new STACKGLResizeDrawingBuffer(e)}export{STACKGLResizeDrawingBuffer,getSTACKGLResizeDrawingBuffer};
@@ -1 +1 @@
1
- import{WebGLRenderingContext as e}from"./webgl-rendering-context.js";import{WebGL2RenderingContext as t}from"./webgl2-rendering-context.js";import{HTMLCanvasElement as n}from"@gjsify/dom-elements";var r=class extends n{constructor(e){super(),this.gtkGlArea=e}get width(){return this.gtkGlArea.get_allocated_width()}set width(e){}get height(){return this.gtkGlArea.get_allocated_height()}set height(e){}get clientWidth(){return this.width}get clientHeight(){return this.height}get offsetWidth(){return this.width}get offsetHeight(){return this.height}getGlArea(){return this.gtkGlArea}getContext(n,r){return n===`webgl`||n===`experimental-webgl`?(this._webgl||=(this.gtkGlArea.make_current(),new e(this,r)),this._webgl):n===`webgl2`?(this._webgl2||=(this.gtkGlArea.make_current(),new t(this,r)),this._webgl2):super.getContext(n,r)}};export{r as HTMLCanvasElement};
1
+ import"./_virtual/_rolldown/runtime.js";import{WebGLRenderingContext as e}from"./webgl-rendering-context.js";import{WebGL2RenderingContext as t}from"./webgl2-rendering-context.js";import{HTMLCanvasElement as n}from"@gjsify/dom-elements";var HTMLCanvasElement=class extends n{constructor(e){super(),this.gtkGlArea=e}get width(){return this.gtkGlArea.get_allocated_width()}set width(e){}get height(){return this.gtkGlArea.get_allocated_height()}set height(e){}get clientWidth(){return this.width}get clientHeight(){return this.height}get offsetWidth(){return this.width}get offsetHeight(){return this.height}getGlArea(){return this.gtkGlArea}getContext(n,r){return n===`webgl`||n===`experimental-webgl`?(this._webgl||=(this.gtkGlArea.make_current(),new e(this,r)),this._webgl):n===`webgl2`?(this._webgl2||=(this.gtkGlArea.make_current(),new t(this,r)),this._webgl2):super.getContext(n,r)}};export{HTMLCanvasElement};
package/lib/esm/index.js CHANGED
@@ -1 +1 @@
1
- import{WebGLContextAttributes as e}from"./webgl-context-attributes.js";import{WebGLUniformLocation as t}from"./webgl-uniform-location.js";import{WebGLActiveInfo as n}from"./webgl-active-info.js";import{WebGLFramebuffer as r}from"./webgl-framebuffer.js";import{WebGLBuffer as i}from"./webgl-buffer.js";import{WebGLDrawingBufferWrapper as a}from"./webgl-drawing-buffer-wrapper.js";import{WebGLProgram as o}from"./webgl-program.js";import{WebGLRenderbuffer as s}from"./webgl-renderbuffer.js";import{WebGLShader as c}from"./webgl-shader.js";import{WebGLShaderPrecisionFormat as l}from"./webgl-shader-precision-format.js";import{WebGLTextureUnit as u}from"./webgl-texture-unit.js";import{WebGLTexture as d}from"./webgl-texture.js";import{WebGLVertexArrayGlobalAttribute as f,WebGLVertexArrayGlobalState as p,WebGLVertexArrayObjectAttribute as m,WebGLVertexArrayObjectState as h}from"./webgl-vertex-attribute.js";import{WebGLContextBase as g}from"./webgl-context-base.js";import{WebGLRenderingContext as _}from"./webgl-rendering-context.js";import{WebGLQuery as v}from"./webgl-query.js";import{WebGLSampler as y}from"./webgl-sampler.js";import{WebGLSync as b}from"./webgl-sync.js";import{WebGLTransformFeedback as x}from"./webgl-transform-feedback.js";import{WebGLVertexArrayObject as S}from"./webgl-vertex-array-object.js";import{WebGL2RenderingContext as C}from"./webgl2-rendering-context.js";import{HTMLCanvasElement as w}from"./html-canvas-element.js";import{WebGLBridge as T}from"./webgl-bridge.js";import"@girs/gtk-4.0";import"@girs/gjs";import"@girs/gio-2.0";globalThis.WebGLRenderingContext=_,globalThis.WebGL2RenderingContext=C;export{w as HTMLCanvasElement,C as WebGL2RenderingContext,n as WebGLActiveInfo,T as WebGLBridge,i as WebGLBuffer,e as WebGLContextAttributes,g as WebGLContextBase,a as WebGLDrawingBufferWrapper,r as WebGLFramebuffer,o as WebGLProgram,v as WebGLQuery,s as WebGLRenderbuffer,_ as WebGLRenderingContext,y as WebGLSampler,c as WebGLShader,l as WebGLShaderPrecisionFormat,b as WebGLSync,d as WebGLTexture,u as WebGLTextureUnit,x as WebGLTransformFeedback,t as WebGLUniformLocation,f as WebGLVertexArrayGlobalAttribute,p as WebGLVertexArrayGlobalState,S as WebGLVertexArrayObject,m as WebGLVertexArrayObjectAttribute,h as WebGLVertexArrayObjectState};
1
+ import{WebGLContextAttributes as e}from"./webgl-context-attributes.js";import{WebGLUniformLocation as t}from"./webgl-uniform-location.js";import{OESElementIndexUint as n,getOESElementIndexUint as r}from"./extensions/oes-element-index-unit.js";import{OESStandardDerivatives as i,getOESStandardDerivatives as a}from"./extensions/oes-standard-derivatives.js";import{OESTextureFloat as o,getOESTextureFloat as s}from"./extensions/oes-texture-float.js";import{OESTextureFloatLinear as c,getOESTextureFloatLinear as l}from"./extensions/oes-texture-float-linear.js";import{STACKGLDestroyContext as u,getSTACKGLDestroyContext as d}from"./extensions/stackgl-destroy-context.js";import{STACKGLResizeDrawingBuffer as f,getSTACKGLResizeDrawingBuffer as p}from"./extensions/stackgl-resize-drawing-buffer.js";import{EXTBlendMinMax as m,getEXTBlendMinMax as h}from"./extensions/ext-blend-minmax.js";import{EXTColorBufferFloat as g,getEXTColorBufferFloat as _}from"./extensions/ext-color-buffer-float.js";import{EXTColorBufferHalfFloat as v,getEXTColorBufferHalfFloat as y}from"./extensions/ext-color-buffer-half-float.js";import{EXTTextureFilterAnisotropic as b,getEXTTextureFilterAnisotropic as x}from"./extensions/ext-texture-filter-anisotropic.js";import{OESTextureHalfFloat as S,getOESTextureHalfFloat as C}from"./extensions/oes-texture-half-float.js";import{WebGLTextureUnit as w}from"./webgl-texture-unit.js";import{WebGLBuffer as T}from"./webgl-buffer.js";import{WebGLVertexArrayGlobalAttribute as E,WebGLVertexArrayGlobalState as D,WebGLVertexArrayObjectAttribute as O,WebGLVertexArrayObjectState as k}from"./webgl-vertex-attribute.js";import{WebGLFramebuffer as A}from"./webgl-framebuffer.js";import{WebGLProgram as j}from"./webgl-program.js";import{WebGLRenderbuffer as M}from"./webgl-renderbuffer.js";import{WebGLShader as N}from"./webgl-shader.js";import{WebGLTexture as P}from"./webgl-texture.js";import{WebGLDrawingBufferWrapper as F}from"./webgl-drawing-buffer-wrapper.js";import{WebGLActiveInfo as I}from"./webgl-active-info.js";import{WebGLShaderPrecisionFormat as L}from"./webgl-shader-precision-format.js";import{WebGLContextBase as R}from"./webgl-context-base.js";import{WebGLRenderingContext as z}from"./webgl-rendering-context.js";import{WebGLQuery as B}from"./webgl-query.js";import{WebGLSampler as V}from"./webgl-sampler.js";import{WebGLSync as H}from"./webgl-sync.js";import{WebGLTransformFeedback as U}from"./webgl-transform-feedback.js";import{WebGLVertexArrayObject as W}from"./webgl-vertex-array-object.js";import{WebGL2RenderingContext as G}from"./webgl2-rendering-context.js";import{HTMLCanvasElement as K}from"./html-canvas-element.js";import{WebGLBridge as q}from"./webgl-bridge.js";import"@girs/gtk-4.0";import"@girs/gjs";import"@girs/gio-2.0";globalThis.WebGLRenderingContext=z,globalThis.WebGL2RenderingContext=G;export{m as EXTBlendMinMax,g as EXTColorBufferFloat,v as EXTColorBufferHalfFloat,b as EXTTextureFilterAnisotropic,K as HTMLCanvasElement,n as OESElementIndexUint,i as OESStandardDerivatives,o as OESTextureFloat,c as OESTextureFloatLinear,S as OESTextureHalfFloat,u as STACKGLDestroyContext,f as STACKGLResizeDrawingBuffer,G as WebGL2RenderingContext,I as WebGLActiveInfo,q as WebGLBridge,T as WebGLBuffer,e as WebGLContextAttributes,R as WebGLContextBase,F as WebGLDrawingBufferWrapper,A as WebGLFramebuffer,j as WebGLProgram,B as WebGLQuery,M as WebGLRenderbuffer,z as WebGLRenderingContext,V as WebGLSampler,N as WebGLShader,L as WebGLShaderPrecisionFormat,H as WebGLSync,P as WebGLTexture,w as WebGLTextureUnit,U as WebGLTransformFeedback,t as WebGLUniformLocation,E as WebGLVertexArrayGlobalAttribute,D as WebGLVertexArrayGlobalState,W as WebGLVertexArrayObject,O as WebGLVertexArrayObjectAttribute,k as WebGLVertexArrayObjectState,h as getEXTBlendMinMax,_ as getEXTColorBufferFloat,y as getEXTColorBufferHalfFloat,x as getEXTTextureFilterAnisotropic,r as getOESElementIndexUint,a as getOESStandardDerivatives,s as getOESTextureFloat,l as getOESTextureFloatLinear,C as getOESTextureHalfFloat,d as getSTACKGLDestroyContext,p as getSTACKGLResizeDrawingBuffer};
@@ -1 +1 @@
1
- var e=class{constructor(e){this._=0,this._references=[],this._refCount=0,this._pendingDelete=!1,this._binding=0,this._=e,this._references=[],this._refCount=0,this._pendingDelete=!1,this._binding=0}_link(e){return this._references.push(e),e._refCount+=1,!0}_unlink(e){let t=this._references.indexOf(e);if(t<0)return!1;for(;t>=0;)this._references[t]=this._references[this._references.length-1],this._references.pop(),--e._refCount,e._checkDelete(),t=this._references.indexOf(e);return!0}_linked(e){return this._references.indexOf(e)>=0}_checkDelete(){if(this._refCount<=0&&this._pendingDelete&&this._!==0){for(;this._references.length>0;)this._unlink(this._references[0]);this._performDelete(),this._=0}}_performDelete(){}};export{e as Linkable};
1
+ import"./_virtual/_rolldown/runtime.js";var Linkable=class{constructor(e){this._=0,this._references=[],this._refCount=0,this._pendingDelete=!1,this._binding=0,this._=e,this._references=[],this._refCount=0,this._pendingDelete=!1,this._binding=0}_link(e){return this._references.push(e),e._refCount+=1,!0}_unlink(e){let t=this._references.indexOf(e);if(t<0)return!1;for(;t>=0;)this._references[t]=this._references[this._references.length-1],this._references.pop(),--e._refCount,e._checkDelete(),t=this._references.indexOf(e);return!0}_linked(e){return this._references.indexOf(e)>=0}_checkDelete(){if(this._refCount<=0&&this._pendingDelete&&this._!==0){for(;this._references.length>0;)this._unlink(this._references[0]);this._performDelete(),this._=0}}_performDelete(){}};export{Linkable};
@@ -1,21 +1,21 @@
1
- function e(e,t,n){let r=e.createShader(t);return e.shaderSource(r,n),e.compileShader(r),r}function t(t,n,r){let i=e(t,t.FRAGMENT_SHADER,r),a=e(t,t.VERTEX_SHADER,n),o=t.createProgram();return t.attachShader(o,i),t.attachShader(o,a),t.bindAttribLocation(o,0,`position`),t.linkProgram(o),o}function n(e){let t=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,t),e.bufferData(e.ARRAY_BUFFER,new Float32Array([-2,-2,-2,4,4,-2]),e.STREAM_DRAW),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,2,e.FLOAT,!1,0,0),e.drawArrays(e.TRIANGLES,0,3),e.bindBuffer(e.ARRAY_BUFFER,null),e.disableVertexAttribArray(0),e.deleteBuffer(t)}function r(e,t=0,n=0){let r=new Uint8Array(4);return e.readPixels(t,n,1,1,e.RGBA,e.UNSIGNED_BYTE,r),r}function i(e,t,n=3){for(let r=0;r<4;r++)if(Math.abs(e[r]-t[r])>n)return!1;return!0}function a(e,t=4,n=4){let r=e.createFramebuffer(),i=e.createTexture();return e.bindTexture(e.TEXTURE_2D,i),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,t,n,0,e.RGBA,e.UNSIGNED_BYTE,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.bindTexture(e.TEXTURE_2D,null),e.bindFramebuffer(e.FRAMEBUFFER,r),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,i,0),e.viewport(0,0,t,n),{fb:r,colorTex:i,width:t,height:n}}function o(e,t=4,n=4){let r=a(e,t,n),i=e.createRenderbuffer();return e.bindRenderbuffer(e.RENDERBUFFER,i),e.renderbufferStorage(e.RENDERBUFFER,e.DEPTH_COMPONENT16,t,n),e.bindRenderbuffer(e.RENDERBUFFER,null),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.RENDERBUFFER,i),{...r,depthRb:i}}function s(e,t){e.bindFramebuffer(e.FRAMEBUFFER,t.fb),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,null,0),e.bindFramebuffer(e.FRAMEBUFFER,null),e.deleteTexture(t.colorTex),e.deleteFramebuffer(t.fb)}function c(e,t){e.bindFramebuffer(e.FRAMEBUFFER,t.fb),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,null,0),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.RENDERBUFFER,null),e.bindFramebuffer(e.FRAMEBUFFER,null),e.deleteTexture(t.colorTex),e.deleteRenderbuffer(t.depthRb),e.deleteFramebuffer(t.fb)}function l(e,t=4,n=4){let r=e.createFramebuffer(),i=e.createTexture();return e.bindTexture(e.TEXTURE_2D,i),e.texImage2D(e.TEXTURE_2D,0,34842,t,n,0,e.RGBA,5131,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.bindTexture(e.TEXTURE_2D,null),e.bindFramebuffer(e.FRAMEBUFFER,r),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,i,0),e.viewport(0,0,t,n),{fb:r,colorTex:i,width:t,height:n}}function u(e,t=4,n=4){let r=e.createFramebuffer(),i=e.createTexture();e.bindTexture(e.TEXTURE_2D,i),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,t,n,0,e.RGBA,e.UNSIGNED_BYTE,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST);let a=e.createTexture();return e.bindTexture(e.TEXTURE_2D,a),e.texImage2D(e.TEXTURE_2D,0,33190,t,n,0,6402,5125,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.bindTexture(e.TEXTURE_2D,null),e.bindFramebuffer(e.FRAMEBUFFER,r),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,i,0),e.framebufferTexture2D(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.TEXTURE_2D,a,0),e.viewport(0,0,t,n),{fb:r,colorTex:i,depthTex:a,width:t,height:n}}const d=`#version 300 es
1
+ import"./_virtual/_rolldown/runtime.js";function makeShader(e,t,n){let r=e.createShader(t);return e.shaderSource(r,n),e.compileShader(r),r}function makeProgram(e,t,n){let r=makeShader(e,e.FRAGMENT_SHADER,n),i=makeShader(e,e.VERTEX_SHADER,t),a=e.createProgram();return e.attachShader(a,r),e.attachShader(a,i),e.bindAttribLocation(a,0,`position`),e.linkProgram(a),a}function drawTriangle(e){let t=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,t),e.bufferData(e.ARRAY_BUFFER,new Float32Array([-2,-2,-2,4,4,-2]),e.STREAM_DRAW),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,2,e.FLOAT,!1,0,0),e.drawArrays(e.TRIANGLES,0,3),e.bindBuffer(e.ARRAY_BUFFER,null),e.disableVertexAttribArray(0),e.deleteBuffer(t)}function readPixel(e,t=0,n=0){let r=new Uint8Array(4);return e.readPixels(t,n,1,1,e.RGBA,e.UNSIGNED_BYTE,r),r}function pixelClose(e,t,n=3){for(let r=0;r<4;r++)if(Math.abs(e[r]-t[r])>n)return!1;return!0}function makeTestFBO(e,t=4,n=4){let r=e.createFramebuffer(),i=e.createTexture();return e.bindTexture(e.TEXTURE_2D,i),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,t,n,0,e.RGBA,e.UNSIGNED_BYTE,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.bindTexture(e.TEXTURE_2D,null),e.bindFramebuffer(e.FRAMEBUFFER,r),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,i,0),e.viewport(0,0,t,n),{fb:r,colorTex:i,width:t,height:n}}function makeTestFBOWithDepth(e,t=4,n=4){let r=makeTestFBO(e,t,n),i=e.createRenderbuffer();return e.bindRenderbuffer(e.RENDERBUFFER,i),e.renderbufferStorage(e.RENDERBUFFER,e.DEPTH_COMPONENT16,t,n),e.bindRenderbuffer(e.RENDERBUFFER,null),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.RENDERBUFFER,i),{...r,depthRb:i}}function destroyTestFBO(e,t){e.bindFramebuffer(e.FRAMEBUFFER,t.fb),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,null,0),e.bindFramebuffer(e.FRAMEBUFFER,null),e.deleteTexture(t.colorTex),e.deleteFramebuffer(t.fb)}function destroyTestFBOWithDepth(e,t){e.bindFramebuffer(e.FRAMEBUFFER,t.fb),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,null,0),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.RENDERBUFFER,null),e.bindFramebuffer(e.FRAMEBUFFER,null),e.deleteTexture(t.colorTex),e.deleteRenderbuffer(t.depthRb),e.deleteFramebuffer(t.fb)}function makeTestFBOFloat(e,t=4,n=4){let r=e.createFramebuffer(),i=e.createTexture();return e.bindTexture(e.TEXTURE_2D,i),e.texImage2D(e.TEXTURE_2D,0,34842,t,n,0,e.RGBA,5131,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.bindTexture(e.TEXTURE_2D,null),e.bindFramebuffer(e.FRAMEBUFFER,r),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,i,0),e.viewport(0,0,t,n),{fb:r,colorTex:i,width:t,height:n}}function makeTestFBOWithDepthTexture(e,t=4,n=4){let r=e.createFramebuffer(),i=e.createTexture();e.bindTexture(e.TEXTURE_2D,i),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,t,n,0,e.RGBA,e.UNSIGNED_BYTE,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST);let a=e.createTexture();return e.bindTexture(e.TEXTURE_2D,a),e.texImage2D(e.TEXTURE_2D,0,33190,t,n,0,6402,5125,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.bindTexture(e.TEXTURE_2D,null),e.bindFramebuffer(e.FRAMEBUFFER,r),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,i,0),e.framebufferTexture2D(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.TEXTURE_2D,a,0),e.viewport(0,0,t,n),{fb:r,colorTex:i,depthTex:a,width:t,height:n}}const e=`#version 300 es
2
2
  in vec2 position;
3
3
  out vec2 vUv;
4
4
  void main() {
5
5
  vUv = position * 0.5 + 0.5;
6
6
  gl_Position = vec4(position, 0.0, 1.0);
7
- }`,f=`#version 300 es
7
+ }`,t=`#version 300 es
8
8
  precision mediump float;
9
9
  uniform sampler2D uTexture;
10
10
  in vec2 vUv;
11
11
  out vec4 fragColor;
12
12
  void main() {
13
13
  fragColor = texture(uTexture, vUv);
14
- }`,p=`#version 300 es
14
+ }`,n=`#version 300 es
15
15
  precision mediump float;
16
16
  uniform samplerCube uCubemap;
17
17
  uniform vec3 uDirection;
18
18
  out vec4 fragColor;
19
19
  void main() {
20
20
  fragColor = texture(uCubemap, uDirection);
21
- }`;export{p as CUBEMAP_FS_300,f as TEXTURE_FS_300,d as TEXTURE_VS_300,s as destroyTestFBO,c as destroyTestFBOWithDepth,n as drawTriangle,t as makeProgram,e as makeShader,a as makeTestFBO,l as makeTestFBOFloat,o as makeTestFBOWithDepth,u as makeTestFBOWithDepthTexture,i as pixelClose,r as readPixel};
21
+ }`;export{n as CUBEMAP_FS_300,t as TEXTURE_FS_300,e as TEXTURE_VS_300,destroyTestFBO,destroyTestFBOWithDepth,drawTriangle,makeProgram,makeShader,makeTestFBO,makeTestFBOFloat,makeTestFBOWithDepth,makeTestFBOWithDepthTexture,pixelClose,readPixel};
package/lib/esm/test.js CHANGED
@@ -1 +1 @@
1
- import e from"./webgl1.spec.js";import t from"./webgl2.spec.js";import{run as n}from"@gjsify/unit";n({testSuite:async()=>{await e(),await t()}});
1
+ import"./_virtual/_rolldown/runtime.js";import e from"./webgl1.spec.js";import t from"./webgl2.spec.js";import{run as n}from"@gjsify/unit";n({testSuite:async()=>{await e(),await t()}});
package/lib/esm/utils.js CHANGED
@@ -1 +1 @@
1
- import{WebGLUniformLocation as e}from"./webgl-uniform-location.js";import t from"@girs/glib-2.0";function n(e,t,n,r){for(let i=0;i<e.length;i++){let a=e[i],o=n[a];if(typeof o==`function`)r.indexOf(a)===-1&&(t[a]=o.bind(n));else{if(a[0]===`_`||a[0]===`0`||a[0]===`1`)continue;t[a]=o}}}function r(e){return typeof e==`object`||e===void 0}function i(t,n){return n instanceof e&&n._program===t&&n._linkCount===t._linkCount}function a(e){return e instanceof Uint8Array||e instanceof Uint8ClampedArray||e instanceof Int8Array||e instanceof Uint16Array||e instanceof Int16Array||e instanceof Uint32Array||e instanceof Int32Array||e instanceof Float32Array||e instanceof Float64Array}function o(e){let t=e.replace(/(?:\/\*(?:[\s\S]*?)\*\/)|(?:([\s;])+\/\/(?:.*)$)/gm,``);return!/["$`@\\'\0]/.test(t)}function s(e,t,n){switch(t){case e.TRIANGLES:return n-n%3;case e.LINES:return n-n%2;case e.LINE_LOOP:case e.POINTS:return n;case e.TRIANGLE_FAN:case e.LINE_STRIP:return n<2?0:n;case e.TRIANGLE_STRIP:return n<3?0:n;default:return-1}}function c(e,t){switch(t){case e.UNSIGNED_BYTE:case e.BYTE:return 1;case e.UNSIGNED_SHORT:case e.SHORT:return 2;case e.UNSIGNED_INT:case e.INT:case e.FLOAT:return 4}return 0}function l(e,t){switch(t){case e.BOOL_VEC4:case e.INT_VEC4:case e.FLOAT_VEC4:return 4;case e.BOOL_VEC3:case e.INT_VEC3:case e.FLOAT_VEC3:return 3;case e.BOOL_VEC2:case e.INT_VEC2:case e.FLOAT_VEC2:return 2;case e.BOOL:case e.INT:case e.FLOAT:case e.SAMPLER_2D:case e.SAMPLER_CUBE:return 1;default:return 0}}const u=e=>{let t=[];for(let n of e.values())t.push(n);return t};function d(e){if(a(e))return new Uint8Array(e.buffer).subarray(e.byteOffset,e.byteLength+e.byteOffset);if(Array.isArray(e)||e instanceof ArrayBuffer)return new Uint8Array(e);if(typeof e.values==`function`)return new Uint8Array(u(e));throw Error(`Can't unpack typed array!`)}function f(e){return new t.Variant(`ay`,e)}function p(e){return Array.from(new Int32Array(e.buffer)).map(e=>!!e)}const m=e=>{let t=e.width,n=e.height;if(typeof e==`object`&&t!==void 0&&n!==void 0){if(e.data!==void 0)return e;let r=null;if(typeof e.getContext==`function`)r=e.getContext(`2d`);else if(typeof e.isPixbuf==`function`&&e.isPixbuf())return e.getImageData();else if(e.src!==void 0&&typeof document==`object`&&typeof document.createElement==`function`){let i=document.createElement(`canvas`);typeof i==`object`&&typeof i.getContext==`function`&&(i.width=t,i.height=n,r=i.getContext(`2d`),r!==null&&r.drawImage(e,0,0))}if(r!==null)return r.getImageData(0,0,t,n)}return null};function h(e,t){switch(t){case e.ALPHA:case e.LUMINANCE:return 1;case e.LUMINANCE_ALPHA:return 2;case e.RGB:return 3;case e.RGBA:return 4}return 0}function g(e){if(typeof e==`object`&&e){if(e instanceof ArrayBuffer)return new Uint8Array(e);if(e instanceof Uint8Array||e instanceof Uint16Array||e instanceof Uint8ClampedArray||e instanceof Float32Array)return d(e);if(e instanceof Buffer)return new Uint8Array(e)}return null}function _(e,t){return t===e.ALPHA||t===e.LUMINANCE_ALPHA||t===e.LUMINANCE||t===e.RGB||t===e.RGBA}function v(e,t){return t===e.TEXTURE_CUBE_MAP_POSITIVE_X||t===e.TEXTURE_CUBE_MAP_NEGATIVE_X||t===e.TEXTURE_CUBE_MAP_POSITIVE_Y||t===e.TEXTURE_CUBE_MAP_NEGATIVE_Y||t===e.TEXTURE_CUBE_MAP_POSITIVE_Z||t===e.TEXTURE_CUBE_MAP_NEGATIVE_Z}function y(e,t,n){return!e||typeof e!=`object`||!(t in e)?n:!!e[t]}function b(e){let t=new Uint8Array(e.length);for(let n=0;n<e.length;n+=4){let r=e[n+3]/255;t[n]=Math.round(e[n]*r),t[n+1]=Math.round(e[n+1]*r),t[n+2]=Math.round(e[n+2]*r),t[n+3]=e[n+3]}return t}export{f as Uint8ArrayToVariant,d as arrayToUint8Array,n as bindPublics,p as boolArray,_ as checkFormat,r as checkObject,i as checkUniform,g as convertPixels,m as extractImageData,y as flag,h as formatSize,a as isTypedArray,o as isValidString,u as listToArray,b as premultiplyAlpha,c as typeSize,l as uniformTypeSize,v as validCubeTarget,s as vertexCount};
1
+ import"./_virtual/_rolldown/runtime.js";import{WebGLUniformLocation as e}from"./webgl-uniform-location.js";import t from"@girs/glib-2.0";function bindPublics(e,t,n,r){for(let i=0;i<e.length;i++){let a=e[i],o=n[a];if(typeof o==`function`)r.indexOf(a)===-1&&(t[a]=o.bind(n));else{if(a[0]===`_`||a[0]===`0`||a[0]===`1`)continue;t[a]=o}}}function checkObject(e){return typeof e==`object`||e===void 0}function checkUniform(t,n){return n instanceof e&&n._program===t&&n._linkCount===t._linkCount}function isTypedArray(e){return e instanceof Uint8Array||e instanceof Uint8ClampedArray||e instanceof Int8Array||e instanceof Uint16Array||e instanceof Int16Array||e instanceof Uint32Array||e instanceof Int32Array||e instanceof Float32Array||e instanceof Float64Array}function isValidString(e){let t=e.replace(/(?:\/\*(?:[\s\S]*?)\*\/)|(?:([\s;])+\/\/(?:.*)$)/gm,``);return!/["$`@\\'\0]/.test(t)}function vertexCount(e,t,n){switch(t){case e.TRIANGLES:return n-n%3;case e.LINES:return n-n%2;case e.LINE_LOOP:case e.POINTS:return n;case e.TRIANGLE_FAN:case e.LINE_STRIP:return n<2?0:n;case e.TRIANGLE_STRIP:return n<3?0:n;default:return-1}}function typeSize(e,t){switch(t){case e.UNSIGNED_BYTE:case e.BYTE:return 1;case e.UNSIGNED_SHORT:case e.SHORT:return 2;case e.UNSIGNED_INT:case e.INT:case e.FLOAT:return 4}return 0}function uniformTypeSize(e,t){switch(t){case e.BOOL_VEC4:case e.INT_VEC4:case e.FLOAT_VEC4:return 4;case e.BOOL_VEC3:case e.INT_VEC3:case e.FLOAT_VEC3:return 3;case e.BOOL_VEC2:case e.INT_VEC2:case e.FLOAT_VEC2:return 2;case e.BOOL:case e.INT:case e.FLOAT:case e.SAMPLER_2D:case e.SAMPLER_CUBE:return 1;default:return 0}}const listToArray=e=>{let t=[];for(let n of e.values())t.push(n);return t};function arrayToUint8Array(e){if(isTypedArray(e))return new Uint8Array(e.buffer).subarray(e.byteOffset,e.byteLength+e.byteOffset);if(Array.isArray(e)||e instanceof ArrayBuffer)return new Uint8Array(e);if(typeof e.values==`function`)return new Uint8Array(listToArray(e));throw Error(`Can't unpack typed array!`)}function Uint8ArrayToVariant(e){return new t.Variant(`ay`,e)}function boolArray(e){return Array.from(new Int32Array(e.buffer)).map(e=>!!e)}const extractImageData=e=>{let t=e.width,n=e.height;if(typeof e==`object`&&t!==void 0&&n!==void 0){if(e.data!==void 0)return e;let r=null;if(typeof e.getContext==`function`)r=e.getContext(`2d`);else if(typeof e.isPixbuf==`function`&&e.isPixbuf())return e.getImageData();else if(e.src!==void 0&&typeof document==`object`&&typeof document.createElement==`function`){let i=document.createElement(`canvas`);typeof i==`object`&&typeof i.getContext==`function`&&(i.width=t,i.height=n,r=i.getContext(`2d`),r!==null&&r.drawImage(e,0,0))}if(r!==null)return r.getImageData(0,0,t,n)}return null};function formatSize(e,t){switch(t){case e.ALPHA:case e.LUMINANCE:return 1;case e.LUMINANCE_ALPHA:return 2;case e.RGB:return 3;case e.RGBA:return 4}return 0}function convertPixels(e){if(typeof e==`object`&&e){if(e instanceof ArrayBuffer)return new Uint8Array(e);if(e instanceof Uint8Array||e instanceof Uint16Array||e instanceof Uint8ClampedArray||e instanceof Float32Array)return arrayToUint8Array(e);if(e instanceof Buffer)return new Uint8Array(e)}return null}function checkFormat(e,t){return t===e.ALPHA||t===e.LUMINANCE_ALPHA||t===e.LUMINANCE||t===e.RGB||t===e.RGBA}function validCubeTarget(e,t){return t===e.TEXTURE_CUBE_MAP_POSITIVE_X||t===e.TEXTURE_CUBE_MAP_NEGATIVE_X||t===e.TEXTURE_CUBE_MAP_POSITIVE_Y||t===e.TEXTURE_CUBE_MAP_NEGATIVE_Y||t===e.TEXTURE_CUBE_MAP_POSITIVE_Z||t===e.TEXTURE_CUBE_MAP_NEGATIVE_Z}function flag(e,t,n){return!e||typeof e!=`object`||!(t in e)?n:!!e[t]}function premultiplyAlpha(e){let t=new Uint8Array(e.length);for(let n=0;n<e.length;n+=4){let r=e[n+3]/255;t[n]=Math.round(e[n]*r),t[n+1]=Math.round(e[n+1]*r),t[n+2]=Math.round(e[n+2]*r),t[n+3]=e[n+3]}return t}export{Uint8ArrayToVariant,arrayToUint8Array,bindPublics,boolArray,checkFormat,checkObject,checkUniform,convertPixels,extractImageData,flag,formatSize,isTypedArray,isValidString,listToArray,premultiplyAlpha,typeSize,uniformTypeSize,validCubeTarget,vertexCount};
@@ -1 +1 @@
1
- var e=class{constructor(e){this.size=e.size,this.type=e.type,this.name=e.name}};export{e as WebGLActiveInfo};
1
+ import"./_virtual/_rolldown/runtime.js";var WebGLActiveInfo=class{constructor(e){this.size=e.size,this.type=e.type,this.name=e.name}};export{WebGLActiveInfo};
@@ -1 +1 @@
1
- import{HTMLCanvasElement as e}from"./html-canvas-element.js";import t from"gi://GObject";import n from"gi://GLib?version=2.0";import r from"gi://Gtk?version=4.0";import{attachEventControllers as i}from"@gjsify/event-bridge";import{Event as a}from"@gjsify/dom-events";const o=t.registerClass({GTypeName:`GjsifyWebGLBridge`},class extends r.GLArea{constructor(t){super(t),this._canvas=null,this._readyCallbacks=[],this._resizeCallbacks=[],this._renderTag=null,this._tickCallbackId=null,this._frameCallback=null,this._timeOrigin=n.get_monotonic_time(),this.set_use_es(!0),this.set_required_version(3,2),this.set_has_depth_buffer(!0),this.set_has_stencil_buffer(!0),i(this,()=>this._canvas,{captureKeys:!0}),this._tickCallbackId=this.add_tick_callback((e,t)=>(this._frameCallback!==null&&this.queue_render(),n.SOURCE_CONTINUE));let r=this.connect(`render`,()=>{this.disconnect(r),this.make_current(),this._canvas=new e(this),globalThis.document?.body&&globalThis.document.body.appendChild(this._canvas),this._canvas.getContext(`webgl2`);let t=this._canvas.getContext(`webgl`);if(t){for(let e of this._readyCallbacks)e(this._canvas,t);this._readyCallbacks=[]}return this._renderTag=this.connect(`render`,e=>{if(this._frameCallback!==null){let e=(n.get_monotonic_time()-this._timeOrigin)/1e3;globalThis.__GJSIFY_DEBUG_RAF===!0&&console.log(`[rAF] frame callback fires t=${e.toFixed(1)}`);let t=this._frameCallback;this._frameCallback=null,t(e)}return!0}),!0});this.connect(`resize`,()=>{let e=this.get_allocated_width(),t=this.get_allocated_height();this._canvas&&this._canvas.dispatchEvent(new a(`resize`));for(let n of this._resizeCallbacks)n(e,t);this._frameCallback&&this.requestAnimationFrame(this._frameCallback)}),this.connect(`unrealize`,()=>{this._renderTag!==null&&(this.disconnect(this._renderTag),this._renderTag=null),this._tickCallbackId!==null&&(this.remove_tick_callback(this._tickCallbackId),this._tickCallbackId=null),this._canvas=null})}get canvas(){return this._canvas}onReady(e){if(this._canvas){let t=this._canvas.getContext(`webgl`);if(t){e(this._canvas,t);return}}this._readyCallbacks.push(e)}onWebGLReady(e){this.onReady(e)}onResize(e){this._resizeCallbacks.push(e)}requestAnimationFrame(e){return this._frameCallback=e,this.queue_render(),0}installGlobals(){globalThis.requestAnimationFrame=e=>this.requestAnimationFrame(e),globalThis.cancelAnimationFrame=e=>{this._frameCallback=null};let e=this._timeOrigin;globalThis.performance={now:()=>(n.get_monotonic_time()-e)/1e3,timeOrigin:Date.now()}}});export{o as WebGLBridge};
1
+ import"./_virtual/_rolldown/runtime.js";import{HTMLCanvasElement as e}from"./html-canvas-element.js";import t from"gi://GObject";import n from"gi://GLib?version=2.0";import r from"gi://Gtk?version=4.0";import{attachEventControllers as i}from"@gjsify/event-bridge";import{Event as a}from"@gjsify/dom-events";const o=t.registerClass({GTypeName:`GjsifyWebGLBridge`},class WebGLBridge extends r.GLArea{constructor(t){super(t),this._canvas=null,this._readyCallbacks=[],this._resizeCallbacks=[],this._renderTag=null,this._tickCallbackId=null,this._frameCallback=null,this._timeOrigin=n.get_monotonic_time(),this.set_use_es(!0),this.set_required_version(3,2),this.set_has_depth_buffer(!0),this.set_has_stencil_buffer(!0),i(this,()=>this._canvas,{captureKeys:!0}),this._tickCallbackId=this.add_tick_callback((e,t)=>(this._frameCallback!==null&&this.queue_render(),n.SOURCE_CONTINUE));let r=this.connect(`render`,()=>{this.disconnect(r),this.make_current(),this._canvas=new e(this),globalThis.document?.body&&globalThis.document.body.appendChild(this._canvas),this._canvas.getContext(`webgl2`);let t=this._canvas.getContext(`webgl`);if(t){for(let e of this._readyCallbacks)e(this._canvas,t);this._readyCallbacks=[]}return this._renderTag=this.connect(`render`,e=>{if(this._frameCallback!==null){let e=(n.get_monotonic_time()-this._timeOrigin)/1e3;globalThis.__GJSIFY_DEBUG_RAF===!0&&console.log(`[rAF] frame callback fires t=${e.toFixed(1)}`);let t=this._frameCallback;this._frameCallback=null,t(e)}return!0}),!0});this.connect(`resize`,()=>{let e=this.get_allocated_width(),t=this.get_allocated_height();this._canvas&&this._canvas.dispatchEvent(new a(`resize`));for(let n of this._resizeCallbacks)n(e,t);this._frameCallback&&this.requestAnimationFrame(this._frameCallback)}),this.connect(`unrealize`,()=>{this._renderTag!==null&&(this.disconnect(this._renderTag),this._renderTag=null),this._tickCallbackId!==null&&(this.remove_tick_callback(this._tickCallbackId),this._tickCallbackId=null),this._canvas=null})}get canvas(){return this._canvas}onReady(e){if(this._canvas){let t=this._canvas.getContext(`webgl`);if(t){e(this._canvas,t);return}}this._readyCallbacks.push(e)}onWebGLReady(e){this.onReady(e)}onResize(e){this._resizeCallbacks.push(e)}requestAnimationFrame(e){return this._frameCallback=e,this.queue_render(),0}installGlobals(){globalThis.requestAnimationFrame=e=>this.requestAnimationFrame(e),globalThis.cancelAnimationFrame=e=>{this._frameCallback=null};let e=this._timeOrigin;globalThis.performance={now:()=>(n.get_monotonic_time()-e)/1e3,timeOrigin:Date.now()}}});export{o as WebGLBridge};
@@ -1 +1 @@
1
- import{Linkable as e}from"./linkable.js";var t=class extends e{constructor(e,t){super(e),this._size=0,this._elements=new Uint8Array,this._ctx=t}_performDelete(){let e=this._ctx;delete e._buffers[this._|0],e._gl.deleteBuffer(this._)}};export{t as WebGLBuffer};
1
+ import"./_virtual/_rolldown/runtime.js";import{Linkable as e}from"./linkable.js";var WebGLBuffer=class extends e{constructor(e,t){super(e),this._size=0,this._elements=new Uint8Array,this._ctx=t}_performDelete(){let e=this._ctx;delete e._buffers[this._|0],e._gl.deleteBuffer(this._)}};export{WebGLBuffer};
@@ -1 +1 @@
1
- var e=class{constructor(e,t,n,r,i,a,o,s){this.alpha=e,this.depth=t,this.stencil=n,this.antialias=r,this.premultipliedAlpha=i,this.preserveDrawingBuffer=a,this.preferLowPowerToHighPerformance=o,this.failIfMajorPerformanceCaveat=s,this.alpha=e,this.depth=t,this.stencil=n,this.antialias=r,this.premultipliedAlpha=i,this.preserveDrawingBuffer=a,this.preferLowPowerToHighPerformance=o,this.failIfMajorPerformanceCaveat=s}};export{e as WebGLContextAttributes};
1
+ import"./_virtual/_rolldown/runtime.js";var WebGLContextAttributes=class{constructor(e,t,n,r,i,a,o,s){this.alpha=e,this.depth=t,this.stencil=n,this.antialias=r,this.premultipliedAlpha=i,this.preserveDrawingBuffer=a,this.preferLowPowerToHighPerformance=o,this.failIfMajorPerformanceCaveat=s,this.alpha=e,this.depth=t,this.stencil=n,this.antialias=r,this.premultipliedAlpha=i,this.preserveDrawingBuffer=a,this.preferLowPowerToHighPerformance=o,this.failIfMajorPerformanceCaveat=s}};export{WebGLContextAttributes};
@@ -1,8 +1 @@
1
- import{WebGLContextAttributes as e}from"./webgl-context-attributes.js";import{WebGLUniformLocation as t}from"./webgl-uniform-location.js";import{Uint8ArrayToVariant as n,arrayToUint8Array as r,checkFormat as i,checkObject as a,checkUniform as o,convertPixels as s,extractImageData as c,flag as l,formatSize as u,isTypedArray as d,isValidString as f,listToArray as p,premultiplyAlpha as m,typeSize as h,uniformTypeSize as g,validCubeTarget as _,vertexCount as v}from"./utils.js";import{getOESElementIndexUint as y}from"./extensions/oes-element-index-unit.js";import{getOESStandardDerivatives as b}from"./extensions/oes-standard-derivatives.js";import{getOESTextureFloat as x}from"./extensions/oes-texture-float.js";import{getOESTextureFloatLinear as S}from"./extensions/oes-texture-float-linear.js";import{getSTACKGLDestroyContext as C}from"./extensions/stackgl-destroy-context.js";import{getSTACKGLResizeDrawingBuffer as w}from"./extensions/stackgl-resize-drawing-buffer.js";import{getEXTBlendMinMax as T}from"./extensions/ext-blend-minmax.js";import{getEXTColorBufferFloat as E}from"./extensions/ext-color-buffer-float.js";import{getEXTColorBufferHalfFloat as D}from"./extensions/ext-color-buffer-half-float.js";import{getEXTTextureFilterAnisotropic as O}from"./extensions/ext-texture-filter-anisotropic.js";import{getOESTextureHalfFloat as k}from"./extensions/oes-texture-half-float.js";import{WebGLActiveInfo as A}from"./webgl-active-info.js";import{WebGLFramebuffer as j}from"./webgl-framebuffer.js";import{WebGLBuffer as M}from"./webgl-buffer.js";import{WebGLDrawingBufferWrapper as N}from"./webgl-drawing-buffer-wrapper.js";import{WebGLProgram as P}from"./webgl-program.js";import{WebGLRenderbuffer as F}from"./webgl-renderbuffer.js";import{WebGLShader as I}from"./webgl-shader.js";import{WebGLShaderPrecisionFormat as L}from"./webgl-shader-precision-format.js";import{WebGLTextureUnit as R}from"./webgl-texture-unit.js";import{WebGLTexture as z}from"./webgl-texture.js";import{WebGLVertexArrayGlobalState as B,WebGLVertexArrayObjectState as V}from"./webgl-vertex-attribute.js";import H from"@girs/gwebgl-0.1";import"@girs/gdkpixbuf-2.0";import*as U from"bit-twiddle";import W from"glsl-tokenizer/string";import G from"gi://GdkPixbuf?version=2.0";import{warnNotImplemented as K}from"@gjsify/utils";let q=0;const J={oes_element_index_uint:y,oes_texture_float:x,oes_texture_float_linear:S,oes_standard_derivatives:b,stackgl_destroy_context:C,stackgl_resize_drawingbuffer:w,ext_blend_minmax:T,ext_color_buffer_float:E,ext_color_buffer_half_float:D,ext_texture_filter_anisotropic:O,oes_texture_half_float:k};var Y=class{get drawingBufferHeight(){return this.canvas.height||0}get drawingBufferWidth(){return this.canvas.width||0}constructor(t,n={}){this.unpackColorSpace=`srgb`,this.RGBA8=32856,this.DEFAULT_ATTACHMENTS=[],this.DEFAULT_COLOR_ATTACHMENTS=[],this._=0,this._extensions={},this._programs={},this._shaders={},this._textures={},this._framebuffers={},this._renderbuffers={},this._buffers={},this._activeProgram=null,this._activeFramebuffer=null,this._activeRenderbuffer=null,this._checkStencil=!1,this._stencilState=!0,this._activeTextureUnit=0,this._errorStack=[],this._maxTextureSize=0,this._maxTextureLevel=0,this._maxCubeMapSize=0,this._maxCubeMapLevel=0,this._unpackAlignment=4,this._packAlignment=4,this._unpackFlipY=!1,this._unpackPremultAlpha=!1,this._viewport=new Int32Array([0,0,0,0]),this._scissorBox=new Int32Array([0,0,0,0]),this._gtkFboId=0,this._textureUnits=[],this._drawingBuffer=null,this.canvas=t,this._contextAttributes=new e(l(n,`alpha`,!0),l(n,`depth`,!0),l(n,`stencil`,!1),!1,l(n,`premultipliedAlpha`,!0),l(n,`preserveDrawingBuffer`,!1),l(n,`preferLowPowerToHighPerformance`,!1),l(n,`failIfMajorPerformanceCaveat`,!1)),this._contextAttributes.premultipliedAlpha=this._contextAttributes.premultipliedAlpha&&this._contextAttributes.alpha}_init(){let e=this._gl.getParameterx(36006);this._gtkFboId=e?.deepUnpack()|0,this._initGLConstants(),this.DEFAULT_ATTACHMENTS=[this.COLOR_ATTACHMENT0,this.DEPTH_ATTACHMENT,this.STENCIL_ATTACHMENT,this.DEPTH_STENCIL_ATTACHMENT],this.DEFAULT_COLOR_ATTACHMENTS=[this.COLOR_ATTACHMENT0];let t=this._contextAttributes,n=this.drawingBufferWidth||t.width||0,r=this.drawingBufferHeight||t.height||0;this._=q++;let i=this.getParameter(this.MAX_COMBINED_TEXTURE_IMAGE_UNITS);this._textureUnits=Array(i);for(let e=0;e<i;++e)this._textureUnits[e]=new R(this,e);this.activeTexture(this.TEXTURE0),this._defaultVertexObjectState=new V(this),this._vertexObjectState=this._defaultVertexObjectState,this._vertexGlobalState=new B(this),this._maxTextureSize=this.getParameter(this.MAX_TEXTURE_SIZE),this._maxTextureLevel=U.log2(U.nextPow2(this._maxTextureSize)),this._maxCubeMapSize=this.getParameter(this.MAX_CUBE_MAP_TEXTURE_SIZE),this._maxCubeMapLevel=U.log2(U.nextPow2(this._maxCubeMapSize)),this._unpackAlignment=4,this._packAlignment=4,this._unpackFlipY=!1,this._unpackPremultAlpha=!1,this.bindBuffer(this.ARRAY_BUFFER,null),this.bindBuffer(this.ELEMENT_ARRAY_BUFFER,null),this.bindFramebuffer(this.FRAMEBUFFER,null),this.bindRenderbuffer(this.RENDERBUFFER,null),this.viewport(0,0,n,r),this.scissor(0,0,n,r),this.clearDepth(1),this.clearColor(0,0,0,0),this.clearStencil(0),this.clear(this.COLOR_BUFFER_BIT|this.DEPTH_BUFFER_BIT|this.STENCIL_BUFFER_BIT),this.disable(this.DEPTH_TEST),this.disable(this.STENCIL_TEST),this.disable(this.BLEND),this.disable(this.CULL_FACE),this.disable(this.POLYGON_OFFSET_FILL),this.disable(this.SCISSOR_TEST),this._gl.colorMask(!0,!0,!0,!0)}_initGLConstants(){let e=new H.WebGLRenderingContextBase().get_webgl_constants();for(let[t,n]of Object.entries(e))Object.defineProperty(this,t,{value:n})}_getGlslVersion(e){return e?`100`:`120`}_checkDimensions(e,t,n,r){if(r<0||t<0||n<0)return this.setError(this.INVALID_VALUE),!1;if(e===this.TEXTURE_2D){if(t>this._maxTextureSize||n>this._maxTextureSize||r>this._maxTextureLevel)return this.setError(this.INVALID_VALUE),!1}else if(this._validCubeTarget(e)){if(t>this._maxCubeMapSize||n>this._maxCubeMapSize||r>this._maxCubeMapLevel)return this.setError(this.INVALID_VALUE),!1}else return this.setError(this.INVALID_ENUM),!1;return!0}_checkLocation(e){return e instanceof t?e._program._ctx!==this||e._linkCount!==e._program._linkCount?(this.setError(this.INVALID_OPERATION),!1):!0:(this.setError(this.INVALID_VALUE),!1)}_checkLocationActive(e){return e&&this._checkLocation(e)?e._program===this._activeProgram?!0:(this.setError(this.INVALID_OPERATION),!1):!1}_checkOwns(e){return typeof e==`object`&&e._ctx===this}_checkShaderSource(e){let t=e._source,n=W(t),r=!1,i=[];for(let e=0;e<n.length;++e){let t=n[e];if(t)switch(t.type){case`ident`:this._validGLSLIdentifier(t.data)||(r=!0,i.push(t.line+`:`+t.column+` invalid identifier - `+t.data));break;case`preprocessor`:{let e=t.data.match(/^\s*#\s*(.*)$/);if(!e||e?.length<2)break;let n=W(e[1]);for(let e=0;e<n.length;++e){let a=n[e];(a.type===`ident`||a.type===void 0)&&(this._validGLSLIdentifier(a.data)||(r=!0,i.push(t.line+`:`+a.column+` invalid identifier - `+a.data)))}break}case`keyword`:switch(t.data){case`do`:r=!0,i.push(t.line+`:`+t.column+` do not supported`);break}break;case`builtin`:switch(t.data){case`dFdx`:case`dFdy`:case`fwidth`:!this._extensions.oes_standard_derivatives&&this._getGlslVersion(!0)===`100`&&(r=!0,i.push(t.line+`:`+t.column+` `+t.data+` not supported`));break}}}return r&&(e._compileInfo=i.join(`
2
- `)),!r}_checkStencilState(){return this._checkStencil?(this._checkStencil=!1,this._stencilState=!0,(this.getParameter(this.STENCIL_WRITEMASK)!==this.getParameter(this.STENCIL_BACK_WRITEMASK)||this.getParameter(this.STENCIL_VALUE_MASK)!==this.getParameter(this.STENCIL_BACK_VALUE_MASK)||this.getParameter(this.STENCIL_REF)!==this.getParameter(this.STENCIL_BACK_REF))&&(this.setError(this.INVALID_OPERATION),this._stencilState=!1),this._stencilState):this._stencilState}_checkTextureTarget(e){let t=this._getActiveTextureUnit(),n=null;if(e===this.TEXTURE_2D)n=t._bind2D;else if(e===this.TEXTURE_CUBE_MAP)n=t._bindCube;else return this.setError(this.INVALID_ENUM),!1;return n?!0:(this.setError(this.INVALID_OPERATION),!1)}_checkWrapper(e,t){return this._checkValid(e,t)?this._checkOwns(e)?!0:(this.setError(this.INVALID_OPERATION),!1):(this.setError(this.INVALID_VALUE),!1)}_checkValid(e,t){return e instanceof t&&e._!==0}_checkVertexAttribState(e){let t=this._activeProgram;if(!t)return this.setError(this.INVALID_OPERATION),!1;let n=this._vertexObjectState._attribs;for(let r=0;r<n.length;++r){let i=n[r];if(i._isPointer){let n=i._pointerBuffer;if(!n)return this.setError(this.INVALID_OPERATION),!1;if(t._attributes.indexOf(r)>=0){let t=0;if(t=i._divisor?i._pointerSize+i._pointerOffset:i._pointerStride*e+i._pointerSize+i._pointerOffset,t>n._size)return this.setError(this.INVALID_OPERATION),!1}}}return!0}_checkVertexIndex(e){return e<0||e>=this._vertexObjectState._attribs.length?(this.setError(this.INVALID_VALUE),!1):!0}_computePixelSize(e,t){let n=u(this,t);if(n===0)return this.setError(this.INVALID_ENUM),0;switch(e){case this.UNSIGNED_BYTE:return n;case this.UNSIGNED_SHORT_5_6_5:if(t!==this.RGB){this.setError(this.INVALID_OPERATION);break}return 2;case this.UNSIGNED_SHORT_4_4_4_4:case this.UNSIGNED_SHORT_5_5_5_1:if(t!==this.RGBA){this.setError(this.INVALID_OPERATION);break}return 2;case this.FLOAT:return 1}return this.setError(this.INVALID_ENUM),0}_computeRowStride(e,t){let n=e*t;return n%this._unpackAlignment&&(n+=this._unpackAlignment-n%this._unpackAlignment),n}_fixupLink(e){if(!this._gl.getProgramParameter(e._,this.LINK_STATUS))return e._linkInfoLog=this._gl.getProgramInfoLog(e._),!1;let t=this.getProgramParameter(e,this.ACTIVE_ATTRIBUTES),n=Array(t);e._attributes.length=t;for(let r=0;r<t;++r)n[r]=this.getActiveAttrib(e,r)?.name,e._attributes[r]=this.getAttribLocation(e,n[r])|0;for(let t=0;t<n.length;++t)if(n[t].length>256)return e._linkInfoLog=`attribute `+n[t]+` is too long`,!1;for(let r=0;r<t;++r)e._attributes[r]<0||this._gl.bindAttribLocation(e._|0,e._attributes[r],n[r]);if(this._gl.linkProgram(e._|0),!this._gl.getProgramParameter(e._|0,this.LINK_STATUS))return e._linkInfoLog=this._gl.getProgramInfoLog(e._),!1;let r=this.getProgramParameter(e,this.ACTIVE_UNIFORMS);e._uniforms.length=r;for(let t=0;t<r;++t){let n=this.getActiveUniform(e,t);n&&(e._uniforms[t]=n)}for(let t=0;t<e._uniforms.length;++t)if(e._uniforms[t].name.length>256)return e._linkInfoLog=`uniform `+e._uniforms[t].name+` is too long`,!1;return e._linkInfoLog=``,!0}_framebufferOk(){let e=this._activeFramebuffer;return e&&this._preCheckFramebufferStatus(e)!==this.FRAMEBUFFER_COMPLETE?(this.setError(this.INVALID_FRAMEBUFFER_OPERATION),!1):!0}_getActiveBuffer(e){return e===this.ARRAY_BUFFER?this._vertexGlobalState._arrayBufferBinding:e===this.ELEMENT_ARRAY_BUFFER?this._vertexObjectState._elementArrayBufferBinding:null}_getActiveTextureUnit(){return this._textureUnits[this._activeTextureUnit]}_getActiveTexture(e){let t=this._getActiveTextureUnit();return e===this.TEXTURE_2D?t._bind2D:e===this.TEXTURE_CUBE_MAP?t._bindCube:null}_getAttachments(){return this._extensions.webgl_draw_buffers?this._extensions.webgl_draw_buffers._ALL_ATTACHMENTS:this.DEFAULT_ATTACHMENTS}_getColorAttachments(){return this._extensions.webgl_draw_buffers?this._extensions.webgl_draw_buffers._ALL_COLOR_ATTACHMENTS:this.DEFAULT_COLOR_ATTACHMENTS}_getParameterDirect(e){return this._gl.getParameterx(e)?.deepUnpack()}_getTexImage(e){let t=this._getActiveTextureUnit();return e===this.TEXTURE_2D?t._bind2D:_(this,e)?t._bindCube:(this.setError(this.INVALID_ENUM),null)}_preCheckFramebufferStatus(e){let t=e._attachments,n=[],r=[],i=t[this.DEPTH_ATTACHMENT],a=t[this.DEPTH_STENCIL_ATTACHMENT],o=t[this.STENCIL_ATTACHMENT];if(a&&(o||i)||o&&i)return this.FRAMEBUFFER_UNSUPPORTED;let s=this._getColorAttachments(),c=0;for(let e in t)t[e]&&s.indexOf(Number(e))!==-1&&c++;if(c===0)return this.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;if(a instanceof z)return this.FRAMEBUFFER_UNSUPPORTED;if(a instanceof F){if(a._format!==this.DEPTH_STENCIL)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;n.push(a._width),r.push(a._height)}if(i instanceof z)return this.FRAMEBUFFER_UNSUPPORTED;if(i instanceof F){if(i._format!==this.DEPTH_COMPONENT16)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;n.push(i._width),r.push(i._height)}if(o instanceof z)return this.FRAMEBUFFER_UNSUPPORTED;if(o instanceof F){if(o._format!==this.STENCIL_INDEX8)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;n.push(o._width),r.push(o._height)}let l=!1;for(let i=0;i<s.length;++i){let a=t[s[i]];if(a instanceof z){if(a._format!==this.RGBA||!(a._type===this.UNSIGNED_BYTE||a._type===this.FLOAT))return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;l=!0;let t=e._attachmentLevel[this.COLOR_ATTACHMENT0];if(t===null)throw TypeError(`level is null!`);n.push(a._levelWidth[t]),r.push(a._levelHeight[t])}else if(a instanceof F){let e=a._format;if(e!==this.RGBA4&&e!==this.RGB565&&e!==this.RGB5_A1)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;l=!0,n.push(a._width),r.push(a._height)}}if(!l&&!o&&!i&&!a)return this.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;if(n.length<=0||r.length<=0)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;for(let e=1;e<n.length;++e)if(n[e-1]!==n[e]||r[e-1]!==r[e])return this.FRAMEBUFFER_INCOMPLETE_DIMENSIONS;return n[0]===0||r[0]===0?this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:(e._width=n[0],e._height=r[0],this.FRAMEBUFFER_COMPLETE)}_isConstantBlendFunc(e){return e===this.CONSTANT_COLOR||e===this.ONE_MINUS_CONSTANT_COLOR||e===this.CONSTANT_ALPHA||e===this.ONE_MINUS_CONSTANT_ALPHA}_isObject(e,t,n){if(e!=null&&!(e instanceof n))throw TypeError(t+`(`+n.name+`)`);return!!(this._checkValid(e,n)&&this._checkOwns(e))}_resizeDrawingBuffer(e,t){let r=this._activeFramebuffer,i=this._getActiveTexture(this.TEXTURE_2D),a=this._activeRenderbuffer,o=this._contextAttributes,s=this._drawingBuffer;s?._framebuffer&&this._gl.bindFramebuffer(this.FRAMEBUFFER,s?._framebuffer);let c=this._getAttachments();for(let e=0;e<c.length;++e)this._gl.framebufferTexture2D(this.FRAMEBUFFER,c[e],this.TEXTURE_2D,0,0);s?._color&&this._gl.bindTexture(this.TEXTURE_2D,s?._color);let l=o.alpha?this.RGBA:this.RGB;this._gl.texImage2D(this.TEXTURE_2D,0,l,e,t,0,l,this.UNSIGNED_BYTE,n(null)),this._gl.texParameteri(this.TEXTURE_2D,this.TEXTURE_MIN_FILTER,this.NEAREST),this._gl.texParameteri(this.TEXTURE_2D,this.TEXTURE_MAG_FILTER,this.NEAREST),s?._color&&this._gl.framebufferTexture2D(this.FRAMEBUFFER,this.COLOR_ATTACHMENT0,this.TEXTURE_2D,s?._color,0);let u=0,d=0;o.depth&&o.stencil?(u=this.DEPTH_STENCIL,d=this.DEPTH_STENCIL_ATTACHMENT):o.depth?(u=33191,d=this.DEPTH_ATTACHMENT):o.stencil&&(u=this.STENCIL_INDEX8,d=this.STENCIL_ATTACHMENT),u&&(s?._depthStencil&&this._gl.bindRenderbuffer(this.RENDERBUFFER,s?._depthStencil),this._gl.renderbufferStorage(this.RENDERBUFFER,u,e,t),s?._depthStencil&&this._gl.framebufferRenderbuffer(this.FRAMEBUFFER,d,this.RENDERBUFFER,s?._depthStencil)),this.bindFramebuffer(this.FRAMEBUFFER,r),this.bindTexture(this.TEXTURE_2D,i),this.bindRenderbuffer(this.RENDERBUFFER,a)}_restoreError(e){let t=this._errorStack.pop();t===this.NO_ERROR?this.setError(e):t&&this.setError(t)}_saveError(){this._errorStack.push(this.getError())}_switchActiveProgram(e){e&&(--e._refCount,e._checkDelete())}_tryDetachFramebuffer(e,t){if(e&&e._linked(t)){let n=this._getAttachments(),r=Object.keys(e._attachments);for(let i=0;i<r.length;++i)e._attachments[n[i]]===t&&this.framebufferTexture2D(this.FRAMEBUFFER,n[i]|0,this.TEXTURE_2D,null)}}_updateFramebufferAttachments(e){if(!e)return;let t=e._status,n=this._getAttachments();if(e._status=this._preCheckFramebufferStatus(e),e._status!==this.FRAMEBUFFER_COMPLETE){if(t===this.FRAMEBUFFER_COMPLETE)for(let t=0;t<n.length;++t){let r=n[t];this._gl.framebufferTexture2D(this.FRAMEBUFFER,r,e._attachmentFace[r]||0,0,e._attachmentLevel[r]||0)}return}for(let t=0;t<n.length;++t){let r=n[t];this._gl.framebufferTexture2D(this.FRAMEBUFFER,r,e._attachmentFace[r]||0,0,e._attachmentLevel[r]||0)}for(let t=0;t<n.length;++t){let r=n[t],i=e._attachments[r];i instanceof z?this._gl.framebufferTexture2D(this.FRAMEBUFFER,r,e._attachmentFace[r]||0,i._|0,e._attachmentLevel[r]||0):i instanceof F&&this._gl.framebufferRenderbuffer(this.FRAMEBUFFER,r,this.RENDERBUFFER,i._|0)}}_validBlendFunc(e){return e===this.ZERO||e===this.ONE||e===this.SRC_COLOR||e===this.ONE_MINUS_SRC_COLOR||e===this.DST_COLOR||e===this.ONE_MINUS_DST_COLOR||e===this.SRC_ALPHA||e===this.ONE_MINUS_SRC_ALPHA||e===this.DST_ALPHA||e===this.ONE_MINUS_DST_ALPHA||e===this.SRC_ALPHA_SATURATE||e===this.CONSTANT_COLOR||e===this.ONE_MINUS_CONSTANT_COLOR||e===this.CONSTANT_ALPHA||e===this.ONE_MINUS_CONSTANT_ALPHA}_validBlendMode(e){return e===this.FUNC_ADD||e===this.FUNC_SUBTRACT||e===this.FUNC_REVERSE_SUBTRACT||this._extensions.ext_blend_minmax&&(e===this._extensions.ext_blend_minmax.MIN_EXT||e===this._extensions.ext_blend_minmax.MAX_EXT)}_validCubeTarget(e){return e===this.TEXTURE_CUBE_MAP_POSITIVE_X||e===this.TEXTURE_CUBE_MAP_NEGATIVE_X||e===this.TEXTURE_CUBE_MAP_POSITIVE_Y||e===this.TEXTURE_CUBE_MAP_NEGATIVE_Y||e===this.TEXTURE_CUBE_MAP_POSITIVE_Z||e===this.TEXTURE_CUBE_MAP_NEGATIVE_Z}_validFramebufferAttachment(e){switch(e){case this.DEPTH_ATTACHMENT:case this.STENCIL_ATTACHMENT:case this.DEPTH_STENCIL_ATTACHMENT:case this.COLOR_ATTACHMENT0:return!0}if(this._extensions.webgl_draw_buffers){let{webgl_draw_buffers:t}=this._extensions;return e<t.COLOR_ATTACHMENT0_WEBGL+t._maxDrawBuffers}return!1}_validGLSLIdentifier(e){return!(e.indexOf(`webgl_`)===0||e.indexOf(`_webgl_`)===0||e.length>256)}_validTextureTarget(e){return e===this.TEXTURE_2D||e===this.TEXTURE_CUBE_MAP}_verifyTextureCompleteness(e,t,n){let r=this._getActiveTextureUnit(),i=null;if(e===this.TEXTURE_2D?i=r._bind2D:this._validCubeTarget(e)&&(i=r._bindCube),this._extensions.oes_texture_float&&!this._extensions.oes_texture_float_linear&&i&&i._type===this.FLOAT&&(t===this.TEXTURE_MAG_FILTER||t===this.TEXTURE_MIN_FILTER)&&(n===this.LINEAR||n===this.LINEAR_MIPMAP_NEAREST||n===this.NEAREST_MIPMAP_LINEAR||n===this.LINEAR_MIPMAP_LINEAR)){i._complete=!1,this.bindTexture(e,i);return}i&&i._complete===!1&&(i._complete=!0,this.bindTexture(e,i))}_wrapShader(e,t){let n=t.startsWith(`#version`)||t.includes(`
3
- #version`),r=``;if(!this._extensions.oes_standard_derivatives&&/#ifdef\s+GL_OES_standard_derivatives/.test(t)&&(r+=`#undef GL_OES_standard_derivatives
4
- `),!this._extensions.webgl_draw_buffers&&!n&&(r+=`#define gl_MaxDrawBuffers 1
5
- `),n){if(r){let e=t.indexOf(`
6
- `);t=e===-1?t+`
7
- `+r:t.slice(0,e+1)+r+t.slice(e+1)}}else if(this.canvas){let e=this.canvas.getGlArea().get_use_es(),n=/\b(attribute|varying)\b/.test(t)?e?`100`:`120`:this._getGlslVersion(e);n?t=`#version `+n+`
8
- `+r+t:r&&(t=r+t)}else r&&(t=r+t);return t}_allocateDrawingBuffer(e,t){this._drawingBuffer=new N(this._gl.createFramebuffer(),this._gl.createTexture(),this._gl.createRenderbuffer()),this._resizeDrawingBuffer(e,t)}getContextAttributes(){return this._contextAttributes}getExtension(e){let t=e.toLowerCase();if(t in this._extensions)return this._extensions[t];let n=J[t]?J[t](this):null;return n&&(this._extensions[t]=n),n}bufferData(e=0,t,i=0){let a=0,o=null;if(typeof t==`number`?a=t:typeof t==`object`&&(o=t),i!==this.STREAM_DRAW&&i!==this.STATIC_DRAW&&i!==this.DYNAMIC_DRAW){this.setError(this.INVALID_ENUM);return}if(e!==this.ARRAY_BUFFER&&e!==this.ELEMENT_ARRAY_BUFFER){this.setError(this.INVALID_ENUM);return}let s=this._getActiveBuffer(e);if(!s){this.setError(this.INVALID_OPERATION);return}if(o){let t=null;if(d(o)||o instanceof DataView||o instanceof ArrayBuffer)t=r(o);else{this.setError(this.INVALID_VALUE);return}this._saveError(),this._gl.bufferData(e,n(t),i);let a=this.getError();if(this._restoreError(a),a!==this.NO_ERROR)return;s._size=t.length,e===this.ELEMENT_ARRAY_BUFFER&&(s._elements=new Uint8Array(t))}else if(typeof t==`number`){if(a<0){this.setError(this.INVALID_VALUE);return}this._saveError(),this._gl.bufferDataSizeOnly(e,a,i);let t=this.getError();if(this._restoreError(t),t!==this.NO_ERROR)return;s._size=a,e===this.ELEMENT_ARRAY_BUFFER&&(s._elements=new Uint8Array(a))}else this.setError(this.INVALID_VALUE)}bufferSubData(e=0,t=0,i){if(e!==this.ARRAY_BUFFER&&e!==this.ELEMENT_ARRAY_BUFFER){this.setError(this.INVALID_ENUM);return}if(typeof i!=`object`||!i)throw TypeError(`bufferSubData: data must be a BufferSource`);let a=this._getActiveBuffer(e);if(!a){this.setError(this.INVALID_OPERATION);return}if(t<0||t>=a._size){this.setError(this.INVALID_VALUE);return}let o=null;if(d(i)||i instanceof DataView||i instanceof ArrayBuffer)o=r(i);else{this.setError(this.INVALID_VALUE);return}if(t+o.length>a._size){this.setError(this.INVALID_VALUE);return}e===this.ELEMENT_ARRAY_BUFFER&&a._elements.set(o,t),this._gl.bufferSubData(e,t,n(o))}compressedTexImage2D(e,t,i,a,o,s,c){return this._gl.compressedTexImage2D(e,t,i,a,o,s,n(r(c)))}compressedTexSubImage2D(e,t,i,a,o,s,c,l){return this._gl.compressedTexSubImage2D(e,t,i,a,o,s,c,n(r(l)))}readPixels(e=0,t=0,i=0,a=0,o=0,s=0,c){if(!c)return;if(!(this._extensions.oes_texture_float&&s===this.FLOAT&&o===this.RGBA)){if(o===this.RGB||o===this.ALPHA||s!==this.UNSIGNED_BYTE){this.setError(this.INVALID_OPERATION);return}else if(o!==this.RGBA){this.setError(this.INVALID_ENUM);return}else if(i<0||a<0||!(c instanceof Uint8Array)){this.setError(this.INVALID_VALUE);return}}if(!this._framebufferOk()){console.error(`framebuffer is not okay!`);return}let l=i*4;l%this._packAlignment!==0&&(l+=this._packAlignment-l%this._packAlignment);let u=l*(a-1)+i*4;if(u<=0)return;if((c.length||c.byteLength||0)<u){this.setError(this.INVALID_VALUE);return}let d=this.drawingBufferWidth,f=this.drawingBufferHeight;this._activeFramebuffer&&(d=this._activeFramebuffer._width,f=this._activeFramebuffer._height);let p=r(c);if(e>=d||e+i<=0||t>=f||t+a<=0)for(let e=0;e<p.length;++e)p[e]=0;else if(e<0||e+i>d||t<0||t+a>f){for(let e=0;e<p.length;++e)p[e]=0;let r=e,c=i;e<0&&(c+=e,r=0),r+i>d&&(c=d-r);let u=t,m=a;t<0&&(m+=t,u=0),u+a>f&&(m=f-u);let h=c*4;if(h%this._packAlignment!==0&&(h+=this._packAlignment-h%this._packAlignment),c>0&&m>0){let i=new Uint8Array(h*m),a=this._gl.readPixels(r,u,c,m,o,s,n(i)),d=a&&a.length>0?a:i,f=4*(r-e)+(u-t)*l;for(let e=0;e<m;++e)for(let t=0;t<c;++t)for(let n=0;n<4;++n)p[f+e*l+4*t+n]=d[e*h+4*t+n]}}else{let r=this._gl.readPixels(e,t,i,a,o,s,n(p));r&&r.length>0&&p.set(r)}}texImage2D(e=0,t=0,r=0,a=0,o=0,l=0,u=0,d=0,f){let p=0,h=0,g=0,v,y,b=0;if(arguments.length===6)if(d=o,g=a,l instanceof G.Pixbuf)y=l,p=y.get_width(),h=y.get_height(),f=y.get_pixels();else{v=l;let e=c(v);if(e==null)throw TypeError(`texImage2D(GLenum, GLint, GLenum, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)`);p=e.width,h=e.height,f=e.data}else arguments.length===9&&(p=a,h=o,b=l,g=u,d=d,f=f);if(typeof f!=`object`&&f!==void 0)throw TypeError(`texImage2D(GLenum, GLint, GLenum, GLint, GLint, GLint, GLenum, GLenum, Uint8Array)`);if(!i(this,g)||!i(this,r)){this.setError(this.INVALID_ENUM);return}if(d===this.FLOAT&&!this._extensions.oes_texture_float){this.setError(this.INVALID_ENUM);return}let x=this._getTexImage(e);if(!x||g!==r){this.setError(this.INVALID_OPERATION);return}let S=this._computePixelSize(d,g);if(S===0||!this._checkDimensions(e,p,h,t))return;let C=s(f),w=this._computeRowStride(p,S),T=w*h;if(C&&C.length<T){this.setError(this.INVALID_OPERATION);return}if(b!==0||_(this,e)&&p!==h){this.setError(this.INVALID_VALUE);return}if(this._unpackPremultAlpha&&C&&g===this.RGBA&&(C=m(C)),this._unpackFlipY&&C&&p>0&&h>0){let e=new Uint8Array(C.length);for(let t=0;t<h;t++){let n=t*w,r=(h-1-t)*w;e.set(C.subarray(n,n+w),r)}C=e}this._saveError(),this._gl.texImage2D(e,t,r,p,h,b,g,d,n(C));let E=this.getError();if(this._restoreError(E),E!==this.NO_ERROR)return;x._levelWidth[t]=p,x._levelHeight[t]=h,x._format=g,x._type=d;let D=this._activeFramebuffer;if(D){let e=!1,t=this._getAttachments();for(let n=0;n<t.length;++n)if(D._attachments[t[n]]===x){e=!0;break}e&&this._activeFramebuffer&&this._updateFramebufferAttachments(this._activeFramebuffer)}}texSubImage2D(e=0,t=0,r=0,i=0,a=0,o=0,l=0,u=0,d){let f=0,p=0,h=0,g,_;if(arguments.length===7)if(u=o,h=a,l instanceof G.Pixbuf)_=l,f=_.get_width(),p=_.get_height(),d=_.get_pixels();else{g=l;let e=c(g);if(e==null)throw TypeError(`texSubImage2D(GLenum, GLint, GLint, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)`);f=e.width,p=e.height,d=e.data}else f=a,p=o,h=l;if(typeof d!=`object`)throw TypeError(`texSubImage2D(GLenum, GLint, GLint, GLint, GLint, GLint, GLenum, GLenum, Uint8Array)`);if(!this._getTexImage(e)){this.setError(this.INVALID_OPERATION);return}if(u===this.FLOAT&&!this._extensions.oes_texture_float){this.setError(this.INVALID_ENUM);return}let v=this._computePixelSize(u,h);if(v===0||!this._checkDimensions(e,f,p,t))return;if(r<0||i<0){this.setError(this.INVALID_VALUE);return}let y=s(d),b=this._computeRowStride(f,v),x=b*p;if(!y||y.length<x){this.setError(this.INVALID_OPERATION);return}if(this._unpackPremultAlpha&&y&&h===this.RGBA&&(y=m(y)),this._unpackFlipY&&y&&f>0&&p>0){let e=new Uint8Array(y.length);for(let t=0;t<p;t++){let n=t*b,r=(p-1-t)*b;e.set(y.subarray(n,n+b),r)}y=e}this._gl.texSubImage2D(e,t,r,i,f,p,h,u,n(y))}_checkUniformValid(e,t,n,r,i){if(!a(e))throw TypeError(`${n}(WebGLUniformLocation, ...)`);if(!e)return!1;if(this._checkLocationActive(e)){let n=e._activeInfo.type;if(n===this.SAMPLER_2D||n===this.SAMPLER_CUBE){if(r!==1){this.setError(this.INVALID_VALUE);return}if(i!==`i`){this.setError(this.INVALID_OPERATION);return}if(t<0||t>=this._textureUnits.length)return this.setError(this.INVALID_VALUE),!1}return g(this,n)>r?(this.setError(this.INVALID_OPERATION),!1):!0}return!1}_checkUniformValueValid(e,t,n,r,i){if(!a(e)||!a(t))throw TypeError(`${n}v(WebGLUniformLocation, Array)`);if(!e||!this._checkLocationActive(e))return!1;if(typeof t!=`object`||!t||typeof t.length!=`number`)throw TypeError(`Second argument to ${n} must be array`);return g(this,e._activeInfo.type)>r?(this.setError(this.INVALID_OPERATION),!1):t.length>=r&&t.length%r===0?e._array||t.length===r?!0:(this.setError(this.INVALID_OPERATION),!1):(this.setError(this.INVALID_VALUE),!1)}uniform1fv(e,t){if(!(!e||!this._checkUniformValueValid(e,t,`uniform1fv`,1,`f`))){if(e?._array){let n=e._array;for(let e=0;e<n.length&&e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform1f(r,t[e])}return}this._gl.uniform1f(e?._|0,t[0])}}uniform1iv(e,t){if(this._checkUniformValueValid(e,t,`uniform1iv`,1,`i`)){if(e?._array){let n=e._array;for(let e=0;e<n.length&&e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform1i(r,t[e])}return}this.uniform1i(e,t[0])}}uniform2fv(e,t){if(this._checkUniformValueValid(e,t,`uniform2fv`,2,`f`)){if(e?._array){let n=e._array;for(let e=0;e<n.length&&2*e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform2f(r,t[2*e],t[2*e+1])}return}this._gl.uniform2f(e?._||0,t[0],t[1])}}uniform2iv(e,t){if(this._checkUniformValueValid(e,t,`uniform2iv`,2,`i`)){if(e?._array){let n=e._array;for(let e=0;e<n.length&&2*e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform2i(r,t[2*e],t[2*e+1])}return}this.uniform2i(e,t[0],t[1])}}uniform3fv(e,t){if(this._checkUniformValueValid(e,t,`uniform3fv`,3,`f`)){if(e?._array){let n=e._array;for(let e=0;e<n.length&&3*e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform3f(r,t[3*e],t[3*e+1],t[3*e+2])}return}this._gl.uniform3f(e?._||0,t[0],t[1],t[2])}}uniform3iv(e,t){if(this._checkUniformValueValid(e,t,`uniform3iv`,3,`i`)){if(e?._array){let n=e._array;for(let e=0;e<n.length&&3*e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform3i(r,t[3*e],t[3*e+1],t[3*e+2])}return}this.uniform3i(e,t[0],t[1],t[2])}}uniform4fv(e,t){if(this._checkUniformValueValid(e,t,`uniform4fv`,4,`f`)){if(e?._array){let n=e._array;for(let e=0;e<n.length&&4*e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform4f(r,t[4*e],t[4*e+1],t[4*e+2],t[4*e+3])}return}this._gl.uniform4f(e?._||0,t[0],t[1],t[2],t[3])}}uniform4iv(e,t){if(this._checkUniformValueValid(e,t,`uniform4iv`,4,`i`)){if(e?._array){let n=e._array;for(let e=0;e<n.length&&4*e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform4i(r,t[4*e],t[4*e+1],t[4*e+2],t[4*e+3])}return}this.uniform4i(e,t[0],t[1],t[2],t[3])}}_checkUniformMatrix(e,t,n,r,i){if(!a(e)||typeof n!=`object`)throw TypeError(r+`(WebGLUniformLocation, Boolean, Array)`);return t||typeof n!=`object`||!n||!n.length||n.length%i*i!==0?(this.setError(this.INVALID_VALUE),!1):!e||!this._checkLocationActive(e)?!1:n.length===i*i||e._array?!0:(this.setError(this.INVALID_VALUE),!1)}uniformMatrix2fv(e,t,n){if(!this._checkUniformMatrix(e,t,n,`uniformMatrix2fv`,2))return;let r=new Float32Array(n);this._gl.uniformMatrix2fv(e?._||0,!!t,p(r))}uniformMatrix3fv(e,t,n){if(!this._checkUniformMatrix(e,t,n,`uniformMatrix3fv`,3))return;let r=new Float32Array(n);this._gl.uniformMatrix3fv(e?._||0,!!t,p(r))}uniformMatrix4fv(e,t,n){if(!this._checkUniformMatrix(e,t,n,`uniformMatrix4fv`,4))return;let r=new Float32Array(n);this._gl.uniformMatrix4fv(e?._||0,!!t,p(r))}activeTexture(e=0){let t=e-this.TEXTURE0;if(t>=0&&t<this._textureUnits.length)return this._activeTextureUnit=t,this._gl.activeTexture(e);this.setError(this.INVALID_ENUM)}attachShader(e,t){if(!a(e)||!a(t))throw TypeError(`attachShader(WebGLProgram, WebGLShader)`);if(!e||!t){this.setError(this.INVALID_VALUE);return}else if(e instanceof P&&t instanceof I&&this._checkOwns(e)&&this._checkOwns(t)&&!e._linked(t)){this._saveError(),this._gl.attachShader(e._|0,t._|0);let n=this.getError();this._restoreError(n),n===this.NO_ERROR&&e._link(t);return}this.setError(this.INVALID_OPERATION)}bindAttribLocation(e,t,n){if(!a(e)||typeof n!=`string`)throw TypeError(`bindAttribLocation(WebGLProgram, GLint, String)`);if(n+=``,!f(n)||n.length>256)this.setError(this.INVALID_VALUE);else if(/^_?webgl_a/.test(n))this.setError(this.INVALID_OPERATION);else if(this._checkWrapper(e,P))return this._gl.bindAttribLocation(e._|0,t|0,n)}bindBuffer(e=0,t){if(!a(t))throw TypeError(`bindBuffer(GLenum, WebGLBuffer)`);if(e!==this.ARRAY_BUFFER&&e!==this.ELEMENT_ARRAY_BUFFER){this.setError(this.INVALID_ENUM);return}if(!t)t=null,this._gl.bindBuffer(e,0);else if(t._pendingDelete)return;else if(this._checkWrapper(t,M)){if(t._binding&&t._binding!==e){this.setError(this.INVALID_OPERATION);return}t._binding=e|0,this._gl.bindBuffer(e,t._|0)}else return;e===this.ARRAY_BUFFER?this._vertexGlobalState.setArrayBuffer(t):this._vertexObjectState.setElementArrayBuffer(t)}bindFramebuffer(e,t){if(!a(t))throw TypeError(`bindFramebuffer(GLenum, WebGLFramebuffer)`);if(e!==this.FRAMEBUFFER){this.setError(this.INVALID_ENUM);return}if(!t)this._gl.bindFramebuffer(this.FRAMEBUFFER,this._gtkFboId);else if(t._pendingDelete)return;else if(this._checkWrapper(t,j))this._gl.bindFramebuffer(this.FRAMEBUFFER,t._|0);else return;let n=this._activeFramebuffer;n!==t&&(n&&(--n._refCount,n._checkDelete()),t&&(t._refCount+=1)),this._activeFramebuffer=t,t&&this._updateFramebufferAttachments(t)}bindRenderbuffer(e,t){if(!a(t))throw TypeError(`bindRenderbuffer(GLenum, WebGLRenderbuffer)`);if(e!==this.RENDERBUFFER){this.setError(this.INVALID_ENUM);return}if(!t)this._gl.bindRenderbuffer(e|0,0);else if(t._pendingDelete)return;else if(this._checkWrapper(t,F))this._gl.bindRenderbuffer(e|0,t._|0);else return;let n=this._activeRenderbuffer;n!==t&&(n&&(--n._refCount,n._checkDelete()),t&&(t._refCount+=1)),this._activeRenderbuffer=t}bindTexture(e=0,t){if(!a(t))throw TypeError(`bindTexture(GLenum, WebGLTexture)`);if(!this._validTextureTarget(e)){this.setError(this.INVALID_ENUM);return}let n=0;if(!t)t=null;else if(t instanceof z&&t._pendingDelete)return;else if(this._checkWrapper(t,z)){if(t._binding&&t._binding!==e){this.setError(this.INVALID_OPERATION);return}t._binding=e,t._complete&&(n=t._|0)}else return;this._saveError(),this._gl.bindTexture(e,n);let r=this.getError();if(this._restoreError(r),r!==this.NO_ERROR)return;let i=this._getActiveTextureUnit(),o=this._getActiveTexture(e);o!==t&&(o&&(--o._refCount,o._checkDelete()),t&&(t._refCount+=1)),e===this.TEXTURE_2D?i._bind2D=t:e===this.TEXTURE_CUBE_MAP&&(i._bindCube=t)}blendColor(e=0,t=0,n=0,r=0){return this._gl.blendColor(+e,+t,+n,+r)}blendEquation(e=0){if(this._validBlendMode(e))return this._gl.blendEquation(e);this.setError(this.INVALID_ENUM)}blendEquationSeparate(e=0,t=0){if(this._validBlendMode(e)&&this._validBlendMode(t))return this._gl.blendEquationSeparate(e,t);this.setError(this.INVALID_ENUM)}blendFunc(e=0,t=0){if(!this._validBlendFunc(e)||!this._validBlendFunc(t)){this.setError(this.INVALID_ENUM);return}if(this._isConstantBlendFunc(e)&&this._isConstantBlendFunc(t)){this.setError(this.INVALID_OPERATION);return}this._gl.blendFunc(e,t)}blendFuncSeparate(e=0,t=0,n=0,r=0){if(!(this._validBlendFunc(e)&&this._validBlendFunc(t)&&this._validBlendFunc(n)&&this._validBlendFunc(r))){this.setError(this.INVALID_ENUM);return}if(this._isConstantBlendFunc(e)&&this._isConstantBlendFunc(t)||this._isConstantBlendFunc(n)&&this._isConstantBlendFunc(r)){this.setError(this.INVALID_OPERATION);return}this._gl.blendFuncSeparate(e,t,n,r)}checkFramebufferStatus(e){if(e!==this.FRAMEBUFFER)return this.setError(this.INVALID_ENUM),0;let t=this._activeFramebuffer;return t?this._preCheckFramebufferStatus(t):this.FRAMEBUFFER_COMPLETE}clear(e=0){if(this._framebufferOk())return this._gl.clear(e)}clearColor(e,t,n,r){return this._gl.clearColor(+e,+t,+n,+r)}clearDepth(e){return this._gl.clearDepth(+e)}clearStencil(e=0){return this._checkStencil=!1,this._gl.clearStencil(e)}colorMask(e,t,n,r){return this._gl.colorMask(!!e,!!t,!!n,!!r)}compileShader(e){if(!a(e))throw TypeError(`compileShader(WebGLShader)`);if(this._checkWrapper(e,I)&&this._checkShaderSource(e)){let t=this.getError();this._gl.compileShader(e._|0),e._needsRecompile=!1;let n=this.getError();e._compileStatus=!!this._gl.getShaderParameter(e._|0,this.COMPILE_STATUS),e._compileInfo=this._gl.getShaderInfoLog(e._|0)||`null`,this.getError(),this.setError(t||n)}}copyTexImage2D(e=0,t=0,n=0,r=0,i=0,a=0,o=0,s=0){let c=this._getTexImage(e);if(!c){this.setError(this.INVALID_OPERATION);return}if(n!==this.RGBA&&n!==this.RGB&&n!==this.ALPHA&&n!==this.LUMINANCE&&n!==this.LUMINANCE_ALPHA){this.setError(this.INVALID_ENUM);return}if(t<0||a<0||o<0||s!==0){this.setError(this.INVALID_VALUE);return}if(t>0&&!(U.isPow2(a)&&U.isPow2(o))){this.setError(this.INVALID_VALUE);return}this._saveError(),this._gl.copyTexImage2D(e,t,n,r,i,a,o,s);let l=this.getError();this._restoreError(l),l===this.NO_ERROR&&(c._levelWidth[t]=a,c._levelHeight[t]=o,c._format=this.RGBA,c._type=this.UNSIGNED_BYTE)}copyTexSubImage2D(e=0,t=0,n=0,r=0,i=0,a=0,o=0,s=0){if(!this._getTexImage(e)){this.setError(this.INVALID_OPERATION);return}if(o<0||s<0||n<0||r<0||t<0){this.setError(this.INVALID_VALUE);return}this._gl.copyTexSubImage2D(e,t,n,r,i,a,o,s)}createBuffer(){let e=this._gl.createBuffer();if(!e||e<=0)return null;let t=new M(e,this);return this._buffers[e]=t,t}createFramebuffer(){let e=this._gl.createFramebuffer();if(e<=0)return null;let t=new j(e,this);return this._framebuffers[e]=t,t}createProgram(){let e=this._gl.createProgram();if(e<=0)return null;let t=new P(e,this);return this._programs[e]=t,t}createRenderbuffer(){let e=this._gl.createRenderbuffer();if(e<=0)return null;let t=new F(e,this);return this._renderbuffers[e]=t,t}createShader(e=0){if(e!==this.FRAGMENT_SHADER&&e!==this.VERTEX_SHADER)return this.setError(this.INVALID_ENUM),null;let t=this._gl.createShader(e);if(t<0)return null;let n=new I(t,this,e);return this._shaders[t]=n,n}createTexture(){let e=this._gl.createTexture();if(e<=0)return null;let t=new z(e,this);return this._textures[e]=t,t}cullFace(e){return this._gl.cullFace(e|0)}deleteBuffer(e){if(!a(e)||e!==null&&!(e instanceof M))throw TypeError(`deleteBuffer(WebGLBuffer)`);if(!(e instanceof M&&this._checkOwns(e))){this.setError(this.INVALID_OPERATION);return}this._vertexGlobalState._arrayBufferBinding===e&&this.bindBuffer(this.ARRAY_BUFFER,null),this._vertexObjectState._elementArrayBufferBinding===e&&this.bindBuffer(this.ELEMENT_ARRAY_BUFFER,null),this._vertexObjectState===this._defaultVertexObjectState&&this._vertexObjectState.releaseArrayBuffer(e),e._pendingDelete=!0,e._checkDelete()}deleteFramebuffer(e){if(!a(e))throw TypeError(`deleteFramebuffer(WebGLFramebuffer)`);if(!(e instanceof j&&this._checkOwns(e))){this.setError(this.INVALID_OPERATION);return}this._activeFramebuffer===e&&this.bindFramebuffer(this.FRAMEBUFFER,null),e._pendingDelete=!0,e._checkDelete()}_deleteLinkable(e,t,n){if(!a(t))throw TypeError(e+`(`+n.name+`)`);if(t instanceof n&&this._checkOwns(t)){t._pendingDelete=!0,t._checkDelete();return}this.setError(this.INVALID_OPERATION)}deleteProgram(e){return this._deleteLinkable(`deleteProgram`,e,P)}deleteRenderbuffer(e){if(!a(e))throw TypeError(`deleteRenderbuffer(WebGLRenderbuffer)`);if(!(e instanceof F&&this._checkOwns(e))){this.setError(this.INVALID_OPERATION);return}this._activeRenderbuffer===e&&this.bindRenderbuffer(this.RENDERBUFFER,null);let t=this._activeFramebuffer;this._tryDetachFramebuffer(t,e),e._pendingDelete=!0,e._checkDelete()}deleteShader(e){return this._deleteLinkable(`deleteShader`,e,I)}deleteTexture(e){if(!a(e))throw TypeError(`deleteTexture(WebGLTexture)`);if(e instanceof z){if(!this._checkOwns(e)){this.setError(this.INVALID_OPERATION);return}}else return;let t=this._activeTextureUnit;for(let t=0;t<this._textureUnits.length;++t){let n=this._textureUnits[t];n._bind2D===e?(this.activeTexture(this.TEXTURE0+t),this.bindTexture(this.TEXTURE_2D,null)):n._bindCube===e&&(this.activeTexture(this.TEXTURE0+t),this.bindTexture(this.TEXTURE_CUBE_MAP,null))}this.activeTexture(this.TEXTURE0+t);let n=this;(t=>{if(t&&t._linked(e)){let r=n._getAttachments();for(let i=0;i<r.length;++i){let a=r[i];t._attachments[a]===e&&n.framebufferTexture2D(this.FRAMEBUFFER,a,this.TEXTURE_2D,null)}}})(this._activeFramebuffer),e._pendingDelete=!0,e._checkDelete()}depthFunc(e){switch(e|=0,e){case this.NEVER:case this.LESS:case this.EQUAL:case this.LEQUAL:case this.GREATER:case this.NOTEQUAL:case this.GEQUAL:case this.ALWAYS:return this._gl.depthFunc(e);default:this.setError(this.INVALID_ENUM)}}depthMask(e){return this._gl.depthMask(!!e)}depthRange(e,t){if(e=+e,t=+t,e<=t)return this._gl.depthRange(e,t);this.setError(this.INVALID_OPERATION)}destroy(){K(`destroy`)}detachShader(e,t){if(!a(e)||!a(t))throw TypeError(`detachShader(WebGLProgram, WebGLShader)`);this._checkWrapper(e,P)&&this._checkWrapper(t,I)&&(e._linked(t)?(this._gl.detachShader(e._,t._),e._unlink(t)):this.setError(this.INVALID_OPERATION))}disable(e=0){if(this._gl.disable(e),e===this.TEXTURE_2D||e===this.TEXTURE_CUBE_MAP){let t=this._getActiveTextureUnit();t._mode===e&&(t._mode=0)}}disableVertexAttribArray(e=0){if(e<0||e>=this._vertexObjectState._attribs.length){this.setError(this.INVALID_VALUE);return}this._gl.disableVertexAttribArray(e),this._vertexObjectState._attribs[e]._isPointer=!1}drawArrays(e=0,t=0,n=0){if(t<0||n<0){this.setError(this.INVALID_VALUE);return}if(!this._checkStencilState())return;let r=v(this,e,n);if(r<0){this.setError(this.INVALID_ENUM);return}if(!this._framebufferOk()||n===0)return;let i=t;n>0&&(i=n+t-1>>>0),this._checkVertexAttribState(i)&&this._gl.drawArrays(e,t,r)}drawElements(e=0,t=0,n=0,r=0){if(t<0||r<0){this.setError(this.INVALID_VALUE);return}if(!this._checkStencilState())return;let i=this._vertexObjectState._elementArrayBufferBinding;if(!i){this.setError(this.INVALID_OPERATION);return}let a=null,o=r;if(n===this.UNSIGNED_SHORT){if(o%2){this.setError(this.INVALID_OPERATION);return}o>>=1,a=new Uint16Array(i._elements.buffer)}else if(this._extensions.oes_element_index_uint&&n===this.UNSIGNED_INT){if(o%4){this.setError(this.INVALID_OPERATION);return}o>>=2,a=new Uint32Array(i._elements.buffer)}else if(n===this.UNSIGNED_BYTE)a=i._elements;else{this.setError(this.INVALID_ENUM);return}let s=t;switch(e){case this.TRIANGLES:t%3&&(s-=t%3);break;case this.LINES:t%2&&(s-=t%2);break;case this.POINTS:break;case this.LINE_LOOP:case this.LINE_STRIP:if(t<2){this.setError(this.INVALID_OPERATION);return}break;case this.TRIANGLE_FAN:case this.TRIANGLE_STRIP:if(t<3){this.setError(this.INVALID_OPERATION);return}break;default:this.setError(this.INVALID_ENUM);return}if(!this._framebufferOk())return;if(t===0){this._checkVertexAttribState(0);return}if(t+o>>>0>a.length){this.setError(this.INVALID_OPERATION);return}let c=-1;for(let e=o;e<o+t;++e)c=Math.max(c,a[e]);if(c<0){this._checkVertexAttribState(0);return}this._checkVertexAttribState(c)&&s>0&&this._gl.drawElements(e,s,n,r)}enable(e=0){return this._gl.enable(e)}enableVertexAttribArray(e){if(e<0||e>=this._vertexObjectState._attribs.length){this.setError(this.INVALID_VALUE);return}this._gl.enableVertexAttribArray(e),this._vertexObjectState._attribs[e]._isPointer=!0}finish(){return this._gl.finish()}flush(){return this._gl.flush()}framebufferRenderbuffer(e,t,n,r){if(!a(r))throw TypeError(`framebufferRenderbuffer(GLenum, GLenum, GLenum, WebGLRenderbuffer)`);if(e!==this.FRAMEBUFFER||!this._validFramebufferAttachment(t)||n!==this.RENDERBUFFER){this.setError(this.INVALID_ENUM);return}let i=this._activeFramebuffer;if(!i){this.setError(this.INVALID_OPERATION);return}r&&!this._checkWrapper(r,F)||(i._setAttachment(r,t),this._updateFramebufferAttachments(i))}framebufferTexture2D(e,t,n,r,i=0){if(e|=0,t|=0,n|=0,i|=0,!a(r))throw TypeError(`framebufferTexture2D(GLenum, GLenum, GLenum, WebGLTexture, GLint)`);if(e!==this.FRAMEBUFFER||!this._validFramebufferAttachment(t)){this.setError(this.INVALID_ENUM);return}if(i!==0){this.setError(this.INVALID_VALUE);return}if(r&&!this._checkWrapper(r,z))return;if(n===this.TEXTURE_2D){if(r&&r._binding!==this.TEXTURE_2D){this.setError(this.INVALID_OPERATION);return}}else if(this._validCubeTarget(n)){if(r&&r._binding!==this.TEXTURE_CUBE_MAP){this.setError(this.INVALID_OPERATION);return}}else{this.setError(this.INVALID_ENUM);return}let o=this._activeFramebuffer;if(!o){this.setError(this.INVALID_OPERATION);return}o._attachmentLevel[t]=i,o._attachmentFace[t]=n,o._setAttachment(r,t),this._updateFramebufferAttachments(o)}frontFace(e=0){return this._gl.frontFace(e)}generateMipmap(e=0){return this._gl.generateMipmap(e)}getActiveAttrib(e,t){if(!a(e))throw TypeError(`getActiveAttrib(WebGLProgram)`);if(!e)throw TypeError(`getActiveAttrib(WebGLProgram, GLuint)`);if(this._checkWrapper(e,P)){if(t>=(e._linkStatus?e._attributes.length:this._gl.getProgramParameter(e._|0,this.ACTIVE_ATTRIBUTES)))return this._gl.getError(),this.setError(this.INVALID_VALUE),null;let n=this._gl.getActiveAttrib(e._|0,t|0);if(n)return new A(n)}return null}getActiveUniform(e,t){if(!a(e))throw TypeError(`getActiveUniform(WebGLProgram, GLint)`);if(!e)throw TypeError(`getActiveUniform(WebGLProgram, GLuint)`);if(this._checkWrapper(e,P)){if(t>=(e._linkStatus?e._uniforms.length:this._gl.getProgramParameter(e._|0,this.ACTIVE_UNIFORMS)))return this.setError(this.INVALID_VALUE),null;let n=this._gl.getActiveUniform(e._|0,t|0);if(n)return new A(n)}return null}getAttachedShaders(e){if(!a(e)||typeof e==`object`&&e&&!(e instanceof P))throw TypeError(`getAttachedShaders(WebGLProgram)`);if(!e)this.setError(this.INVALID_VALUE);else if(this._checkWrapper(e,P))return e._references.filter(e=>e instanceof I);return null}getAttribLocation(e,t){if(!a(e))throw TypeError(`getAttribLocation(WebGLProgram, String)`);if(t+=``,!f(t)||t.length>256)this.setError(this.INVALID_VALUE);else if(this._checkWrapper(e,P))return this._gl.getAttribLocation(e._|0,t+``);return-1}getBufferParameter(e=0,t=0){if(e!==this.ARRAY_BUFFER&&e!==this.ELEMENT_ARRAY_BUFFER)return this.setError(this.INVALID_ENUM),null;switch(t){case this.BUFFER_SIZE:case this.BUFFER_USAGE:return this._gl.getBufferParameteriv(e|0,t|0)[0];default:return this.setError(this.INVALID_ENUM),null}}getError(){return this._gl.getError()}setError(e){this._gl.setError(e)}getFramebufferAttachmentParameter(e=0,t=0,n=0){if(e!==this.FRAMEBUFFER||!this._validFramebufferAttachment(t))return this.setError(this.INVALID_ENUM),null;let r=this._activeFramebuffer;if(!r)return this.setError(this.INVALID_OPERATION),null;let i=r._attachments[t];if(i===null){if(n===this.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)return this.NONE}else if(i instanceof z)switch(n){case this.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:return i;case this.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:return this.TEXTURE;case this.FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:return r._attachmentLevel[t];case this.FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:{let e=r._attachmentFace[t];return e===this.TEXTURE_2D?0:e}}else if(i instanceof F)switch(n){case this.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:return i;case this.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:return this.RENDERBUFFER}return this.setError(this.INVALID_ENUM),null}getParameter(e=0){switch(e){case this.ARRAY_BUFFER_BINDING:return this._vertexGlobalState._arrayBufferBinding;case this.ELEMENT_ARRAY_BUFFER_BINDING:return this._vertexObjectState._elementArrayBufferBinding;case this.CURRENT_PROGRAM:return this._activeProgram;case this.FRAMEBUFFER_BINDING:return this._activeFramebuffer;case this.RENDERBUFFER_BINDING:return this._activeRenderbuffer;case this.TEXTURE_BINDING_2D:return this._getActiveTextureUnit()._bind2D;case this.TEXTURE_BINDING_CUBE_MAP:return this._getActiveTextureUnit()._bindCube;case this.VERSION:return`WebGL 1.0 0.0.1`;case this.VENDOR:return``;case this.RENDERER:return`ANGLE`;case this.SHADING_LANGUAGE_VERSION:return`WebGL GLSL ES 1.0 `;case this.COMPRESSED_TEXTURE_FORMATS:return new Uint32Array;case this.SCISSOR_BOX:return new Int32Array(this._scissorBox);case this.VIEWPORT:return new Int32Array(this._viewport);case this.MAX_VIEWPORT_DIMS:return new Int32Array([32767,32767]);case this.ALIASED_LINE_WIDTH_RANGE:case this.ALIASED_POINT_SIZE_RANGE:return new Float32Array([1,1]);case this.DEPTH_RANGE:return new Float32Array([0,1]);case this.BLEND_COLOR:case this.COLOR_CLEAR_VALUE:return new Float32Array(this._gl.getParameterfv(e,4));case this.COLOR_WRITEMASK:{let t=this._gl.getParameteriv(e,4);return[!!t[0],!!t[1],!!t[2],!!t[3]]}case this.DEPTH_CLEAR_VALUE:case this.LINE_WIDTH:case this.POLYGON_OFFSET_FACTOR:case this.POLYGON_OFFSET_UNITS:case this.SAMPLE_COVERAGE_VALUE:return this._gl.getParameterf(e);case this.BLEND:case this.CULL_FACE:case this.DEPTH_TEST:case this.DEPTH_WRITEMASK:case this.DITHER:case this.POLYGON_OFFSET_FILL:case this.SAMPLE_COVERAGE_INVERT:case this.SCISSOR_TEST:case this.STENCIL_TEST:case this.UNPACK_PREMULTIPLY_ALPHA_WEBGL:return!!this._gl.getParameteri(e);case this.UNPACK_FLIP_Y_WEBGL:return this._unpackFlipY;case this.ACTIVE_TEXTURE:case this.ALPHA_BITS:case this.BLEND_DST_ALPHA:case this.BLEND_DST_RGB:case this.BLEND_EQUATION_ALPHA:case this.BLEND_EQUATION_RGB:case this.BLEND_SRC_ALPHA:case this.BLEND_SRC_RGB:case this.BLUE_BITS:case this.CULL_FACE_MODE:case this.DEPTH_BITS:case this.DEPTH_FUNC:case this.FRONT_FACE:case this.GENERATE_MIPMAP_HINT:case this.GREEN_BITS:case this.MAX_COMBINED_TEXTURE_IMAGE_UNITS:case this.MAX_CUBE_MAP_TEXTURE_SIZE:case this.MAX_FRAGMENT_UNIFORM_VECTORS:case this.MAX_RENDERBUFFER_SIZE:case this.MAX_TEXTURE_IMAGE_UNITS:case this.MAX_TEXTURE_SIZE:case this.MAX_VARYING_VECTORS:case this.MAX_VERTEX_ATTRIBS:case this.MAX_VERTEX_TEXTURE_IMAGE_UNITS:case this.MAX_VERTEX_UNIFORM_VECTORS:case this.PACK_ALIGNMENT:case this.RED_BITS:case this.SAMPLE_BUFFERS:case this.SAMPLES:case this.STENCIL_BACK_FAIL:case this.STENCIL_BACK_FUNC:case this.STENCIL_BACK_PASS_DEPTH_FAIL:case this.STENCIL_BACK_PASS_DEPTH_PASS:case this.STENCIL_BACK_REF:case this.STENCIL_BACK_VALUE_MASK:case this.STENCIL_BACK_WRITEMASK:case this.STENCIL_BITS:case this.STENCIL_CLEAR_VALUE:case this.STENCIL_FAIL:case this.STENCIL_FUNC:case this.STENCIL_PASS_DEPTH_FAIL:case this.STENCIL_PASS_DEPTH_PASS:case this.STENCIL_REF:case this.STENCIL_VALUE_MASK:case this.STENCIL_WRITEMASK:case this.SUBPIXEL_BITS:case this.UNPACK_ALIGNMENT:case this.UNPACK_COLORSPACE_CONVERSION_WEBGL:return this._gl.getParameteri(e);case this.IMPLEMENTATION_COLOR_READ_FORMAT:case this.IMPLEMENTATION_COLOR_READ_TYPE:return this._getParameterDirect(e);default:if(this._extensions.webgl_draw_buffers){let t=this._extensions.webgl_draw_buffers;switch(e){case t.DRAW_BUFFER0_WEBGL:case t.DRAW_BUFFER1_WEBGL:case t.DRAW_BUFFER2_WEBGL:case t.DRAW_BUFFER3_WEBGL:case t.DRAW_BUFFER4_WEBGL:case t.DRAW_BUFFER5_WEBGL:case t.DRAW_BUFFER6_WEBGL:case t.DRAW_BUFFER7_WEBGL:case t.DRAW_BUFFER8_WEBGL:case t.DRAW_BUFFER9_WEBGL:case t.DRAW_BUFFER10_WEBGL:case t.DRAW_BUFFER11_WEBGL:case t.DRAW_BUFFER12_WEBGL:case t.DRAW_BUFFER13_WEBGL:case t.DRAW_BUFFER14_WEBGL:case t.DRAW_BUFFER15_WEBGL:return t._buffersState.length===1&&t._buffersState[0]===this.BACK?this.BACK:this._getParameterDirect(e);case t.MAX_DRAW_BUFFERS_WEBGL:case t.MAX_COLOR_ATTACHMENTS_WEBGL:return this._getParameterDirect(e)}}return this._extensions.oes_standard_derivatives&&e===this._extensions.oes_standard_derivatives.FRAGMENT_SHADER_DERIVATIVE_HINT_OES||this._extensions.ext_texture_filter_anisotropic&&e===this._extensions.ext_texture_filter_anisotropic.MAX_TEXTURE_MAX_ANISOTROPY_EXT?this._getParameterDirect(e):this._extensions.oes_vertex_array_object&&e===this._extensions.oes_vertex_array_object.VERTEX_ARRAY_BINDING_OES?this._extensions.oes_vertex_array_object._activeVertexArrayObject:(this.setError(this.INVALID_ENUM),null)}}getProgramInfoLog(e){if(!a(e))throw TypeError(`getProgramInfoLog(WebGLProgram)`);return this._checkWrapper(e,P)?e._linkInfoLog:null}getProgramParameter(e,t=0){if(!a(e))throw TypeError(`getProgramParameter(WebGLProgram, GLenum)`);if(this._checkWrapper(e,P)){switch(t){case this.DELETE_STATUS:return e._pendingDelete;case this.LINK_STATUS:return e._linkStatus;case this.VALIDATE_STATUS:return!!this._gl.getProgramParameter(e._,t);case this.ATTACHED_SHADERS:return this._gl.getProgramParameter(e._,t);case this.ACTIVE_ATTRIBUTES:return e._linkStatus?e._attributes.length:this._gl.getProgramParameter(e._,t);case this.ACTIVE_UNIFORMS:return e._linkStatus?e._uniforms.length:this._gl.getProgramParameter(e._,t)}this.setError(this.INVALID_ENUM)}return null}getRenderbufferParameter(e=0,t=0){if(e!==this.RENDERBUFFER)return this.setError(this.INVALID_ENUM),null;let n=this._activeRenderbuffer;if(!n)return this.setError(this.INVALID_OPERATION),null;switch(t){case this.RENDERBUFFER_INTERNAL_FORMAT:return n._format;case this.RENDERBUFFER_WIDTH:return n._width;case this.RENDERBUFFER_HEIGHT:return n._height;case this.MAX_RENDERBUFFER_SIZE:case this.RENDERBUFFER_RED_SIZE:case this.RENDERBUFFER_GREEN_SIZE:case this.RENDERBUFFER_BLUE_SIZE:case this.RENDERBUFFER_ALPHA_SIZE:case this.RENDERBUFFER_DEPTH_SIZE:case this.RENDERBUFFER_STENCIL_SIZE:return this._gl.getRenderbufferParameter(e,t)}return this.setError(this.INVALID_ENUM),null}getShaderInfoLog(e){if(!a(e))throw TypeError(`getShaderInfoLog(WebGLShader)`);return this._checkWrapper(e,I)?e._compileInfo:null}getShaderParameter(e,t=0){if(!a(e))throw TypeError(`getShaderParameter(WebGLShader, GLenum)`);if(this._checkWrapper(e,I)){switch(t){case this.DELETE_STATUS:return e._pendingDelete;case this.COMPILE_STATUS:return e._compileStatus;case this.SHADER_TYPE:return e._type}this.setError(this.INVALID_ENUM)}return null}getShaderPrecisionFormat(e=0,t=0){if(!(e===this.FRAGMENT_SHADER||e===this.VERTEX_SHADER)||!(t===this.LOW_FLOAT||t===this.MEDIUM_FLOAT||t===this.HIGH_FLOAT||t===this.LOW_INT||t===this.MEDIUM_INT||t===this.HIGH_INT))return this.setError(this.INVALID_ENUM),null;let n=this._gl.getShaderPrecisionFormat(e,t);return n?new L(n):null}getShaderSource(e){if(!a(e))throw TypeError(`Input to getShaderSource must be an object`);return this._checkWrapper(e,I)?e._source:null}getSupportedExtensions(){let e=[`ANGLE_instanced_arrays`,`STACKGL_resize_drawingbuffer`,`STACKGL_destroy_context`],t=this._gl.getSupportedExtensions();return t?(t.indexOf(`GL_OES_element_index_uint`)>=0&&e.push(`OES_element_index_uint`),t.indexOf(`GL_OES_standard_derivatives`)>=0&&e.push(`OES_standard_derivatives`),t.indexOf(`GL_OES_texture_float`)>=0&&e.push(`OES_texture_float`),t.indexOf(`GL_OES_texture_float_linear`)>=0&&e.push(`OES_texture_float_linear`),(t.indexOf(`GL_OES_texture_half_float`)>=0||t.indexOf(`GL_ARB_half_float_pixel`)>=0)&&e.push(`OES_texture_half_float`),(t.indexOf(`GL_EXT_color_buffer_float`)>=0||t.indexOf(`GL_ARB_color_buffer_float`)>=0)&&e.push(`EXT_color_buffer_float`),t.indexOf(`GL_EXT_color_buffer_half_float`)>=0&&e.push(`EXT_color_buffer_half_float`),t.indexOf(`EXT_draw_buffers`)>=0&&e.push(`WEBGL_draw_buffers`),t.indexOf(`EXT_blend_minmax`)>=0&&e.push(`EXT_blend_minmax`),t.indexOf(`EXT_texture_filter_anisotropic`)>=0&&e.push(`EXT_texture_filter_anisotropic`),t.indexOf(`GL_OES_vertex_array_object`)>=0&&e.push(`OES_vertex_array_object`),e):e}_getTexParameterDirect(e=0,t=0){return this._gl.getTexParameterx(e,t)?.unpack()}getTexParameter(e=0,t=0){if(!this._checkTextureTarget(e))return null;let n=this._getActiveTextureUnit();if(e===this.TEXTURE_2D&&!n._bind2D||e===this.TEXTURE_CUBE_MAP&&!n._bindCube)return this.setError(this.INVALID_OPERATION),null;switch(t){case this.TEXTURE_MAG_FILTER:case this.TEXTURE_MIN_FILTER:case this.TEXTURE_WRAP_S:case this.TEXTURE_WRAP_T:return this._getTexParameterDirect(e,t)}return this._extensions.ext_texture_filter_anisotropic&&t===this._extensions.ext_texture_filter_anisotropic.TEXTURE_MAX_ANISOTROPY_EXT?this._getTexParameterDirect(e,t):(this.setError(this.INVALID_ENUM),null)}getUniform(e,t){if(!a(e)||!a(t))throw TypeError(`getUniform(WebGLProgram, WebGLUniformLocation)`);if(!e)return this.setError(this.INVALID_VALUE),null;if(!t)return null;if(this._checkWrapper(e,P)){if(!o(e,t))return this.setError(this.INVALID_OPERATION),null;let n=this._gl.getUniform(e._|0,t._|0);if(!n)return null;switch(t._activeInfo.type){case this.FLOAT:return n[0];case this.FLOAT_VEC2:return new Float32Array(n.slice(0,2));case this.FLOAT_VEC3:return new Float32Array(n.slice(0,3));case this.FLOAT_VEC4:return new Float32Array(n.slice(0,4));case this.INT:return n[0]|0;case this.INT_VEC2:return new Int32Array(n.slice(0,2));case this.INT_VEC3:return new Int32Array(n.slice(0,3));case this.INT_VEC4:return new Int32Array(n.slice(0,4));case this.BOOL:return!!n[0];case this.BOOL_VEC2:return[!!n[0],!!n[1]];case this.BOOL_VEC3:return[!!n[0],!!n[1],!!n[2]];case this.BOOL_VEC4:return[!!n[0],!!n[1],!!n[2],!!n[3]];case this.FLOAT_MAT2:return new Float32Array(n.slice(0,4));case this.FLOAT_MAT3:return new Float32Array(n.slice(0,9));case this.FLOAT_MAT4:return new Float32Array(n.slice(0,16));case this.SAMPLER_2D:case this.SAMPLER_CUBE:return n[0]|0;default:return null}}return null}getUniformLocation(e,n){if(!a(e))throw TypeError(`getUniformLocation(WebGLProgram, String)`);if(n+=``,!f(n))return this.setError(this.INVALID_VALUE),null;if(this._checkWrapper(e,P)){let r=this._gl.getUniformLocation(e._|0,n);if(r!==null&&r>=0){let i=n;/\[\d+\]$/.test(n)&&(i=n.replace(/\[\d+\]$/,`[0]`));let a=i+`[0]`,o=null;for(let t=0;t<e._uniforms.length;++t){let n=e._uniforms[t];if(n.name===i||n.name===a){o={size:n.size,type:n.type,name:n.name};break}}o||={name:i,type:0,size:1};let s=new t(r,e,o),c=n.match(/\[(\d+)\]$/),l=c?+c[1]:-1;if(/\[0\]$/.test(o.name)&&(l===-1||l===0)){let t=o.name.replace(/\[0\]$/,``),n=[];this._saveError();for(let r=0;this.getError()===this.NO_ERROR;++r){let i=this._gl.getUniformLocation(e._|0,t+`[`+r+`]`);if(this.getError()!==this.NO_ERROR||i==null||i<0)break;n.push(i)}this._restoreError(this.NO_ERROR),s._array=n}else if(l>0&&l>=o.size)return null;return s}}return null}getVertexAttrib(e=0,t=0){if(e<0||e>=this._vertexObjectState._attribs.length)return this.setError(this.INVALID_VALUE),null;let n=this._vertexObjectState._attribs[e],r=this._vertexGlobalState._attribs[e]._data,i=this._extensions.angle_instanced_arrays;if(i&&t===i.VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE)return n._divisor;switch(t){case this.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:return n._pointerBuffer;case this.VERTEX_ATTRIB_ARRAY_ENABLED:return n._isPointer;case this.VERTEX_ATTRIB_ARRAY_SIZE:return n._inputSize;case this.VERTEX_ATTRIB_ARRAY_STRIDE:return n._inputStride;case this.VERTEX_ATTRIB_ARRAY_TYPE:return n._pointerType;case this.VERTEX_ATTRIB_ARRAY_NORMALIZED:return n._pointerNormal;case this.CURRENT_VERTEX_ATTRIB:return new Float32Array(r);default:return this.setError(this.INVALID_ENUM),null}}getVertexAttribOffset(e=0,t=0){return e<0||e>=this._vertexObjectState._attribs.length?(this.setError(this.INVALID_VALUE),-1):t===this.VERTEX_ATTRIB_ARRAY_POINTER?this._vertexObjectState._attribs[e]._pointerOffset:(this.setError(this.INVALID_ENUM),-1)}hint(e=0,t=0){if(!(e===this.GENERATE_MIPMAP_HINT||this._extensions.oes_standard_derivatives&&e===this._extensions.oes_standard_derivatives.FRAGMENT_SHADER_DERIVATIVE_HINT_OES)){this.setError(this.INVALID_ENUM);return}if(t!==this.FASTEST&&t!==this.NICEST&&t!==this.DONT_CARE){this.setError(this.INVALID_ENUM);return}return this._gl.hint(e,t)}isBuffer(e){return this._isObject(e,`isBuffer`,M)?this._gl.isBuffer(e?._):!1}isContextLost(){return!1}isEnabled(e=0){return this._gl.isEnabled(e)}isFramebuffer(e){return this._isObject(e,`isFramebuffer`,j)?this._gl.isFramebuffer(e?._):!1}isProgram(e){return this._isObject(e,`isProgram`,P)?this._gl.isProgram(e?._):!1}isRenderbuffer(e){return this._isObject(e,`isRenderbuffer`,F)?this._gl.isRenderbuffer(e?._):!1}isShader(e){return this._isObject(e,`isShader`,I)?this._gl.isShader(e?._):!1}isTexture(e){return this._isObject(e,`isTexture`,z)?this._gl.isTexture(e?._):!1}lineWidth(e){if(isNaN(e)){this.setError(this.INVALID_VALUE);return}return this._gl.lineWidth(+e)}linkProgram(e){if(!a(e))throw TypeError(`linkProgram(WebGLProgram)`);if(this._checkWrapper(e,P)){e._linkCount+=1,e._attributes=[];let t=this.getError();for(let t of e._references)t instanceof I&&t._needsRecompile&&(this._gl.compileShader(t._|0),t._needsRecompile=!1);this._gl.linkProgram(e._|0);let n=this.getError();n===this.NO_ERROR&&(e._linkStatus=this._fixupLink(e)),this.getError(),this.setError(t||n)}}pixelStorei(e=0,t=0){if(typeof t==`boolean`&&(t=t===!1?0:1),e===this.UNPACK_ALIGNMENT)if(t===1||t===2||t===4||t===8)this._unpackAlignment=t;else{this.setError(this.INVALID_VALUE);return}else if(e===this.PACK_ALIGNMENT)if(t===1||t===2||t===4||t===8)this._packAlignment=t;else{this.setError(this.INVALID_VALUE);return}else if(e===this.UNPACK_COLORSPACE_CONVERSION_WEBGL){if(!(t===this.NONE||t===this.BROWSER_DEFAULT_WEBGL)){this.setError(this.INVALID_VALUE);return}}else if(e===this.UNPACK_FLIP_Y_WEBGL){this._unpackFlipY=!!t;return}else if(e===this.UNPACK_PREMULTIPLY_ALPHA_WEBGL){this._unpackPremultAlpha=!!t;return}return this._gl.pixelStorei(e,t)}polygonOffset(e,t){return this._gl.polygonOffset(+e,+t)}renderbufferStorage(e=0,t=0,n=0,r=0){if(e!==this.RENDERBUFFER){this.setError(this.INVALID_ENUM);return}let i=this._activeRenderbuffer;if(!i){this.setError(this.INVALID_OPERATION);return}if(t!==this.RGBA4&&t!==this.RGB565&&t!==this.RGB5_A1&&t!==this.DEPTH_COMPONENT16&&t!==this.STENCIL_INDEX&&t!==this.STENCIL_INDEX8&&t!==this.DEPTH_STENCIL){this.setError(this.INVALID_ENUM);return}this._saveError(),this._gl.renderbufferStorage(e,t,n,r);let a=this.getError();if(this._restoreError(a),a!==this.NO_ERROR)return;i._width=n,i._height=r,i._format=t;let o=this._activeFramebuffer;if(o){let e=!1,t=this._getAttachments();for(let n=0;n<t.length;++n)if(o._attachments[t[n]]===i){e=!0;break}e&&this._updateFramebufferAttachments(this._activeFramebuffer)}}resize(e=0,t=0){if(e|=0,t|=0,e>0&&t>0)(e!==this.drawingBufferWidth||t!==this.drawingBufferHeight)&&this._resizeDrawingBuffer(e,t);else throw Error(`Invalid surface dimensions`)}sampleCoverage(e,t){return this._gl.sampleCoverage(+e,!!t)}scissor(e,t,n,r){return this._scissorBox[0]=e|0,this._scissorBox[1]=t|0,this._scissorBox[2]=n|0,this._scissorBox[3]=r|0,this._gl.scissor(e|0,t|0,n|0,r|0)}shaderSource(e,t){if(!a(e))throw TypeError(`shaderSource(WebGLShader, String)`);if(!e||!t&&typeof t!=`string`){this.setError(this.INVALID_VALUE);return}f(t)?this._checkWrapper(e,I)&&(t=this._wrapShader(e._type,t),this._gl.shaderSource(e._|0,t),e._source=t,e._needsRecompile=!0):this.setError(this.INVALID_VALUE)}stencilFunc(e,t,n){return this._checkStencil=!0,this._gl.stencilFunc(e|0,t|0,n|0)}stencilFuncSeparate(e,t,n,r){return this._checkStencil=!0,this._gl.stencilFuncSeparate(e|0,t|0,n|0,r|0)}stencilMask(e){return this._checkStencil=!0,this._gl.stencilMask(e>>>0)}stencilMaskSeparate(e,t){return this._checkStencil=!0,this._gl.stencilMaskSeparate(e|0,t>>>0)}stencilOp(e,t,n){return this._checkStencil=!0,this._gl.stencilOp(e|0,t|0,n|0)}stencilOpSeparate(e,t,n,r){return this._checkStencil=!0,this._gl.stencilOpSeparate(e|0,t|0,n|0,r|0)}texParameterf(e=0,t=0,n){if(n=+n,this._checkTextureTarget(e)){switch(this._verifyTextureCompleteness(e,t,n),t){case this.TEXTURE_MIN_FILTER:case this.TEXTURE_MAG_FILTER:case this.TEXTURE_WRAP_S:case this.TEXTURE_WRAP_T:return this._gl.texParameterf(e,t,n)}if(this._extensions.ext_texture_filter_anisotropic&&t===this._extensions.ext_texture_filter_anisotropic.TEXTURE_MAX_ANISOTROPY_EXT)return this._gl.texParameterf(e,t,n);this.setError(this.INVALID_ENUM)}}texParameteri(e=0,t=0,n=0){if(this._checkTextureTarget(e)){switch(this._verifyTextureCompleteness(e,t,n),t){case this.TEXTURE_MIN_FILTER:case this.TEXTURE_MAG_FILTER:case this.TEXTURE_WRAP_S:case this.TEXTURE_WRAP_T:return this._gl.texParameteri(e,t,n)}if(this._extensions.ext_texture_filter_anisotropic&&t===this._extensions.ext_texture_filter_anisotropic.TEXTURE_MAX_ANISOTROPY_EXT)return this._gl.texParameteri(e,t,n);this.setError(this.INVALID_ENUM)}}uniform1f(e,t){if(this._checkUniformValid(e,t,`uniform1f`,1,`f`))return this._gl.uniform1f(e?._||0,t)}uniform1i(e,t){return this._gl.uniform1i(e?._||0,t)}uniform2f(e,t,n){if(this._checkUniformValid(e,t,`uniform2f`,2,`f`))return this._gl.uniform2f(e?._||0,t,n)}uniform2i(e,t,n){this._checkUniformValid(e,t,`uniform2i`,2,`i`)&&this._gl.uniform2i(e?._||0,t,n)}uniform3f(e,t,n,r){if(this._checkUniformValid(e,t,`uniform3f`,3,`f`))return this._gl.uniform3f(e?._||0,t,n,r)}uniform3i(e,t,n,r){if(this._checkUniformValid(e,t,`uniform3i`,3,`i`))return this._gl.uniform3i(e?._||0,t,n,r)}uniform4f(e,t,n,r,i){if(!this._checkUniformValid(e,t,`uniform4f`,4,`f`)){console.error(`uniform4f is not valid!`);return}return this._gl.uniform4f(e?._||0,t,n,r,i)}uniform4i(e,t,n,r,i){if(this._checkUniformValid(e,t,`uniform4i`,4,`i`))return this._gl.uniform4i(e?._||0,t,n,r,i)}useProgram(e){if(!a(e))throw TypeError(`useProgram(WebGLProgram)`);if(!e)return this._switchActiveProgram(this._activeProgram),this._activeProgram=null,this._gl.useProgram(0);if(this._checkWrapper(e,P))return this._activeProgram!==e&&(this._switchActiveProgram(this._activeProgram),this._activeProgram=e,e._refCount+=1),this._gl.useProgram(e._|0)}validateProgram(e){if(this._checkWrapper(e,P)){this._gl.validateProgram(e._|0);let t=this.getError();t===this.NO_ERROR&&(e._linkInfoLog=this._gl.getProgramInfoLog(e._|0)),this.getError(),this.setError(t)}}vertexAttrib1f(e,t){if(e|=0,!this._checkVertexIndex(e))return;let n=this._vertexGlobalState._attribs[e]._data;return n[3]=1,n[1]=n[2]=0,n[0]=t,this._gl.vertexAttrib1f(e|0,+t)}vertexAttrib1fv(e,t){if(e|=0,!this._checkVertexIndex(e))return;if(typeof t!=`object`||!t||t.length<1){this.setError(this.INVALID_OPERATION);return}let n=this._vertexGlobalState._attribs[e]._data;return n[3]=1,n[2]=0,n[1]=0,n[0]=t[0],this._gl.vertexAttrib1f(e|0,+t[0])}vertexAttrib2f(e,t,n){if(e|=0,!this._checkVertexIndex(e))return;let r=this._vertexGlobalState._attribs[e]._data;return r[3]=1,r[2]=0,r[1]=n,r[0]=t,this._gl.vertexAttrib2f(e|0,+t,+n)}vertexAttrib2fv(e,t){if(e|=0,!this._checkVertexIndex(e))return;if(typeof t!=`object`||!t||t.length<2){this.setError(this.INVALID_OPERATION);return}let n=this._vertexGlobalState._attribs[e]._data;return n[3]=1,n[2]=0,n[1]=t[1],n[0]=t[0],this._gl.vertexAttrib2f(e|0,+t[0],+t[1])}vertexAttrib3f(e,t,n,r){if(e|=0,!this._checkVertexIndex(e))return;let i=this._vertexGlobalState._attribs[e]._data;return i[3]=1,i[2]=r,i[1]=n,i[0]=t,this._gl.vertexAttrib3f(e|0,+t,+n,+r)}vertexAttrib3fv(e,t){if(e|=0,!this._checkVertexIndex(e))return;if(typeof t!=`object`||!t||t.length<3){this.setError(this.INVALID_OPERATION);return}let n=this._vertexGlobalState._attribs[e]._data;return n[3]=1,n[2]=t[2],n[1]=t[1],n[0]=t[0],this._gl.vertexAttrib3f(e|0,+t[0],+t[1],+t[2])}vertexAttrib4f(e=0,t,n,r,i){if(!this._checkVertexIndex(e))return;let a=this._vertexGlobalState._attribs[e]._data;return a[3]=i,a[2]=r,a[1]=n,a[0]=t,this._gl.vertexAttrib4f(e|0,+t,+n,+r,+i)}vertexAttrib4fv(e,t){if(e|=0,!this._checkVertexIndex(e))return;if(typeof t!=`object`||!t||t.length<4){this.setError(this.INVALID_OPERATION);return}let n=this._vertexGlobalState._attribs[e]._data;return n[3]=t[3],n[2]=t[2],n[1]=t[1],n[0]=t[0],this._gl.vertexAttrib4f(e|0,+t[0],+t[1],+t[2],+t[3])}vertexAttribPointer(e=0,t=0,n=0,r=!1,i=0,a=0){if(i<0||a<0){this.setError(this.INVALID_VALUE);return}if(i<0||a<0||e<0||e>=this._vertexObjectState._attribs.length||!(t===1||t===2||t===3||t===4)){this.setError(this.INVALID_VALUE);return}if(this._vertexGlobalState._arrayBufferBinding===null){this.setError(this.INVALID_OPERATION);return}let o=h(this,n);if(o===0||n===this.INT||n===this.UNSIGNED_INT){this.setError(this.INVALID_ENUM);return}if(i>255||i<0){this.setError(this.INVALID_VALUE);return}if(i%o!==0||a%o!==0){this.setError(this.INVALID_OPERATION);return}this._gl.vertexAttribPointer(e,t,n,r,i,a),this._vertexObjectState.setVertexAttribPointer(this._vertexGlobalState._arrayBufferBinding,e,t*o,a,i||t*o,n,r,i,t)}viewport(e,t,n,r){return this._viewport[0]=e|0,this._viewport[1]=t|0,this._viewport[2]=n|0,this._viewport[3]=r|0,this._gl.viewport(e,t,n,r)}};export{Y as WebGLContextBase};
1
+ import"./_virtual/_rolldown/runtime.js";import{WebGLContextAttributes as e}from"./webgl-context-attributes.js";import{flag as t}from"./utils.js";import{getOESElementIndexUint as n}from"./extensions/oes-element-index-unit.js";import{getOESStandardDerivatives as r}from"./extensions/oes-standard-derivatives.js";import{getOESTextureFloat as i}from"./extensions/oes-texture-float.js";import{getOESTextureFloatLinear as a}from"./extensions/oes-texture-float-linear.js";import{getSTACKGLDestroyContext as o}from"./extensions/stackgl-destroy-context.js";import{getSTACKGLResizeDrawingBuffer as s}from"./extensions/stackgl-resize-drawing-buffer.js";import{getEXTBlendMinMax as c}from"./extensions/ext-blend-minmax.js";import{getEXTColorBufferFloat as l}from"./extensions/ext-color-buffer-float.js";import{getEXTColorBufferHalfFloat as u}from"./extensions/ext-color-buffer-half-float.js";import{getEXTTextureFilterAnisotropic as d}from"./extensions/ext-texture-filter-anisotropic.js";import{getOESTextureHalfFloat as f}from"./extensions/oes-texture-half-float.js";import{WebGLTextureUnit as p}from"./webgl-texture-unit.js";import{WebGLVertexArrayGlobalState as m,WebGLVertexArrayObjectState as h}from"./webgl-vertex-attribute.js";import{installAllContextMethods as g}from"./context/index.js";import _ from"@girs/gwebgl-0.1";import"@girs/gdkpixbuf-2.0";import*as v from"bit-twiddle";import{warnNotImplemented as y}from"@gjsify/utils";let b=0;const x={oes_element_index_uint:n,oes_texture_float:i,oes_texture_float_linear:a,oes_standard_derivatives:r,stackgl_destroy_context:o,stackgl_resize_drawingbuffer:s,ext_blend_minmax:c,ext_color_buffer_float:l,ext_color_buffer_half_float:u,ext_texture_filter_anisotropic:d,oes_texture_half_float:f};var WebGLContextBase=class{get drawingBufferHeight(){return this.canvas.height||0}get drawingBufferWidth(){return this.canvas.width||0}constructor(n,r={}){this.unpackColorSpace=`srgb`,this.RGBA8=32856,this.DEFAULT_ATTACHMENTS=[],this.DEFAULT_COLOR_ATTACHMENTS=[],this._=0,this._extensions={},this._programs={},this._shaders={},this._textures={},this._framebuffers={},this._renderbuffers={},this._buffers={},this._activeProgram=null,this._activeFramebuffer=null,this._activeRenderbuffer=null,this._checkStencil=!1,this._stencilState=!0,this._activeTextureUnit=0,this._errorStack=[],this._maxTextureSize=0,this._maxTextureLevel=0,this._maxCubeMapSize=0,this._maxCubeMapLevel=0,this._unpackAlignment=4,this._packAlignment=4,this._unpackFlipY=!1,this._unpackPremultAlpha=!1,this._viewport=new Int32Array([0,0,0,0]),this._scissorBox=new Int32Array([0,0,0,0]),this._gtkFboId=0,this._textureUnits=[],this._drawingBuffer=null,this.canvas=n,this._contextAttributes=new e(t(r,`alpha`,!0),t(r,`depth`,!0),t(r,`stencil`,!1),!1,t(r,`premultipliedAlpha`,!0),t(r,`preserveDrawingBuffer`,!1),t(r,`preferLowPowerToHighPerformance`,!1),t(r,`failIfMajorPerformanceCaveat`,!1)),this._contextAttributes.premultipliedAlpha=this._contextAttributes.premultipliedAlpha&&this._contextAttributes.alpha}_init(){let e=this._gl.getParameterx(36006);this._gtkFboId=e?.deepUnpack()|0,this._initGLConstants(),this.DEFAULT_ATTACHMENTS=[this.COLOR_ATTACHMENT0,this.DEPTH_ATTACHMENT,this.STENCIL_ATTACHMENT,this.DEPTH_STENCIL_ATTACHMENT],this.DEFAULT_COLOR_ATTACHMENTS=[this.COLOR_ATTACHMENT0];let t=this.drawingBufferWidth||0,n=this.drawingBufferHeight||0;this._=b++;let r=this.getParameter(this.MAX_COMBINED_TEXTURE_IMAGE_UNITS);this._textureUnits=Array(r);for(let e=0;e<r;++e)this._textureUnits[e]=new p(this,e);this.activeTexture(this.TEXTURE0),this._defaultVertexObjectState=new h(this),this._vertexObjectState=this._defaultVertexObjectState,this._vertexGlobalState=new m(this),this._maxTextureSize=this.getParameter(this.MAX_TEXTURE_SIZE),this._maxTextureLevel=v.log2(v.nextPow2(this._maxTextureSize)),this._maxCubeMapSize=this.getParameter(this.MAX_CUBE_MAP_TEXTURE_SIZE),this._maxCubeMapLevel=v.log2(v.nextPow2(this._maxCubeMapSize)),this._unpackAlignment=4,this._packAlignment=4,this._unpackFlipY=!1,this._unpackPremultAlpha=!1,this.bindBuffer(this.ARRAY_BUFFER,null),this.bindBuffer(this.ELEMENT_ARRAY_BUFFER,null),this.bindFramebuffer(this.FRAMEBUFFER,null),this.bindRenderbuffer(this.RENDERBUFFER,null),this.viewport(0,0,t,n),this.scissor(0,0,t,n),this.clearDepth(1),this.clearColor(0,0,0,0),this.clearStencil(0),this.clear(this.COLOR_BUFFER_BIT|this.DEPTH_BUFFER_BIT|this.STENCIL_BUFFER_BIT),this.disable(this.DEPTH_TEST),this.disable(this.STENCIL_TEST),this.disable(this.BLEND),this.disable(this.CULL_FACE),this.disable(this.POLYGON_OFFSET_FILL),this.disable(this.SCISSOR_TEST),this._gl.colorMask(!0,!0,!0,!0)}_initGLConstants(){let e=new _.WebGLRenderingContextBase().get_webgl_constants();for(let[t,n]of Object.entries(e))Object.defineProperty(this,t,{value:n})}_getGlslVersion(e){return e?`100`:`120`}_checkOwns(e){return typeof e==`object`&&!!e&&e._ctx===this}_checkValid(e,t){return e instanceof t&&e._!==0}_checkWrapper(e,t){return this._checkValid(e,t)?this._checkOwns(e)?!0:(this.setError(this.INVALID_OPERATION),!1):(this.setError(this.INVALID_VALUE),!1)}_isObject(e,t,n){if(e!=null&&!(e instanceof n))throw TypeError(t+`(`+n.name+`)`);return!!(this._checkValid(e,n)&&this._checkOwns(e))}_checkStencilState(){return this._checkStencil?(this._checkStencil=!1,this._stencilState=!0,(this.getParameter(this.STENCIL_WRITEMASK)!==this.getParameter(this.STENCIL_BACK_WRITEMASK)||this.getParameter(this.STENCIL_VALUE_MASK)!==this.getParameter(this.STENCIL_BACK_VALUE_MASK)||this.getParameter(this.STENCIL_REF)!==this.getParameter(this.STENCIL_BACK_REF))&&(this.setError(this.INVALID_OPERATION),this._stencilState=!1),this._stencilState):this._stencilState}_validGLSLIdentifier(e){return!(e.indexOf(`webgl_`)===0||e.indexOf(`_webgl_`)===0||e.length>256)}_getParameterDirect(e){return this._gl.getParameterx(e)?.deepUnpack()}getContextAttributes(){return this._contextAttributes}getExtension(e){let t=e.toLowerCase();if(t in this._extensions)return this._extensions[t];let n=x[t]?x[t](this):null;return n&&(this._extensions[t]=n),n}getSupportedExtensions(){let e=[`ANGLE_instanced_arrays`,`STACKGL_resize_drawingbuffer`,`STACKGL_destroy_context`],t=this._gl.getSupportedExtensions();return t?(t.indexOf(`GL_OES_element_index_uint`)>=0&&e.push(`OES_element_index_uint`),t.indexOf(`GL_OES_standard_derivatives`)>=0&&e.push(`OES_standard_derivatives`),t.indexOf(`GL_OES_texture_float`)>=0&&e.push(`OES_texture_float`),t.indexOf(`GL_OES_texture_float_linear`)>=0&&e.push(`OES_texture_float_linear`),(t.indexOf(`GL_OES_texture_half_float`)>=0||t.indexOf(`GL_ARB_half_float_pixel`)>=0)&&e.push(`OES_texture_half_float`),(t.indexOf(`GL_EXT_color_buffer_float`)>=0||t.indexOf(`GL_ARB_color_buffer_float`)>=0)&&e.push(`EXT_color_buffer_float`),t.indexOf(`GL_EXT_color_buffer_half_float`)>=0&&e.push(`EXT_color_buffer_half_float`),t.indexOf(`EXT_draw_buffers`)>=0&&e.push(`WEBGL_draw_buffers`),t.indexOf(`EXT_blend_minmax`)>=0&&e.push(`EXT_blend_minmax`),t.indexOf(`EXT_texture_filter_anisotropic`)>=0&&e.push(`EXT_texture_filter_anisotropic`),t.indexOf(`GL_OES_vertex_array_object`)>=0&&e.push(`OES_vertex_array_object`),e):e}getParameter(e=0){switch(e){case this.ARRAY_BUFFER_BINDING:return this._vertexGlobalState._arrayBufferBinding;case this.ELEMENT_ARRAY_BUFFER_BINDING:return this._vertexObjectState._elementArrayBufferBinding;case this.CURRENT_PROGRAM:return this._activeProgram;case this.FRAMEBUFFER_BINDING:return this._activeFramebuffer;case this.RENDERBUFFER_BINDING:return this._activeRenderbuffer;case this.TEXTURE_BINDING_2D:return this._getActiveTextureUnit()._bind2D;case this.TEXTURE_BINDING_CUBE_MAP:return this._getActiveTextureUnit()._bindCube;case this.VERSION:return`WebGL 1.0 0.0.1`;case this.VENDOR:return``;case this.RENDERER:return`ANGLE`;case this.SHADING_LANGUAGE_VERSION:return`WebGL GLSL ES 1.0 `;case this.COMPRESSED_TEXTURE_FORMATS:return new Uint32Array;case this.SCISSOR_BOX:return new Int32Array(this._scissorBox);case this.VIEWPORT:return new Int32Array(this._viewport);case this.MAX_VIEWPORT_DIMS:return new Int32Array([32767,32767]);case this.ALIASED_LINE_WIDTH_RANGE:case this.ALIASED_POINT_SIZE_RANGE:return new Float32Array([1,1]);case this.DEPTH_RANGE:return new Float32Array([0,1]);case this.BLEND_COLOR:case this.COLOR_CLEAR_VALUE:return new Float32Array(this._gl.getParameterfv(e,4));case this.COLOR_WRITEMASK:{let t=this._gl.getParameteriv(e,4);return[!!t[0],!!t[1],!!t[2],!!t[3]]}case this.DEPTH_CLEAR_VALUE:case this.LINE_WIDTH:case this.POLYGON_OFFSET_FACTOR:case this.POLYGON_OFFSET_UNITS:case this.SAMPLE_COVERAGE_VALUE:return this._gl.getParameterf(e);case this.BLEND:case this.CULL_FACE:case this.DEPTH_TEST:case this.DEPTH_WRITEMASK:case this.DITHER:case this.POLYGON_OFFSET_FILL:case this.SAMPLE_COVERAGE_INVERT:case this.SCISSOR_TEST:case this.STENCIL_TEST:case this.UNPACK_PREMULTIPLY_ALPHA_WEBGL:return!!this._gl.getParameteri(e);case this.UNPACK_FLIP_Y_WEBGL:return this._unpackFlipY;case this.ACTIVE_TEXTURE:case this.ALPHA_BITS:case this.BLEND_DST_ALPHA:case this.BLEND_DST_RGB:case this.BLEND_EQUATION_ALPHA:case this.BLEND_EQUATION_RGB:case this.BLEND_SRC_ALPHA:case this.BLEND_SRC_RGB:case this.BLUE_BITS:case this.CULL_FACE_MODE:case this.DEPTH_BITS:case this.DEPTH_FUNC:case this.FRONT_FACE:case this.GENERATE_MIPMAP_HINT:case this.GREEN_BITS:case this.MAX_COMBINED_TEXTURE_IMAGE_UNITS:case this.MAX_CUBE_MAP_TEXTURE_SIZE:case this.MAX_FRAGMENT_UNIFORM_VECTORS:case this.MAX_RENDERBUFFER_SIZE:case this.MAX_TEXTURE_IMAGE_UNITS:case this.MAX_TEXTURE_SIZE:case this.MAX_VARYING_VECTORS:case this.MAX_VERTEX_ATTRIBS:case this.MAX_VERTEX_TEXTURE_IMAGE_UNITS:case this.MAX_VERTEX_UNIFORM_VECTORS:case this.PACK_ALIGNMENT:case this.RED_BITS:case this.SAMPLE_BUFFERS:case this.SAMPLES:case this.STENCIL_BACK_FAIL:case this.STENCIL_BACK_FUNC:case this.STENCIL_BACK_PASS_DEPTH_FAIL:case this.STENCIL_BACK_PASS_DEPTH_PASS:case this.STENCIL_BACK_REF:case this.STENCIL_BACK_VALUE_MASK:case this.STENCIL_BACK_WRITEMASK:case this.STENCIL_BITS:case this.STENCIL_CLEAR_VALUE:case this.STENCIL_FAIL:case this.STENCIL_FUNC:case this.STENCIL_PASS_DEPTH_FAIL:case this.STENCIL_PASS_DEPTH_PASS:case this.STENCIL_REF:case this.STENCIL_VALUE_MASK:case this.STENCIL_WRITEMASK:case this.SUBPIXEL_BITS:case this.UNPACK_ALIGNMENT:case this.UNPACK_COLORSPACE_CONVERSION_WEBGL:return this._gl.getParameteri(e);case this.IMPLEMENTATION_COLOR_READ_FORMAT:case this.IMPLEMENTATION_COLOR_READ_TYPE:return this._getParameterDirect(e);default:if(this._extensions.webgl_draw_buffers){let t=this._extensions.webgl_draw_buffers;switch(e){case t.DRAW_BUFFER0_WEBGL:case t.DRAW_BUFFER1_WEBGL:case t.DRAW_BUFFER2_WEBGL:case t.DRAW_BUFFER3_WEBGL:case t.DRAW_BUFFER4_WEBGL:case t.DRAW_BUFFER5_WEBGL:case t.DRAW_BUFFER6_WEBGL:case t.DRAW_BUFFER7_WEBGL:case t.DRAW_BUFFER8_WEBGL:case t.DRAW_BUFFER9_WEBGL:case t.DRAW_BUFFER10_WEBGL:case t.DRAW_BUFFER11_WEBGL:case t.DRAW_BUFFER12_WEBGL:case t.DRAW_BUFFER13_WEBGL:case t.DRAW_BUFFER14_WEBGL:case t.DRAW_BUFFER15_WEBGL:return t._buffersState.length===1&&t._buffersState[0]===this.BACK?this.BACK:this._getParameterDirect(e);case t.MAX_DRAW_BUFFERS_WEBGL:case t.MAX_COLOR_ATTACHMENTS_WEBGL:return this._getParameterDirect(e)}}return this._extensions.oes_standard_derivatives&&e===this._extensions.oes_standard_derivatives.FRAGMENT_SHADER_DERIVATIVE_HINT_OES||this._extensions.ext_texture_filter_anisotropic&&e===this._extensions.ext_texture_filter_anisotropic.MAX_TEXTURE_MAX_ANISOTROPY_EXT?this._getParameterDirect(e):this._extensions.oes_vertex_array_object&&e===this._extensions.oes_vertex_array_object.VERTEX_ARRAY_BINDING_OES?this._extensions.oes_vertex_array_object._activeVertexArrayObject:(this.setError(this.INVALID_ENUM),null)}}destroy(){y(`destroy`)}};g(WebGLContextBase.prototype);export{WebGLContextBase};
@@ -1 +1 @@
1
- var e=class{constructor(e,t,n){this._framebuffer=e,this._color=t,this._depthStencil=n}};export{e as WebGLDrawingBufferWrapper};
1
+ import"./_virtual/_rolldown/runtime.js";var WebGLDrawingBufferWrapper=class{constructor(e,t,n){this._framebuffer=e,this._color=t,this._depthStencil=n}};export{WebGLDrawingBufferWrapper};
@@ -1 +1 @@
1
- import{Linkable as e}from"./linkable.js";var t=class extends e{constructor(e,t){if(super(e),this._binding=0,this._width=0,this._height=0,this._status=null,this._ctx=t,this._attachments={},this._attachments[t.COLOR_ATTACHMENT0]=null,this._attachments[t.DEPTH_ATTACHMENT]=null,this._attachments[t.STENCIL_ATTACHMENT]=null,this._attachments[t.DEPTH_STENCIL_ATTACHMENT]=null,this._attachmentLevel={},this._attachmentLevel[t.COLOR_ATTACHMENT0]=0,this._attachmentLevel[t.DEPTH_ATTACHMENT]=0,this._attachmentLevel[t.STENCIL_ATTACHMENT]=0,this._attachmentLevel[t.DEPTH_STENCIL_ATTACHMENT]=0,this._attachmentFace={},this._attachmentFace[t.COLOR_ATTACHMENT0]=0,this._attachmentFace[t.DEPTH_ATTACHMENT]=0,this._attachmentFace[t.STENCIL_ATTACHMENT]=0,this._attachmentFace[t.DEPTH_STENCIL_ATTACHMENT]=0,t._extensions.webgl_draw_buffers){let e=t._extensions.webgl_draw_buffers;this._attachments[e.COLOR_ATTACHMENT1_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT2_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT3_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT4_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT5_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT6_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT7_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT8_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT9_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT10_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT11_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT12_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT13_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT14_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT15_WEBGL]=null,this._attachments[t.NONE]=null,this._attachments[t.BACK]=null,this._attachmentLevel[e.COLOR_ATTACHMENT1_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT2_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT3_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT4_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT5_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT6_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT7_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT8_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT9_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT10_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT11_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT12_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT13_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT14_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT15_WEBGL]=0,this._attachmentLevel[t.NONE]=null,this._attachmentLevel[t.BACK]=null,this._attachmentFace[e.COLOR_ATTACHMENT1_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT2_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT3_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT4_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT5_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT6_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT7_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT8_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT9_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT10_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT11_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT12_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT13_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT14_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT15_WEBGL]=0,this._attachmentFace[t.NONE]=null,this._attachmentFace[t.BACK]=null}}_clearAttachment(e){let t=this._attachments[e];t&&(this._attachments[e]=null,this._unlink(t))}_setAttachment(e,t){this._attachments[t]!==e&&(this._clearAttachment(t),e&&(this._attachments[t]=e,this._link(e)))}_performDelete(){let e=this._ctx;delete e._framebuffers[this._|0],e._gl.deleteFramebuffer(this._|0)}};export{t as WebGLFramebuffer};
1
+ import"./_virtual/_rolldown/runtime.js";import{Linkable as e}from"./linkable.js";var WebGLFramebuffer=class extends e{constructor(e,t){if(super(e),this._binding=0,this._width=0,this._height=0,this._status=null,this._ctx=t,this._attachments={},this._attachments[t.COLOR_ATTACHMENT0]=null,this._attachments[t.DEPTH_ATTACHMENT]=null,this._attachments[t.STENCIL_ATTACHMENT]=null,this._attachments[t.DEPTH_STENCIL_ATTACHMENT]=null,this._attachmentLevel={},this._attachmentLevel[t.COLOR_ATTACHMENT0]=0,this._attachmentLevel[t.DEPTH_ATTACHMENT]=0,this._attachmentLevel[t.STENCIL_ATTACHMENT]=0,this._attachmentLevel[t.DEPTH_STENCIL_ATTACHMENT]=0,this._attachmentFace={},this._attachmentFace[t.COLOR_ATTACHMENT0]=0,this._attachmentFace[t.DEPTH_ATTACHMENT]=0,this._attachmentFace[t.STENCIL_ATTACHMENT]=0,this._attachmentFace[t.DEPTH_STENCIL_ATTACHMENT]=0,t._extensions.webgl_draw_buffers){let e=t._extensions.webgl_draw_buffers;this._attachments[e.COLOR_ATTACHMENT1_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT2_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT3_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT4_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT5_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT6_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT7_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT8_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT9_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT10_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT11_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT12_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT13_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT14_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT15_WEBGL]=null,this._attachments[t.NONE]=null,this._attachments[t.BACK]=null,this._attachmentLevel[e.COLOR_ATTACHMENT1_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT2_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT3_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT4_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT5_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT6_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT7_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT8_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT9_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT10_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT11_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT12_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT13_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT14_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT15_WEBGL]=0,this._attachmentLevel[t.NONE]=null,this._attachmentLevel[t.BACK]=null,this._attachmentFace[e.COLOR_ATTACHMENT1_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT2_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT3_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT4_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT5_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT6_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT7_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT8_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT9_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT10_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT11_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT12_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT13_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT14_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT15_WEBGL]=0,this._attachmentFace[t.NONE]=null,this._attachmentFace[t.BACK]=null}}_clearAttachment(e){let t=this._attachments[e];t&&(this._attachments[e]=null,this._unlink(t))}_setAttachment(e,t){this._attachments[t]!==e&&(this._clearAttachment(t),e&&(this._attachments[t]=e,this._link(e)))}_performDelete(){let e=this._ctx;delete e._framebuffers[this._|0],e._gl.deleteFramebuffer(this._|0)}};export{WebGLFramebuffer};
@@ -1 +1 @@
1
- import{Linkable as e}from"./linkable.js";var t=class extends e{constructor(e,t){super(e),this._linkCount=0,this._linkStatus=!1,this._linkInfoLog=`not linked`,this._attributes=[],this._uniforms=[],this._ctx=t,this._linkCount=0,this._linkStatus=!1,this._linkInfoLog=`not linked`,this._attributes=[],this._uniforms=[]}_performDelete(){let e=this._ctx;delete e._programs[this._|0],e._gl.deleteProgram(this._|0)}};export{t as WebGLProgram};
1
+ import"./_virtual/_rolldown/runtime.js";import{Linkable as e}from"./linkable.js";var WebGLProgram=class extends e{constructor(e,t){super(e),this._linkCount=0,this._linkStatus=!1,this._linkInfoLog=`not linked`,this._attributes=[],this._uniforms=[],this._ctx=t,this._linkCount=0,this._linkStatus=!1,this._linkInfoLog=`not linked`,this._attributes=[],this._uniforms=[]}_performDelete(){let e=this._ctx;delete e._programs[this._|0],e._gl.deleteProgram(this._|0)}};export{WebGLProgram};
@@ -1 +1 @@
1
- import{Linkable as e}from"./linkable.js";var t=class extends e{constructor(e,t){super(e),this._ctx=t}_performDelete(){let e=this._ctx;delete e._queries[this._|0],e._native2.deleteQuery(this._|0)}};export{t as WebGLQuery};
1
+ import"./_virtual/_rolldown/runtime.js";import{Linkable as e}from"./linkable.js";var WebGLQuery=class extends e{constructor(e,t){super(e),this._ctx=t}_performDelete(){let e=this._ctx;delete e._queries[this._|0],e._native2.deleteQuery(this._|0)}};export{WebGLQuery};
@@ -1 +1 @@
1
- import{Linkable as e}from"./linkable.js";var t=class extends e{constructor(e,t){super(e),this._binding=0,this._width=0,this._height=0,this._format=0,this._ctx=t,this._binding=0,this._width=0,this._height=0,this._format=0}_performDelete(){let e=this._ctx;delete e._renderbuffers[this._|0],e._gl.deleteRenderbuffer(this._)}};export{t as WebGLRenderbuffer};
1
+ import"./_virtual/_rolldown/runtime.js";import{Linkable as e}from"./linkable.js";var WebGLRenderbuffer=class extends e{constructor(e,t){super(e),this._binding=0,this._width=0,this._height=0,this._format=0,this._ctx=t,this._binding=0,this._width=0,this._height=0,this._format=0}_performDelete(){let e=this._ctx;delete e._renderbuffers[this._|0],e._gl.deleteRenderbuffer(this._)}};export{WebGLRenderbuffer};
@@ -1 +1 @@
1
- import{Uint8ArrayToVariant as e,vertexCount as t}from"./utils.js";import{WebGLContextBase as n}from"./webgl-context-base.js";import r from"@girs/gwebgl-0.1";var i=class extends n{get _gl(){return this._native}constructor(e,t={}){super(e,t),this._attrib0Buffer=null,this._native=new r.WebGLRenderingContext({}),this._init();let n=this.createBuffer();this._attrib0Buffer=n}_beginAttrib0Hack(){this._native.bindBuffer(this.ARRAY_BUFFER,this._attrib0Buffer?._||0);let t=new Uint8Array(this._vertexGlobalState._attribs[0]._data.buffer);this._native.bufferData(this.ARRAY_BUFFER,e(t),this.STREAM_DRAW),this._native.enableVertexAttribArray(0),this._native.vertexAttribPointer(0,4,this.FLOAT,!1,0,0),this._native._vertexAttribDivisor(0,1)}_endAttrib0Hack(){let e=this._vertexObjectState._attribs[0];e._pointerBuffer?this._native.bindBuffer(this.ARRAY_BUFFER,e._pointerBuffer._):this._native.bindBuffer(this.ARRAY_BUFFER,0),this._native.vertexAttribPointer(0,e._inputSize,e._pointerType,e._pointerNormal,e._inputStride,e._pointerOffset),this._native._vertexAttribDivisor(0,e._divisor),this._native.disableVertexAttribArray(0),this._vertexGlobalState._arrayBufferBinding?this._native.bindBuffer(this.ARRAY_BUFFER,this._vertexGlobalState._arrayBufferBinding._):this._native.bindBuffer(this.ARRAY_BUFFER,0)}drawArrays(e=0,n=0,r=0){if(n<0||r<0){this.setError(this.INVALID_VALUE);return}if(!this._checkStencilState())return;let i=t(this,e,r);if(i<0){this.setError(this.INVALID_ENUM);return}if(!this._framebufferOk()||r===0)return;let a=n;if(r>0&&(a=r+n-1>>>0),this._checkVertexAttribState(a)){if(this._vertexObjectState._attribs[0]._isPointer||this._extensions.webgl_draw_buffers&&this._extensions.webgl_draw_buffers._buffersState&&this._extensions.webgl_draw_buffers._buffersState.length>0)return this._native.drawArrays(e,n,i);this._beginAttrib0Hack(),this._native._drawArraysInstanced(e,n,i,1),this._endAttrib0Hack()}}drawElements(e=0,t=0,n=0,r=0){if(t<0||r<0){this.setError(this.INVALID_VALUE);return}if(!this._checkStencilState())return;let i=this._vertexObjectState._elementArrayBufferBinding;if(!i){this.setError(this.INVALID_OPERATION);return}let a=null,o=r;if(n===this.UNSIGNED_SHORT){if(o%2){this.setError(this.INVALID_OPERATION);return}o>>=1,a=new Uint16Array(i._elements.buffer)}else if(this._extensions.oes_element_index_uint&&n===this.UNSIGNED_INT){if(o%4){this.setError(this.INVALID_OPERATION);return}o>>=2,a=new Uint32Array(i._elements.buffer)}else if(n===this.UNSIGNED_BYTE)a=i._elements;else{this.setError(this.INVALID_ENUM);return}let s=t;switch(e){case this.TRIANGLES:t%3&&(s-=t%3);break;case this.LINES:t%2&&(s-=t%2);break;case this.POINTS:break;case this.LINE_LOOP:case this.LINE_STRIP:if(t<2){this.setError(this.INVALID_OPERATION);return}break;case this.TRIANGLE_FAN:case this.TRIANGLE_STRIP:if(t<3){this.setError(this.INVALID_OPERATION);return}break;default:this.setError(this.INVALID_ENUM);return}if(!this._framebufferOk())return;if(t===0){this._checkVertexAttribState(0);return}if(t+o>>>0>a.length){this.setError(this.INVALID_OPERATION);return}let c=-1;for(let e=o;e<o+t;++e)c=Math.max(c,a[e]);if(c<0){this._checkVertexAttribState(0);return}if(this._checkVertexAttribState(c)&&s>0){if(this._vertexObjectState._attribs[0]._isPointer)return this._native.drawElements(e,s,n,r);this._beginAttrib0Hack(),this._native._drawElementsInstanced(e,s,n,r,1),this._endAttrib0Hack()}}};export{n as WebGLContextBase,i as WebGLRenderingContext};
1
+ import"./_virtual/_rolldown/runtime.js";import{Uint8ArrayToVariant as e,vertexCount as t}from"./utils.js";import{WebGLContextBase as n}from"./webgl-context-base.js";import r from"@girs/gwebgl-0.1";var WebGLRenderingContext=class extends n{get _gl(){return this._native}constructor(e,t={}){super(e,t),this._attrib0Buffer=null,this._native=new r.WebGLRenderingContext({}),this._init();let n=this.createBuffer();this._attrib0Buffer=n}_beginAttrib0Hack(){this._native.bindBuffer(this.ARRAY_BUFFER,this._attrib0Buffer?._||0);let t=new Uint8Array(this._vertexGlobalState._attribs[0]._data.buffer);this._native.bufferData(this.ARRAY_BUFFER,e(t),this.STREAM_DRAW),this._native.enableVertexAttribArray(0),this._native.vertexAttribPointer(0,4,this.FLOAT,!1,0,0),this._native._vertexAttribDivisor(0,1)}_endAttrib0Hack(){let e=this._vertexObjectState._attribs[0];e._pointerBuffer?this._native.bindBuffer(this.ARRAY_BUFFER,e._pointerBuffer._):this._native.bindBuffer(this.ARRAY_BUFFER,0),this._native.vertexAttribPointer(0,e._inputSize,e._pointerType,e._pointerNormal,e._inputStride,e._pointerOffset),this._native._vertexAttribDivisor(0,e._divisor),this._native.disableVertexAttribArray(0),this._vertexGlobalState._arrayBufferBinding?this._native.bindBuffer(this.ARRAY_BUFFER,this._vertexGlobalState._arrayBufferBinding._):this._native.bindBuffer(this.ARRAY_BUFFER,0)}drawArrays(e=0,n=0,r=0){if(n<0||r<0){this.setError(this.INVALID_VALUE);return}if(!this._checkStencilState())return;let i=t(this,e,r);if(i<0){this.setError(this.INVALID_ENUM);return}if(!this._framebufferOk()||r===0)return;let a=n;if(r>0&&(a=r+n-1>>>0),this._checkVertexAttribState(a)){if(this._vertexObjectState._attribs[0]._isPointer||this._extensions.webgl_draw_buffers&&this._extensions.webgl_draw_buffers._buffersState&&this._extensions.webgl_draw_buffers._buffersState.length>0)return this._native.drawArrays(e,n,i);this._beginAttrib0Hack(),this._native._drawArraysInstanced(e,n,i,1),this._endAttrib0Hack()}}drawElements(e=0,t=0,n=0,r=0){if(t<0||r<0){this.setError(this.INVALID_VALUE);return}if(!this._checkStencilState())return;let i=this._vertexObjectState._elementArrayBufferBinding;if(!i){this.setError(this.INVALID_OPERATION);return}let a=null,o=r;if(n===this.UNSIGNED_SHORT){if(o%2){this.setError(this.INVALID_OPERATION);return}o>>=1,a=new Uint16Array(i._elements.buffer)}else if(this._extensions.oes_element_index_uint&&n===this.UNSIGNED_INT){if(o%4){this.setError(this.INVALID_OPERATION);return}o>>=2,a=new Uint32Array(i._elements.buffer)}else if(n===this.UNSIGNED_BYTE)a=i._elements;else{this.setError(this.INVALID_ENUM);return}let s=t;switch(e){case this.TRIANGLES:t%3&&(s-=t%3);break;case this.LINES:t%2&&(s-=t%2);break;case this.POINTS:break;case this.LINE_LOOP:case this.LINE_STRIP:if(t<2){this.setError(this.INVALID_OPERATION);return}break;case this.TRIANGLE_FAN:case this.TRIANGLE_STRIP:if(t<3){this.setError(this.INVALID_OPERATION);return}break;default:this.setError(this.INVALID_ENUM);return}if(!this._framebufferOk())return;if(t===0){this._checkVertexAttribState(0);return}if(t+o>>>0>a.length){this.setError(this.INVALID_OPERATION);return}let c=-1;for(let e=o;e<o+t;++e)c=Math.max(c,a[e]);if(c<0){this._checkVertexAttribState(0);return}if(this._checkVertexAttribState(c)&&s>0){if(this._vertexObjectState._attribs[0]._isPointer)return this._native.drawElements(e,s,n,r);this._beginAttrib0Hack(),this._native._drawElementsInstanced(e,s,n,r,1),this._endAttrib0Hack()}}};export{n as WebGLContextBase,WebGLRenderingContext};
@@ -1 +1 @@
1
- import{Linkable as e}from"./linkable.js";var t=class extends e{constructor(e,t){super(e),this._ctx=t}_performDelete(){let e=this._ctx;delete e._samplers[this._|0],e._native2.deleteSampler(this._|0)}};export{t as WebGLSampler};
1
+ import"./_virtual/_rolldown/runtime.js";import{Linkable as e}from"./linkable.js";var WebGLSampler=class extends e{constructor(e,t){super(e),this._ctx=t}_performDelete(){let e=this._ctx;delete e._samplers[this._|0],e._native2.deleteSampler(this._|0)}};export{WebGLSampler};
@@ -1 +1 @@
1
- var e=class{constructor(e){this.rangeMin=e.rangeMin,this.rangeMax=e.rangeMax,this.precision=e.precision}};export{e as WebGLShaderPrecisionFormat};
1
+ import"./_virtual/_rolldown/runtime.js";var WebGLShaderPrecisionFormat=class{constructor(e){this.rangeMin=e.rangeMin,this.rangeMax=e.rangeMax,this.precision=e.precision}};export{WebGLShaderPrecisionFormat};
@@ -1 +1 @@
1
- import{Linkable as e}from"./linkable.js";var t=class extends e{constructor(e,t,n){super(e),this._source=``,this._compileStatus=!1,this._compileInfo=``,this._needsRecompile=!1,this._type=n,this._ctx=t,this._source=``,this._compileStatus=!1,this._compileInfo=``}_performDelete(){let e=this._ctx;delete e._shaders[this._|0],e._gl.deleteShader(this._|0)}};export{t as WebGLShader};
1
+ import"./_virtual/_rolldown/runtime.js";import{Linkable as e}from"./linkable.js";var WebGLShader=class extends e{constructor(e,t,n){super(e),this._source=``,this._compileStatus=!1,this._compileInfo=``,this._needsRecompile=!1,this._type=n,this._ctx=t,this._source=``,this._compileStatus=!1,this._compileInfo=``}_performDelete(){let e=this._ctx;delete e._shaders[this._|0],e._gl.deleteShader(this._|0)}};export{WebGLShader};
@@ -1 +1 @@
1
- import{Linkable as e}from"./linkable.js";var t=class extends e{constructor(e,t){super(e),this._ctx=t}_performDelete(){let e=this._ctx;delete e._syncs[this._|0],e._native2.deleteSync(this._|0)}};export{t as WebGLSync};
1
+ import"./_virtual/_rolldown/runtime.js";import{Linkable as e}from"./linkable.js";var WebGLSync=class extends e{constructor(e,t){super(e),this._ctx=t}_performDelete(){let e=this._ctx;delete e._syncs[this._|0],e._native2.deleteSync(this._|0)}};export{WebGLSync};