# thatmg393-2/fogltlogles architecture

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

- Interactive diagram: https://gitdiagram.com/thatmg393-2/fogltlogles
- Repository: https://github.com/thatmg393-2/fogltlogles

## Overview

##### Project type and purpose
- This is a C++ “translation layer” library whose job is to let an application written to the OpenGL API run on OpenGL ES 3.2 drivers. It wraps, adapts, and translates desktop-GL calls (and shaders) into GLES calls. It bundles third-party shader tooling (Shaderc, SPIRV-Cross), and provides its own state-tracking, binding, and command-translation logic.

##### File structure
- Top-level:
- / : public headers for EGL, GL, GLES variants, shader interfaces, utilities
- src/ : implementation grouped by API surface (egl/, gl/, gles/, gles20/, gles30/, gles32/)
- deps/ : embedded third-party repos (shaderc, spirv-cross)
- tools/ : auxiliary utilities (clangd config)
- build scripts (CMakeLists.txt, build.sh), devcontainer and CI config
- Patterns:
- Adapter/Wrapper pattern: each GL entry point is re-implemented and forwarded to GLES equivalents
- State-tracking modules: track buffers/textures/framebuffers for GLES limitations
- Shader pipeline: preprocess, compile (Shaderc), cross-compile (SPIRV-Cross), postprocess

##### README for insights
- Confirms it’s a “Fast OpenGL Translation Layer to OpenGL ES”, proof-of-concept, relies on GLES 3.2, uses Shaderc and SPIRV-Cross.

##### Final advice
- Shader translation pipeline end-to-end
- Both build-time (CMake/Shaderc/SPIRV-Cross) and run-time (API interception, state tracking, actual GLES calls)
- Don’t overthink: a clear separation into Application → FOGLTLOGLES → GLES Driver plus Shader Pipeline is sufficient

## Diagram (Mermaid)

