Files
fan/README.md
Cristian Gora d081108ea5 Add GL error handling, resource fallbacks and GPU timing; speed up lighting
Bug fixes:
- Release static GL objects (UBOs, logo texture) before the context is
  destroyed via new Renderer::shutdown()
- Fix max point/spot light warnings never firing
- Show frame time in ms instead of seconds
- Size the viewport framebuffer in physical pixels on HiDPI displays
- Stop double-flipping OBJ UVs; add flip_uvs option to load_obj for
  models with a top-left UV origin (backpack)

Build:
- Track header dependencies (-MMD -MP) so header edits trigger rebuilds
- Create build/ automatically

Error handling:
- Add gldebug module: KHR_debug output routed to the logger in debug
  builds, object labels, and error/status string helpers
- Validate inputs and check GL errors when creating textures, meshes,
  framebuffers, uniform buffers and shaders; FrameBuffer::resize() and
  Renderer::init() now report failure

Resources:
- Add ResourceCache: shares textures and shaders by path and substitutes
  fallbacks (magenta checkerboard texture, unlit shader, cube mesh) for
  assets that fail to load; specular maps are optional
- load_obj never fails, a broken model becomes a fallback cube
- Renderer draws submeshes with broken materials using the fallback
  material instead of skipping them
- Add Texture::create_from_pixels, Shader::create_from_source and
  Mesh::create_cube
- Cache uniform locations in Shader, looked up with string_view so
  hits don't allocate; missing uniforms warn once

Performance:
- Add CpuTimer and GpuTimer (GL_TIME_ELAPSED, non-blocking readback)
  and a Performance section in the UI with averaged overlay numbers
- Sample material textures once per fragment and apply material colors
  after accumulating lights
- Pass camera position through CameraBlock instead of inverting the
  view matrix per fragment
- Compute the normal matrix on the CPU instead of per vertex
- Skip spot light work for fragments outside the outer cone
2026-10-28 21:23:41 +01:00

3.0 KiB

Fan Engine

A minimal 3D renderer written in C++ and OpenGL 3.3 Core.

NOTE: The engine is still in development. Expect breaking changes.

Building

The only tested platform at the moment is GNU/Linux (x86_64).

To build the project you'll need to have GLFW already installed system-wide, the rest of the dependencies are already included.

After that, building comes down to just running the included Makefile.

$ make # optionally pass -j$(nproc)

Features

This is the current state of the engine architecture:

flowchart TB
    subgraph Infrastructure["Infrastructure"]
        direction LR

        subgraph Platform
            direction TB
            Window --> GLFW
            Window --> glad
            Window --> ImGui["Dear ImGui"]
        end

        subgraph Loading
            direction TB
            Loader --> tinyobjloader
            Loader --> stb_image
        end
    end

    subgraph Application
        direction LR
        Framebuffer
        Renderer --> Camera
        Renderer --> Scene
        Renderer -->|Updates| UniformBuffer
        Renderer -->|Owns| ResourceCache
    end

    subgraph World
        direction LR

        subgraph SceneGraph["Scene Graph"]
            direction TB
            Scene --> Entity
            Entity --> Transform
            Entity --> Mesh
            Entity -.->|Optional override| Material
            Mesh -->|Partitions| SubMesh
            SubMesh -->|Owns| Material
        end

        subgraph Lighting
            direction TB
            Scene --> LightEnvironment
            LightEnvironment --> DirectionalLight
            LightEnvironment --> PointLight
            LightEnvironment --> SpotLight
        end
    end

    subgraph SceneData["Scene Data"]
        direction LR

        subgraph Geometry
            direction TB
            Mesh --> Vertices
            Mesh --> Indices
        end

        subgraph Resources
            direction TB
            Material --> Shader
            Material --> Texture
            UniformBuffer -->|Global data| Shader
            ResourceCache -.->|Caches, falls back| Texture
            ResourceCache -.->|Caches, falls back| Shader
        end
    end

    tinyobjloader -->|Generates| Entity
    Texture -.->|Decodes via| stb_image

    classDef application fill:#7c3aed,stroke:#4c1d95,color:#fff
    classDef world fill:#2563eb,stroke:#1e3a8a,color:#fff
    classDef data fill:#0f766e,stroke:#134e4a,color:#fff
    classDef loading fill:#d97706,stroke:#92400e,color:#fff
    classDef platform fill:#64748b,stroke:#334155,color:#fff

    class Renderer,Scene,Camera,Framebuffer,ResourceCache application
    class Entity,Transform,Mesh,SubMesh,Material,LightEnvironment world
    class UniformBuffer,Shader,Texture,Vertices,Indices,DirectionalLight,PointLight,SpotLight data
    class Loader,tinyobjloader,stb_image loading
    class Window,GLFW,glad,ImGui platform