glslh 1.1.0 → 1.1.2
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/CHANGELOG.md +21 -1
- package/README.md +5 -9
- package/package.json +1 -1
- package/src/parser.js +11 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
## 📋 `glslh` Changelog
|
|
2
2
|
|
|
3
|
-
### **v1.
|
|
3
|
+
### **v1.1.2** (Latest)
|
|
4
|
+
|
|
5
|
+
- **AI-Native Error Context Mapping**: Upgraded `translateShaderError` inside `parser.js` to automatically extract and embed surrounding 5-line code snippets (`--- Code Context ---`) directly alongside modular file and line indicators, allowing developers and AI assistants to diagnose and patch WebGL compilation errors instantly without manual file lookups.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
### **v1.1.1**
|
|
10
|
+
|
|
11
|
+
- **Documentation & README Refinement**: Updated documentation, architecture diagrams, and release logs to reflect complete structural guides for modular struct-based composition, CPU/GPU division of labor, and extension workflows.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
### **v1.1.0**
|
|
16
|
+
|
|
17
|
+
- **Duplicate Function Collision Detection & Overloading Support**: Added automated static analysis to scan included modules and warn developers if conflicting function signatures clash, while fully supporting valid GLSL function overloading distinguished by parameter signatures.
|
|
18
|
+
- **Strict `#version` Directive Pinning**: Upgraded the preprocessor parsing pipeline to extract and pin `#version` directives to the absolute top of the generated string, ensuring full compliance with strict WebGL driver standards regardless of auto-injected uniform declarations or math constants.
|
|
19
|
+
- **Enhanced Error Line Mapping**: Improved error translation utilities to map monolithic WebGL compilation error line numbers back to their exact source file and line number (`[shape_utils.glsl:14]`).
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
### **v1.0.1**
|
|
4
24
|
|
|
5
25
|
- **Strict File Extension Whitelisting**: Added validation checks inside `GLSLHParser` to restrict `#include` directives exclusively to valid shader extensions (`.glsl`, `.glslh`, `.frag`, `.vert`, `.frag.glsl`, `.vert.glsl`), preventing security risks and unauthorized inclusions of non-shader files (e.g., `.py`, `.cpp`, `.txt`).
|
|
6
26
|
- **Compound Header Support**: Enhanced path checking to natively support complex shader extension combinations like `.frag.glslh` and `.vert.glslh`.
|
package/README.md
CHANGED
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
- **Clear CPU/GPU Separation:** All orchestration, math constant calculations (`Math.PI`), and uniform state updates run efficiently on the **CPU**, while heavy rasterization and pixel shading run natively in parallel on the **GPU**.
|
|
40
40
|
- **Zero Runtime Performance Cost:** Because modular files are stitched and compiled once during initialization, your shaders execute at full native GPU speed with zero runtime overhead.
|
|
41
41
|
- **C-Style `#include` Directives:** Split massive shaders into modular files with full circular dependency protection and strict extension validation.
|
|
42
|
-
- **Duplicate Function Collision Detection:** Automatically scans included modules and warns you if multiple files define conflicting function signatures (`float hash()`) before WebGL compilation fails.
|
|
43
|
-
- **Error
|
|
42
|
+
- **Duplicate Function Collision Detection:** Automatically scans included modules and warns you if multiple files define conflicting function signatures (`float hash()`) before WebGL compilation fails, while fully supporting valid GLSL function overloading.
|
|
43
|
+
- **Error Context Mapping:** Automatically captures and embeds 5-line surrounding code context snippets alongside modular file and line numbers when WebGL compilation fails.
|
|
44
44
|
- **Self-Contained Metadata Blocks:** Define uniform data types, default values, and derived per-frame formulas right at the top of your shader file (`@uniforms`).
|
|
45
45
|
- **Direct JavaScript Math Injection:** Use native JS constants like `Math.PI` or `Math.TAU` directly in your GLSL code; the preprocessor evaluates them before GPU compilation.
|
|
46
46
|
- **Framework Agnostic:** Seamlessly output standard Three.js `ShaderMaterial` objects ready for Vanilla JS, Three.js, or React Three Fiber.
|
|
@@ -93,22 +93,18 @@ package/
|
|
|
93
93
|
## 🚀 Installation & Quick Start
|
|
94
94
|
|
|
95
95
|
```bash
|
|
96
|
-
npm install glslh
|
|
96
|
+
npm install glslh@1.1.2
|
|
97
97
|
```
|
|
98
98
|
|
|
99
99
|
### 1. Create a `.glslh` Shader File (`./shaders/header.glslh`)
|
|
100
100
|
|
|
101
|
-
Refer to the complete working example setup here: [GLSLH](https://www.google.com/search?q=./test/shaders/header.glslh)
|
|
102
|
-
|
|
103
101
|
### 2. Run Declaratively in HTML (`index.html`)
|
|
104
102
|
|
|
105
|
-
Refer to the complete working example setup here: [index.html](https://www.google.com/search?q=./test/index.html)
|
|
106
|
-
|
|
107
103
|
---
|
|
108
104
|
|
|
109
105
|
## ⚡ VS Code Extension (Live Preview)
|
|
110
106
|
|
|
111
|
-
Want instant syntax highlighting, color pickers, and a live WebGL preview pane right inside your editor? Install the official **GLSLH Previewer** extension from the marketplace:
|
|
107
|
+
Want instant syntax highlighting, color pickers, and a live WebGL preview pane right inside your editor? Install the official [**GLSLH Previewer**](https://marketplace.visualstudio.com/items?itemName=SudhanshuAmbastha.glslh-previewer) extension from the marketplace:
|
|
112
108
|
|
|
113
109
|
- **Live WebGL Preview:** Inspect shaders side-by-side with automatic hot-reloading on save.
|
|
114
110
|
- **Native Color Pickers:** Click color definitions or uniform arrays in `@uniforms` or `vec3()` blocks to adjust values visually.
|
|
@@ -118,4 +114,4 @@ Want instant syntax highlighting, color pickers, and a live WebGL preview pane r
|
|
|
118
114
|
|
|
119
115
|
## 📜 License
|
|
120
116
|
|
|
121
|
-
Distributed under the
|
|
117
|
+
Distributed under the **MIT License**. See [`LICENSE`](../LICENSE) for more information.
|
package/package.json
CHANGED
package/src/parser.js
CHANGED
|
@@ -103,7 +103,6 @@ export class GLSLHParser {
|
|
|
103
103
|
new Set(),
|
|
104
104
|
);
|
|
105
105
|
|
|
106
|
-
// Run duplicate function collision check on the final flattened source
|
|
107
106
|
detectFunctionCollisions(result.source);
|
|
108
107
|
|
|
109
108
|
return result;
|
|
@@ -239,7 +238,6 @@ export class GLSLHParser {
|
|
|
239
238
|
}
|
|
240
239
|
}
|
|
241
240
|
|
|
242
|
-
// 1. Extract #version if present so it always stays at the absolute top
|
|
243
241
|
const versionMatch = processed.match(/^\s*#version[^\n]*\r?\n/);
|
|
244
242
|
let versionHeader = "";
|
|
245
243
|
if (versionMatch) {
|
|
@@ -247,7 +245,6 @@ export class GLSLHParser {
|
|
|
247
245
|
processed = processed.slice(versionHeader.length);
|
|
248
246
|
}
|
|
249
247
|
|
|
250
|
-
// 2. Build auto-injected math constants defines
|
|
251
248
|
let constantsBlock = "";
|
|
252
249
|
if (usedConstants.size > 0) {
|
|
253
250
|
constantsBlock = "// --- GLSLH Auto-injected Math Constants ---\n";
|
|
@@ -258,7 +255,6 @@ export class GLSLHParser {
|
|
|
258
255
|
constantsBlock += "\n";
|
|
259
256
|
}
|
|
260
257
|
|
|
261
|
-
// 3. Build auto-injected uniform declarations
|
|
262
258
|
let declBlock = "";
|
|
263
259
|
const declLines = Object.entries(uniformsDefinition)
|
|
264
260
|
.filter(
|
|
@@ -273,7 +269,6 @@ export class GLSLHParser {
|
|
|
273
269
|
"\n\n";
|
|
274
270
|
}
|
|
275
271
|
|
|
276
|
-
// 4. Re-assemble with #version strictly at the top
|
|
277
272
|
processed = versionHeader + constantsBlock + declBlock + processed;
|
|
278
273
|
|
|
279
274
|
return {
|
|
@@ -362,7 +357,17 @@ export function translateShaderError(
|
|
|
362
357
|
const mapped = lineMap.at(flatLine - 1);
|
|
363
358
|
|
|
364
359
|
if (mapped && !mapped.isMarker) {
|
|
365
|
-
|
|
360
|
+
const contextStart = Math.max(0, flatLine - 3);
|
|
361
|
+
const contextEnd = Math.min(lines.length - 1, flatLine + 1);
|
|
362
|
+
let snippet = "\n--- Code Context ---\n";
|
|
363
|
+
|
|
364
|
+
for (let i = contextStart; i <= contextEnd; i++) {
|
|
365
|
+
const prefix = i === flatLine - 1 ? " >> " : " ";
|
|
366
|
+
snippet += `${prefix}${i + 1}: ${lines[i]}\n`;
|
|
367
|
+
}
|
|
368
|
+
snippet += "--------------------";
|
|
369
|
+
|
|
370
|
+
return `[File: ${mapped.file} | Line: ${mapped.line}]${snippet}`;
|
|
366
371
|
}
|
|
367
372
|
return match;
|
|
368
373
|
});
|