webgl2 1.1.7 → 1.1.8

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/coverage.md CHANGED
@@ -3,34 +3,34 @@
3
3
  > **Legend:** 🟢 ≥80% | 🟡 ≥50% (or ≤6 lines) | 🟠 ≥20% | 🔴 <20%
4
4
 
5
5
  | File | Lines Covered | Lines Missed | Total Lines | Coverage |
6
- |---|---|---|---|---|
7
- | src/lib.rs | 110 | 31 | 141 | 78.01% 🟡 |
8
- | src/naga_wasm_backend/backend.rs | 45 | 1 | 46 | 97.83% 🟢 |
9
- | src/naga_wasm_backend/control_flow.rs | 24 | 11 | 35 | 68.57% 🟡 |
6
+ |---|---|---|---|---:|
7
+ | src/lib.rs | 108 | 30 | 138 | 78.26% 🟡 |
8
+ | src/naga_wasm_backend/backend.rs | 43 | 2 | 45 | 95.56% 🟢 |
9
+ | src/naga_wasm_backend/control_flow.rs | 25 | 11 | 36 | 69.44% 🟡 |
10
10
  | src/naga_wasm_backend/debug/stub.rs | 20 | 0 | 20 | 100.00% 🟢 |
11
- | src/naga_wasm_backend/expressions.rs | 32 | 14 | 46 | 69.57% 🟡 |
12
- | src/naga_wasm_backend/types.rs | 6 | 0 | 6 | 100.00% 🟢 |
11
+ | src/naga_wasm_backend/expressions.rs | 41 | 19 | 60 | 68.33% 🟡 |
12
+ | src/naga_wasm_backend/types.rs | 7 | 0 | 7 | 100.00% 🟢 |
13
13
  | src/wasm_gl_emu/framebuffer.rs | 1 | 0 | 1 | 100.00% 🟢 |
14
- | src/wasm_gl_emu/rasterizer.rs | 15 | 0 | 15 | 100.00% 🟢 |
14
+ | src/wasm_gl_emu/rasterizer.rs | 14 | 0 | 14 | 100.00% 🟢 |
15
15
  | src/webgl2_context/buffers.rs | 15 | 1 | 16 | 93.75% 🟢 |
16
16
  | src/webgl2_context/drawing.rs | 29 | 4 | 33 | 87.88% 🟢 |
17
- | src/webgl2_context/framebuffers.rs | 7 | 0 | 7 | 100.00% 🟢 |
17
+ | src/webgl2_context/framebuffers.rs | 8 | 0 | 8 | 100.00% 🟢 |
18
18
  | src/webgl2_context/registry.rs | 5 | 0 | 5 | 100.00% 🟢 |
19
19
  | src/webgl2_context/renderbuffers.rs | 10 | 0 | 10 | 100.00% 🟢 |
20
20
  | src/webgl2_context/shaders.rs | 70 | 3 | 73 | 95.89% 🟢 |
21
- | src/webgl2_context/state.rs | 14 | 3 | 17 | 82.35% 🟢 |
21
+ | src/webgl2_context/state.rs | 13 | 3 | 16 | 81.25% 🟢 |
22
22
  | src/webgl2_context/textures.rs | 10 | 0 | 10 | 100.00% 🟢 |
23
- | src/webgl2_context/types.rs | 9 | 1 | 10 | 90.00% 🟢 |
24
- | src/webgl2_context/vaos.rs | 36 | 0 | 36 | 100.00% 🟢 |
25
- | src/webgpu/adapter.rs | 2 | 0 | 2 | 100.00% 🟢 |
26
- | src/webgpu/backend.rs | 24 | 26 | 50 | 48.00% 🟠 |
27
- | **Total** | **484** | **95** | **579** | **83.59% 🟢** |
23
+ | src/webgl2_context/types.rs | 11 | 1 | 12 | 91.67% 🟢 |
24
+ | src/webgl2_context/vaos.rs | 37 | 0 | 37 | 100.00% 🟢 |
25
+ | src/webgpu/adapter.rs | 3 | 0 | 3 | 100.00% 🟢 |
26
+ | src/webgpu/backend.rs | 25 | 25 | 50 | 50.00% 🟡 |
27
+ | **Total** | **495** | **99** | **594** | **83.33% 🟢** |
28
28
 
