Compare commits

..

2 Commits

Author SHA1 Message Date
4d9e1f03b0 Fun menu :3
Signed-off-by: Slendi <slendi@socopon.com>
2025-12-17 21:42:59 +02:00
b01a32194e boop
Signed-off-by: Slendi <slendi@socopon.com>
2025-12-17 21:31:11 +02:00
6 changed files with 76 additions and 59 deletions

View File

@@ -1,23 +0,0 @@
#version 460
layout (local_size_x = 16, local_size_y = 16) in;
layout(rgba16f, set = 0, binding = 0) uniform image2D image;
void main() {
ivec2 texelCoord = ivec2(gl_GlobalInvocationID.xy);
ivec2 size = imageSize(image);
if (texelCoord.x >= size.x || texelCoord.y >= size.y)
return;
vec2 uv = (vec2(texelCoord) + 0.5) / vec2(size);
float v = sin(uv.x * 10.0) + cos(uv.y * 10.0);
float r = 0.5 + 0.5 * cos(6.2831 * (uv.x + v));
float g = 0.5 + 0.5 * cos(6.2831 * (uv.y + v + 0.33));
float b = 0.5 + 0.5 * cos(6.2831 * (uv.x - uv.y + 0.66));
vec4 color = vec4(r, g, b, 1.0);
imageStore(image, texelCoord, color);
}

View File

@@ -1,21 +0,0 @@
#version 450
layout(location = 0) out vec4 out_color;
layout(push_constant) uniform PushConstants {
vec2 resolution;
} pc;
void main()
{
vec2 uv = (gl_FragCoord.xy + vec2(0.5)) / pc.resolution;
float v = sin(uv.x * 10.0) + cos(uv.y * 10.0);
float r = 0.5 + 0.5 * cos(6.2831 * (uv.x + v));
float g = 0.5 + 0.5 * cos(6.2831 * (uv.y + v + 0.33));
float b = 0.5 + 0.5 * cos(6.2831 * (uv.x - uv.y + 0.66));
out_color = vec4(r, g, b, 1.0);
}

View File

@@ -1,13 +0,0 @@
#version 450
void main()
{
vec2 positions[3] = vec2[](
vec2(-1.0, -1.0),
vec2( 3.0, -1.0),
vec2(-1.0, 3.0)
);
gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0);
}

View File

@@ -224,6 +224,8 @@ Application::Application()
mouse_captured(true); mouse_captured(true);
m_logger.info("App init done!"); m_logger.info("App init done!");
m_renderer->set_antialiasing(VulkanRenderer::AntiAliasingKind::MSAA_4X);
} }
Application::~Application() Application::~Application()
@@ -306,12 +308,31 @@ auto Application::run() -> void
ImGui::Text("%s", std::format("FPS: {:.2f}", fps).c_str()); ImGui::Text("%s", std::format("FPS: {:.2f}", fps).c_str());
} }
ImGui::PopStyleColor(); ImGui::PopStyleColor();
ImGui::SetNextWindowSize({ 300, -1 }, ImGuiCond_Once);
if (ImGui::Begin("Fun menu")) {
defer(ImGui::End());
static std::array<char const *, 4> const aa_items {
"None",
"MSAA 2X",
"MSAA 4X",
"MSAA 8X",
};
int selected_item {
static_cast<int>(m_renderer->antialiasing()),
};
if (ImGui::Combo("Antialiasing", &selected_item,
aa_items.data(), aa_items.size())) {
m_renderer->set_antialiasing(
static_cast<VulkanRenderer::AntiAliasingKind>(
selected_item));
}
}
} }
ImGui::Render(); ImGui::Render();
m_renderer->set_antialiasing(VulkanRenderer::AntiAliasingKind::MSAA_8X);
m_renderer->render([&](VulkanRenderer::GL &gl) { m_renderer->render([&](VulkanRenderer::GL &gl) {
auto view { smath::matrix_look_at(smath::Vec3 { 0.0f, 0.0f, 3.0f }, auto view { smath::matrix_look_at(smath::Vec3 { 0.0f, 0.0f, 3.0f },
smath::Vec3 { 0.0f, 0.0f, 0.0f }, smath::Vec3 { 0.0f, 0.0f, 0.0f },

View File

@@ -9,6 +9,8 @@
#include <optional> #include <optional>
#include <print> #include <print>
#include <stdexcept> #include <stdexcept>
#include <type_traits>
#include <utility>
#include <SDL3/SDL_video.h> #include <SDL3/SDL_video.h>
#include <SDL3/SDL_vulkan.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 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) { auto requested_samples = [&](AntiAliasingKind aa) {
switch (aa) { switch (aa) {
@@ -616,6 +625,33 @@ auto VulkanRenderer::set_antialiasing(AntiAliasingKind kind) -> void
pipelines_init(); 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( auto VulkanRenderer::immediate_submit(
std::function<void(vk::CommandBuffer cmd)> &&function, std::function<void(vk::CommandBuffer cmd)> &&function,
bool flush_frame_deletion_queue, bool clear_frame_descriptors) -> void 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; return;
} }
process_render_commands();
auto &frame = m_vk.get_current_frame(); auto &frame = m_vk.get_current_frame();
VK_CHECK(m_logger, VK_CHECK(m_logger,
m_device.waitForFences(frame.render_fence.get(), true, 1'000'000'000)); m_device.waitForFences(frame.render_fence.get(), true, 1'000'000'000));

View File

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