@gjsify/webgl 0.64.57-next.363 → 0.64.57
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
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
|
|
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(`
|
|
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=e===this.FRAGMENT_SHADER&&t===this.MEDIUM_FLOAT&&this._fragmentHighpSupported(),i=this._gl.getShaderPrecisionFormat(e,n?this.HIGH_FLOAT:t);return i?new r(i):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`)}},_fragmentHighpSupported(){if(this._fragHighp===void 0){let e=this._gl.getShaderPrecisionFormat(this.FRAGMENT_SHADER,this.HIGH_FLOAT);this._fragHighp=!!e&&e.precision>0}return this._fragHighp},_wrapShader(e,t,n=!1){e===this.FRAGMENT_SHADER&&this._fragmentHighpSupported()&&(t=t.replace(/\bmediump\b/g,`highp`));let r=t.startsWith(`#version`)||t.includes(`
|
|
4
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
5
|
`),!this._extensions.webgl_draw_buffers&&a===`glsl1`&&(o+=`#define gl_MaxDrawBuffers 1
|
|
6
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
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import{__name as e}from"./_virtual/_rolldown/runtime.js";import{destroyTestFBO as t,drawTriangle as n,makeProgram as r,makeTestFBO as i}from"./test-utils.js";import{describe as a,expect as o,it as s,on as c}from"@gjsify/unit";import{WebGLBridge as l}from"@gjsify/webgl";import u from"@girs/glib-2.0";import d from"@girs/gtk-4.0";const f=1024,p=`#version 300 es
|
|
2
|
+
in vec2 position;
|
|
3
|
+
out float v_u;
|
|
4
|
+
void main() {
|
|
5
|
+
v_u = position.x * 0.5 + 0.5;
|
|
6
|
+
gl_Position = vec4(position, 0.0, 1.0);
|
|
7
|
+
}`,fs=e=>`#version 300 es
|
|
8
|
+
${e}
|
|
9
|
+
in float v_u;
|
|
10
|
+
out vec4 outColor;
|
|
11
|
+
void main() {
|
|
12
|
+
outColor = vec4(fract(v_u * ${f}.0), 0.0, 0.0, 1.0);
|
|
13
|
+
}`;var m=e(async()=>{await c(`Gl`,async()=>{d.init();let e,c,m=new u.MainLoop(null,!1),h=new d.Window({});h.set_default_size(200,200),e=new l,e.onReady(e=>{c=e.getContext(`webgl2`),m.quit()}),h.set_child(e),h.present();let g=u.timeout_add(u.PRIORITY_DEFAULT,1e4,()=>(m.quit(),u.SOURCE_REMOVE));if(m.run(),u.source_remove(g),!c){console.warn(`WebGL2 context not available — skipping shader precision tests`),h.destroy();return}e.make_current();let worstError=a=>{e.make_current();let o=i(c,f,1),s=r(c,p,fs(a));c.useProgram(s),n(c);let l=new Uint8Array(f*4);c.readPixels(0,0,f,1,c.RGBA,c.UNSIGNED_BYTE,l),t(c,o);let u=0;for(let e=0;e<f;e++)u=Math.max(u,Math.abs(l[e*4]-127.5));return u};await a(`fragment float precision`,async()=>{await s(`runs mediump at the precision of highp, as a browser on desktop GL does`,async()=>{let e=worstError(`precision highp float;`);o(worstError(`precision mediump float;`)).toBeLessThan(e+1)}),await s(`promotes a mediump qualifier on a single variable too`,async()=>{let a=`#version 300 es
|
|
14
|
+
precision lowp float;
|
|
15
|
+
in mediump float v_u;
|
|
16
|
+
out vec4 outColor;
|
|
17
|
+
void main() { outColor = vec4(fract(v_u * ${f}.0), 0.0, 0.0, 1.0); }`;e.make_current();let s=i(c,f,1);c.useProgram(r(c,p.replace(`out float`,`out mediump float`),a)),n(c);let l=new Uint8Array(f*4);c.readPixels(0,0,f,1,c.RGBA,c.UNSIGNED_BYTE,l),t(c,s);let u=0;for(let e=0;e<f;e++)u=Math.max(u,Math.abs(l[e*4]-127.5));o(u).toBeLessThan(2)}),await s(`reports the precision that actually runs`,async()=>{let fmt=e=>c.getShaderPrecisionFormat(c.FRAGMENT_SHADER,e);o(fmt(c.MEDIUM_FLOAT).precision).toBe(fmt(c.HIGH_FLOAT).precision)})})})},`default`);export{m as default};
|
package/lib/esm/test.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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
|
|
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"./shader-precision.spec.js";import s from"./software-renderer.spec.js";import c from"./webgl1.spec.js";import l from"./webgl2.spec.js";import{run as u}from"@gjsify/unit";import"@gjsify/unit/gl";u({testSuite:async()=>{await c(),await l(),await r(),await n(),await s(),await e(),await t(),await i(),await o()},registerSuite:a});
|
|
@@ -5,6 +5,7 @@ export interface ShaderLifecycleMethods {
|
|
|
5
5
|
deleteShader(shader: WebGLShader | null): void;
|
|
6
6
|
compileShader(shader: WebGLShader): void;
|
|
7
7
|
shaderSource(shader: WebGLShader, source: string): void;
|
|
8
|
+
_fragmentHighpSupported(): boolean;
|
|
8
9
|
getShaderInfoLog(shader: WebGLShader): string | null;
|
|
9
10
|
getShaderParameter(shader: WebGLShader, pname?: GLenum): unknown;
|
|
10
11
|
getShaderPrecisionFormat(shaderType?: GLenum, precisionType?: GLenum): WebGLShaderPrecisionFormat | null;
|
|
@@ -205,6 +205,8 @@ export declare abstract class WebGLContextBase {
|
|
|
205
205
|
* context always writes, and any other never has a swizzle to reset.
|
|
206
206
|
*/
|
|
207
207
|
_setTextureSwizzle(target: GLenum, texture: WebGLTexture | null, swizzle: Swizzle | null): void;
|
|
208
|
+
/** Cached probe of fragment `highp float`; `undefined` = not probed yet. */
|
|
209
|
+
_fragHighp: boolean | undefined;
|
|
208
210
|
/** Cached answer of {@link _desktopGlslForEsDerivatives}; `undefined` = not probed yet. */
|
|
209
211
|
private _esDerivativesDesktopGlsl;
|
|
210
212
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/webgl",
|
|
3
|
-
"version": "0.64.57
|
|
3
|
+
"version": "0.64.57",
|
|
4
4
|
"description": "WebGL module for Gjs",
|
|
5
5
|
"module": "lib/esm/index.js",
|
|
6
6
|
"types": "lib/types/index.d.ts",
|
|
@@ -64,8 +64,8 @@
|
|
|
64
64
|
"WebGL"
|
|
65
65
|
],
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@gjsify/cli": "0.64.57
|
|
68
|
-
"@gjsify/unit": "0.64.57
|
|
67
|
+
"@gjsify/cli": "0.64.57",
|
|
68
|
+
"@gjsify/unit": "0.64.57",
|
|
69
69
|
"@types/bit-twiddle": "^1.0.3",
|
|
70
70
|
"@types/node": "^25.9.2",
|
|
71
71
|
"typescript": "^6.0.3"
|
|
@@ -75,10 +75,10 @@
|
|
|
75
75
|
"@girs/gjs": "5.4.0",
|
|
76
76
|
"@girs/gtk-4.0": "5.4.0",
|
|
77
77
|
"@girs/gwebgl-0.1": "0.1.0-4.0.0-rc.5",
|
|
78
|
-
"@gjsify/dom-elements": "0.64.57
|
|
79
|
-
"@gjsify/dom-events": "0.64.57
|
|
80
|
-
"@gjsify/event-bridge": "0.64.57
|
|
81
|
-
"@gjsify/utils": "0.64.57
|
|
78
|
+
"@gjsify/dom-elements": "0.64.57",
|
|
79
|
+
"@gjsify/dom-events": "0.64.57",
|
|
80
|
+
"@gjsify/event-bridge": "0.64.57",
|
|
81
|
+
"@gjsify/utils": "0.64.57",
|
|
82
82
|
"bit-twiddle": "^1.0.2",
|
|
83
83
|
"glsl-tokenizer": "^2.1.5"
|
|
84
84
|
},
|
|
@@ -93,14 +93,13 @@
|
|
|
93
93
|
},
|
|
94
94
|
"homepage": "https://github.com/gjsify/gjsify/tree/main/packages/framework/webgl#readme",
|
|
95
95
|
"optionalDependencies": {
|
|
96
|
-
"@gjsify/webgl-darwin-arm64": "0.64.57
|
|
97
|
-
"@gjsify/webgl-darwin-x64": "0.64.57
|
|
98
|
-
"@gjsify/webgl-linux-arm64": "0.64.57
|
|
99
|
-
"@gjsify/webgl-linux-ppc64": "0.64.57
|
|
100
|
-
"@gjsify/webgl-linux-riscv64": "0.64.57
|
|
101
|
-
"@gjsify/webgl-linux-s390x": "0.64.57
|
|
102
|
-
"@gjsify/webgl-linux-x64": "0.64.57
|
|
103
|
-
"@gjsify/webgl-win32-x64": "0.64.57
|
|
104
|
-
}
|
|
105
|
-
"gitHead": "75905af1599250ab9a443fe4b079c4cd7fbc0bad"
|
|
96
|
+
"@gjsify/webgl-darwin-arm64": "0.64.57",
|
|
97
|
+
"@gjsify/webgl-darwin-x64": "0.64.57",
|
|
98
|
+
"@gjsify/webgl-linux-arm64": "0.64.57",
|
|
99
|
+
"@gjsify/webgl-linux-ppc64": "0.64.57",
|
|
100
|
+
"@gjsify/webgl-linux-riscv64": "0.64.57",
|
|
101
|
+
"@gjsify/webgl-linux-s390x": "0.64.57",
|
|
102
|
+
"@gjsify/webgl-linux-x64": "0.64.57",
|
|
103
|
+
"@gjsify/webgl-win32-x64": "0.64.57"
|
|
104
|
+
}
|
|
106
105
|
}
|