29
29
  ## Top Missed Files
30
30
 
31
31
  | File | Lines Missed | Illustrative Line | Coverage |
32
- |---|---|---|---|
33
- | src/lib.rs | 31/141 | [516] `/// Set uniform 3f.` | 78.01% 🟡 |
34
- | src/webgpu/backend.rs | 26/50 | [919] `}` | 48.00% 🟠 |
35
- | src/naga_wasm_backend/expressions.rs | 14/46 | [11] `pub fn is_integer_type(type_inner: &TypeInner) -> bool {` | 69.57% 🟡 |
36
- | src/naga_wasm_backend/control_flow.rs | 11/35 | [171] `for i in (0..types.len()).rev() {` | 68.57% 🟡 |
32
+ |---|---|---|---:|
33
+ | src/lib.rs | 30/138 | [516] `/// Set uniform 3f.` | 78.26% 🟡 |
34
+ | src/webgpu/backend.rs | 25/50 | [919] `}` | 50.00% 🟡 |
35
+ | src/naga_wasm_backend/expressions.rs | 19/60 | [11] `pub fn is_integer_type(type_inner: &TypeInner) -> bool {` | 68.33% 🟡 |
36
+ | src/naga_wasm_backend/control_flow.rs | 11/36 | [181] `for i in (0..types.len()).rev() {` | 69.44% 🟡 |
package/index.js CHANGED
@@ -45,7 +45,7 @@ const isNode =
45
45
  * This function:
46
46
  * 1. Auto-loads webgl2.wasm (expects it next to index2.js)
47
47
  * 2. Instantiates the WASM module with memory
48
- * 3. Creates a Rust-owned context via wasm_create_context()
48
+ * 3. Creates a Rust-owned context via wasm_create_context_with_flags(flags)
49
49
  * 4. Returns a WasmWebGL2RenderingContext JS wrapper
50
50
  *
