Inside the companion
First Light
Make your first CPU image, rasterize triangles, and trace an allocation budget.
Project files 15
Give an image one owner
Owned pixel storage and the renderer and PPM-writing interfaces.
#pragma once
#include "prism/scene.hpp"
#include <span>
#include <filesystem>
namespace prism {
// A value owns the complete RGB image. A span is only a temporary borrowed view.
struct Image {
std::uint32_t width{}, height{};
std::vector<std::uint8_t> rgb;
[[nodiscard]] std::span<const std::uint8_t> pixels() const & noexcept { return rgb; }
std::span<const std::uint8_t> pixels() const && = delete;
};
[[nodiscard]] std::expected<Image, Error> render(const Scene& scene);
[[nodiscard]] std::expected<void, Error> write_ppm(const std::filesystem::path& path,
const Image& image);
} // namespace prism
This is the file included with the course. Copy and download give you its complete source.
Taking your work offline? Download all course companions
