webgl2 1.0.8 → 1.0.10
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 +37 -20
- package/index.js +2 -2
- package/package.json +3 -4
package/README.md
CHANGED
|
@@ -6,23 +6,33 @@ A **Rust + WASM** based toolkit for debugging GLSL shaders and generating ergono
|
|
|
6
6
|
|
|
7
7
|
## 🎯 Quick Start
|
|
8
8
|
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
npm run build
|
|
9
|
+
```javascript
|
|
10
|
+
import { webGL2 } from 'webgl2';
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
```
|
|
12
|
+
// Initialize the Rust-backed WebGL2 context
|
|
13
|
+
const gl = await webGL2();
|
|
16
14
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
// Use it like a standard WebGL2RenderingContext
|
|
16
|
+
const buffer = gl.createBuffer();
|
|
17
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
18
|
+
```
|
|
20
19
|
|
|
21
20
|
```bash
|
|
22
|
-
#
|
|
21
|
+
# Build the project (Rust + WASM)
|
|
23
22
|
npm run build
|
|
23
|
+
|
|
24
|
+
# Run the extensive test suite
|
|
25
|
+
npm test
|
|
24
26
|
```
|
|
25
27
|
|
|
28
|
+
## ✨ Key Features
|
|
29
|
+
|
|
30
|
+
- **Rust-Owned Context**: All WebGL2 state (textures, buffers, framebuffers) lives in Rust for deterministic resource management.
|
|
31
|
+
- **GLSL to WASM Compiler**: Compiles GLSL shaders directly to WebAssembly using Naga IR.
|
|
32
|
+
- **Integrated Debugging**: Generates DWARF debug information for shaders, enabling step-through debugging in browser DevTools.
|
|
33
|
+
- **Software Rasterizer**: A full software-based WebGL2 implementation for headless testing and GPU-independent execution.
|
|
34
|
+
- **JS Thin-Forwarder**: Ergonomic JavaScript bindings that forward calls to the WASM core with minimal overhead.
|
|
35
|
+
|
|
26
36
|
## 🚀 Project Overview and Goals
|
|
27
37
|
|
|
28
38
|
The project aims to create a **Composite WebGL2 Development Platform** built with **Rust and WASM**. The primary objective is to significantly improve the WebGL2 developer experience by introducing standard software engineering practices—specifically, **robust debugging and streamlined resource management**—into the WebGL/GLSL workflow, which is currently hindered by hairy API, lack of debugging, incomprehensible errors and opaque GPU execution.
|
|
@@ -37,24 +47,31 @@ The project aims to create a **Composite WebGL2 Development Platform** built wit
|
|
|
37
47
|
|
|
38
48
|
## 🏗️ Architecture
|
|
39
49
|
|
|
40
|
-
|
|
50
|
+
The platform follows a "Rust-first" architecture where the GPU state and shader execution are managed by a high-performance Rust core compiled to WASM.
|
|
51
|
+
|
|
52
|
+
1. **Frontend**: A thin JS wrapper (`WasmWebGL2RenderingContext`) that mirrors the WebGL2 API.
|
|
53
|
+
2. **Compiler**: Uses **Naga** to parse GLSL and a custom **WASM Backend** to emit executable WASM modules with DWARF debug info.
|
|
54
|
+
3. **Emulator**: A software rasterizer (`wasm_gl_emu`) that executes shader logic and manages the framebuffer.
|
|
55
|
+
4. **Context**: A centralized registry (`webgl2_context.rs`) that tracks all GL resources and handles lifecycle.
|
|
41
56
|
|
|
42
57
|
## 🔧 Development Status
|
|
43
58
|
|
|
44
|
-
**Current Phase: Phase
|
|
59
|
+
**Current Phase: Phase 1 - Core Emulator & Compiler** ✅
|
|
45
60
|
|
|
46
|
-
- [x]
|
|
47
|
-
- [x]
|
|
48
|
-
- [x]
|
|
49
|
-
- [x]
|
|
50
|
-
- [x]
|
|
51
|
-
- [ ]
|
|
52
|
-
- [ ] Browser DevTools integration validation
|
|
61
|
+
- [x] Rust-owned WebGL2 Context & Resource Registry
|
|
62
|
+
- [x] Naga-to-WASM backend with DWARF support
|
|
63
|
+
- [x] Software Rasterizer for shader emulation
|
|
64
|
+
- [x] JS/TS ergonomic bindings
|
|
65
|
+
- [x] Extensive WebGL2 API test coverage (>100 tests)
|
|
66
|
+
- [ ] Browser DevTools integration validation (in progress)
|
|
53
67
|
|
|
54
68
|
## 📚 Documentation
|
|
55
69
|
|
|
56
70
|
- [`docs/1-plan.md`](docs/1-plan.md) - Original project proposal and plan
|
|
57
|
-
- [`docs/1.1-ir-wasm.md`](docs/1.1-ir-wasm.md) - Naga IR → WASM architecture
|
|
71
|
+
- [`docs/1.1-ir-wasm.md`](docs/1.1-ir-wasm.md) - Naga IR → WASM architecture
|
|
72
|
+
- [`docs/1.1.1-webgl2-prototype.md`](docs/1.1.1-webgl2-prototype.md) - Rust-owned Context design
|
|
73
|
+
- [`docs/1.1.2-texture.md`](docs/1.1.2-texture.md) - Texture implementation details
|
|
74
|
+
- [`docs/1.1.3-rust-wasm-test-coverage.md`](docs/1.1.3-rust-wasm-test-coverage.md) - Testing strategy and coverage
|
|
58
75
|
|
|
59
76
|
## 🧪 Testing
|
|
60
77
|
|
package/index.js
CHANGED
|
@@ -116,9 +116,9 @@ async function initWASM() {
|
|
|
116
116
|
const bytes = mem.subarray(ptr, ptr + len);
|
|
117
117
|
console.log(new TextDecoder('utf-8').decode(bytes));
|
|
118
118
|
},
|
|
119
|
-
wasm_execute_shader: (type, attrPtr, uniformPtr, varyingPtr, privatePtr) => {
|
|
119
|
+
wasm_execute_shader: (type, attrPtr, uniformPtr, varyingPtr, privatePtr, texturePtr) => {
|
|
120
120
|
if (WasmWebGL2RenderingContext.activeContext) {
|
|
121
|
-
WasmWebGL2RenderingContext.activeContext._executeShader(type, attrPtr, uniformPtr, varyingPtr, privatePtr);
|
|
121
|
+
WasmWebGL2RenderingContext.activeContext._executeShader(type, attrPtr, uniformPtr, varyingPtr, privatePtr, texturePtr);
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webgl2",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
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",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"start": "node ./index.js",
|
|
9
|
-
"build": "cargo build --target wasm32-unknown-unknown --release &&
|
|
10
|
-
"build:wasm": "node scripts/build-wasm.cjs",
|
|
9
|
+
"build": "cargo build --target wasm32-unknown-unknown --release && node -e \"fs.copyFileSync('target/wasm32-unknown-unknown/release/webgl2.wasm', 'webgl2.wasm')\"",
|
|
11
10
|
"prepublishOnly": "npm run build",
|
|
12
11
|
"test": "node --test test/*.test.js",
|
|
13
|
-
"test:smoke": "npm run build
|
|
12
|
+
"test:smoke": "npm run build && node ./test/smoke.js"
|
|
14
13
|
},
|
|
15
14
|
"wasmBuild": {
|
|
16
15
|
"outDir": "wasm",
|