@gjsify/webgl 0.33.0 → 0.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -3
- package/lib/esm/context/shader-program/shader-lifecycle.js +6 -6
- package/lib/esm/extensions/webgl-debug-renderer-info.js +1 -0
- package/lib/esm/html-canvas-element.js +1 -1
- package/lib/esm/html-canvas-element.spec.js +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/esm/software-renderer.js +1 -0
- package/lib/esm/software-renderer.spec.js +1 -0
- package/lib/esm/test.js +1 -1
- package/lib/esm/webgl-bridge.js +1 -1
- package/lib/esm/webgl-context-base.js +1 -1
- package/lib/esm/webgl1.spec.js +1 -1
- package/lib/esm/webgl2-rendering-context.js +1 -1
- package/lib/esm/webgl2.spec.js +15 -1
- package/lib/types/extensions/webgl-debug-renderer-info.d.ts +22 -0
- package/lib/types/html-canvas-element.d.ts +17 -0
- package/lib/types/index.d.ts +2 -0
- package/lib/types/software-renderer.d.ts +16 -0
- package/lib/types/webgl-bridge.d.ts +217 -0
- package/lib/types/webgl-context-base.d.ts +47 -0
- package/lib/types/webgl2-rendering-context.d.ts +14 -0
- package/package.json +14 -14
package/README.md
CHANGED
|
@@ -132,10 +132,10 @@ consumer installs only the artifact that fits its platform.
|
|
|
132
132
|
| `linux-x64` | ✅ `libgwebgl.so` + `Gwebgl-0.1.typelib` | native runner |
|
|
133
133
|
| `linux-arm64` | ✅ | native runner |
|
|
134
134
|
| `linux-ppc64`, `linux-s390x`, `linux-riscv64` | ✅ | QEMU emulation |
|
|
135
|
-
| `darwin-arm64` / `darwin-x64` | ✅ `libgwebgl.dylib` + `Gwebgl-0.1.typelib` | native runner — **
|
|
135
|
+
| `darwin-arm64` / `darwin-x64` | ✅ `libgwebgl.dylib` + `Gwebgl-0.1.typelib` | native runner — **WebGL2 via a shader-dialect rewrite, see below** |
|
|
136
136
|
| Windows | ❌ | — no Vala/GI bridge in this repo targets Windows |
|
|
137
137
|
|
|
138
|
-
**macOS renders
|
|
138
|
+
**macOS renders, WebGL1 and WebGL2.** Measured on macOS 15.7.8 / x86_64 with gtk 4.22 and
|
|
139
139
|
libepoxy 1.5.10: `Gtk.GLArea` realizes a `GdkMacosGLContext`, and this bridge draws real
|
|
140
140
|
pixels through it. That describes the GL stack once GTK is loaded — reaching it needed
|
|
141
141
|
`DYLD_LIBRARY_PATH=/usr/local/lib` exported by hand, because the `Gtk-4.0` typelib names a
|
|
@@ -150,7 +150,22 @@ platform, not from the bridge:
|
|
|
150
150
|
GL 4.1 on macOS.
|
|
151
151
|
- Desktop GL 4.1 has **no GLSL ES 3.00 compiler** (that needs `ARB_ES3_compatibility`, GL 4.3),
|
|
152
152
|
so `#version 300 es` shaders — i.e. all WebGL2 content, including three.js ≥ r163 and
|
|
153
|
-
Excalibur 0.32 — do not compile. `#version 100` (WebGL1) does, via
|
|
153
|
+
Excalibur 0.32 — do not compile as written. `#version 100` (WebGL1) does, via
|
|
154
|
+
`ARB_ES2_compatibility`, which is core from 4.1; that one-version gap between the two
|
|
155
|
+
extensions is the entire reason WebGL1 worked here first.
|
|
156
|
+
|
|
157
|
+
**`shaderSource()` now closes it by rewriting the dialect**, and only where it must: on a
|
|
158
|
+
desktop context that lacks `ARB_ES3_compatibility`, `#version 300 es` becomes
|
|
159
|
+
`#version <the context's GLSL> core` (4.10 on macOS). Nothing else in the source changes,
|
|
160
|
+
which is a measured claim rather than a hopeful one — a three.js-shaped GLES 3.00 pair
|
|
161
|
+
(`layout(location=)` on attributes and fragment outputs, a `layout(std140)` block,
|
|
162
|
+
`texture()`, `isampler2D` + `texelFetch`, `textureLod`, MRT, precision statements) and
|
|
163
|
+
eleven separately probed edge constructs all compile on GLSL 4.10 with just that
|
|
164
|
+
substitution. Measured end to end on macOS 15.7.9 / GL 4.1 core: compiles, links, draws,
|
|
165
|
+
and `readPixels` returns the shader's colour. `#version 100` is left byte-for-byte alone,
|
|
166
|
+
and a context that already speaks GLSL ES 3.00 — Mesa's `4.6 (Compatibility Profile)` on
|
|
167
|
+
win32, GLES anywhere — is not rewritten at all.
|
|
168
|
+
|
|
154
169
|
Of the 219 GL entry points the library references, exactly two are absent from Apple's
|
|
155
170
|
`OpenGL.framework` (`glInvalidateFramebuffer`, `glInvalidateSubFramebuffer`, both GL 4.3);
|
|
156
171
|
they are gated on `epoxy_gl_version() >= 43` because libepoxy aborts rather than returning
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import"../../_virtual/_rolldown/runtime.js";import{checkObject as e,isValidString as t}from"../../utils.js";import{WebGLShader as n}from"../../webgl-shader.js";import{WebGLShaderPrecisionFormat as r}from"../../webgl-shader-precision-format.js";import i from"glsl-tokenizer/string";const a={createShader(e=0){if(e!==this.FRAGMENT_SHADER&&e!==this.VERTEX_SHADER)return this.setError(this.INVALID_ENUM),null;let t=this._gl.createShader(e);if(t<0)return null;let r=new n(t,this,e);return this._shaders[t]=r,r},deleteShader(e){this._deleteLinkable(`deleteShader`,e,n)},compileShader(t){if(!e(t))throw TypeError(`compileShader(WebGLShader)`);if(this._checkWrapper(t,n)&&this._checkShaderSource(t)){let e=this.getError();this._gl.compileShader(t._|0),t._needsRecompile=!1;let n=this.getError();t._compileStatus=!!this._gl.getShaderParameter(t._|0,this.COMPILE_STATUS),t._compileInfo=this._gl.getShaderInfoLog(t._|0)||`null`,this.getError(),this.setError(e||n)}},shaderSource(r,i){if(!e(r))throw TypeError(`shaderSource(WebGLShader, String)`);if(!r||!i&&typeof i!=`string`){this.setError(this.INVALID_VALUE);return}t(i)?this._checkWrapper(r,n)&&(i=this._wrapShader(r._type,i),this._gl.shaderSource(r._|0,i),r._source=i,r._needsRecompile=!0):this.setError(this.INVALID_VALUE)},getShaderInfoLog(t){if(!e(t))throw TypeError(`getShaderInfoLog(WebGLShader)`);return this._checkWrapper(t,n)?t._compileInfo:null},getShaderParameter(t,r=0){if(!e(t))throw TypeError(`getShaderParameter(WebGLShader, GLenum)`);if(this._checkWrapper(t,n)){switch(r){case this.DELETE_STATUS:return t._pendingDelete;case this.COMPILE_STATUS:return t._compileStatus;case this.SHADER_TYPE:return t._type}this.setError(this.INVALID_ENUM)}return null},getShaderPrecisionFormat(e=0,t=0){if(!(e===this.FRAGMENT_SHADER||e===this.VERTEX_SHADER)||!(t===this.LOW_FLOAT||t===this.MEDIUM_FLOAT||t===this.HIGH_FLOAT||t===this.LOW_INT||t===this.MEDIUM_INT||t===this.HIGH_INT))return this.setError(this.INVALID_ENUM),null;let n=this._gl.getShaderPrecisionFormat(e,t);return n?new r(n):null},getShaderSource(t){if(!e(t))throw TypeError(`Input to getShaderSource must be an object`);return this._checkWrapper(t,n)?t._source:null},_checkShaderSource(e){let t=e._source,n=i(t),r=!1,a=[];for(let e=0;e<n.length;++e){let t=n[e];if(t)switch(t.type){case`ident`:this._validGLSLIdentifier(t.data)||(r=!0,a.push(t.line+`:`+t.column+` invalid identifier - `+t.data));break;case`preprocessor`:{let e=t.data.match(/^\s*#\s*(.*)$/);if(!e||e?.length<2)break;let n=i(e[1]);for(let e=0;e<n.length;++e){let i=n[e];(i.type===`ident`||i.type===void 0)&&(this._validGLSLIdentifier(i.data)||(r=!0,a.push(t.line+`:`+i.column+` invalid identifier - `+i.data)))}break}case`keyword`:switch(t.data){case`do`:r=!0,a.push(t.line+`:`+t.column+` do not supported`);break}break;case`builtin`:switch(t.data){case`dFdx`:case`dFdy`:case`fwidth`:!this._extensions.oes_standard_derivatives&&this._getGlslVersion(!0)===`100`&&(r=!0,a.push(t.line+`:`+t.column+` `+t.data+` not supported`));break}}}return r&&(e._compileInfo=a.join(`
|
|
1
|
+
import"../../_virtual/_rolldown/runtime.js";import{checkObject as e,isValidString as t}from"../../utils.js";import{WebGLShader as n}from"../../webgl-shader.js";import{WebGLShaderPrecisionFormat as r}from"../../webgl-shader-precision-format.js";import i from"glsl-tokenizer/string";const a=/\b(attribute|varying|gl_FragColor|gl_FragData|texture2D|texture2DProj|textureCube)\b/,o=new RegExp([String.raw`^\s*(?:flat\s+|smooth\s+|centroid\s+)*(?:in|out)\s+\w+\s+\w+\s*;`,String.raw`\blayout\s*\(`,String.raw`\b(?:texture|textureProj|textureLod|textureProjLod|textureGrad|textureProjGrad|texelFetch|texelFetchOffset|textureSize|textureOffset)\s*\(`,String.raw`\b(?:isampler|usampler)(?:2D|3D|Cube|2DArray)\b`,String.raw`\b(?:uint|uvec[234])\b`,String.raw`\b(?:gl_VertexID|gl_InstanceID|gl_FragDepth)\b`].join(`|`),`m`);function glslDialectOf(e){return a.test(e)?`glsl1`:o.test(e)?`modern`:`glsl1`}const s={createShader(e=0){if(e!==this.FRAGMENT_SHADER&&e!==this.VERTEX_SHADER)return this.setError(this.INVALID_ENUM),null;let t=this._gl.createShader(e);if(t<0)return null;let r=new n(t,this,e);return this._shaders[t]=r,r},deleteShader(e){this._deleteLinkable(`deleteShader`,e,n)},compileShader(t){if(!e(t))throw TypeError(`compileShader(WebGLShader)`);if(this._checkWrapper(t,n)&&this._checkShaderSource(t)){let e=this.getError();this._gl.compileShader(t._|0),t._needsRecompile=!1;let n=this.getError();t._compileStatus=!!this._gl.getShaderParameter(t._|0,this.COMPILE_STATUS),t._compileInfo=this._gl.getShaderInfoLog(t._|0)||`null`,this.getError(),this.setError(e||n)}},shaderSource(r,i){if(!e(r))throw TypeError(`shaderSource(WebGLShader, String)`);if(!r||!i&&typeof i!=`string`){this.setError(this.INVALID_VALUE);return}t(i)?this._checkWrapper(r,n)&&(i=this._wrapShader(r._type,i),this._gl.shaderSource(r._|0,i),r._source=i,r._needsRecompile=!0):this.setError(this.INVALID_VALUE)},getShaderInfoLog(t){if(!e(t))throw TypeError(`getShaderInfoLog(WebGLShader)`);return this._checkWrapper(t,n)?t._compileInfo:null},getShaderParameter(t,r=0){if(!e(t))throw TypeError(`getShaderParameter(WebGLShader, GLenum)`);if(this._checkWrapper(t,n)){switch(r){case this.DELETE_STATUS:return t._pendingDelete;case this.COMPILE_STATUS:return t._compileStatus;case this.SHADER_TYPE:return t._type}this.setError(this.INVALID_ENUM)}return null},getShaderPrecisionFormat(e=0,t=0){if(!(e===this.FRAGMENT_SHADER||e===this.VERTEX_SHADER)||!(t===this.LOW_FLOAT||t===this.MEDIUM_FLOAT||t===this.HIGH_FLOAT||t===this.LOW_INT||t===this.MEDIUM_INT||t===this.HIGH_INT))return this.setError(this.INVALID_ENUM),null;let n=this._gl.getShaderPrecisionFormat(e,t);return n?new r(n):null},getShaderSource(t){if(!e(t))throw TypeError(`Input to getShaderSource must be an object`);return this._checkWrapper(t,n)?t._source:null},_checkShaderSource(e){let t=e._source,n=i(t),r=!1,a=[];for(let e=0;e<n.length;++e){let t=n[e];if(t)switch(t.type){case`ident`:this._validGLSLIdentifier(t.data)||(r=!0,a.push(t.line+`:`+t.column+` invalid identifier - `+t.data));break;case`preprocessor`:{let e=t.data.match(/^\s*#\s*(.*)$/);if(!e||e?.length<2)break;let n=i(e[1]);for(let e=0;e<n.length;++e){let i=n[e];(i.type===`ident`||i.type===void 0)&&(this._validGLSLIdentifier(i.data)||(r=!0,a.push(t.line+`:`+i.column+` invalid identifier - `+i.data)))}break}case`keyword`:switch(t.data){case`do`:r=!0,a.push(t.line+`:`+t.column+` do not supported`);break}break;case`builtin`:switch(t.data){case`dFdx`:case`dFdy`:case`fwidth`:!this._extensions.oes_standard_derivatives&&this._getGlslVersion(!0)===`100`&&(r=!0,a.push(t.line+`:`+t.column+` `+t.data+` not supported`));break}}}return r&&(e._compileInfo=a.join(`
|
|
2
2
|
`)),!r},_wrapShader(e,t){let n=t.startsWith(`#version`)||t.includes(`
|
|
3
|
-
#version`),r=``;if(!this._extensions.oes_standard_derivatives&&/#ifdef\s+GL_OES_standard_derivatives/.test(t)&&(
|
|
4
|
-
`),!this._extensions.webgl_draw_buffers
|
|
5
|
-
`),n){if(
|
|
3
|
+
#version`),r=n?null:glslDialectOf(t),i=``;if(!this._extensions.oes_standard_derivatives&&/#ifdef\s+GL_OES_standard_derivatives/.test(t)&&(i+=`#undef GL_OES_standard_derivatives
|
|
4
|
+
`),!this._extensions.webgl_draw_buffers&&r===`glsl1`&&(i+=`#define gl_MaxDrawBuffers 1
|
|
5
|
+
`),n){if(i){let e=t.indexOf(`
|
|
6
6
|
`);t=e===-1?t+`
|
|
7
|
-
`+
|
|
8
|
-
`+
|
|
7
|
+
`+i:t.slice(0,e+1)+i+t.slice(e+1)}}else if(this.canvas){let e=this.canvas.getGlArea().get_use_es(),n=r===`glsl1`?this._getGlsl1Version(e):this._getGlslVersion(e);n?t=`#version `+n+`
|
|
8
|
+
`+i+t:i&&(t=i+t)}else i&&(t=i+t);return t}};function installShaderLifecycleMethods(e){Object.assign(e,s)}export{installShaderLifecycleMethods};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"../_virtual/_rolldown/runtime.js";var WEBGLDebugRendererInfo=class{constructor(){this.UNMASKED_VENDOR_WEBGL=37445,this.UNMASKED_RENDERER_WEBGL=37446}};function getWEBGLDebugRendererInfo(e){return new WEBGLDebugRendererInfo}export{WEBGLDebugRendererInfo,getWEBGLDebugRendererInfo};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{WebGLRenderingContext as e}from"./webgl-rendering-context.js";import{WebGL2RenderingContext as t}from"./webgl2-rendering-context.js";import{HTMLCanvasElement as n}from"@gjsify/dom-elements";var HTMLCanvasElement=class extends n{constructor(e){super(),this.gtkGlArea=e}get width(){return this.gtkGlArea.get_allocated_width()*this.scaleFactor}set width(e){}get height(){return this.gtkGlArea.get_allocated_height()*this.scaleFactor}set height(e){}get scaleFactor(){return this.gtkGlArea.get_scale_factor()||1}get clientWidth(){return this.gtkGlArea.get_allocated_width()}get clientHeight(){return this.gtkGlArea.get_allocated_height()}get offsetWidth(){return this.clientWidth}get offsetHeight(){return this.clientHeight}getGlArea(){return this.gtkGlArea}getContext(n,r){return n===`webgl`||n===`experimental-webgl`?(this._webgl||=(this.gtkGlArea.make_current(),new e(this,r)),this._webgl):n===`webgl2`?(this._webgl2||=(this.gtkGlArea.make_current(),new t(this,r)),this._webgl2):super.getContext(n,r)}};export{HTMLCanvasElement};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{WebGLRenderingContext as e}from"./webgl-rendering-context.js";import{WebGL2RenderingContext as t}from"./webgl2-rendering-context.js";import{HTMLCanvasElement as n}from"@gjsify/dom-elements";var HTMLCanvasElement=class extends n{constructor(e){super(),this.gtkGlArea=e}get width(){return this.gtkGlArea.get_allocated_width()*this.scaleFactor}set width(e){}get height(){return this.gtkGlArea.get_allocated_height()*this.scaleFactor}set height(e){}get scaleFactor(){return this.gtkGlArea.get_scale_factor()||1}get clientWidth(){return this.gtkGlArea.get_allocated_width()}get clientHeight(){return this.gtkGlArea.get_allocated_height()}get offsetWidth(){return this.clientWidth}get offsetHeight(){return this.clientHeight}getGlArea(){return this.gtkGlArea}_createCloneTarget(){let e=new n;return e.width=this.width,e.height=this.height,e}getContext(n,r){return n===`webgl`||n===`experimental-webgl`?(this._webgl||=(this.gtkGlArea.make_current(),new e(this,r)),this._webgl):n===`webgl2`?(this._webgl2||=(this.gtkGlArea.make_current(),new t(this,r)),this._webgl2):super.getContext(n,r)}};export{HTMLCanvasElement};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__name as e}from"./_virtual/_rolldown/runtime.js";import{HTMLCanvasElement as t}from"./html-canvas-element.js";import{describe as n,expect as r,it as i}from"@gjsify/unit";function stubGlArea(e,t,n){return{get_allocated_width:()=>e,get_allocated_height:()=>t,get_scale_factor:()=>n}}var a=e(async()=>{await n(`HTMLCanvasElement (GLArea) — drawing buffer vs CSS size`,async()=>{await i(`reports the drawing buffer in DEVICE pixels on a HiDPI surface`,async()=>{let e=new t(stubGlArea(360,655,3));r(e.width).toBe(1080),r(e.height).toBe(1965)}),await i(`keeps the CSS layout size LOGICAL on the same surface`,async()=>{let e=new t(stubGlArea(360,655,3));r(e.clientWidth).toBe(360),r(e.clientHeight).toBe(655),r(e.offsetWidth).toBe(360),r(e.offsetHeight).toBe(655)}),await i(`CSS size × devicePixelRatio equals the drawing buffer`,async()=>{let e=new t(stubGlArea(800,600,2));r(e.clientWidth*e.scaleFactor).toBe(e.width),r(e.clientHeight*e.scaleFactor).toBe(e.height)}),await i(`is a no-op change at scale-factor 1 (every pre-HiDPI host)`,async()=>{let e=new t(stubGlArea(1024,768,1));r(e.width).toBe(1024),r(e.height).toBe(768),r(e.clientWidth).toBe(1024),r(e.clientHeight).toBe(768)}),await i(`treats an unrealized widget (scale 0) as scale 1, not as a 0×0 buffer`,async()=>{let e=new t(stubGlArea(640,480,0));r(e.scaleFactor).toBe(1),r(e.width).toBe(640),r(e.height).toBe(480)}),await i(`ignores width/height writes — GTK owns the allocation`,async()=>{let e=new t(stubGlArea(360,655,3));e.width=42,e.height=42,r(e.width).toBe(1080),r(e.height).toBe(1965)})})},`default`);export{a as default};
|
|
1
|
+
import{__name as e}from"./_virtual/_rolldown/runtime.js";import{HTMLCanvasElement as t}from"./html-canvas-element.js";import{describe as n,expect as r,it as i}from"@gjsify/unit";function stubGlArea(e,t,n){return{get_allocated_width:()=>e,get_allocated_height:()=>t,get_scale_factor:()=>n}}var a=e(async()=>{await n(`HTMLCanvasElement (GLArea) — cloneNode`,async()=>{await i(`clones to a plain canvas instead of throwing`,async()=>{let e=new t(stubGlArea(640,480,1)).cloneNode(!1);r(e.width).toBe(640),r(e.height).toBe(480)}),await i(`gives the clone a writable size — no widget owns it`,async()=>{let e=new t(stubGlArea(640,480,1)).cloneNode(!1);e.width=800,e.height=600,r(e.width).toBe(800),r(e.height).toBe(600)}),await i(`leaves the original bound to its widget`,async()=>{let e=new t(stubGlArea(640,480,2));e.cloneNode(!1),r(e.width).toBe(1280)})}),await n(`HTMLCanvasElement (GLArea) — drawing buffer vs CSS size`,async()=>{await i(`reports the drawing buffer in DEVICE pixels on a HiDPI surface`,async()=>{let e=new t(stubGlArea(360,655,3));r(e.width).toBe(1080),r(e.height).toBe(1965)}),await i(`keeps the CSS layout size LOGICAL on the same surface`,async()=>{let e=new t(stubGlArea(360,655,3));r(e.clientWidth).toBe(360),r(e.clientHeight).toBe(655),r(e.offsetWidth).toBe(360),r(e.offsetHeight).toBe(655)}),await i(`CSS size × devicePixelRatio equals the drawing buffer`,async()=>{let e=new t(stubGlArea(800,600,2));r(e.clientWidth*e.scaleFactor).toBe(e.width),r(e.clientHeight*e.scaleFactor).toBe(e.height)}),await i(`is a no-op change at scale-factor 1 (every pre-HiDPI host)`,async()=>{let e=new t(stubGlArea(1024,768,1));r(e.width).toBe(1024),r(e.height).toBe(768),r(e.clientWidth).toBe(1024),r(e.clientHeight).toBe(768)}),await i(`treats an unrealized widget (scale 0) as scale 1, not as a 0×0 buffer`,async()=>{let e=new t(stubGlArea(640,480,0));r(e.scaleFactor).toBe(1),r(e.width).toBe(640),r(e.height).toBe(480)}),await i(`ignores width/height writes — GTK owns the allocation`,async()=>{let e=new t(stubGlArea(360,655,3));e.width=42,e.height=42,r(e.width).toBe(1080),r(e.height).toBe(1965)})})},`default`);export{a as default};
|
package/lib/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{WebGLBuffer as e}from"./webgl-buffer.js";import{WebGLUniformLocation as t}from"./webgl-uniform-location.js";import{WebGLDrawingBufferWrapper as n}from"./webgl-drawing-buffer-wrapper.js";import{WebGLFramebuffer as r}from"./webgl-framebuffer.js";import{WebGLRenderbuffer as i}from"./webgl-renderbuffer.js";import{WebGLTexture as a}from"./webgl-texture.js";import{WebGLProgram as o}from"./webgl-program.js";import{WebGLShader as s}from"./webgl-shader.js";import{WebGLShaderPrecisionFormat as c}from"./webgl-shader-precision-format.js";import{WebGLActiveInfo as l}from"./webgl-active-info.js";import{EXTBlendMinMax as u,getEXTBlendMinMax as d}from"./extensions/ext-blend-minmax.js";import{EXTColorBufferFloat as f,getEXTColorBufferFloat as p}from"./extensions/ext-color-buffer-float.js";import{EXTColorBufferHalfFloat as m,getEXTColorBufferHalfFloat as h}from"./extensions/ext-color-buffer-half-float.js";import{EXTTextureFilterAnisotropic as g,getEXTTextureFilterAnisotropic as _}from"./extensions/ext-texture-filter-anisotropic.js";import{OESElementIndexUint as v,getOESElementIndexUint as y}from"./extensions/oes-element-index-unit.js";import{OESStandardDerivatives as b,getOESStandardDerivatives as x}from"./extensions/oes-standard-derivatives.js";import{OESTextureFloatLinear as S,getOESTextureFloatLinear as C}from"./extensions/oes-texture-float-linear.js";import{OESTextureFloat as w,getOESTextureFloat as T}from"./extensions/oes-texture-float.js";import{OESTextureHalfFloat as E,getOESTextureHalfFloat as D}from"./extensions/oes-texture-half-float.js";import{STACKGLDestroyContext as O,getSTACKGLDestroyContext as k}from"./extensions/stackgl-destroy-context.js";import{STACKGLResizeDrawingBuffer as A,getSTACKGLResizeDrawingBuffer as j}from"./extensions/stackgl-resize-drawing-buffer.js";import{
|
|
1
|
+
import{WebGLBuffer as e}from"./webgl-buffer.js";import{WebGLUniformLocation as t}from"./webgl-uniform-location.js";import{WebGLDrawingBufferWrapper as n}from"./webgl-drawing-buffer-wrapper.js";import{WebGLFramebuffer as r}from"./webgl-framebuffer.js";import{WebGLRenderbuffer as i}from"./webgl-renderbuffer.js";import{WebGLTexture as a}from"./webgl-texture.js";import{WebGLProgram as o}from"./webgl-program.js";import{WebGLShader as s}from"./webgl-shader.js";import{WebGLShaderPrecisionFormat as c}from"./webgl-shader-precision-format.js";import{WebGLActiveInfo as l}from"./webgl-active-info.js";import{EXTBlendMinMax as u,getEXTBlendMinMax as d}from"./extensions/ext-blend-minmax.js";import{EXTColorBufferFloat as f,getEXTColorBufferFloat as p}from"./extensions/ext-color-buffer-float.js";import{EXTColorBufferHalfFloat as m,getEXTColorBufferHalfFloat as h}from"./extensions/ext-color-buffer-half-float.js";import{EXTTextureFilterAnisotropic as g,getEXTTextureFilterAnisotropic as _}from"./extensions/ext-texture-filter-anisotropic.js";import{OESElementIndexUint as v,getOESElementIndexUint as y}from"./extensions/oes-element-index-unit.js";import{OESStandardDerivatives as b,getOESStandardDerivatives as x}from"./extensions/oes-standard-derivatives.js";import{OESTextureFloatLinear as S,getOESTextureFloatLinear as C}from"./extensions/oes-texture-float-linear.js";import{OESTextureFloat as w,getOESTextureFloat as T}from"./extensions/oes-texture-float.js";import{OESTextureHalfFloat as E,getOESTextureHalfFloat as D}from"./extensions/oes-texture-half-float.js";import{STACKGLDestroyContext as O,getSTACKGLDestroyContext as k}from"./extensions/stackgl-destroy-context.js";import{STACKGLResizeDrawingBuffer as A,getSTACKGLResizeDrawingBuffer as j}from"./extensions/stackgl-resize-drawing-buffer.js";import{WEBGLDebugRendererInfo as M,getWEBGLDebugRendererInfo as N}from"./extensions/webgl-debug-renderer-info.js";import{WebGLContextAttributes as P}from"./webgl-context-attributes.js";import{WebGLTextureUnit as F}from"./webgl-texture-unit.js";import{WebGLVertexArrayGlobalAttribute as I,WebGLVertexArrayGlobalState as L,WebGLVertexArrayObjectAttribute as R,WebGLVertexArrayObjectState as z}from"./webgl-vertex-attribute.js";import{WebGLContextBase as B}from"./webgl-context-base.js";import{WebGLRenderingContext as V}from"./webgl-rendering-context.js";import{WebGLQuery as H}from"./webgl-query.js";import{WebGLSampler as U}from"./webgl-sampler.js";import{WebGLSync as W}from"./webgl-sync.js";import{WebGLTransformFeedback as G}from"./webgl-transform-feedback.js";import{WebGLVertexArrayObject as K}from"./webgl-vertex-array-object.js";import{WebGL2RenderingContext as q}from"./webgl2-rendering-context.js";import{HTMLCanvasElement as J}from"./html-canvas-element.js";import{isSoftwareRenderer as Y}from"./software-renderer.js";import{WebGLBridge as X}from"./webgl-bridge.js";import"@girs/gtk-4.0";import"@girs/gjs";import"@girs/gio-2.0";export{u as EXTBlendMinMax,f as EXTColorBufferFloat,m as EXTColorBufferHalfFloat,g as EXTTextureFilterAnisotropic,J as HTMLCanvasElement,v as OESElementIndexUint,b as OESStandardDerivatives,w as OESTextureFloat,S as OESTextureFloatLinear,E as OESTextureHalfFloat,O as STACKGLDestroyContext,A as STACKGLResizeDrawingBuffer,M as WEBGLDebugRendererInfo,q as WebGL2RenderingContext,l as WebGLActiveInfo,X as WebGLBridge,e as WebGLBuffer,P as WebGLContextAttributes,B as WebGLContextBase,n as WebGLDrawingBufferWrapper,r as WebGLFramebuffer,o as WebGLProgram,H as WebGLQuery,i as WebGLRenderbuffer,V as WebGLRenderingContext,U as WebGLSampler,s as WebGLShader,c as WebGLShaderPrecisionFormat,W as WebGLSync,a as WebGLTexture,F as WebGLTextureUnit,G as WebGLTransformFeedback,t as WebGLUniformLocation,I as WebGLVertexArrayGlobalAttribute,L as WebGLVertexArrayGlobalState,K as WebGLVertexArrayObject,R as WebGLVertexArrayObjectAttribute,z as WebGLVertexArrayObjectState,d as getEXTBlendMinMax,p as getEXTColorBufferFloat,h as getEXTColorBufferHalfFloat,_ as getEXTTextureFilterAnisotropic,y as getOESElementIndexUint,x as getOESStandardDerivatives,T as getOESTextureFloat,C as getOESTextureFloatLinear,D as getOESTextureHalfFloat,k as getSTACKGLDestroyContext,j as getSTACKGLResizeDrawingBuffer,N as getWEBGLDebugRendererInfo,Y as isSoftwareRenderer};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";const e=[`apple software renderer`,`llvmpipe`,`softpipe`,`swrast`,`swiftshader`,`microsoft basic render driver`,`mesa offscreen`];function isSoftwareRenderer(t){if(!t)return!1;let n=t.toLowerCase();return e.some(e=>n.includes(e))}export{isSoftwareRenderer};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{__name as e}from"./_virtual/_rolldown/runtime.js";import{isSoftwareRenderer as t}from"./software-renderer.js";import{describe as n,expect as r,it as i}from"@gjsify/unit";var a=e(async()=>{await n(`isSoftwareRenderer`,async()=>{await i(`recognises the CPU rasterisers we have seen in the wild`,async()=>{r(t(`Apple Software Renderer`)).toBe(!0),r(t(`llvmpipe (LLVM 15.0.7, 256 bits)`)).toBe(!0),r(t(`softpipe`)).toBe(!0),r(t(`Gallium 0.4 on swrast`)).toBe(!0),r(t(`Google SwiftShader`)).toBe(!0),r(t(`Microsoft Basic Render Driver`)).toBe(!0),r(t(`Mesa OffScreen`)).toBe(!0)}),await i(`is case-insensitive`,async()=>{r(t(`APPLE SOFTWARE RENDERER`)).toBe(!0),r(t(`LLVMpipe`)).toBe(!0)}),await i(`leaves hardware renderers alone`,async()=>{r(t(`Apple M1 Pro`)).toBe(!1),r(t(`Mesa Intel(R) UHD Graphics 620 (KBL GT2)`)).toBe(!1),r(t(`NVIDIA GeForce RTX 3080/PCIe/SSE2`)).toBe(!1),r(t(`AMD Radeon RX 6800 XT (radeonsi, navi21)`)).toBe(!1),r(t(`ANGLE`)).toBe(!1)}),await i(`treats an absent string as unknown, not as software`,async()=>{r(t(``)).toBe(!1),r(t(null)).toBe(!1),r(t(void 0)).toBe(!1)})})},`default`);export{a as default};
|
package/lib/esm/test.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import e from"./html-canvas-element.spec.js";import t from"./register.spec.js";import n from"./
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import e from"./html-canvas-element.spec.js";import t from"./register.spec.js";import n from"./software-renderer.spec.js";import r from"./webgl1.spec.js";import i from"./webgl2.spec.js";import{run as a}from"@gjsify/unit";a({testSuite:async()=>{await r(),await i(),await e(),await n()},registerSuite:t});
|
package/lib/esm/webgl-bridge.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{WebGLRenderingContext as e}from"./webgl-rendering-context.js";import{WebGL2RenderingContext as t}from"./webgl2-rendering-context.js";import{HTMLCanvasElement as n}from"./html-canvas-element.js";import{
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{WebGLRenderingContext as e}from"./webgl-rendering-context.js";import{WebGL2RenderingContext as t}from"./webgl2-rendering-context.js";import{HTMLCanvasElement as n}from"./html-canvas-element.js";import{isSoftwareRenderer as r}from"./software-renderer.js";import{notifyElementResize as i}from"@gjsify/dom-elements";import a from"gi://GObject";import o from"gi://Gdk?version=4.0";import s from"gi://GLib?version=2.0";import c from"gi://Gtk?version=4.0";import{attachEventControllers as l}from"@gjsify/event-bridge";import{Event as u}from"@gjsify/dom-events";const d=a.registerClass({GTypeName:`GjsifyWebGLBridge`},class WebGLBridge extends c.GLArea{constructor(e){super(e),this._canvas=null,this._readyCallbacks=[],this._resizeCallbacks=[],this._renderTag=null,this._tickCallbackId=null,this._frameCallback=null,this._lastFrameCallback=null,this._lastFrameTime=0,this._replaying=!1,this._frameCallbackId=0,this._nextFrameId=1,this._timeOrigin=s.get_monotonic_time(),this._rendererInfo=null,this.set_allowed_apis(o.GLAPI.GL|o.GLAPI.GLES),this.set_required_version(3,2),this.set_has_depth_buffer(!0),this.set_has_stencil_buffer(!0),l(this,()=>this._canvas,{captureKeys:!0}),this._tickCallbackId=this.add_tick_callback((e,t)=>(this._frameCallback!==null&&this.queue_render(),s.SOURCE_CONTINUE));let t=this.connect(`render`,()=>{this.disconnect(t),this.make_current(),this._canvas=new n(this);{let e=globalThis;e.document?.body&&e.document.body.appendChild(this._canvas)}this._canvas.getContext(`webgl2`);let e=this._canvas.getContext(`webgl`);if(e){this._reportRenderer(e);for(let t of this._readyCallbacks)t(this._canvas,e);this._readyCallbacks=[]}return this._renderTag=this.connect(`render`,e=>{let t=(s.get_monotonic_time()-this._timeOrigin)/1e3;if(this._frameCallback!==null){globalThis.__GJSIFY_DEBUG_RAF===!0&&console.log(`[rAF] frame callback fires t=${t.toFixed(1)}`);let e=this._frameCallback;this._frameCallback=null,this._frameCallbackId=0,this._lastFrameCallback=e,this._lastFrameTime=t,e(t)}else if(this._lastFrameCallback!==null){this._replaying=!0;try{this._lastFrameCallback(this._lastFrameTime)}finally{this._replaying=!1}}return!0}),!0});this.connect(`resize`,()=>{let e=this.get_allocated_width(),t=this.get_allocated_height();this._canvas&&(this._canvas.dispatchEvent(new u(`resize`)),i(this._canvas,e,t));for(let n of this._resizeCallbacks)n(e,t);this._frameCallback&&this.requestAnimationFrame(this._frameCallback)}),this.connect(`unrealize`,()=>{this._renderTag!==null&&(this.disconnect(this._renderTag),this._renderTag=null),this._tickCallbackId!==null&&(this.remove_tick_callback(this._tickCallbackId),this._tickCallbackId=null),this._frameCallback=null,this._lastFrameCallback=null,this._lastFrameTime=0,this._replaying=!1,this._canvas=null})}get canvas(){return this._canvas}get rendererInfo(){return this._rendererInfo}onReady(e){if(this._canvas){let t=this._canvas.getContext(`webgl`);if(t){e(this._canvas,t);return}}this._readyCallbacks.push(e)}onWebGLReady(e){this.onReady(e)}_reportRenderer(e){let t=e.getExtension(`WEBGL_debug_renderer_info`),n=String(e.getParameter(t.UNMASKED_VENDOR_WEBGL)??``),i=String(e.getParameter(t.UNMASKED_RENDERER_WEBGL)??``);this._rendererInfo={vendor:n,renderer:i},r(i)&&console.warn(`[@gjsify/webgl] GL is rasterised on the CPU by "${i}" (${n}) — this host exposes no usable GPU. Every draw call still works; fill-heavy or continuously animating content will be orders of magnitude slower than on hardware, which can look like a frozen window rather than a slow one. Read it yourself via WebGLBridge.rendererInfo or the WEBGL_debug_renderer_info extension.`)}onResize(e){this._resizeCallbacks.push(e)}requestAnimationFrame(e){let t=this._nextFrameId++;return this._replaying?t:(this._frameCallback=e,this._frameCallbackId=t,this.queue_render(),t)}cancelAnimationFrame(e){e!==0&&e===this._frameCallbackId&&(this._frameCallback=null,this._frameCallbackId=0,this._lastFrameCallback=null,this._lastFrameTime=0)}installGlobals(){let n=globalThis;n.requestAnimationFrame=e=>this.requestAnimationFrame(e),n.cancelAnimationFrame=e=>this.cancelAnimationFrame(e),n.WebGLRenderingContext=e,n.WebGL2RenderingContext=t,Object.defineProperty(globalThis,"devicePixelRatio",{get:()=>this.get_scale_factor()||1,configurable:!0});let r=this._timeOrigin;n.performance={now:()=>(s.get_monotonic_time()-r)/1e3,timeOrigin:Date.now()}}});export{d as WebGLBridge};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{flag as e}from"./utils.js";import{installAllContextMethods as t}from"./context/index.js";import{getEXTBlendMinMax as n}from"./extensions/ext-blend-minmax.js";import{getEXTColorBufferFloat as r}from"./extensions/ext-color-buffer-float.js";import{getEXTColorBufferHalfFloat as i}from"./extensions/ext-color-buffer-half-float.js";import{getEXTTextureFilterAnisotropic as a}from"./extensions/ext-texture-filter-anisotropic.js";import{getOESElementIndexUint as o}from"./extensions/oes-element-index-unit.js";import{getOESStandardDerivatives as s}from"./extensions/oes-standard-derivatives.js";import{getOESTextureFloatLinear as c}from"./extensions/oes-texture-float-linear.js";import{getOESTextureFloat as l}from"./extensions/oes-texture-float.js";import{getOESTextureHalfFloat as u}from"./extensions/oes-texture-half-float.js";import{getSTACKGLDestroyContext as d}from"./extensions/stackgl-destroy-context.js";import{getSTACKGLResizeDrawingBuffer as f}from"./extensions/stackgl-resize-drawing-buffer.js";import{WebGLContextAttributes as p}from"./webgl-context-attributes.js";import{WebGLTextureUnit as m}from"./webgl-texture-unit.js";import{WebGLVertexArrayGlobalState as h,WebGLVertexArrayObjectState as g}from"./webgl-vertex-attribute.js";import*as _ from"bit-twiddle";import v from"@girs/gwebgl-0.1";import"@girs/gdkpixbuf-2.0";import{warnNotImplemented as y}from"@gjsify/utils";let b=0;const x={oes_element_index_uint:o,oes_texture_float:l,oes_texture_float_linear:c,oes_standard_derivatives:s,stackgl_destroy_context:d,stackgl_resize_drawingbuffer:f,ext_blend_minmax:n,ext_color_buffer_float:r,ext_color_buffer_half_float:i,ext_texture_filter_anisotropic:a,oes_texture_half_float:u};var WebGLContextBase=class{get drawingBufferHeight(){return this.canvas.height||0}get drawingBufferWidth(){return this.canvas.width||0}constructor(t,n={}){this.drawingBufferColorSpace=`srgb`,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=t,this._contextAttributes=new p(e(n,`alpha`,!0),e(n,`depth`,!0),e(n,`stencil`,!1),!1,e(n,`premultipliedAlpha`,!0),e(n,`preserveDrawingBuffer`,!1),e(n,`preferLowPowerToHighPerformance`,!1),e(n,`failIfMajorPerformanceCaveat`,!1)),this._contextAttributes.premultipliedAlpha=this._contextAttributes.premultipliedAlpha&&this._contextAttributes.alpha}_init(){let e=this._gl.getParameterx(36006);this._gtkFboId=e?.deepUnpack()|0,this._initGLConstants(),this.DEFAULT_ATTACHMENTS=[this.COLOR_ATTACHMENT0,this.DEPTH_ATTACHMENT,this.STENCIL_ATTACHMENT,this.DEPTH_STENCIL_ATTACHMENT],this.DEFAULT_COLOR_ATTACHMENTS=[this.COLOR_ATTACHMENT0];let t=this.drawingBufferWidth||0,n=this.drawingBufferHeight||0;this._=b++;let r=this.getParameter(this.MAX_COMBINED_TEXTURE_IMAGE_UNITS);this._textureUnits=Array.from({length:r});for(let e=0;e<r;++e)this._textureUnits[e]=new m(this,e);this.activeTexture(this.TEXTURE0),this._defaultVertexObjectState=new g(this),this._vertexObjectState=this._defaultVertexObjectState,this._vertexGlobalState=new h(this),this._maxTextureSize=this.getParameter(this.MAX_TEXTURE_SIZE),this._maxTextureLevel=_.log2(_.nextPow2(this._maxTextureSize)),this._maxCubeMapSize=this.getParameter(this.MAX_CUBE_MAP_TEXTURE_SIZE),this._maxCubeMapLevel=_.log2(_.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 v.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:return this._gl.getParameteri(e);case this.MAX_RENDERBUFFER_SIZE:return this._maxRenderbufferSize;case this.MAX_COMBINED_TEXTURE_IMAGE_UNITS:case this.MAX_CUBE_MAP_TEXTURE_SIZE:case this.MAX_FRAGMENT_UNIFORM_VECTORS: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)}}let t=this._extensions.oes_standard_derivatives;if(t&&e===t.FRAGMENT_SHADER_DERIVATIVE_HINT_OES)return this._getParameterDirect(e);let n=this._extensions.ext_texture_filter_anisotropic;if(n&&e===n.MAX_TEXTURE_MAX_ANISOTROPY_EXT)return this._getParameterDirect(e);let r=this._extensions.oes_vertex_array_object;return r&&e===r.VERTEX_ARRAY_BINDING_OES?r._activeVertexArrayObject:(this.setError(this.INVALID_ENUM),null)}}destroy(){y(`destroy`)}};t(WebGLContextBase.prototype);export{WebGLContextBase};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{flag as e}from"./utils.js";import{installAllContextMethods as t}from"./context/index.js";import{getEXTBlendMinMax as n}from"./extensions/ext-blend-minmax.js";import{getEXTColorBufferFloat as r}from"./extensions/ext-color-buffer-float.js";import{getEXTColorBufferHalfFloat as i}from"./extensions/ext-color-buffer-half-float.js";import{getEXTTextureFilterAnisotropic as a}from"./extensions/ext-texture-filter-anisotropic.js";import{getOESElementIndexUint as o}from"./extensions/oes-element-index-unit.js";import{getOESStandardDerivatives as s}from"./extensions/oes-standard-derivatives.js";import{getOESTextureFloatLinear as c}from"./extensions/oes-texture-float-linear.js";import{getOESTextureFloat as l}from"./extensions/oes-texture-float.js";import{getOESTextureHalfFloat as u}from"./extensions/oes-texture-half-float.js";import{getSTACKGLDestroyContext as d}from"./extensions/stackgl-destroy-context.js";import{getSTACKGLResizeDrawingBuffer as f}from"./extensions/stackgl-resize-drawing-buffer.js";import{getWEBGLDebugRendererInfo as p}from"./extensions/webgl-debug-renderer-info.js";import{WebGLContextAttributes as m}from"./webgl-context-attributes.js";import{WebGLTextureUnit as h}from"./webgl-texture-unit.js";import{WebGLVertexArrayGlobalState as g,WebGLVertexArrayObjectState as _}from"./webgl-vertex-attribute.js";import*as v from"bit-twiddle";import y from"@girs/gwebgl-0.1";import"@girs/gdkpixbuf-2.0";import{warnNotImplemented as b}from"@gjsify/utils";let x=0;const S={oes_element_index_uint:o,oes_texture_float:l,oes_texture_float_linear:c,oes_standard_derivatives:s,stackgl_destroy_context:d,stackgl_resize_drawingbuffer:f,ext_blend_minmax:n,ext_color_buffer_float:r,ext_color_buffer_half_float:i,ext_texture_filter_anisotropic:a,oes_texture_half_float:u,webgl_debug_renderer_info:p};var WebGLContextBase=class{get drawingBufferHeight(){return this.canvas.height||0}get drawingBufferWidth(){return this.canvas.width||0}constructor(t,n={}){this.drawingBufferColorSpace=`srgb`,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=t,this._contextAttributes=new m(e(n,`alpha`,!0),e(n,`depth`,!0),e(n,`stencil`,!1),!1,e(n,`premultipliedAlpha`,!0),e(n,`preserveDrawingBuffer`,!1),e(n,`preferLowPowerToHighPerformance`,!1),e(n,`failIfMajorPerformanceCaveat`,!1)),this._contextAttributes.premultipliedAlpha=this._contextAttributes.premultipliedAlpha&&this._contextAttributes.alpha}_init(){let e=this._gl.getParameterx(36006);this._gtkFboId=e?.deepUnpack()|0,this._initGLConstants(),this.DEFAULT_ATTACHMENTS=[this.COLOR_ATTACHMENT0,this.DEPTH_ATTACHMENT,this.STENCIL_ATTACHMENT,this.DEPTH_STENCIL_ATTACHMENT],this.DEFAULT_COLOR_ATTACHMENTS=[this.COLOR_ATTACHMENT0];let t=this.drawingBufferWidth||0,n=this.drawingBufferHeight||0;this._=x++;let r=this.getParameter(this.MAX_COMBINED_TEXTURE_IMAGE_UNITS);this._textureUnits=Array.from({length:r});for(let e=0;e<r;++e)this._textureUnits[e]=new h(this,e);this.activeTexture(this.TEXTURE0),this._defaultVertexObjectState=new _(this),this._vertexObjectState=this._defaultVertexObjectState,this._vertexGlobalState=new g(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 y.WebGLRenderingContextBase().get_webgl_constants();for(let[t,n]of Object.entries(e))Object.defineProperty(this,t,{value:n})}_getGlslVersion(e){return this._getGlsl1Version(e)}_getGlsl1Version(e){return e||this._atLeastGlVersion(4,1)?`100`:`120`}_desktopGlslVersion(){let e=this._gl.getString(35724);if(!e||e.startsWith(`OpenGL ES `))return`130`;let[t,n]=e.split(`.`,2).map(e=>Number.parseInt(e,10));return!Number.isFinite(t)||!Number.isFinite(n)?`130`:String(t*100+(n>=10?n:n*10))}_atLeastGlVersion(e,t){let n=this._gl.getString(7938);if(!n||n.startsWith(`OpenGL ES `))return!1;let[r,i]=n.split(`.`,2).map(e=>Number.parseInt(e,10));return!Number.isFinite(r)||!Number.isFinite(i)?!1:r>e||r===e&&i>=t}_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=S[t]?S[t](this):null;return n&&(this._extensions[t]=n),n}getSupportedExtensions(){let e=[`ANGLE_instanced_arrays`,`STACKGL_resize_drawingbuffer`,`STACKGL_destroy_context`,`WEBGL_debug_renderer_info`],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 37445:return this._gl.getString(7936);case 37446:return this._gl.getString(7937);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:return this._gl.getParameteri(e);case this.MAX_RENDERBUFFER_SIZE:return this._maxRenderbufferSize;case this.MAX_COMBINED_TEXTURE_IMAGE_UNITS:case this.MAX_CUBE_MAP_TEXTURE_SIZE:case this.MAX_FRAGMENT_UNIFORM_VECTORS: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)}}let t=this._extensions.oes_standard_derivatives;if(t&&e===t.FRAGMENT_SHADER_DERIVATIVE_HINT_OES)return this._getParameterDirect(e);let n=this._extensions.ext_texture_filter_anisotropic;if(n&&e===n.MAX_TEXTURE_MAX_ANISOTROPY_EXT)return this._getParameterDirect(e);let r=this._extensions.oes_vertex_array_object;return r&&e===r.VERTEX_ARRAY_BINDING_OES?r._activeVertexArrayObject:(this.setError(this.INVALID_ENUM),null)}}destroy(){b(`destroy`)}};t(WebGLContextBase.prototype);export{WebGLContextBase};
|
package/lib/esm/webgl1.spec.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__name as e}from"./_virtual/_rolldown/runtime.js";import{destroyTestFBO as t,destroyTestFBOWithDepth as n,drawTriangle as r,makeProgram as i,makeTestFBO as a,makeTestFBOWithDepth as o,pixelClose as s,readPixel as c}from"./test-utils.js";import{beforeEach as l,describe as u,expect as d,it as f,on as p}from"@gjsify/unit";import{WebGLBridge as m}from"@gjsify/webgl";import h from"@girs/glib-2.0";import g from"@girs/gtk-4.0";const _=`ACTIVE_ATTRIBUTES.ACTIVE_TEXTURE.ACTIVE_UNIFORMS.ALIASED_LINE_WIDTH_RANGE.ALIASED_POINT_SIZE_RANGE.ALPHA.ALPHA_BITS.ALWAYS.ARRAY_BUFFER.ARRAY_BUFFER_BINDING.ATTACHED_SHADERS.BACK.BLEND.BLEND_COLOR.BLEND_DST_ALPHA.BLEND_DST_RGB.BLEND_EQUATION.BLEND_EQUATION_ALPHA.BLEND_EQUATION_RGB.BLEND_SRC_ALPHA.BLEND_SRC_RGB.BLUE_BITS.BOOL.BOOL_VEC2.BOOL_VEC3.BOOL_VEC4.BROWSER_DEFAULT_WEBGL.BUFFER_SIZE.BUFFER_USAGE.BYTE.CCW.CLAMP_TO_EDGE.COLOR_ATTACHMENT0.COLOR_BUFFER_BIT.COLOR_CLEAR_VALUE.COLOR_WRITEMASK.COMPILE_STATUS.COMPRESSED_TEXTURE_FORMATS.CONSTANT_ALPHA.CONSTANT_COLOR.CONTEXT_LOST_WEBGL.CULL_FACE.CULL_FACE_MODE.CURRENT_PROGRAM.CURRENT_VERTEX_ATTRIB.CW.DECR.DECR_WRAP.DELETE_STATUS.DEPTH_ATTACHMENT.DEPTH_BITS.DEPTH_BUFFER_BIT.DEPTH_CLEAR_VALUE.DEPTH_COMPONENT.DEPTH_COMPONENT16.DEPTH_FUNC.DEPTH_RANGE.DEPTH_STENCIL.DEPTH_STENCIL_ATTACHMENT.DEPTH_TEST.DEPTH_WRITEMASK.DITHER.DONT_CARE.DST_ALPHA.DST_COLOR.DYNAMIC_DRAW.ELEMENT_ARRAY_BUFFER.ELEMENT_ARRAY_BUFFER_BINDING.EQUAL.FASTEST.FLOAT.FLOAT_MAT2.FLOAT_MAT3.FLOAT_MAT4.FLOAT_VEC2.FLOAT_VEC3.FLOAT_VEC4.FRAGMENT_SHADER.FRAMEBUFFER.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE.FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE.FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL.FRAMEBUFFER_BINDING.FRAMEBUFFER_COMPLETE.FRAMEBUFFER_INCOMPLETE_ATTACHMENT.FRAMEBUFFER_INCOMPLETE_DIMENSIONS.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT.FRAMEBUFFER_UNSUPPORTED.FRONT.FRONT_AND_BACK.FRONT_FACE.FUNC_ADD.FUNC_REVERSE_SUBTRACT.FUNC_SUBTRACT.GENERATE_MIPMAP_HINT.GEQUAL.GREATER.GREEN_BITS.HIGH_FLOAT.HIGH_INT.IMPLEMENTATION_COLOR_READ_FORMAT.IMPLEMENTATION_COLOR_READ_TYPE.INCR.INCR_WRAP.INT.INT_VEC2.INT_VEC3.INT_VEC4.INVALID_ENUM.INVALID_FRAMEBUFFER_OPERATION.INVALID_OPERATION.INVALID_VALUE.INVERT.KEEP.LEQUAL.LESS.LINEAR.LINEAR_MIPMAP_LINEAR.LINEAR_MIPMAP_NEAREST.LINES.LINE_LOOP.LINE_STRIP.LINE_WIDTH.LINK_STATUS.LOW_FLOAT.LOW_INT.LUMINANCE.LUMINANCE_ALPHA.MAX_COMBINED_TEXTURE_IMAGE_UNITS.MAX_CUBE_MAP_TEXTURE_SIZE.MAX_FRAGMENT_UNIFORM_VECTORS.MAX_RENDERBUFFER_SIZE.MAX_TEXTURE_IMAGE_UNITS.MAX_TEXTURE_SIZE.MAX_VARYING_VECTORS.MAX_VERTEX_ATTRIBS.MAX_VERTEX_TEXTURE_IMAGE_UNITS.MAX_VERTEX_UNIFORM_VECTORS.MAX_VIEWPORT_DIMS.MEDIUM_FLOAT.MEDIUM_INT.MIRRORED_REPEAT.NEAREST.NEAREST_MIPMAP_LINEAR.NEAREST_MIPMAP_NEAREST.NEVER.NICEST.NONE.NOTEQUAL.NO_ERROR.ONE.ONE_MINUS_CONSTANT_ALPHA.ONE_MINUS_CONSTANT_COLOR.ONE_MINUS_DST_ALPHA.ONE_MINUS_DST_COLOR.ONE_MINUS_SRC_ALPHA.ONE_MINUS_SRC_COLOR.OUT_OF_MEMORY.PACK_ALIGNMENT.POINTS.POLYGON_OFFSET_FACTOR.POLYGON_OFFSET_FILL.POLYGON_OFFSET_UNITS.RED_BITS.RENDERBUFFER.RENDERBUFFER_ALPHA_SIZE.RENDERBUFFER_BINDING.RENDERBUFFER_BLUE_SIZE.RENDERBUFFER_DEPTH_SIZE.RENDERBUFFER_GREEN_SIZE.RENDERBUFFER_HEIGHT.RENDERBUFFER_INTERNAL_FORMAT.RENDERBUFFER_RED_SIZE.RENDERBUFFER_STENCIL_SIZE.RENDERBUFFER_WIDTH.RENDERER.REPEAT.REPLACE.RGB.RGB565.RGB5_A1.RGBA.RGBA4.SAMPLER_2D.SAMPLER_CUBE.SAMPLES.SAMPLE_ALPHA_TO_COVERAGE.SAMPLE_BUFFERS.SAMPLE_COVERAGE.SAMPLE_COVERAGE_INVERT.SAMPLE_COVERAGE_VALUE.SCISSOR_BOX.SCISSOR_TEST.SHADER_TYPE.SHADING_LANGUAGE_VERSION.SHORT.SRC_ALPHA.SRC_ALPHA_SATURATE.SRC_COLOR.STATIC_DRAW.STENCIL_ATTACHMENT.STENCIL_BACK_FAIL.STENCIL_BACK_FUNC.STENCIL_BACK_PASS_DEPTH_FAIL.STENCIL_BACK_PASS_DEPTH_PASS.STENCIL_BACK_REF.STENCIL_BACK_VALUE_MASK.STENCIL_BACK_WRITEMASK.STENCIL_BITS.STENCIL_BUFFER_BIT.STENCIL_CLEAR_VALUE.STENCIL_FAIL.STENCIL_FUNC.STENCIL_INDEX8.STENCIL_PASS_DEPTH_FAIL.STENCIL_PASS_DEPTH_PASS.STENCIL_REF.STENCIL_TEST.STENCIL_VALUE_MASK.STENCIL_WRITEMASK.STREAM_DRAW.SUBPIXEL_BITS.TEXTURE.TEXTURE0.TEXTURE1.TEXTURE10.TEXTURE11.TEXTURE12.TEXTURE13.TEXTURE14.TEXTURE15.TEXTURE16.TEXTURE17.TEXTURE18.TEXTURE19.TEXTURE2.TEXTURE20.TEXTURE21.TEXTURE22.TEXTURE23.TEXTURE24.TEXTURE25.TEXTURE26.TEXTURE27.TEXTURE28.TEXTURE29.TEXTURE3.TEXTURE30.TEXTURE31.TEXTURE4.TEXTURE5.TEXTURE6.TEXTURE7.TEXTURE8.TEXTURE9.TEXTURE_2D.TEXTURE_BINDING_2D.TEXTURE_BINDING_CUBE_MAP.TEXTURE_CUBE_MAP.TEXTURE_CUBE_MAP_NEGATIVE_X.TEXTURE_CUBE_MAP_NEGATIVE_Y.TEXTURE_CUBE_MAP_NEGATIVE_Z.TEXTURE_CUBE_MAP_POSITIVE_X.TEXTURE_CUBE_MAP_POSITIVE_Y.TEXTURE_CUBE_MAP_POSITIVE_Z.TEXTURE_MAG_FILTER.TEXTURE_MIN_FILTER.TEXTURE_WRAP_S.TEXTURE_WRAP_T.TRIANGLES.TRIANGLE_FAN.TRIANGLE_STRIP.UNPACK_ALIGNMENT.UNPACK_COLORSPACE_CONVERSION_WEBGL.UNPACK_FLIP_Y_WEBGL.UNPACK_PREMULTIPLY_ALPHA_WEBGL.UNSIGNED_BYTE.UNSIGNED_INT.UNSIGNED_SHORT.UNSIGNED_SHORT_4_4_4_4.UNSIGNED_SHORT_5_5_5_1.UNSIGNED_SHORT_5_6_5.VALIDATE_STATUS.VENDOR.VERSION.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING.VERTEX_ATTRIB_ARRAY_ENABLED.VERTEX_ATTRIB_ARRAY_NORMALIZED.VERTEX_ATTRIB_ARRAY_POINTER.VERTEX_ATTRIB_ARRAY_SIZE.VERTEX_ATTRIB_ARRAY_STRIDE.VERTEX_ATTRIB_ARRAY_TYPE.VERTEX_SHADER.VIEWPORT.ZERO`.split(`.`);var v=e(async()=>{await p(`Display`,async()=>{g.init();let e,p,v=new h.MainLoop(null,!1),y=new g.Window({});y.set_default_size(200,200),e=new m,e.onReady((e,t)=>{p=t,v.quit()}),y.set_child(e),y.present();let b=h.timeout_add(h.PRIORITY_DEFAULT,1e4,()=>(v.quit(),h.SOURCE_REMOVE));if(v.run(),h.source_remove(b),!p){console.warn(`WebGL context not available after 10s — skipping tests`),y.destroy();return}e.make_current(),await u(`WebGLRenderingContext constants`,async()=>{l(async()=>{e.make_current()}),await f(`should have all standard WebGL constants as numbers`,async()=>{for(let e of _){let t=p?.[e];d(typeof t).toBe(`number`),e===`NONE`||e===`ZERO`||e===`NO_ERROR`||e===`POINTS`?d(t===0).toBeTruthy():d(t>0).toBeTruthy()}})}),await u(`Buffers`,async()=>{l(async()=>{e.make_current()}),await f(`createBuffer returns a WebGLBuffer`,async()=>{let e=p.createBuffer();d(e).toBeDefined(),d(e).not.toBeNull()}),await f(`bindBuffer + bufferData with Float32Array`,async()=>{let e=p.createBuffer();p.bindBuffer(p.ARRAY_BUFFER,e);let t=new Float32Array([1,2,3,4]);d(()=>p.bufferData(p.ARRAY_BUFFER,t,p.STATIC_DRAW)).not.toThrow()}),await f(`getBufferParameter returns buffer size`,async()=>{let e=p.createBuffer();p.bindBuffer(p.ARRAY_BUFFER,e);let t=new Float32Array([1,2,3,4]);p.bufferData(p.ARRAY_BUFFER,t,p.STATIC_DRAW),d(p.getBufferParameter(p.ARRAY_BUFFER,p.BUFFER_SIZE)).toBe(t.byteLength)}),await f(`bufferSubData updates buffer data`,async()=>{let e=p.createBuffer();p.bindBuffer(p.ARRAY_BUFFER,e);let t=new Float32Array([1,2,3,4]);p.bufferData(p.ARRAY_BUFFER,t,p.DYNAMIC_DRAW),d(()=>p.bufferSubData(p.ARRAY_BUFFER,0,new Float32Array([9,9]))).not.toThrow()}),await f(`deleteBuffer cleans up`,async()=>{let e=p.createBuffer();d(()=>p.deleteBuffer(e)).not.toThrow()})}),await u(`Shaders`,async()=>{l(async()=>{e.make_current()});let t=`attribute vec2 position; void main() { gl_Position = vec4(position, 0.0, 1.0); }`,n=`void main() { gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); }`;await f(`createShader returns a WebGLShader`,async()=>{let e=p.createShader(p.VERTEX_SHADER);d(e).toBeDefined(),d(e).not.toBeNull()}),await f(`vertex shader compiles successfully`,async()=>{let e=p.createShader(p.VERTEX_SHADER);p.shaderSource(e,t),p.compileShader(e);let n=p.getShaderParameter(e,p.COMPILE_STATUS);n||console.error(`Vertex shader log:`,p.getShaderInfoLog(e)),d(n).toBeTruthy()}),await f(`fragment shader compiles successfully`,async()=>{let e=p.createShader(p.FRAGMENT_SHADER);p.shaderSource(e,n),p.compileShader(e);let t=p.getShaderParameter(e,p.COMPILE_STATUS);t||console.error(`Fragment shader log:`,p.getShaderInfoLog(e)),d(t).toBeTruthy()}),await f(`program links successfully`,async()=>{let e=p.createShader(p.VERTEX_SHADER);p.shaderSource(e,t),p.compileShader(e);let r=p.createShader(p.FRAGMENT_SHADER);p.shaderSource(r,n),p.compileShader(r);let i=p.createProgram();p.attachShader(i,e),p.attachShader(i,r),p.linkProgram(i);let a=p.getProgramParameter(i,p.LINK_STATUS);a||console.error(`Program log:`,p.getProgramInfoLog(i)),d(a).toBeTruthy()})}),await u(`Textures`,async()=>{l(async()=>{e.make_current()}),await f(`createTexture returns a WebGLTexture`,async()=>{let e=p.createTexture();d(e).toBeDefined(),d(e).not.toBeNull()}),await f(`bindTexture + texImage2D with Uint8Array`,async()=>{let e=p.createTexture();p.bindTexture(p.TEXTURE_2D,e);let t=new Uint8Array([255,0,0,255]);d(()=>p.texImage2D(p.TEXTURE_2D,0,p.RGBA,1,1,0,p.RGBA,p.UNSIGNED_BYTE,t)).not.toThrow()}),await f(`texParameteri sets filter params without error`,async()=>{let e=p.createTexture();p.bindTexture(p.TEXTURE_2D,e),d(()=>{p.texParameteri(p.TEXTURE_2D,p.TEXTURE_MIN_FILTER,p.NEAREST),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_MAG_FILTER,p.NEAREST),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_WRAP_S,p.CLAMP_TO_EDGE),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_WRAP_T,p.CLAMP_TO_EDGE)}).not.toThrow()}),await f(`deleteTexture cleans up`,async()=>{let e=p.createTexture();d(()=>p.deleteTexture(e)).not.toThrow()})}),await u(`Draw`,async()=>{l(async()=>{e.make_current()}),await f(`clearColor + clear does not throw`,async()=>{d(()=>{p.clearColor(0,0,0,1),p.clear(p.COLOR_BUFFER_BIT)}).not.toThrow(),d(p.getError()).toBe(p.NO_ERROR)}),await f(`viewport does not throw`,async()=>{d(()=>p.viewport(0,0,200,200)).not.toThrow()}),await f(`drawArrays (triangle) produces no GL error`,async()=>{let e=p.createShader(p.VERTEX_SHADER);p.shaderSource(e,`attribute vec2 position; void main() { gl_Position = vec4(position, 0.0, 1.0); }`),p.compileShader(e);let t=p.createShader(p.FRAGMENT_SHADER);p.shaderSource(t,`void main() { gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); }`),p.compileShader(t);let n=p.createProgram();p.attachShader(n,e),p.attachShader(n,t),p.linkProgram(n),p.useProgram(n);let r=p.createBuffer();p.bindBuffer(p.ARRAY_BUFFER,r),p.bufferData(p.ARRAY_BUFFER,new Float32Array([-1,0,0,-1,1,1]),p.STATIC_DRAW);let i=p.getAttribLocation(n,`position`);p.enableVertexAttribArray(i),p.vertexAttribPointer(i,2,p.FLOAT,!1,0,0),p.clearColor(0,0,0,1),p.clear(p.COLOR_BUFFER_BIT),d(()=>p.drawArrays(p.TRIANGLES,0,3)).not.toThrow(),d(p.getError()).toBe(p.NO_ERROR)})}),await u(`Extensions`,async()=>{l(async()=>{e.make_current()}),await f(`OES_texture_float is supported`,async()=>{d(p.getExtension(`OES_texture_float`)).not.toBeNull()}),await f(`OES_standard_derivatives is supported`,async()=>{d(p.getExtension(`OES_standard_derivatives`)).not.toBeNull()}),await f(`OES_element_index_uint is supported`,async()=>{d(p.getExtension(`OES_element_index_uint`)).not.toBeNull()}),await f(`getSupportedExtensions returns an array`,async()=>{let e=p.getSupportedExtensions();d(Array.isArray(e)).toBeTruthy(),d((e?.length??0)>0).toBeTruthy()})}),await u(`Gwebgl.WebGLRenderingContext native bindings`,async()=>{l(async()=>{e.make_current()}),await f(`getParameterb returns a boolean`,async()=>{let e=p?._native.getParameterb(p?.BLEND);d(typeof e).toBe(`boolean`)}),await f(`getParameterbv returns an array of booleans`,async()=>{let e=p?._native.getParameterbv(p?.COLOR_WRITEMASK,16);if(d(Array.isArray(e)).toBeTruthy(),Array.isArray(e))for(let t of e)d(typeof t).toBe(`boolean`)}),await f(`getParameterf returns a float`,async()=>{let e=p?._native.getParameterf(p?.SAMPLE_COVERAGE_VALUE);d(typeof e).toBe(`number`)}),await f(`getParameterfv returns an array of floats`,async()=>{let e=p?._native.getParameterfv(p?.DEPTH_RANGE,8);if(d(Array.isArray(e)).toBeTruthy(),Array.isArray(e))for(let t of e)d(typeof t).toBe(`number`)}),await f(`getParameteri returns an integer`,async()=>{let e=p?._native.getParameteri(p?.ARRAY_BUFFER_BINDING);d(typeof e).toBe(`number`)}),await f(`getParameteriv returns an array of integers`,async()=>{let e=p?._native.getParameteriv(p?.MAX_VIEWPORT_DIMS,8);if(d(Array.isArray(e)).toBeTruthy(),Array.isArray(e))for(let t of e)d(typeof t).toBe(`number`)})}),await u(`simple-shader rendering`,async()=>{l(async()=>{e.make_current()}),await f(`renders a green triangle — all pixels (0,255,0,255)`,async()=>{let e=a(p,8,8);p.clearColor(0,0,0,1),p.clear(p.COLOR_BUFFER_BIT);let n=i(p,`attribute vec2 position; void main() { gl_Position = vec4(position, 0.0, 1.0); }`,`void main() { gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); }`);d(p.getProgramParameter(n,p.LINK_STATUS)).toBeTruthy(),p.useProgram(n),r(p),d(p.getError()).toBe(p.NO_ERROR);let o=new Uint8Array(e.width*e.height*4);p.readPixels(0,0,e.width,e.height,p.RGBA,p.UNSIGNED_BYTE,o);let s=!0;for(let e=0;e<o.length;e+=4)if(o[e]!==0||o[e+1]!==255||o[e+2]!==0||o[e+3]!==255){s=!1;break}d(s).toBeTruthy(),p.deleteProgram(n),t(p,e)})}),await u(`clearColor`,async()=>{l(async()=>{e.make_current()}),await f(`clears to black (0,0,0,0)`,async()=>{let e=a(p);p.clearColor(0,0,0,0),p.clear(p.COLOR_BUFFER_BIT);let n=c(p,0,0);t(p,e),d(n[0]).toBe(0),d(n[1]).toBe(0),d(n[2]).toBe(0),d(n[3]).toBe(0)}),await f(`clears to white (255,255,255,255)`,async()=>{let e=a(p);p.clearColor(1,1,1,1),p.clear(p.COLOR_BUFFER_BIT);let n=c(p,0,0);t(p,e),d(n[0]).toBe(255),d(n[1]).toBe(255),d(n[2]).toBe(255),d(n[3]).toBe(255)}),await f(`clears to green (0,255,0,255)`,async()=>{let e=a(p);p.clearColor(0,1,0,1),p.clear(p.COLOR_BUFFER_BIT);let n=c(p,0,0);t(p,e),d(n[0]).toBe(0),d(n[1]).toBe(255),d(n[2]).toBe(0),d(n[3]).toBe(255)}),await f(`clears to magenta (255,0,255,255)`,async()=>{let e=a(p);p.clearColor(1,0,1,1),p.clear(p.COLOR_BUFFER_BIT);let n=c(p,0,0);t(p,e),d(n[0]).toBe(255),d(n[1]).toBe(0),d(n[2]).toBe(255),d(n[3]).toBe(255)})}),await u(`blending`,async()=>{l(async()=>{e.make_current()});let n=[`precision mediump float;`,`attribute vec2 position;`,`void main() { gl_Position = vec4(position, 0.0, 1.0); }`].join(`
|
|
1
|
+
import{__name as e}from"./_virtual/_rolldown/runtime.js";import{destroyTestFBO as t,destroyTestFBOWithDepth as n,drawTriangle as r,makeProgram as i,makeTestFBO as a,makeTestFBOWithDepth as o,pixelClose as s,readPixel as c}from"./test-utils.js";import{beforeEach as l,describe as u,expect as d,it as f,on as p}from"@gjsify/unit";import{WebGLBridge as m}from"@gjsify/webgl";import h from"@girs/glib-2.0";import g from"@girs/gtk-4.0";const _=`ACTIVE_ATTRIBUTES.ACTIVE_TEXTURE.ACTIVE_UNIFORMS.ALIASED_LINE_WIDTH_RANGE.ALIASED_POINT_SIZE_RANGE.ALPHA.ALPHA_BITS.ALWAYS.ARRAY_BUFFER.ARRAY_BUFFER_BINDING.ATTACHED_SHADERS.BACK.BLEND.BLEND_COLOR.BLEND_DST_ALPHA.BLEND_DST_RGB.BLEND_EQUATION.BLEND_EQUATION_ALPHA.BLEND_EQUATION_RGB.BLEND_SRC_ALPHA.BLEND_SRC_RGB.BLUE_BITS.BOOL.BOOL_VEC2.BOOL_VEC3.BOOL_VEC4.BROWSER_DEFAULT_WEBGL.BUFFER_SIZE.BUFFER_USAGE.BYTE.CCW.CLAMP_TO_EDGE.COLOR_ATTACHMENT0.COLOR_BUFFER_BIT.COLOR_CLEAR_VALUE.COLOR_WRITEMASK.COMPILE_STATUS.COMPRESSED_TEXTURE_FORMATS.CONSTANT_ALPHA.CONSTANT_COLOR.CONTEXT_LOST_WEBGL.CULL_FACE.CULL_FACE_MODE.CURRENT_PROGRAM.CURRENT_VERTEX_ATTRIB.CW.DECR.DECR_WRAP.DELETE_STATUS.DEPTH_ATTACHMENT.DEPTH_BITS.DEPTH_BUFFER_BIT.DEPTH_CLEAR_VALUE.DEPTH_COMPONENT.DEPTH_COMPONENT16.DEPTH_FUNC.DEPTH_RANGE.DEPTH_STENCIL.DEPTH_STENCIL_ATTACHMENT.DEPTH_TEST.DEPTH_WRITEMASK.DITHER.DONT_CARE.DST_ALPHA.DST_COLOR.DYNAMIC_DRAW.ELEMENT_ARRAY_BUFFER.ELEMENT_ARRAY_BUFFER_BINDING.EQUAL.FASTEST.FLOAT.FLOAT_MAT2.FLOAT_MAT3.FLOAT_MAT4.FLOAT_VEC2.FLOAT_VEC3.FLOAT_VEC4.FRAGMENT_SHADER.FRAMEBUFFER.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE.FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE.FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL.FRAMEBUFFER_BINDING.FRAMEBUFFER_COMPLETE.FRAMEBUFFER_INCOMPLETE_ATTACHMENT.FRAMEBUFFER_INCOMPLETE_DIMENSIONS.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT.FRAMEBUFFER_UNSUPPORTED.FRONT.FRONT_AND_BACK.FRONT_FACE.FUNC_ADD.FUNC_REVERSE_SUBTRACT.FUNC_SUBTRACT.GENERATE_MIPMAP_HINT.GEQUAL.GREATER.GREEN_BITS.HIGH_FLOAT.HIGH_INT.IMPLEMENTATION_COLOR_READ_FORMAT.IMPLEMENTATION_COLOR_READ_TYPE.INCR.INCR_WRAP.INT.INT_VEC2.INT_VEC3.INT_VEC4.INVALID_ENUM.INVALID_FRAMEBUFFER_OPERATION.INVALID_OPERATION.INVALID_VALUE.INVERT.KEEP.LEQUAL.LESS.LINEAR.LINEAR_MIPMAP_LINEAR.LINEAR_MIPMAP_NEAREST.LINES.LINE_LOOP.LINE_STRIP.LINE_WIDTH.LINK_STATUS.LOW_FLOAT.LOW_INT.LUMINANCE.LUMINANCE_ALPHA.MAX_COMBINED_TEXTURE_IMAGE_UNITS.MAX_CUBE_MAP_TEXTURE_SIZE.MAX_FRAGMENT_UNIFORM_VECTORS.MAX_RENDERBUFFER_SIZE.MAX_TEXTURE_IMAGE_UNITS.MAX_TEXTURE_SIZE.MAX_VARYING_VECTORS.MAX_VERTEX_ATTRIBS.MAX_VERTEX_TEXTURE_IMAGE_UNITS.MAX_VERTEX_UNIFORM_VECTORS.MAX_VIEWPORT_DIMS.MEDIUM_FLOAT.MEDIUM_INT.MIRRORED_REPEAT.NEAREST.NEAREST_MIPMAP_LINEAR.NEAREST_MIPMAP_NEAREST.NEVER.NICEST.NONE.NOTEQUAL.NO_ERROR.ONE.ONE_MINUS_CONSTANT_ALPHA.ONE_MINUS_CONSTANT_COLOR.ONE_MINUS_DST_ALPHA.ONE_MINUS_DST_COLOR.ONE_MINUS_SRC_ALPHA.ONE_MINUS_SRC_COLOR.OUT_OF_MEMORY.PACK_ALIGNMENT.POINTS.POLYGON_OFFSET_FACTOR.POLYGON_OFFSET_FILL.POLYGON_OFFSET_UNITS.RED_BITS.RENDERBUFFER.RENDERBUFFER_ALPHA_SIZE.RENDERBUFFER_BINDING.RENDERBUFFER_BLUE_SIZE.RENDERBUFFER_DEPTH_SIZE.RENDERBUFFER_GREEN_SIZE.RENDERBUFFER_HEIGHT.RENDERBUFFER_INTERNAL_FORMAT.RENDERBUFFER_RED_SIZE.RENDERBUFFER_STENCIL_SIZE.RENDERBUFFER_WIDTH.RENDERER.REPEAT.REPLACE.RGB.RGB565.RGB5_A1.RGBA.RGBA4.SAMPLER_2D.SAMPLER_CUBE.SAMPLES.SAMPLE_ALPHA_TO_COVERAGE.SAMPLE_BUFFERS.SAMPLE_COVERAGE.SAMPLE_COVERAGE_INVERT.SAMPLE_COVERAGE_VALUE.SCISSOR_BOX.SCISSOR_TEST.SHADER_TYPE.SHADING_LANGUAGE_VERSION.SHORT.SRC_ALPHA.SRC_ALPHA_SATURATE.SRC_COLOR.STATIC_DRAW.STENCIL_ATTACHMENT.STENCIL_BACK_FAIL.STENCIL_BACK_FUNC.STENCIL_BACK_PASS_DEPTH_FAIL.STENCIL_BACK_PASS_DEPTH_PASS.STENCIL_BACK_REF.STENCIL_BACK_VALUE_MASK.STENCIL_BACK_WRITEMASK.STENCIL_BITS.STENCIL_BUFFER_BIT.STENCIL_CLEAR_VALUE.STENCIL_FAIL.STENCIL_FUNC.STENCIL_INDEX8.STENCIL_PASS_DEPTH_FAIL.STENCIL_PASS_DEPTH_PASS.STENCIL_REF.STENCIL_TEST.STENCIL_VALUE_MASK.STENCIL_WRITEMASK.STREAM_DRAW.SUBPIXEL_BITS.TEXTURE.TEXTURE0.TEXTURE1.TEXTURE10.TEXTURE11.TEXTURE12.TEXTURE13.TEXTURE14.TEXTURE15.TEXTURE16.TEXTURE17.TEXTURE18.TEXTURE19.TEXTURE2.TEXTURE20.TEXTURE21.TEXTURE22.TEXTURE23.TEXTURE24.TEXTURE25.TEXTURE26.TEXTURE27.TEXTURE28.TEXTURE29.TEXTURE3.TEXTURE30.TEXTURE31.TEXTURE4.TEXTURE5.TEXTURE6.TEXTURE7.TEXTURE8.TEXTURE9.TEXTURE_2D.TEXTURE_BINDING_2D.TEXTURE_BINDING_CUBE_MAP.TEXTURE_CUBE_MAP.TEXTURE_CUBE_MAP_NEGATIVE_X.TEXTURE_CUBE_MAP_NEGATIVE_Y.TEXTURE_CUBE_MAP_NEGATIVE_Z.TEXTURE_CUBE_MAP_POSITIVE_X.TEXTURE_CUBE_MAP_POSITIVE_Y.TEXTURE_CUBE_MAP_POSITIVE_Z.TEXTURE_MAG_FILTER.TEXTURE_MIN_FILTER.TEXTURE_WRAP_S.TEXTURE_WRAP_T.TRIANGLES.TRIANGLE_FAN.TRIANGLE_STRIP.UNPACK_ALIGNMENT.UNPACK_COLORSPACE_CONVERSION_WEBGL.UNPACK_FLIP_Y_WEBGL.UNPACK_PREMULTIPLY_ALPHA_WEBGL.UNSIGNED_BYTE.UNSIGNED_INT.UNSIGNED_SHORT.UNSIGNED_SHORT_4_4_4_4.UNSIGNED_SHORT_5_5_5_1.UNSIGNED_SHORT_5_6_5.VALIDATE_STATUS.VENDOR.VERSION.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING.VERTEX_ATTRIB_ARRAY_ENABLED.VERTEX_ATTRIB_ARRAY_NORMALIZED.VERTEX_ATTRIB_ARRAY_POINTER.VERTEX_ATTRIB_ARRAY_SIZE.VERTEX_ATTRIB_ARRAY_STRIDE.VERTEX_ATTRIB_ARRAY_TYPE.VERTEX_SHADER.VIEWPORT.ZERO`.split(`.`);var v=e(async()=>{await p(`Display`,async()=>{g.init();let e,p,v=new h.MainLoop(null,!1),y=new g.Window({});y.set_default_size(200,200),e=new m,e.onReady((e,t)=>{p=t,v.quit()}),y.set_child(e),y.present();let b=h.timeout_add(h.PRIORITY_DEFAULT,1e4,()=>(v.quit(),h.SOURCE_REMOVE));if(v.run(),h.source_remove(b),!p){console.warn(`WebGL context not available after 10s — skipping tests`),y.destroy();return}e.make_current(),await u(`WebGLRenderingContext constants`,async()=>{l(async()=>{e.make_current()}),await f(`should have all standard WebGL constants as numbers`,async()=>{for(let e of _){let t=p?.[e];d(typeof t).toBe(`number`),e===`NONE`||e===`ZERO`||e===`NO_ERROR`||e===`POINTS`?d(t===0).toBeTruthy():d(t>0).toBeTruthy()}})}),await u(`Buffers`,async()=>{l(async()=>{e.make_current()}),await f(`createBuffer returns a WebGLBuffer`,async()=>{let e=p.createBuffer();d(e).toBeDefined(),d(e).not.toBeNull()}),await f(`bindBuffer + bufferData with Float32Array`,async()=>{let e=p.createBuffer();p.bindBuffer(p.ARRAY_BUFFER,e);let t=new Float32Array([1,2,3,4]);d(()=>p.bufferData(p.ARRAY_BUFFER,t,p.STATIC_DRAW)).not.toThrow()}),await f(`getBufferParameter returns buffer size`,async()=>{let e=p.createBuffer();p.bindBuffer(p.ARRAY_BUFFER,e);let t=new Float32Array([1,2,3,4]);p.bufferData(p.ARRAY_BUFFER,t,p.STATIC_DRAW),d(p.getBufferParameter(p.ARRAY_BUFFER,p.BUFFER_SIZE)).toBe(t.byteLength)}),await f(`bufferSubData updates buffer data`,async()=>{let e=p.createBuffer();p.bindBuffer(p.ARRAY_BUFFER,e);let t=new Float32Array([1,2,3,4]);p.bufferData(p.ARRAY_BUFFER,t,p.DYNAMIC_DRAW),d(()=>p.bufferSubData(p.ARRAY_BUFFER,0,new Float32Array([9,9]))).not.toThrow()}),await f(`deleteBuffer cleans up`,async()=>{let e=p.createBuffer();d(()=>p.deleteBuffer(e)).not.toThrow()})}),await u(`Shaders`,async()=>{l(async()=>{e.make_current()});let t=`attribute vec2 position; void main() { gl_Position = vec4(position, 0.0, 1.0); }`,n=`void main() { gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); }`;await f(`createShader returns a WebGLShader`,async()=>{let e=p.createShader(p.VERTEX_SHADER);d(e).toBeDefined(),d(e).not.toBeNull()}),await f(`vertex shader compiles successfully`,async()=>{let e=p.createShader(p.VERTEX_SHADER);p.shaderSource(e,t),p.compileShader(e);let n=p.getShaderParameter(e,p.COMPILE_STATUS);n||console.error(`Vertex shader log:`,p.getShaderInfoLog(e)),d(n).toBeTruthy()}),await f(`fragment shader compiles successfully`,async()=>{let e=p.createShader(p.FRAGMENT_SHADER);p.shaderSource(e,n),p.compileShader(e);let t=p.getShaderParameter(e,p.COMPILE_STATUS);t||console.error(`Fragment shader log:`,p.getShaderInfoLog(e)),d(t).toBeTruthy()}),await f(`program links successfully`,async()=>{let e=p.createShader(p.VERTEX_SHADER);p.shaderSource(e,t),p.compileShader(e);let r=p.createShader(p.FRAGMENT_SHADER);p.shaderSource(r,n),p.compileShader(r);let i=p.createProgram();p.attachShader(i,e),p.attachShader(i,r),p.linkProgram(i);let a=p.getProgramParameter(i,p.LINK_STATUS);a||console.error(`Program log:`,p.getProgramInfoLog(i)),d(a).toBeTruthy()})}),await u(`Textures`,async()=>{l(async()=>{e.make_current()}),await f(`createTexture returns a WebGLTexture`,async()=>{let e=p.createTexture();d(e).toBeDefined(),d(e).not.toBeNull()}),await f(`bindTexture + texImage2D with Uint8Array`,async()=>{let e=p.createTexture();p.bindTexture(p.TEXTURE_2D,e);let t=new Uint8Array([255,0,0,255]);d(()=>p.texImage2D(p.TEXTURE_2D,0,p.RGBA,1,1,0,p.RGBA,p.UNSIGNED_BYTE,t)).not.toThrow()}),await f(`texParameteri sets filter params without error`,async()=>{let e=p.createTexture();p.bindTexture(p.TEXTURE_2D,e),d(()=>{p.texParameteri(p.TEXTURE_2D,p.TEXTURE_MIN_FILTER,p.NEAREST),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_MAG_FILTER,p.NEAREST),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_WRAP_S,p.CLAMP_TO_EDGE),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_WRAP_T,p.CLAMP_TO_EDGE)}).not.toThrow()}),await f(`deleteTexture cleans up`,async()=>{let e=p.createTexture();d(()=>p.deleteTexture(e)).not.toThrow()})}),await u(`Draw`,async()=>{l(async()=>{e.make_current()}),await f(`clearColor + clear does not throw`,async()=>{d(()=>{p.clearColor(0,0,0,1),p.clear(p.COLOR_BUFFER_BIT)}).not.toThrow(),d(p.getError()).toBe(p.NO_ERROR)}),await f(`viewport does not throw`,async()=>{d(()=>p.viewport(0,0,200,200)).not.toThrow()}),await f(`drawArrays (triangle) produces no GL error`,async()=>{let e=p.createShader(p.VERTEX_SHADER);p.shaderSource(e,`attribute vec2 position; void main() { gl_Position = vec4(position, 0.0, 1.0); }`),p.compileShader(e);let t=p.createShader(p.FRAGMENT_SHADER);p.shaderSource(t,`void main() { gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); }`),p.compileShader(t);let n=p.createProgram();p.attachShader(n,e),p.attachShader(n,t),p.linkProgram(n),p.useProgram(n);let r=p.createBuffer();p.bindBuffer(p.ARRAY_BUFFER,r),p.bufferData(p.ARRAY_BUFFER,new Float32Array([-1,0,0,-1,1,1]),p.STATIC_DRAW);let i=p.getAttribLocation(n,`position`);p.enableVertexAttribArray(i),p.vertexAttribPointer(i,2,p.FLOAT,!1,0,0),p.clearColor(0,0,0,1),p.clear(p.COLOR_BUFFER_BIT),d(()=>p.drawArrays(p.TRIANGLES,0,3)).not.toThrow(),d(p.getError()).toBe(p.NO_ERROR)})}),await u(`Extensions`,async()=>{l(async()=>{e.make_current()}),await f(`OES_texture_float is supported`,async()=>{d(p.getExtension(`OES_texture_float`)).not.toBeNull()}),await f(`OES_standard_derivatives is supported`,async()=>{d(p.getExtension(`OES_standard_derivatives`)).not.toBeNull()}),await f(`OES_element_index_uint is supported`,async()=>{d(p.getExtension(`OES_element_index_uint`)).not.toBeNull()}),await f(`getSupportedExtensions returns an array`,async()=>{let e=p.getSupportedExtensions();d(Array.isArray(e)).toBeTruthy(),d((e?.length??0)>0).toBeTruthy()}),await f(`WEBGL_debug_renderer_info reports the real driver`,async()=>{d(p.getSupportedExtensions()?.includes(`WEBGL_debug_renderer_info`)).toBeTruthy();let e=p.getExtension(`WEBGL_debug_renderer_info`);d(e).not.toBeNull(),d(e.UNMASKED_VENDOR_WEBGL).toBe(37445),d(e.UNMASKED_RENDERER_WEBGL).toBe(37446);let t=p.getParameter(e.UNMASKED_VENDOR_WEBGL),n=p.getParameter(e.UNMASKED_RENDERER_WEBGL);d(typeof t).toBe(`string`),d(typeof n).toBe(`string`),d(n.length>0).toBeTruthy(),d(n).not.toBe(`ANGLE`)})}),await u(`Gwebgl.WebGLRenderingContext native bindings`,async()=>{l(async()=>{e.make_current()}),await f(`getParameterb returns a boolean`,async()=>{let e=p?._native.getParameterb(p?.BLEND);d(typeof e).toBe(`boolean`)}),await f(`getParameterbv returns an array of booleans`,async()=>{let e=p?._native.getParameterbv(p?.COLOR_WRITEMASK,16);if(d(Array.isArray(e)).toBeTruthy(),Array.isArray(e))for(let t of e)d(typeof t).toBe(`boolean`)}),await f(`getParameterf returns a float`,async()=>{let e=p?._native.getParameterf(p?.SAMPLE_COVERAGE_VALUE);d(typeof e).toBe(`number`)}),await f(`getParameterfv returns an array of floats`,async()=>{let e=p?._native.getParameterfv(p?.DEPTH_RANGE,8);if(d(Array.isArray(e)).toBeTruthy(),Array.isArray(e))for(let t of e)d(typeof t).toBe(`number`)}),await f(`getParameteri returns an integer`,async()=>{let e=p?._native.getParameteri(p?.ARRAY_BUFFER_BINDING);d(typeof e).toBe(`number`)}),await f(`getParameteriv returns an array of integers`,async()=>{let e=p?._native.getParameteriv(p?.MAX_VIEWPORT_DIMS,8);if(d(Array.isArray(e)).toBeTruthy(),Array.isArray(e))for(let t of e)d(typeof t).toBe(`number`)})}),await u(`simple-shader rendering`,async()=>{l(async()=>{e.make_current()}),await f(`renders a green triangle — all pixels (0,255,0,255)`,async()=>{let e=a(p,8,8);p.clearColor(0,0,0,1),p.clear(p.COLOR_BUFFER_BIT);let n=i(p,`attribute vec2 position; void main() { gl_Position = vec4(position, 0.0, 1.0); }`,`void main() { gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); }`);d(p.getProgramParameter(n,p.LINK_STATUS)).toBeTruthy(),p.useProgram(n),r(p),d(p.getError()).toBe(p.NO_ERROR);let o=new Uint8Array(e.width*e.height*4);p.readPixels(0,0,e.width,e.height,p.RGBA,p.UNSIGNED_BYTE,o);let s=!0;for(let e=0;e<o.length;e+=4)if(o[e]!==0||o[e+1]!==255||o[e+2]!==0||o[e+3]!==255){s=!1;break}d(s).toBeTruthy(),p.deleteProgram(n),t(p,e)})}),await u(`clearColor`,async()=>{l(async()=>{e.make_current()}),await f(`clears to black (0,0,0,0)`,async()=>{let e=a(p);p.clearColor(0,0,0,0),p.clear(p.COLOR_BUFFER_BIT);let n=c(p,0,0);t(p,e),d(n[0]).toBe(0),d(n[1]).toBe(0),d(n[2]).toBe(0),d(n[3]).toBe(0)}),await f(`clears to white (255,255,255,255)`,async()=>{let e=a(p);p.clearColor(1,1,1,1),p.clear(p.COLOR_BUFFER_BIT);let n=c(p,0,0);t(p,e),d(n[0]).toBe(255),d(n[1]).toBe(255),d(n[2]).toBe(255),d(n[3]).toBe(255)}),await f(`clears to green (0,255,0,255)`,async()=>{let e=a(p);p.clearColor(0,1,0,1),p.clear(p.COLOR_BUFFER_BIT);let n=c(p,0,0);t(p,e),d(n[0]).toBe(0),d(n[1]).toBe(255),d(n[2]).toBe(0),d(n[3]).toBe(255)}),await f(`clears to magenta (255,0,255,255)`,async()=>{let e=a(p);p.clearColor(1,0,1,1),p.clear(p.COLOR_BUFFER_BIT);let n=c(p,0,0);t(p,e),d(n[0]).toBe(255),d(n[1]).toBe(0),d(n[2]).toBe(255),d(n[3]).toBe(255)})}),await u(`blending`,async()=>{l(async()=>{e.make_current()});let n=[`precision mediump float;`,`attribute vec2 position;`,`void main() { gl_Position = vec4(position, 0.0, 1.0); }`].join(`
|
|
2
2
|
`),o=[{name:`ADD ONE ONE`,equn:p.FUNC_ADD,func1:p.ONE,func2:p.ONE,dstColor:[.5,.5,.5,1],srcColor:[.5,.5,.5,1],expected:[255,255,255,255]},{name:`ADD ONE ZERO`,equn:p.FUNC_ADD,func1:p.ONE,func2:p.ZERO,dstColor:[.5,.5,.5,.5],srcColor:[.2,.2,.2,1],expected:[51,51,51,255]},{name:`ADD ZERO SRC_COLOR`,equn:p.FUNC_ADD,func1:p.ZERO,func2:p.SRC_COLOR,dstColor:[.8,.8,.8,1],srcColor:[.5,.5,.5,.5],expected:[102,102,102,128]},{name:`ADD DST_COLOR ZERO`,equn:p.FUNC_ADD,func1:p.DST_COLOR,func2:p.ZERO,dstColor:[.8,.8,.8,1],srcColor:[.5,.5,.5,.5],expected:[102,102,102,128]},{name:`ADD SRC_ALPHA ONE_MINUS_SRC_ALPHA`,equn:p.FUNC_ADD,func1:p.SRC_ALPHA,func2:p.ONE_MINUS_SRC_ALPHA,dstColor:[.5,0,.5,1],srcColor:[.5,1,0,.5],expected:[127,127,64,191]}];for(let e of o){let{name:o,equn:l,func1:u,func2:m,dstColor:h,srcColor:g,expected:_}=e,v=[`precision mediump float;`,`void main() { gl_FragColor = vec4(${g[0]},${g[1]},${g[2]},${g[3]}); }`].join(`
|
|
3
3
|
`);await f(o,async()=>{let e=a(p);p.clearColor(h[0],h[1],h[2],h[3]),p.clear(p.COLOR_BUFFER_BIT);let o=i(p,n,v);p.useProgram(o),p.enable(p.BLEND),p.blendEquation(l),p.blendFunc(u,m),r(p),d(p.getError()).toBe(p.NO_ERROR),p.disable(p.BLEND);let f=c(p,0,0);p.deleteProgram(o),t(p,e),d(s(f,_)).toBeTruthy()})}}),await u(`drawElements (indexed drawing)`,async()=>{l(async()=>{e.make_current()}),await f(`draws a quad via index buffer — all pixels green`,async()=>{let e=a(p,8,8);p.clearColor(1,0,0,1),p.clear(p.COLOR_BUFFER_BIT);let n=i(p,`attribute vec2 position; void main() { gl_Position = vec4(position, 0.0, 1.0); }`,`void main() { gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); }`);p.useProgram(n);let r=p.createBuffer();p.bindBuffer(p.ARRAY_BUFFER,r),p.bufferData(p.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),p.STATIC_DRAW),p.enableVertexAttribArray(0),p.vertexAttribPointer(0,2,p.FLOAT,!1,0,0);let o=p.createBuffer();p.bindBuffer(p.ELEMENT_ARRAY_BUFFER,o),p.bufferData(p.ELEMENT_ARRAY_BUFFER,new Uint16Array([0,1,2,2,1,3]),p.STATIC_DRAW),p.drawElements(p.TRIANGLES,6,p.UNSIGNED_SHORT,0),d(p.getError()).toBe(p.NO_ERROR);let s=new Uint8Array(e.width*e.height*4);p.readPixels(0,0,e.width,e.height,p.RGBA,p.UNSIGNED_BYTE,s);let c=!0;for(let e=0;e<s.length;e+=4)if(s[e]!==0||s[e+1]!==255||s[e+2]!==0||s[e+3]!==255){c=!1;break}d(c).toBeTruthy(),p.disableVertexAttribArray(0),p.deleteBuffer(r),p.deleteBuffer(o),p.deleteProgram(n),t(p,e)})}),await u(`readPixels`,async()=>{l(async()=>{e.make_current()}),await f(`RGBA + UNSIGNED_BYTE returns correct data size`,async()=>{let e=a(p,4,4);p.clearColor(1,0,0,1),p.clear(p.COLOR_BUFFER_BIT);let n=new Uint8Array(e.width*e.height*4);p.readPixels(0,0,e.width,e.height,p.RGBA,p.UNSIGNED_BYTE,n),d(p.getError()).toBe(p.NO_ERROR),d(n.length).toBe(e.width*e.height*4),t(p,e)}),await f(`pixel values match the clear color`,async()=>{let e=a(p);p.clearColor(0,0,1,1),p.clear(p.COLOR_BUFFER_BIT);let n=c(p,0,0);t(p,e),d(n[0]).toBe(0),d(n[1]).toBe(0),d(n[2]).toBe(255),d(n[3]).toBe(255)}),await f(`readPixels reads a single red pixel`,async()=>{let e=a(p);p.clearColor(1,0,0,1),p.clear(p.COLOR_BUFFER_BIT);let n=new Uint8Array(4);p.readPixels(0,0,1,1,p.RGBA,p.UNSIGNED_BYTE,n),t(p,e),d(n[0]).toBe(255),d(n[1]).toBe(0),d(n[2]).toBe(0),d(n[3]).toBe(255)})}),await u(`depth buffer`,async()=>{l(async()=>{e.make_current()}),await f(`depth test (LESS) — nearer triangle occludes farther one`,async()=>{let e=[`attribute vec2 position;`,`uniform float depth;`,`void main() { gl_Position = vec4(position, depth, 1.0); }`].join(`
|
|
4
4
|
`),t=[`precision mediump float;`,`uniform vec4 color;`,`void main() { gl_FragColor = color; }`].join(`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{Uint8ArrayToVariant as e,arrayToUint8Array as t,checkObject as n,convertPixels as r,extractImageData as i,premultiplyAlpha as a,vertexCount as o}from"./utils.js";import{WebGLFramebuffer as s}from"./webgl-framebuffer.js";import{WebGLRenderbuffer as c}from"./webgl-renderbuffer.js";import{WebGLTexture as l}from"./webgl-texture.js";import{WebGLContextBase as u}from"./webgl-context-base.js";import{installObjectLifecycleMethods as d}from"./webgl2-context/object-lifecycle.js";import{installTexImage3DMethods as f}from"./webgl2-context/tex-image-3d.js";import{installUniformMethods as p}from"./webgl2-context/uniform.js";import{installClearBufferMethods as m}from"./webgl2-context/clear-buffer.js";import{installInstancedAndFramebufferOpsMethods as h}from"./webgl2-context/instanced-and-framebuffer-ops.js";import g from"gi://GdkPixbuf?version=2.0";import _ from"@girs/gwebgl-0.1";import{warnNotImplemented as v}from"@gjsify/utils";var y=class WebGL2RenderingContext extends u{get _gl(){return this._native2}constructor(e,t={}){super(e,t),this._queries={},this._samplers={},this._transformFeedbacks={},this._vertexArrayObjects={},this._syncs={},this._activeReadFramebuffer=null,this._activeDrawFramebuffer=null,this._native2=new _.WebGL2RenderingContext({}),this._init()}_getGlslVersion(e){return e?`300 es`:`130`}_validFramebufferAttachment(e){return super._validFramebufferAttachment(e)?!0:e>=36065&&e<=36079}static{this._WGL2_ALL_COLOR_ATTACHMENTS=[36064,36065,36066,36067,36068,36069,36070,36071,36072,36073,36074,36075,36076,36077,36078,36079]}_getColorAttachments(){return WebGL2RenderingContext._WGL2_ALL_COLOR_ATTACHMENTS}_preCheckFramebufferStatus(e){let t=e._attachments,n=0,r=0,i=[this.COLOR_ATTACHMENT0,this.DEPTH_ATTACHMENT,this.STENCIL_ATTACHMENT,this.DEPTH_STENCIL_ATTACHMENT,...WebGL2RenderingContext._WGL2_ALL_COLOR_ATTACHMENTS];for(let a of i){let i=t[a];if(i){if(i instanceof l){let t=e._attachmentLevel[a]??0,o=i._levelWidth[t]??0,s=i._levelHeight[t]??0;if(o>0&&s>0){n=o,r=s;break}}else if(i instanceof c&&i._width>0&&i._height>0){n=i._width,r=i._height;break}}}return n>0&&r>0?(e._width=n,e._height=r,this.FRAMEBUFFER_COMPLETE):this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT}_updateFramebufferAttachments(e){if(super._updateFramebufferAttachments(e),e)for(let t=1;t<=15;t++){let n=36064+t;if(!(n in e._attachments))continue;let r=e._attachments[n];if(r instanceof l){let t=e._attachmentFace[n]||this.TEXTURE_2D,i=e._attachmentLevel[n]??0;this._gl.framebufferTexture2D(this.FRAMEBUFFER,n,t,r._|0,i|0)}else r instanceof c?this._gl.framebufferRenderbuffer(this.FRAMEBUFFER,n,this.RENDERBUFFER,r._|0):this._gl.framebufferTexture2D(this.FRAMEBUFFER,n,this.TEXTURE_2D,0,0)}}bindBuffer(e,t){if(e===35345||e===35982||e===36662||e===36663){let n=t?t._|0:0;this._gl.bindBuffer(e,n);return}super.bindBuffer(e,t)}bindFramebuffer(e,t){if(e===36008||e===36009){if(!n(t))throw TypeError(`bindFramebuffer(GLenum, WebGLFramebuffer)`);if(t&&t._pendingDelete||t&&!this._checkWrapper(t,s))return;let r=t?t._|0:this._gtkFboId;if(this._gl.bindFramebuffer(e,r),e===36008){let e=this._activeReadFramebuffer;e!==t&&(e&&(--e._refCount,e._checkDelete()),t&&(t._refCount+=1)),this._activeReadFramebuffer=t}else{let e=this._activeDrawFramebuffer;e!==t&&(e&&(--e._refCount,e._checkDelete()),t&&(t._refCount+=1)),this._activeDrawFramebuffer=t,this._activeFramebuffer=t}return}super.bindFramebuffer(this.FRAMEBUFFER,t),this._activeReadFramebuffer=t,this._activeDrawFramebuffer=t}deleteFramebuffer(e){this._activeReadFramebuffer===e&&this.bindFramebuffer(36008,null),this._activeDrawFramebuffer===e&&this.bindFramebuffer(36009,null),super.deleteFramebuffer(e)}bufferData(n,r,i){let a=n===35345||n===35982||n===36662||n===36663,o=i===35041||i===35043||i===35045||i===35042||i===35044||i===35046?this.STATIC_DRAW:i;if(a){if(typeof r==`number`)r>=0&&this._gl.bufferDataSizeOnly(n,r,o);else if(typeof r==`object`&&r){let i=t(r);this._gl.bufferData(n,e(i),o)}return}super.bufferData(n,r,o)}bufferSubData(n,r,i){if(n===35345||n===35982||n===36662||n===36663){if(r<0){this.setError(this.INVALID_VALUE);return}if(!i){this.setError(this.INVALID_VALUE);return}let a=t(i);this._gl.bufferSubData(n,r,e(a));return}super.bufferSubData(n,r,i)}bindTexture(e,t){if(e===32879||e===35866){let n=t,r=n?n._|0:0;this._gl.bindTexture(e,r),n&&(n._binding=e);return}super.bindTexture(e,t)}texParameteri(e,t,n){if(e===32879||e===35866){this._gl.texParameteri(e,t,n);return}if(t===32882||t===34892||t===34893||t===33084||t===33085||t===33083||t===33082){this._gl.texParameteri(e,t,n);return}super.texParameteri(e,t,n)}drawArrays(e,t,n){if(t<0||n<0){this.setError(this.INVALID_VALUE);return}if(!this._checkStencilState())return;let r=o(this,e,n);if(r<0){this.setError(this.INVALID_ENUM);return}this._framebufferOk()&&n!==0&&this._checkVertexAttribState(n+t-1>>>0)&&this._native2.drawArrays(e,t,r)}drawElements(e=0,t=0,n=0,r=0){if(t<0||r<0){this.setError(this.INVALID_VALUE);return}if(!this._checkStencilState())return;let i=this._vertexObjectState._elementArrayBufferBinding;if(!i){this.setError(this.INVALID_OPERATION);return}let a=null,o=r;if(n===this.UNSIGNED_SHORT){if(o%2){this.setError(this.INVALID_OPERATION);return}o>>=1,a=new Uint16Array(i._elements.buffer)}else if(n===this.UNSIGNED_INT){if(o%4){this.setError(this.INVALID_OPERATION);return}o>>=2,a=new Uint32Array(i._elements.buffer)}else if(n===this.UNSIGNED_BYTE)a=i._elements;else{this.setError(this.INVALID_ENUM);return}let s=t;switch(e){case this.TRIANGLES:t%3&&(s-=t%3);break;case this.LINES:t%2&&(s-=t%2);break;case this.POINTS:break;case this.LINE_LOOP:case this.LINE_STRIP:if(t<2){this.setError(this.INVALID_OPERATION);return}break;case this.TRIANGLE_FAN:case this.TRIANGLE_STRIP:if(t<3){this.setError(this.INVALID_OPERATION);return}break;default:this.setError(this.INVALID_ENUM);return}if(!this._framebufferOk()||t===0)return;let c=0;for(let e=o;e<o+s;++e)e<a.length&&a[e]>c&&(c=a[e]);this._checkVertexAttribState(c)&&this._native2.drawElements(e,s,n,r)}bindBufferBase(e,t,n){this._native2.bindBufferBase(e,t,n?n._:0)}bindBufferRange(e,t,n,r,i){this._native2.bindBufferRange(e,t,n?n._:0,r,i)}copyBufferSubData(e,t,n,r,i){this._native2.copyBufferSubData(e,t,n,r,i)}getBufferSubData(e,t,n,r,i){let a=i===void 0?n.byteLength-(r??0):i,o=this._native2.getBufferSubData(e,t,a),s=new Uint8Array(n.buffer,n.byteOffset+(r??0)*(n instanceof Uint8Array?1:n.BYTES_PER_ELEMENT??1));s.set(o.subarray(0,s.byteLength))}texImage2D(t=0,n=0,o=0,s=0,c=0,l=0,u=0,d=0,f){let p=0,m=0,h=0,_=0;if(arguments.length===6)if(d=c,h=s,l instanceof g.Pixbuf){let e=l;p=e.get_width(),m=e.get_height(),f=e.get_pixels()}else{let e=i(l);if(e==null)throw TypeError(`texImage2D(GLenum, GLint, GLenum, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)`);p=e.width,m=e.height,f=e.data}else arguments.length>=9&&(p=s,m=c,_=l,h=u);let v=this._getTexImage(t);if(!v){this.setError(this.INVALID_OPERATION);return}let y=r(f);if(this._unpackPremultAlpha&&y&&h===this.RGBA&&(y=a(y)),this._unpackFlipY&&y&&p>0&&m>0){let e=this._computePixelSize(d,h);if(e>0){let t=this._computeRowStride(p,e),n=new Uint8Array(y.length);for(let e=0;e<m;e++){let r=e*t,i=(m-1-e)*t;n.set(y.subarray(r,r+t),i)}y=n}}this._saveError(),this._gl.texImage2D(t,n,o,p,m,_,h,d,e(y));let b=this.getError();if(this._restoreError(b),b!==this.NO_ERROR)return;v._levelWidth[n]=p,v._levelHeight[n]=m,v._format=h,v._type=d;let x=this._activeFramebuffer;if(x){let e=!1,t=this._getAttachments();for(let n=0;n<t.length;++n)if(x._attachments[t[n]]===v){e=!0;break}e&&this._activeFramebuffer&&this._updateFramebufferAttachments(this._activeFramebuffer)}}texSubImage2D(t=0,n=0,o=0,s=0,c=0,l=0,u=0,d=0,f){let p=0,m=0,h=0;if(arguments.length===7)if(d=l,h=c,u instanceof g.Pixbuf){let e=u;p=e.get_width(),m=e.get_height(),f=e.get_pixels()}else{let e=i(u);if(e==null)throw TypeError(`texSubImage2D(GLenum, GLint, GLint, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)`);p=e.width,m=e.height,f=e.data}else p=c,m=l,h=u;if(!this._getTexImage(t)){this.setError(this.INVALID_OPERATION);return}let _=r(f);if(!_){this.setError(this.INVALID_OPERATION);return}if(this._unpackPremultAlpha&&_&&h===this.RGBA&&(_=a(_)),this._unpackFlipY&&_&&p>0&&m>0){let e=this._computePixelSize(d,h);if(e>0){let t=this._computeRowStride(p,e),n=new Uint8Array(_.length);for(let e=0;e<m;e++){let r=e*t,i=(m-1-e)*t;n.set(_.subarray(r,r+t),i)}_=n}}this._gl.texSubImage2D(t,n,o,s,p,m,h,d,e(_))}getUniform(e,t){let n=t?._activeInfo?.type,r=5125,i=36294,a=36295,o=n===r||n===i||n===a||n===36296,s=e;if(!o)return super.getUniform(s,t);if(!e||!t)return null;let c=this._native2.getUniformi(s._|0,t._|0);return c?n===r?c[0]>>>0:n===i?new Uint32Array([c[0]>>>0,c[1]>>>0]):n===a?new Uint32Array([c[0]>>>0,c[1]>>>0,c[2]>>>0]):new Uint32Array([c[0]>>>0,c[1]>>>0,c[2]>>>0,c[3]>>>0]):null}getUniformBlockIndex(e,t){return this._native2.getUniformBlockIndex(e._,t)}uniformBlockBinding(e,t,n){this._native2.uniformBlockBinding(e._,t,n)}getActiveUniformBlockName(e,t){let n=this._native2.getActiveUniformBlockName(e._,t);return n.length>0?n:null}getActiveUniformBlockParameter(e,t,n){return this._native2.getActiveUniformBlockParameter(e._,t,n)}getActiveUniforms(e,t,n){return this._native2.getActiveUniforms(e._,t,n)}getFragDataLocation(e,t){return this._native2.getFragDataLocation(e._,t)}getIndexedParameter(e,t){return this._native2.getIndexedParameteri(e,t)}getInternalformatParameter(e,t,n){return this._native2.getInternalformatParameter(e,t,n)}getParameter(e){if(e===7938)return`WebGL 2.0`;if(e===35724)return`WebGL GLSL ES 3.00`;if(e===7939)return v(`WebGL2RenderingContext.getParameter(GL_EXTENSIONS)`),``;if(e===36006)return this._activeDrawFramebuffer;if(e===36010)return this._activeReadFramebuffer;switch(e){case 36183:case 35071:case 32883:case 36063:case 34852:case 36203:case 33001:case 33e3:case 37157:case 35373:case 35657:case 35077:case 35978:case 35979:case 35968:case 35376:case 35375:case 35659:case 37154:case 35371:case 35658:case 35379:case 35374:case 35377:case 35076:case 3330:case 3332:case 3331:case 35053:case 35055:case 3074:case 32874:case 35869:case 36389:case 35983:case 35368:case 35380:case 32878:case 3314:case 32877:case 3316:case 3315:case 34045:return this._native2.getParameterx(e)?.deepUnpack()|0;case 35977:case 36388:case 36387:return!!this._native2.getParameterx(e)?.deepUnpack()}return super.getParameter(e)}getStringi(e,t){let n=this._native2.getStringi(e,t);return n.length>0?n:null}renderbufferStorage(e,t,n,r){if(e!==this.RENDERBUFFER){this.setError(this.INVALID_ENUM);return}let i=this._activeRenderbuffer;if(!i){this.setError(this.INVALID_OPERATION);return}if(n<0||r<0){this.setError(this.INVALID_VALUE);return}for(;this._gl.getError()!==this.NO_ERROR;);if(this._gl.renderbufferStorage(e,t,n,r),this._gl.getError()!==this.NO_ERROR)return;i._width=n,i._height=r,i._format=t;let a=this._activeFramebuffer;if(a){let e=this._getAttachments(),t=!1;for(let n=0;n<e.length;++n)if(a._attachments[e[n]]===i){t=!0;break}t&&this._updateFramebufferAttachments(a)}}getSupportedExtensions(){let e=super.getSupportedExtensions();for(let t of[`EXT_color_buffer_float`,`EXT_color_buffer_half_float`,`OES_texture_half_float`])e.indexOf(t)===-1&&e.push(t);return e}readPixels(t,n,r,i,a,o,s){if(!s)return;if(r<0||i<0){this.setError(this.INVALID_VALUE);return}if(!this._framebufferOk())return;let c=a===6408||a===32856?4:a===6407?3:a===33319?2:1,l=o===5126?4:o===5131||o===36193?2:o===5125||o===5124?4:o===5123||o===5122?2:1,u=r*i*c*l,d=new Uint8Array(u);this._saveError();let f=this._gl.readPixels(t,n,r,i,a,o,e(d)),p=this.getError();if(this._restoreError(p),p!==this.NO_ERROR)return;let m=f&&f.length>0?f:d;if(s instanceof Uint8Array)s.set(m);else if(s instanceof Float32Array){let e=new Float32Array(m.buffer,0,s.length);s.set(e)}}_framebufferOk(){return!0}};d(y.prototype),f(y.prototype),p(y.prototype),m(y.prototype),h(y.prototype);export{y as WebGL2RenderingContext};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{Uint8ArrayToVariant as e,arrayToUint8Array as t,checkObject as n,convertPixels as r,extractImageData as i,premultiplyAlpha as a,vertexCount as o}from"./utils.js";import{WebGLFramebuffer as s}from"./webgl-framebuffer.js";import{WebGLRenderbuffer as c}from"./webgl-renderbuffer.js";import{WebGLTexture as l}from"./webgl-texture.js";import{WebGLContextBase as u}from"./webgl-context-base.js";import{installObjectLifecycleMethods as d}from"./webgl2-context/object-lifecycle.js";import{installTexImage3DMethods as f}from"./webgl2-context/tex-image-3d.js";import{installUniformMethods as p}from"./webgl2-context/uniform.js";import{installClearBufferMethods as m}from"./webgl2-context/clear-buffer.js";import{installInstancedAndFramebufferOpsMethods as h}from"./webgl2-context/instanced-and-framebuffer-ops.js";import g from"gi://GdkPixbuf?version=2.0";import _ from"@girs/gwebgl-0.1";import{warnNotImplemented as v}from"@gjsify/utils";var y=class WebGL2RenderingContext extends u{get _gl(){return this._native2}constructor(e,t={}){super(e,t),this._queries={},this._samplers={},this._transformFeedbacks={},this._vertexArrayObjects={},this._syncs={},this._activeReadFramebuffer=null,this._activeDrawFramebuffer=null,this._native2=new _.WebGL2RenderingContext({}),this._init()}_getGlslVersion(e){return e?`300 es`:this._desktopGlslVersion()}_validFramebufferAttachment(e){return super._validFramebufferAttachment(e)?!0:e>=36065&&e<=36079}static{this._WGL2_ALL_COLOR_ATTACHMENTS=[36064,36065,36066,36067,36068,36069,36070,36071,36072,36073,36074,36075,36076,36077,36078,36079]}_getColorAttachments(){return WebGL2RenderingContext._WGL2_ALL_COLOR_ATTACHMENTS}_preCheckFramebufferStatus(e){let t=e._attachments,n=0,r=0,i=[this.COLOR_ATTACHMENT0,this.DEPTH_ATTACHMENT,this.STENCIL_ATTACHMENT,this.DEPTH_STENCIL_ATTACHMENT,...WebGL2RenderingContext._WGL2_ALL_COLOR_ATTACHMENTS];for(let a of i){let i=t[a];if(i){if(i instanceof l){let t=e._attachmentLevel[a]??0,o=i._levelWidth[t]??0,s=i._levelHeight[t]??0;if(o>0&&s>0){n=o,r=s;break}}else if(i instanceof c&&i._width>0&&i._height>0){n=i._width,r=i._height;break}}}return n>0&&r>0?(e._width=n,e._height=r,this.FRAMEBUFFER_COMPLETE):this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT}_updateFramebufferAttachments(e){if(super._updateFramebufferAttachments(e),e)for(let t=1;t<=15;t++){let n=36064+t;if(!(n in e._attachments))continue;let r=e._attachments[n];if(r instanceof l){let t=e._attachmentFace[n]||this.TEXTURE_2D,i=e._attachmentLevel[n]??0;this._gl.framebufferTexture2D(this.FRAMEBUFFER,n,t,r._|0,i|0)}else r instanceof c?this._gl.framebufferRenderbuffer(this.FRAMEBUFFER,n,this.RENDERBUFFER,r._|0):this._gl.framebufferTexture2D(this.FRAMEBUFFER,n,this.TEXTURE_2D,0,0)}}bindBuffer(e,t){if(e===35345||e===35982||e===36662||e===36663){let n=t?t._|0:0;this._gl.bindBuffer(e,n);return}super.bindBuffer(e,t)}bindFramebuffer(e,t){if(e===36008||e===36009){if(!n(t))throw TypeError(`bindFramebuffer(GLenum, WebGLFramebuffer)`);if(t&&t._pendingDelete||t&&!this._checkWrapper(t,s))return;let r=t?t._|0:this._gtkFboId;if(this._gl.bindFramebuffer(e,r),e===36008){let e=this._activeReadFramebuffer;e!==t&&(e&&(--e._refCount,e._checkDelete()),t&&(t._refCount+=1)),this._activeReadFramebuffer=t}else{let e=this._activeDrawFramebuffer;e!==t&&(e&&(--e._refCount,e._checkDelete()),t&&(t._refCount+=1)),this._activeDrawFramebuffer=t,this._activeFramebuffer=t}return}super.bindFramebuffer(this.FRAMEBUFFER,t),this._activeReadFramebuffer=t,this._activeDrawFramebuffer=t}deleteFramebuffer(e){this._activeReadFramebuffer===e&&this.bindFramebuffer(36008,null),this._activeDrawFramebuffer===e&&this.bindFramebuffer(36009,null),super.deleteFramebuffer(e)}bufferData(n,r,i){let a=n===35345||n===35982||n===36662||n===36663,o=i===35041||i===35043||i===35045||i===35042||i===35044||i===35046?this.STATIC_DRAW:i;if(a){if(typeof r==`number`)r>=0&&this._gl.bufferDataSizeOnly(n,r,o);else if(typeof r==`object`&&r){let i=t(r);this._gl.bufferData(n,e(i),o)}return}super.bufferData(n,r,o)}bufferSubData(n,r,i){if(n===35345||n===35982||n===36662||n===36663){if(r<0){this.setError(this.INVALID_VALUE);return}if(!i){this.setError(this.INVALID_VALUE);return}let a=t(i);this._gl.bufferSubData(n,r,e(a));return}super.bufferSubData(n,r,i)}bindTexture(e,t){if(e===32879||e===35866){let n=t,r=n?n._|0:0;this._gl.bindTexture(e,r),n&&(n._binding=e);return}super.bindTexture(e,t)}texParameteri(e,t,n){if(e===32879||e===35866){this._gl.texParameteri(e,t,n);return}if(t===32882||t===34892||t===34893||t===33084||t===33085||t===33083||t===33082){this._gl.texParameteri(e,t,n);return}super.texParameteri(e,t,n)}drawArrays(e,t,n){if(t<0||n<0){this.setError(this.INVALID_VALUE);return}if(!this._checkStencilState())return;let r=o(this,e,n);if(r<0){this.setError(this.INVALID_ENUM);return}this._framebufferOk()&&n!==0&&this._checkVertexAttribState(n+t-1>>>0)&&this._native2.drawArrays(e,t,r)}drawElements(e=0,t=0,n=0,r=0){if(t<0||r<0){this.setError(this.INVALID_VALUE);return}if(!this._checkStencilState())return;let i=this._vertexObjectState._elementArrayBufferBinding;if(!i){this.setError(this.INVALID_OPERATION);return}let a=null,o=r;if(n===this.UNSIGNED_SHORT){if(o%2){this.setError(this.INVALID_OPERATION);return}o>>=1,a=new Uint16Array(i._elements.buffer)}else if(n===this.UNSIGNED_INT){if(o%4){this.setError(this.INVALID_OPERATION);return}o>>=2,a=new Uint32Array(i._elements.buffer)}else if(n===this.UNSIGNED_BYTE)a=i._elements;else{this.setError(this.INVALID_ENUM);return}let s=t;switch(e){case this.TRIANGLES:t%3&&(s-=t%3);break;case this.LINES:t%2&&(s-=t%2);break;case this.POINTS:break;case this.LINE_LOOP:case this.LINE_STRIP:if(t<2){this.setError(this.INVALID_OPERATION);return}break;case this.TRIANGLE_FAN:case this.TRIANGLE_STRIP:if(t<3){this.setError(this.INVALID_OPERATION);return}break;default:this.setError(this.INVALID_ENUM);return}if(!this._framebufferOk()||t===0)return;let c=0;for(let e=o;e<o+s;++e)e<a.length&&a[e]>c&&(c=a[e]);this._checkVertexAttribState(c)&&this._native2.drawElements(e,s,n,r)}bindBufferBase(e,t,n){this._native2.bindBufferBase(e,t,n?n._:0)}bindBufferRange(e,t,n,r,i){this._native2.bindBufferRange(e,t,n?n._:0,r,i)}copyBufferSubData(e,t,n,r,i){this._native2.copyBufferSubData(e,t,n,r,i)}getBufferSubData(e,t,n,r,i){let a=i===void 0?n.byteLength-(r??0):i,o=this._native2.getBufferSubData(e,t,a),s=new Uint8Array(n.buffer,n.byteOffset+(r??0)*(n instanceof Uint8Array?1:n.BYTES_PER_ELEMENT??1));s.set(o.subarray(0,s.byteLength))}texImage2D(t=0,n=0,o=0,s=0,c=0,l=0,u=0,d=0,f){let p=0,m=0,h=0,_=0;if(arguments.length===6)if(d=c,h=s,l instanceof g.Pixbuf){let e=l;p=e.get_width(),m=e.get_height(),f=e.get_pixels()}else{let e=i(l);if(e==null)throw TypeError(`texImage2D(GLenum, GLint, GLenum, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)`);p=e.width,m=e.height,f=e.data}else arguments.length>=9&&(p=s,m=c,_=l,h=u);let v=this._getTexImage(t);if(!v){this.setError(this.INVALID_OPERATION);return}let y=r(f);if(this._unpackPremultAlpha&&y&&h===this.RGBA&&(y=a(y)),this._unpackFlipY&&y&&p>0&&m>0){let e=this._computePixelSize(d,h);if(e>0){let t=this._computeRowStride(p,e),n=new Uint8Array(y.length);for(let e=0;e<m;e++){let r=e*t,i=(m-1-e)*t;n.set(y.subarray(r,r+t),i)}y=n}}this._saveError(),this._gl.texImage2D(t,n,o,p,m,_,h,d,e(y));let b=this.getError();if(this._restoreError(b),b!==this.NO_ERROR)return;v._levelWidth[n]=p,v._levelHeight[n]=m,v._format=h,v._type=d;let x=this._activeFramebuffer;if(x){let e=!1,t=this._getAttachments();for(let n=0;n<t.length;++n)if(x._attachments[t[n]]===v){e=!0;break}e&&this._activeFramebuffer&&this._updateFramebufferAttachments(this._activeFramebuffer)}}texSubImage2D(t=0,n=0,o=0,s=0,c=0,l=0,u=0,d=0,f){let p=0,m=0,h=0;if(arguments.length===7)if(d=l,h=c,u instanceof g.Pixbuf){let e=u;p=e.get_width(),m=e.get_height(),f=e.get_pixels()}else{let e=i(u);if(e==null)throw TypeError(`texSubImage2D(GLenum, GLint, GLint, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)`);p=e.width,m=e.height,f=e.data}else p=c,m=l,h=u;if(!this._getTexImage(t)){this.setError(this.INVALID_OPERATION);return}let _=r(f);if(!_){this.setError(this.INVALID_OPERATION);return}if(this._unpackPremultAlpha&&_&&h===this.RGBA&&(_=a(_)),this._unpackFlipY&&_&&p>0&&m>0){let e=this._computePixelSize(d,h);if(e>0){let t=this._computeRowStride(p,e),n=new Uint8Array(_.length);for(let e=0;e<m;e++){let r=e*t,i=(m-1-e)*t;n.set(_.subarray(r,r+t),i)}_=n}}this._gl.texSubImage2D(t,n,o,s,p,m,h,d,e(_))}getUniform(e,t){let n=t?._activeInfo?.type,r=5125,i=36294,a=36295,o=n===r||n===i||n===a||n===36296,s=e;if(!o)return super.getUniform(s,t);if(!e||!t)return null;let c=this._native2.getUniformi(s._|0,t._|0);return c?n===r?c[0]>>>0:n===i?new Uint32Array([c[0]>>>0,c[1]>>>0]):n===a?new Uint32Array([c[0]>>>0,c[1]>>>0,c[2]>>>0]):new Uint32Array([c[0]>>>0,c[1]>>>0,c[2]>>>0,c[3]>>>0]):null}getUniformBlockIndex(e,t){return this._native2.getUniformBlockIndex(e._,t)}uniformBlockBinding(e,t,n){this._native2.uniformBlockBinding(e._,t,n)}getActiveUniformBlockName(e,t){let n=this._native2.getActiveUniformBlockName(e._,t);return n.length>0?n:null}getActiveUniformBlockParameter(e,t,n){return this._native2.getActiveUniformBlockParameter(e._,t,n)}getActiveUniforms(e,t,n){return this._native2.getActiveUniforms(e._,t,n)}getFragDataLocation(e,t){return this._native2.getFragDataLocation(e._,t)}getIndexedParameter(e,t){return this._native2.getIndexedParameteri(e,t)}getInternalformatParameter(e,t,n){return this._native2.getInternalformatParameter(e,t,n)}getParameter(e){if(e===7938)return`WebGL 2.0`;if(e===35724)return`WebGL GLSL ES 3.00`;if(e===7939)return v(`WebGL2RenderingContext.getParameter(GL_EXTENSIONS)`),``;if(e===36006)return this._activeDrawFramebuffer;if(e===36010)return this._activeReadFramebuffer;switch(e){case 36183:case 35071:case 32883:case 36063:case 34852:case 36203:case 33001:case 33e3:case 37157:case 35373:case 35657:case 35077:case 35978:case 35979:case 35968:case 35376:case 35375:case 35659:case 37154:case 35371:case 35658:case 35379:case 35374:case 35377:case 35076:case 3330:case 3332:case 3331:case 35053:case 35055:case 3074:case 32874:case 35869:case 36389:case 35983:case 35368:case 35380:case 32878:case 3314:case 32877:case 3316:case 3315:case 34045:return this._native2.getParameterx(e)?.deepUnpack()|0;case 35977:case 36388:case 36387:return!!this._native2.getParameterx(e)?.deepUnpack()}return super.getParameter(e)}getStringi(e,t){let n=this._native2.getStringi(e,t);return n.length>0?n:null}renderbufferStorage(e,t,n,r){if(e!==this.RENDERBUFFER){this.setError(this.INVALID_ENUM);return}let i=this._activeRenderbuffer;if(!i){this.setError(this.INVALID_OPERATION);return}if(n<0||r<0){this.setError(this.INVALID_VALUE);return}for(;this._gl.getError()!==this.NO_ERROR;);if(this._gl.renderbufferStorage(e,t,n,r),this._gl.getError()!==this.NO_ERROR)return;i._width=n,i._height=r,i._format=t;let a=this._activeFramebuffer;if(a){let e=this._getAttachments(),t=!1;for(let n=0;n<e.length;++n)if(a._attachments[e[n]]===i){t=!0;break}t&&this._updateFramebufferAttachments(a)}}getSupportedExtensions(){let e=super.getSupportedExtensions();for(let t of[`EXT_color_buffer_float`,`EXT_color_buffer_half_float`,`OES_texture_half_float`])e.indexOf(t)===-1&&e.push(t);return e}readPixels(t,n,r,i,a,o,s){if(!s)return;if(r<0||i<0){this.setError(this.INVALID_VALUE);return}if(!this._framebufferOk())return;let c=a===6408||a===32856?4:a===6407?3:a===33319?2:1,l=o===5126?4:o===5131||o===36193?2:o===5125||o===5124?4:o===5123||o===5122?2:1,u=r*i*c*l,d=new Uint8Array(u);this._saveError();let f=this._gl.readPixels(t,n,r,i,a,o,e(d)),p=this.getError();if(this._restoreError(p),p!==this.NO_ERROR)return;let m=f&&f.length>0?f:d;if(s instanceof Uint8Array)s.set(m);else if(s instanceof Float32Array){let e=new Float32Array(m.buffer,0,s.length);s.set(e)}}_framebufferOk(){return!0}};d(y.prototype),f(y.prototype),p(y.prototype),m(y.prototype),h(y.prototype);export{y as WebGL2RenderingContext};
|
package/lib/esm/webgl2.spec.js
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
import{__name as e}from"./_virtual/_rolldown/runtime.js";import{TEXTURE_FS_300 as t,TEXTURE_VS_300 as n,destroyTestFBO as r,drawTriangle as i,makeProgram as a,makeTestFBO as o,makeTestFBOFloat as s,makeTestFBOWithDepthTexture as c,readPixel as l}from"./test-utils.js";import{beforeEach as u,describe as d,expect as f,it as p,on as m}from"@gjsify/unit";import{WebGL2RenderingContext as h,WebGLBridge as g}from"@gjsify/webgl";import _ from"@girs/glib-2.0";import v from"@girs/gtk-4.0";var y=e(async()=>{await m(`Display`,async()=>{v.init();let e,m,y=new _.MainLoop(null,!1),b=new v.Window({});b.set_default_size(200,200),e=new g,e.onReady((e,t)=>{m=e.getContext(`webgl2`),y.quit()}),b.set_child(e),b.present();let x=_.timeout_add(_.PRIORITY_DEFAULT,1e4,()=>(y.quit(),_.SOURCE_REMOVE));if(y.run(),_.source_remove(x),!m){console.warn(`WebGL2 context not available — skipping WebGL2 tests`),b.destroy();return}e.make_current(),await d(`WebGL2 context`,async()=>{u(async()=>{e.make_current()}),await p(`getContext("webgl2") returns a WebGL2RenderingContext`,async()=>{f(m).toBeInstanceOf(h)}),await p(`VERSION is "WebGL 2.0"`,async()=>{f(m.getParameter(m.VERSION)).toBe(`WebGL 2.0`)}),await p(`SHADING_LANGUAGE_VERSION is "WebGL GLSL ES 3.00"`,async()=>{f(m.getParameter(m.SHADING_LANGUAGE_VERSION)).toBe(`WebGL GLSL ES 3.00`)}),await p(`drawingBufferWidth and drawingBufferHeight are positive`,async()=>{f(m.drawingBufferWidth>0).toBeTruthy(),f(m.drawingBufferHeight>0).toBeTruthy()}),await p(`getError() returns NO_ERROR initially`,async()=>{f(m.getError()).toBe(m.NO_ERROR)})}),await d(`GLSL ES 3.00 compilation`,async()=>{u(async()=>{e.make_current()});let t=[`#version 300 es`,`in vec2 position;`,`void main() { gl_Position = vec4(position, 0.0, 1.0); }`].join(`
|
|
2
2
|
`),n=[`#version 300 es`,`precision mediump float;`,`out vec4 fragColor;`,`void main() { fragColor = vec4(0.0, 1.0, 0.0, 1.0); }`].join(`
|
|
3
|
-
`);await p(`#version 300 es vertex shader compiles`,async()=>{let e=m.createShader(m.VERTEX_SHADER);m.shaderSource(e,t),m.compileShader(e),m.getShaderParameter(e,m.COMPILE_STATUS)||console.error(`VS300 log:`,m.getShaderInfoLog(e)),f(m.getShaderParameter(e,m.COMPILE_STATUS)).toBeTruthy(),m.deleteShader(e)}),await p(`#version 300 es fragment shader compiles`,async()=>{let e=m.createShader(m.FRAGMENT_SHADER);m.shaderSource(e,n),m.compileShader(e),m.getShaderParameter(e,m.COMPILE_STATUS)||console.error(`FS300 log:`,m.getShaderInfoLog(e)),f(m.getShaderParameter(e,m.COMPILE_STATUS)).toBeTruthy(),m.deleteShader(e)}),await p(
|
|
3
|
+
`);await p(`#version 300 es vertex shader compiles`,async()=>{let e=m.createShader(m.VERTEX_SHADER);m.shaderSource(e,t),m.compileShader(e),m.getShaderParameter(e,m.COMPILE_STATUS)||console.error(`VS300 log:`,m.getShaderInfoLog(e)),f(m.getShaderParameter(e,m.COMPILE_STATUS)).toBeTruthy(),m.deleteShader(e)}),await p(`#version 300 es fragment shader compiles`,async()=>{let e=m.createShader(m.FRAGMENT_SHADER);m.shaderSource(e,n),m.compileShader(e),m.getShaderParameter(e,m.COMPILE_STATUS)||console.error(`FS300 log:`,m.getShaderInfoLog(e)),f(m.getShaderParameter(e,m.COMPILE_STATUS)).toBeTruthy(),m.deleteShader(e)}),await p(`leaves the source alone on a context that speaks GLSL ES 3.00`,async()=>{let e=m.createShader(m.VERTEX_SHADER);m.shaderSource(e,t);let n=m.getShaderSource(e)??``,r=n.split(`
|
|
4
|
+
`)[0].trim(),i=n.split(`
|
|
5
|
+
`).slice(1).join(`
|
|
6
|
+
`);f(r===`#version 300 es`||/^#version \d{3} core$/.test(r)).toBeTruthy(),f(i).toBe(t.split(`
|
|
7
|
+
`).slice(1).join(`
|
|
8
|
+
`)),m.deleteShader(e)}),await p(`compiles a VERSIONLESS GLSL1 shader — the injected #version must suit the profile`,async()=>{let e=[`attribute vec4 aPos;`,`varying vec2 vUv;`,`void main(){ vUv = aPos.xy; gl_Position = aPos; }`].join(`
|
|
9
|
+
`),t=m.createShader(m.VERTEX_SHADER);m.shaderSource(t,e),m.compileShader(t),m.getShaderParameter(t,m.COMPILE_STATUS)||(console.error(`versionless GLSL1 log:`,m.getShaderInfoLog(t)),console.error(`injected source:`,m.getShaderSource(t)?.split(`
|
|
10
|
+
`)[0])),f(m.getShaderParameter(t,m.COMPILE_STATUS)).toBeTruthy(),m.deleteShader(t)});for(let[e,t]of[[`gl_FragColor`,`void main(){ gl_FragColor = vec4(1.0); }`],[`gl_FragData`,`void main(){ gl_FragData[0] = vec4(1.0); }`],[`texture2D`,`uniform sampler2D uTex;
|
|
11
|
+
void main(){ gl_FragColor = texture2D(uTex, vec2(0.0)); }`],[`textureCube`,`uniform samplerCube uCube;
|
|
12
|
+
void main(){ gl_FragColor = textureCube(uCube, vec3(0.0)); }`]])await p(`treats a VERSIONLESS shader using ${e} as GLSL 1.0`,async()=>{let n=`precision mediump float;\n${t}`,r=m.createShader(m.FRAGMENT_SHADER);m.shaderSource(r,n),m.compileShader(r),m.getShaderParameter(r,m.COMPILE_STATUS)||(console.error(`versionless ${e} log:`,m.getShaderInfoLog(r)),console.error(`injected source:`,m.getShaderSource(r)?.split(`
|
|
13
|
+
`)[0])),f(m.getShaderParameter(r,m.COMPILE_STATUS)).toBeTruthy(),m.deleteShader(r)});await p(`keeps the gl_-prefixed preamble macro off a MODERN versionless shader`,async()=>{let e=[`precision mediump float;`,`out vec4 fragColor;`,`void main(){ fragColor = vec4(1.0); }`].join(`
|
|
14
|
+
`),t=m.createShader(m.FRAGMENT_SHADER);m.shaderSource(t,e),f((m.getShaderSource(t)??``).includes(`#define gl_MaxDrawBuffers`)).toBeFalsy(),m.compileShader(t),m.getShaderParameter(t,m.COMPILE_STATUS)||console.error(`versionless modern log:`,m.getShaderInfoLog(t)),f(m.getShaderParameter(t,m.COMPILE_STATUS)).toBeTruthy(),m.deleteShader(t)}),await p(`keeps a versionless ESSL3 shader modern when only a BUILT-IN says so`,async()=>{let e=[`uniform highp sampler2D uTex;`,`void main(){ gl_Position = texelFetch(uTex, ivec2(0), 0); }`].join(`
|
|
15
|
+
`),t=m.createShader(m.VERTEX_SHADER);m.shaderSource(t,e),m.compileShader(t),m.getShaderParameter(t,m.COMPILE_STATUS)||(console.error(`versionless texelFetch log:`,m.getShaderInfoLog(t)),console.error(`injected source:`,m.getShaderSource(t)?.split(`
|
|
16
|
+
`)[0])),f(m.getShaderParameter(t,m.COMPILE_STATUS)).toBeTruthy(),m.deleteShader(t)}),await p(`never rewrites a WebGL1 #version 100 shader`,async()=>{let e=[`#version 100`,`attribute vec4 aPos;`,`void main(){ gl_Position = aPos; }`].join(`
|
|
17
|
+
`),t=m.createShader(m.VERTEX_SHADER);m.shaderSource(t,e),f(m.getShaderSource(t)).toBe(e),m.deleteShader(t)}),await p(`#version 300 es program links and renders green`,async()=>{let e=a(m,t,n);m.getProgramParameter(e,m.LINK_STATUS)||console.error(`Program300 log:`,m.getProgramInfoLog(e)),f(m.getProgramParameter(e,m.LINK_STATUS)).toBeTruthy();let s=o(m,4,4);m.clearColor(0,0,0,1),m.clear(m.COLOR_BUFFER_BIT),m.useProgram(e),i(m),f(m.getError()).toBe(m.NO_ERROR);let c=l(m,0,0);r(m,s),f(c[0]).toBe(0),f(c[1]).toBe(255),f(c[2]).toBe(0),f(c[3]).toBe(255),m.deleteProgram(e)})}),await d(`VAO`,async()=>{u(async()=>{e.make_current()}),await p(`createVertexArray returns a non-null object`,async()=>{let e=m.createVertexArray();f(e).not.toBeNull(),f(e).toBeDefined(),m.deleteVertexArray(e)}),await p(`isVertexArray is true after creation, false after deletion`,async()=>{let e=m.createVertexArray();m.bindVertexArray(e),f(m.isVertexArray(e)).toBeTruthy(),m.bindVertexArray(null),m.deleteVertexArray(e),f(m.isVertexArray(e)).toBeFalsy()}),await p(`VAO preserves vertex attribute state`,async()=>{let e=[`#version 300 es`,`in vec2 position;`,`void main() { gl_Position = vec4(position,0.0,1.0); }`].join(`
|
|
4
18
|
`),t=[`#version 300 es`,`precision mediump float;`,`out vec4 c;`,`void main() { c = vec4(0.0,1.0,0.0,1.0); }`].join(`
|
|
5
19
|
`),n=a(m,e,t);m.useProgram(n);let i=o(m,4,4),s=m.createVertexArray();m.bindVertexArray(s);let c=m.createBuffer();m.bindBuffer(m.ARRAY_BUFFER,c),m.bufferData(m.ARRAY_BUFFER,new Float32Array([-2,-2,-2,4,4,-2]),m.STREAM_DRAW),m.enableVertexAttribArray(0),m.vertexAttribPointer(0,2,m.FLOAT,!1,0,0),m.bindVertexArray(null),m.bindVertexArray(s),m.clearColor(0,0,0,1),m.clear(m.COLOR_BUFFER_BIT),m.drawArrays(m.TRIANGLES,0,3),f(m.getError()).toBe(m.NO_ERROR);let u=l(m,0,0);r(m,i),f(u[1]).toBe(255),m.bindVertexArray(null),m.deleteVertexArray(s),m.deleteBuffer(c),m.deleteProgram(n)})}),await d(`getBufferSubData`,async()=>{u(async()=>{e.make_current()}),await p(`reads back float data written with bufferData`,async()=>{let e=new Float32Array([1,2,3,4]),t=m.createBuffer();m.bindBuffer(m.ARRAY_BUFFER,t),m.bufferData(m.ARRAY_BUFFER,e,m.STATIC_READ);let n=new Float32Array(4);m.getBufferSubData(m.ARRAY_BUFFER,0,n),f(m.getError()).toBe(m.NO_ERROR),f(n[0]).toBe(1),f(n[1]).toBe(2),f(n[2]).toBe(3),f(n[3]).toBe(4),m.deleteBuffer(t)}),await p(`reads a sub-range correctly`,async()=>{let e=new Float32Array([10,20,30,40]),t=m.createBuffer();m.bindBuffer(m.ARRAY_BUFFER,t),m.bufferData(m.ARRAY_BUFFER,e,m.STATIC_READ);let n=new Float32Array(2);m.getBufferSubData(m.ARRAY_BUFFER,8,n),f(n[0]).toBe(30),f(n[1]).toBe(40),m.deleteBuffer(t)})}),await d(`sync objects`,async()=>{u(async()=>{e.make_current()}),await p(`fenceSync returns a non-null sync`,async()=>{let e=m.fenceSync(m.SYNC_GPU_COMMANDS_COMPLETE,0);f(e).not.toBeNull(),m.deleteSync(e),f(m.getError()).toBe(m.NO_ERROR)}),await p(`isSync is true before deletion, false after`,async()=>{let e=m.fenceSync(m.SYNC_GPU_COMMANDS_COMPLETE,0);f(m.isSync(e)).toBeTruthy(),m.deleteSync(e),f(m.isSync(e)).toBeFalsy()}),await p(`clientWaitSync returns TIMEOUT_EXPIRED or CONDITION_SATISFIED`,async()=>{let e=m.fenceSync(m.SYNC_GPU_COMMANDS_COMPLETE,0);m.flush();let t=m.clientWaitSync(e,0,0);f(t===m.TIMEOUT_EXPIRED||t===m.CONDITION_SATISFIED||t===m.ALREADY_SIGNALED).toBeTruthy(),m.deleteSync(e)})}),await d(`uint uniforms`,async()=>{u(async()=>{e.make_current()});let t=[`#version 300 es`,`in vec2 position;`,`void main() { gl_Position = vec4(position,0.0,1.0); }`].join(`
|
|
6
20
|
`),n=[`#version 300 es`,`precision mediump float;`,`uniform uint uR; uniform uint uG; uniform uint uB;`,`out vec4 c;`,`void main() { c = vec4(float(uR)/255.0, float(uG)/255.0, float(uB)/255.0, 1.0); }`].join(`
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { WebGLContextBase } from '../webgl-context-base.js';
|
|
2
|
+
/**
|
|
3
|
+
* `WEBGL_debug_renderer_info` — the two `getParameter` pnames that return the
|
|
4
|
+
* UNMASKED driver strings instead of the spec's deliberately vague defaults.
|
|
5
|
+
*
|
|
6
|
+
* Browsers mask `VENDOR`/`RENDERER` for fingerprinting reasons and we match that
|
|
7
|
+
* (`RENDERER` answers `'ANGLE'`), so without this extension there is NO way for a
|
|
8
|
+
* consumer to learn which GL implementation it actually got. That mattered: a
|
|
9
|
+
* GPU-less host silently hands out a CPU rasteriser, every draw call still
|
|
10
|
+
* succeeds, and the only symptom is a frame budget 1000x over — indistinguishable
|
|
11
|
+
* from an application bug until someone reaches into the private native handle.
|
|
12
|
+
*
|
|
13
|
+
* The masking rationale does not apply here: a GJS/GTK app is not a web origin,
|
|
14
|
+
* so the extension is always available rather than gated on a permission.
|
|
15
|
+
*
|
|
16
|
+
* @see https://registry.khronos.org/webgl/extensions/WEBGL_debug_renderer_info/
|
|
17
|
+
*/
|
|
18
|
+
export declare class WEBGLDebugRendererInfo {
|
|
19
|
+
readonly UNMASKED_VENDOR_WEBGL = 37445;
|
|
20
|
+
readonly UNMASKED_RENDERER_WEBGL = 37446;
|
|
21
|
+
}
|
|
22
|
+
export declare function getWEBGLDebugRendererInfo(_context: WebGLContextBase): WEBGLDebugRendererInfo;
|
|
@@ -47,6 +47,23 @@ export declare class HTMLCanvasElement extends BaseHTMLCanvasElement {
|
|
|
47
47
|
get offsetHeight(): number;
|
|
48
48
|
/** Returns the underlying Gtk.GLArea. Used by WebGLRenderingContext for GLSL version detection. */
|
|
49
49
|
getGlArea(): Gtk.GLArea;
|
|
50
|
+
/**
|
|
51
|
+
* A copy of this canvas is a PLAIN, widget-less one.
|
|
52
|
+
*
|
|
53
|
+
* There is exactly one `Gtk.GLArea` and it stays with the original, so a
|
|
54
|
+
* clone cannot be GLArea-backed: the default `new this.constructor()` built
|
|
55
|
+
* one with `gtkGlArea === undefined`, and the first `width` read threw. That
|
|
56
|
+
* is not a hypothetical — it is how Excalibur switches renderers
|
|
57
|
+
* (`canvas.cloneNode(false)` → `replaceChild` → `getContext('2d')`), so the
|
|
58
|
+
* whole fallback died at the clone rather than degrading (gjsify#1107).
|
|
59
|
+
*
|
|
60
|
+
* A detached canvas is also what a browser hands back: same size, blank
|
|
61
|
+
* bitmap, no context, not presented by anything. Dropping to the DOM base
|
|
62
|
+
* class gives precisely that, including a writable `width`/`height` — the
|
|
63
|
+
* overrides above deliberately ignore writes because GTK owns the widget's
|
|
64
|
+
* size, and a clone has no widget to own it.
|
|
65
|
+
*/
|
|
66
|
+
protected _createCloneTarget(): BaseHTMLCanvasElement;
|
|
50
67
|
/**
|
|
51
68
|
* Returns a WebGL rendering context backed by the underlying Gtk.GLArea.
|
|
52
69
|
* 'webgl' and 'experimental-webgl' return a WebGLRenderingContext (WebGL 1.0).
|
package/lib/types/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import '@girs/gjs';
|
|
|
2
2
|
import '@girs/gio-2.0';
|
|
3
3
|
import '@girs/gtk-4.0';
|
|
4
4
|
export * from './html-canvas-element.js';
|
|
5
|
+
export * from './software-renderer.js';
|
|
5
6
|
export * from './webgl-bridge.js';
|
|
6
7
|
export * from './webgl-active-info.js';
|
|
7
8
|
export * from './webgl-buffer.js';
|
|
@@ -35,3 +36,4 @@ export * from './extensions/oes-texture-float.js';
|
|
|
35
36
|
export * from './extensions/oes-texture-half-float.js';
|
|
36
37
|
export * from './extensions/stackgl-destroy-context.js';
|
|
37
38
|
export * from './extensions/stackgl-resize-drawing-buffer.js';
|
|
39
|
+
export * from './extensions/webgl-debug-renderer-info.js';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* True when `renderer` names a GL implementation that rasterises on the CPU.
|
|
3
|
+
*
|
|
4
|
+
* This is a DIAGNOSTIC, not a capability check, and deliberately so: a software
|
|
5
|
+
* renderer is not by itself a reason to change behaviour. Measured on one
|
|
6
|
+
* GPU-less macOS host, the same `Apple Software Renderer` draws a demand-driven
|
|
7
|
+
* three.js scene and a flat-shaded full-screen quad without trouble (1.2 ms per
|
|
8
|
+
* frame) while a continuously animating, fill-heavy 2D game needs 1.1 s for a
|
|
9
|
+
* single textured full-screen draw. What separates them is the workload, not the
|
|
10
|
+
* driver — so key any fallback on a MEASURED frame budget and use this only to
|
|
11
|
+
* name the cause.
|
|
12
|
+
*
|
|
13
|
+
* @param renderer The unmasked `RENDERER` string, e.g. from
|
|
14
|
+
* `gl.getParameter(gl.getExtension('WEBGL_debug_renderer_info').UNMASKED_RENDERER_WEBGL)`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isSoftwareRenderer(renderer: string | null | undefined): boolean;
|
|
@@ -3,6 +3,7 @@ import Gdk from 'gi://Gdk?version=4.0';
|
|
|
3
3
|
import GLib from 'gi://GLib?version=2.0';
|
|
4
4
|
import Gtk from 'gi://Gtk?version=4.0';
|
|
5
5
|
import { HTMLCanvasElement as OurHTMLCanvasElement } from './html-canvas-element.js';
|
|
6
|
+
import { WebGLRenderingContext as OurWebGLRenderingContext } from './webgl-rendering-context.js';
|
|
6
7
|
type WebGLReadyCallback = (canvas: globalThis.HTMLCanvasElement, gl: globalThis.WebGLRenderingContext) => void;
|
|
7
8
|
/**
|
|
8
9
|
* A `Gtk.GLArea` subclass that handles WebGL bootstrapping:
|
|
@@ -38,8 +39,26 @@ export declare const WebGLBridge: {
|
|
|
38
39
|
_frameCallbackId: number;
|
|
39
40
|
_nextFrameId: number;
|
|
40
41
|
_timeOrigin: number;
|
|
42
|
+
_rendererInfo: {
|
|
43
|
+
vendor: string;
|
|
44
|
+
renderer: string;
|
|
45
|
+
} | null;
|
|
41
46
|
/** The HTMLCanvasElement wrapping this GLArea. Available after the first render. */
|
|
42
47
|
get canvas(): globalThis.HTMLCanvasElement | null;
|
|
48
|
+
/**
|
|
49
|
+
* The GL implementation GDK negotiated, unmasked — `{vendor, renderer}`
|
|
50
|
+
* straight from `glGetString`, e.g. `Apple Software Renderer`. `null`
|
|
51
|
+
* until the context exists (i.e. before the first `onReady`).
|
|
52
|
+
*
|
|
53
|
+
* Read it to REPORT what a host provides. It is not a capability check:
|
|
54
|
+
* a CPU rasteriser draws everything a GPU does, only slower, and how much
|
|
55
|
+
* slower depends entirely on the workload. Anything that switches
|
|
56
|
+
* renderers should key on a measured frame budget, not on this string.
|
|
57
|
+
*/
|
|
58
|
+
get rendererInfo(): {
|
|
59
|
+
vendor: string;
|
|
60
|
+
renderer: string;
|
|
61
|
+
} | null;
|
|
43
62
|
/**
|
|
44
63
|
* Registers a callback to be called once the WebGL context is ready.
|
|
45
64
|
* If the context is already available, the callback fires synchronously.
|
|
@@ -49,6 +68,24 @@ export declare const WebGLBridge: {
|
|
|
49
68
|
* @deprecated Use `onReady()` instead.
|
|
50
69
|
*/
|
|
51
70
|
onWebGLReady(cb: WebGLReadyCallback): void;
|
|
71
|
+
/**
|
|
72
|
+
* Records the negotiated GL implementation and, when it rasterises on the
|
|
73
|
+
* CPU, says so ONCE on stderr.
|
|
74
|
+
*
|
|
75
|
+
* A GPU-less host is invisible from inside the app: context creation
|
|
76
|
+
* succeeds, every draw call succeeds, nothing rejects, and the only tell
|
|
77
|
+
* is a frame budget blown by three orders of magnitude — which presents as
|
|
78
|
+
* a window that sits there. Naming the renderer at the one place that
|
|
79
|
+
* knows it turns that into a line anyone can act on, for every consumer,
|
|
80
|
+
* without any of them asking.
|
|
81
|
+
*
|
|
82
|
+
* Diagnostic only: it changes no behaviour, because a software renderer is
|
|
83
|
+
* fine for plenty of workloads (measured on one GPU-less macOS host: a
|
|
84
|
+
* demand-driven three.js scene and a flat-shaded full-screen quad both run
|
|
85
|
+
* comfortably on the same driver that needs 1.1 s for one textured
|
|
86
|
+
* full-screen draw in a 2D game).
|
|
87
|
+
*/
|
|
88
|
+
_reportRenderer(gl: OurWebGLRenderingContext): void;
|
|
52
89
|
/**
|
|
53
90
|
* Register a callback invoked whenever the GTK widget is resized.
|
|
54
91
|
* The callback fires alongside the native 'resize' GObject signal and
|
|
@@ -533,8 +570,26 @@ export declare const WebGLBridge: {
|
|
|
533
570
|
_frameCallbackId: number;
|
|
534
571
|
_nextFrameId: number;
|
|
535
572
|
_timeOrigin: number;
|
|
573
|
+
_rendererInfo: {
|
|
574
|
+
vendor: string;
|
|
575
|
+
renderer: string;
|
|
576
|
+
} | null;
|
|
536
577
|
/** The HTMLCanvasElement wrapping this GLArea. Available after the first render. */
|
|
537
578
|
get canvas(): globalThis.HTMLCanvasElement | null;
|
|
579
|
+
/**
|
|
580
|
+
* The GL implementation GDK negotiated, unmasked — `{vendor, renderer}`
|
|
581
|
+
* straight from `glGetString`, e.g. `Apple Software Renderer`. `null`
|
|
582
|
+
* until the context exists (i.e. before the first `onReady`).
|
|
583
|
+
*
|
|
584
|
+
* Read it to REPORT what a host provides. It is not a capability check:
|
|
585
|
+
* a CPU rasteriser draws everything a GPU does, only slower, and how much
|
|
586
|
+
* slower depends entirely on the workload. Anything that switches
|
|
587
|
+
* renderers should key on a measured frame budget, not on this string.
|
|
588
|
+
*/
|
|
589
|
+
get rendererInfo(): {
|
|
590
|
+
vendor: string;
|
|
591
|
+
renderer: string;
|
|
592
|
+
} | null;
|
|
538
593
|
/**
|
|
539
594
|
* Registers a callback to be called once the WebGL context is ready.
|
|
540
595
|
* If the context is already available, the callback fires synchronously.
|
|
@@ -544,6 +599,24 @@ export declare const WebGLBridge: {
|
|
|
544
599
|
* @deprecated Use `onReady()` instead.
|
|
545
600
|
*/
|
|
546
601
|
onWebGLReady(cb: WebGLReadyCallback): void;
|
|
602
|
+
/**
|
|
603
|
+
* Records the negotiated GL implementation and, when it rasterises on the
|
|
604
|
+
* CPU, says so ONCE on stderr.
|
|
605
|
+
*
|
|
606
|
+
* A GPU-less host is invisible from inside the app: context creation
|
|
607
|
+
* succeeds, every draw call succeeds, nothing rejects, and the only tell
|
|
608
|
+
* is a frame budget blown by three orders of magnitude — which presents as
|
|
609
|
+
* a window that sits there. Naming the renderer at the one place that
|
|
610
|
+
* knows it turns that into a line anyone can act on, for every consumer,
|
|
611
|
+
* without any of them asking.
|
|
612
|
+
*
|
|
613
|
+
* Diagnostic only: it changes no behaviour, because a software renderer is
|
|
614
|
+
* fine for plenty of workloads (measured on one GPU-less macOS host: a
|
|
615
|
+
* demand-driven three.js scene and a flat-shaded full-screen quad both run
|
|
616
|
+
* comfortably on the same driver that needs 1.1 s for one textured
|
|
617
|
+
* full-screen draw in a 2D game).
|
|
618
|
+
*/
|
|
619
|
+
_reportRenderer(gl: OurWebGLRenderingContext): void;
|
|
547
620
|
/**
|
|
548
621
|
* Register a callback invoked whenever the GTK widget is resized.
|
|
549
622
|
* The callback fires alongside the native 'resize' GObject signal and
|
|
@@ -1028,8 +1101,26 @@ export declare const WebGLBridge: {
|
|
|
1028
1101
|
_frameCallbackId: number;
|
|
1029
1102
|
_nextFrameId: number;
|
|
1030
1103
|
_timeOrigin: number;
|
|
1104
|
+
_rendererInfo: {
|
|
1105
|
+
vendor: string;
|
|
1106
|
+
renderer: string;
|
|
1107
|
+
} | null;
|
|
1031
1108
|
/** The HTMLCanvasElement wrapping this GLArea. Available after the first render. */
|
|
1032
1109
|
get canvas(): globalThis.HTMLCanvasElement | null;
|
|
1110
|
+
/**
|
|
1111
|
+
* The GL implementation GDK negotiated, unmasked — `{vendor, renderer}`
|
|
1112
|
+
* straight from `glGetString`, e.g. `Apple Software Renderer`. `null`
|
|
1113
|
+
* until the context exists (i.e. before the first `onReady`).
|
|
1114
|
+
*
|
|
1115
|
+
* Read it to REPORT what a host provides. It is not a capability check:
|
|
1116
|
+
* a CPU rasteriser draws everything a GPU does, only slower, and how much
|
|
1117
|
+
* slower depends entirely on the workload. Anything that switches
|
|
1118
|
+
* renderers should key on a measured frame budget, not on this string.
|
|
1119
|
+
*/
|
|
1120
|
+
get rendererInfo(): {
|
|
1121
|
+
vendor: string;
|
|
1122
|
+
renderer: string;
|
|
1123
|
+
} | null;
|
|
1033
1124
|
/**
|
|
1034
1125
|
* Registers a callback to be called once the WebGL context is ready.
|
|
1035
1126
|
* If the context is already available, the callback fires synchronously.
|
|
@@ -1039,6 +1130,24 @@ export declare const WebGLBridge: {
|
|
|
1039
1130
|
* @deprecated Use `onReady()` instead.
|
|
1040
1131
|
*/
|
|
1041
1132
|
onWebGLReady(cb: WebGLReadyCallback): void;
|
|
1133
|
+
/**
|
|
1134
|
+
* Records the negotiated GL implementation and, when it rasterises on the
|
|
1135
|
+
* CPU, says so ONCE on stderr.
|
|
1136
|
+
*
|
|
1137
|
+
* A GPU-less host is invisible from inside the app: context creation
|
|
1138
|
+
* succeeds, every draw call succeeds, nothing rejects, and the only tell
|
|
1139
|
+
* is a frame budget blown by three orders of magnitude — which presents as
|
|
1140
|
+
* a window that sits there. Naming the renderer at the one place that
|
|
1141
|
+
* knows it turns that into a line anyone can act on, for every consumer,
|
|
1142
|
+
* without any of them asking.
|
|
1143
|
+
*
|
|
1144
|
+
* Diagnostic only: it changes no behaviour, because a software renderer is
|
|
1145
|
+
* fine for plenty of workloads (measured on one GPU-less macOS host: a
|
|
1146
|
+
* demand-driven three.js scene and a flat-shaded full-screen quad both run
|
|
1147
|
+
* comfortably on the same driver that needs 1.1 s for one textured
|
|
1148
|
+
* full-screen draw in a 2D game).
|
|
1149
|
+
*/
|
|
1150
|
+
_reportRenderer(gl: OurWebGLRenderingContext): void;
|
|
1042
1151
|
/**
|
|
1043
1152
|
* Register a callback invoked whenever the GTK widget is resized.
|
|
1044
1153
|
* The callback fires alongside the native 'resize' GObject signal and
|
|
@@ -1523,8 +1632,26 @@ export declare const WebGLBridge: {
|
|
|
1523
1632
|
_frameCallbackId: number;
|
|
1524
1633
|
_nextFrameId: number;
|
|
1525
1634
|
_timeOrigin: number;
|
|
1635
|
+
_rendererInfo: {
|
|
1636
|
+
vendor: string;
|
|
1637
|
+
renderer: string;
|
|
1638
|
+
} | null;
|
|
1526
1639
|
/** The HTMLCanvasElement wrapping this GLArea. Available after the first render. */
|
|
1527
1640
|
get canvas(): globalThis.HTMLCanvasElement | null;
|
|
1641
|
+
/**
|
|
1642
|
+
* The GL implementation GDK negotiated, unmasked — `{vendor, renderer}`
|
|
1643
|
+
* straight from `glGetString`, e.g. `Apple Software Renderer`. `null`
|
|
1644
|
+
* until the context exists (i.e. before the first `onReady`).
|
|
1645
|
+
*
|
|
1646
|
+
* Read it to REPORT what a host provides. It is not a capability check:
|
|
1647
|
+
* a CPU rasteriser draws everything a GPU does, only slower, and how much
|
|
1648
|
+
* slower depends entirely on the workload. Anything that switches
|
|
1649
|
+
* renderers should key on a measured frame budget, not on this string.
|
|
1650
|
+
*/
|
|
1651
|
+
get rendererInfo(): {
|
|
1652
|
+
vendor: string;
|
|
1653
|
+
renderer: string;
|
|
1654
|
+
} | null;
|
|
1528
1655
|
/**
|
|
1529
1656
|
* Registers a callback to be called once the WebGL context is ready.
|
|
1530
1657
|
* If the context is already available, the callback fires synchronously.
|
|
@@ -1534,6 +1661,24 @@ export declare const WebGLBridge: {
|
|
|
1534
1661
|
* @deprecated Use `onReady()` instead.
|
|
1535
1662
|
*/
|
|
1536
1663
|
onWebGLReady(cb: WebGLReadyCallback): void;
|
|
1664
|
+
/**
|
|
1665
|
+
* Records the negotiated GL implementation and, when it rasterises on the
|
|
1666
|
+
* CPU, says so ONCE on stderr.
|
|
1667
|
+
*
|
|
1668
|
+
* A GPU-less host is invisible from inside the app: context creation
|
|
1669
|
+
* succeeds, every draw call succeeds, nothing rejects, and the only tell
|
|
1670
|
+
* is a frame budget blown by three orders of magnitude — which presents as
|
|
1671
|
+
* a window that sits there. Naming the renderer at the one place that
|
|
1672
|
+
* knows it turns that into a line anyone can act on, for every consumer,
|
|
1673
|
+
* without any of them asking.
|
|
1674
|
+
*
|
|
1675
|
+
* Diagnostic only: it changes no behaviour, because a software renderer is
|
|
1676
|
+
* fine for plenty of workloads (measured on one GPU-less macOS host: a
|
|
1677
|
+
* demand-driven three.js scene and a flat-shaded full-screen quad both run
|
|
1678
|
+
* comfortably on the same driver that needs 1.1 s for one textured
|
|
1679
|
+
* full-screen draw in a 2D game).
|
|
1680
|
+
*/
|
|
1681
|
+
_reportRenderer(gl: OurWebGLRenderingContext): void;
|
|
1537
1682
|
/**
|
|
1538
1683
|
* Register a callback invoked whenever the GTK widget is resized.
|
|
1539
1684
|
* The callback fires alongside the native 'resize' GObject signal and
|
|
@@ -2018,8 +2163,26 @@ export declare const WebGLBridge: {
|
|
|
2018
2163
|
_frameCallbackId: number;
|
|
2019
2164
|
_nextFrameId: number;
|
|
2020
2165
|
_timeOrigin: number;
|
|
2166
|
+
_rendererInfo: {
|
|
2167
|
+
vendor: string;
|
|
2168
|
+
renderer: string;
|
|
2169
|
+
} | null;
|
|
2021
2170
|
/** The HTMLCanvasElement wrapping this GLArea. Available after the first render. */
|
|
2022
2171
|
get canvas(): globalThis.HTMLCanvasElement | null;
|
|
2172
|
+
/**
|
|
2173
|
+
* The GL implementation GDK negotiated, unmasked — `{vendor, renderer}`
|
|
2174
|
+
* straight from `glGetString`, e.g. `Apple Software Renderer`. `null`
|
|
2175
|
+
* until the context exists (i.e. before the first `onReady`).
|
|
2176
|
+
*
|
|
2177
|
+
* Read it to REPORT what a host provides. It is not a capability check:
|
|
2178
|
+
* a CPU rasteriser draws everything a GPU does, only slower, and how much
|
|
2179
|
+
* slower depends entirely on the workload. Anything that switches
|
|
2180
|
+
* renderers should key on a measured frame budget, not on this string.
|
|
2181
|
+
*/
|
|
2182
|
+
get rendererInfo(): {
|
|
2183
|
+
vendor: string;
|
|
2184
|
+
renderer: string;
|
|
2185
|
+
} | null;
|
|
2023
2186
|
/**
|
|
2024
2187
|
* Registers a callback to be called once the WebGL context is ready.
|
|
2025
2188
|
* If the context is already available, the callback fires synchronously.
|
|
@@ -2029,6 +2192,24 @@ export declare const WebGLBridge: {
|
|
|
2029
2192
|
* @deprecated Use `onReady()` instead.
|
|
2030
2193
|
*/
|
|
2031
2194
|
onWebGLReady(cb: WebGLReadyCallback): void;
|
|
2195
|
+
/**
|
|
2196
|
+
* Records the negotiated GL implementation and, when it rasterises on the
|
|
2197
|
+
* CPU, says so ONCE on stderr.
|
|
2198
|
+
*
|
|
2199
|
+
* A GPU-less host is invisible from inside the app: context creation
|
|
2200
|
+
* succeeds, every draw call succeeds, nothing rejects, and the only tell
|
|
2201
|
+
* is a frame budget blown by three orders of magnitude — which presents as
|
|
2202
|
+
* a window that sits there. Naming the renderer at the one place that
|
|
2203
|
+
* knows it turns that into a line anyone can act on, for every consumer,
|
|
2204
|
+
* without any of them asking.
|
|
2205
|
+
*
|
|
2206
|
+
* Diagnostic only: it changes no behaviour, because a software renderer is
|
|
2207
|
+
* fine for plenty of workloads (measured on one GPU-less macOS host: a
|
|
2208
|
+
* demand-driven three.js scene and a flat-shaded full-screen quad both run
|
|
2209
|
+
* comfortably on the same driver that needs 1.1 s for one textured
|
|
2210
|
+
* full-screen draw in a 2D game).
|
|
2211
|
+
*/
|
|
2212
|
+
_reportRenderer(gl: OurWebGLRenderingContext): void;
|
|
2032
2213
|
/**
|
|
2033
2214
|
* Register a callback invoked whenever the GTK widget is resized.
|
|
2034
2215
|
* The callback fires alongside the native 'resize' GObject signal and
|
|
@@ -2513,8 +2694,26 @@ export declare const WebGLBridge: {
|
|
|
2513
2694
|
_frameCallbackId: number;
|
|
2514
2695
|
_nextFrameId: number;
|
|
2515
2696
|
_timeOrigin: number;
|
|
2697
|
+
_rendererInfo: {
|
|
2698
|
+
vendor: string;
|
|
2699
|
+
renderer: string;
|
|
2700
|
+
} | null;
|
|
2516
2701
|
/** The HTMLCanvasElement wrapping this GLArea. Available after the first render. */
|
|
2517
2702
|
get canvas(): globalThis.HTMLCanvasElement | null;
|
|
2703
|
+
/**
|
|
2704
|
+
* The GL implementation GDK negotiated, unmasked — `{vendor, renderer}`
|
|
2705
|
+
* straight from `glGetString`, e.g. `Apple Software Renderer`. `null`
|
|
2706
|
+
* until the context exists (i.e. before the first `onReady`).
|
|
2707
|
+
*
|
|
2708
|
+
* Read it to REPORT what a host provides. It is not a capability check:
|
|
2709
|
+
* a CPU rasteriser draws everything a GPU does, only slower, and how much
|
|
2710
|
+
* slower depends entirely on the workload. Anything that switches
|
|
2711
|
+
* renderers should key on a measured frame budget, not on this string.
|
|
2712
|
+
*/
|
|
2713
|
+
get rendererInfo(): {
|
|
2714
|
+
vendor: string;
|
|
2715
|
+
renderer: string;
|
|
2716
|
+
} | null;
|
|
2518
2717
|
/**
|
|
2519
2718
|
* Registers a callback to be called once the WebGL context is ready.
|
|
2520
2719
|
* If the context is already available, the callback fires synchronously.
|
|
@@ -2524,6 +2723,24 @@ export declare const WebGLBridge: {
|
|
|
2524
2723
|
* @deprecated Use `onReady()` instead.
|
|
2525
2724
|
*/
|
|
2526
2725
|
onWebGLReady(cb: WebGLReadyCallback): void;
|
|
2726
|
+
/**
|
|
2727
|
+
* Records the negotiated GL implementation and, when it rasterises on the
|
|
2728
|
+
* CPU, says so ONCE on stderr.
|
|
2729
|
+
*
|
|
2730
|
+
* A GPU-less host is invisible from inside the app: context creation
|
|
2731
|
+
* succeeds, every draw call succeeds, nothing rejects, and the only tell
|
|
2732
|
+
* is a frame budget blown by three orders of magnitude — which presents as
|
|
2733
|
+
* a window that sits there. Naming the renderer at the one place that
|
|
2734
|
+
* knows it turns that into a line anyone can act on, for every consumer,
|
|
2735
|
+
* without any of them asking.
|
|
2736
|
+
*
|
|
2737
|
+
* Diagnostic only: it changes no behaviour, because a software renderer is
|
|
2738
|
+
* fine for plenty of workloads (measured on one GPU-less macOS host: a
|
|
2739
|
+
* demand-driven three.js scene and a flat-shaded full-screen quad both run
|
|
2740
|
+
* comfortably on the same driver that needs 1.1 s for one textured
|
|
2741
|
+
* full-screen draw in a 2D game).
|
|
2742
|
+
*/
|
|
2743
|
+
_reportRenderer(gl: OurWebGLRenderingContext): void;
|
|
2527
2744
|
/**
|
|
2528
2745
|
* Register a callback invoked whenever the GTK widget is resized.
|
|
2529
2746
|
* The callback fires alongside the native 'resize' GObject signal and
|
|
@@ -92,6 +92,53 @@ export declare abstract class WebGLContextBase {
|
|
|
92
92
|
protected _init(): void;
|
|
93
93
|
_initGLConstants(): void;
|
|
94
94
|
_getGlslVersion(es: boolean): string;
|
|
95
|
+
/**
|
|
96
|
+
* The `#version` a GLSL ES 1.00-SHAPED shader must carry — the dialect with
|
|
97
|
+
* `attribute`, `varying` and `gl_FragColor`. Deliberately NOT overridden by
|
|
98
|
+
* the WebGL2 context: such a source stays GLSL1 wherever it appears.
|
|
99
|
+
*
|
|
100
|
+
* On a desktop context the answer used to be an unconditional `'120'`, and
|
|
101
|
+
* desktop GLSL 1.20 is a COMPATIBILITY-profile dialect. A core profile
|
|
102
|
+
* rejects the directive outright — `version '120' is not supported`, then
|
|
103
|
+
* `#version required and missing`, then a syntax error on the first
|
|
104
|
+
* `varying` — so every versionless shader died on macOS, which is the one
|
|
105
|
+
* platform that gets a core profile. Measured on the
|
|
106
|
+
* `three-postprocessing-pixel` showcase: its fourteen GLSL ES 3.00 shaders
|
|
107
|
+
* compiled and its two versionless ones did not, leaving the scene black
|
|
108
|
+
* behind a fully-drawn Adwaita window.
|
|
109
|
+
*
|
|
110
|
+
* `'100'` is the right answer rather than a workaround: it is the dialect
|
|
111
|
+
* the source is actually written in, and `ARB_ES2_compatibility` — CORE FROM
|
|
112
|
+
* GL 4.1 — is precisely the extension that makes a desktop compiler accept
|
|
113
|
+
* it. Measured on macOS 15.7.9 / GL 4.1 core, GLSL1-shaped body:
|
|
114
|
+
* `100` OK, `110` FAIL, `120` FAIL.
|
|
115
|
+
*
|
|
116
|
+
* The version gate keeps the old answer where nothing better exists: below
|
|
117
|
+
* GL 4.1 there is no `ARB_ES2_compatibility`, and such a context can only be
|
|
118
|
+
* a compatibility profile anyway — which is exactly where `120` works.
|
|
119
|
+
*/
|
|
120
|
+
_getGlsl1Version(es: boolean): string;
|
|
121
|
+
/**
|
|
122
|
+
* The `#version` token of the context's OWN desktop GLSL — `'410'` for
|
|
123
|
+
* GLSL 4.10 — for a versionless shader written in the MODERN dialect
|
|
124
|
+
* (`in`/`out`, no `gl_FragColor`).
|
|
125
|
+
*
|
|
126
|
+
* Derived rather than a hand-picked floor, because the driver's own version
|
|
127
|
+
* is by construction one it accepts, and on any context that can be a core
|
|
128
|
+
* profile it is ≥ 1.40 — which is the whole requirement. Falls back to
|
|
129
|
+
* `'130'` where no version can be read, the pre-core case the previous
|
|
130
|
+
* hardcoded literal was right about.
|
|
131
|
+
*/
|
|
132
|
+
protected _desktopGlslVersion(): string;
|
|
133
|
+
/**
|
|
134
|
+
* Is the RAW GL version at least `major.minor`, on a DESKTOP context?
|
|
135
|
+
*
|
|
136
|
+
* False for GLES, whose versions answer a different question entirely.
|
|
137
|
+
* Read off `glGetString(GL_VERSION)` rather than `getParameter(VERSION)`,
|
|
138
|
+
* which this class answers with the WebGL spelling (`"WebGL 1.0 …"`) and so
|
|
139
|
+
* cannot be parsed for a driver version.
|
|
140
|
+
*/
|
|
141
|
+
protected _atLeastGlVersion(major: number, minor: number): boolean;
|
|
95
142
|
_checkOwns(object: unknown): boolean;
|
|
96
143
|
_checkValid(object: unknown, Type: {
|
|
97
144
|
new (...args: unknown[]): unknown;
|
|
@@ -21,6 +21,20 @@ export declare class WebGL2RenderingContext extends WebGLContextBase implements
|
|
|
21
21
|
_activeReadFramebuffer: WebGLFramebuffer | null;
|
|
22
22
|
_activeDrawFramebuffer: WebGLFramebuffer | null;
|
|
23
23
|
constructor(canvas: HTMLCanvasElement | null, options?: Partial<Gwebgl.WebGL2RenderingContext.ConstructorProps>);
|
|
24
|
+
/**
|
|
25
|
+
* `'130'` here was the same defect as the base class's `'120'`, and equally
|
|
26
|
+
* unmeasured: measured on macOS 15.7.9 / GL 4.1 core with a modern (`out`)
|
|
27
|
+
* body, `#version 130` FAILS while `140`, `150` and `410 core` compile — a
|
|
28
|
+
* core profile supports 1.40 upwards and nothing below. So a versionless
|
|
29
|
+
* modern shader was uncompilable there for exactly the reason a versionless
|
|
30
|
+
* GLSL1 one was.
|
|
31
|
+
*
|
|
32
|
+
* The context's OWN GLSL version is the answer, not a floor picked by hand:
|
|
33
|
+
* it is by construction the highest the compiler accepts, and on any context
|
|
34
|
+
* that can be core it is ≥ 1.40. `_desktopGlslVersion()` falls back to `130`
|
|
35
|
+
* only where it cannot read one, which is the pre-core case the old literal
|
|
36
|
+
* was right about.
|
|
37
|
+
*/
|
|
24
38
|
_getGlslVersion(es: boolean): string;
|
|
25
39
|
/**
|
|
26
40
|
* WebGL2 delegates framebuffer completeness to the native GL driver.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/webgl",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.35.0",
|
|
4
4
|
"description": "WebGL module for Gjs",
|
|
5
5
|
"module": "lib/esm/index.js",
|
|
6
6
|
"types": "lib/types/index.d.ts",
|
|
@@ -60,8 +60,8 @@
|
|
|
60
60
|
"WebGL"
|
|
61
61
|
],
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@gjsify/cli": "^0.
|
|
64
|
-
"@gjsify/unit": "^0.
|
|
63
|
+
"@gjsify/cli": "^0.35.0",
|
|
64
|
+
"@gjsify/unit": "^0.35.0",
|
|
65
65
|
"@types/bit-twiddle": "^1.0.3",
|
|
66
66
|
"@types/node": "^25.9.2",
|
|
67
67
|
"typescript": "^6.0.3"
|
|
@@ -71,10 +71,10 @@
|
|
|
71
71
|
"@girs/gjs": "^4.1.0",
|
|
72
72
|
"@girs/gtk-4.0": "^4.1.0",
|
|
73
73
|
"@girs/gwebgl-0.1": "0.1.0-4.0.0-rc.5",
|
|
74
|
-
"@gjsify/dom-elements": "^0.
|
|
75
|
-
"@gjsify/dom-events": "^0.
|
|
76
|
-
"@gjsify/event-bridge": "^0.
|
|
77
|
-
"@gjsify/utils": "^0.
|
|
74
|
+
"@gjsify/dom-elements": "^0.35.0",
|
|
75
|
+
"@gjsify/dom-events": "^0.35.0",
|
|
76
|
+
"@gjsify/event-bridge": "^0.35.0",
|
|
77
|
+
"@gjsify/utils": "^0.35.0",
|
|
78
78
|
"bit-twiddle": "^1.0.2",
|
|
79
79
|
"glsl-tokenizer": "^2.1.5"
|
|
80
80
|
},
|
|
@@ -89,12 +89,12 @@
|
|
|
89
89
|
},
|
|
90
90
|
"homepage": "https://github.com/gjsify/gjsify/tree/main/packages/framework/webgl#readme",
|
|
91
91
|
"optionalDependencies": {
|
|
92
|
-
"@gjsify/webgl-darwin-arm64": "0.
|
|
93
|
-
"@gjsify/webgl-darwin-x64": "0.
|
|
94
|
-
"@gjsify/webgl-linux-arm64": "0.
|
|
95
|
-
"@gjsify/webgl-linux-ppc64": "0.
|
|
96
|
-
"@gjsify/webgl-linux-riscv64": "0.
|
|
97
|
-
"@gjsify/webgl-linux-s390x": "0.
|
|
98
|
-
"@gjsify/webgl-linux-x64": "0.
|
|
92
|
+
"@gjsify/webgl-darwin-arm64": "0.35.0",
|
|
93
|
+
"@gjsify/webgl-darwin-x64": "0.35.0",
|
|
94
|
+
"@gjsify/webgl-linux-arm64": "0.35.0",
|
|
95
|
+
"@gjsify/webgl-linux-ppc64": "0.35.0",
|
|
96
|
+
"@gjsify/webgl-linux-riscv64": "0.35.0",
|
|
97
|
+
"@gjsify/webgl-linux-s390x": "0.35.0",
|
|
98
|
+
"@gjsify/webgl-linux-x64": "0.35.0"
|
|
99
99
|
}
|
|
100
100
|
}
|