@gjsify/webgl 0.3.16 → 0.3.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/conformance/attribs.spec.js +3 -315
- package/lib/esm/conformance/buffers.spec.js +1 -220
- package/lib/esm/conformance/context.spec.js +3 -302
- package/lib/esm/conformance/programs.spec.js +3 -477
- package/lib/esm/conformance/rendering-basic.spec.js +3 -141
- package/lib/esm/conformance/rendering.spec.js +7 -514
- package/lib/esm/conformance/setup.js +1 -47
- package/lib/esm/conformance/state.spec.js +1 -365
- package/lib/esm/conformance/textures.spec.js +3 -337
- package/lib/esm/conformance/uniforms.spec.js +1 -484
- package/lib/esm/conformance-test.js +1 -25
- package/lib/esm/extensions/ext-blend-minmax.js +1 -18
- package/lib/esm/extensions/ext-color-buffer-float.js +1 -12
- package/lib/esm/extensions/ext-color-buffer-half-float.js +1 -12
- package/lib/esm/extensions/ext-texture-filter-anisotropic.js +1 -18
- package/lib/esm/extensions/oes-element-index-unit.js +1 -13
- package/lib/esm/extensions/oes-standard-derivatives.js +1 -17
- package/lib/esm/extensions/oes-texture-float-linear.js +1 -13
- package/lib/esm/extensions/oes-texture-float.js +1 -13
- package/lib/esm/extensions/oes-texture-half-float.js +1 -19
- package/lib/esm/extensions/stackgl-destroy-context.js +1 -12
- package/lib/esm/extensions/stackgl-resize-drawing-buffer.js +1 -12
- package/lib/esm/html-canvas-element.js +1 -65
- package/lib/esm/index.js +1 -33
- package/lib/esm/linkable.js +1 -50
- package/lib/esm/test-utils.js +4 -186
- package/lib/esm/test.js +1 -11
- package/lib/esm/types/index.js +1 -5
- package/lib/esm/utils.js +1 -201
- package/lib/esm/webgl-active-info.js +1 -11
- package/lib/esm/webgl-bridge.js +1 -167
- package/lib/esm/webgl-buffer.js +1 -19
- package/lib/esm/webgl-context-attributes.js +1 -24
- package/lib/esm/webgl-context-base.js +8 -3069
- package/lib/esm/webgl-drawing-buffer-wrapper.js +1 -11
- package/lib/esm/webgl-framebuffer.js +1 -110
- package/lib/esm/webgl-program.js +1 -27
- package/lib/esm/webgl-query.js +1 -17
- package/lib/esm/webgl-renderbuffer.js +1 -25
- package/lib/esm/webgl-rendering-context.js +1 -175
- package/lib/esm/webgl-sampler.js +1 -17
- package/lib/esm/webgl-shader-precision-format.js +1 -11
- package/lib/esm/webgl-shader.js +1 -25
- package/lib/esm/webgl-sync.js +1 -17
- package/lib/esm/webgl-texture-unit.js +1 -13
- package/lib/esm/webgl-texture.js +1 -23
- package/lib/esm/webgl-transform-feedback.js +1 -17
- package/lib/esm/webgl-uniform-location.js +1 -15
- package/lib/esm/webgl-vertex-array-object.js +1 -23
- package/lib/esm/webgl-vertex-attribute.js +1 -151
- package/lib/esm/webgl1.spec.js +10 -1044
- package/lib/esm/webgl2-rendering-context.js +1 -1218
- package/lib/esm/webgl2.spec.js +45 -1288
- package/lib/types/webgl-bridge.d.ts +9 -9
- package/package.json +9 -9
package/lib/esm/webgl-bridge.js
CHANGED
|
@@ -1,167 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import GObject from "gi://GObject";
|
|
3
|
-
import GLib from "gi://GLib?version=2.0";
|
|
4
|
-
import Gtk from "gi://Gtk?version=4.0";
|
|
5
|
-
import { attachEventControllers } from "@gjsify/event-bridge";
|
|
6
|
-
import { Event } from "@gjsify/dom-events";
|
|
7
|
-
|
|
8
|
-
//#region src/ts/webgl-bridge.ts
|
|
9
|
-
/**
|
|
10
|
-
* A `Gtk.GLArea` subclass that handles WebGL bootstrapping:
|
|
11
|
-
* - Sets up OpenGL ES 3.2 context, depth buffer, stencil buffer
|
|
12
|
-
* - Creates an `HTMLCanvasElement` wrapping the GLArea on first render
|
|
13
|
-
* - Fires `onReady()` callbacks with (canvas, gl) once the context is available
|
|
14
|
-
* - Provides `requestAnimationFrame()` backed by GTK frame clock (vsync) + render signal
|
|
15
|
-
* - `installGlobals()` sets `globalThis.requestAnimationFrame` and `globalThis.performance`
|
|
16
|
-
*
|
|
17
|
-
* Usage:
|
|
18
|
-
* ```ts
|
|
19
|
-
* const widget = new WebGLBridge();
|
|
20
|
-
* widget.installGlobals(); // sets globalThis.requestAnimationFrame
|
|
21
|
-
* widget.onReady((canvas, gl) => {
|
|
22
|
-
* gl.clearColor(0, 0, 0, 1);
|
|
23
|
-
* // requestAnimationFrame is now available globally
|
|
24
|
-
* });
|
|
25
|
-
* window.set_child(widget);
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
const WebGLBridge = GObject.registerClass({ GTypeName: "GjsifyWebGLBridge" }, class WebGLBridge extends Gtk.GLArea {
|
|
29
|
-
constructor(params) {
|
|
30
|
-
super(params);
|
|
31
|
-
this._canvas = null;
|
|
32
|
-
this._readyCallbacks = [];
|
|
33
|
-
this._resizeCallbacks = [];
|
|
34
|
-
this._renderTag = null;
|
|
35
|
-
this._tickCallbackId = null;
|
|
36
|
-
this._frameCallback = null;
|
|
37
|
-
this._timeOrigin = GLib.get_monotonic_time();
|
|
38
|
-
this.set_use_es(true);
|
|
39
|
-
this.set_required_version(3, 2);
|
|
40
|
-
this.set_has_depth_buffer(true);
|
|
41
|
-
this.set_has_stencil_buffer(true);
|
|
42
|
-
attachEventControllers(this, () => this._canvas, { captureKeys: true });
|
|
43
|
-
this._tickCallbackId = this.add_tick_callback((_widget, _frameClock) => {
|
|
44
|
-
if (this._frameCallback !== null) {
|
|
45
|
-
this.queue_render();
|
|
46
|
-
}
|
|
47
|
-
return GLib.SOURCE_CONTINUE;
|
|
48
|
-
});
|
|
49
|
-
const initId = this.connect("render", () => {
|
|
50
|
-
this.disconnect(initId);
|
|
51
|
-
this.make_current();
|
|
52
|
-
this._canvas = new HTMLCanvasElement(this);
|
|
53
|
-
if (globalThis.document?.body) {
|
|
54
|
-
globalThis.document.body.appendChild(this._canvas);
|
|
55
|
-
}
|
|
56
|
-
this._canvas.getContext("webgl2");
|
|
57
|
-
const gl = this._canvas.getContext("webgl");
|
|
58
|
-
if (gl) {
|
|
59
|
-
for (const cb of this._readyCallbacks) {
|
|
60
|
-
cb(this._canvas, gl);
|
|
61
|
-
}
|
|
62
|
-
this._readyCallbacks = [];
|
|
63
|
-
}
|
|
64
|
-
this._renderTag = this.connect("render", (_widget) => {
|
|
65
|
-
if (this._frameCallback !== null) {
|
|
66
|
-
const time = (GLib.get_monotonic_time() - this._timeOrigin) / 1e3;
|
|
67
|
-
if (globalThis.__GJSIFY_DEBUG_RAF === true) {
|
|
68
|
-
console.log(`[rAF] frame callback fires t=${time.toFixed(1)}`);
|
|
69
|
-
}
|
|
70
|
-
const cb = this._frameCallback;
|
|
71
|
-
this._frameCallback = null;
|
|
72
|
-
cb(time);
|
|
73
|
-
}
|
|
74
|
-
return true;
|
|
75
|
-
});
|
|
76
|
-
return true;
|
|
77
|
-
});
|
|
78
|
-
this.connect("resize", () => {
|
|
79
|
-
const width = this.get_allocated_width();
|
|
80
|
-
const height = this.get_allocated_height();
|
|
81
|
-
if (this._canvas) {
|
|
82
|
-
this._canvas.dispatchEvent(new Event("resize"));
|
|
83
|
-
}
|
|
84
|
-
for (const cb of this._resizeCallbacks) {
|
|
85
|
-
cb(width, height);
|
|
86
|
-
}
|
|
87
|
-
if (this._frameCallback) {
|
|
88
|
-
this.requestAnimationFrame(this._frameCallback);
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
this.connect("unrealize", () => {
|
|
92
|
-
if (this._renderTag !== null) {
|
|
93
|
-
this.disconnect(this._renderTag);
|
|
94
|
-
this._renderTag = null;
|
|
95
|
-
}
|
|
96
|
-
if (this._tickCallbackId !== null) {
|
|
97
|
-
this.remove_tick_callback(this._tickCallbackId);
|
|
98
|
-
this._tickCallbackId = null;
|
|
99
|
-
}
|
|
100
|
-
this._canvas = null;
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
/** The HTMLCanvasElement wrapping this GLArea. Available after the first render. */
|
|
104
|
-
get canvas() {
|
|
105
|
-
return this._canvas;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Registers a callback to be called once the WebGL context is ready.
|
|
109
|
-
* If the context is already available, the callback fires synchronously.
|
|
110
|
-
*/
|
|
111
|
-
onReady(cb) {
|
|
112
|
-
if (this._canvas) {
|
|
113
|
-
const gl = this._canvas.getContext("webgl");
|
|
114
|
-
if (gl) {
|
|
115
|
-
cb(this._canvas, gl);
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
this._readyCallbacks.push(cb);
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* @deprecated Use `onReady()` instead.
|
|
123
|
-
*/
|
|
124
|
-
onWebGLReady(cb) {
|
|
125
|
-
this.onReady(cb);
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Register a callback invoked whenever the GTK widget is resized.
|
|
129
|
-
* The callback fires alongside the native 'resize' GObject signal and
|
|
130
|
-
* after the DOM 'resize' event has been dispatched on the canvas.
|
|
131
|
-
* Canvas buffer dimensions are NOT automatically updated — consumers
|
|
132
|
-
* should set `canvas.width`/`canvas.height` themselves if desired.
|
|
133
|
-
*/
|
|
134
|
-
onResize(cb) {
|
|
135
|
-
this._resizeCallbacks.push(cb);
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Schedules a single animation frame callback, matching the browser `requestAnimationFrame` API.
|
|
139
|
-
* Backed by a persistent GTK frame clock tick callback (vsync-synced) + a persistent GLArea
|
|
140
|
-
* render signal handler. Both are installed once at construction / first render respectively,
|
|
141
|
-
* eliminating per-frame GLib.Source allocation and GObject signal connect/disconnect overhead.
|
|
142
|
-
* Returns 0 (handle — cancel via cancelAnimationFrame clears the pending callback).
|
|
143
|
-
*/
|
|
144
|
-
requestAnimationFrame(cb) {
|
|
145
|
-
this._frameCallback = cb;
|
|
146
|
-
this.queue_render();
|
|
147
|
-
return 0;
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Sets browser globals (`requestAnimationFrame`, `performance`) so that
|
|
151
|
-
* browser-targeted code (e.g. Three.js) works unchanged on GJS.
|
|
152
|
-
*/
|
|
153
|
-
installGlobals() {
|
|
154
|
-
globalThis.requestAnimationFrame = (cb) => this.requestAnimationFrame(cb);
|
|
155
|
-
globalThis.cancelAnimationFrame = (_id) => {
|
|
156
|
-
this._frameCallback = null;
|
|
157
|
-
};
|
|
158
|
-
const timeOrigin = this._timeOrigin;
|
|
159
|
-
globalThis.performance = {
|
|
160
|
-
now: () => (GLib.get_monotonic_time() - timeOrigin) / 1e3,
|
|
161
|
-
timeOrigin: Date.now()
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
//#endregion
|
|
167
|
-
export { WebGLBridge };
|
|
1
|
+
import{HTMLCanvasElement as e}from"./html-canvas-element.js";import t from"gi://GObject";import n from"gi://GLib?version=2.0";import r from"gi://Gtk?version=4.0";import{attachEventControllers as i}from"@gjsify/event-bridge";import{Event as a}from"@gjsify/dom-events";const o=t.registerClass({GTypeName:`GjsifyWebGLBridge`},class extends r.GLArea{constructor(t){super(t),this._canvas=null,this._readyCallbacks=[],this._resizeCallbacks=[],this._renderTag=null,this._tickCallbackId=null,this._frameCallback=null,this._timeOrigin=n.get_monotonic_time(),this.set_use_es(!0),this.set_required_version(3,2),this.set_has_depth_buffer(!0),this.set_has_stencil_buffer(!0),i(this,()=>this._canvas,{captureKeys:!0}),this._tickCallbackId=this.add_tick_callback((e,t)=>(this._frameCallback!==null&&this.queue_render(),n.SOURCE_CONTINUE));let r=this.connect(`render`,()=>{this.disconnect(r),this.make_current(),this._canvas=new e(this),globalThis.document?.body&&globalThis.document.body.appendChild(this._canvas),this._canvas.getContext(`webgl2`);let t=this._canvas.getContext(`webgl`);if(t){for(let e of this._readyCallbacks)e(this._canvas,t);this._readyCallbacks=[]}return this._renderTag=this.connect(`render`,e=>{if(this._frameCallback!==null){let e=(n.get_monotonic_time()-this._timeOrigin)/1e3;globalThis.__GJSIFY_DEBUG_RAF===!0&&console.log(`[rAF] frame callback fires t=${e.toFixed(1)}`);let t=this._frameCallback;this._frameCallback=null,t(e)}return!0}),!0});this.connect(`resize`,()=>{let e=this.get_allocated_width(),t=this.get_allocated_height();this._canvas&&this._canvas.dispatchEvent(new a(`resize`));for(let n of this._resizeCallbacks)n(e,t);this._frameCallback&&this.requestAnimationFrame(this._frameCallback)}),this.connect(`unrealize`,()=>{this._renderTag!==null&&(this.disconnect(this._renderTag),this._renderTag=null),this._tickCallbackId!==null&&(this.remove_tick_callback(this._tickCallbackId),this._tickCallbackId=null),this._canvas=null})}get canvas(){return this._canvas}onReady(e){if(this._canvas){let t=this._canvas.getContext(`webgl`);if(t){e(this._canvas,t);return}}this._readyCallbacks.push(e)}onWebGLReady(e){this.onReady(e)}onResize(e){this._resizeCallbacks.push(e)}requestAnimationFrame(e){return this._frameCallback=e,this.queue_render(),0}installGlobals(){globalThis.requestAnimationFrame=e=>this.requestAnimationFrame(e),globalThis.cancelAnimationFrame=e=>{this._frameCallback=null};let e=this._timeOrigin;globalThis.performance={now:()=>(n.get_monotonic_time()-e)/1e3,timeOrigin:Date.now()}}});export{o as WebGLBridge};
|
package/lib/esm/webgl-buffer.js
CHANGED
|
@@ -1,19 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
//#region src/ts/webgl-buffer.ts
|
|
4
|
-
var WebGLBuffer = class extends Linkable {
|
|
5
|
-
constructor(_, ctx) {
|
|
6
|
-
super(_);
|
|
7
|
-
this._size = 0;
|
|
8
|
-
this._elements = new Uint8Array(0);
|
|
9
|
-
this._ctx = ctx;
|
|
10
|
-
}
|
|
11
|
-
_performDelete() {
|
|
12
|
-
const ctx = this._ctx;
|
|
13
|
-
delete ctx._buffers[this._ | 0];
|
|
14
|
-
ctx._gl.deleteBuffer(this._);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
//#endregion
|
|
19
|
-
export { WebGLBuffer };
|
|
1
|
+
import{Linkable as e}from"./linkable.js";var t=class extends e{constructor(e,t){super(e),this._size=0,this._elements=new Uint8Array,this._ctx=t}_performDelete(){let e=this._ctx;delete e._buffers[this._|0],e._gl.deleteBuffer(this._)}};export{t as WebGLBuffer};
|
|
@@ -1,24 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var WebGLContextAttributes = class {
|
|
3
|
-
constructor(alpha, depth, stencil, antialias, premultipliedAlpha, preserveDrawingBuffer, preferLowPowerToHighPerformance, failIfMajorPerformanceCaveat) {
|
|
4
|
-
this.alpha = alpha;
|
|
5
|
-
this.depth = depth;
|
|
6
|
-
this.stencil = stencil;
|
|
7
|
-
this.antialias = antialias;
|
|
8
|
-
this.premultipliedAlpha = premultipliedAlpha;
|
|
9
|
-
this.preserveDrawingBuffer = preserveDrawingBuffer;
|
|
10
|
-
this.preferLowPowerToHighPerformance = preferLowPowerToHighPerformance;
|
|
11
|
-
this.failIfMajorPerformanceCaveat = failIfMajorPerformanceCaveat;
|
|
12
|
-
this.alpha = alpha;
|
|
13
|
-
this.depth = depth;
|
|
14
|
-
this.stencil = stencil;
|
|
15
|
-
this.antialias = antialias;
|
|
16
|
-
this.premultipliedAlpha = premultipliedAlpha;
|
|
17
|
-
this.preserveDrawingBuffer = preserveDrawingBuffer;
|
|
18
|
-
this.preferLowPowerToHighPerformance = preferLowPowerToHighPerformance;
|
|
19
|
-
this.failIfMajorPerformanceCaveat = failIfMajorPerformanceCaveat;
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
|
-
export { WebGLContextAttributes };
|
|
1
|
+
var e=class{constructor(e,t,n,r,i,a,o,s){this.alpha=e,this.depth=t,this.stencil=n,this.antialias=r,this.premultipliedAlpha=i,this.preserveDrawingBuffer=a,this.preferLowPowerToHighPerformance=o,this.failIfMajorPerformanceCaveat=s,this.alpha=e,this.depth=t,this.stencil=n,this.antialias=r,this.premultipliedAlpha=i,this.preserveDrawingBuffer=a,this.preferLowPowerToHighPerformance=o,this.failIfMajorPerformanceCaveat=s}};export{e as WebGLContextAttributes};
|