Skip to content

flubbe/swr

Repository files navigation

Software Rasterizer

License Build Status

Rasterizer Demos

Introduction

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:

  1. the public header files include/swr/swr.h, include/swr/shader.h, include/swr/stats.h,
  2. the graphics library implementation part in src/library/,
  3. the demo applications in src/demos/,
  4. a support framework for quickly generating applications in src/swr_app/,
  5. some common files in src/common/,
  6. 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.

Dependencies

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:

As a build system, the project uses CMake.

Building the Library and Demos

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.

Limitations

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.

Licenses

The project itself is licensed according to the MIT License.

  • The textures are licensed under the terms stated in the corresponding NOTICE files.

About

a software rasterizer

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages