# skywind3000/mini3d architecture

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

- Interactive diagram: https://gitdiagram.com/skywind3000/mini3d
- Repository: https://github.com/skywind3000/mini3d

## Overview

##### Project Type and Purpose
- This is a single-file, fixed-pipeline 3D software renderer tutorial in C (“mini3d.c”).

a. Entry & OS Integration
- main() loop, window creation via GDI, frame swap
b. Math & Data Structures
- Vector/Matrix routines, matrix stack (WORLD, VIEW, PROJECTION), vertex struct
c. Vertex Processing Stage
- Apply WORLD → VIEW → PROJECTION transforms
- Homogeneous divide → Normalized Device Coordinates
d. Clipping Stage
- CVV (Canonical View Volume) clipping against near/far and view‐frustum planes
e. Rasterization Stage
- Triangle setup, edge function or scanline algorithm
f. Pixel/Shading Stage
- Depth test using Z‐buffer
g. Frame Buffer & Display
- Write final RGBA values into in-memory buffer
- BitBlt via GDI to screen

##### Relationships & Data Flow
- Mesh/Data → [Vertex Processing] → [Clipping] → [Rasterizer] → [Pixel Shader] → Frame Buffer → OS/GDI Display
- Texture resource loaded into memory, sampled in Pixel Shader.

##### Architectural Patterns & Design Principles
- Single pipeline, linear data flow (no threading or external services).
- Modular separation by pipeline stage for clarity—even in one file.
- Explicit stage interfaces: output of Stage N feeds Stage N+1.

- Scanline traversal or edge function inside Rasterizer.
- Z‐buffer test within Pixel Shader.

##### Why This Matters
- Even in a minimalist codebase, capturing each logical stage clarifies the renderer’s flow and maintenance points.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top Row Inputs
    Mesh["Mesh Data"]:::datastore
    Matrices["World/View/Projection Matrices"]:::datastore
    Textures["Texture Resources"]:::datastore

    %% Pipeline Stages
    VP["Vertex Processing\n(World→View→Projection)"]:::compute
    Clip["Clipping\n(CVV & Frustum)"]:::compute
    Raster["Rasterization\n(Scanline/Edge Func)"]:::compute
    Shader["Pixel/Shading\n(Perspective‐correct, Z‐Test)"]:::compute

    %% Buffers & Display
    FB["Frame Buffer\n(RGBA)"]:::datastore
    ZB["Z‐Buffer"]:::datastore
    Display["OS/GDI Display\n(BitBlt)"]:::os

    %% Project Files
    subgraph "Project Files"
        README["README.md"]:::datastore
        README_EN["README.en.md"]:::datastore
        SLN["Mini3D.sln"]:::datastore
        VCXPROJ["Mini3D.vcxproj"]:::datastore
        FILTERS["Mini3D.vcxproj.filters"]:::datastore
        LICENSE["LICENSE"]:::datastore
        GITIGNORE[".gitignore"]:::datastore
    end

    %% Data Flow
    Mesh -->|feeds| VP
    Matrices -->|transforms| VP
    VP --> Clip
    Clip --> Raster
    Raster --> Shader
    Textures -->|sample| Shader
    Shader --> FB
    Shader --> ZB
    FB -->|GDI BitBlt| Display

    %% Click Events
    click VP "https://github.com/skywind3000/mini3d/blob/master/mini3d.c"
    click Clip "https://github.com/skywind3000/mini3d/blob/master/mini3d.c"
    click Raster "https://github.com/skywind3000/mini3d/blob/master/mini3d.c"
    click Shader "https://github.com/skywind3000/mini3d/blob/master/mini3d.c"
    click FB "https://github.com/skywind3000/mini3d/blob/master/mini3d.c"
    click Mesh "https://github.com/skywind3000/mini3d/blob/master/mini3d.c"
    click Matrices "https://github.com/skywind3000/mini3d/blob/master/mini3d.c"
    click Textures "https://github.com/skywind3000/mini3d/tree/master/images/"
    click README "https://github.com/skywind3000/mini3d/blob/master/README.md"
    click README_EN "https://github.com/skywind3000/mini3d/blob/master/README.en.md"
    click SLN "https://github.com/skywind3000/mini3d/blob/master/Mini3D.sln"
    click VCXPROJ "https://github.com/skywind3000/mini3d/blob/master/Mini3D.vcxproj"
    click FILTERS "https://github.com/skywind3000/mini3d/blob/master/Mini3D.vcxproj.filters"
    click LICENSE "https://github.com/skywind3000/mini3d/tree/master/LICENSE"
    click GITIGNORE "https://github.com/skywind3000/mini3d/blob/master/.gitignore"

    %% Styles
    classDef datastore fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef compute fill:#90EE90,stroke:#000,stroke-width:1px
    classDef os fill:#FFD580,stroke:#000,stroke-width:1px
```
