@gjsify/webgl 0.4.22 → 0.4.24
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.
- package/lib/esm/conformance/textures.spec.js +1 -1
- package/lib/esm/context/framebuffer.js +1 -1
- package/lib/esm/context/texture-management.js +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/esm/webgl-context-base.js +1 -1
- package/lib/types/context/framebuffer.d.ts +1 -0
- package/lib/types/context/texture-management.d.ts +1 -0
- package/lib/types/webgl-context-base.d.ts +6 -3
- package/package.json +7 -7
|
@@ -9,4 +9,4 @@ import{__name as e}from"../_virtual/_rolldown/runtime.js";import{destroyTestFBO
|
|
|
9
9
|
precision mediump float;
|
|
10
10
|
uniform sampler2D uTex;
|
|
11
11
|
varying vec2 vTexCoord;
|
|
12
|
-
void main() { gl_FragColor = texture2D(uTex, vTexCoord); }`;var p=e(async()=>{await u(`Display`,async()=>{let e=a();if(!e){console.warn(`WebGL context not available — skipping conformance/textures tests`);return}let{gl:u,glArea:p}=e;p.make_current(),await s(`textures/texImage2D-rgba`,async()=>{o(async()=>{p.make_current()}),await l(`upload 2×2 RGBA Uint8Array and sample it back`,async()=>{let e=i(u,2,2),a=new Uint8Array([255,0,0,255,0,255,0,255,0,0,255,255,255,255,0,255]),o=u.createTexture();u.bindTexture(u.TEXTURE_2D,o),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_WRAP_S,u.CLAMP_TO_EDGE),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_WRAP_T,u.CLAMP_TO_EDGE),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MIN_FILTER,u.NEAREST),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MAG_FILTER,u.NEAREST),u.texImage2D(u.TEXTURE_2D,0,u.RGBA,2,2,0,u.RGBA,u.UNSIGNED_BYTE,a);let s=r(u,d,f);u.useProgram(s),u.uniform1i(u.getUniformLocation(s,`uTex`),0),n(u),c(u.getError()).toBe(u.NO_ERROR),u.deleteTexture(o),t(u,e)}),await l(`createTexture returns non-null; deleteTexture cleans up`,async()=>{let e=u.createTexture();c(e).toBeDefined(),u.bindTexture(u.TEXTURE_2D,e),u.texImage2D(u.TEXTURE_2D,0,u.RGBA,1,1,0,u.RGBA,u.UNSIGNED_BYTE,new Uint8Array([128,128,128,255])),c(u.getError()).toBe(u.NO_ERROR),u.bindTexture(u.TEXTURE_2D,null),u.deleteTexture(e),c(u.getError()).toBe(u.NO_ERROR)})}),await s(`textures/alpha-texture`,async()=>{o(async()=>{p.make_current()}),await l(`ALPHA format texImage2D: RGB channels zero, alpha matches upload data`,async()=>{let e=i(u,4,4),a=new Uint8Array(16);for(let e=0;e<4;e++)for(let t=0;t<4;t++)a[e*4+t]=(e+t)%255;let o=u.createTexture();u.bindTexture(u.TEXTURE_2D,o),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_WRAP_S,u.CLAMP_TO_EDGE),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_WRAP_T,u.CLAMP_TO_EDGE),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MIN_FILTER,u.NEAREST),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MAG_FILTER,u.NEAREST),u.texImage2D(u.TEXTURE_2D,0,u.ALPHA,4,4,0,u.ALPHA,u.UNSIGNED_BYTE,a),c(u.getError()).toBe(u.NO_ERROR),u.clearColor(0,0,0,0),u.clear(u.COLOR_BUFFER_BIT);let s=r(u,d,f);u.useProgram(s),u.uniform1i(u.getUniformLocation(s,`uTex`),0),n(u),c(u.getError()).toBe(u.NO_ERROR);let l=new Uint8Array(64);u.readPixels(0,0,4,4,u.RGBA,u.UNSIGNED_BYTE,l);let p=!0;for(let e=0;e<16;e++){let t=e*4;if(l[t]!==0||l[t+1]!==0||l[t+2]!==0){p=!1;break}if(Math.abs(l[t+3]-a[e])>3){p=!1;break}}c(p).toBe(!0),u.deleteTexture(o),t(u,e)})}),await s(`textures/texSubImage2D`,async()=>{o(async()=>{p.make_current()}),await l(`texSubImage2D overwrites a sub-region of an RGBA texture`,async()=>{let e=i(u,4,4),n=new Uint8Array(64).fill(0);for(let e=0;e<16;e++)n[e*4]=255,n[e*4+3]=255;let r=u.createTexture();u.bindTexture(u.TEXTURE_2D,r),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_WRAP_S,u.CLAMP_TO_EDGE),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_WRAP_T,u.CLAMP_TO_EDGE),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MIN_FILTER,u.NEAREST),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MAG_FILTER,u.NEAREST),u.texImage2D(u.TEXTURE_2D,0,u.RGBA,4,4,0,u.RGBA,u.UNSIGNED_BYTE,n);let a=new Uint8Array([0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255]);u.texSubImage2D(u.TEXTURE_2D,0,0,0,2,2,u.RGBA,u.UNSIGNED_BYTE,a),c(u.getError()).toBe(u.NO_ERROR),u.deleteTexture(r),t(u,e)})}),await s(`textures/parameters`,async()=>{o(async()=>{p.make_current()}),await l(`getTexParameter returns set WRAP and FILTER values`,async()=>{let e=u.createTexture();u.bindTexture(u.TEXTURE_2D,e),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_WRAP_S,u.CLAMP_TO_EDGE),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_WRAP_T,u.REPEAT),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MIN_FILTER,u.LINEAR),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MAG_FILTER,u.NEAREST),c(u.getTexParameter(u.TEXTURE_2D,u.TEXTURE_WRAP_S)).toBe(u.CLAMP_TO_EDGE),c(u.getTexParameter(u.TEXTURE_2D,u.TEXTURE_WRAP_T)).toBe(u.REPEAT),c(u.getTexParameter(u.TEXTURE_2D,u.TEXTURE_MIN_FILTER)).toBe(u.LINEAR),c(u.getTexParameter(u.TEXTURE_2D,u.TEXTURE_MAG_FILTER)).toBe(u.NEAREST),c(u.getError()).toBe(u.NO_ERROR),u.bindTexture(u.TEXTURE_2D,null),u.deleteTexture(e)}),await l(`MIRRORED_REPEAT wrap mode is accepted`,async()=>{let e=u.createTexture();u.bindTexture(u.TEXTURE_2D,e),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_WRAP_S,u.MIRRORED_REPEAT),c(u.getError()).toBe(u.NO_ERROR),c(u.getTexParameter(u.TEXTURE_2D,u.TEXTURE_WRAP_S)).toBe(u.MIRRORED_REPEAT),u.bindTexture(u.TEXTURE_2D,null),u.deleteTexture(e)}),await l(`LINEAR_MIPMAP_LINEAR min filter is accepted`,async()=>{let e=u.createTexture();u.bindTexture(u.TEXTURE_2D,e),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MIN_FILTER,u.LINEAR_MIPMAP_LINEAR),c(u.getError()).toBe(u.NO_ERROR),c(u.getTexParameter(u.TEXTURE_2D,u.TEXTURE_MIN_FILTER)).toBe(u.LINEAR_MIPMAP_LINEAR),u.bindTexture(u.TEXTURE_2D,null),u.deleteTexture(e)})}),await s(`textures/active-texture`,async()=>{o(async()=>{p.make_current()}),await l(`activeTexture switches binding slot; each unit holds independent binding`,async()=>{let e=u.createTexture(),t=u.createTexture();u.activeTexture(u.TEXTURE0),u.bindTexture(u.TEXTURE_2D,e),u.activeTexture(u.TEXTURE1),u.bindTexture(u.TEXTURE_2D,t),u.activeTexture(u.TEXTURE0),c(u.getParameter(u.TEXTURE_BINDING_2D)).toBe(e),u.activeTexture(u.TEXTURE1),c(u.getParameter(u.TEXTURE_BINDING_2D)).toBe(t),c(u.getError()).toBe(u.NO_ERROR),u.activeTexture(u.TEXTURE0),u.bindTexture(u.TEXTURE_2D,null),u.activeTexture(u.TEXTURE1),u.bindTexture(u.TEXTURE_2D,null),u.deleteTexture(e),u.deleteTexture(t)}),await l(`getParameter ACTIVE_TEXTURE reflects activeTexture call`,async()=>{u.activeTexture(u.TEXTURE3),c(u.getParameter(u.ACTIVE_TEXTURE)).toBe(u.TEXTURE3),u.activeTexture(u.TEXTURE0),c(u.getParameter(u.ACTIVE_TEXTURE)).toBe(u.TEXTURE0),c(u.getError()).toBe(u.NO_ERROR)})}),await s(`textures/cubemap`,async()=>{o(async()=>{p.make_current()}),await l(`attach all 6 cubemap faces to FBO — no GL error`,async()=>{let e=u.createTexture(),t=u.createFramebuffer(),n=new Uint8Array([255,255,255,255]);u.activeTexture(u.TEXTURE1),u.bindTexture(u.TEXTURE_CUBE_MAP,e),u.texParameteri(u.TEXTURE_CUBE_MAP,u.TEXTURE_WRAP_S,u.CLAMP_TO_EDGE),u.texParameteri(u.TEXTURE_CUBE_MAP,u.TEXTURE_WRAP_T,u.CLAMP_TO_EDGE),u.texParameteri(u.TEXTURE_CUBE_MAP,u.TEXTURE_MAG_FILTER,u.NEAREST),u.texParameteri(u.TEXTURE_CUBE_MAP,u.TEXTURE_MIN_FILTER,u.NEAREST),u.bindFramebuffer(u.FRAMEBUFFER,t);for(let t=0;t<6;t++)u.texImage2D(u.TEXTURE_CUBE_MAP_POSITIVE_X+t,0,u.RGBA,1,1,0,u.RGBA,u.UNSIGNED_BYTE,n),u.framebufferTexture2D(u.FRAMEBUFFER,u.COLOR_ATTACHMENT0,u.TEXTURE_CUBE_MAP_POSITIVE_X+t,e,0);c(u.getError()).toBe(u.NO_ERROR),u.bindFramebuffer(u.FRAMEBUFFER,null),u.activeTexture(u.TEXTURE1),u.bindTexture(u.TEXTURE_CUBE_MAP,null),u.activeTexture(u.TEXTURE0),u.deleteTexture(e),u.deleteFramebuffer(t)}),await l(`createTexture with TEXTURE_CUBE_MAP binding — no error`,async()=>{let e=u.createTexture();u.bindTexture(u.TEXTURE_CUBE_MAP,e),u.texParameteri(u.TEXTURE_CUBE_MAP,u.TEXTURE_MIN_FILTER,u.LINEAR),u.texParameteri(u.TEXTURE_CUBE_MAP,u.TEXTURE_MAG_FILTER,u.LINEAR),u.texParameteri(u.TEXTURE_CUBE_MAP,u.TEXTURE_WRAP_S,u.CLAMP_TO_EDGE),u.texParameteri(u.TEXTURE_CUBE_MAP,u.TEXTURE_WRAP_T,u.CLAMP_TO_EDGE),c(u.getError()).toBe(u.NO_ERROR),u.bindTexture(u.TEXTURE_CUBE_MAP,null),u.deleteTexture(e)})}),await s(`textures/luminance`,async()=>{o(async()=>{p.make_current()}),await l(`LUMINANCE format texImage2D — no error`,async()=>{let e=u.createTexture();u.bindTexture(u.TEXTURE_2D,e),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MIN_FILTER,u.NEAREST),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MAG_FILTER,u.NEAREST);let t=new Uint8Array([128,64,192,32]);u.texImage2D(u.TEXTURE_2D,0,u.LUMINANCE,4,1,0,u.LUMINANCE,u.UNSIGNED_BYTE,t),c(u.getError()).toBe(u.NO_ERROR),u.bindTexture(u.TEXTURE_2D,null),u.deleteTexture(e)}),await l(`LUMINANCE_ALPHA format texImage2D — no error`,async()=>{let e=u.createTexture();u.bindTexture(u.TEXTURE_2D,e),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MIN_FILTER,u.NEAREST),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MAG_FILTER,u.NEAREST);let t=new Uint8Array([128,255,64,128]);u.texImage2D(u.TEXTURE_2D,0,u.LUMINANCE_ALPHA,2,1,0,u.LUMINANCE_ALPHA,u.UNSIGNED_BYTE,t),c(u.getError()).toBe(u.NO_ERROR),u.bindTexture(u.TEXTURE_2D,null),u.deleteTexture(e)})}),await s(`textures/generateMipmap`,async()=>{o(async()=>{p.make_current()}),await l(`generateMipmap on power-of-two RGBA texture — no error`,async()=>{let e=u.createTexture();u.bindTexture(u.TEXTURE_2D,e),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MIN_FILTER,u.LINEAR_MIPMAP_LINEAR),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MAG_FILTER,u.LINEAR);let t=new Uint8Array(64).fill(255);u.texImage2D(u.TEXTURE_2D,0,u.RGBA,4,4,0,u.RGBA,u.UNSIGNED_BYTE,t),u.generateMipmap(u.TEXTURE_2D),c(u.getError()).toBe(u.NO_ERROR),u.bindTexture(u.TEXTURE_2D,null),u.deleteTexture(e)})})})},`default`);export{p as default};
|
|
12
|
+
void main() { gl_FragColor = texture2D(uTex, vTexCoord); }`;var p=e(async()=>{await u(`Display`,async()=>{let e=a();if(!e){console.warn(`WebGL context not available — skipping conformance/textures tests`);return}let{gl:u,glArea:p}=e;p.make_current(),await s(`textures/texImage2D-rgba`,async()=>{o(async()=>{p.make_current()}),await l(`upload 2×2 RGBA Uint8Array and sample it back`,async()=>{let e=i(u,2,2),a=new Uint8Array([255,0,0,255,0,255,0,255,0,0,255,255,255,255,0,255]),o=u.createTexture();u.bindTexture(u.TEXTURE_2D,o),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_WRAP_S,u.CLAMP_TO_EDGE),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_WRAP_T,u.CLAMP_TO_EDGE),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MIN_FILTER,u.NEAREST),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MAG_FILTER,u.NEAREST),u.texImage2D(u.TEXTURE_2D,0,u.RGBA,2,2,0,u.RGBA,u.UNSIGNED_BYTE,a);let s=r(u,d,f);u.useProgram(s),u.uniform1i(u.getUniformLocation(s,`uTex`),0),n(u),c(u.getError()).toBe(u.NO_ERROR),u.deleteTexture(o),t(u,e)}),await l(`createTexture returns non-null; deleteTexture cleans up`,async()=>{let e=u.createTexture();c(e).toBeDefined(),u.bindTexture(u.TEXTURE_2D,e),u.texImage2D(u.TEXTURE_2D,0,u.RGBA,1,1,0,u.RGBA,u.UNSIGNED_BYTE,new Uint8Array([128,128,128,255])),c(u.getError()).toBe(u.NO_ERROR),u.bindTexture(u.TEXTURE_2D,null),u.deleteTexture(e),c(u.getError()).toBe(u.NO_ERROR)})}),await s(`textures/alpha-texture`,async()=>{o(async()=>{p.make_current()}),await l(`ALPHA format texImage2D: RGB channels zero, alpha matches upload data`,async()=>{let e=i(u,4,4),a=new Uint8Array(16);for(let e=0;e<4;e++)for(let t=0;t<4;t++)a[e*4+t]=(e+t)%255;let o=u.createTexture();u.bindTexture(u.TEXTURE_2D,o),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_WRAP_S,u.CLAMP_TO_EDGE),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_WRAP_T,u.CLAMP_TO_EDGE),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MIN_FILTER,u.NEAREST),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MAG_FILTER,u.NEAREST),u.texImage2D(u.TEXTURE_2D,0,u.ALPHA,4,4,0,u.ALPHA,u.UNSIGNED_BYTE,a),c(u.getError()).toBe(u.NO_ERROR),u.clearColor(0,0,0,0),u.clear(u.COLOR_BUFFER_BIT);let s=r(u,d,f);u.useProgram(s),u.uniform1i(u.getUniformLocation(s,`uTex`),0),n(u),c(u.getError()).toBe(u.NO_ERROR);let l=new Uint8Array(64);u.readPixels(0,0,4,4,u.RGBA,u.UNSIGNED_BYTE,l);let p=!0;for(let e=0;e<16;e++){let t=e*4;if(l[t]!==0||l[t+1]!==0||l[t+2]!==0){p=!1;break}if(Math.abs(l[t+3]-a[e])>3){p=!1;break}}c(p).toBe(!0),u.deleteTexture(o),t(u,e)})}),await s(`textures/texSubImage2D`,async()=>{o(async()=>{p.make_current()}),await l(`texSubImage2D overwrites a sub-region of an RGBA texture`,async()=>{let e=i(u,4,4),n=new Uint8Array(64).fill(0);for(let e=0;e<16;e++)n[e*4]=255,n[e*4+3]=255;let r=u.createTexture();u.bindTexture(u.TEXTURE_2D,r),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_WRAP_S,u.CLAMP_TO_EDGE),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_WRAP_T,u.CLAMP_TO_EDGE),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MIN_FILTER,u.NEAREST),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MAG_FILTER,u.NEAREST),u.texImage2D(u.TEXTURE_2D,0,u.RGBA,4,4,0,u.RGBA,u.UNSIGNED_BYTE,n);let a=new Uint8Array([0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255]);u.texSubImage2D(u.TEXTURE_2D,0,0,0,2,2,u.RGBA,u.UNSIGNED_BYTE,a),c(u.getError()).toBe(u.NO_ERROR),u.deleteTexture(r),t(u,e)})}),await s(`textures/parameters`,async()=>{o(async()=>{p.make_current()}),await l(`getTexParameter returns set WRAP and FILTER values`,async()=>{let e=u.createTexture();u.bindTexture(u.TEXTURE_2D,e),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_WRAP_S,u.CLAMP_TO_EDGE),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_WRAP_T,u.REPEAT),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MIN_FILTER,u.LINEAR),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MAG_FILTER,u.NEAREST),c(u.getTexParameter(u.TEXTURE_2D,u.TEXTURE_WRAP_S)).toBe(u.CLAMP_TO_EDGE),c(u.getTexParameter(u.TEXTURE_2D,u.TEXTURE_WRAP_T)).toBe(u.REPEAT),c(u.getTexParameter(u.TEXTURE_2D,u.TEXTURE_MIN_FILTER)).toBe(u.LINEAR),c(u.getTexParameter(u.TEXTURE_2D,u.TEXTURE_MAG_FILTER)).toBe(u.NEAREST),c(u.getError()).toBe(u.NO_ERROR),u.bindTexture(u.TEXTURE_2D,null),u.deleteTexture(e)}),await l(`MIRRORED_REPEAT wrap mode is accepted`,async()=>{let e=u.createTexture();u.bindTexture(u.TEXTURE_2D,e),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_WRAP_S,u.MIRRORED_REPEAT),c(u.getError()).toBe(u.NO_ERROR),c(u.getTexParameter(u.TEXTURE_2D,u.TEXTURE_WRAP_S)).toBe(u.MIRRORED_REPEAT),u.bindTexture(u.TEXTURE_2D,null),u.deleteTexture(e)}),await l(`LINEAR_MIPMAP_LINEAR min filter is accepted`,async()=>{let e=u.createTexture();u.bindTexture(u.TEXTURE_2D,e),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MIN_FILTER,u.LINEAR_MIPMAP_LINEAR),c(u.getError()).toBe(u.NO_ERROR),c(u.getTexParameter(u.TEXTURE_2D,u.TEXTURE_MIN_FILTER)).toBe(u.LINEAR_MIPMAP_LINEAR),u.bindTexture(u.TEXTURE_2D,null),u.deleteTexture(e)})}),await s(`textures/active-texture`,async()=>{o(async()=>{p.make_current()}),await l(`activeTexture switches binding slot; each unit holds independent binding`,async()=>{let e=u.createTexture(),t=u.createTexture();u.activeTexture(u.TEXTURE0),u.bindTexture(u.TEXTURE_2D,e),u.activeTexture(u.TEXTURE1),u.bindTexture(u.TEXTURE_2D,t),u.activeTexture(u.TEXTURE0),c(u.getParameter(u.TEXTURE_BINDING_2D)).toBe(e),u.activeTexture(u.TEXTURE1),c(u.getParameter(u.TEXTURE_BINDING_2D)).toBe(t),c(u.getError()).toBe(u.NO_ERROR),u.activeTexture(u.TEXTURE0),u.bindTexture(u.TEXTURE_2D,null),u.activeTexture(u.TEXTURE1),u.bindTexture(u.TEXTURE_2D,null),u.deleteTexture(e),u.deleteTexture(t)}),await l(`getParameter ACTIVE_TEXTURE reflects activeTexture call`,async()=>{u.activeTexture(u.TEXTURE3),c(u.getParameter(u.ACTIVE_TEXTURE)).toBe(u.TEXTURE3),u.activeTexture(u.TEXTURE0),c(u.getParameter(u.ACTIVE_TEXTURE)).toBe(u.TEXTURE0),c(u.getError()).toBe(u.NO_ERROR)})}),await s(`textures/cubemap`,async()=>{o(async()=>{p.make_current()}),await l(`attach all 6 cubemap faces to FBO — no GL error`,async()=>{let e=u.createTexture(),t=u.createFramebuffer(),n=new Uint8Array([255,255,255,255]);u.activeTexture(u.TEXTURE1),u.bindTexture(u.TEXTURE_CUBE_MAP,e),u.texParameteri(u.TEXTURE_CUBE_MAP,u.TEXTURE_WRAP_S,u.CLAMP_TO_EDGE),u.texParameteri(u.TEXTURE_CUBE_MAP,u.TEXTURE_WRAP_T,u.CLAMP_TO_EDGE),u.texParameteri(u.TEXTURE_CUBE_MAP,u.TEXTURE_MAG_FILTER,u.NEAREST),u.texParameteri(u.TEXTURE_CUBE_MAP,u.TEXTURE_MIN_FILTER,u.NEAREST),u.bindFramebuffer(u.FRAMEBUFFER,t);for(let t=0;t<6;t++)u.texImage2D(u.TEXTURE_CUBE_MAP_POSITIVE_X+t,0,u.RGBA,1,1,0,u.RGBA,u.UNSIGNED_BYTE,n),u.framebufferTexture2D(u.FRAMEBUFFER,u.COLOR_ATTACHMENT0,u.TEXTURE_CUBE_MAP_POSITIVE_X+t,e,0);c(u.getError()).toBe(u.NO_ERROR),u.bindFramebuffer(u.FRAMEBUFFER,null),u.activeTexture(u.TEXTURE1),u.bindTexture(u.TEXTURE_CUBE_MAP,null),u.activeTexture(u.TEXTURE0),u.deleteTexture(e),u.deleteFramebuffer(t)}),await l(`createTexture with TEXTURE_CUBE_MAP binding — no error`,async()=>{let e=u.createTexture();u.bindTexture(u.TEXTURE_CUBE_MAP,e),u.texParameteri(u.TEXTURE_CUBE_MAP,u.TEXTURE_MIN_FILTER,u.LINEAR),u.texParameteri(u.TEXTURE_CUBE_MAP,u.TEXTURE_MAG_FILTER,u.LINEAR),u.texParameteri(u.TEXTURE_CUBE_MAP,u.TEXTURE_WRAP_S,u.CLAMP_TO_EDGE),u.texParameteri(u.TEXTURE_CUBE_MAP,u.TEXTURE_WRAP_T,u.CLAMP_TO_EDGE),c(u.getError()).toBe(u.NO_ERROR),u.bindTexture(u.TEXTURE_CUBE_MAP,null),u.deleteTexture(e)})}),await s(`textures/luminance`,async()=>{o(async()=>{p.make_current()}),await l(`LUMINANCE format texImage2D — no error`,async()=>{let e=u.createTexture();u.bindTexture(u.TEXTURE_2D,e),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MIN_FILTER,u.NEAREST),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MAG_FILTER,u.NEAREST);let t=new Uint8Array([128,64,192,32]);u.texImage2D(u.TEXTURE_2D,0,u.LUMINANCE,4,1,0,u.LUMINANCE,u.UNSIGNED_BYTE,t),c(u.getError()).toBe(u.NO_ERROR),u.bindTexture(u.TEXTURE_2D,null),u.deleteTexture(e)}),await l(`LUMINANCE_ALPHA format texImage2D — no error`,async()=>{let e=u.createTexture();u.bindTexture(u.TEXTURE_2D,e),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MIN_FILTER,u.NEAREST),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MAG_FILTER,u.NEAREST);let t=new Uint8Array([128,255,64,128]);u.texImage2D(u.TEXTURE_2D,0,u.LUMINANCE_ALPHA,2,1,0,u.LUMINANCE_ALPHA,u.UNSIGNED_BYTE,t),c(u.getError()).toBe(u.NO_ERROR),u.bindTexture(u.TEXTURE_2D,null),u.deleteTexture(e)})}),await s(`textures/generateMipmap`,async()=>{o(async()=>{p.make_current()}),await l(`generateMipmap on power-of-two RGBA texture — no error`,async()=>{let e=u.createTexture();u.bindTexture(u.TEXTURE_2D,e),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MIN_FILTER,u.LINEAR_MIPMAP_LINEAR),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MAG_FILTER,u.LINEAR);let t=new Uint8Array(64).fill(255);u.texImage2D(u.TEXTURE_2D,0,u.RGBA,4,4,0,u.RGBA,u.UNSIGNED_BYTE,t),u.generateMipmap(u.TEXTURE_2D),c(u.getError()).toBe(u.NO_ERROR),u.bindTexture(u.TEXTURE_2D,null),u.deleteTexture(e)})}),await s(`textures/deleteTexture-multiFBO`,async()=>{o(async()=>{p.make_current()}),await l(`detaches deleted texture from every framebuffer that referenced it`,async()=>{let e=u.createTexture();u.bindTexture(u.TEXTURE_2D,e),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MIN_FILTER,u.NEAREST),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MAG_FILTER,u.NEAREST),u.texImage2D(u.TEXTURE_2D,0,u.RGBA,1,1,0,u.RGBA,u.UNSIGNED_BYTE,new Uint8Array([255,255,255,255]));let t=u.createFramebuffer();u.bindFramebuffer(u.FRAMEBUFFER,t),u.framebufferTexture2D(u.FRAMEBUFFER,u.COLOR_ATTACHMENT0,u.TEXTURE_2D,e,0);let n=u.createFramebuffer();u.bindFramebuffer(u.FRAMEBUFFER,n),u.framebufferTexture2D(u.FRAMEBUFFER,u.COLOR_ATTACHMENT0,u.TEXTURE_2D,e,0),c(u.getError()).toBe(u.NO_ERROR),c(u.getFramebufferAttachmentParameter(u.FRAMEBUFFER,u.COLOR_ATTACHMENT0,u.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)).toBe(u.TEXTURE),u.bindFramebuffer(u.FRAMEBUFFER,t),c(u.getFramebufferAttachmentParameter(u.FRAMEBUFFER,u.COLOR_ATTACHMENT0,u.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)).toBe(u.TEXTURE),u.bindFramebuffer(u.FRAMEBUFFER,n),u.bindTexture(u.TEXTURE_2D,null),u.deleteTexture(e),c(u.getFramebufferAttachmentParameter(u.FRAMEBUFFER,u.COLOR_ATTACHMENT0,u.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)).toBe(u.NONE),u.bindFramebuffer(u.FRAMEBUFFER,t),c(u.getFramebufferAttachmentParameter(u.FRAMEBUFFER,u.COLOR_ATTACHMENT0,u.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)).toBe(u.NONE),c(u.getError()).toBe(u.NO_ERROR),u.bindFramebuffer(u.FRAMEBUFFER,null),u.deleteFramebuffer(t),u.deleteFramebuffer(n)}),await l(`detaches deleted renderbuffer from every framebuffer that referenced it`,async()=>{let e=u.createRenderbuffer();u.bindRenderbuffer(u.RENDERBUFFER,e),u.renderbufferStorage(u.RENDERBUFFER,u.DEPTH_COMPONENT16,1,1);let t=u.createFramebuffer();u.bindFramebuffer(u.FRAMEBUFFER,t),u.framebufferRenderbuffer(u.FRAMEBUFFER,u.DEPTH_ATTACHMENT,u.RENDERBUFFER,e);let n=u.createFramebuffer();u.bindFramebuffer(u.FRAMEBUFFER,n),u.framebufferRenderbuffer(u.FRAMEBUFFER,u.DEPTH_ATTACHMENT,u.RENDERBUFFER,e),c(u.getError()).toBe(u.NO_ERROR),u.bindRenderbuffer(u.RENDERBUFFER,null),u.deleteRenderbuffer(e),c(u.getFramebufferAttachmentParameter(u.FRAMEBUFFER,u.DEPTH_ATTACHMENT,u.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)).toBe(u.NONE),u.bindFramebuffer(u.FRAMEBUFFER,t),c(u.getFramebufferAttachmentParameter(u.FRAMEBUFFER,u.DEPTH_ATTACHMENT,u.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)).toBe(u.NONE),c(u.getError()).toBe(u.NO_ERROR),u.bindFramebuffer(u.FRAMEBUFFER,null),u.deleteFramebuffer(t),u.deleteFramebuffer(n)})})})},`default`);export{p as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../_virtual/_rolldown/runtime.js";import{Uint8ArrayToVariant as e,checkObject as t}from"../utils.js";import{WebGLFramebuffer as n}from"../webgl-framebuffer.js";import{WebGLRenderbuffer as r}from"../webgl-renderbuffer.js";import{WebGLTexture as i}from"../webgl-texture.js";import{WebGLDrawingBufferWrapper as a}from"../webgl-drawing-buffer-wrapper.js";const o={bindFramebuffer(e,r){if(!t(r))throw TypeError(`bindFramebuffer(GLenum, WebGLFramebuffer)`);if(e!==this.FRAMEBUFFER){this.setError(this.INVALID_ENUM);return}if(!r)this._gl.bindFramebuffer(this.FRAMEBUFFER,this._gtkFboId);else if(r._pendingDelete)return;else if(this._checkWrapper(r,n))this._gl.bindFramebuffer(this.FRAMEBUFFER,r._|0);else return;let i=this._activeFramebuffer;i!==r&&(i&&(--i._refCount,i._checkDelete()),r&&(r._refCount+=1)),this._activeFramebuffer=r,r&&this._updateFramebufferAttachments(r)},bindRenderbuffer(e,n){if(!t(n))throw TypeError(`bindRenderbuffer(GLenum, WebGLRenderbuffer)`);if(e!==this.RENDERBUFFER){this.setError(this.INVALID_ENUM);return}if(!n)this._gl.bindRenderbuffer(e|0,0);else if(n._pendingDelete)return;else if(this._checkWrapper(n,r))this._gl.bindRenderbuffer(e|0,n._|0);else return;let i=this._activeRenderbuffer;i!==n&&(i&&(--i._refCount,i._checkDelete()),n&&(n._refCount+=1)),this._activeRenderbuffer=n},framebufferRenderbuffer(e,n,i,a){if(!t(a))throw TypeError(`framebufferRenderbuffer(GLenum, GLenum, GLenum, WebGLRenderbuffer)`);if(e!==this.FRAMEBUFFER||!this._validFramebufferAttachment(n)||i!==this.RENDERBUFFER){this.setError(this.INVALID_ENUM);return}let o=this._activeFramebuffer;if(!o){this.setError(this.INVALID_OPERATION);return}a&&!this._checkWrapper(a,r)||(o._setAttachment(a,n),this._updateFramebufferAttachments(o))},framebufferTexture2D(e,n,r,a,o=0){if(e|=0,n|=0,r|=0,o|=0,!t(a))throw TypeError(`framebufferTexture2D(GLenum, GLenum, GLenum, WebGLTexture, GLint)`);if(e!==this.FRAMEBUFFER||!this._validFramebufferAttachment(n)){this.setError(this.INVALID_ENUM);return}if(o!==0){this.setError(this.INVALID_VALUE);return}if(a&&!this._checkWrapper(a,i))return;if(r===this.TEXTURE_2D){if(a&&a._binding!==this.TEXTURE_2D){this.setError(this.INVALID_OPERATION);return}}else if(this._validCubeTarget(r)){if(a&&a._binding!==this.TEXTURE_CUBE_MAP){this.setError(this.INVALID_OPERATION);return}}else{this.setError(this.INVALID_ENUM);return}let s=this._activeFramebuffer;if(!s){this.setError(this.INVALID_OPERATION);return}s._attachmentLevel[n]=o,s._attachmentFace[n]=r,s._setAttachment(a,n),this._updateFramebufferAttachments(s)},createFramebuffer(){let e=this._gl.createFramebuffer();if(e<=0)return null;let t=new n(e,this);return this._framebuffers[e]=t,t},deleteFramebuffer(e){if(!t(e))throw TypeError(`deleteFramebuffer(WebGLFramebuffer)`);if(!(e instanceof n&&this._checkOwns(e))){this.setError(this.INVALID_OPERATION);return}this._activeFramebuffer===e&&this.bindFramebuffer(this.FRAMEBUFFER,null),e._pendingDelete=!0,e._checkDelete()},createRenderbuffer(){let e=this._gl.createRenderbuffer();if(e<=0)return null;let t=new r(e,this);return this._renderbuffers[e]=t,t},deleteRenderbuffer(e){if(!t(e))throw TypeError(`deleteRenderbuffer(WebGLRenderbuffer)`);if(!(e instanceof r&&this._checkOwns(e))){this.setError(this.INVALID_OPERATION);return}this._activeRenderbuffer===e&&this.bindRenderbuffer(this.RENDERBUFFER,null);let n=this._activeFramebuffer;this._tryDetachFramebuffer(n,e),e._pendingDelete=!0,e._checkDelete()},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)}},getFramebufferAttachmentParameter(e=0,t=0,n=0){if(e!==this.FRAMEBUFFER||!this._validFramebufferAttachment(t))return this.setError(this.INVALID_ENUM),null;let a=this._activeFramebuffer;if(!a)return this.setError(this.INVALID_OPERATION),null;let o=a._attachments[t];if(o===null){if(n===this.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)return this.NONE}else if(o instanceof i)switch(n){case this.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:return o;case this.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:return this.TEXTURE;case this.FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:return a._attachmentLevel[t];case this.FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:{let e=a._attachmentFace[t];return e===this.TEXTURE_2D?0:e}}else if(o instanceof r)switch(n){case this.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:return o;case this.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:return this.RENDERBUFFER}return this.setError(this.INVALID_ENUM),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},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},_preCheckFramebufferStatus(e){let t=e._attachments,n=[],a=[],o=t[this.DEPTH_ATTACHMENT],s=t[this.DEPTH_STENCIL_ATTACHMENT],c=t[this.STENCIL_ATTACHMENT];if(s&&(c||o)||c&&o)return this.FRAMEBUFFER_UNSUPPORTED;let l=this._getColorAttachments(),u=0;for(let e in t)t[e]&&l.indexOf(Number(e))!==-1&&u++;if(u===0)return this.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;if(s instanceof i)return this.FRAMEBUFFER_UNSUPPORTED;if(s instanceof r){if(s._format!==this.DEPTH_STENCIL)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;n.push(s._width),a.push(s._height)}if(o instanceof i)return this.FRAMEBUFFER_UNSUPPORTED;if(o instanceof r){if(o._format!==this.DEPTH_COMPONENT16)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;n.push(o._width),a.push(o._height)}if(c instanceof i)return this.FRAMEBUFFER_UNSUPPORTED;if(c instanceof r){if(c._format!==this.STENCIL_INDEX8)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;n.push(c._width),a.push(c._height)}let d=!1;for(let o=0;o<l.length;++o){let s=t[l[o]];if(s instanceof i){if(s._format!==this.RGBA||!(s._type===this.UNSIGNED_BYTE||s._type===this.FLOAT))return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;d=!0;let t=e._attachmentLevel[this.COLOR_ATTACHMENT0];if(t===null)throw TypeError(`level is null!`);n.push(s._levelWidth[t]),a.push(s._levelHeight[t])}else if(s instanceof r){let e=s._format;if(e!==this.RGBA4&&e!==this.RGB565&&e!==this.RGB5_A1)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;d=!0,n.push(s._width),a.push(s._height)}}if(!d&&!c&&!o&&!s)return this.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;if(n.length<=0||a.length<=0)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;for(let e=1;e<n.length;++e)if(n[e-1]!==n[e]||a[e-1]!==a[e])return this.FRAMEBUFFER_INCOMPLETE_DIMENSIONS;return n[0]===0||a[0]===0?this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:(e._width=n[0],e._height=a[0],this.FRAMEBUFFER_COMPLETE)},_framebufferOk(){let e=this._activeFramebuffer;return e&&this._preCheckFramebufferStatus(e)!==this.FRAMEBUFFER_COMPLETE?(this.setError(this.INVALID_FRAMEBUFFER_OPERATION),!1):!0},_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},_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 a=n[t],o=e._attachments[a];o instanceof i?this._gl.framebufferTexture2D(this.FRAMEBUFFER,a,e._attachmentFace[a]||0,o._|0,e._attachmentLevel[a]||0):o instanceof r&&this._gl.framebufferRenderbuffer(this.FRAMEBUFFER,a,this.RENDERBUFFER,o._|0)}},_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)}},_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},_resizeDrawingBuffer(t,n){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,t,n,0,l,this.UNSIGNED_BYTE,e(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,t,n),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)},_allocateDrawingBuffer(e,t){this._drawingBuffer=new a(this._gl.createFramebuffer(),this._gl.createTexture(),this._gl.createRenderbuffer()),this._resizeDrawingBuffer(e,t)},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`)}};function installFramebufferMethods(e){Object.assign(e,o)}export{installFramebufferMethods};
|
|
1
|
+
import"../_virtual/_rolldown/runtime.js";import{Uint8ArrayToVariant as e,checkObject as t}from"../utils.js";import{WebGLFramebuffer as n}from"../webgl-framebuffer.js";import{WebGLRenderbuffer as r}from"../webgl-renderbuffer.js";import{WebGLTexture as i}from"../webgl-texture.js";import{WebGLDrawingBufferWrapper as a}from"../webgl-drawing-buffer-wrapper.js";const o={bindFramebuffer(e,r){if(!t(r))throw TypeError(`bindFramebuffer(GLenum, WebGLFramebuffer)`);if(e!==this.FRAMEBUFFER){this.setError(this.INVALID_ENUM);return}if(!r)this._gl.bindFramebuffer(this.FRAMEBUFFER,this._gtkFboId);else if(r._pendingDelete)return;else if(this._checkWrapper(r,n))this._gl.bindFramebuffer(this.FRAMEBUFFER,r._|0);else return;let i=this._activeFramebuffer;i!==r&&(i&&(--i._refCount,i._checkDelete()),r&&(r._refCount+=1)),this._activeFramebuffer=r,r&&this._updateFramebufferAttachments(r)},bindRenderbuffer(e,n){if(!t(n))throw TypeError(`bindRenderbuffer(GLenum, WebGLRenderbuffer)`);if(e!==this.RENDERBUFFER){this.setError(this.INVALID_ENUM);return}if(!n)this._gl.bindRenderbuffer(e|0,0);else if(n._pendingDelete)return;else if(this._checkWrapper(n,r))this._gl.bindRenderbuffer(e|0,n._|0);else return;let i=this._activeRenderbuffer;i!==n&&(i&&(--i._refCount,i._checkDelete()),n&&(n._refCount+=1)),this._activeRenderbuffer=n},framebufferRenderbuffer(e,n,i,a){if(!t(a))throw TypeError(`framebufferRenderbuffer(GLenum, GLenum, GLenum, WebGLRenderbuffer)`);if(e!==this.FRAMEBUFFER||!this._validFramebufferAttachment(n)||i!==this.RENDERBUFFER){this.setError(this.INVALID_ENUM);return}let o=this._activeFramebuffer;if(!o){this.setError(this.INVALID_OPERATION);return}a&&!this._checkWrapper(a,r)||(o._setAttachment(a,n),this._updateFramebufferAttachments(o))},framebufferTexture2D(e,n,r,a,o=0){if(e|=0,n|=0,r|=0,o|=0,!t(a))throw TypeError(`framebufferTexture2D(GLenum, GLenum, GLenum, WebGLTexture, GLint)`);if(e!==this.FRAMEBUFFER||!this._validFramebufferAttachment(n)){this.setError(this.INVALID_ENUM);return}if(o!==0){this.setError(this.INVALID_VALUE);return}if(a&&!this._checkWrapper(a,i))return;if(r===this.TEXTURE_2D){if(a&&a._binding!==this.TEXTURE_2D){this.setError(this.INVALID_OPERATION);return}}else if(this._validCubeTarget(r)){if(a&&a._binding!==this.TEXTURE_CUBE_MAP){this.setError(this.INVALID_OPERATION);return}}else{this.setError(this.INVALID_ENUM);return}let s=this._activeFramebuffer;if(!s){this.setError(this.INVALID_OPERATION);return}s._attachmentLevel[n]=o,s._attachmentFace[n]=r,s._setAttachment(a,n),this._updateFramebufferAttachments(s)},createFramebuffer(){let e=this._gl.createFramebuffer();if(e<=0)return null;let t=new n(e,this);return this._framebuffers[e]=t,t},deleteFramebuffer(e){if(!t(e))throw TypeError(`deleteFramebuffer(WebGLFramebuffer)`);if(!(e instanceof n&&this._checkOwns(e))){this.setError(this.INVALID_OPERATION);return}this._activeFramebuffer===e&&this.bindFramebuffer(this.FRAMEBUFFER,null),e._pendingDelete=!0,e._checkDelete()},createRenderbuffer(){let e=this._gl.createRenderbuffer();if(e<=0)return null;let t=new r(e,this);return this._renderbuffers[e]=t,t},deleteRenderbuffer(e){if(!t(e))throw TypeError(`deleteRenderbuffer(WebGLRenderbuffer)`);if(!(e instanceof r&&this._checkOwns(e))){this.setError(this.INVALID_OPERATION);return}this._activeRenderbuffer===e&&this.bindRenderbuffer(this.RENDERBUFFER,null),this._detachRenderbufferFromAllFramebuffers(e),e._pendingDelete=!0,e._checkDelete()},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)}},getFramebufferAttachmentParameter(e=0,t=0,n=0){if(e!==this.FRAMEBUFFER||!this._validFramebufferAttachment(t))return this.setError(this.INVALID_ENUM),null;let a=this._activeFramebuffer;if(!a)return this.setError(this.INVALID_OPERATION),null;let o=a._attachments[t];if(o===null){if(n===this.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)return this.NONE}else if(o instanceof i)switch(n){case this.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:return o;case this.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:return this.TEXTURE;case this.FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:return a._attachmentLevel[t];case this.FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:{let e=a._attachmentFace[t];return e===this.TEXTURE_2D?0:e}}else if(o instanceof r)switch(n){case this.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:return o;case this.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:return this.RENDERBUFFER}return this.setError(this.INVALID_ENUM),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:return this._maxRenderbufferSize;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},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},_preCheckFramebufferStatus(e){let t=e._attachments,n=[],a=[],o=t[this.DEPTH_ATTACHMENT],s=t[this.DEPTH_STENCIL_ATTACHMENT],c=t[this.STENCIL_ATTACHMENT];if(s&&(c||o)||c&&o)return this.FRAMEBUFFER_UNSUPPORTED;let l=this._getColorAttachments(),u=0;for(let e in t)t[e]&&l.indexOf(Number(e))!==-1&&u++;if(u===0)return this.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;if(s instanceof i)return this.FRAMEBUFFER_UNSUPPORTED;if(s instanceof r){if(s._format!==this.DEPTH_STENCIL)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;n.push(s._width),a.push(s._height)}if(o instanceof i)return this.FRAMEBUFFER_UNSUPPORTED;if(o instanceof r){if(o._format!==this.DEPTH_COMPONENT16)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;n.push(o._width),a.push(o._height)}if(c instanceof i)return this.FRAMEBUFFER_UNSUPPORTED;if(c instanceof r){if(c._format!==this.STENCIL_INDEX8)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;n.push(c._width),a.push(c._height)}let d=!1;for(let o=0;o<l.length;++o){let s=t[l[o]];if(s instanceof i){if(s._format!==this.RGBA||!(s._type===this.UNSIGNED_BYTE||s._type===this.FLOAT))return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;d=!0;let t=e._attachmentLevel[this.COLOR_ATTACHMENT0];if(t===null)throw TypeError(`level is null!`);n.push(s._levelWidth[t]),a.push(s._levelHeight[t])}else if(s instanceof r){let e=s._format;if(e!==this.RGBA4&&e!==this.RGB565&&e!==this.RGB5_A1)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;d=!0,n.push(s._width),a.push(s._height)}}if(!d&&!c&&!o&&!s)return this.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;if(n.length<=0||a.length<=0)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;for(let e=1;e<n.length;++e)if(n[e-1]!==n[e]||a[e-1]!==a[e])return this.FRAMEBUFFER_INCOMPLETE_DIMENSIONS;return n[0]===0||a[0]===0?this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:(e._width=n[0],e._height=a[0],this.FRAMEBUFFER_COMPLETE)},_framebufferOk(){let e=this._activeFramebuffer;return e&&this._preCheckFramebufferStatus(e)!==this.FRAMEBUFFER_COMPLETE?(this.setError(this.INVALID_FRAMEBUFFER_OPERATION),!1):!0},_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},_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 a=n[t],o=e._attachments[a];o instanceof i?this._gl.framebufferTexture2D(this.FRAMEBUFFER,a,e._attachmentFace[a]||0,o._|0,e._attachmentLevel[a]||0):o instanceof r&&this._gl.framebufferRenderbuffer(this.FRAMEBUFFER,a,this.RENDERBUFFER,o._|0)}},_tryDetachFramebuffer(e,t){if(e&&e._linked(t)){let n=this._getAttachments();for(let r=0;r<n.length;++r)e._attachments[n[r]]===t&&this.framebufferTexture2D(this.FRAMEBUFFER,n[r]|0,this.TEXTURE_2D,null)}},_detachRenderbufferFromAllFramebuffers(e){let t=this._activeFramebuffer,n=this._getAttachments(),r=!1;for(let i in this._framebuffers){let a=this._framebuffers[i];if(!(!a||!a._linked(e))){a!==t&&(this._gl.bindFramebuffer(this.FRAMEBUFFER,a._|0),r=!0);for(let t=0;t<n.length;++t){let r=n[t];a._attachments[r]===e&&(this._gl.framebufferRenderbuffer(this.FRAMEBUFFER,r,this.RENDERBUFFER,0),a._setAttachment(null,r))}}}r&&this._gl.bindFramebuffer(this.FRAMEBUFFER,t?t._|0:this._gtkFboId)},_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},_resizeDrawingBuffer(t,n){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,t,n,0,l,this.UNSIGNED_BYTE,e(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,t,n),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)},_allocateDrawingBuffer(e,t){this._drawingBuffer=new a(this._gl.createFramebuffer(),this._gl.createTexture(),this._gl.createRenderbuffer()),this._resizeDrawingBuffer(e,t)},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`)}};function installFramebufferMethods(e){Object.assign(e,o)}export{installFramebufferMethods};
|
|
@@ -1 +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
|
+
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),this._detachTextureFromAllFramebuffers(e),e._pendingDelete=!0,e._checkDelete()},_detachTextureFromAllFramebuffers(e){let t=this._activeFramebuffer,n=this._getAttachments(),r=!1;for(let i in this._framebuffers){let a=this._framebuffers[i];if(!(!a||!a._linked(e))){a!==t&&(this._gl.bindFramebuffer(this.FRAMEBUFFER,a._|0),r=!0);for(let t=0;t<n.length;++t){let r=n[t];a._attachments[r]===e&&(this._gl.framebufferTexture2D(this.FRAMEBUFFER,r,a._attachmentFace[r]||this.TEXTURE_2D,0,a._attachmentLevel[r]||0),a._setAttachment(null,r))}}}r&&this._gl.bindFramebuffer(this.FRAMEBUFFER,t?t._|0:this._gtkFboId)},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};
|
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{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,
|
|
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";const J=globalThis;J.WebGLRenderingContext=z,J.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
|
-
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
|
+
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._maxRenderbufferSize=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._maxRenderbufferSize=this.getParameter(this.MAX_RENDERBUFFER_SIZE),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};
|
|
@@ -19,6 +19,7 @@ export interface FramebufferMethods {
|
|
|
19
19
|
_validFramebufferAttachment(attachment: GLenum): boolean;
|
|
20
20
|
_updateFramebufferAttachments(framebuffer: WebGLFramebuffer | null): void;
|
|
21
21
|
_tryDetachFramebuffer(framebuffer: WebGLFramebuffer | null, renderbuffer: WebGLRenderbuffer): void;
|
|
22
|
+
_detachRenderbufferFromAllFramebuffers(renderbuffer: WebGLRenderbuffer): void;
|
|
22
23
|
_getAttachments(): number[];
|
|
23
24
|
_getColorAttachments(): number[];
|
|
24
25
|
_resizeDrawingBuffer(width: number, height: number): void;
|
|
@@ -7,6 +7,7 @@ export interface TextureManagementMethods {
|
|
|
7
7
|
bindTexture(target: GLenum | undefined, texture: WebGLTexture | null): void;
|
|
8
8
|
createTexture(): WebGLTexture | null;
|
|
9
9
|
deleteTexture(texture: WebGLTexture | null): void;
|
|
10
|
+
_detachTextureFromAllFramebuffers(texture: WebGLTexture): void;
|
|
10
11
|
pixelStorei(pname?: GLenum, param?: GLint | GLboolean): void;
|
|
11
12
|
texImage2D(target: GLenum, level: GLint, internalFormat: GLint, width: GLsizei, height: GLsizei, border: GLint, format: GLenum, type: GLenum, pixels: ArrayBufferView | null): void;
|
|
12
13
|
texImage2D(target: GLenum, level: GLint, internalFormat: GLint, format: GLenum, type: GLenum, source: TexImageSource | GdkPixbuf.Pixbuf): void;
|
|
@@ -24,9 +24,11 @@ export interface WebGLContextBase extends WebGLConstants {
|
|
|
24
24
|
export declare abstract class WebGLContextBase {
|
|
25
25
|
canvas: HTMLCanvasElement;
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
27
|
+
* Static `PredefinedColorSpace` placeholder — honouring `'display-p3'`
|
|
28
|
+
* end-to-end requires per-context surface-format selection through Cairo/GTK
|
|
29
|
+
* GL output (no consumer requests it today). Tracked in STATUS.md
|
|
30
|
+
* "Open TODOs" under WebGL Workstream D: drawingBufferColorSpace
|
|
31
|
+
* colorimetry plumbing.
|
|
30
32
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawingBufferColorSpace
|
|
31
33
|
*/
|
|
32
34
|
drawingBufferColorSpace: PredefinedColorSpace;
|
|
@@ -67,6 +69,7 @@ export declare abstract class WebGLContextBase {
|
|
|
67
69
|
_maxTextureLevel: number;
|
|
68
70
|
_maxCubeMapSize: number;
|
|
69
71
|
_maxCubeMapLevel: number;
|
|
72
|
+
_maxRenderbufferSize: number;
|
|
70
73
|
_unpackAlignment: number;
|
|
71
74
|
_packAlignment: number;
|
|
72
75
|
_unpackFlipY: boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/webgl",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.24",
|
|
4
4
|
"description": "WebGL module for Gjs",
|
|
5
5
|
"module": "lib/esm/index.js",
|
|
6
6
|
"types": "lib/types/index.d.ts",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"WebGL"
|
|
40
40
|
],
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@gjsify/cli": "^0.4.
|
|
43
|
-
"@gjsify/unit": "^0.4.
|
|
42
|
+
"@gjsify/cli": "^0.4.24",
|
|
43
|
+
"@gjsify/unit": "^0.4.24",
|
|
44
44
|
"@types/bit-twiddle": "^1.0.3",
|
|
45
45
|
"@types/node": "^25.9.1",
|
|
46
46
|
"typescript": "^6.0.3"
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
"@girs/gjs": "4.0.1",
|
|
50
50
|
"@girs/gtk-4.0": "4.23.0-4.0.1",
|
|
51
51
|
"@girs/gwebgl-0.1": "0.1.0-4.0.0-rc.5",
|
|
52
|
-
"@gjsify/dom-elements": "^0.4.
|
|
53
|
-
"@gjsify/dom-events": "^0.4.
|
|
54
|
-
"@gjsify/event-bridge": "^0.4.
|
|
55
|
-
"@gjsify/utils": "^0.4.
|
|
52
|
+
"@gjsify/dom-elements": "^0.4.24",
|
|
53
|
+
"@gjsify/dom-events": "^0.4.24",
|
|
54
|
+
"@gjsify/event-bridge": "^0.4.24",
|
|
55
|
+
"@gjsify/utils": "^0.4.24",
|
|
56
56
|
"bit-twiddle": "^1.0.2",
|
|
57
57
|
"glsl-tokenizer": "^2.1.5"
|
|
58
58
|
}
|