Theme Catppuccin
Make yourself at homeCatppuccin

A softer light for long learning sessions.

Appearance

Loading your preference…

Dark palette

Choose a dark palette to try it.

Light uses Latte. Your choices stay in this browser.

Back to your source shelf

Inside the companion

Metal · Copper Orchard

Connect a Cocoa window to a C++ Metal renderer and verify GPU results.

Project files 7

Declare the Metal renderer boundary

The ordinary C++ interface called by the platform window bridge.

30 lines window_renderer.hpp
#pragma once

#include <cstddef>
#include <memory>

namespace MTL { class Device; class RenderPassDescriptor; }
namespace CA { class MetalDrawable; }

// The Cocoa bridge borrows these API objects for a single call. Ownership of
// command buffers and readback storage stays inside the C++ renderer.
class OrchardRenderer final {
public:
    explicit OrchardRenderer(MTL::Device* device, bool verify_pixels);
    ~OrchardRenderer();
    OrchardRenderer(const OrchardRenderer&) = delete;
    OrchardRenderer& operator=(const OrchardRenderer&) = delete;
    OrchardRenderer(OrchardRenderer&&) = delete;
    OrchardRenderer& operator=(OrchardRenderer&&) = delete;

    [[nodiscard]] bool has_capacity();
    void draw(MTL::RenderPassDescriptor* pass, CA::MetalDrawable* drawable);
    void finish();
    [[nodiscard]] std::size_t submitted() const noexcept;
    [[nodiscard]] std::size_t verified() const noexcept;

private:
    struct Impl;
    std::unique_ptr<Impl> impl_;
};

This is the file included with the course. Copy and download give you its complete source.

Taking your work offline? Download all course companions