Skip to content
MAIPA01Public

About

Tiny but powerful pbrt-v4 loader

Resources

Stars

3 stars

Watchers

0 watching

Forks

Repository files navigation

tinypbrt

Docs & coverage Documentation Coverage C11 C++20

Tiny but powerful pbrt-v4 scene file loader written in C11, with an optional header-only C++20 wrapper.

tinypbrt parses .pbrt scene descriptions (cameras, film, samplers, integrators, shapes, materials, textures, lights, participating media, object instancing, animated transforms, Include/Import) into plain C structures that you can feed into your own renderer. It does not render anything and it does not load external assets (PLY meshes, images, spectra files) - it gives you their file names.

tpbrt_scene_t scene;
if (tpbrt_scene_load_from_file("scene.pbrt", &scene) == TPBRT_ERROR_NONE) {
    printf("%zu shapes\n", scene.shapes.count);
    tpbrt_scene_free(&scene);
}

The same in C++ (C++ wrapper) - the scene frees itself and tagged unions become std::variant:

if (const auto scene = tpbrt::load_scene_from_file("scene.pbrt")) {
    std::printf("%zu shapes\n", scene->shapes().size());
}

Contents

Features

  • The whole pbrt-v4 scene language
    • transforms: Identity, Translate, Scale, Rotate, LookAt, Transform, ConcatTransform, CoordinateSystem, CoordSysTransform (including the built-in "camera" system), TransformTimes, ActiveTransform (motion blur: every transform has a start and an end matrix)
    • scene options: Camera, Film, Sampler, Integrator, Accelerator, PixelFilter, ColorSpace, Option
    • world: AttributeBegin/AttributeEnd, Attribute defaults, ReverseOrientation, Shape, Material, MakeNamedMaterial/NamedMaterial, Texture, LightSource, AreaLightSource, MakeNamedMedium/MediumInterface, ObjectBegin/ObjectEnd/ObjectInstance
    • Include and Import (paths relative to the directory of the main file)
    • deprecated TransformBegin/TransformEnd are accepted
  • Parameters of every type (integer, float, point2/3, vector2/3, normal, bool, string, rgb, spectrum, blackbody, texture) with pbrt-v4 defaults applied
  • Spectra as RGB, blackbody, (wavelength, value) pairs, named built-ins ("metal-Cu-eta", "stdillum-D65", ...) or a file name
  • pbrt-v4 semantics where they matter: the camera is created at WorldBegin, so Film may come after Camera; uroughness/vroughness default to roughness; the explicit parameter wins over Attribute; string escapes (\n, \t, \\, escaped quotes, ...) are decoded
  • Validation: unknown types, wrong parameter types, out-of-range mesh indices, mismatched AttributeBegin/ObjectBegin nesting, include cycles - every problem is reported as an error code
  • Compact output: identical matrices are stored once and referenced by handles
  • C++20 wrapper (tinypbrt::tinypbrt_cpp, header-only): RAII scene, zero-copy views, std::variant for every tagged union, ranges-compatible lists and tpbrt::result<T> instead of output parameters - with the same performance as the C API
Category Supported types
Cameras perspective, orthographic, realistic, spherical
Films rgb, gbuffer, spectral
Samplers zsobol, halton, sobol, paddedsobol, independent, stratified
Integrators volpath, path, bdpt, mlt, sppm, lightpath, randomwalk, simplepath, simplevolpath, ambientocclusion
Filters gaussian, box, mitchell, sinc, triangle
Accelerators bvh, kdtree
Shapes sphere, cylinder, disk, trianglemesh, bilinearmesh, curve, plymesh, loopsubdiv
Materials diffuse, coateddiffuse, conductor, coatedconductor, dielectric, thindielectric, diffusetransmission, hair, measured, mix, subsurface, interface
Textures constant, checkerboard, imagemap, bilerp, dots, fbm, wrinkled, windy, marble, mix, directionmix, scale, ptex
Lights point, spot, distant, infinite, goniometric, projection, area diffuse
Media homogeneous, uniformgrid, rgbgrid, cloud, nanovdb

