# edubart/sokol_gp architecture

> Architecture diagram of the GitHub repository edubart/sokol_gp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/edubart/sokol_gp
- Repository: https://github.com/edubart/sokol_gp

## Overview

##### Main Components Identification

The system should be represented with these key components:

a) Core Components:
- Sokol GP Core (Main Interface)
- Command Queue Manager
- Batch Optimizer
- State Manager
- Pipeline Manager
- Transform Manager

b) External Dependencies:
- Sokol GFX (Graphics Backend)
- Platform-specific Graphics APIs (D3D11/OpenGL/Metal/WebGPU)

**[Application Layer]**
- ↓
**[Sokol GP Layer]**
- Command Queue Manager
- Batch Optimizer
- State Manager
- Pipeline Manager
- Transform Manager
- ↓
**[Sokol GFX Layer]**
- ↓
**[Graphics API Layer]**

##### Component Details

For each component, highlight:

Command Queue Manager:
- Pre-allocated command buffer management
- Command dispatch to Sokol GFX

Batch Optimizer:
- 8-command lookback window (configurable)
- Pipeline state matching
- Texture binding optimization

State Manager:
- Viewport management
- Transform state
- Texture bindings
- Blend modes

Pipeline Manager:
- Built-in pipelines
- Custom shader pipeline creation
- Uniform management

Transform Manager:
- 2D space transformations
- Matrix stack management
- Viewport projection

##### Data Flow

- State changes affecting the pipeline
- Transform matrix updates
- Texture and uniform bindings

##### Notes

Annotations for:
- Configuration options (SGP_BATCH_OPTIMIZER_DEPTH, SGP_UNIFORM_CONTENT_SLOTS, etc.)
- Memory management strategy
- Performance optimization points
- Backend compatibility

This design captures both the simplicity of the API for users and the sophisticated internal optimizations that make the library efficient for 2D graphics rendering.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef external fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef manager fill:#2ecc71,stroke:#27ae60,color:white
    classDef optimizer fill:#e67e22,stroke:#d35400,color:white
    classDef api fill:#34495e,stroke:#2c3e50,color:white

    %% Application Layer
    subgraph AppLayer["Application Layer"]
        App[Application]
    end

    %% Sokol GP Layer
    subgraph SokolGPLayer["Sokol GP Layer"]
        Core["Sokol GP Core"]:::core
        CmdQueue["Command Queue Manager"]:::manager
        BatchOpt["Batch Optimizer"]:::optimizer
        StateMan["State Manager"]:::manager
        PipeMan["Pipeline Manager"]:::manager
        TransMan["Transform Manager"]:::manager
    end

    %% Sokol GFX Layer
    subgraph SokolGFXLayer["Sokol GFX Layer"]
        SokolGFX["Sokol GFX"]:::external
    end

    %% Graphics API Layer
    subgraph GraphicsAPILayer["Graphics API Layer"]
        D3D11["Direct3D 11"]:::api
        OpenGL["OpenGL"]:::api
        Metal["Metal"]:::api
        WebGPU["WebGPU"]:::api
    end

    %% Relationships
    App --> Core
    Core --> CmdQueue
    CmdQueue --> BatchOpt
    BatchOpt --> SokolGFX
    Core --> StateMan
    Core --> PipeMan
    Core --> TransMan
    
    StateMan --> BatchOpt
    PipeMan --> BatchOpt
    TransMan --> BatchOpt
    
    SokolGFX --> D3D11
    SokolGFX --> OpenGL
    SokolGFX --> Metal
    SokolGFX --> WebGPU

    %% Click events
    click Core "https://github.com/edubart/sokol_gp/blob/master/sokol_gp.h"
    click CmdQueue "https://github.com/edubart/sokol_gp/blob/master/sokol_gp.h"
    click BatchOpt "https://github.com/edubart/sokol_gp/blob/master/sokol_gp.h"
    click StateMan "https://github.com/edubart/sokol_gp/blob/master/sokol_gp.h"
    click PipeMan "https://github.com/edubart/sokol_gp/blob/master/shaders/sokol_gp.glsl"
    click TransMan "https://github.com/edubart/sokol_gp/blob/master/sokol_gp.h"
    click SokolGFX "https://github.com/edubart/sokol_gp/blob/master/thirdparty/sokol_gfx.h"

    %% Legend
    subgraph Legend
        L1["Core Component"]:::core
        L2["Manager Component"]:::manager
        L3["Optimizer Component"]:::optimizer
        L4["External Dependency"]:::external
        L5["Graphics API"]:::api
    end
```
