# aliabbas299792/openglwasmtemplate architecture

> Architecture diagram of the GitHub repository aliabbas299792/openglwasmtemplate, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aliabbas299792/openglwasmtemplate
- Repository: https://github.com/aliabbas299792/openglwasmtemplate

## Overview

##### Main Components

a) Client-Side Components:
- Inside the browser container, include:
- WebGL 2.0 Runtime
- WebAssembly Runtime
- JavaScript Bridge
- HTML5 Canvas Element

b) Build System Components:
- Emscripten Toolchain
- Shader Compilation Pipeline
- C++ Compilation Pipeline

##### Component Relationships

Layer 1 (Source):

Layer 2 (Build Pipeline):
- Emscripten compilation flow
- Shader compilation flow

Layer 3 (Runtime):
- Browser environment
- WebAssembly execution
- WebGL rendering pipeline

##### Use the following symbols and conventions

- Use rectangles for main components
- Use hexagons for build tools

##### Specific Component Details

a) Source Code Section:
**main.cpp → helper.cpp → shader.cpp**
- ↓          ↓          ↓
**helper.h ←–––– shader.h**

b) Shader Pipeline:
**fragshader.glsl → Shader Compilation → WebGL Shaders**
**vertexshader.glsl ↗**

c) Runtime Flow:
**WASM Module → JavaScript Bridge → WebGL Context → Canvas**

##### Important Notes

- Role of Emscripten in bridging C++ and WebAssembly
- How GLFW3 and GLM are integrated
- Shader compilation and loading process
- Demonstrate the event loop mechanism using emscripten_set_main_loop

##### Technical Details

- Node.js server component (minimal, for development)
- GLES 3.0 to WebGL 2.0 mapping
- Memory management between WASM and JavaScript
- GLM mathematics library integration
- GLFW3 event handling

##### Execution Flow

**index.html → library.js → index.wasm**
- ↓
- WebGL Context
- ↓
- Canvas Rendering

Remember to:
- Keep the main architectural components clearly separated
- Build pipeline as a distinct process
- Runtime interaction between WebAssembly and WebGL
- Notes about performance-critical paths
- Version compatibility information (GLES 3.0 → WebGL 2.0)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Browser["Browser Environment"]
        direction TB
        HTML["HTML5 Entry Point"]:::html
        Canvas["Canvas Element"]:::runtime
        WebGL["WebGL 2.0 Context"]:::runtime
        WASM["WebAssembly Runtime"]:::runtime
        JSBridge["JavaScript Bridge"]:::js
        
        HTML --> Canvas
        HTML --> WebGL
        HTML --> WASM
        HTML --> JSBridge
        WebGL --> Canvas
        WASM --> JSBridge
        JSBridge --> WebGL
    end

    subgraph Source["Source Code"]
        direction TB
        Main["Main Application"]:::cpp
        Helper["Helper Implementation"]:::cpp
        ShaderImpl["Shader Implementation"]:::cpp
        Headers["Header Files"]:::header
        
        Main --> Helper
        Main --> ShaderImpl
        Helper --> Headers
        ShaderImpl --> Headers
    end

    subgraph Assets["Asset Files"]
        direction TB
        VertShader["Vertex Shader"]:::glsl
        FragShader["Fragment Shader"]:::glsl
        GLM["GLM Math Library"]:::lib
    end

    subgraph BuildSystem["Build Pipeline"]
        direction TB
        Emscripten["Emscripten Toolchain"]:::build
        ShaderCompiler["Shader Compiler"]:::build
        BuildScript["Build Script"]:::build
        
        Emscripten --> |"Compiles"| WASM
        ShaderCompiler --> |"Processes"| WebGL
    end

    Source --> BuildSystem
    Assets --> BuildSystem
    
    classDef html fill:#f9f,stroke:#333
    classDef runtime fill:#c9e,stroke:#333
    classDef js fill:#ff9,stroke:#333
    classDef cpp fill:#9cf,stroke:#333
    classDef header fill:#cff,stroke:#333
    classDef glsl fill:#9f9,stroke:#333
    classDef build fill:#fc9,stroke:#333
    classDef lib fill:#ccc,stroke:#333

    click HTML "https://github.com/aliabbas299792/openglWASMTemplate/blob/master/public/index.html"
    click WASM "https://github.com/aliabbas299792/openglWASMTemplate/blob/master/public/index.wasm"
    click JSBridge "https://github.com/aliabbas299792/openglWASMTemplate/blob/master/public/library.js"
    click Main "https://github.com/aliabbas299792/openglWASMTemplate/blob/master/public/src/main.cpp"
    click ShaderImpl "https://github.com/aliabbas299792/openglWASMTemplate/blob/master/public/src/helperAndShader/shader.cpp"
    click Helper "https://github.com/aliabbas299792/openglWASMTemplate/blob/master/public/src/helperAndShader/helper.cpp"
    click Headers "https://github.com/aliabbas299792/openglWASMTemplate/tree/master/public/src/header"
    click VertShader "https://github.com/aliabbas299792/openglWASMTemplate/blob/master/public/assets/vertexshader.glsl"
    click FragShader "https://github.com/aliabbas299792/openglWASMTemplate/blob/master/public/assets/fragshader.glsl"
    click BuildScript "https://github.com/aliabbas299792/openglWASMTemplate/blob/master/public/compile.sh"
    click GLM "https://github.com/aliabbas299792/openglWASMTemplate/blob/master/public/include/glm.sh"
```