Requirements

  • an ISO C11 compiler: the library builds warning-free with -Wpedantic (tested with GCC 13 and Clang 18; the Windows presets use Clang)
  • CMake 3.30 or newer
  • no runtime dependencies (only the C standard library; libm is linked automatically where needed)
  • for the optional C++ wrapper: a C++20 compiler (tested with GCC 13 and Clang 18)

Adding tinypbrt to your project

The CMake target is tinypbrt::tinypbrt for C and tinypbrt::tinypbrt_cpp for the C++20 wrapper (it links the C library for you; disable it with TINYPBRT_BUILD_CPP_WRAPPER=OFF). Tests, benchmarks, documentation and examples are built only when tinypbrt is the top-level project, so adding it as a dependency builds just the library.

CPM.cmake (recommended)

CPM.cmake downloads and caches the dependency for you.

cmake_minimum_required(VERSION 3.30)
project(my_renderer LANGUAGES C)

# https://github.com/cpm-cmake/CPM.cmake#adding-cpm
include(cmake/CPM.cmake)

CPMAddPackage("gh:MAIPA01/tinypbrt@v1.1.1")

add_executable(my_renderer main.c)
target_link_libraries(my_renderer PRIVATE tinypbrt::tinypbrt)

# or, for C++20:
# add_executable(my_renderer main.cpp)
# target_link_libraries(my_renderer PRIVATE tinypbrt::tinypbrt_cpp)

gh:MAIPA01/tinypbrt@v1.1.1 fetches the git tag v1.1.1. To follow a branch or pin a commit, or to pass options, use the long form:

CPMAddPackage(
        NAME tinypbrt
        GITHUB_REPOSITORY MAIPA01/tinypbrt
        GIT_TAG main            # branch, tag or commit hash
        OPTIONS
        "TINYPBRT_BUILD_SHARED ON"   # optional: build tinypbrt as a .dll/.so (default: static)
)

If your project does not use CPM yet, the smallest setup is to download CPM.cmake at configure time:

