Fun menu :3

Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
2025-12-17 21:42:59 +02:00
parent b01a32194e
commit 4d9e1f03b0
3 changed files with 58 additions and 6 deletions

View File

@@ -224,6 +224,8 @@ Application::Application()
mouse_captured(true);
m_logger.info("App init done!");
m_renderer->set_antialiasing(VulkanRenderer::AntiAliasingKind::MSAA_4X);
}
Application::~Application()
@@ -307,6 +309,7 @@ auto Application::run() -> void
}
ImGui::PopStyleColor();
ImGui::SetNextWindowSize({ 300, -1 }, ImGuiCond_Once);
if (ImGui::Begin("Fun menu")) {
defer(ImGui::End());
@@ -319,10 +322,8 @@ auto Application::run() -> void
int selected_item {
static_cast<int>(m_renderer->antialiasing()),
};
int prev_selected_item { selected_item };
ImGui::Combo("Antialiasing", &selected_item, aa_items.data(),
aa_items.size());
if (prev_selected_item != selected_item) {
if (ImGui::Combo("Antialiasing", &selected_item,
aa_items.data(), aa_items.size())) {
m_renderer->set_antialiasing(
static_cast<VulkanRenderer::AntiAliasingKind>(
selected_item));
@@ -332,8 +333,6 @@ auto Application::run() -> void
ImGui::Render();
m_renderer->set_antialiasing(VulkanRenderer::AntiAliasingKind::MSAA_8X);
m_renderer->render([&](VulkanRenderer::GL &gl) {
auto view { smath::matrix_look_at(smath::Vec3 { 0.0f, 0.0f, 3.0f },
smath::Vec3 { 0.0f, 0.0f, 0.0f },

View File

@@ -9,6 +9,8 @@
#include <optional>
#include <print>
#include <stdexcept>
#include <type_traits>
#include <utility>
#include <SDL3/SDL_video.h>
#include <SDL3/SDL_vulkan.h>
@@ -526,6 +528,13 @@ auto VulkanRenderer::resize(uint32_t width, uint32_t height) -> void
}
auto VulkanRenderer::set_antialiasing(AntiAliasingKind kind) -> void
{
enqueue_render_command(RenderCommand {
RenderCommand::SetAntiAliasing { kind },
});
}
auto VulkanRenderer::apply_antialiasing(AntiAliasingKind kind) -> void
{
auto requested_samples = [&](AntiAliasingKind aa) {
switch (aa) {
@@ -616,6 +625,33 @@ auto VulkanRenderer::set_antialiasing(AntiAliasingKind kind) -> void
pipelines_init();
}
auto VulkanRenderer::enqueue_render_command(RenderCommand &&command) -> void
{
std::scoped_lock lock { m_command_mutex };
m_pending_render_commands.emplace_back(std::move(command));
}
auto VulkanRenderer::process_render_commands() -> void
{
std::vector<RenderCommand> commands;
{
std::scoped_lock lock { m_command_mutex };
commands.swap(m_pending_render_commands);
}
for (auto &command : commands) {
std::visit(
[&](auto &&payload) {
using Payload = std::decay_t<decltype(payload)>;
if constexpr (std::is_same_v<Payload,
RenderCommand::SetAntiAliasing>) {
apply_antialiasing(payload.kind);
}
},
command.payload);
}
}
auto VulkanRenderer::immediate_submit(
std::function<void(vk::CommandBuffer cmd)> &&function,
bool flush_frame_deletion_queue, bool clear_frame_descriptors) -> void
@@ -1155,6 +1191,8 @@ auto VulkanRenderer::render(std::function<void(GL &)> const &record) -> void
return;
}
process_render_commands();
auto &frame = m_vk.get_current_frame();
VK_CHECK(m_logger,
m_device.waitForFences(frame.render_fence.get(), true, 1'000'000'000));

View File

@@ -2,7 +2,9 @@
#include <array>
#include <functional>
#include <mutex>
#include <optional>
#include <variant>
#include <vector>
#include <SDL3/SDL_video.h>
@@ -156,6 +158,14 @@ struct VulkanRenderer {
GL gl;
private:
struct RenderCommand {
struct SetAntiAliasing {
AntiAliasingKind kind;
};
std::variant<SetAntiAliasing> payload;
};
auto vk_init() -> void;
auto swapchain_init() -> void;
auto commands_init() -> void;
@@ -190,6 +200,9 @@ private:
auto create_buffer(size_t alloc_size, vk::BufferUsageFlags usage,
VmaMemoryUsage memory_usage) -> AllocatedBuffer;
auto destroy_buffer(AllocatedBuffer const &buffer) -> void;
auto enqueue_render_command(RenderCommand &&command) -> void;
auto process_render_commands() -> void;
auto apply_antialiasing(AntiAliasingKind kind) -> void;
vk::Instance m_instance {};
vk::PhysicalDevice m_physical_device {};
@@ -267,6 +280,8 @@ private:
SDL_Window *m_window { nullptr };
Logger &m_logger;
std::mutex m_command_mutex;
std::vector<RenderCommand> m_pending_render_commands;
};
} // namespace Lunar