@gjsify/webgl 0.52.0 → 0.53.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 +93 -7
- package/lib/esm/context/shader-program/glsl1-desktop.js +6 -0
- package/lib/esm/context/shader-program/glsl1-desktop.spec.js +8 -0
- package/lib/esm/context/shader-program/program-lifecycle.js +1 -1
- package/lib/esm/context/shader-program/shader-lifecycle.js +9 -7
- package/lib/esm/context/state.js +1 -1
- package/lib/esm/context/texture-management/copy-and-compressed.js +1 -1
- package/lib/esm/context/texture-management/legacy-formats.js +1 -0
- package/lib/esm/context/texture-management/legacy-formats.spec.js +1 -0
- package/lib/esm/context/texture-management/parameters.js +1 -1
- package/lib/esm/context/texture-management/tex-image.js +1 -1
- package/lib/esm/hidpi.spec.js +1 -0
- package/lib/esm/legacy-core-profile.spec.js +6 -0
- package/lib/esm/test.hidpi.js +1 -0
- package/lib/esm/test.js +1 -1
- package/lib/esm/webgl-context-base.js +5 -1
- package/lib/esm/webgl-shader.js +1 -1
- package/lib/esm/webgl-texture.js +1 -1
- package/lib/esm/webgl1.spec.js +35 -1
- package/lib/esm/webgl2-context/tex-image-3d.js +1 -1
- package/lib/esm/webgl2-rendering-context.js +1 -1
- package/lib/types/context/shader-program/glsl1-desktop.d.ts +31 -0
- package/lib/types/context/shader-program/shader-lifecycle.d.ts +5 -1
- package/lib/types/context/texture-management/copy-and-compressed.d.ts +3 -0
- package/lib/types/context/texture-management/legacy-formats.d.ts +46 -0
- package/lib/types/webgl-context-base.d.ts +81 -0
- package/lib/types/webgl-shader.d.ts +6 -0
- package/lib/types/webgl-texture.d.ts +2 -0
- package/package.json +19 -17
package/README.md
CHANGED
|
@@ -196,7 +196,7 @@ platform, not from the bridge:
|
|
|
196
196
|
they are gated on `epoxy_gl_version() >= 43` because libepoxy aborts rather than returning
|
|
197
197
|
null.
|
|
198
198
|
|
|
199
|
-
Remaining darwin gaps are tracked in [`status/open-todos.md`](../../../status/open-todos.md).
|
|
199
|
+
Remaining darwin gaps are tracked in [`status/open-todos/webgl.md`](../../../status/open-todos/webgl.md).
|
|
200
200
|
|
|
201
201
|
### The darwin GL 4.1 ceiling
|
|
202
202
|
|
|
@@ -216,11 +216,90 @@ nm -u libgwebgl.dylib | sed -n 's/^ *_epoxy_//p' | grep -E '^gl[A-Z]'
|
|
|
216
216
|
# then, per name, ctypes.CDLL('/System/Library/Frameworks/OpenGL.framework/OpenGL')
|
|
217
217
|
```
|
|
218
218
|
|
|
219
|
-
**The GLES 3.0 spellings
|
|
220
|
-
the shader rewrite above
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
219
|
+
**The GLES 3.0 spellings desktop 4.1 does not have are now supplied rather than refused**,
|
|
220
|
+
which is the part the shader rewrite above could not reach. Both were draw-time matters, so
|
|
221
|
+
a shader that compiles was never evidence that a scene using them would render.
|
|
222
|
+
|
|
223
|
+
- **`GL_PRIMITIVE_RESTART_FIXED_INDEX`** is a GL 4.3 state, and WebGL 2.0 removes it and
|
|
224
|
+
"behaves as though it were always enabled". Where the context has it, that is one
|
|
225
|
+
`Enable` — and it has to be made, because GLES 3.0 gives it the initial value **disabled**
|
|
226
|
+
while desktop GL 3.1 gives `PRIMITIVE_RESTART` the initial value *enabled*, so neither
|
|
227
|
+
default can be assumed. Where the state is absent the layer emulates it the way ANGLE does
|
|
228
|
+
on the same backends: `GL_PRIMITIVE_RESTART` plus
|
|
229
|
+
`glPrimitiveRestartIndex(<max of the element type>)`, **per draw call**, because the value
|
|
230
|
+
is a function of the element type (`0xFF` / `0xFFFF` / `0xFFFFFFFF`). Measured on
|
|
231
|
+
macOS 27 / GL 4.1 core: an index buffer whose second triangle is built from the restart
|
|
232
|
+
index (255) paints the far half of the framebuffer white without the emulation and
|
|
233
|
+
leaves it the clear colour with it, and `GL_PRIMITIVE_RESTART_INDEX` reads `0xff` /
|
|
234
|
+
`0xffff` / `0xffffffff` after a draw as `UNSIGNED_BYTE` / `_SHORT` / `_INT`. The predicate
|
|
235
|
+
is the one the dialect rewrite above already uses — the `ARB_ES3_compatibility` EXTENSION,
|
|
236
|
+
not the OS — and `Enable`/`Disable` of the removed state is `INVALID_ENUM` on **every**
|
|
237
|
+
context, which is what stops a consumer switching off behaviour the layer now supplies.
|
|
238
|
+
- **The ten ETC2/EAC compressed formats** are not a WebGL 2.0 requirement at all: the spec
|
|
239
|
+
removes them ("No ETC2 and EAC compressed texture formats") and re-offers them through
|
|
240
|
+
`WEBGL_compressed_texture_etc`, which this package does not implement, so `webgl2.idl`
|
|
241
|
+
names none of them. Handing the number to the driver is not a uniform outcome to leave to
|
|
242
|
+
chance — macOS's desktop GL 4.1 answers `INVALID_ENUM` anyway (measured), while on the
|
|
243
|
+
GLES 3.x context a Linux runner gets, every one of the ten is a *valid* format and the
|
|
244
|
+
upload would silently succeed. All four compressed entry points and
|
|
245
|
+
`getInternalformatParameter` now refuse them with the error WebGL specifies.
|
|
246
|
+
|
|
247
|
+
Both are measured, in `status/open-todos/webgl.md` § "the GLES 3.0 restart / ETC2 refusal
|
|
248
|
+
spec is owed": against the PREBUILT `libgwebgl` the far half reads white (the driver assembled
|
|
249
|
+
the triangle built from the restart index) and against a locally built library it reads the
|
|
250
|
+
clear colour. **No spec holds either yet** — the suite loads the prebuilt library, which still
|
|
251
|
+
carries the previous Vala, so the spec owed here is written down in full there and lands once
|
|
252
|
+
`main` refreshes the prebuilds.
|
|
253
|
+
|
|
254
|
+
**Four WebGL1 extensions are core on desktop GL, so the version answers, not the list.**
|
|
255
|
+
`OES_element_index_uint` (GL 1.1), `OES_standard_derivatives` (GL 2.0), `OES_texture_float` and
|
|
256
|
+
`OES_texture_float_linear` (GL 3.0) are features a GLES driver names as `GL_OES_*` extensions
|
|
257
|
+
and a desktop driver has no reason to list — macOS's does not, so `getExtension()` used to
|
|
258
|
+
answer `null` for three of them where Safari and Chrome expose all four.
|
|
259
|
+
`getSupportedExtensions()` now advertises each when the list names it OR the desktop GL version
|
|
260
|
+
provides it; on GLES the list stays the only source. An `RGBA`/`RGB` + `FLOAT` upload is handed
|
|
261
|
+
to a desktop driver as `RGBA32F`/`RGB32F`, since an unsized format leaves the storage to the
|
|
262
|
+
driver. `EXT_blend_minmax` (core GL 1.4) and `EXT_texture_filter_anisotropic` follow the same
|
|
263
|
+
rule. Each is held to a spec that USES the feature (a texel outside [0, 1] survives, a float
|
|
264
|
+
texture filters, 32-bit indices draw, `dFdx` evaluates, MAX blends), not merely to a non-null
|
|
265
|
+
object.
|
|
266
|
+
|
|
267
|
+
**Derivatives need a respelled shader on macOS.** A desktop core context compiles
|
|
268
|
+
`#version 100` through ARB_ES2_compatibility, and macOS's ES front end is GLSL ES 1.00 with no
|
|
269
|
+
extensions: `#extension GL_OES_standard_derivatives : enable` is "not supported" and `dFdx` is
|
|
270
|
+
undeclared. So a GLSL1 shader that calls a derivative is respelled in the context's own desktop
|
|
271
|
+
GLSL (`#version 410`, `attribute`/`varying`/`texture2D`/`gl_FragColor` renamed by macro —
|
|
272
|
+
`context/shader-program/glsl1-desktop.ts`), where the derivatives are core. Whether a context
|
|
273
|
+
needs that is PROBED once by compiling the smallest such shader, never read off the OS: a
|
|
274
|
+
driver whose ES front end honours the extension keeps the shader as written. Because macOS will
|
|
275
|
+
not link an ES stage with a desktop one, `linkProgram` gives every GLSL1 shader of a program the
|
|
276
|
+
spelling its most demanding member needs, recomputed per link so a vertex shader shared with a
|
|
277
|
+
plain program returns to the ES dialect there. `#ifdef GL_OES_standard_derivatives` is pointed
|
|
278
|
+
at an unreserved stand-in macro, defined only once the extension is enabled, because desktop GLSL
|
|
279
|
+
refuses to `#define` a `GL_` name; the `#extension` line is commented out (`: require` would be
|
|
280
|
+
an error there); a consumer name desktop GLSL claims (`uniform sampler2D texture;`) is renamed;
|
|
281
|
+
`#line` keeps every consumer line at its own number in compile errors.
|
|
282
|
+
|
|
283
|
+
**What a core profile removed, WebGL still has, so the bridge supplies it.** The profile is
|
|
284
|
+
asked of the context (`GL_CONTEXT_PROFILE_MASK`, `_isCoreProfile()`), never read off the OS,
|
|
285
|
+
so GLES and compatibility profiles keep the driver's own behaviour. Measured on macOS 27 /
|
|
286
|
+
Apple Silicon / GL 4.1 core: `test:conformance` went from 202/209 to 209/209.
|
|
287
|
+
|
|
288
|
+
- `ALPHA` / `LUMINANCE` / `LUMINANCE_ALPHA` textures are stored as `R8`/`RG8` (`R32F`/`RG32F`,
|
|
289
|
+
`R16F`/`RG16F` for float types) plus a texture swizzle (`(0,0,0,R)`, `(R,R,R,1)`,
|
|
290
|
+
`(R,R,R,G)`), which is how ANGLE does it (`context/texture-management/legacy-formats.ts`).
|
|
291
|
+
The swizzle is texture state, so re-specifying the texture in another format resets it.
|
|
292
|
+
`copyTex(Sub)Image2D` and `copyTexSubImage3D` into `ALPHA`/`LUMINANCE_ALPHA` read the region
|
|
293
|
+
back, because no GL copy moves the framebuffer's alpha into a red or green channel. What the
|
|
294
|
+
R/RG storage cannot say itself is checked from the format JS records, on every context: a
|
|
295
|
+
sub-upload in another format is `INVALID_OPERATION`, and a legacy texture is never a complete
|
|
296
|
+
color attachment (WebGL 2 included). WebGL 2's `TEXTURE_SWIZZLE_*` pnames are `INVALID_ENUM`.
|
|
297
|
+
- `GENERATE_MIPMAP_HINT` is kept in JS: `hint()` records it and `getParameter` reports it,
|
|
298
|
+
which is all a hint obliges an implementation to do.
|
|
299
|
+
- Three program rules are WebGL's (GLES 2.0 §2.10.3) and are checked in TypeScript, because a
|
|
300
|
+
desktop linker may accept what they forbid (macOS does): one shader per stage, no link
|
|
301
|
+
without both a vertex and a fragment shader, no `useProgram` on a program whose last link
|
|
302
|
+
failed. These run on every context; a GLES driver gives the same answers.
|
|
224
303
|
|
|
225
304
|
For the dialect rewrite itself — including why **win32 is rewritten too**, which this file
|
|
226
305
|
predicted wrongly once — see [Platform coverage](#platform-coverage) above. Host diagnosis:
|
|
@@ -243,7 +322,14 @@ is what lets an unmodified Three.js or Excalibur viewport cover the whole frameb
|
|
|
243
322
|
|
|
244
323
|
Reporting the allocation as `canvas.width` — as this bridge did until 2026-08 — is invisible at scale-factor 1, which is every desktop, every CI runner and every test VM. On the first scale-factor-3 host it drew each scene into the bottom-left NINTH of its widget: measured on a OnePlus 6T running postmarketOS / GNOME Mobile, where the teapot, the pixel-postprocessing and the Excalibur showcases all rendered a 120x218 corner of a 360x655-logical widget.
|
|
245
324
|
|
|
246
|
-
`@gjsify/dom-elements`' register seeds `devicePixelRatio: 1` as the widget-less default only.
|
|
325
|
+
`@gjsify/dom-elements`' register seeds `devicePixelRatio: 1` as the widget-less default only.
|
|
326
|
+
|
|
327
|
+
Two specs hold it, because each answers a question the other cannot:
|
|
328
|
+
|
|
329
|
+
- `html-canvas-element.spec.ts` varies the scale factor through a stub, so the arithmetic is pinned at 0, 1, 2 and 3 on any host.
|
|
330
|
+
- `hidpi.spec.ts` realizes a REAL `Gtk.GLArea` and checks the arithmetic against GTK itself: the device-pixel size GTK passes to the `resize` signal, the GL viewport GTK binds for `render` (read from GL, since `getParameter(VIEWPORT)` answers from a shadow of the app's own calls), and a pixel written to the framebuffer's top-right corner and read back. It re-checks all of it after a resize. At scale 1 it proves nothing, so CI runs it as `test:hidpi` under `GDK_SCALE=2` on X11, with `GJSIFY_TEST_EXPECT_SCALE=2` failing the run if the override stops taking effect.
|
|
331
|
+
|
|
332
|
+
Measured on a Retina Mac (macOS 27, Apple silicon, Homebrew GTK 4.24, scale 2): a 400x300 widget gets an 800x600 buffer, `devicePixelRatio` is 2, 1-device-pixel stripes come back pixel-exact from both `readPixels` and GTK's own composite, and a resize to 640x480 moves the buffer to 1280x960. The real-GLArea spec passes all 14 cases there — 13, plus the `GJSIFY_TEST_EXPECT_SCALE` case CI adds. Drop the `× this.scaleFactor` from `get width()` and 6 of the 14 fail. That run needed no gate change: `canRealizeGl` in `@gjsify/unit` already probes for a real context rather than deciding by OS, which is why the `Gl` gate opened itself on a Mac. No CI leg realizes a context on darwin yet, though (`status/open-todos/webgl.md`).
|
|
247
333
|
|
|
248
334
|
## Naming the GL you actually got
|
|
249
335
|
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import"../../_virtual/_rolldown/runtime.js";const usesStandardDerivatives=e=>/\b(?:dFdx|dFdy|fwidth)\s*\(/.test(e),e=`gjsify_FragColor`,t=`gjsify_FragData`,n=`GJSIFY_OES_standard_derivatives`,r=/\b(texture|sample|smooth|flat|layout|centroid|noperspective|patch|subroutine|precise|uint|uvec[234]|common|partition|active|filter)\b/g;function translateGlsl1ToDesktop(i,a,o,s,c){let l=i.replace(/^(\s*)#\s*version\s+100\b[^\n]*/,`$1`).replace(r,`gjsify_$1`),u=[`#version ${o}`,`#define texture2D texture`,`#define texture2DProj textureProj`,`#define texture2DLod textureLod`,`#define texture2DProjLod textureProjLod`,`#define textureCube texture`,`#define textureCubeLod textureLod`];c&&u.push(`#define ${n} 1`);let d=[];a===`vertex`?u.push(`#define attribute in`,`#define varying out`):(u.push(`#define varying in`),/\bgl_FragColor\b/.test(l)&&(u.push(`#define gl_FragColor ${e}`),d.push(`out vec4 ${e};`)),/\bgl_FragData\b/.test(l)&&(u.push(`#define gl_FragData ${t}`),d.push(`out vec4 ${t}[1];`)));let f=l.split(`
|
|
2
|
+
`),p=-1;for(let e=0;e<f.length;e++)/^\s*#\s*extension\s+GL_OES_standard_derivatives\b/.test(f[e])?(f[e]=`// `+f[e],p=e):/^\s*#\s*extension\b/.test(f[e])?p=e:/^\s*#\s*(?:if|ifdef|ifndef|elif)\b/.test(f[e])&&(f[e]=f[e].replace(/\bGL_OES_standard_derivatives\b/g,n));return d.length>0&&f.splice(p+1,0,...d,`#line ${p+2}`),u.join(`
|
|
3
|
+
`)+`
|
|
4
|
+
`+s+`#line 1
|
|
5
|
+
`+f.join(`
|
|
6
|
+
`)}export{translateGlsl1ToDesktop,usesStandardDerivatives};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import{__name as e}from"../../_virtual/_rolldown/runtime.js";import{translateGlsl1ToDesktop as t,usesStandardDerivatives as n}from"./glsl1-desktop.js";import{describe as r,expect as i,it as a}from"@gjsify/unit";const numberLines=e=>{let t=[],n=1;for(let r of e.split(`
|
|
2
|
+
`)){let e=/^\s*#\s*line\s+(\d+)/.exec(r);if(e){n=Number(e[1]);continue}t.push({n,text:r}),n+=1}return t},o=[`#extension GL_OES_standard_derivatives : require`,`precision mediump float;`,`uniform sampler2D texture;`,`varying vec2 vUv;`,`void main() {`,`#ifdef GL_OES_standard_derivatives`,` float d = fwidth(vUv.x);`,`#else`,` float d = 0.0;`,`#endif`,` gl_FragColor = texture2D(texture, vUv) * d;`,`}`].join(`
|
|
3
|
+
`);var s=e(async()=>{await r(`translateGlsl1ToDesktop`,async()=>{await a(`recognises derivative calls and nothing else`,async()=>{i(n(o)).toBe(!0),i(n(`void main() { float dFdxScale = 1.0; }`)).toBe(!1)}),await a(`keeps every consumer line at its own number`,async()=>{let e=numberLines(t(o,`fragment`,`410`,``,!0)),n=o.split(`
|
|
4
|
+
`);i(e.find(e=>e.text===`void main() {`)?.n).toBe(n.indexOf(`void main() {`)+1),i(e.find(e=>e.text.includes(`gl_FragColor = `))?.n).toBe(11)}),await a("replaces `#version 100` without shifting the lines below it",async()=>{let e=t(`#version 100
|
|
5
|
+
precision mediump float;
|
|
6
|
+
void main() { gl_FragColor = vec4(dFdx(1.0)); }`,`fragment`,`410`,``,!0);i(e.startsWith(`#version 410
|
|
7
|
+
`)).toBe(!0),i(e.includes(`version 100`)).toBe(!1),i(numberLines(e).find(e=>e.text.startsWith(`void main`))?.n).toBe(3)}),await a("comments out the ES extension directive, `: require` included",async()=>{let e=t(o,`fragment`,`410`,``,!0);i(/^\s*#\s*extension/m.test(e)).toBe(!1),i(e.includes(`// #extension GL_OES_standard_derivatives : require`)).toBe(!0)}),await a("answers `#ifdef GL_OES_standard_derivatives` by whether the consumer enabled it",async()=>{let e=t(o,`fragment`,`410`,``,!0),n=t(o,`fragment`,`410`,``,!1);for(let t of[e,n])i(/#\s*(?:define|undef|ifdef|if)\s+GL_/.test(t)).toBe(!1),i(t.includes(`#ifdef GJSIFY_OES_standard_derivatives`)).toBe(!0);i(e.includes(`#define GJSIFY_OES_standard_derivatives 1`)).toBe(!0),i(n.includes(`#define GJSIFY_OES_standard_derivatives`)).toBe(!1)}),await a(`renames consumer identifiers desktop GLSL claims, not the ES built-ins`,async()=>{let e=t(o,`fragment`,`410`,``,!0);i(e.includes(`uniform sampler2D gjsify_texture;`)).toBe(!0),i(e.includes(`texture2D(gjsify_texture, vUv)`)).toBe(!0),i(e.includes(`#define texture2D texture`)).toBe(!0)}),await a(`declares the fragment output after the directives and maps the ES names`,async()=>{let e=t(o,`fragment`,`410`,``,!0);i(e.includes(`#define varying in`)).toBe(!0),i(e.indexOf(`out vec4 gjsify_FragColor;`)).toBeGreaterThan(e.indexOf(`// #extension`));let n=t(`attribute vec2 p; varying vec2 v;
|
|
8
|
+
void main() {}`,`vertex`,`410`,``,!0);i(n.includes(`#define attribute in`)).toBe(!0),i(n.includes(`#define varying out`)).toBe(!0),i(n.includes(`gjsify_FragColor`)).toBe(!1)})})},`default`);export{s as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../../_virtual/_rolldown/runtime.js";import{checkObject as e,isValidString as t}from"../../utils.js";import{WebGLProgram as n}from"../../webgl-program.js";import{WebGLShader as r}from"../../webgl-shader.js";const i={createProgram(){let e=this._gl.createProgram();if(e<=0)return null;let t=new n(e,this);return this._programs[e]=t,t},deleteProgram(e){this._deleteLinkable(`deleteProgram`,e,n)},useProgram(t){if(!e(t))throw TypeError(`useProgram(WebGLProgram)`);if(t)this._checkWrapper(t,n)
|
|
1
|
+
import"../../_virtual/_rolldown/runtime.js";import{checkObject as e,isValidString as t}from"../../utils.js";import{WebGLProgram as n}from"../../webgl-program.js";import{WebGLShader as r}from"../../webgl-shader.js";const i={createProgram(){let e=this._gl.createProgram();if(e<=0)return null;let t=new n(e,this);return this._programs[e]=t,t},deleteProgram(e){this._deleteLinkable(`deleteProgram`,e,n)},useProgram(t){if(!e(t))throw TypeError(`useProgram(WebGLProgram)`);if(!t){this._switchActiveProgram(this._activeProgram),this._activeProgram=null,this._gl.useProgram(0);return}else if(this._checkWrapper(t,n)){if(!t._linkStatus){this.setError(this.INVALID_OPERATION);return}this._activeProgram!==t&&(this._switchActiveProgram(this._activeProgram),this._activeProgram=t,t._refCount+=1),this._gl.useProgram(t._|0)}},linkProgram(t){if(!e(t))throw TypeError(`linkProgram(WebGLProgram)`);if(this._checkWrapper(t,n)){t._linkCount+=1,t._attributes=[];let e=this.getError(),n=t._references.filter(e=>e instanceof r),i=n.some(e=>e._type===this.VERTEX_SHADER)?n.some(e=>e._type===this.FRAGMENT_SHADER)?null:`fragment`:`vertex`;if(i){t._linkStatus=!1,t._uniforms=[],t._linkInfoLog=`link failed: no ${i} shader attached`,this.setError(e);return}this._harmoniseShaderSpelling(n);for(let e of t._references)e instanceof r&&e._needsRecompile&&(this._gl.compileShader(e._|0),e._needsRecompile=!1);this._gl.linkProgram(t._|0);let a=this.getError();a===this.NO_ERROR&&(t._linkStatus=this._fixupLink(t)),this.getError(),this.setError(e||a)}},validateProgram(e){if(this._checkWrapper(e,n)){this._gl.validateProgram(e._|0);let t=this.getError();t===this.NO_ERROR&&(e._linkInfoLog=this._gl.getProgramInfoLog(e._|0)),this.getError(),this.setError(t)}},attachShader(t,i){if(!e(t)||!e(i))throw TypeError(`attachShader(WebGLProgram, WebGLShader)`);if(!t||!i){this.setError(this.INVALID_VALUE);return}else if(t instanceof n&&i instanceof r&&this._checkOwns(t)&&this._checkOwns(i)){let e=t._references.some(e=>e instanceof r&&e!==i&&e._type===i._type);if(!t._linked(i)&&!e){this._saveError(),this._gl.attachShader(t._|0,i._|0);let e=this.getError();this._restoreError(e),e===this.NO_ERROR&&t._link(i);return}}this.setError(this.INVALID_OPERATION)},detachShader(t,i){if(!e(t)||!e(i))throw TypeError(`detachShader(WebGLProgram, WebGLShader)`);this._checkWrapper(t,n)&&this._checkWrapper(i,r)&&(t._linked(i)?(this._gl.detachShader(t._,i._),t._unlink(i)):this.setError(this.INVALID_OPERATION))},bindAttribLocation(r,i,a){if(!e(r)||typeof a!=`string`)throw TypeError(`bindAttribLocation(WebGLProgram, GLint, String)`);a+=``,!t(a)||a.length>256?this.setError(this.INVALID_VALUE):/^_?webgl_a/.test(a)?this.setError(this.INVALID_OPERATION):this._checkWrapper(r,n)&&this._gl.bindAttribLocation(r._|0,i|0,a)},getAttachedShaders(t){if(!e(t)||typeof t==`object`&&t&&!(t instanceof n))throw TypeError(`getAttachedShaders(WebGLProgram)`);if(!t)this.setError(this.INVALID_VALUE);else if(this._checkWrapper(t,n))return t._references.filter(e=>e instanceof r);return null},getProgramInfoLog(t){if(!e(t))throw TypeError(`getProgramInfoLog(WebGLProgram)`);return this._checkWrapper(t,n)?t._linkInfoLog:null},getProgramParameter(t,r=0){if(!e(t))throw TypeError(`getProgramParameter(WebGLProgram, GLenum)`);if(this._checkWrapper(t,n)){switch(r){case this.DELETE_STATUS:return t._pendingDelete;case this.LINK_STATUS:return t._linkStatus;case this.VALIDATE_STATUS:return t._linkStatus&&!!this._gl.getProgramParameter(t._,r);case this.ATTACHED_SHADERS:return this._gl.getProgramParameter(t._,r);case this.ACTIVE_ATTRIBUTES:return t._linkStatus?t._attributes.length:this._gl.getProgramParameter(t._,r);case this.ACTIVE_UNIFORMS:return t._linkStatus?t._uniforms.length:this._gl.getProgramParameter(t._,r)}this.setError(this.INVALID_ENUM)}return null},_switchActiveProgram(e){e&&(--e._refCount,e._checkDelete())},_fixupLink(e){if(!this._gl.getProgramParameter(e._,this.LINK_STATUS))return e._linkInfoLog=this._gl.getProgramInfoLog(e._),!1;let t=this.getProgramParameter(e,this.ACTIVE_ATTRIBUTES),n=Array.from({length:t});e._attributes.length=t;for(let r=0;r<t;++r)n[r]=this.getActiveAttrib(e,r)?.name,e._attributes[r]=this.getAttribLocation(e,n[r])|0;for(let t=0;t<n.length;++t)if(n[t].length>256)return e._linkInfoLog=`attribute `+n[t]+` is too long`,!1;for(let r=0;r<t;++r)e._attributes[r]<0||this._gl.bindAttribLocation(e._|0,e._attributes[r],n[r]);if(this._gl.linkProgram(e._|0),!this._gl.getProgramParameter(e._|0,this.LINK_STATUS))return e._linkInfoLog=this._gl.getProgramInfoLog(e._),!1;let r=this.getProgramParameter(e,this.ACTIVE_UNIFORMS);e._uniforms.length=r;for(let t=0;t<r;++t){let n=this.getActiveUniform(e,t);n&&(e._uniforms[t]=n)}for(let t=0;t<e._uniforms.length;++t)if(e._uniforms[t].name.length>256)return e._linkInfoLog=`uniform `+e._uniforms[t].name+` is too long`,!1;return e._linkInfoLog=``,!0},_deleteLinkable(t,n,r){if(!e(n))throw TypeError(t+`(`+r.name+`)`);if(n instanceof r&&this._checkOwns(n)){n._pendingDelete=!0,n._checkDelete();return}this.setError(this.INVALID_OPERATION)}};function installProgramLifecycleMethods(e){Object.assign(e,i)}export{installProgramLifecycleMethods};
|
|
@@ -1,8 +1,10 @@
|
|
|
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
|
|
2
|
-
`))
|
|
3
|
-
|
|
4
|
-
`)
|
|
5
|
-
`)
|
|
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{translateGlsl1ToDesktop as i,usesStandardDerivatives as a}from"./glsl1-desktop.js";import o from"glsl-tokenizer/string";const s=/\b(attribute|varying|gl_FragColor|gl_FragData|texture2D|texture2DProj|textureCube)\b/,c=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 s.test(e)?`glsl1`:c.test(e)?`modern`:`glsl1`}function isGlsl1Source(e){return e.startsWith(`#version`)||e.includes(`
|
|
2
|
+
#version`)?/^\s*#\s*version\s+100\b/.test(e):glslDialectOf(e)===`glsl1`}const l={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)&&(r._userSource=i,r._needsDesktop=this._needsDesktopSpelling(i),r._desktopSpelled=r._needsDesktop,i=this._wrapShader(r._type,i,r._desktopSpelled),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=o(t),r=!1,i=[];for(let e=0;e<n.length;++e){let t=n[e];if(t)switch(t.type){case`ident`:this._validGLSLIdentifier(t.data)||(r=!0,i.push(t.line+`:`+t.column+` invalid identifier - `+t.data));break;case`preprocessor`:{let e=t.data.match(/^\s*#\s*(.*)$/);if(!e||e?.length<2)break;let n=o(e[1]);for(let e=0;e<n.length;++e){let a=n[e];(a.type===`ident`||a.type===void 0)&&(this._validGLSLIdentifier(a.data)||(r=!0,i.push(t.line+`:`+a.column+` invalid identifier - `+a.data)))}break}case`keyword`:switch(t.data){case`do`:r=!0,i.push(t.line+`:`+t.column+` do not supported`);break}break;case`builtin`:switch(t.data){case`dFdx`:case`dFdy`:case`fwidth`:!this._extensions.oes_standard_derivatives&&this._getGlslVersion(!0)===`100`&&(r=!0,i.push(t.line+`:`+t.column+` `+t.data+` not supported`));break}}}return r&&(e._compileInfo=i.join(`
|
|
3
|
+
`)),!r},_needsDesktopSpelling(e){return isGlsl1Source(e)&&a(e)&&!!this._desktopGlslForEsDerivatives()},_harmoniseShaderSpelling(e){let t=e.some(e=>e._needsDesktop);for(let n of e){if(n._desktopSpelled===t||!isGlsl1Source(n._userSource))continue;let e=this._wrapShader(n._type,n._userSource,t);this._gl.shaderSource(n._|0,e),n._source=e,n._desktopSpelled=t,n._needsRecompile||(this._gl.compileShader(n._|0),n._compileStatus=!!this._gl.getShaderParameter(n._|0,this.COMPILE_STATUS),n._compileInfo=this._gl.getShaderInfoLog(n._|0)||`null`)}},_wrapShader(e,t,n=!1){let r=t.startsWith(`#version`)||t.includes(`
|
|
4
|
+
#version`),a=r?null:glslDialectOf(t),o=``;!this._extensions.oes_standard_derivatives&&/#ifdef\s+GL_OES_standard_derivatives/.test(t)&&(o+=`#undef GL_OES_standard_derivatives
|
|
5
|
+
`),!this._extensions.webgl_draw_buffers&&a===`glsl1`&&(o+=`#define gl_MaxDrawBuffers 1
|
|
6
|
+
`);let s=n?this._desktopGlslForEsDerivatives():null;if(s){let n=e===this.VERTEX_SHADER?`vertex`:`fragment`,r=o.replace(`#undef GL_OES_standard_derivatives
|
|
7
|
+
`,``);return i(t,n,s,r,!!this._extensions.oes_standard_derivatives)}if(r){if(o){let e=t.indexOf(`
|
|
6
8
|
`);t=e===-1?t+`
|
|
7
|
-
`+
|
|
8
|
-
`+
|
|
9
|
+
`+o:t.slice(0,e+1)+o+t.slice(e+1)}}else if(this.canvas){let e=this.canvas.getGlArea().get_use_es(),n=a===`glsl1`?this._getGlsl1Version(e):this._getGlslVersion(e);n?t=`#version `+n+`
|
|
10
|
+
`+o+t:o&&(t=o+t)}else o&&(t=o+t);return t}};function installShaderLifecycleMethods(e){Object.assign(e,l)}export{installShaderLifecycleMethods,isGlsl1Source};
|
package/lib/esm/context/state.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../_virtual/_rolldown/runtime.js";import{WebGLBuffer as e}from"../webgl-buffer.js";import{WebGLFramebuffer as t}from"../webgl-framebuffer.js";import{WebGLRenderbuffer as n}from"../webgl-renderbuffer.js";import{WebGLTexture as r}from"../webgl-texture.js";import{WebGLProgram as i}from"../webgl-program.js";import{WebGLShader as a}from"../webgl-shader.js";const o={enable(e=0){this._gl.enable(e)},disable(e=0){if(this._gl.disable(e),e===this.TEXTURE_2D||e===this.TEXTURE_CUBE_MAP){let t=this._getActiveTextureUnit();t._mode===e&&(t._mode=0)}},cullFace(e){this._gl.cullFace(e|0)},depthFunc(e){switch(e|=0,e){case this.NEVER:case this.LESS:case this.EQUAL:case this.LEQUAL:case this.GREATER:case this.NOTEQUAL:case this.GEQUAL:case this.ALWAYS:this._gl.depthFunc(e);return;default:this.setError(this.INVALID_ENUM)}},depthMask(e){this._gl.depthMask(!!e)},depthRange(e,t){if(e=+e,t=+t,e<=t){this._gl.depthRange(e,t);return}this.setError(this.INVALID_OPERATION)},frontFace(e=0){this._gl.frontFace(e)},lineWidth(e){if(isNaN(e)){this.setError(this.INVALID_VALUE);return}this._gl.lineWidth(+e)},polygonOffset(e,t){this._gl.polygonOffset(+e,+t)},sampleCoverage(e,t){this._gl.sampleCoverage(+e,!!t)},hint(e=0,t=0){let n=this._extensions.oes_standard_derivatives;if(!(e===this.GENERATE_MIPMAP_HINT||n&&e===n.FRAGMENT_SHADER_DERIVATIVE_HINT_OES)){this.setError(this.INVALID_ENUM);return}if(t!==this.FASTEST&&t!==this.NICEST&&t!==this.DONT_CARE){this.setError(this.INVALID_ENUM);return}this._gl.hint(e,t)},finish(){this._gl.finish()},flush(){this._gl.flush()},blendColor(e=0,t=0,n=0,r=0){this._gl.blendColor(+e,+t,+n,+r)},blendEquation(e=0){if(this._validBlendMode(e)){this._gl.blendEquation(e);return}this.setError(this.INVALID_ENUM)},blendEquationSeparate(e=0,t=0){if(this._validBlendMode(e)&&this._validBlendMode(t)){this._gl.blendEquationSeparate(e,t);return}this.setError(this.INVALID_ENUM)},blendFunc(e=0,t=0){if(!this._validBlendFunc(e)||!this._validBlendFunc(t)){this.setError(this.INVALID_ENUM);return}if(this._isConstantBlendFunc(e)&&this._isConstantBlendFunc(t)){this.setError(this.INVALID_OPERATION);return}this._gl.blendFunc(e,t)},blendFuncSeparate(e=0,t=0,n=0,r=0){if(!(this._validBlendFunc(e)&&this._validBlendFunc(t)&&this._validBlendFunc(n)&&this._validBlendFunc(r))){this.setError(this.INVALID_ENUM);return}if(this._isConstantBlendFunc(e)&&this._isConstantBlendFunc(t)||this._isConstantBlendFunc(n)&&this._isConstantBlendFunc(r)){this.setError(this.INVALID_OPERATION);return}this._gl.blendFuncSeparate(e,t,n,r)},clear(e=0){this._framebufferOk()&&this._gl.clear(e)},clearColor(e,t,n,r){this._gl.clearColor(+e,+t,+n,+r)},clearDepth(e){this._gl.clearDepth(+e)},clearStencil(e=0){this._checkStencil=!1,this._gl.clearStencil(e)},colorMask(e,t,n,r){this._gl.colorMask(!!e,!!t,!!n,!!r)},stencilFunc(e,t,n){this._checkStencil=!0,this._gl.stencilFunc(e|0,t|0,n|0)},stencilFuncSeparate(e,t,n,r){this._checkStencil=!0,this._gl.stencilFuncSeparate(e|0,t|0,n|0,r|0)},stencilMask(e){this._checkStencil=!0,this._gl.stencilMask(e>>>0)},stencilMaskSeparate(e,t){this._checkStencil=!0,this._gl.stencilMaskSeparate(e|0,t>>>0)},stencilOp(e,t,n){this._checkStencil=!0,this._gl.stencilOp(e|0,t|0,n|0)},stencilOpSeparate(e,t,n,r){this._checkStencil=!0,this._gl.stencilOpSeparate(e|0,t|0,n|0,r|0)},isEnabled(e=0){return this._gl.isEnabled(e)},isContextLost(){return!1},getError(){return this._gl.getError()},setError(e){this._gl.setError(e)},isBuffer(t){return this._isObject(t,`isBuffer`,e)?this._gl.isBuffer(t?._):!1},isFramebuffer(e){return this._isObject(e,`isFramebuffer`,t)?this._gl.isFramebuffer(e?._):!1},isProgram(e){return this._isObject(e,`isProgram`,i)?this._gl.isProgram(e?._):!1},isRenderbuffer(e){return this._isObject(e,`isRenderbuffer`,n)?this._gl.isRenderbuffer(e?._):!1},isShader(e){return this._isObject(e,`isShader`,a)?this._gl.isShader(e?._):!1},isTexture(e){return this._isObject(e,`isTexture`,r)?this._gl.isTexture(e?._):!1},generateMipmap(e=0){this._gl.generateMipmap(e)},_validBlendFunc(e){return e===this.ZERO||e===this.ONE||e===this.SRC_COLOR||e===this.ONE_MINUS_SRC_COLOR||e===this.DST_COLOR||e===this.ONE_MINUS_DST_COLOR||e===this.SRC_ALPHA||e===this.ONE_MINUS_SRC_ALPHA||e===this.DST_ALPHA||e===this.ONE_MINUS_DST_ALPHA||e===this.SRC_ALPHA_SATURATE||e===this.CONSTANT_COLOR||e===this.ONE_MINUS_CONSTANT_COLOR||e===this.CONSTANT_ALPHA||e===this.ONE_MINUS_CONSTANT_ALPHA},_validBlendMode(e){let t=this._extensions.ext_blend_minmax;return e===this.FUNC_ADD||e===this.FUNC_SUBTRACT||e===this.FUNC_REVERSE_SUBTRACT||!!(t&&(e===t.MIN_EXT||e===t.MAX_EXT))},_isConstantBlendFunc(e){return e===this.CONSTANT_COLOR||e===this.ONE_MINUS_CONSTANT_COLOR||e===this.CONSTANT_ALPHA||e===this.ONE_MINUS_CONSTANT_ALPHA},_saveError(){this._errorStack.push(this.getError())},_restoreError(e){let t=this._errorStack.pop();t===this.NO_ERROR?this.setError(e):t!==void 0&&this.setError(t)}};function installStateMethods(e){Object.assign(e,o)}export{installStateMethods};
|
|
1
|
+
import"../_virtual/_rolldown/runtime.js";import{WebGLBuffer as e}from"../webgl-buffer.js";import{WebGLFramebuffer as t}from"../webgl-framebuffer.js";import{WebGLRenderbuffer as n}from"../webgl-renderbuffer.js";import{WebGLTexture as r}from"../webgl-texture.js";import{WebGLProgram as i}from"../webgl-program.js";import{WebGLShader as a}from"../webgl-shader.js";const o={enable(e=0){this._gl.enable(e)},disable(e=0){if(this._gl.disable(e),e===this.TEXTURE_2D||e===this.TEXTURE_CUBE_MAP){let t=this._getActiveTextureUnit();t._mode===e&&(t._mode=0)}},cullFace(e){this._gl.cullFace(e|0)},depthFunc(e){switch(e|=0,e){case this.NEVER:case this.LESS:case this.EQUAL:case this.LEQUAL:case this.GREATER:case this.NOTEQUAL:case this.GEQUAL:case this.ALWAYS:this._gl.depthFunc(e);return;default:this.setError(this.INVALID_ENUM)}},depthMask(e){this._gl.depthMask(!!e)},depthRange(e,t){if(e=+e,t=+t,e<=t){this._gl.depthRange(e,t);return}this.setError(this.INVALID_OPERATION)},frontFace(e=0){this._gl.frontFace(e)},lineWidth(e){if(isNaN(e)){this.setError(this.INVALID_VALUE);return}this._gl.lineWidth(+e)},polygonOffset(e,t){this._gl.polygonOffset(+e,+t)},sampleCoverage(e,t){this._gl.sampleCoverage(+e,!!t)},hint(e=0,t=0){let n=this._extensions.oes_standard_derivatives;if(!(e===this.GENERATE_MIPMAP_HINT||n&&e===n.FRAGMENT_SHADER_DERIVATIVE_HINT_OES)){this.setError(this.INVALID_ENUM);return}if(t!==this.FASTEST&&t!==this.NICEST&&t!==this.DONT_CARE){this.setError(this.INVALID_ENUM);return}e===this.GENERATE_MIPMAP_HINT&&(this._generateMipmapHint=t,this._isCoreProfile())||this._gl.hint(e,t)},finish(){this._gl.finish()},flush(){this._gl.flush()},blendColor(e=0,t=0,n=0,r=0){this._gl.blendColor(+e,+t,+n,+r)},blendEquation(e=0){if(this._validBlendMode(e)){this._gl.blendEquation(e);return}this.setError(this.INVALID_ENUM)},blendEquationSeparate(e=0,t=0){if(this._validBlendMode(e)&&this._validBlendMode(t)){this._gl.blendEquationSeparate(e,t);return}this.setError(this.INVALID_ENUM)},blendFunc(e=0,t=0){if(!this._validBlendFunc(e)||!this._validBlendFunc(t)){this.setError(this.INVALID_ENUM);return}if(this._isConstantBlendFunc(e)&&this._isConstantBlendFunc(t)){this.setError(this.INVALID_OPERATION);return}this._gl.blendFunc(e,t)},blendFuncSeparate(e=0,t=0,n=0,r=0){if(!(this._validBlendFunc(e)&&this._validBlendFunc(t)&&this._validBlendFunc(n)&&this._validBlendFunc(r))){this.setError(this.INVALID_ENUM);return}if(this._isConstantBlendFunc(e)&&this._isConstantBlendFunc(t)||this._isConstantBlendFunc(n)&&this._isConstantBlendFunc(r)){this.setError(this.INVALID_OPERATION);return}this._gl.blendFuncSeparate(e,t,n,r)},clear(e=0){this._framebufferOk()&&this._gl.clear(e)},clearColor(e,t,n,r){this._gl.clearColor(+e,+t,+n,+r)},clearDepth(e){this._gl.clearDepth(+e)},clearStencil(e=0){this._checkStencil=!1,this._gl.clearStencil(e)},colorMask(e,t,n,r){this._gl.colorMask(!!e,!!t,!!n,!!r)},stencilFunc(e,t,n){this._checkStencil=!0,this._gl.stencilFunc(e|0,t|0,n|0)},stencilFuncSeparate(e,t,n,r){this._checkStencil=!0,this._gl.stencilFuncSeparate(e|0,t|0,n|0,r|0)},stencilMask(e){this._checkStencil=!0,this._gl.stencilMask(e>>>0)},stencilMaskSeparate(e,t){this._checkStencil=!0,this._gl.stencilMaskSeparate(e|0,t>>>0)},stencilOp(e,t,n){this._checkStencil=!0,this._gl.stencilOp(e|0,t|0,n|0)},stencilOpSeparate(e,t,n,r){this._checkStencil=!0,this._gl.stencilOpSeparate(e|0,t|0,n|0,r|0)},isEnabled(e=0){return this._gl.isEnabled(e)},isContextLost(){return!1},getError(){return this._gl.getError()},setError(e){this._gl.setError(e)},isBuffer(t){return this._isObject(t,`isBuffer`,e)?this._gl.isBuffer(t?._):!1},isFramebuffer(e){return this._isObject(e,`isFramebuffer`,t)?this._gl.isFramebuffer(e?._):!1},isProgram(e){return this._isObject(e,`isProgram`,i)?this._gl.isProgram(e?._):!1},isRenderbuffer(e){return this._isObject(e,`isRenderbuffer`,n)?this._gl.isRenderbuffer(e?._):!1},isShader(e){return this._isObject(e,`isShader`,a)?this._gl.isShader(e?._):!1},isTexture(e){return this._isObject(e,`isTexture`,r)?this._gl.isTexture(e?._):!1},generateMipmap(e=0){this._gl.generateMipmap(e)},_validBlendFunc(e){return e===this.ZERO||e===this.ONE||e===this.SRC_COLOR||e===this.ONE_MINUS_SRC_COLOR||e===this.DST_COLOR||e===this.ONE_MINUS_DST_COLOR||e===this.SRC_ALPHA||e===this.ONE_MINUS_SRC_ALPHA||e===this.DST_ALPHA||e===this.ONE_MINUS_DST_ALPHA||e===this.SRC_ALPHA_SATURATE||e===this.CONSTANT_COLOR||e===this.ONE_MINUS_CONSTANT_COLOR||e===this.CONSTANT_ALPHA||e===this.ONE_MINUS_CONSTANT_ALPHA},_validBlendMode(e){let t=this._extensions.ext_blend_minmax;return e===this.FUNC_ADD||e===this.FUNC_SUBTRACT||e===this.FUNC_REVERSE_SUBTRACT||!!(t&&(e===t.MIN_EXT||e===t.MAX_EXT))},_isConstantBlendFunc(e){return e===this.CONSTANT_COLOR||e===this.ONE_MINUS_CONSTANT_COLOR||e===this.CONSTANT_ALPHA||e===this.ONE_MINUS_CONSTANT_ALPHA},_saveError(){this._errorStack.push(this.getError())},_restoreError(e){let t=this._errorStack.pop();t===this.NO_ERROR?this.setError(e):t!==void 0&&this.setError(t)}};function installStateMethods(e){Object.assign(e,o)}export{installStateMethods};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../../_virtual/_rolldown/runtime.js";import{Uint8ArrayToVariant as e,arrayToUint8Array as t}from"../../utils.js";import
|
|
1
|
+
import"../../_virtual/_rolldown/runtime.js";import{Uint8ArrayToVariant as e,arrayToUint8Array as t}from"../../utils.js";import{coreStorageForLegacyFormat as n,extractLegacyChannels as r,isLegacyFormat as i}from"./legacy-formats.js";import*as a from"bit-twiddle";const o=5121,s=35051,c=35052,l=[[3333,4],[3330,0],[3331,0],[3332,0],[3317,1],[3314,0],[3315,0],[3316,0]],u={copyTexImage2D(e=0,t=0,n=0,r=0,s=0,c=0,l=0,u=0){let d=this._getTexImage(e);if(!d){this.setError(this.INVALID_OPERATION);return}if(n!==this.RGBA&&n!==this.RGB&&n!==this.ALPHA&&n!==this.LUMINANCE&&n!==this.LUMINANCE_ALPHA){this.setError(this.INVALID_ENUM);return}if(t<0||c<0||l<0||u!==0){this.setError(this.INVALID_VALUE);return}if(t>0&&!(a.isPow2(c)&&a.isPow2(l))){this.setError(this.INVALID_VALUE);return}let f=this._legacyFormatStorage(n,this.UNSIGNED_BYTE);this._saveError(),f&&n!==this.LUMINANCE?this._copyLegacyChannels(n,r,s,c,l,(n,r)=>this._gl.texImage2D(e,t,n.internalFormat,c,l,0,n.format,o,r)):this._gl.copyTexImage2D(e,t,f?f.internalFormat:n,r,s,c,l,u);let p=this.getError();this._restoreError(p),p===this.NO_ERROR&&(d._levelWidth[t]=c,d._levelHeight[t]=l,d._format=i(n)?n:this.RGBA,d._type=this.UNSIGNED_BYTE,this._setTextureSwizzle(e,d,f?f.swizzle:null))},copyTexSubImage2D(e=0,t=0,n=0,r=0,i=0,a=0,s=0,c=0){let l=this._getTexImage(e);if(!l){this.setError(this.INVALID_OPERATION);return}if(s<0||c<0||n<0||r<0||t<0){this.setError(this.INVALID_VALUE);return}if((l._format===this.ALPHA||l._format===this.LUMINANCE_ALPHA)&&this._legacyFormatStorage(l._format,this.UNSIGNED_BYTE)){this._copyLegacyChannels(l._format,i,a,s,c,(i,a)=>this._gl.texSubImage2D(e,t,n,r,s,c,i.format,o,a));return}this._gl.copyTexSubImage2D(e,t,n,r,i,a,s,c)},_copyLegacyChannels(t,a,u,d,f,p){let m=i(t)?n(t,o):null;if(!m)return;if(this._gl.checkFramebufferStatus(36008)!==36053){this.setError(1286);return}let h=this._gl.getParameteri(35053),g=this._gl.getParameteri(35055),_=l.map(([e])=>this._gl.getParameteri(e)),v=this._packAlignment;h&&this._gl.bindBuffer(s,0),g&&this._gl.bindBuffer(c,0);for(let[e,t]of l)this._gl.pixelStorei(e,t);this._packAlignment=4;try{let n=new Uint8Array(Math.max(0,d*f*4));n.length>0&&this.readPixels(a,u,d,f,6408,o,n),p(m,e(r(n,t)))}finally{this._packAlignment=v,l.forEach(([e],t)=>this._gl.pixelStorei(e,_[t])),h&&this._gl.bindBuffer(s,h),g&&this._gl.bindBuffer(c,g)}},compressedTexImage2D(n,r,i,a,o,s,c){this._saveError(),this._gl.compressedTexImage2D(n,r,i,a,o,s,e(t(c)));let l=this.getError();if(this._restoreError(l),l!==this.NO_ERROR)return;let u=this._getTexImage(n);u&&(u._format=i,this._setTextureSwizzle(n,u,null))},compressedTexSubImage2D(n,r,i,a,o,s,c,l){this._gl.compressedTexSubImage2D(n,r,i,a,o,s,c,e(t(l)))}};function installCopyAndCompressedTextureMethods(e){Object.assign(e,u)}export{installCopyAndCompressedTextureMethods};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"../../_virtual/_rolldown/runtime.js";const e=6406,t=6409,n=6410,r=6403,i=6404,a=33319,o=[36418,36419,36420,36421],s=[r,i,6405,e];function isLegacyFormat(r){return r===e||r===t||r===n}function coreStorageForLegacyFormat(e,t){if(!isLegacyFormat(e))return null;let i=e===n,o;switch(t){case 5121:o=i?33323:33321;break;case 5126:o=i?33328:33326;break;case 5131:case 36193:o=i?33327:33325;break;default:return null}return{internalFormat:o,format:i?a:r,swizzle:legacySwizzle(e)}}function legacySwizzle(n){return n===e?[0,0,0,r]:n===t?[r,r,r,1]:[r,r,r,i]}function coreTransferFormat(i){return i===n?a:i===e||i===t?r:i}function textureParameterTarget(e){return e>=34069&&e<=34074?34067:e}function extractLegacyChannels(t,r){let i=t.length>>2;if(r===n){let e=new Uint8Array(i*2);for(let n=0;n<i;++n)e[2*n]=t[4*n],e[2*n+1]=t[4*n+3];return e}let a=r===e?3:0,o=new Uint8Array(i);for(let e=0;e<i;++e)o[e]=t[4*e+a];return o}export{s as IDENTITY_SWIZZLE,o as TEXTURE_SWIZZLE_PNAMES,coreStorageForLegacyFormat,coreTransferFormat,extractLegacyChannels,isLegacyFormat,legacySwizzle,textureParameterTarget};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{__name as e}from"../../_virtual/_rolldown/runtime.js";import{IDENTITY_SWIZZLE as t,coreStorageForLegacyFormat as n,coreTransferFormat as r,extractLegacyChannels as i,isLegacyFormat as a,textureParameterTarget as o}from"./legacy-formats.js";import{describe as s,expect as c,it as l}from"@gjsify/unit";const u=6406,d=6408,f=6409,p=6410,m=6403,h=6404,g=33319,_=5121,v=5126;var y=e(async()=>{await s(`legacy texture formats on a core profile`,async()=>{await l(`recognises exactly the three legacy formats`,async()=>{c([u,f,p].every(a)).toBe(!0),c([m,g,6407,d].some(a)).toBe(!1)}),await l(`stores one channel in R8 and two in RG8`,async()=>{c(n(u,_)).toStrictEqual({internalFormat:33321,format:m,swizzle:[0,0,0,m]}),c(n(f,_)).toStrictEqual({internalFormat:33321,format:m,swizzle:[m,m,m,1]}),c(n(p,_)).toStrictEqual({internalFormat:33323,format:g,swizzle:[m,m,m,h]})}),await l(`keeps float and half-float precision with a sized format`,async()=>{c(n(f,v)?.internalFormat).toBe(33326),c(n(p,v)?.internalFormat).toBe(33328),c(n(u,5131)?.internalFormat).toBe(33325),c(n(p,36193)?.internalFormat).toBe(33327)}),await l(`leaves other formats and invalid types to the driver`,async()=>{c(n(d,_)).toBe(null),c(n(f,32819)).toBe(null)}),await l(`maps the transfer format to the storage layout, and nothing else`,async()=>{c(r(u)).toBe(m),c(r(f)).toBe(m),c(r(p)).toBe(g),c(r(d)).toBe(d),c(t).toStrictEqual([m,h,6405,u])}),await l(`sets a cube face swizzle on the cube map`,async()=>{c(o(34069)).toBe(34067),c(o(34074)).toBe(34067),c(o(3553)).toBe(3553),c(o(35866)).toBe(35866)}),await l(`picks A, R, and R+A out of read-back RGBA`,async()=>{let e=new Uint8Array([10,20,30,40,50,60,70,80]);c(Array.from(i(e,u))).toStrictEqual([40,80]),c(Array.from(i(e,f))).toStrictEqual([10,50]),c(Array.from(i(e,p))).toStrictEqual([10,40,50,80])})})},`default`);export{y as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../../_virtual/_rolldown/runtime.js";const e={texParameterf(e=0,t=0,n){if(n=+n,this._checkTextureTarget(e)){switch(this._verifyTextureCompleteness(e,t,n),t){case this.TEXTURE_MIN_FILTER:case this.TEXTURE_MAG_FILTER:case this.TEXTURE_WRAP_S:case this.TEXTURE_WRAP_T:this._gl.texParameterf(e,t,n);return}let r=this._extensions.ext_texture_filter_anisotropic;if(r&&t===r.TEXTURE_MAX_ANISOTROPY_EXT){this._gl.texParameterf(e,t,n);return}this.setError(this.INVALID_ENUM)}},texParameteri(e=0,t=0,n=0){if(this._checkTextureTarget(e)){switch(this._verifyTextureCompleteness(e,t,n),t){case this.TEXTURE_MIN_FILTER:case this.TEXTURE_MAG_FILTER:case this.TEXTURE_WRAP_S:case this.TEXTURE_WRAP_T:this._gl.texParameteri(e,t,n);return}let r=this._extensions.ext_texture_filter_anisotropic;if(r&&t===r.TEXTURE_MAX_ANISOTROPY_EXT){this._gl.texParameteri(e,t,n);return}this.setError(this.INVALID_ENUM)}},getTexParameter(e=0,t=0){if(!this._checkTextureTarget(e))return null;let n=this._getActiveTextureUnit();if(e===this.TEXTURE_2D&&!n._bind2D||e===this.TEXTURE_CUBE_MAP&&!n._bindCube)return this.setError(this.INVALID_OPERATION),null;switch(t){case this.TEXTURE_MAG_FILTER:case this.TEXTURE_MIN_FILTER:case this.TEXTURE_WRAP_S:case this.TEXTURE_WRAP_T:return this._getTexParameterDirect(e,t)}let r=this._extensions.ext_texture_filter_anisotropic;return r&&t===r.TEXTURE_MAX_ANISOTROPY_EXT?this.
|
|
1
|
+
import"../../_virtual/_rolldown/runtime.js";const e={texParameterf(e=0,t=0,n){if(n=+n,this._checkTextureTarget(e)){switch(this._verifyTextureCompleteness(e,t,n),t){case this.TEXTURE_MIN_FILTER:case this.TEXTURE_MAG_FILTER:case this.TEXTURE_WRAP_S:case this.TEXTURE_WRAP_T:this._gl.texParameterf(e,t,n);return}let r=this._extensions.ext_texture_filter_anisotropic;if(r&&t===r.TEXTURE_MAX_ANISOTROPY_EXT){this._gl.texParameterf(e,t,n);return}this.setError(this.INVALID_ENUM)}},texParameteri(e=0,t=0,n=0){if(this._checkTextureTarget(e)){switch(this._verifyTextureCompleteness(e,t,n),t){case this.TEXTURE_MIN_FILTER:case this.TEXTURE_MAG_FILTER:case this.TEXTURE_WRAP_S:case this.TEXTURE_WRAP_T:this._gl.texParameteri(e,t,n);return}let r=this._extensions.ext_texture_filter_anisotropic;if(r&&t===r.TEXTURE_MAX_ANISOTROPY_EXT){this._gl.texParameteri(e,t,n);return}this.setError(this.INVALID_ENUM)}},getTexParameter(e=0,t=0){if(!this._checkTextureTarget(e))return null;let n=this._getActiveTextureUnit();if(e===this.TEXTURE_2D&&!n._bind2D||e===this.TEXTURE_CUBE_MAP&&!n._bindCube)return this.setError(this.INVALID_OPERATION),null;switch(t){case this.TEXTURE_MAG_FILTER:case this.TEXTURE_MIN_FILTER:case this.TEXTURE_WRAP_S:case this.TEXTURE_WRAP_T:return this._getTexParameterDirect(e,t)}let r=this._extensions.ext_texture_filter_anisotropic;return r&&t===r.TEXTURE_MAX_ANISOTROPY_EXT?this._gl.getTexParameterfv(e,t):(this.setError(this.INVALID_ENUM),null)},_getTexParameterDirect(e=0,t=0){return this._gl.getTexParameterx(e,t)?.unpack()}};function installTextureParameterMethods(t){Object.assign(t,e)}export{installTextureParameterMethods};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../../_virtual/_rolldown/runtime.js";import{Uint8ArrayToVariant as e,checkFormat as t,convertPixels as n,extractImageData as r,premultiplyAlpha as i,validCubeTarget as a}from"../../utils.js";import o from"gi://GdkPixbuf?version=2.0";const s={texImage2D(s=0,c=0,l=0,u=0,d=0,f=0,p=0,m=0,h){let g=0,_=0,v=0,y,b,x=0;if(arguments.length===6)if(m=d,v=u,f instanceof o.Pixbuf)b=f,g=b.get_width(),_=b.get_height(),h=b.get_pixels();else{y=f;let e=r(y);if(e==null)throw TypeError(`texImage2D(GLenum, GLint, GLenum, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)`);g=e.width,_=e.height,h=e.data}else arguments.length===9&&(g=u,_=d,x=f,v=p,h=h);if(typeof h!=`object`&&h!==void 0)throw TypeError(`texImage2D(GLenum, GLint, GLenum, GLint, GLint, GLint, GLenum, GLenum, Uint8Array)`);if(!t(this,v)||!t(this,l)){this.setError(this.INVALID_ENUM);return}if(m===this.FLOAT&&!this._extensions.oes_texture_float){this.setError(this.INVALID_ENUM);return}let S=this._getTexImage(s);if(!S||v!==l){this.setError(this.INVALID_OPERATION);return}let C=this._computePixelSize(m,v);if(C===0||!this._checkDimensions(s,g,_,c))return;let w=n(h),T=this._computeRowStride(g,C),E=T*_;if(w&&w.length<E){this.setError(this.INVALID_OPERATION);return}if(x!==0||a(this,s)&&g!==_){this.setError(this.INVALID_VALUE);return}if(this._unpackPremultAlpha&&w&&v===this.RGBA&&(w=i(w)),this._unpackFlipY&&w&&g>0&&_>0){let e=new Uint8Array(w.length);for(let t=0;t<_;t++){let n=t*T,r=(_-1-t)*T;e.set(w.subarray(n,n+T),r)}w=e}this._saveError(),this._gl.texImage2D(s,c,l,g,_,x,v,m,e(w));let
|
|
1
|
+
import"../../_virtual/_rolldown/runtime.js";import{Uint8ArrayToVariant as e,checkFormat as t,convertPixels as n,extractImageData as r,premultiplyAlpha as i,validCubeTarget as a}from"../../utils.js";import o from"gi://GdkPixbuf?version=2.0";const s={texImage2D(s=0,c=0,l=0,u=0,d=0,f=0,p=0,m=0,h){let g=0,_=0,v=0,y,b,x=0;if(arguments.length===6)if(m=d,v=u,f instanceof o.Pixbuf)b=f,g=b.get_width(),_=b.get_height(),h=b.get_pixels();else{y=f;let e=r(y);if(e==null)throw TypeError(`texImage2D(GLenum, GLint, GLenum, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)`);g=e.width,_=e.height,h=e.data}else arguments.length===9&&(g=u,_=d,x=f,v=p,h=h);if(typeof h!=`object`&&h!==void 0)throw TypeError(`texImage2D(GLenum, GLint, GLenum, GLint, GLint, GLint, GLenum, GLenum, Uint8Array)`);if(!t(this,v)||!t(this,l)){this.setError(this.INVALID_ENUM);return}if(m===this.FLOAT&&!this._extensions.oes_texture_float){this.setError(this.INVALID_ENUM);return}let S=this._getTexImage(s);if(!S||v!==l){this.setError(this.INVALID_OPERATION);return}let C=this._computePixelSize(m,v);if(C===0||!this._checkDimensions(s,g,_,c))return;let w=n(h),T=this._computeRowStride(g,C),E=T*_;if(w&&w.length<E){this.setError(this.INVALID_OPERATION);return}if(x!==0||a(this,s)&&g!==_){this.setError(this.INVALID_VALUE);return}if(this._unpackPremultAlpha&&w&&v===this.RGBA&&(w=i(w)),this._unpackFlipY&&w&&g>0&&_>0){let e=new Uint8Array(w.length);for(let t=0;t<_;t++){let n=t*T,r=(_-1-t)*T;e.set(w.subarray(n,n+T),r)}w=e}let D=this._legacyFormatStorage(v,m);this._saveError(),this._gl.texImage2D(s,c,D?D.internalFormat:this._nativeFloatInternalFormat(l,m),g,_,x,D?D.format:v,m,e(w));let O=this.getError();if(this._restoreError(O),O!==this.NO_ERROR)return;this._setTextureSwizzle(s,S,D?D.swizzle:null),S._levelWidth[c]=g,S._levelHeight[c]=_,S._format=v,S._type=m;let k=this._activeFramebuffer;if(k){let e=!1,t=this._getAttachments();for(let n=0;n<t.length;++n)if(k._attachments[t[n]]===S){e=!0;break}e&&this._activeFramebuffer&&this._updateFramebufferAttachments(this._activeFramebuffer)}},texSubImage2D(t=0,a=0,s=0,c=0,l=0,u=0,d=0,f=0,p){let m=0,h=0,g=0,_,v;if(arguments.length===7)if(f=u,g=l,d instanceof o.Pixbuf)v=d,m=v.get_width(),h=v.get_height(),p=v.get_pixels();else{_=d;let e=r(_);if(e==null)throw TypeError(`texSubImage2D(GLenum, GLint, GLint, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)`);m=e.width,h=e.height,p=e.data}else m=l,h=u,g=d;if(typeof p!=`object`)throw TypeError(`texSubImage2D(GLenum, GLint, GLint, GLint, GLint, GLint, GLenum, GLenum, Uint8Array)`);let y=this._getTexImage(t);if(!y){this.setError(this.INVALID_OPERATION);return}if(this._legacySubImageMismatch(y,g)){this.setError(this.INVALID_OPERATION);return}if(f===this.FLOAT&&!this._extensions.oes_texture_float){this.setError(this.INVALID_ENUM);return}let b=this._computePixelSize(f,g);if(b===0||!this._checkDimensions(t,m,h,a))return;if(s<0||c<0){this.setError(this.INVALID_VALUE);return}let x=n(p),S=this._computeRowStride(m,b),C=S*h;if(!x||x.length<C){this.setError(this.INVALID_OPERATION);return}if(this._unpackPremultAlpha&&x&&g===this.RGBA&&(x=i(x)),this._unpackFlipY&&x&&m>0&&h>0){let e=new Uint8Array(x.length);for(let t=0;t<h;t++){let n=t*S,r=(h-1-t)*S;e.set(x.subarray(n,n+S),r)}x=e}let w=this._legacyFormatStorage(g,f)?.format??g;this._gl.texSubImage2D(t,a,s,c,m,h,w,f,e(x))}};function installTexImage2DMethods(e){Object.assign(e,s)}export{installTexImage2DMethods};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{__name as e}from"./_virtual/_rolldown/runtime.js";import{describe as t,expect as n,it as r,on as i}from"@gjsify/unit";import{WebGLBridge as a}from"@gjsify/webgl";import o from"@girs/glib-2.0";import s from"@girs/gtk-4.0";function nativeGl(e){return e._native}function spinUntil(e,t=1e4){let n=o.MainContext.default(),r=o.get_monotonic_time()+t*1e3,i=o.timeout_add(o.PRIORITY_DEFAULT,50,()=>o.SOURCE_CONTINUE);for(;!e()&&o.get_monotonic_time()<r;)n.iteration(!0);return o.source_remove(i),e()}var c=e(async()=>{await i(`Gl`,async()=>{s.init();let e=new s.Window({default_width:320,default_height:240}),i=new a;i.set_hexpand(!0),i.set_vexpand(!0),i.installGlobals();let c=[];i.connect(`resize`,(e,t,n)=>{c.push([t,n])});let l=null,u=null;i.onReady((e,t)=>{l=e,u=t}),e.set_child(i),e.present(),spinUntil(()=>u!==null);let captureFrame=()=>{let e=null;return i.requestAnimationFrame(()=>{let t=u,n=l,r=Array.from(nativeGl(t).getParameteriv(2978,4)),a=t.drawingBufferWidth,o=t.drawingBufferHeight;t.enable(t.SCISSOR_TEST),t.scissor(0,0,a,o),t.clearColor(1,0,0,1),t.clear(t.COLOR_BUFFER_BIT),t.scissor(a-1,o-1,1,1),t.clearColor(0,1,0,1),t.clear(t.COLOR_BUFFER_BIT),t.disable(t.SCISSOR_TEST);let s=new Uint8Array(4);t.readPixels(a-1,o-1,1,1,t.RGBA,t.UNSIGNED_BYTE,s),e={allocW:i.get_allocated_width(),allocH:i.get_allocated_height(),scale:i.get_scale_factor(),dpr:globalThis.devicePixelRatio,canvasW:n.width,canvasH:n.height,clientW:n.clientWidth,clientH:n.clientHeight,bufferW:a,bufferH:o,gtkViewport:r,farCorner:Array.from(s)}}),spinUntil(()=>e!==null),e},assertFrame=async(e,i)=>{await t(`WebGLBridge HiDPI on a real GLArea — ${e}`,async()=>{await r(`renders a frame`,async()=>{n(i()).not.toBeNull()}),await r(`devicePixelRatio is the widget scale factor`,async()=>{let e=i();n(e.scale).toBeGreaterThan(0),n(e.dpr).toBe(e.scale)}),await r(`drawing buffer = CSS size × devicePixelRatio`,async()=>{let e=i();n(e.clientW).toBe(e.allocW),n(e.clientH).toBe(e.allocH),n(e.canvasW).toBe(e.clientW*e.dpr),n(e.canvasH).toBe(e.clientH*e.dpr),n(e.bufferW).toBe(e.canvasW),n(e.bufferH).toBe(e.canvasH)}),await r(`matches the size GTK's resize signal gave in device pixels`,async()=>{let e=i(),t=c[c.length-1];n(t).toBeDefined(),n(t[0]).toBe(e.bufferW),n(t[1]).toBe(e.bufferH)}),await r(`matches the viewport GTK bound for the render`,async()=>{let e=i();n(e.gtkViewport.join(`,`)).toBe(`0,0,${e.bufferW},${e.bufferH}`)}),await r(`reaches the top-right device pixel of the framebuffer`,async()=>{n(i().farCorner.join(`,`)).toBe(`0,255,0,255`)})})};n(u).not.toBeNull();let d=captureFrame();await assertFrame(`initial size`,()=>d);let f=o.getenv(`GJSIFY_TEST_EXPECT_SCALE`);f&&await t(`WebGLBridge HiDPI — requested scale took effect`,async()=>{await r(`runs at scale ${f}`,async()=>{n(d?.scale).toBe(Number(f))})});let p=c.length,m=(d?.allocW??320)+160,h=(d?.allocH??240)+120;i.set_size_request(m,h),spinUntil(()=>c.length>p&&i.get_allocated_width()>=m);let g=captureFrame();await assertFrame(`after resize`,()=>g),await t(`WebGLBridge HiDPI — resize`,async()=>{await r(`the drawing buffer followed the new allocation`,async()=>{n(g.allocW).toBeGreaterThan(d.allocW),n(g.bufferW).toBe(g.allocW*g.scale),n(g.bufferH).toBe(g.allocH*g.scale)})}),e.destroy()})},`default`);export{c as default};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{__name as e}from"./_virtual/_rolldown/runtime.js";import{destroyTestFBO as t,drawTriangle as n,makeProgram as r,makeTestFBO as i,readPixel as a}from"./test-utils.js";import{beforeEach as o,describe as s,expect as c,it as l,on as u}from"@gjsify/unit";import{WebGLBridge as d}from"@gjsify/webgl";import f from"@girs/glib-2.0";import p from"@girs/gtk-4.0";const m=[`attribute vec2 position;`,`varying vec2 vUv;`,`void main() { vUv = position * 0.5 + 0.5; gl_Position = vec4(position, 0.0, 1.0); }`].join(`
|
|
2
|
+
`),h=[`precision mediump float;`,`uniform sampler2D uTex;`,`varying vec2 vUv;`,`void main() { gl_FragColor = texture2D(uTex, vUv); }`].join(`
|
|
3
|
+
`),g=[`#version 300 es`,`in vec2 position;`,`void main() { gl_Position = vec4(position, 0.0, 1.0); }`].join(`
|
|
4
|
+
`),_=[`#version 300 es`,`precision mediump float;`,`precision mediump sampler2DArray;`,`uniform sampler2DArray uTex;`,`out vec4 fragColor;`,`void main() { fragColor = texture(uTex, vec3(0.5, 0.5, 0.0)); }`].join(`
|
|
5
|
+
`);function realize(e){let t=new f.MainLoop(null,!1),n=new p.Window({});n.set_default_size(64,64);let r=new d,i={area:r,win:n,gl:null};r.onReady((n,r)=>{i.gl=e===`webgl`?r:n.getContext(`webgl2`),t.quit()}),n.set_child(r),n.present();let a=f.timeout_add(f.PRIORITY_DEFAULT,1e4,()=>(t.quit(),f.SOURCE_REMOVE));return t.run(),f.source_remove(a),r.make_current(),i}function sampleUpload(e,t,n,r,i){let a=e.createTexture();e.bindTexture(e.TEXTURE_2D,a),e.texImage2D(e.TEXTURE_2D,0,n,r,r,0,n,e.UNSIGNED_BYTE,i);let o=e.getError(),s=sampleTexture(e,t,a);return e.deleteTexture(a),{pixel:s,error:o}}function sampleTexture(e,r,o){let s=i(e,4,4);e.bindTexture(e.TEXTURE_2D,o),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.clearColor(.5,.5,.5,.5),e.clear(e.COLOR_BUFFER_BIT),e.useProgram(r),e.uniform1i(e.getUniformLocation(r,`uTex`),0),n(e);let c=a(e,0,0);return t(e,s),c}const rgba=e=>Array.from(e);var v=e(async()=>{await u(`Gl`,async()=>{p.init(),await s(`core-profile gaps: WebGL1`,async()=>{let{gl:e,win:n,area:a}=realize(`webgl`);if(!e){console.warn(`WebGL context not available after 10s — skipping tests`),n.destroy();return}let s=e,u=r(s,m,h);o(async()=>{a.make_current(),s.activeTexture(s.TEXTURE0),s.pixelStorei(s.UNPACK_ALIGNMENT,1),s.getError()}),await l(`samples ALPHA as (0, 0, 0, a)`,async()=>{let{pixel:e,error:t}=sampleUpload(s,u,s.ALPHA,2,new Uint8Array([200,200,200,200]));c(t).toBe(s.NO_ERROR),c(rgba(e)).toStrictEqual([0,0,0,200])}),await l(`samples LUMINANCE as (l, l, l, 1)`,async()=>{let{pixel:e,error:t}=sampleUpload(s,u,s.LUMINANCE,2,new Uint8Array([90,90,90,90]));c(t).toBe(s.NO_ERROR),c(rgba(e)).toStrictEqual([90,90,90,255])}),await l(`samples LUMINANCE_ALPHA as (l, l, l, a)`,async()=>{let e=new Uint8Array([60,180,60,180,60,180,60,180]),{pixel:t,error:n}=sampleUpload(s,u,s.LUMINANCE_ALPHA,2,e);c(n).toBe(s.NO_ERROR),c(rgba(t)).toStrictEqual([60,60,60,180])}),await l(`texSubImage2D writes both LUMINANCE_ALPHA channels`,async()=>{let e=s.createTexture();s.bindTexture(s.TEXTURE_2D,e),s.texImage2D(s.TEXTURE_2D,0,s.LUMINANCE_ALPHA,1,1,0,s.LUMINANCE_ALPHA,s.UNSIGNED_BYTE,null),s.texSubImage2D(s.TEXTURE_2D,0,0,0,1,1,s.LUMINANCE_ALPHA,s.UNSIGNED_BYTE,new Uint8Array([30,240])),c(s.getError()).toBe(s.NO_ERROR),c(rgba(sampleTexture(s,u,e))).toStrictEqual([30,30,30,240]),s.deleteTexture(e)}),await l(`re-specifying a LUMINANCE texture as RGBA samples plain RGBA`,async()=>{let e=s.createTexture();s.bindTexture(s.TEXTURE_2D,e),s.texImage2D(s.TEXTURE_2D,0,s.LUMINANCE,1,1,0,s.LUMINANCE,s.UNSIGNED_BYTE,new Uint8Array([7])),s.texImage2D(s.TEXTURE_2D,0,s.RGBA,1,1,0,s.RGBA,s.UNSIGNED_BYTE,new Uint8Array([10,20,30,40])),c(s.getError()).toBe(s.NO_ERROR),c(rgba(sampleTexture(s,u,e))).toStrictEqual([10,20,30,40]),s.deleteTexture(e)}),await l(`copyTexImage2D takes the framebuffer alpha into ALPHA and LUMINANCE_ALPHA`,async()=>{let e=[[s.ALPHA,[0,0,0,204]],[s.LUMINANCE,[51,51,51,255]],[s.LUMINANCE_ALPHA,[51,51,51,204]]];for(let[n,r]of e){let e=i(s,2,2);s.clearColor(.2,.4,.6,.8),s.clear(s.COLOR_BUFFER_BIT);let a=s.createTexture();s.bindTexture(s.TEXTURE_2D,a),s.copyTexImage2D(s.TEXTURE_2D,0,n,0,0,2,2,0),c(s.getError()).toBe(s.NO_ERROR),t(s,e),c(rgba(sampleTexture(s,u,a))).toStrictEqual(r),s.deleteTexture(a)}}),await l(`copyTexSubImage2D updates an ALPHA texture from the framebuffer alpha`,async()=>{let e=i(s,1,1);s.clearColor(1,1,1,.4),s.clear(s.COLOR_BUFFER_BIT);let n=s.createTexture();s.bindTexture(s.TEXTURE_2D,n),s.texImage2D(s.TEXTURE_2D,0,s.ALPHA,1,1,0,s.ALPHA,s.UNSIGNED_BYTE,new Uint8Array([0])),s.copyTexSubImage2D(s.TEXTURE_2D,0,0,0,0,0,1,1),c(s.getError()).toBe(s.NO_ERROR),t(s,e),c(rgba(sampleTexture(s,u,n))).toStrictEqual([0,0,0,102]),s.deleteTexture(n)}),await l(`refuses a sub-upload in another format than the legacy image`,async()=>{let e=s.createTexture();s.bindTexture(s.TEXTURE_2D,e),s.texImage2D(s.TEXTURE_2D,0,s.LUMINANCE,1,1,0,s.LUMINANCE,s.UNSIGNED_BYTE,new Uint8Array([90])),c(s.getError()).toBe(s.NO_ERROR),s.texSubImage2D(s.TEXTURE_2D,0,0,0,1,1,s.ALPHA,s.UNSIGNED_BYTE,new Uint8Array([7])),c(s.getError()).toBe(s.INVALID_OPERATION),s.texSubImage2D(s.TEXTURE_2D,0,0,0,1,1,s.RGBA,s.UNSIGNED_BYTE,new Uint8Array([7,7,7,7])),c(s.getError()).toBe(s.INVALID_OPERATION),c(rgba(sampleTexture(s,u,e))).toStrictEqual([90,90,90,255]),s.deleteTexture(e)}),await l(`a legacy-format texture is no complete color attachment`,async()=>{let e=s.createTexture();s.bindTexture(s.TEXTURE_2D,e),s.texImage2D(s.TEXTURE_2D,0,s.ALPHA,2,2,0,s.ALPHA,s.UNSIGNED_BYTE,null);let t=s.createFramebuffer();s.bindFramebuffer(s.FRAMEBUFFER,t),s.framebufferTexture2D(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0,s.TEXTURE_2D,e,0),c(s.checkFramebufferStatus(s.FRAMEBUFFER)).not.toBe(s.FRAMEBUFFER_COMPLETE),s.framebufferTexture2D(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0,s.TEXTURE_2D,null,0),s.bindFramebuffer(s.FRAMEBUFFER,null),s.deleteFramebuffer(t),s.deleteTexture(e),s.getError()}),await l(`GENERATE_MIPMAP_HINT starts at DONT_CARE and reports what hint() set`,async()=>{c(s.getParameter(s.GENERATE_MIPMAP_HINT)).toBe(s.DONT_CARE),s.hint(s.GENERATE_MIPMAP_HINT,s.NICEST),c(s.getError()).toBe(s.NO_ERROR),c(s.getParameter(s.GENERATE_MIPMAP_HINT)).toBe(s.NICEST),s.hint(s.GENERATE_MIPMAP_HINT,s.DONT_CARE),c(s.getError()).toBe(s.NO_ERROR)}),await l(`refuses a second shader of the same stage`,async()=>{let e=s.createProgram(),t=s.createShader(s.FRAGMENT_SHADER),n=s.createShader(s.FRAGMENT_SHADER);s.attachShader(e,t),s.attachShader(e,n),c(s.getError()).toBe(s.INVALID_OPERATION),c(s.getAttachedShaders(e)?.length).toBe(1),s.deleteProgram(e),s.deleteShader(t),s.deleteShader(n)}),await l(`a program without a fragment shader fails to link, use and validate`,async()=>{let e=s.createShader(s.VERTEX_SHADER);s.shaderSource(e,m),s.compileShader(e);let t=s.createProgram();s.attachShader(t,e),s.linkProgram(t),c(s.getProgramParameter(t,s.LINK_STATUS)).toBe(!1),c((s.getProgramInfoLog(t)??``).length).toBeGreaterThan(0);let n=r(s,m,`precision mediump float;
|
|
6
|
+
void main() { gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); }`);s.useProgram(n),s.getError(),s.useProgram(t),c(s.getError()).toBe(s.INVALID_OPERATION),c(s.getParameter(s.CURRENT_PROGRAM)).toBe(n),s.validateProgram(t),c(s.getProgramParameter(t,s.VALIDATE_STATUS)).toBe(!1),s.useProgram(null),s.deleteProgram(n),s.deleteProgram(t),s.deleteShader(e)}),await l(`a link WebGL refuses keeps an error queued before it`,async()=>{let e=s.createShader(s.VERTEX_SHADER);s.shaderSource(e,m),s.compileShader(e);let t=s.createProgram();s.attachShader(t,e),s.getError(),s.hint(4660,s.NICEST),s.linkProgram(t),c(s.getProgramParameter(t,s.LINK_STATUS)).toBe(!1),c(s.getError()).toBe(s.INVALID_ENUM),s.deleteProgram(t),s.deleteShader(e)}),s.pixelStorei(s.UNPACK_ALIGNMENT,4),s.deleteProgram(u),n.destroy()}),await s(`core-profile gaps: WebGL2`,async()=>{let{gl:e,win:s,area:u}=realize(`webgl2`);if(!e){console.warn(`WebGL2 context not available after 10s — skipping tests`),s.destroy();return}let d=e,f=d;o(async()=>{u.make_current(),d.pixelStorei(d.UNPACK_ALIGNMENT,1),d.getError()}),await l(`samples an unsized LUMINANCE_ALPHA texImage2D as (l, l, l, a)`,async()=>{let e=r(f,m,h),t=new Uint8Array([60,180,60,180,60,180,60,180]),{pixel:n,error:i}=sampleUpload(f,e,d.LUMINANCE_ALPHA,2,t);c(i).toBe(d.NO_ERROR),c(rgba(n)).toStrictEqual([60,60,60,180]),d.deleteProgram(e)}),await l(`samples an unsized ALPHA texImage3D array layer as (0, 0, 0, a)`,async()=>{let e=r(f,g,_);c(d.getProgramParameter(e,d.LINK_STATUS)).toBe(!0);let o=d.createTexture();d.bindTexture(d.TEXTURE_2D_ARRAY,o),d.texImage3D(d.TEXTURE_2D_ARRAY,0,d.ALPHA,1,1,1,0,d.ALPHA,d.UNSIGNED_BYTE,new Uint8Array([77])),c(d.getError()).toBe(d.NO_ERROR),d.texParameteri(d.TEXTURE_2D_ARRAY,d.TEXTURE_MIN_FILTER,d.NEAREST),d.texParameteri(d.TEXTURE_2D_ARRAY,d.TEXTURE_MAG_FILTER,d.NEAREST);let s=i(f,4,4);d.clearColor(.5,.5,.5,.5),d.clear(d.COLOR_BUFFER_BIT),d.useProgram(e),n(f);let l=a(f,0,0);t(f,s),c(rgba(l)).toStrictEqual([0,0,0,77]),d.deleteTexture(o),d.deleteProgram(e)}),await l(`copyTexSubImage3D takes the framebuffer alpha into an ALPHA array layer`,async()=>{let e=r(f,g,_),o=d.createTexture();d.bindTexture(d.TEXTURE_2D_ARRAY,o),d.texImage3D(d.TEXTURE_2D_ARRAY,0,d.ALPHA,1,1,1,0,d.ALPHA,d.UNSIGNED_BYTE,new Uint8Array([0])),d.texParameteri(d.TEXTURE_2D_ARRAY,d.TEXTURE_MIN_FILTER,d.NEAREST),d.texParameteri(d.TEXTURE_2D_ARRAY,d.TEXTURE_MAG_FILTER,d.NEAREST);let s=i(f,1,1);d.clearColor(1,1,1,.4),d.clear(d.COLOR_BUFFER_BIT),d.bindTexture(d.TEXTURE_2D_ARRAY,o),d.copyTexSubImage3D(d.TEXTURE_2D_ARRAY,0,0,0,0,0,0,1,1),c(d.getError()).toBe(d.NO_ERROR),t(f,s);let l=i(f,4,4);d.clearColor(.5,.5,.5,.5),d.clear(d.COLOR_BUFFER_BIT),d.useProgram(e),n(f);let u=a(f,0,0);t(f,l),c(rgba(u)).toStrictEqual([0,0,0,102]),d.deleteTexture(o),d.deleteProgram(e)}),await l(`an unsized LUMINANCE texture is no complete color attachment`,async()=>{let e=d.createTexture();d.bindTexture(d.TEXTURE_2D,e),d.texImage2D(d.TEXTURE_2D,0,d.LUMINANCE,2,2,0,d.LUMINANCE,d.UNSIGNED_BYTE,null);let t=d.createFramebuffer();d.bindFramebuffer(d.FRAMEBUFFER,t),d.framebufferTexture2D(d.FRAMEBUFFER,d.COLOR_ATTACHMENT0,d.TEXTURE_2D,e,0),c(d.checkFramebufferStatus(d.FRAMEBUFFER)).toBe(d.FRAMEBUFFER_INCOMPLETE_ATTACHMENT),d.framebufferTexture2D(d.FRAMEBUFFER,d.COLOR_ATTACHMENT0,d.TEXTURE_2D,null,0),d.bindFramebuffer(d.FRAMEBUFFER,null),d.deleteFramebuffer(t),d.deleteTexture(e),d.getError()}),await l(`refuses TEXTURE_SWIZZLE_* and keeps a failed texStorage2D from resetting one`,async()=>{let e=d.createTexture();d.bindTexture(d.TEXTURE_2D_ARRAY,e),d.texParameteri(d.TEXTURE_2D_ARRAY,36418,d.ONE),c(d.getError()).toBe(d.INVALID_ENUM),d.deleteTexture(e);let t=r(f,m,h),n=d.createTexture();d.bindTexture(d.TEXTURE_2D,n),d.texImage2D(d.TEXTURE_2D,0,d.LUMINANCE,1,1,0,d.LUMINANCE,d.UNSIGNED_BYTE,new Uint8Array([90])),d.texStorage2D(d.TEXTURE_2D,1,d.ALPHA,1,1),c(d.getError()).not.toBe(d.NO_ERROR),c(rgba(sampleTexture(f,t,n))).toStrictEqual([90,90,90,255]),d.deleteTexture(n),d.deleteProgram(t)}),d.pixelStorei(d.UNPACK_ALIGNMENT,4),s.destroy()})})},`default`);export{v as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"./hidpi.spec.js";import{run as t}from"@gjsify/unit";t({testSuite:e});
|
package/lib/esm/test.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import e from"./html-canvas-element.spec.js";import
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import e from"./context/shader-program/glsl1-desktop.spec.js";import t from"./context/texture-management/legacy-formats.spec.js";import n from"./hidpi.spec.js";import r from"./html-canvas-element.spec.js";import i from"./legacy-core-profile.spec.js";import a from"./register.spec.js";import o from"./software-renderer.spec.js";import s from"./webgl1.spec.js";import c from"./webgl2.spec.js";import{run as l}from"@gjsify/unit";l({testSuite:async()=>{await s(),await c(),await r(),await n(),await o(),await e(),await t(),await i()},registerSuite:a});
|
|
@@ -1 +1,5 @@
|
|
|
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};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{flag as e}from"./utils.js";import{IDENTITY_SWIZZLE as t,TEXTURE_SWIZZLE_PNAMES as n,coreStorageForLegacyFormat as r,isLegacyFormat as i,textureParameterTarget as a}from"./context/texture-management/legacy-formats.js";import{installAllContextMethods as o}from"./context/index.js";import{getEXTBlendMinMax as s}from"./extensions/ext-blend-minmax.js";import{getEXTColorBufferFloat as c}from"./extensions/ext-color-buffer-float.js";import{getEXTColorBufferHalfFloat as l}from"./extensions/ext-color-buffer-half-float.js";import{getEXTTextureFilterAnisotropic as u}from"./extensions/ext-texture-filter-anisotropic.js";import{getOESElementIndexUint as d}from"./extensions/oes-element-index-unit.js";import{getOESStandardDerivatives as f}from"./extensions/oes-standard-derivatives.js";import{getOESTextureFloatLinear as p}from"./extensions/oes-texture-float-linear.js";import{getOESTextureFloat as m}from"./extensions/oes-texture-float.js";import{getOESTextureHalfFloat as h}from"./extensions/oes-texture-half-float.js";import{getSTACKGLDestroyContext as g}from"./extensions/stackgl-destroy-context.js";import{getSTACKGLResizeDrawingBuffer as _}from"./extensions/stackgl-resize-drawing-buffer.js";import{getWEBGLDebugRendererInfo as v}from"./extensions/webgl-debug-renderer-info.js";import{WebGLContextAttributes as y}from"./webgl-context-attributes.js";import{WebGLTextureUnit as b}from"./webgl-texture-unit.js";import{WebGLVertexArrayGlobalState as x,WebGLVertexArrayObjectState as S}from"./webgl-vertex-attribute.js";import*as C from"bit-twiddle";import w from"@girs/gwebgl-0.1";import"@girs/gdkpixbuf-2.0";import{openNativeLibrary as T}from"@gjsify/utils/core";import{warnNotImplemented as E}from"@gjsify/utils";let D=0;const O={oes_element_index_uint:d,oes_texture_float:m,oes_texture_float_linear:p,oes_standard_derivatives:f,stackgl_destroy_context:g,stackgl_resize_drawingbuffer:_,ext_blend_minmax:s,ext_color_buffer_float:c,ext_color_buffer_half_float:l,ext_texture_filter_anisotropic:u,oes_texture_half_float:h,webgl_debug_renderer_info:v};let k=!1;function openGwebgl(){if(k)return;let e=T(`Gwebgl`);if(e)throw e;k=!0}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._generateMipmapHint=4352,this._viewport=new Int32Array([0,0,0,0]),this._scissorBox=new Int32Array([0,0,0,0]),this._gtkFboId=0,this._textureUnits=[],this._drawingBuffer=null,openGwebgl(),this.canvas=t,this._contextAttributes=new y(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._=D++;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 b(this,e);this.activeTexture(this.TEXTURE0),this._defaultVertexObjectState=new S(this),this._vertexObjectState=this._defaultVertexObjectState,this._vertexGlobalState=new x(this),this._maxTextureSize=this.getParameter(this.MAX_TEXTURE_SIZE),this._maxTextureLevel=C.log2(C.nextPow2(this._maxTextureSize)),this._maxCubeMapSize=this.getParameter(this.MAX_CUBE_MAP_TEXTURE_SIZE),this._maxCubeMapLevel=C.log2(C.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 w.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}_nativeFloatInternalFormat(e,t){return t!==this.FLOAT||!this._atLeastGlVersion(3,0)?e:e===this.RGBA?34836:e===this.RGB?34837:e}_isCoreProfile(){if(this._coreProfile!==void 0)return this._coreProfile;let e=!1;return this._atLeastGlVersion(3,2)&&(e=(this._gl.getParameteri(37158)&1)!=0),this._coreProfile=e,e}_emulatesLegacyFormats(){return this._legacyFormatEmulation===void 0&&(this._legacyFormatEmulation=this._isCoreProfile()&&this._atLeastGlVersion(3,3)),this._legacyFormatEmulation}_legacyFormatStorage(e,t){return!i(e)||!this._emulatesLegacyFormats()?null:r(e,t)}_legacySubImageMismatch(e,t){return(i(t)||i(e._format))&&t!==e._format}_setTextureSwizzle(e,r,i){if(!i&&(r?!r._swizzled:!this._emulatesLegacyFormats()))return;let o=i??t,s=a(e);for(let e=0;e<4;++e)this._gl.texParameteri(s,n[e],o[e]);r&&(r._swizzled=i!==null)}_desktopGlslForEsDerivatives(){if(this._esDerivativesDesktopGlsl!==void 0)return this._esDerivativesDesktopGlsl;let e=null;if(this._atLeastGlVersion(4,1)){let t=this._gl.createShader(this.FRAGMENT_SHADER);this._gl.shaderSource(t,`#version 100
|
|
2
|
+
#extension GL_OES_standard_derivatives : enable
|
|
3
|
+
precision mediump float;
|
|
4
|
+
void main() { gl_FragColor = vec4(dFdx(gl_FragCoord.x)); }
|
|
5
|
+
`),this._gl.compileShader(t);let n=!!this._gl.getShaderParameter(t,this.COMPILE_STATUS);this._gl.deleteShader(t),n||(e=this._desktopGlslVersion())}return this._esDerivativesDesktopGlsl=e,e}_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=O[t]?O[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.indexOf(`GL_OES_element_index_uint`)>=0||this._atLeastGlVersion(1,1))&&e.push(`OES_element_index_uint`),(t.indexOf(`GL_OES_standard_derivatives`)>=0||this._atLeastGlVersion(2,0))&&e.push(`OES_standard_derivatives`),(t.indexOf(`GL_OES_texture_float`)>=0||this._atLeastGlVersion(3,0))&&e.push(`OES_texture_float`),(t.indexOf(`GL_OES_texture_float_linear`)>=0||this._atLeastGlVersion(3,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(`GL_EXT_blend_minmax`)>=0||this._atLeastGlVersion(1,4))&&e.push(`EXT_blend_minmax`),(t.indexOf(`GL_EXT_texture_filter_anisotropic`)>=0||t.indexOf(`GL_ARB_texture_filter_anisotropic`)>=0||this._atLeastGlVersion(4,6))&&e.push(`EXT_texture_filter_anisotropic`),t.indexOf(`GL_OES_vertex_array_object`)>=0&&e.push(`OES_vertex_array_object`),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.GENERATE_MIPMAP_HINT:return this._generateMipmapHint;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.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._gl.getParameterf(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(){E(`destroy`)}};o(WebGLContextBase.prototype);export{WebGLContextBase};
|
package/lib/esm/webgl-shader.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{Linkable as e}from"./linkable.js";var WebGLShader=class extends e{constructor(e,t,n){super(e),this._source=``,this._compileStatus=!1,this._compileInfo=``,this._needsRecompile=!1,this._type=n,this._ctx=t,this._source=``,this._compileStatus=!1,this._compileInfo=``}_performDelete(){let e=this._ctx;delete e._shaders[this._|0],e._gl.deleteShader(this._|0)}};export{WebGLShader};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{Linkable as e}from"./linkable.js";var WebGLShader=class extends e{constructor(e,t,n){super(e),this._source=``,this._userSource=``,this._needsDesktop=!1,this._desktopSpelled=!1,this._compileStatus=!1,this._compileInfo=``,this._needsRecompile=!1,this._type=n,this._ctx=t,this._source=``,this._compileStatus=!1,this._compileInfo=``}_performDelete(){let e=this._ctx;delete e._shaders[this._|0],e._gl.deleteShader(this._|0)}};export{WebGLShader};
|
package/lib/esm/webgl-texture.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{Linkable as e}from"./linkable.js";var WebGLTexture=class extends e{constructor(e,t){super(e),this._binding=0,this._levelWidth=new Int32Array(32),this._levelHeight=new Int32Array(32),this._format=0,this._type=0,this._complete=!0,this._ctx=t}_performDelete(){let e=this._ctx;delete e._textures[this._|0],e._gl.deleteTexture(this._|0)}};export{WebGLTexture};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{Linkable as e}from"./linkable.js";var WebGLTexture=class extends e{constructor(e,t){super(e),this._binding=0,this._levelWidth=new Int32Array(32),this._levelHeight=new Int32Array(32),this._format=0,this._type=0,this._complete=!0,this._swizzled=!1,this._ctx=t}_performDelete(){let e=this._ctx;delete e._textures[this._|0],e._gl.deleteTexture(this._|0)}};export{WebGLTexture};
|
package/lib/esm/webgl1.spec.js
CHANGED
|
@@ -1,4 +1,38 @@
|
|
|
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(`Gl`,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(`
|
|
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(`Gl`,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()});let n=`attribute vec2 position; void main() { gl_Position = vec4(position, 0.0, 1.0); }`,sampleFloatTexture=(e,o,s,l)=>{let u=a(p,1,1),d=p.createTexture();p.activeTexture(p.TEXTURE0),p.bindTexture(p.TEXTURE_2D,d),p.texImage2D(p.TEXTURE_2D,0,p.RGBA,o,1,0,p.RGBA,p.FLOAT,new Float32Array(e)),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_MIN_FILTER,s),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_MAG_FILTER,s),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);let f=i(p,n,l);p.useProgram(f),p.uniform1i(p.getUniformLocation(f,`t`),0),r(p);let m=c(p);return p.useProgram(null),p.deleteProgram(f),p.bindTexture(p.TEXTURE_2D,null),p.deleteTexture(d),t(p,u),m};await f(`OES_texture_float stores texels outside [0, 1] at full precision`,async()=>{d(p.getExtension(`OES_texture_float`)).not.toBeNull();let e=sampleFloatTexture([1.5,-1,.3,1],1,p.NEAREST,`precision highp float;
|
|
2
|
+
uniform sampler2D t;
|
|
3
|
+
void main() {
|
|
4
|
+
vec4 v = texture2D(t, vec2(0.5));
|
|
5
|
+
gl_FragColor = vec4(
|
|
6
|
+
v.r > 1.25 ? 1.0 : 0.0,
|
|
7
|
+
v.g < -0.5 ? 1.0 : 0.0,
|
|
8
|
+
abs(v.b - 0.3) < 0.001 ? 1.0 : 0.0,
|
|
9
|
+
1.0);
|
|
10
|
+
}`);d(p.getError()).toBe(p.NO_ERROR),d(s(e,[255,255,255,255])).toBeTruthy()}),await f(`OES_texture_float_linear filters a float texture`,async()=>{d(p.getExtension(`OES_texture_float`)).not.toBeNull(),d(p.getExtension(`OES_texture_float_linear`)).not.toBeNull();let e=sampleFloatTexture([0,0,0,1,4,0,0,1],2,p.LINEAR,`precision highp float;
|
|
11
|
+
uniform sampler2D t;
|
|
12
|
+
void main() {
|
|
13
|
+
float r = texture2D(t, vec2(0.5, 0.5)).r;
|
|
14
|
+
gl_FragColor = vec4(abs(r - 2.0) < 0.01 ? 1.0 : 0.0, 0.0, 0.0, 1.0);
|
|
15
|
+
}`);d(p.getError()).toBe(p.NO_ERROR),d(s(e,[255,0,0,255])).toBeTruthy()}),await f(`OES_standard_derivatives compiles and evaluates dFdx`,async()=>{let e=p.getExtension(`OES_standard_derivatives`);d(e).not.toBeNull(),p.hint(e.FRAGMENT_SHADER_DERIVATIVE_HINT_OES,p.NICEST),d(p.getError()).toBe(p.NO_ERROR);let o=a(p,4,4),l=i(p,n,`#extension GL_OES_standard_derivatives : enable
|
|
16
|
+
precision highp float;
|
|
17
|
+
void main() {
|
|
18
|
+
// The ES front end defines this wherever the extension is
|
|
19
|
+
// supported; a shader that branches on it must see it.
|
|
20
|
+
#ifdef GL_OES_standard_derivatives
|
|
21
|
+
// gl_FragCoord.x steps by exactly one per pixel.
|
|
22
|
+
float d = dFdx(gl_FragCoord.x);
|
|
23
|
+
#else
|
|
24
|
+
float d = 0.0;
|
|
25
|
+
#endif
|
|
26
|
+
gl_FragColor = vec4(abs(d - 1.0) < 0.01 ? 1.0 : 0.0, 0.0, 0.0, 1.0);
|
|
27
|
+
}`);d(p.getProgramParameter(l,p.LINK_STATUS)).toBe(!0),p.useProgram(l),r(p),d(p.getError()).toBe(p.NO_ERROR),d(s(c(p,1,1),[255,0,0,255])).toBeTruthy(),p.useProgram(null),p.deleteProgram(l),t(p,o)}),await f(`a vertex shader shared with a derivative program still links beside ES stages`,async()=>{p.getExtension(`OES_standard_derivatives`);let compile=(e,t)=>{let n=p.createShader(e);return p.shaderSource(n,t),p.compileShader(n),d(p.getShaderParameter(n,p.COMPILE_STATUS)).toBe(!0),n},link=(e,t)=>{let n=p.createProgram();return p.attachShader(n,e),p.attachShader(n,t),p.bindAttribLocation(n,0,`position`),p.linkProgram(n),n},e=compile(p.VERTEX_SHADER,n),i=compile(p.FRAGMENT_SHADER,`#extension GL_OES_standard_derivatives : enable
|
|
28
|
+
precision mediump float;
|
|
29
|
+
void main() { gl_FragColor = vec4(fwidth(gl_FragCoord.x), 0.0, 0.0, 1.0); }`),o=compile(p.FRAGMENT_SHADER,`void main() { gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); }`),l=link(e,o),u=link(e,i),f=link(e,o);d(p.getProgramParameter(l,p.LINK_STATUS)).toBe(!0),d(p.getProgramParameter(u,p.LINK_STATUS)).toBe(!0),d(p.getProgramParameter(f,p.LINK_STATUS)).toBe(!0),d(p.getShaderParameter(e,p.COMPILE_STATUS)).toBe(!0);let m=a(p,2,2);p.useProgram(f),r(p),d(s(c(p),[0,255,0,255])).toBeTruthy(),p.useProgram(u),r(p),d(s(c(p),[255,0,0,255])).toBeTruthy(),d(p.getError()).toBe(p.NO_ERROR),p.useProgram(null);for(let e of[l,u,f])p.deleteProgram(e);for(let t of[e,i,o])p.deleteShader(t);t(p,m)}),await f(`OES_element_index_uint draws with 32-bit indices`,async()=>{d(p.getExtension(`OES_element_index_uint`)).not.toBeNull();let e=a(p,8,8);p.clearColor(1,0,0,1),p.clear(p.COLOR_BUFFER_BIT);let r=i(p,n,`void main() { gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); }`);p.useProgram(r);let o=p.createBuffer();p.bindBuffer(p.ARRAY_BUFFER,o),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 c=p.createBuffer();p.bindBuffer(p.ELEMENT_ARRAY_BUFFER,c),p.bufferData(p.ELEMENT_ARRAY_BUFFER,new Uint32Array([0,1,2,2,1,3]),p.STATIC_DRAW),p.drawElements(p.TRIANGLES,6,p.UNSIGNED_INT,0),d(p.getError()).toBe(p.NO_ERROR);let l=new Uint8Array(e.width*e.height*4);p.readPixels(0,0,e.width,e.height,p.RGBA,p.UNSIGNED_BYTE,l);let u=!0;for(let e=0;e<l.length;e+=4)s(l.subarray(e,e+4),[0,255,0,255],0)||(u=!1);d(u).toBeTruthy(),p.disableVertexAttribArray(0),p.bindBuffer(p.ARRAY_BUFFER,null),p.bindBuffer(p.ELEMENT_ARRAY_BUFFER,null),p.deleteBuffer(o),p.deleteBuffer(c),p.useProgram(null),p.deleteProgram(r),t(p,e)}),await f("a derivative shader with `: require` and a sampler named `texture` draws",async()=>{p.getExtension(`OES_standard_derivatives`);let e=a(p,4,4),o=p.createTexture();p.activeTexture(p.TEXTURE0),p.bindTexture(p.TEXTURE_2D,o),p.texImage2D(p.TEXTURE_2D,0,p.RGBA,1,1,0,p.RGBA,p.UNSIGNED_BYTE,new Uint8Array([0,255,0,255])),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_MIN_FILTER,p.NEAREST);let l=i(p,n,`#extension GL_OES_standard_derivatives : require
|
|
30
|
+
precision highp float;
|
|
31
|
+
uniform sampler2D texture;
|
|
32
|
+
void main() {
|
|
33
|
+
float d = dFdx(gl_FragCoord.x);
|
|
34
|
+
gl_FragColor = texture2D(texture, vec2(0.5)) * (abs(d - 1.0) < 0.01 ? 1.0 : 0.0);
|
|
35
|
+
}`);d(p.getProgramParameter(l,p.LINK_STATUS)).toBe(!0),p.useProgram(l),p.uniform1i(p.getUniformLocation(l,`texture`),0),r(p),d(p.getError()).toBe(p.NO_ERROR),d(s(c(p,1,1),[0,255,0,255])).toBeTruthy(),p.useProgram(null),p.deleteProgram(l),p.bindTexture(p.TEXTURE_2D,null),p.deleteTexture(o),t(p,e)}),await f(`EXT_blend_minmax is advertised and MAX blends`,async()=>{let e=p.getExtension(`EXT_blend_minmax`);d(e).not.toBeNull(),d(p.getSupportedExtensions()).toContain(`EXT_blend_minmax`);let o=a(p,1,1);p.clearColor(.2,.8,0,1),p.clear(p.COLOR_BUFFER_BIT);let l=i(p,n,`precision mediump float; void main() { gl_FragColor = vec4(0.6, 0.4, 0.0, 1.0); }`);p.useProgram(l),p.enable(p.BLEND),p.blendEquation(e.MAX_EXT),p.blendFunc(p.ONE,p.ONE),r(p),d(p.getError()).toBe(p.NO_ERROR),d(s(c(p),[153,204,0,255])).toBeTruthy(),p.blendEquation(p.FUNC_ADD),p.disable(p.BLEND),p.useProgram(null),p.deleteProgram(l),t(p,o)}),await f(`EXT_texture_filter_anisotropic is advertised and takes its parameter`,async()=>{let e=p.getExtension(`EXT_texture_filter_anisotropic`);d(e).not.toBeNull(),d(p.getSupportedExtensions()).toContain(`EXT_texture_filter_anisotropic`),d(p.getParameter(e.MAX_TEXTURE_MAX_ANISOTROPY_EXT)).toBeGreaterThan(1);let t=p.createTexture();p.bindTexture(p.TEXTURE_2D,t),p.texParameterf(p.TEXTURE_2D,e.TEXTURE_MAX_ANISOTROPY_EXT,2),d(p.getError()).toBe(p.NO_ERROR),d(p.getTexParameter(p.TEXTURE_2D,e.TEXTURE_MAX_ANISOTROPY_EXT)).toBe(2),p.bindTexture(p.TEXTURE_2D,null),p.deleteTexture(t)}),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
36
|
`),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
37
|
`);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
38
|
`),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}from"../utils.js";const t={texImage3D(t,n,r,i,a,o,s,c,l,u){u===null?this._native2.texImage3DNull(t,n,
|
|
1
|
+
import"../_virtual/_rolldown/runtime.js";import{Uint8ArrayToVariant as e}from"../utils.js";function boundTexture3D(e,t){let n=t===32879?32874:t===35866?35869:0;return n?e._textures[e._gl.getParameteri(n)]??null:null}const t={texImage3D(t,n,r,i,a,o,s,c,l,u){let d=r===c?this._legacyFormatStorage(c,l):null,f=d?d.internalFormat:r,p=d?d.format:c;this._saveError(),u===null?this._native2.texImage3DNull(t,n,f,i,a,o,s,p,l):this._native2.texImage3D(t,n,f,i,a,o,s,p,l,e(new Uint8Array(u.buffer,u.byteOffset,u.byteLength)));let m=this.getError();if(this._restoreError(m),m!==this.NO_ERROR)return;let h=boundTexture3D(this,t);h&&(h._format=c,h._type=l),this._setTextureSwizzle(t,h,d?d.swizzle:null)},texSubImage3D(t,n,r,i,a,o,s,c,l,u,d){if(d===null)return;let f=boundTexture3D(this,t);if(f&&this._legacySubImageMismatch(f,l)){this.setError(this.INVALID_OPERATION);return}this._native2.texSubImage3D(t,n,r,i,a,o,s,c,this._legacyFormatStorage(l,u)?.format??l,u,e(new Uint8Array(d.buffer,d.byteOffset,d.byteLength)))},compressedTexImage3D(t,n,r,i,a,o,s,c,l){this._saveError(),this._native2.compressedTexImage3D(t,n,r,i,a,o,s,e(new Uint8Array(l.buffer,l.byteOffset,l.byteLength)));let u=this.getError();if(this._restoreError(u),u!==this.NO_ERROR)return;let d=boundTexture3D(this,t);d&&(d._format=r),this._setTextureSwizzle(t,d,null)},compressedTexSubImage3D(t,n,r,i,a,o,s,c,l,u,d){this._native2.compressedTexSubImage3D(t,n,r,i,a,o,s,c,l,e(new Uint8Array(d.buffer,d.byteOffset,d.byteLength)))},copyTexSubImage3D(e,t,n,r,i,a,o,s,c){let l=boundTexture3D(this,e)?._format??0;if((l===this.ALPHA||l===this.LUMINANCE_ALPHA)&&this._legacyFormatStorage(l,this.UNSIGNED_BYTE)){if(s<0||c<0){this.setError(this.INVALID_VALUE);return}this._copyLegacyChannels(l,a,o,s,c,(a,o)=>this._native2.texSubImage3D(e,t,n,r,i,s,c,1,a.format,this.UNSIGNED_BYTE,o));return}this._native2.copyTexSubImage3D(e,t,n,r,i,a,o,s,c)},texStorage2D(e,t,n,r,i){this._saveError(),this._native2.texStorage2D(e,t,n,r,i);let a=this.getError();if(this._restoreError(a),a!==this.NO_ERROR)return;let o=this._getTexImage(e);if(o){for(let e=0;e<t;e++)o._levelWidth[e]=Math.max(1,r>>e),o._levelHeight[e]=Math.max(1,i>>e);o._format=this.RGBA,o._type=this.UNSIGNED_BYTE,this._setTextureSwizzle(e,o,null)}},texStorage3D(e,t,n,r,i,a){this._saveError(),this._native2.texStorage3D(e,t,n,r,i,a);let o=this.getError();if(this._restoreError(o),o!==this.NO_ERROR)return;let s=boundTexture3D(this,e);s&&(s._format=this.RGBA,s._type=this.UNSIGNED_BYTE),this._setTextureSwizzle(e,s,null)}};function installTexImage3DMethods(e){Object.assign(e,t)}export{installTexImage3DMethods};
|
|
@@ -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`: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};
|
|
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{isLegacyFormat as u}from"./context/texture-management/legacy-formats.js";import{WebGLContextBase as d}from"./webgl-context-base.js";import{installObjectLifecycleMethods as f}from"./webgl2-context/object-lifecycle.js";import{installTexImage3DMethods as p}from"./webgl2-context/tex-image-3d.js";import{installUniformMethods as m}from"./webgl2-context/uniform.js";import{installClearBufferMethods as h}from"./webgl2-context/clear-buffer.js";import{installInstancedAndFramebufferOpsMethods as g}from"./webgl2-context/instanced-and-framebuffer-ops.js";import _ from"gi://GdkPixbuf?version=2.0";import v from"@girs/gwebgl-0.1";import{warnNotImplemented as y}from"@gjsify/utils";var b=class WebGL2RenderingContext extends d{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 v.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 e of i){let n=t[e];if(n instanceof l&&u(n._format))return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT}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&&!u(r._format)){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(t>=36418&&t<=36422){this.setError(this.INVALID_ENUM);return}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,g=0;if(arguments.length===6)if(d=c,h=s,l instanceof _.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,g=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}}let b=o===h?this._legacyFormatStorage(h,d):null;this._saveError(),this._gl.texImage2D(t,n,b?b.internalFormat:o,p,m,g,b?b.format:h,d,e(y));let x=this.getError();if(this._restoreError(x),x!==this.NO_ERROR)return;this._setTextureSwizzle(t,v,b?b.swizzle:null),v._levelWidth[n]=p,v._levelHeight[n]=m,v._format=h,v._type=d;let S=this._activeFramebuffer;if(S){let e=!1,t=this._getAttachments();for(let n=0;n<t.length;++n)if(S._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 _.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;let g=this._getTexImage(t);if(!g){this.setError(this.INVALID_OPERATION);return}if(this._legacySubImageMismatch(g,h)){this.setError(this.INVALID_OPERATION);return}let v=r(f);if(!v){this.setError(this.INVALID_OPERATION);return}if(this._unpackPremultAlpha&&v&&h===this.RGBA&&(v=a(v)),this._unpackFlipY&&v&&p>0&&m>0){let e=this._computePixelSize(d,h);if(e>0){let t=this._computeRowStride(p,e),n=new Uint8Array(v.length);for(let e=0;e<m;e++){let r=e*t,i=(m-1-e)*t;n.set(v.subarray(r,r+t),i)}v=n}}let y=this._legacyFormatStorage(h,d)?.format??h;this._gl.texSubImage2D(t,n,o,s,p,m,y,d,e(v))}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 y(`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}};f(b.prototype),p(b.prototype),m(b.prototype),h(b.prototype),g(b.prototype);export{b as WebGL2RenderingContext};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Does a source call one of the three OES_standard_derivatives built-ins? */
|
|
2
|
+
export declare const usesStandardDerivatives: (source: string) => boolean;
|
|
3
|
+
/**
|
|
4
|
+
* Respell a GLSL ES 1.00 source as desktop `#version <desktopVersion>` GLSL.
|
|
5
|
+
*
|
|
6
|
+
* Macros, not a parser: every construct ES 1.00 has and core desktop GLSL lost
|
|
7
|
+
* is a NAME (`attribute`, `varying`, `texture2D`, `gl_FragColor`, …), so a
|
|
8
|
+
* `#define` renames it in place and the consumer's lines stay as written, in
|
|
9
|
+
* order. Precision qualifiers need no help: desktop GLSL accepts and ignores
|
|
10
|
+
* them. `#line` directives put every consumer line back at its own number, so a
|
|
11
|
+
* compile error still names the line the consumer wrote — `desktopVersion` is
|
|
12
|
+
* always ≥ 330 here (the caller only respells on GL ≥ 4.1), where `#line N`
|
|
13
|
+
* numbers the NEXT line N.
|
|
14
|
+
*
|
|
15
|
+
* The fragment outputs are the one thing a macro cannot supply, since core GLSL
|
|
16
|
+
* needs them DECLARED. The declaration goes after the last `#extension`
|
|
17
|
+
* directive, because a directive after the first non-preprocessor token is an
|
|
18
|
+
* error in several front ends.
|
|
19
|
+
*
|
|
20
|
+
* `#extension GL_OES_standard_derivatives` is commented out: the derivatives are
|
|
21
|
+
* core desktop GLSL, and a desktop front end does not know the ES name — `: enable`
|
|
22
|
+
* would only warn, but `: require` is a compile error.
|
|
23
|
+
*
|
|
24
|
+
* `#ifdef GL_OES_standard_derivatives` must still answer as WebGL says: defined
|
|
25
|
+
* exactly when the consumer enabled the extension (`derivativesEnabled`), because
|
|
26
|
+
* consumers branch on it. It cannot simply be `#define`d: desktop GLSL reserves
|
|
27
|
+
* every `GL_`-prefixed macro name, and macOS refuses the definition ("#define of
|
|
28
|
+
* reserved name", measured). So the conditionals are pointed at an unreserved
|
|
29
|
+
* stand-in, defined only when the extension is on.
|
|
30
|
+
*/
|
|
31
|
+
export declare function translateGlsl1ToDesktop(source: string, stage: 'vertex' | 'fragment', desktopVersion: string, preamble: string, derivativesEnabled: boolean): string;
|
|
@@ -10,11 +10,15 @@ export interface ShaderLifecycleMethods {
|
|
|
10
10
|
getShaderPrecisionFormat(shaderType?: GLenum, precisionType?: GLenum): WebGLShaderPrecisionFormat | null;
|
|
11
11
|
getShaderSource(shader: WebGLShader): string | null;
|
|
12
12
|
_checkShaderSource(shader: WebGLShader): boolean;
|
|
13
|
-
_wrapShader(type: GLenum, source: string): string;
|
|
13
|
+
_wrapShader(type: GLenum, source: string, desktopSpelling?: boolean): string;
|
|
14
|
+
_needsDesktopSpelling(source: string): boolean;
|
|
15
|
+
_harmoniseShaderSpelling(shaders: WebGLShader[]): void;
|
|
14
16
|
}
|
|
15
17
|
declare module '../shader-program.js' {
|
|
16
18
|
interface ShaderProgramMethods extends ShaderLifecycleMethods {
|
|
17
19
|
}
|
|
18
20
|
}
|
|
21
|
+
/** Is a source GLSL ES 1.00 — versionless and GLSL1-shaped, or `#version 100`? */
|
|
22
|
+
export declare function isGlsl1Source(source: string): boolean;
|
|
19
23
|
/** Install shader-object lifecycle + source-validation methods on WebGLContextBase.prototype. */
|
|
20
24
|
export declare function installShaderLifecycleMethods(proto: object): void;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import type GLib from '@girs/glib-2.0';
|
|
1
2
|
import type { TypedArray } from '../../types/index.js';
|
|
3
|
+
import { type LegacyFormatStorage } from './legacy-formats.js';
|
|
2
4
|
export interface CopyAndCompressedTextureMethods {
|
|
3
5
|
copyTexImage2D(target?: GLenum, level?: GLint, internalFormat?: GLenum, x?: GLint, y?: GLint, width?: GLsizei, height?: GLsizei, border?: GLint): void;
|
|
4
6
|
copyTexSubImage2D(target?: GLenum, level?: GLint, xoffset?: GLint, yoffset?: GLint, x?: GLint, y?: GLint, width?: GLsizei, height?: GLsizei): void;
|
|
5
7
|
compressedTexImage2D(target: GLenum, level: GLint, internalFormat: GLenum, width: GLsizei, height: GLsizei, border: GLint, data: TypedArray): void;
|
|
6
8
|
compressedTexSubImage2D(target: GLenum, level: GLint, xoffset: GLint, yoffset: GLint, width: GLsizei, height: GLsizei, format: GLenum, data: TypedArray): void;
|
|
9
|
+
_copyLegacyChannels(format: GLenum, x: GLint, y: GLint, width: GLsizei, height: GLsizei, upload: (storage: LegacyFormatStorage, channels: GLib.Variant) => void): void;
|
|
7
10
|
}
|
|
8
11
|
declare module '../../webgl-context-base.js' {
|
|
9
12
|
interface WebGLContextBase extends CopyAndCompressedTextureMethods {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** `GL_TEXTURE_SWIZZLE_R/G/B/A` — core since GL 3.3, which every core profile the emulation runs on exceeds. */
|
|
2
|
+
export declare const TEXTURE_SWIZZLE_PNAMES: readonly [36418, 36419, 36420, 36421];
|
|
3
|
+
export type Swizzle = readonly [number, number, number, number];
|
|
4
|
+
/** What a texture samples as when nothing is emulated. */
|
|
5
|
+
export declare const IDENTITY_SWIZZLE: Swizzle;
|
|
6
|
+
/** How a legacy-format image is stored on a core profile. */
|
|
7
|
+
export interface LegacyFormatStorage {
|
|
8
|
+
/** Sized internal format handed to the driver. */
|
|
9
|
+
internalFormat: number;
|
|
10
|
+
/** Pixel-transfer format handed to the driver (`RED` or `RG`). */
|
|
11
|
+
format: number;
|
|
12
|
+
/** Texture swizzle that makes the stored channels sample as the legacy format. */
|
|
13
|
+
swizzle: Swizzle;
|
|
14
|
+
}
|
|
15
|
+
export declare function isLegacyFormat(format: number): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* The core-profile storage for a legacy-format image of `type`, or `null` when
|
|
18
|
+
* `format` is not a legacy format or `type` is one the legacy formats never
|
|
19
|
+
* accept — the driver then sees the call unchanged and raises the error itself.
|
|
20
|
+
*
|
|
21
|
+
* The internal format is SIZED, never the unsized `RED`/`RG`: an unsized format
|
|
22
|
+
* leaves the storage precision to a desktop driver, and a float LUMINANCE
|
|
23
|
+
* upload (OES_texture_float) must not be quantised to 8 bits — the same
|
|
24
|
+
* reasoning as `_nativeFloatInternalFormat` for RGBA.
|
|
25
|
+
*/
|
|
26
|
+
export declare function coreStorageForLegacyFormat(format: number, type: number): LegacyFormatStorage | null;
|
|
27
|
+
/** The swizzle a legacy format samples through once stored as RED/RG. */
|
|
28
|
+
export declare function legacySwizzle(format: number): Swizzle;
|
|
29
|
+
/**
|
|
30
|
+
* The pixel-transfer format a `texSubImage*` must hand the driver for a
|
|
31
|
+
* legacy `format` on a core profile: the storage layout, not the legacy name.
|
|
32
|
+
* Any other format is returned unchanged.
|
|
33
|
+
*/
|
|
34
|
+
export declare function coreTransferFormat(format: number): number;
|
|
35
|
+
/**
|
|
36
|
+
* The target `texParameter*` takes for an image `target`: a cube-map FACE
|
|
37
|
+
* names an image, but the swizzle belongs to the cube-map texture as a whole.
|
|
38
|
+
*/
|
|
39
|
+
export declare function textureParameterTarget(target: number): number;
|
|
40
|
+
/**
|
|
41
|
+
* Pick the legacy channels out of tightly packed RGBA8 pixels, in the RED/RG
|
|
42
|
+
* layout the core storage holds: ALPHA keeps A, LUMINANCE keeps R (GLES defines
|
|
43
|
+
* a copied luminance as the red component), LUMINANCE_ALPHA keeps R and A.
|
|
44
|
+
* Used where the source is a framebuffer read back, not consumer data.
|
|
45
|
+
*/
|
|
46
|
+
export declare function extractLegacyChannels(rgba: Uint8Array, format: number): Uint8Array;
|
|
@@ -2,6 +2,7 @@ import '@girs/gdkpixbuf-2.0';
|
|
|
2
2
|
import Gwebgl from '@girs/gwebgl-0.1';
|
|
3
3
|
import { WebGLContextAttributes } from './webgl-context-attributes.js';
|
|
4
4
|
import type { HTMLCanvasElement } from './html-canvas-element.js';
|
|
5
|
+
import { type LegacyFormatStorage, type Swizzle } from './context/texture-management/legacy-formats.js';
|
|
5
6
|
import type { WebGLBuffer } from './webgl-buffer.js';
|
|
6
7
|
import type { WebGLDrawingBufferWrapper } from './webgl-drawing-buffer-wrapper.js';
|
|
7
8
|
import type { WebGLFramebuffer } from './webgl-framebuffer.js';
|
|
@@ -78,6 +79,8 @@ export declare abstract class WebGLContextBase {
|
|
|
78
79
|
_packAlignment: number;
|
|
79
80
|
_unpackFlipY: boolean;
|
|
80
81
|
_unpackPremultAlpha: boolean;
|
|
82
|
+
/** `GENERATE_MIPMAP_HINT`, kept in JS because a core profile has no such state; see `hint`. */
|
|
83
|
+
_generateMipmapHint: GLenum;
|
|
81
84
|
_viewport: Int32Array;
|
|
82
85
|
_scissorBox: Int32Array;
|
|
83
86
|
_gtkFboId: number;
|
|
@@ -138,6 +141,84 @@ export declare abstract class WebGLContextBase {
|
|
|
138
141
|
* cannot be parsed for a driver version.
|
|
139
142
|
*/
|
|
140
143
|
protected _atLeastGlVersion(major: number, minor: number): boolean;
|
|
144
|
+
/**
|
|
145
|
+
* The internal format to hand the DRIVER for a WebGL1 `texImage2D`.
|
|
146
|
+
*
|
|
147
|
+
* OES_texture_float uploads with an UNSIZED format (`RGBA` + `FLOAT`). GLES
|
|
148
|
+
* derives float storage from the type; desktop GL leaves an unsized format's
|
|
149
|
+
* storage to the driver, and nothing obliges it to choose float — an `RGBA8`
|
|
150
|
+
* choice would clamp 1.5 to 1.0 behind an extension this context advertised.
|
|
151
|
+
* Naming the sized float format keeps the promise on every desktop driver,
|
|
152
|
+
* not only the ones that happen to choose float (macOS does, measured).
|
|
153
|
+
* GLES keeps the unsized format it requires.
|
|
154
|
+
*/
|
|
155
|
+
_nativeFloatInternalFormat(internalFormat: GLenum, type: GLenum): GLenum;
|
|
156
|
+
/** Cached answer of {@link _isCoreProfile}; `undefined` = not asked yet. */
|
|
157
|
+
private _coreProfile;
|
|
158
|
+
/**
|
|
159
|
+
* Is this a desktop-GL CORE profile — the context that removed what WebGL
|
|
160
|
+
* still has (legacy texture formats, `GENERATE_MIPMAP_HINT`)?
|
|
161
|
+
*
|
|
162
|
+
* ASKED, not inferred from the OS, exactly like the Vala side's
|
|
163
|
+
* `needsDefaultVertexArray()`: `GL_CONTEXT_PROFILE_MASK` answers it, and a
|
|
164
|
+
* compatibility profile (Mesa's `4.6 (Compatibility Profile)`) or GLES keeps
|
|
165
|
+
* the legacy behaviour natively and must see no emulation. The mask only
|
|
166
|
+
* exists from GL 3.2, the first version that can be core, so below it the
|
|
167
|
+
* version gate IS the answer — and the query never queues an INVALID_ENUM
|
|
168
|
+
* for a consumer's `getError()`.
|
|
169
|
+
*/
|
|
170
|
+
_isCoreProfile(): boolean;
|
|
171
|
+
/** Cached answer of {@link _emulatesLegacyFormats}. */
|
|
172
|
+
private _legacyFormatEmulation;
|
|
173
|
+
/**
|
|
174
|
+
* Does this context store `ALPHA` / `LUMINANCE` / `LUMINANCE_ALPHA` as
|
|
175
|
+
* RED/RG + texture swizzle? A core profile removed the formats; the swizzle
|
|
176
|
+
* that replaces them is core from GL 3.3, so a 3.2 core context has neither
|
|
177
|
+
* and gets the driver's own answer.
|
|
178
|
+
*/
|
|
179
|
+
_emulatesLegacyFormats(): boolean;
|
|
180
|
+
/**
|
|
181
|
+
* How to store a legacy-format image on THIS context: the RED/RG + swizzle
|
|
182
|
+
* storage where {@link _emulatesLegacyFormats}, `null` everywhere the driver
|
|
183
|
+
* takes the legacy format as it is (GLES, compatibility profiles).
|
|
184
|
+
*/
|
|
185
|
+
_legacyFormatStorage(format: GLenum, type: GLenum): LegacyFormatStorage | null;
|
|
186
|
+
/**
|
|
187
|
+
* Must a sub-upload of `format` into `texture` be refused (INVALID_OPERATION)
|
|
188
|
+
* because it does not match the image's legacy format? WebGL, like GLES, wants
|
|
189
|
+
* the format of a legacy image's sub-upload to be that legacy format. Only a
|
|
190
|
+
* GLES driver says so itself: emulated RED storage cannot tell ALPHA from
|
|
191
|
+
* LUMINANCE or from a genuine R8, and a desktop driver (core or compatibility)
|
|
192
|
+
* converts any format — so the check is made here, on every context, from the
|
|
193
|
+
* format JS recorded.
|
|
194
|
+
*/
|
|
195
|
+
_legacySubImageMismatch(texture: WebGLTexture, format: GLenum): boolean;
|
|
196
|
+
/**
|
|
197
|
+
* Point the texture bound to `target` at `swizzle` (`null` = identity).
|
|
198
|
+
*
|
|
199
|
+
* The swizzle is TEXTURE state, so it must follow the image: a texture that
|
|
200
|
+
* held LUMINANCE and is re-specified as RGBA would otherwise keep sampling
|
|
201
|
+
* (R, R, R, 1). WebGL exposes no swizzle of its own (not even WebGL 2), so
|
|
202
|
+
* the emulation owns this state outright — no consumer value to preserve.
|
|
203
|
+
* `_swizzled` spares the four calls on the common path, where a texture
|
|
204
|
+
* never held a legacy format; without a texture to ask, an emulating
|
|
205
|
+
* context always writes, and any other never has a swizzle to reset.
|
|
206
|
+
*/
|
|
207
|
+
_setTextureSwizzle(target: GLenum, texture: WebGLTexture | null, swizzle: Swizzle | null): void;
|
|
208
|
+
/** Cached answer of {@link _desktopGlslForEsDerivatives}; `undefined` = not probed yet. */
|
|
209
|
+
private _esDerivativesDesktopGlsl;
|
|
210
|
+
/**
|
|
211
|
+
* The desktop GLSL version to respell a derivative-using GLSL ES 1.00
|
|
212
|
+
* shader in — or `null` when the context compiles it as written.
|
|
213
|
+
*
|
|
214
|
+
* PROBED, once per context, rather than inferred from the OS or the GL
|
|
215
|
+
* version: whether a desktop driver's ES 1.00 front end honours
|
|
216
|
+
* `GL_OES_standard_derivatives` is the driver's own choice (macOS's does not;
|
|
217
|
+
* nothing in the GL version says so), and compiling the smallest shader
|
|
218
|
+
* that needs it is the question itself. A failed compile queues no GL error,
|
|
219
|
+
* so the probe leaves nothing behind for a consumer's `getError()`.
|
|
220
|
+
*/
|
|
221
|
+
_desktopGlslForEsDerivatives(): string | null;
|
|
141
222
|
_checkOwns(object: unknown): boolean;
|
|
142
223
|
_checkValid(object: unknown, Type: {
|
|
143
224
|
new (...args: unknown[]): unknown;
|
|
@@ -4,6 +4,12 @@ export declare class WebGLShader extends Linkable implements WebGLShader {
|
|
|
4
4
|
_type: GLenum;
|
|
5
5
|
_ctx: WebGLContextBase;
|
|
6
6
|
_source: string;
|
|
7
|
+
/** The source exactly as the consumer passed it, before `_wrapShader`. */
|
|
8
|
+
_userSource: string;
|
|
9
|
+
/** Does this source itself need desktop GLSL (see `_needsDesktopSpelling`)? */
|
|
10
|
+
_needsDesktop: boolean;
|
|
11
|
+
/** Is it CURRENTLY spelled in desktop GLSL — itself, or to match a program partner? */
|
|
12
|
+
_desktopSpelled: boolean;
|
|
7
13
|
_compileStatus: boolean;
|
|
8
14
|
_compileInfo: string;
|
|
9
15
|
_needsRecompile: boolean;
|
|
@@ -8,6 +8,8 @@ export declare class WebGLTexture extends Linkable implements WebGLTexture {
|
|
|
8
8
|
_format: number;
|
|
9
9
|
_type: number;
|
|
10
10
|
_complete: boolean;
|
|
11
|
+
/** Does the driver-side swizzle currently differ from identity (core-profile legacy-format emulation)? */
|
|
12
|
+
_swizzled: boolean;
|
|
11
13
|
constructor(_: number, ctx: WebGLContextBase);
|
|
12
14
|
_performDelete(): void;
|
|
13
15
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/webgl",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.53.0",
|
|
4
4
|
"description": "WebGL module for Gjs",
|
|
5
5
|
"module": "lib/esm/index.js",
|
|
6
6
|
"types": "lib/types/index.d.ts",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"tier": 1
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
|
-
"clear": "gjsify clear lib tmp build test.gjs.mjs tsconfig.tsbuildinfo tsconfig.types.tsbuildinfo",
|
|
44
|
+
"clear": "gjsify clear lib tmp build test.gjs.mjs test.hidpi.gjs.js tsconfig.tsbuildinfo tsconfig.types.tsbuildinfo",
|
|
45
45
|
"check": "gjsify tsc --noEmit",
|
|
46
46
|
"init:meson": "meson setup build .",
|
|
47
47
|
"init:meson:wipe": "gjsify run init:meson --wipe",
|
|
@@ -54,15 +54,17 @@
|
|
|
54
54
|
"build:conformance": "gjsify build src/ts/test.conformance.ts --app gjs --outfile conformance.gjs.js",
|
|
55
55
|
"test": "gjsify run build:gjsify && gjsify run build:test && gjsify run test:gjs",
|
|
56
56
|
"test:gjs": "gjsify run test.gjs.js",
|
|
57
|
-
"test:conformance": "gjsify run build:gjsify && gjsify run build:conformance && gjsify run conformance.gjs.js"
|
|
57
|
+
"test:conformance": "gjsify run build:gjsify && gjsify run build:conformance && gjsify run conformance.gjs.js",
|
|
58
|
+
"build:hidpi": "gjsify build src/ts/test.hidpi.ts --app gjs --outfile test.hidpi.gjs.js",
|
|
59
|
+
"test:hidpi": "gjsify run build:gjsify && gjsify run build:hidpi && gjsify run test.hidpi.gjs.js"
|
|
58
60
|
},
|
|
59
61
|
"keywords": [
|
|
60
62
|
"gjs",
|
|
61
63
|
"WebGL"
|
|
62
64
|
],
|
|
63
65
|
"devDependencies": {
|
|
64
|
-
"@gjsify/cli": "^0.
|
|
65
|
-
"@gjsify/unit": "^0.
|
|
66
|
+
"@gjsify/cli": "^0.53.0",
|
|
67
|
+
"@gjsify/unit": "^0.53.0",
|
|
66
68
|
"@types/bit-twiddle": "^1.0.3",
|
|
67
69
|
"@types/node": "^25.9.2",
|
|
68
70
|
"typescript": "^6.0.3"
|
|
@@ -72,10 +74,10 @@
|
|
|
72
74
|
"@girs/gjs": "5.4.0",
|
|
73
75
|
"@girs/gtk-4.0": "5.4.0",
|
|
74
76
|
"@girs/gwebgl-0.1": "0.1.0-4.0.0-rc.5",
|
|
75
|
-
"@gjsify/dom-elements": "^0.
|
|
76
|
-
"@gjsify/dom-events": "^0.
|
|
77
|
-
"@gjsify/event-bridge": "^0.
|
|
78
|
-
"@gjsify/utils": "^0.
|
|
77
|
+
"@gjsify/dom-elements": "^0.53.0",
|
|
78
|
+
"@gjsify/dom-events": "^0.53.0",
|
|
79
|
+
"@gjsify/event-bridge": "^0.53.0",
|
|
80
|
+
"@gjsify/utils": "^0.53.0",
|
|
79
81
|
"bit-twiddle": "^1.0.2",
|
|
80
82
|
"glsl-tokenizer": "^2.1.5"
|
|
81
83
|
},
|
|
@@ -90,13 +92,13 @@
|
|
|
90
92
|
},
|
|
91
93
|
"homepage": "https://github.com/gjsify/gjsify/tree/main/packages/framework/webgl#readme",
|
|
92
94
|
"optionalDependencies": {
|
|
93
|
-
"@gjsify/webgl-darwin-arm64": "0.
|
|
94
|
-
"@gjsify/webgl-darwin-x64": "0.
|
|
95
|
-
"@gjsify/webgl-linux-arm64": "0.
|
|
96
|
-
"@gjsify/webgl-linux-ppc64": "0.
|
|
97
|
-
"@gjsify/webgl-linux-riscv64": "0.
|
|
98
|
-
"@gjsify/webgl-linux-s390x": "0.
|
|
99
|
-
"@gjsify/webgl-linux-x64": "0.
|
|
100
|
-
"@gjsify/webgl-win32-x64": "0.
|
|
95
|
+
"@gjsify/webgl-darwin-arm64": "0.53.0",
|
|
96
|
+
"@gjsify/webgl-darwin-x64": "0.53.0",
|
|
97
|
+
"@gjsify/webgl-linux-arm64": "0.53.0",
|
|
98
|
+
"@gjsify/webgl-linux-ppc64": "0.53.0",
|
|
99
|
+
"@gjsify/webgl-linux-riscv64": "0.53.0",
|
|
100
|
+
"@gjsify/webgl-linux-s390x": "0.53.0",
|
|
101
|
+
"@gjsify/webgl-linux-x64": "0.53.0",
|
|
102
|
+
"@gjsify/webgl-win32-x64": "0.53.0"
|
|
101
103
|
}
|
|
102
104
|
}
|