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
This commit is contained in:
+34
@@ -34,6 +34,8 @@ struct pipeline::impl {
|
||||
|
||||
auto build(pipeline_desc const& desc) -> bool;
|
||||
auto bind_texture(char const* sampler_name, std::uint32_t texture_id, std::uint32_t unit) const -> void;
|
||||
auto bind_vec3(char const* name, glm::vec3 const& v) const -> void;
|
||||
auto bind_float(char const* name, float v) const -> void;
|
||||
};
|
||||
|
||||
auto pipeline::impl::build(pipeline_desc const& desc) -> bool {
|
||||
@@ -105,6 +107,26 @@ auto pipeline::impl::build(pipeline_desc const& desc) -> bool {
|
||||
}
|
||||
|
||||
|
||||
auto pipeline::impl::bind_vec3(char const* name, glm::vec3 const& v) const -> void {
|
||||
if (!m_prog.valid()) return;
|
||||
m_prog.use();
|
||||
GLint const loc = glGetUniformLocation(m_prog.id(), name);
|
||||
if (loc != -1) {
|
||||
glUniform3fv(loc, 1, glm::value_ptr(v));
|
||||
}
|
||||
m_prog.unuse();
|
||||
}
|
||||
|
||||
auto pipeline::impl::bind_float(char const* name, float v) const -> void {
|
||||
if (!m_prog.valid()) return;
|
||||
m_prog.use();
|
||||
GLint const loc = glGetUniformLocation(m_prog.id(), name);
|
||||
if (loc != -1) {
|
||||
glUniform1f(loc, v);
|
||||
}
|
||||
m_prog.unuse();
|
||||
}
|
||||
|
||||
auto pipeline::impl::bind_texture(char const* sampler_name, std::uint32_t texture_id, std::uint32_t unit) const -> void {
|
||||
if (!m_prog.valid()) {
|
||||
return;
|
||||
@@ -187,6 +209,18 @@ auto pipeline::bind_texture(char const* sampler_name, std::uint32_t texture_id,
|
||||
}
|
||||
}
|
||||
|
||||
auto pipeline::bind_vec3(char const* name, glm::vec3 const& v) const -> void {
|
||||
if (m_impl) {
|
||||
m_impl->bind_vec3(name, v);
|
||||
}
|
||||
}
|
||||
|
||||
auto pipeline::bind_float(char const* name, float v) const -> void {
|
||||
if (m_impl) {
|
||||
m_impl->bind_float(name, v);
|
||||
}
|
||||
}
|
||||
|
||||
struct render_target::impl {
|
||||
GLuint m_fbo = 0;
|
||||
opengl::texture m_color{opengl::texture_target::_2d};
|
||||
|
||||
@@ -50,6 +50,8 @@ public:
|
||||
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;
|
||||
|
||||
@@ -10,4 +10,6 @@ auto scene::update(float) -> void {}
|
||||
|
||||
auto scene::render(int, int) -> void {}
|
||||
|
||||
auto scene::on_mouse_drag(double, double) -> void {}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ public:
|
||||
virtual auto init() -> bool;
|
||||
virtual auto update(float delta_time) -> void;
|
||||
virtual auto render(int width, int height) -> void;
|
||||
virtual auto on_mouse_drag(double dx, double dy) -> void;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user