Adding a New Backend
- Create directory:
src/backend/<name>/ - Define internal types: Concrete structs for
MopRhiDevice,MopRhiBuffer,MopRhiFramebuffer - Implement all 14 RHI functions — see RHI for the full contract
- Expose factory:
const MopRhiBackend *mop_rhi_backend_<name>(void); - Register in dispatcher: Add a
casetomop_rhi_get_backendinsrc/rhi/rhi.c - Add source to root Makefile: Append the
.cfile toCORE_SRCSand add the obj directory toobj_dirs - Write documentation: Create
docs/reference/backend-<name>.mdx
The new backend must pass the same visual tests as the CPU backend (identical output within floating-point tolerance).
Software rasterization backends can reuse the shared rasterizer at src/rasterizer/ — include "rasterizer/rasterizer.h" for MopSwFramebuffer, MopSwClipVertex, and all mop_sw_* functions.
Adding a New Public API Function
- Declare in the appropriate header under
include/mop/ - Implement in viewport core (
src/viewport/viewport.c) - If the function needs backend support: Add a new function pointer to
MopRhiBackendand implement in every backend - Document the contract in API Contracts
- Update the example if the function demonstrates a new capability
Adding a New Vertex Attribute
The current fixed vertex format (MopVertex) includes position, normal, and color. To add UV coordinates:
- Add
MopVec2 uvtoMopVertexininclude/mop/types.h - Update the software rasterizer to interpolate UVs during rasterization
- Update GPU backend shaders to accept and pass through UVs
- Add texture support to the RHI (new
MopRhiTexturehandle and bind function)
Adding a New Subsystem
For a major new subsystem (e.g., shadow mapping, post-processing):
- Create
src/<subsystem>/ - Create internal headers in
src/<subsystem>/ - Expose public API in
include/mop/if application-facing - Create
docs/reference/<subsystem>.mdx - Link from
docs/reference.mdx
The subsystem must follow the same layer rules — it may consume the RHI but must not reference backend internals.
Documentation-Code Invariant
For every directory under src/, a corresponding .mdx file must exist under docs/reference/. For every .mdx file under docs/reference/, there must be a corresponding implementation.
docs/reference/rhi.mdx ↔ src/rhi/
docs/reference/rasterizer.mdx ↔ src/rasterizer/
docs/reference/backend-cpu.mdx ↔ src/backend/cpu/
docs/reference/math.mdx ↔ src/math/
This invariant is checked during review. If you add code, add docs. If you add docs, add code.