51
51
  * @param {{
@@ -83,21 +83,25 @@ export async function webGL2({ debug = (typeof process !== 'undefined' ? process
83
83
  ex.wasm_init_coverage(numEntries);
84
84
  }
85
85
 
86
- // Create a context in WASM
87
- const ctxHandle = ex.wasm_create_context();
86
+ // Determine debug flags for creation
87
+ const debugShaders = debug === true || debug === 'shaders' || debug === 'all';
88
+ const debugRust = debug === true || debug === 'rust' || debug === 'all';
89
+ const flags = (debugShaders ? 1 : 0); // only shader debug encoded in flags
90
+
91
+ // Default size to 640x480 if not provided
92
+ const width = size?.width ?? 640;
93
+ const height = size?.height ?? 480;
94
+
95
+ // Create a context in WASM using the flags-aware API (mandatory)
96
+ const ctxHandle = ex.wasm_create_context_with_flags(flags, width, height);
97
+
88
98
  if (ctxHandle === 0) {
89
99
  const msg = readErrorMessage(instance);
90
100
  throw new Error(`Failed to create context: ${msg}`);
91
101
  }
92
102
 
93
- // Wrap and return
94
- const gl = new WasmWebGL2RenderingContext(instance, ctxHandle);
95
-
96
- // Set debug mode if requested
97
- if (debug) {
98
- gl.setDebugMode(debug);
99
- }
100
-
103
+ // Wrap and return, pass debug booleans to the JS wrapper
104
+ const gl = new WasmWebGL2RenderingContext({ instance, ctxHandle, width, height, debugShaders: !!debugShaders });
101
105
 
102
106
  if (size && typeof size.width === 'number' && typeof size.height === 'number') {
103
107
  gl.resize(size.width, size.height);
@@ -185,8 +189,8 @@ async function initWASM({ debug } = {}) {
185
189
 
186
190
  // Verify required exports
187
191
  const ex = instance.exports;
188
- if (typeof ex.wasm_create_context !== 'function') {
189
- throw new Error('WASM module missing wasm_create_context export');
192
+ if (typeof ex.wasm_create_context_with_flags !== 'function') {
193
+ throw new Error('WASM module missing wasm_create_context_with_flags export');
190
194
  }
191
195
  if (!(ex.memory instanceof WebAssembly.Memory)) {
192
196
  throw new Error('WASM module missing memory export');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webgl2",
3
- "version": "1.1.7",
3
+ "version": "1.1.8",
4
4
  "description": "WebGL2 tools to derisk large GPU projects on the web beyond toys and demos.",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -96,37 +96,22 @@ export class WasmWebGL2RenderingContext {
96
96
  /**
97
97
  * @param {WebAssembly.Instance} instance
98
98
  * @param {u32} ctxHandle
99
+ * @param {number} width
100
+ * @param {number} height
101
+ * @param {boolean} [debugShaders]
99
102
  */
100
- constructor(instance, ctxHandle) {
103
+ constructor({ instance, ctxHandle, width, height, debugShaders = false }) {
101
104
  this._instance = instance;
102
105
  this._ctxHandle = ctxHandle;
103
106
  this._destroyed = false;
104
107
  /** @type {import('./webgl2_resources.js').WasmWebGLProgram | null} */
105
108
  this._currentProgram = null;
106
- this._debugMode = 0; // 0=None, 1=Shaders, 2=Rust, 3=All
107
- this._drawingBufferWidth = 640;
108
- this._drawingBufferHeight = 480;
109
-
110
- WasmWebGL2RenderingContext._contexts.set(ctxHandle, this);
111
- }
112
-
113
- setDebugMode(mode) {
114
- this._assertNotDestroyed();
115
- const ex = this._instance.exports;
116
- if (!ex || typeof ex.wasm_ctx_set_debug_mode !== 'function') {
117
- console.warn('wasm_ctx_set_debug_mode not found');
118
- return;
119
- }
120
-
121
- let modeVal = 0;
122
- if (mode === true || mode === 'all') modeVal = 3;
123
- else if (mode === 'shaders') modeVal = 1;
124
- else if (mode === 'rust') modeVal = 2;
125
- else modeVal = 0;
109
+ // Explicit booleans for clarity
110
+ this._debugShaders = !!debugShaders;
111
+ this._drawingBufferWidth = width;
112
+ this._drawingBufferHeight = height;
126
113
 
127
- this._debugMode = modeVal;
128
- const code = ex.wasm_ctx_set_debug_mode(this._ctxHandle, modeVal);
129
- _checkErr(code, this._instance);
114
+ WasmWebGL2RenderingContext._contexts.set(this._ctxHandle, this);
130
115
  }
131
116
 
132
117
  get drawingBufferWidth() {
@@ -544,7 +529,7 @@ export class WasmWebGL2RenderingContext {
544
529
  const fsWasm = this.getProgramWasm(program, this.FRAGMENT_SHADER);
545
530
 
546
531
  const createDebugEnv = (type, instanceRef) => {
547
- if (this._debugMode !== 1 && this._debugMode !== 3) return {};
532
+ if (!this._debugShaders) return {};
548
533
 
549
534
  const stubCode = this.getProgramDebugStub(program, type);
550
535
  if (!stubCode) return {};
@@ -564,6 +549,10 @@ export class WasmWebGL2RenderingContext {
564
549
 
565
550
  return {
566
551
  debug_step: (line, funcIdx, resultPtr) => {
552
+ if (line === 999999) {
553
+ console.log(`DEBUG LOG: val=${funcIdx} (0x${(funcIdx >>> 0).toString(16)})`);
554
+ return;
555
+ }
567
556
  const func = stubFuncs[line - 1];
568
557
  if (func) {
569
558
  const ctx = {
@@ -596,7 +585,7 @@ export class WasmWebGL2RenderingContext {
596
585
  });
597
586
  instanceRef.current = program._vsInstance;
598
587
  } catch (e) {
599
- // console.log(`DEBUG: VS Instance creation failed: ${e}`);
588
+ console.log(`DEBUG: VS Instance creation failed: ${e}`);
600
589
  }
601
590
  }
602
591
  if (fsWasm) {
@@ -613,7 +602,7 @@ export class WasmWebGL2RenderingContext {
613
602
  });
614
603
  instanceRef.current = program._fsInstance;
615
604
  } catch (e) {
616
- // console.log(`DEBUG: FS Instance creation failed: ${e}`);
605
+ console.log(`DEBUG: FS Instance creation failed: ${e}`);
617
606
  }
618
607
  }
619
608
  }
package/webgl2.debug.wasm CHANGED
Binary file
package/webgl2.wasm CHANGED
Binary file