How patriciogonzalezvivo/glsleditor works
Project type and purpose
• This is a standalone, client-side WebGL/JavaScript application (“glslEditor”) that provides an in-browser (and Electron) GLSL shader editing environment.
• It packages as a pure-frontend library (build/glslEditor.js + .css) and has an Electron wrapper for local desktop use.
File structure
• Top-level:
• build/ ← production artifacts (glslEditor.js, .css, source maps)
• gulpfile.js ← build/task runner
• index.html ← demo/embed page
• package.json ← dependencies, scripts (start, dev)
• src/ ← source code
• src/css/ ← global styling and component styles
• src/index.html ← development HTML shell
• src/js/:
• core/ ← core classes: Editor.js (ties CodeMirror + UI), Shader.js (compiles GLSL, interfaces with WebGL)
• io/ ← BufferManager, FileDrop, LocalStorage, Share modules
• tools/ ← utilities (debugging, downloading, media capture, URL handling, interactive DOM helpers)
• ui/ ← visual components (menus, pickers, error displays, modals, debugger)
• main.js ← Electron main process entrypoint
README for additional insights
• Built on top of CodeMirror, glslCanvas or glslViewer backends.
• Exposes an API: new GlslEditor(element, options).
• Supports drag-drop, hash-watch, multiple buffers, menu, inline pickers, error display, breakpoints.
Main components
a. User Interfaces (Browser or Electron UI)
• HTML container
• CSS styles
• UI modules (Menus, Pickers, Modals, Debugger)
b. Editor Core
• CodeMirror integration (syntax, editing)
• Buffer management (multiple shader files/tabs)
c. GLSL Shader Pipeline
• Shader.js → compiles GLSL, injects headers/footers
• WebGL canvas (via glslCanvas or native WebGL context)
d. I/O and Persistence Modules
• FileDrop → drag & drop files
• LocalStorage → save/load shaders in browser storage
• Share → generate share links / export
• HashWatch → URL hash‐based file loading
e. Utility Tools
• Debugging, media capture, downloads, interactive DOM helpers
f. Build & Packaging
• Gulp tasks (build, minify)
• npm scripts (start, dev)
g. Electron Layer (optional)
• main.js process
• renderer loads the same src/js modules
Relationships and interactions
• User interacts with UI components → events sent to Editor core
• Editor core reads/writes shader buffers via I/O modules
• On compile/run: Editor passes shader code to Shader.js → WebGL context → Canvas output
• UI pickers hook into Editor to modify uniform values at runtime
• Tools respond to user actions (download code, capture media, debug shader)
• Build system (Gulp) generates the final glslEditor.js/css artifacts consumed by index.html or by Electron renderer
Architectural patterns and design principles
• Modular directory structure by responsibility (core, io, tools, ui)
• Single-page application style; MVC-like: Editor (Controller), UI (View), BufferManager & Shader (Model)
• Event-driven communication (custom events or callback hooks)
• Reuse of external libraries (CodeMirror, glslCanvas)
Elements
• User → UI
• UI → Editor core
• Editor core ↔ I/O modules
• Core → Shader.js → WebGL Canvas
• Tools ↔ Core/UI
• Labels for external dependencies (CodeMirror, WebGL, Electron)
Final advice
• Don’t omit the build step and Electron wrapper.
• Data flow (shader code, uniform values) and control flow (user actions, compile triggers).
• Keep it detailed but organized by functional layers.