This project is for learning how software rasterization (or rasterization in general) works. It mimics part of the OpenGL API, or at least took it as a strong inspiration of how things can work. The color rendering is based on 32-bit floats.
The project directory layout consists of:
- the public header files
include/swr/swr.h
,include/swr/shader.h
,include/swr/stats.h
, - the graphics library implementation part in
src/library/
, - the demo applications in
src/demos/
, - a support framework for quickly generating applications in
src/swr_app/
, - some common files in
src/common/
, - some textures in
textures/
.
For understanding the graphics pipeline code, you should probably start with the function Present
in src/library/pipeline.cpp
.
The primitive rasterization takes places in src/library/rasterizer/point.cpp
, src/library/rasterizer/line.cpp
and src/library/rasterizer/triangle.cpp
.
Some configuration options can be set in src/library/swr_internal.h
.
The project uses boost and SDL2, and the tests rely on the Boost.Test framework. If you'd like to run the benchmarks, you also need Google's benchmark library.
For the other dependencies:
- put the Compositional Numeric Library, release 1.1.2, in
deps/3rd-party/cnl
. - put cpu_features, release 0.7.0, into
deps/3rd-party/cpu_features
- put fmt, release 8.1.1, into
deps/3rd-party/fmt
- if you use Morton Codes (enabled by default), put libmorton into
deps/3rd-party/libmorton
- clone lodepng into
deps/3rd-party/lodepng
- clone stb into
deps/3rd-party/stb
- clone tinyobjloader into
deps/3rd-party/tinyobjloader
- clone ml into
deps/ml
- clone concurrency_utils into
deps/concurrency_utils
As a build system, the project uses CMake.
Install the dependencies listed above. In the root directory, execute:
mkdir bin
mkdir build
cd build
cmake .. -G Ninja
(or use any generator you like)ninja
Alternatively, you can use the included build scripts:
- Make the scripts executable:
chmod +x ./scripts/*
- Set up the build directory structure and download the dependencies:
./scripts/pre-build.sh
- Build the library and demos:
./scripts/build.sh
If everything succeeded, you should find the demo files in the bin
-directory.
Building was tested on Linux, GCC 12.2 (with C++-17 enabled), CMake 3.24.1 and Ninja 1.11.0.
There are many, so in general expect things to not work if you use the library. It is meant for learning after all, with no specific goal in mind.
- Many functionalities are only partly implemented or not implemented at all.
- Error propagation and handling is mostly missing and sometimes not very consistent. For example, some functions throw std::runtime_error, while others may just set an error flag.
- The library is not thread-safe.
The project itself is licensed according to the MIT License.
- The textures are licensed under the terms stated in the corresponding NOTICE files.