Skip to content

Commit 764c670

Browse files
committed
Add RenderMode
- Replace `Scene::pipeline_state` with `render_mode`. - Remove `Pipeline::State::line_width`.
1 parent afcf7a4 commit 764c670

File tree

4 files changed

+21
-14
lines changed

4 files changed

+21
-14
lines changed

lib/engine/src/scene_renderer.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ std::span<glm::mat4x4 const> SceneRenderer::make_instance_mats(Node const& node,
7878
}
7979

8080
void SceneRenderer::render(Renderer& renderer, vk::CommandBuffer cb, Skybox const& skybox) {
81-
auto state = m_scene->pipeline_state;
82-
state.depth_test = false;
83-
auto pipeline = renderer.bind_pipeline(cb, state, "skybox");
81+
auto pipeline = renderer.bind_pipeline(cb, {.depth_test = false}, "skybox");
8482
pipeline.set_line_width(1.0f);
8583
update_view(pipeline);
8684
auto& set1 = pipeline.next_set(1);
@@ -99,10 +97,9 @@ void SceneRenderer::render(Renderer& renderer, vk::CommandBuffer cb, Node const&
9997
auto const& material = primitive.material ? resources.materials[primitive.material->value()] : static_cast<Material const&>(s_default_material);
10098
auto const& static_mesh = resources.static_meshes[primitive.static_mesh];
10199

102-
auto state = m_scene->pipeline_state;
103-
state.topology = static_mesh.topology();
104-
auto pipeline = renderer.bind_pipeline(cb, state, material.shader_id());
105-
pipeline.set_line_width(m_scene->pipeline_state.line_width);
100+
auto const mode = m_scene->render_mode.type == RenderMode::Type::eWireframe ? vk::PolygonMode::eLine : vk::PolygonMode::eFill;
101+
auto pipeline = renderer.bind_pipeline(cb, {.mode = mode, .topology = static_mesh.topology()}, material.shader_id());
102+
pipeline.set_line_width(m_scene->render_mode.line_width);
106103

107104
update_view(pipeline);
108105
auto const store = TextureStore{resources.textures, m_white, m_black};

lib/scene/include/facade/scene/scene.hpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,25 @@
66
#include <facade/util/image.hpp>
77
#include <facade/util/ptr.hpp>
88
#include <facade/util/transform.hpp>
9-
#include <facade/vk/pipeline.hpp>
109
#include <memory>
1110
#include <span>
1211
#include <vector>
1312

1413
namespace facade {
1514
struct DataProvider;
1615

16+
///
17+
/// \brief Polygon rendering mode: applied scene-wide.
18+
///
19+
struct RenderMode {
20+
enum class Type { eFill, eWireframe };
21+
22+
Type type{Type::eFill};
23+
float line_width{1.0f};
24+
25+
bool operator==(RenderMode const&) const = default;
26+
};
27+
1728
///
1829
/// \brief Models a 3D scene.
1930
///
@@ -177,9 +188,9 @@ class Scene {
177188
Lights lights{};
178189

179190
///
180-
/// \brief Global pipeline state.
191+
/// \brief Render mode.
181192
///
182-
Pipeline::State pipeline_state{};
193+
RenderMode render_mode{};
183194

184195
///
185196
/// \brief Update animations and corresponding nodes.

lib/vk/include/facade/vk/pipeline.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ class Pipeline {
99
struct State {
1010
vk::PolygonMode mode{vk::PolygonMode::eFill};
1111
vk::PrimitiveTopology topology{vk::PrimitiveTopology::eTriangleList};
12-
float line_width{1.0f};
1312
bool depth_test{true};
1413

1514
bool operator==(State const&) const = default;

src/gui/main_menu.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ bool WindowMenu::display_stats(Engine& engine) {
9494
if (ImGui::SmallButton("Vsync")) { change_vsync(engine); }
9595
ImGui::SameLine();
9696
ImGui::Text("%s", vsync_status(stats.mode).data());
97-
auto& ps = engine.scene().pipeline_state;
98-
bool wireframe = ps.mode == vk::PolygonMode::eLine;
99-
if (ImGui::Checkbox("Wireframe", &wireframe)) { ps.mode = wireframe ? vk::PolygonMode::eLine : vk::PolygonMode::eFill; }
97+
auto& ps = engine.scene().render_mode;
98+
bool wireframe = ps.type == RenderMode::Type::eWireframe;
99+
if (ImGui::Checkbox("Wireframe", &wireframe)) { ps.type = wireframe ? RenderMode::Type::eWireframe : RenderMode::Type::eFill; }
100100
if (wireframe) {
101101
ImGui::SameLine();
102102
ImGui::DragFloat("Line Width", &ps.line_width, 0.1f, 1.0f, 10.0f);

0 commit comments

Comments
 (0)