Files
portersky 6bfde6c6fb feat: add Cornell Box scene with orbit camera
- gfx::pipeline gains bind_vec3/bind_float for passing arbitrary
  uniforms to shaders (used for light position/color)
- scene base gains on_mouse_drag virtual hook; cuber.cpp polls
  left-mouse delta each frame and forwards it to the active scene
- cornell_box scene: 5-wall room (red/green/white), two pre-rotated
  white boxes with proportions from the original paper, an unlit
  ceiling light panel, and a point-light Lambert shader
- left-click drag orbits the camera around the scene origin;
  pitch is clamped to ±80° to prevent gimbal flip
- key 3 / --scene cornell_box selects the scene
2026-05-11 16:35:26 +02:00

84 lines
2.2 KiB
C++

#pragma once
#include <cstddef>
#include <cstdint>
#include <memory>
#include <span>
#include <vector>
#include "glm/glm.hpp"
namespace cbt::gfx {
enum class primitive_type {
triangles
};
enum class index_type {
uint16,
uint32
};
struct attribute_desc {
std::uint32_t location = 0;
std::uint32_t num_components = 3;
std::uint32_t offset = 0;
};
struct pipeline_desc {
std::span<std::byte const> vertex_data{};
std::span<std::byte const> index_data{};
std::vector<attribute_desc> attributes{};
std::uint32_t vertex_stride = 0;
char const* vertex_shader_src = nullptr;
char const* fragment_shader_src = nullptr;
bool depth_test = true;
primitive_type primitive = primitive_type::triangles;
index_type index_type_ = index_type::uint32;
};
class pipeline {
public:
pipeline();
explicit pipeline(pipeline_desc const& desc);
pipeline(pipeline const&) = delete;
pipeline(pipeline&& other) noexcept;
auto operator=(pipeline const&) -> pipeline& = delete;
auto operator=(pipeline&& other) noexcept -> pipeline&;
~pipeline();
auto valid() const -> bool;
auto draw(glm::mat4 const& model, glm::mat4 const& view, glm::mat4 const& proj) const -> void;
auto bind_texture(char const* sampler_name, std::uint32_t texture_id, std::uint32_t unit = 0) const -> void;
auto bind_vec3(char const* name, glm::vec3 const& v) const -> void;
auto bind_float(char const* name, float v) const -> void;
private:
struct impl;
std::unique_ptr<impl> m_impl;
};
class render_target {
public:
explicit render_target(int width, int height);
render_target(render_target const&) = delete;
render_target(render_target&& other) noexcept;
auto operator=(render_target const&) -> render_target& = delete;
auto operator=(render_target&& other) noexcept -> render_target&;
~render_target();
auto bind() const -> void;
auto unbind() const -> void;
auto color_id() const -> std::uint32_t;
auto width() const -> int;
auto height() const -> int;
auto valid() const -> bool;
auto resize(int width, int height) -> void;
private:
struct impl;
std::unique_ptr<impl> m_impl;
};
} // namespace cbt::gfx