set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM.cmake")
if (NOT EXISTS ${CPM_DOWNLOAD_LOCATION})
    file(DOWNLOAD https://github.com/cpm-cmake/CPM.cmake/releases/latest/download/CPM.cmake ${CPM_DOWNLOAD_LOCATION})
endif ()
include(${CPM_DOWNLOAD_LOCATION})

Set the CPM_SOURCE_CACHE environment variable (for example to ~/.cache/CPM) to share downloaded packages between projects.

FetchContent

include(FetchContent)
FetchContent_Declare(tinypbrt
        GIT_REPOSITORY https://github.com/MAIPA01/tinypbrt.git
        GIT_TAG v1.1.1
)
FetchContent_MakeAvailable(tinypbrt)

target_link_libraries(my_renderer PRIVATE tinypbrt::tinypbrt)

add_subdirectory

add_subdirectory(external/tinypbrt)
target_link_libraries(my_renderer PRIVATE tinypbrt::tinypbrt)

Installed package (find_package)

cmake -S tinypbrt -B build -DCMAKE_BUILD_TYPE=Release -DTINYPBRT_BUILD_TESTS=OFF
cmake --build build
cmake --install build --prefix /opt/tinypbrt
find_package(tinypbrt 1.1 REQUIRED CONFIG)   # -DCMAKE_PREFIX_PATH=/opt/tinypbrt
target_link_libraries(my_renderer PRIVATE tinypbrt::tinypbrt)

# C++ wrapper (finds tinypbrt by itself)
find_package(tinypbrt_cpp 1.1 REQUIRED CONFIG)
target_link_libraries(my_cpp_renderer PRIVATE tinypbrt::tinypbrt_cpp)

Static or shared library

tinypbrt is a static library by default. Set TINYPBRT_BUILD_SHARED=ON (or the global BUILD_SHARED_LIBS=ON) to build tinypbrt.dll / libtinypbrt.so / libtinypbrt.dylib instead. Nothing changes in your code: linking tinypbrt::tinypbrt adds the TINYPBRT_SHARED_LIBS definition for you, and the public functions are declared with TPBRT_API:

building tinypbrt using tinypbrt
Windows (MSVC, clang-cl, Clang, MinGW) __declspec(dllexport) __declspec(dllimport)
Linux / macOS (GCC, Clang) __attribute__((visibility("default"))) same
static library (empty) (empty)

Only the public API (tpbrt_scene_load_*, tpbrt_scene_free, tpbrt_get_*) is exported; everything else is hidden. On Windows the DLL has to be found at run time - for example copy it next to your executable:

if (WIN32)
    add_custom_command(TARGET my_renderer POST_BUILD
            COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_RUNTIME_DLLS:my_renderer> $<TARGET_FILE_DIR:my_renderer>
            COMMAND_EXPAND_LISTS)
endif ()

If you build tinypbrt without CMake, define TINYPBRT_SHARED_LIBS everywhere and TINYPBRT_EXPORTS only while compiling the library.

Quick start

#include <stdio.h>

#include <tinypbrt/tinypbrt.h>

int main(int argc, char** argv) {
	if (argc < 2) {
		fprintf(stderr, "usage: %s scene.pbrt\n", argv[0]);
		return 1;
	}

	tpbrt_scene_t scene;
	const tpbrt_error_t err = tpbrt_scene_load_from_file(argv[1], &scene);
	if (err != TPBRT_ERROR_NONE) {
		char message[128];
		tpbrt_get_error_message(err, message, sizeof(message));
		fprintf(stderr, "failed to load %s: %s (%d)\n", argv[1], message, (int)err);
		return 1; // on error the scene is already freed
	}

	printf("film:   %ux%u -> %.*s\n", scene.film.x_resolution, scene.film.y_resolution, (int)scene.film.file_name.size,
	  scene.film.file_name.data);
	printf("shapes: %zu, lights: %zu, materials: %zu, textures: %zu\n", scene.shapes.count,
	  scene.lights.lights_sources.count, scene.materials.count, scene.textures.count);

	for (size_t i = 0; i < scene.shapes.count; ++i) {
		const tpbrt_shape_t* shape = &scene.shapes.shapes[i];

		// object -> world matrix (row-major: m[row * 4 + column])
		const tpbrt_mat4_t* object_to_world = NULL;
		tpbrt_get_transform(&scene.transforms, shape->transform.start_transform, &object_to_world);

		const tpbrt_material_t* material = NULL;
		tpbrt_get_material_by_handle(&scene.materials, shape->material, &material);

		if (shape->type == TPBRT_SHAPE_TYPE_SPHERE) {
			printf("sphere r=%g at (%g %g %g)\n", shape->as.sphere.radius, object_to_world->m[3], object_to_world->m[7],
			  object_to_world->m[11]);
		}
		else if (shape->type == TPBRT_SHAPE_TYPE_TRIANGLE_MESH) {
			printf("triangle mesh: %zu vertices, %zu triangles\n", shape->as.triangle_mesh.p.count,
			  shape->as.triangle_mesh.indices.count / 3);
		}
		(void)material;
	}

	tpbrt_scene_free(&scene);
	return 0;
}

Scenes can also be parsed from memory. The second argument is the directory used to resolve Include/Import paths:

const char* source =
    "Camera \"perspective\" \"float fov\" 45\n"
    "WorldBegin\n"
    "Include \"geometry.pbrt\"\n";

tpbrt_scene_t scene;
tpbrt_error_t err = tpbrt_scene_load_from_memory(source, "assets/scenes", &scene);

Using the scene

Everything you get back lives in tpbrt_scene_t and is owned by it: call tpbrt_scene_free once you are done (and only after a successful load).

Field Contents
camera, film, sampler, integrator, accelerator, filter, options scene-wide settings with pbrt-v4 defaults filled in
start_time, end_time shutter interval from TransformTimes
shapes shapes outside of ObjectBegin blocks
objects, instances object definitions (their shapes are in objects.objects[i].children) and their instances
materials, textures, medias every material, texture and medium, named or not
lights.lights_sources, lights.area_lights light sources and area lights referenced by shapes
transforms shared pool of matrices referenced by transform handles

Things worth knowing:

  • Tagged unions. Every object with variants has a type field and an as union, e.g. shape->type == TPBRT_SHAPE_TYPE_SPHERE → shape->as.sphere.
  • Strings are not NUL-terminated. tpbrt_string_t is { data, size }; print it with printf("%.*s", (int)s.size, s.data).
  • Handles instead of pointers. Shapes refer to materials, area lights, media and transforms by small handles. Resolve them with tpbrt_get_material_by_handle, tpbrt_get_area_light_by_handle, tpbrt_get_media_by_handle, tpbrt_get_texture_by_handle, tpbrt_get_object_by_handle and tpbrt_get_transform. Named objects can be looked up with the *_by_name variants. Lists are passed by pointer (tpbrt_get_material_by_name(&scene.materials, name, &material)); name lookups use a small hash index built while loading (O (1), about 5 bytes per named object, nothing at all for scenes with at most 8 names in a list).
  • Transforms. Matrices are row-major float m[16] mapping object space to world space (for the camera: camera to world). Shapes, instances and the camera have a start_transform and an end_transform for motion blur; both handles are equal when the transform is not animated. Lights, media and textures have a single transform, as in pbrt-v4.
  • Texture parameters (tpbrt_texture_handle_t) are either a reference to a texture (value_type == TPBRT_TEXTURE_HANDLE_VALUE_TYPE_TEXTURE_IDX) or an inline value (..._SPECTRUM); plain floats are stored as constant spectra (as.spectrum.as.constant).
  • Spectra (tpbrt_spectrum_t) are RGB (in the color space active at that point), blackbody temperature, wavelength/value pairs, a built-in name, a file name or a constant.
  • External files (PLY meshes, images, spectra, NanoVDB grids, lens files) are not opened; their paths are stored as written in the scene file.

Error handling

All functions return tpbrt_error_t (TPBRT_ERROR_NONE on success). Loading stops at the first error and frees everything that was allocated, so a failed tpbrt_scene_load_* needs no cleanup. tpbrt_get_error_message turns a code into a readable message:

char message[128];
tpbrt_get_error_message(err, message, sizeof(message));

Parameters are matched by name and declared type, as in pbrt-v4: Shape "sphere" "string radius" "big" (or "integer radius" 2) fails with TPBRT_ERROR_PARAM_TYPE_MISMATCH - "Parameter is declared with a different type than expected". point/vector/normal are accepted as synonyms of point3/vector3/normal3. Numbers are parsed independently of the C locale, and a token must be a complete number (1.5abc or an integer written as 2.0 is an error). Redefining a named material, medium, object or a texture of the same type is an error (TPBRT_ERROR_DUPLICATE_*), like in pbrt-v4; float and spectrum textures have separate namespaces.

C++ wrapper

#include <tinypbrt/tinypbrt.hpp> and link tinypbrt::tinypbrt_cpp (C++20). The wrapper is header-only and adds no copies: every type is a small view over the C structure, so it is as fast as the C API (see Benchmarks).

#include <tinypbrt/tinypbrt.hpp>

#include <cstdio>
#include <utility>

template<class... Fs> struct overloaded : Fs... { using Fs::operator()...; };

int main(int argc, char** argv) {
	if (argc < 2) { return 1; }
	auto loaded = tpbrt::load_scene_from_file(argv[1]);   // tpbrt::result<tpbrt::scene>
	if (!loaded) {
		std::fprintf(stderr, "%s\n", tpbrt::to_string(loaded.get_error()).c_str());
		return 1;
	}
	const tpbrt::scene scene = std::move(*loaded);          // owns the C scene, frees it in the destructor

	for (const tpbrt::shape shape : scene.shapes()) {
		shape.visit(overloaded {
		  [](const tpbrt::shape_sphere_params& sphere) { std::printf("sphere r=%g\n", sphere.radius()); },
		  [](const tpbrt::shape_triangle_mesh_params& mesh) { std::printf("%zu vertices\n", mesh.p().size()); },
		  [](const auto&) {},
		});

		if (const auto material = scene.materials().at(shape.material())) {   // handle -> tpbrt::result<material>
			std::printf("  material %s\n", tpbrt::to_string(material->type()).data());
		}
	}
	if (const auto gold = scene.materials().at("gold"); gold && gold->is_conductor()) { /* lookup by name */ }
}
C C++
tpbrt_scene_t + tpbrt_scene_free tpbrt::scene (RAII, move-only) or tpbrt::scene_view over a scene you own
tpbrt_error_t + output parameter tpbrt::result<T> (if (r), *r, r->, get_error(), value_or(), visit())
tpbrt_string_t tpbrt::string (std::string_view-like, comparable with strings)
{ data, count } arrays and lists tpbrt::array<...>: size(), [], at(), iterators, std::ranges algorithms/views
type + as union type(), is_xxx(), as_xxx() → std::optional, visit(), as<T>(), holds<T>()
tpbrt_get_material_by_handle / _by_name scene.materials().at(handle) / .at("name") (also textures, media, objects, ...)
TPBRT_SHAPE_TYPE_SPHERE, ... enum class (tpbrt::shape_type::SPHERE) and tpbrt::to_string(...)

Things worth knowing:

  • Views. All wrappers (except tpbrt::scene) are non-owning, pointer-sized and cheap to copy - take them by value. They stay valid as long as the scene lives, also after the tpbrt::scene object was moved (the C data does not move). .native() returns the C structure, so both APIs can be mixed freely.
  • Variants. Every alternative of a variant is a distinct type, so std::visit always knows what it got: a blackbody temperature is tpbrt::blackbody, not a float like a constant spectrum, and fbm/wrinkled/windy textures have their own parameter types. visit returns std::optional with the visitor's result (empty for an unknown type), or nothing for a void visitor.
  • No exceptions, no allocations. Errors are values (tpbrt::result); operator[] and *result are unchecked like in the standard library, at() and get_value() check. Only get_value() on an error throws (std::bad_variant_access).
  • Comparison. Views compare by value (== and <=> compare the contents, not the addresses).

CMake options

Option Default Description
TINYPBRT_BUILD_SHARED BUILD_SHARED_LIBS build tinypbrt as a shared library (details)
TINYPBRT_BUILD_CPP_WRAPPER ON provide the C++20 wrapper tinypbrt::tinypbrt_cpp (details)
BUILD_SHARED_LIBS OFF CMake's global default for all libraries (also GoogleTest in this repository)
TINYPBRT_BUILD_TESTS top-level only build the GoogleTest suites (C library and C++ wrapper) and the C API test
TINYPBRT_BUILD_BENCHMARK top-level only build benchmarks (C and C++)
TINYPBRT_BUILD_EXAMPLES top-level only build examples
TINYPBRT_BUILD_DOCUMENTATION top-level only Doxygen documentation: docs target (details)
TINYPBRT_BUILD_COVERAGE top-level only LLVM coverage instrumentation and the coverage target (Clang) (details)
TINYPBRT_ENABLE_CLANG_TIDY top-level only clang_tidy_* targets (details)
TINYPBRT_WARNINGS_AS_ERRORS top-level only treat compiler warnings as errors when building tinypbrt
TINYPBRT_ENABLE_PEDANTIC ON build tinypbrt with -Wpedantic (GCC/Clang): only ISO C11, no compiler extensions
TINYPBRT_ENABLE_SANITIZERS OFF build the library and tests with sanitizers
TINYPBRT_SANITIZERS address;undefined sanitizers to use (address, undefined, leak, memory, thread)
TINYPBRT_INSTALL top-level only generate install rules
TINYPBRT_SYNC_VERSION top-level only write the version into README.md and examples/cpm_project (details)

Compiler warnings and optimization flags used to build tinypbrt are private to the library: they are not added to your targets. Link-time optimization and static linking are left to your project (e.g. CMAKE_INTERPROCEDURAL_OPTIMIZATION).

Versioning

The version is set in one place only: project(tinypbrt VERSION x.y.z ...) in the main CMakeLists.txt. The library (VERSION/SOVERSION), the installed package version files and the Doxygen documentation read it from there, and configuring tinypbrt as the top-level project writes it into this README (@vx.y.z, GIT_TAG vx.y.z, find_package(tinypbrt x.y)) and into examples/cpm_project (cmake/version_sync.cmake). With TINYPBRT_SYNC_VERSION=OFF run cmake --build build --target tinypbrt-sync-version instead; the tinypbrt-version-check test fails when the files are out of date. Push the matching vx.y.z git tag when releasing, so the CPM and FetchContent snippets work.

Examples

examples/ contains small C11 programs built on the public API (-DTINYPBRT_BUILD_EXAMPLES=ON, on by default when tinypbrt is the top-level project), together with two scenes in examples/scenes:

Example Shows
quickstart the program from Quick start
scene_info camera, film, sampler, integrator, filter and accelerator settings; shapes, materials, textures and media
load_from_memory parsing from memory, Include relative to a working directory, error codes and messages
materials shape → material → texture handles, inline values vs. texture references, lookup by name
lights light sources in world space (from/to transformed by the light's CTM), area lights on shapes
export_obj converting meshes, spheres, cylinders, disks and object instances to a Wavefront OBJ file

The C++20 versions in examples/cpp use the wrapper (built when TINYPBRT_BUILD_CPP_WRAPPER=ON):

Example Shows
tinypbrt-cpp-example-quickstart RAII scene, visit with overloaded lambdas, handle lookups returning tpbrt::result
tinypbrt-cpp-example-scene_info settings via tpbrt::to_string, a generic visitor with if constexpr, lights, textures
tinypbrt-cpp-example-materials std::views::filter / std::ranges::count_if on lists, lookup by name, texture handles
./build/examples/tinypbrt-example-scene_info examples/scenes/forest.pbrt
./build/examples/tinypbrt-example-export_obj examples/scenes/forest.pbrt forest.obj
./build/examples/tinypbrt-cpp-example-materials examples/scenes/cornell_box.pbrt gold

examples/cpm_project is a standalone CMake project that pulls tinypbrt with CPM, exactly as described above. Pass -DCPM_tinypbrt_SOURCE=/path/to/tinypbrt to build it against a local checkout.

Building and testing tinypbrt

git clone https://github.com/MAIPA01/tinypbrt.git
cd tinypbrt

# Linux / macOS: Clang, Debug, AddressSanitizer + UndefinedBehaviorSanitizer + LeakSanitizer
cmake --preset linux-debug-sanitizers
cmake --build build/linux-debug-sanitizers
ctest --preset linux-debug-sanitizers

On Windows (Clang + Ninja) use the x64-debug-c11 preset, or x64-debug-c11-sanitizers for AddressSanitizer + UndefinedBehaviorSanitizer:

cmake --preset x64-debug-c11-sanitizers
cmake --build build/x64-debug-c11-sanitizers
ctest --preset x64-debug-c11-sanitizers

The shared-library build has its own presets: linux-debug-shared-sanitizers and x64-debug-c11-shared (the GoogleTest suite then links a static copy of the library, because it also tests internal functions; tinypbrt-c-api-tests runs against the DLL / .so).

Without presets:

cmake -B build -DCMAKE_BUILD_TYPE=Debug -DTINYPBRT_ENABLE_SANITIZERS=ON
cmake --build build
ctest --test-dir build --output-on-failure

The test suite (tinypbrt-tests, GoogleTest, C++17) covers the parser, parameter handling, every directive and object type, error paths and memory safety under the sanitizers; tinypbrt-c-api-tests checks that the public headers compile and work as strict C11. tinypbrt-cpp-tests (GoogleTest, C++20) tests the wrapper: every variant alternative, to_string of every enum value against the C parser, lookups, tpbrt::result, moves of tpbrt::scene, and that whole example scenes read through the wrapper give the same values as the C API. The tinypbrt_cpp_header_check target compiles every C++ header on its own.

Benchmarks

tinypbrt-benchmark (Google Benchmark, -DTINYPBRT_BUILD_BENCHMARK=ON) loads generated scenes of growing size, each stressing a different part of the parser: many shapes with their own transforms, one large triangle mesh (number parsing), named materials and textures (name lookups), object instances, shared transforms (matrix deduplication), deeply nested attributes and a mixed scene. It also measures handle resolution and tpbrt_get_material_by_name on a loaded scene. Use a Release build:

cmake --preset linux-release
cmake --build build/linux-release
./build/linux-release/benchmark/tinypbrt-benchmark
./build/linux-release/benchmark/tinypbrt-benchmark --benchmark_filter=triangle_mesh
./build/linux-release/benchmark/tinypbrt-benchmark my_scene.pbrt other.pbrt   # also time your own files
./build/linux-release/benchmark/tinypbrt-benchmark --benchmark_format=json > before.json

bytes_per_second is the parser throughput, items_per_second the number of scene elements (shapes, vertices, instances...) per second. Compare two JSON runs with tools/compare.py from Google Benchmark.

tinypbrt-cpp-benchmark measures the cost of the C++ wrapper: every bm_cpp_* benchmark has a bm_c_* twin doing the same work with the C API (loading, iterating shapes with visit/as_xxx(), iterating a 1M-vertex mesh, lookup by name). Example results (GCC 13, Release):

Benchmark C C++
load 100k spheres 98.9 ms 97.0 ms
sum radii of 100k spheres 390 µs 402 µs (visit), 384 µs (as_sphere())
max x of a 1M-vertex mesh 1.45 ms 1.47 ms
material by name (10k materials) 49.7 ns 48.3 ns

Coverage

With Clang (clang/clang++, also clang.exe on Windows) and TINYPBRT_BUILD_COVERAGE=ON the library, the tests and the examples are built with LLVM source-based coverage. The coverage target runs every test from ctest (each process writes its own .profraw), merges the data with llvm-profdata and writes an HTML report with line, region, branch and MC/DC coverage, plus a summary table in the console:

cmake --preset linux-debug-coverage
cmake --build build/linux-debug-coverage --target coverage
# report: build/linux-debug-coverage/coverage_report/index.html

llvm-profdata/llvm-cov matching the Clang version are found next to the compiler. Tests, examples, benchmarks and third-party code are excluded from the report.

The report for the latest commit on main is published at https://maipa01.github.io/tinypbrt/coverage/ by the Docs & coverage workflow.

clang-tidy

With TINYPBRT_ENABLE_CLANG_TIDY=ON every checked target gets two targets: clang_tidy_<target> checks only the files that changed (or still had warnings) since the last run, clang_tidy_<target>_full checks everything. Targets added with the same GROUP share one configuration and one run, clang_tidy_<group> / clang_tidy_<group>_full:

enable_clang_tidy(TARGET tinypbrt-example-utils GROUP examples
                  CONFIG "${PROJECT_SOURCE_DIR}/.clang-tidy" CXX_STANDARD c11 HEADER_FILTER "...")
enable_clang_tidy(TARGET tinypbrt-example-quickstart GROUP examples)   # settings inherited from the group
cmake --build build --target clang_tidy_tinypbrt     # library
cmake --build build --target clang_tidy_examples     # all examples in one run

The first target of a group sets CONFIG, CXX_STANDARD and the header filters; later targets may omit them or must pass the same values (a different value is a configuration error). clang-tidy reads the compile flags from compile_commands.json, so it needs a Ninja or Makefile generator; EXCLUDE_HEADER_FILTER requires clang-tidy 19+ and is skipped for older versions.

Documentation

cmake --build <build> --target docs runs Doxygen (TINYPBRT_BUILD_DOCUMENTATION=ON) with docs/Doxyfile.in and writes <build>/docs/html/index.html. This README is the main page; additional pages go to docs/pages (Markdown) and images to docs/images. Document the public headers with Doxygen comments; -DTINYPBRT_DOCUMENTATION_WARN_UNDOCUMENTED=ON lists what is still missing.

The documentation of main is published at https://maipa01.github.io/tinypbrt/ on every push (GitHub Actions -> GitHub Pages, together with the coverage report).

License

tinypbrt is released under the BSD 3-Clause License with an attribution requirement - see LICENSE for the full terms.

About

Tiny but powerful pbrt-v4 loader

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages