# benpm/gl_playground architecture

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

- Interactive diagram: https://gitdiagram.com/benpm/gl_playground
- Repository: https://github.com/benpm/gl_playground

## Overview

##### Main Components

a. Core Application & Main Loop
- Components such as main.cpp and app.cpp/app.hpp which initialize the application, manage the main loop, and orchestrate interactions between systems.
- This as the central “Application Controller” block.

b. Rendering Engine
- Components such as gfx.cpp/gfx.hpp, camera.cpp/camera.hpp, model.cpp/model.hpp, mesh.cpp, and light.cpp belong to the rendering system.
- Shader files (found in the resources/shaders directory) as part of the rendering pipeline.
- How models, textures, and lighting information are processed and rendered.

c. Physics & Simulation
- The physics module (physics.cpp/physics.hpp) indicates an interactive physics engine, with additional support for rigid body and soft body simulation.

d. Asset & Resource Management
- Assets such as models, textures, fonts, and shaders are stored in the resources directory.
- Script components (download_assets.sh, package_assets.sh, and upload_assets.sh) that manage external assets.
- This block as the “Asset Manager,” which provides data (models, textures, materials) to the rendering engine and possibly the physics system.

e. Utility Libraries & Third-Party Dependencies
- The project integrates numerous external libraries: GLFW for window/context management; eigen for math operations; glad for OpenGL extension loading; spdlog for logging; EnTT for entity-component management; and others.
- Additionally, note the use of a “lib” folder containing custom (or vendor-supplied) code that supports the project’s functionality.

f. Build & Configuration Infrastructure
- The presence of the CMakeLists.txt file, the cmake directory with several cmake configuration scripts, and platform-specific build instructions in the README should be represented as the “Build System.”
- This block can indicate preprocessing, dependency resolution, and build configuration that generates the executable.

##### Relationships and Data Flows

- From the "Core Application" to the "Rendering Engine" (to pass scene updates, camera positions, and command calls).
- From the "Core Application" to the "Physics Engine" (to update simulation and retrieve new object positions).
- From the "Asset Manager" to both "Rendering Engine" and "Physics Engine" (indicating that assets such as models and textures are loaded and used in these systems).
- From the "Build System" to all modules, illustrating how configuration and build scripts bring together all modules and external dependencies.
- From the "External Libraries/Dependencies" block into the "Rendering" and "Physics" blocks indicating that these libraries are integrated throughout the system.

##### Architectural Patterns and Design Principles

- A modular design:
- The separation between the application controller, rendering, physics simulation, and asset management suggests a modular design where each component has distinct responsibilities.
- Dependency injection and configuration via CMake:
- How the project uses CMake scripts (in the cmake folder) to integrate third-party libraries such as GLFW, Eigen, and so on.
- If applicable, point out design aspects like a scene graph approach in the interplay between the rendering and physics systems (although not explicitly a scene graph, the separation of assets and transformation data gives a similar conceptual model).

##### Putting It All Together

- The separation between key subsystems: the Core Application, Rendering, Physics, and Asset Management.
- The build and dependency integration layer via CMake and external libraries.
- The flow of data from asset resources through to final rendered output and physics simulation.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Build & Configuration
    subgraph "Build & Configuration"
        BS1("CMakeLists.txt"):::build
        BS2("cmake"):::build
        BS3("README.md"):::build
    end

    %% External Libraries/Dependencies
    subgraph "External Libraries/Dependencies"
        EL1("lib"):::external
        EL2("extmath.hpp"):::external
    end

    %% Core Application (Main Loop)
    subgraph "Core Application (Main Loop)"
        CA1("main.cpp"):::core
        CA2("app.cpp"):::core
        CA3("app.hpp"):::core
    end

    %% Asset & Resource Management
    subgraph "Asset & Resource Management"
        AM1("resources"):::assets
        AM2("download_assets.sh"):::assets
        AM3("package_assets.sh"):::assets
        AM4("upload_assets.sh"):::assets
    end

    %% Rendering Engine (Shaders, Models, Lights, Cameras)
    subgraph "Rendering Engine (Shaders, Models, Lights, Cameras)"
        RE1("gfx.cpp"):::rendering
        RE2("gfx.hpp"):::rendering
        RE3("camera.cpp"):::rendering
        RE4("camera.hpp"):::rendering
        RE5("model.cpp"):::rendering
        RE6("model.hpp"):::rendering
        RE7("mesh.cpp"):::rendering
        RE8("mesh.hpp"):::rendering
        RE9("light.cpp"):::rendering
        RE10("light.hpp"):::rendering
        RE11("Shaders"):::rendering
    end

    %% Physics Engine (Rigid & Soft Body)
    subgraph "Physics Engine (Rigid & Soft Body)"
        PE1("physics.cpp"):::physics
        PE2("physics.hpp"):::physics
    end

    %% Relationships & Data Flows
    %% Build System configures all modules
    BS1 -->|"builds"| CA1
    BS1 -->|"builds"| AM1
    BS1 -->|"builds"| RE1
    BS1 -->|"builds"| PE1

    %% External Libraries integration
    EL1 -->|"integrates"| RE1
    EL1 -->|"integrates"| PE1

    %% Core Application updates engines
    CA1 -->|"updates"| RE1
    CA1 -->|"updates"| PE1

    %% Asset Manager supplies resources
    AM1 -->|"supplies"| RE1
    AM1 -->|"supplies"| PE1

    %% Click Events for Core Application
    click CA1 "https://github.com/benpm/gl_playground/blob/main/src/main.cpp"
    click CA2 "https://github.com/benpm/gl_playground/blob/main/src/app.cpp"
    click CA3 "https://github.com/benpm/gl_playground/blob/main/include/app.hpp"

    %% Click Events for Rendering Engine
    click RE1 "https://github.com/benpm/gl_playground/blob/main/src/gfx.cpp"
    click RE2 "https://github.com/benpm/gl_playground/blob/main/include/gfx.hpp"
    click RE3 "https://github.com/benpm/gl_playground/blob/main/src/camera.cpp"
    click RE4 "https://github.com/benpm/gl_playground/blob/main/include/camera.hpp"
    click RE5 "https://github.com/benpm/gl_playground/blob/main/src/model.cpp"
    click RE6 "https://github.com/benpm/gl_playground/blob/main/include/model.hpp"
    click RE7 "https://github.com/benpm/gl_playground/blob/main/src/mesh.cpp"
    click RE8 "https://github.com/benpm/gl_playground/blob/main/include/mesh.hpp"
    click RE9 "https://github.com/benpm/gl_playground/blob/main/src/light.cpp"
    click RE10 "https://github.com/benpm/gl_playground/blob/main/include/light.hpp"
    click RE11 "https://github.com/benpm/gl_playground/tree/main/resources/shaders"

    %% Click Events for Physics Engine
    click PE1 "https://github.com/benpm/gl_playground/blob/main/src/physics.cpp"
    click PE2 "https://github.com/benpm/gl_playground/blob/main/include/physics.hpp"

    %% Click Events for Asset Manager
    click AM1 "https://github.com/benpm/gl_playground/tree/main/resources"
    click AM2 "https://github.com/benpm/gl_playground/blob/main/download_assets.sh"
    click AM3 "https://github.com/benpm/gl_playground/blob/main/package_assets.sh"
    click AM4 "https://github.com/benpm/gl_playground/blob/main/upload_assets.sh"

    %% Click Events for External Libraries
    click EL1 "https://github.com/benpm/gl_playground/tree/main/lib"
    click EL2 "https://github.com/benpm/gl_playground/blob/main/include/extmath.hpp"

    %% Click Events for Build & Configuration
    click BS1 "https://github.com/benpm/gl_playground/blob/main/CMakeLists.txt"
    click BS2 "https://github.com/benpm/gl_playground/tree/main/cmake"
    click BS3 "https://github.com/benpm/gl_playground/blob/main/README.md"

    %% Styles
    classDef core fill:#f9c74f,stroke:#333,stroke-width:2px;
    classDef rendering fill:#90be6d,stroke:#333,stroke-width:2px;
    classDef physics fill:#43aa8b,stroke:#333,stroke-width:2px;
    classDef assets fill:#f9844a,stroke:#333,stroke-width:2px;
    classDef external fill:#577590,stroke:#333,stroke-width:2px;
    classDef build fill:#f94144,stroke:#333,stroke-width:2px;
```