```mermaid
flowchart TD
    classDef internal fill:#add8e6,stroke:#000;
    classDef external fill:#ffa500,stroke:#000;
    classDef driver fill:#90ee90,stroke:#000;

    Application["Application (OpenGL App)"]:::external

    subgraph "FOGLTLOGLES Library"
        subgraph "Public API Layer"
            GLh["gl.h"]:::internal
            GLshader["shader.h"]:::internal
            GLESh["main.h (gles)"]:::internal
            GLES20h["main.h (gles20)"]:::internal
            GLES30h["main.h (gles30)"]:::internal
            GLES32h["main.h (gles32)"]:::internal
            EGLh["egl.h"]:::internal
        end

        subgraph "Context Management (EGL)"
            EGLcpp["egl.cpp"]:::internal
        end

        subgraph "Core Translation Modules"
            GLcpp["gl.cpp"]:::internal
            State["state_tracking.h"]:::internal
            Utils["utils.h"]:::internal
            Proxy["proxy.h"]:::internal
        end

        subgraph "Fixed-Function Pipeline Emulation"
            FFPmain["main.cpp"]:::internal
            FFPcolor["color.cpp"]:::internal
            FFPmatrix["matrix.cpp"]:::internal
            FFPvertex["vertex.cpp"]:::internal
            FFPinc["main.h"]:::internal
            FFPesffp["ffp.h"]:::internal
        end

        subgraph "GLES 2.0 Adapter & State Tracking"
            G20main["main.cpp"]:::internal
            G20track["tracking.cpp"]:::internal
            G20tex["textures.cpp"]:::internal
            G20rb["renderbuffer.cpp"]:::internal
            G20ext["ext/main.cpp"]:::internal
            G20bth["buffer_tracking.h"]:::internal
            G20fth["framebuffer_tracking.h"]:::internal
            G20tth["texture_tracking.h"]:::internal
        end

        subgraph "GLES 3.0 Adapter & Extensions"
            G30main["main.cpp"]:::internal
            G30trans["translation.cpp"]:::internal
            G30md["multidraw.cpp"]:::internal
            G30tex["textures.cpp"]:::internal
            G30h["main.h"]:::internal
            G30rp["read_pixels.h"]:::internal
        end

        subgraph "GLES 3.2 Adapter & Base Vertex"
            G32main["main.cpp"]:::internal
            G32bv["basevertex.cpp"]:::internal
            G32fb["framebuffer.cpp"]:::internal
            G32tex["textures.cpp"]:::internal
            G32h["main.h"]:::internal
        end

        subgraph "Shader Translation Pipeline"
            Preproc["preprocess.h"]:::internal
            Postproc["postprocess.h"]:::internal
            ShUtils["utils.h"]:::internal
            ShCache["cache.h"]:::internal
            ShConv["converter.h"]:::internal
            ShComp["compilers.h"]:::internal
            Shaderc["Shaderc"]:::external
            SPIRVC["SPIRV-Cross"]:::external
        end
    end

    Driver["GLES 3.2 Driver"]:::driver

    Application -->|Calls GL API| GLh
    GLh -->|forwards to| EGLcpp
    EGLcpp -->|initializes context| Driver

    GLh -->|intercept calls| GLcpp
    GLcpp -->|updates state| State
    GLcpp -->|uses utilities| Utils
    GLcpp -->|proxies calls| Proxy

    GLcpp -->|dispatch| G20main
    GLcpp -->|dispatch| G30main
    GLcpp -->|dispatch| G32main
    GLcpp -->|dispatch| FFPmain

    G20main -->|tracks| G20track
    G20main -->|textures| G20tex
    G20main -->|renderbuf| G20rb
    G20main -->|ext| G20ext
    G20main -->|calls| Driver
    G20bth -.-> G20main
    G20fth -.-> G20main
    G20tth -.-> G20main

    G30main -->|translate| G30trans
    G30main -->|multi-draw| G30md
    G30main -->|textures| G30tex
    G30main -->|calls| Driver
    G30h -.-> G30main
    G30rp -.-> G30main

    G32main -->|base vertex| G32bv
    G32main -->|framebuffer| G32fb
    G32main -->|textures| G32tex
    G32main -->|calls| Driver
    G32h -.-> G32main

    FFPmain -->|color| FFPcolor
    FFPmain -->|matrix| FFPmatrix
    FFPmain -->|vertex| FFPvertex
    FFPmain -->|calls| Driver
    FFPinc -.-> FFPmain
    FFPesffp -.-> FFPmain

    GLh -->|create shader| Preproc
    Preproc -->|post| Postproc
    Preproc -->|utils| ShUtils
    Preproc -->|caching| ShCache
    Preproc -->|conversion| ShConv
    Preproc -->|compilers| ShComp
    Preproc -->|invoke| Shaderc
    Shaderc -->|SPIR-V| SPIRVC
    SPIRVC -->|GLES GLSL| Preproc
    Preproc -->|runtime compile| Driver

    click GLh "https://github.com/thatmg393-2/fogltlogles/blob/master/include/gl/gl.h"
    click GLshader "https://github.com/thatmg393-2/fogltlogles/blob/master/include/gl/shader.h"
    click GLESh "https://github.com/thatmg393-2/fogltlogles/blob/master/include/gles/main.h"
    click GLES20h "https://github.com/thatmg393-2/fogltlogles/blob/master/include/gles20/main.h"
    click GLES30h "https://github.com/thatmg393-2/fogltlogles/blob/master/include/gles30/main.h"
    click GLES32h "https://github.com/thatmg393-2/fogltlogles/blob/master/include/gles32/main.h"
    click EGLh "https://github.com/thatmg393-2/fogltlogles/blob/master/include/egl/egl.h"
    click EGLcpp "https://github.com/thatmg393-2/fogltlogles/blob/master/src/egl/egl.cpp"
    click GLcpp "https://github.com/thatmg393-2/fogltlogles/blob/master/src/gl/gl.cpp"
    click State "https://github.com/thatmg393-2/fogltlogles/blob/master/include/es/state_tracking.h"
    click Utils "https://github.com/thatmg393-2/fogltlogles/blob/master/include/es/utils.h"
    click Proxy "https://github.com/thatmg393-2/fogltlogles/blob/master/include/es/proxy.h"
    click G20main "https://github.com/thatmg393-2/fogltlogles/blob/master/src/gles20/main.cpp"
    click G20track "https://github.com/thatmg393-2/fogltlogles/blob/master/src/gles20/tracking.cpp"
    click G20tex "https://github.com/thatmg393-2/fogltlogles/blob/master/src/gles20/textures.cpp"
    click G20rb "https://github.com/thatmg393-2/fogltlogles/blob/master/src/gles20/renderbuffer.cpp"
    click G20ext "https://github.com/thatmg393-2/fogltlogles/blob/master/src/gles20/ext/main.cpp"
    click G20bth "https://github.com/thatmg393-2/fogltlogles/blob/master/include/gles20/buffer_tracking.h"
    click G20fth "https://github.com/thatmg393-2/fogltlogles/blob/master/include/gles20/framebuffer_tracking.h"
    click G20tth "https://github.com/thatmg393-2/fogltlogles/blob/master/include/gles20/texture_tracking.h"
    click G30main "https://github.com/thatmg393-2/fogltlogles/blob/master/src/gles30/main.cpp"
    click G30trans "https://github.com/thatmg393-2/fogltlogles/blob/master/src/gles30/translation.cpp"
    click G30md "https://github.com/thatmg393-2/fogltlogles/blob/master/src/gles30/multidraw.cpp"
    click G30tex "https://github.com/thatmg393-2/fogltlogles/blob/master/src/gles30/textures.cpp"
    click G30h "https://github.com/thatmg393-2/fogltlogles/blob/master/include/gles30/main.h"
    click G30rp "https://github.com/thatmg393-2/fogltlogles/blob/master/include/gles30/read_pixels.h"
    click G32main "https://github.com/thatmg393-2/fogltlogles/blob/master/src/gles32/main.cpp"
    click G32bv "https://github.com/thatmg393-2/fogltlogles/blob/master/src/gles32/basevertex.cpp"
    click G32fb "https://github.com/thatmg393-2/fogltlogles/blob/master/src/gles32/framebuffer.cpp"
    click G32tex "https://github.com/thatmg393-2/fogltlogles/blob/master/src/gles32/textures.cpp"
    click G32h "https://github.com/thatmg393-2/fogltlogles/blob/master/include/gles32/main.h"
    click FFPmain "https://github.com/thatmg393-2/fogltlogles/blob/master/src/gles/ffp/main.cpp"
    click FFPcolor "https://github.com/thatmg393-2/fogltlogles/blob/master/src/gles/ffp/color.cpp"
    click FFPmatrix "https://github.com/thatmg393-2/fogltlogles/blob/master/src/gles/ffp/matrix.cpp"
    click FFPvertex "https://github.com/thatmg393-2/fogltlogles/blob/master/src/gles/ffp/vertex.cpp"
    click FFPinc "https://github.com/thatmg393-2/fogltlogles/blob/master/include/gles/ffp/main.h"
    click FFPesffp "https://github.com/thatmg393-2/fogltlogles/blob/master/include/es/ffp.h"
    click Preproc "https://github.com/thatmg393-2/fogltlogles/blob/master/include/shader/preprocess.h"
    click Postproc "https://github.com/thatmg393-2/fogltlogles/blob/master/include/shader/postprocess.h"
    click ShUtils "https://github.com/thatmg393-2/fogltlogles/blob/master/include/shader/utils.h"
    click ShCache "https://github.com/thatmg393-2/fogltlogles/blob/master/include/shader/cache.h"
    click ShConv "https://github.com/thatmg393-2/fogltlogles/blob/master/include/shader/converter.h"
    click ShComp "https://github.com/thatmg393-2/fogltlogles/blob/master/include/shader/compilers.h"
    click Shaderc "https://github.com/thatmg393-2/fogltlogles/tree/master/deps/shaderc"
    click SPIRVC "https://github.com/thatmg393-2/fogltlogles/tree/master/deps/spirv-cross"
```
