oughj
This commit is contained in:
parent
7d10d6c480
commit
f8278f4a74
|
@ -40,14 +40,12 @@
|
||||||
inherit (sources.${name}) pname version src;
|
inherit (sources.${name}) pname version src;
|
||||||
};
|
};
|
||||||
|
|
||||||
fmt = mkPkg "fmt";
|
|
||||||
imgui = (mkPkg "imgui").override {
|
imgui = (mkPkg "imgui").override {
|
||||||
IMGUI_BUILD_GLFW_BINDING = true;
|
IMGUI_BUILD_GLFW_BINDING = true;
|
||||||
IMGUI_BUILD_VULKAN_BINDING = true;
|
IMGUI_BUILD_VULKAN_BINDING = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
deps = with pkgs; [
|
deps = with pkgs; [
|
||||||
fmt
|
|
||||||
glfw
|
glfw
|
||||||
glm
|
glm
|
||||||
imgui
|
imgui
|
||||||
|
|
|
@ -21,7 +21,6 @@ common_cpp_args = [
|
||||||
add_project_arguments(cpp.get_supported_arguments(common_cpp_args), language: 'cpp')
|
add_project_arguments(cpp.get_supported_arguments(common_cpp_args), language: 'cpp')
|
||||||
|
|
||||||
deps = [
|
deps = [
|
||||||
dependency('fmt', include_type: 'system'),
|
|
||||||
dependency('glfw3', include_type: 'system'),
|
dependency('glfw3', include_type: 'system'),
|
||||||
dependency('glm', include_type: 'system'),
|
dependency('glm', include_type: 'system'),
|
||||||
dependency('vulkan', include_type: 'system'),
|
dependency('vulkan', include_type: 'system'),
|
||||||
|
|
|
@ -1,7 +1,3 @@
|
||||||
[fmt]
|
|
||||||
src.github = "fmtlib/fmt"
|
|
||||||
fetch.github = "fmtlib/fmt"
|
|
||||||
|
|
||||||
[imgui]
|
[imgui]
|
||||||
src.git = "https://github.com/ocornut/imgui.git"
|
src.git = "https://github.com/ocornut/imgui.git"
|
||||||
src.branch = "docking"
|
src.branch = "docking"
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
#include <fmt/format.h>
|
|
||||||
|
|
||||||
#include "imgui_manager.hpp"
|
#include "imgui_manager.hpp"
|
||||||
|
|
||||||
ImGuiManager::~ImGuiManager() { cleanup(); }
|
ImGuiManager::~ImGuiManager() { cleanup(); }
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
#define FMT_HEADER_ONLY
|
|
||||||
#include <fmt/color.h>
|
|
||||||
#include <fmt/format.h>
|
|
||||||
|
|
||||||
#include "debug_messenger.hpp"
|
#include "debug_messenger.hpp"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
constexpr std::string_view ANSI_RESET = "\033[0m";
|
||||||
|
constexpr std::string_view ANSI_BOLD = "\033[1m";
|
||||||
|
constexpr std::string_view ANSI_RED = "\033[31m";
|
||||||
|
constexpr std::string_view ANSI_YELLOW = "\033[33m";
|
||||||
|
constexpr std::string_view ANSI_LIGHT_BLUE = "\033[94m";
|
||||||
|
constexpr std::string_view ANSI_WHITE = "\033[97m";
|
||||||
|
}
|
||||||
|
|
||||||
fn DebugMessenger::create(const vk::Instance& instance, Config config)
|
fn DebugMessenger::create(const vk::Instance& instance, Config config)
|
||||||
-> std::expected<vk::UniqueDebugUtilsMessengerEXT, std::string> {
|
-> std::expected<vk::UniqueDebugUtilsMessengerEXT, std::string> {
|
||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
|
@ -19,7 +24,7 @@ fn DebugMessenger::create(const vk::Instance& instance, Config config)
|
||||||
|
|
||||||
return instance.createDebugUtilsMessengerEXTUnique(createInfo);
|
return instance.createDebugUtilsMessengerEXTUnique(createInfo);
|
||||||
} catch (const vk::SystemError& e) {
|
} catch (const vk::SystemError& e) {
|
||||||
return std::unexpected(fmt::format("Failed to create debug messenger: {}", e.what()));
|
return std::unexpected(std::format("Failed to create debug messenger: {}", e.what()));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -44,9 +49,9 @@ VKAPI_ATTR VkBool32 VKAPI_CALL DebugMessenger::debugCallback(
|
||||||
|
|
||||||
if (config && config->use_stderr_for_errors &&
|
if (config && config->use_stderr_for_errors &&
|
||||||
(messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT)) {
|
(messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT)) {
|
||||||
fmt::println(stderr, "{}", formattedMessage);
|
std::println(stderr, "{}", formattedMessage);
|
||||||
} else {
|
} else {
|
||||||
fmt::println("{}", formattedMessage);
|
std::println("{}", formattedMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
return VK_FALSE;
|
return VK_FALSE;
|
||||||
|
@ -54,24 +59,24 @@ VKAPI_ATTR VkBool32 VKAPI_CALL DebugMessenger::debugCallback(
|
||||||
|
|
||||||
fn DebugMessenger::formatMessage(const Message& msg) -> std::string {
|
fn DebugMessenger::formatMessage(const Message& msg) -> std::string {
|
||||||
// Color based on severity
|
// Color based on severity
|
||||||
fmt::color textColor = fmt::color::white;
|
std::string_view colorCode = ANSI_WHITE;
|
||||||
std::string_view severityText;
|
std::string_view severityText;
|
||||||
|
|
||||||
switch (msg.severity) {
|
switch (msg.severity) {
|
||||||
case vk::DebugUtilsMessageSeverityFlagBitsEXT::eVerbose:
|
case vk::DebugUtilsMessageSeverityFlagBitsEXT::eVerbose:
|
||||||
textColor = fmt::color::light_blue;
|
colorCode = ANSI_LIGHT_BLUE;
|
||||||
severityText = "VERBOSE";
|
severityText = "VERBOSE";
|
||||||
break;
|
break;
|
||||||
case vk::DebugUtilsMessageSeverityFlagBitsEXT::eInfo:
|
case vk::DebugUtilsMessageSeverityFlagBitsEXT::eInfo:
|
||||||
textColor = fmt::color::white;
|
colorCode = ANSI_WHITE;
|
||||||
severityText = "INFO";
|
severityText = "INFO";
|
||||||
break;
|
break;
|
||||||
case vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning:
|
case vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning:
|
||||||
textColor = fmt::color::yellow;
|
colorCode = ANSI_YELLOW;
|
||||||
severityText = "WARNING";
|
severityText = "WARNING";
|
||||||
break;
|
break;
|
||||||
case vk::DebugUtilsMessageSeverityFlagBitsEXT::eError:
|
case vk::DebugUtilsMessageSeverityFlagBitsEXT::eError:
|
||||||
textColor = fmt::color::red;
|
colorCode = ANSI_RED;
|
||||||
severityText = "ERROR";
|
severityText = "ERROR";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -86,13 +91,15 @@ fn DebugMessenger::formatMessage(const Message& msg) -> std::string {
|
||||||
typeStr += "PERFORMANCE ";
|
typeStr += "PERFORMANCE ";
|
||||||
|
|
||||||
// Format the message with color and structure
|
// Format the message with color and structure
|
||||||
return fmt::format(
|
return std::format(
|
||||||
fmt::emphasis::bold | fg(textColor),
|
"{}{}[{}] {} {}{}: {}{}",
|
||||||
"[{}] {} {}{}: {}",
|
colorCode,
|
||||||
|
ANSI_BOLD,
|
||||||
severityText,
|
severityText,
|
||||||
typeStr,
|
typeStr,
|
||||||
msg.function_name.has_value() ? fmt::format("in {} ", *msg.function_name) : "",
|
msg.function_name.has_value() ? std::format("in {} ", *msg.function_name) : "",
|
||||||
msg.id,
|
msg.id,
|
||||||
msg.message
|
msg.message,
|
||||||
|
ANSI_RESET
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,9 @@
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <span>
|
#include <span>
|
||||||
|
|
||||||
#define FMT_HEADER_ONLY
|
#include "device_manager.hpp"
|
||||||
#include <fmt/format.h>
|
|
||||||
|
|
||||||
#include "../structs/swap_chain_support_details.hpp"
|
#include "../structs/swap_chain_support_details.hpp"
|
||||||
#include "device_manager.hpp"
|
|
||||||
|
|
||||||
struct PhysicalDeviceInfo {
|
struct PhysicalDeviceInfo {
|
||||||
vk::PhysicalDevice physical_device;
|
vk::PhysicalDevice physical_device;
|
||||||
|
@ -33,7 +31,7 @@ fn DeviceManager::pickPhysicalDevice(
|
||||||
return std::unexpected("Failed to find GPUs with Vulkan support!");
|
return std::unexpected("Failed to find GPUs with Vulkan support!");
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
fmt::println("Available devices:");
|
std::println("Available devices:");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Find the first suitable device using ranges
|
// Find the first suitable device using ranges
|
||||||
|
@ -47,9 +45,9 @@ fn DeviceManager::pickPhysicalDevice(
|
||||||
vk::PhysicalDeviceProperties deviceProperties = suitableDevice->getProperties();
|
vk::PhysicalDeviceProperties deviceProperties = suitableDevice->getProperties();
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
fmt::println("\t{}", deviceProperties.deviceName.data());
|
std::println("\t{}", deviceProperties.deviceName.data());
|
||||||
fmt::println("Maximum supported line width: {}", deviceProperties.limits.lineWidthRange[1]);
|
std::println("Maximum supported line width: {}", deviceProperties.limits.lineWidthRange[1]);
|
||||||
fmt::println("Wide lines supported: {}", deviceProperties.limits.lineWidthRange[1] > 1.0F ? "yes" : "no");
|
std::println("Wide lines supported: {}", deviceProperties.limits.lineWidthRange[1] > 1.0F ? "yes" : "no");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return PhysicalDeviceInfo {
|
return PhysicalDeviceInfo {
|
||||||
|
@ -113,7 +111,7 @@ fn DeviceManager::createLogicalDevice(
|
||||||
.present_queue = presentQueue,
|
.present_queue = presentQueue,
|
||||||
};
|
};
|
||||||
} catch (const vk::SystemError& e) {
|
} catch (const vk::SystemError& e) {
|
||||||
return std::unexpected(fmt::format("Failed to create logical device: {}", e.what()));
|
return std::unexpected(std::format("Failed to create logical device: {}", e.what()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
#define VULKAN_HPP_DISPATCH_LOADER_DYNAMIC 1
|
#define VULKAN_HPP_DISPATCH_LOADER_DYNAMIC 1
|
||||||
|
|
||||||
#include <fmt/format.h>
|
|
||||||
|
|
||||||
#include "vulkan_instance.hpp"
|
#include "vulkan_instance.hpp"
|
||||||
|
|
||||||
#include "../util/constants.hpp"
|
#include "../util/constants.hpp"
|
||||||
|
@ -29,8 +27,8 @@ fn VulkanInstance::create() -> vk::UniqueInstance {
|
||||||
std::vector<const char*> extensions = getRequiredExtensions();
|
std::vector<const char*> extensions = getRequiredExtensions();
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
fmt::println("Available extensions:");
|
std::println("Available extensions:");
|
||||||
for (const char* extension : extensions) { fmt::println("\t{}", extension); }
|
for (const char* extension : extensions) { std::println("\t{}", extension); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Create the instance
|
// Create the instance
|
||||||
|
|
14
src/main.cpp
14
src/main.cpp
|
@ -1,7 +1,5 @@
|
||||||
// Include necessary headers
|
// Include necessary headers
|
||||||
#include <chrono> // For time-related functions
|
#include <chrono> // For time-related functions
|
||||||
#define FMT_HEADER_ONLY
|
|
||||||
#include <fmt/format.h> // For string formatting
|
|
||||||
#include <shaderc/shaderc.hpp> // For shader compilation
|
#include <shaderc/shaderc.hpp> // For shader compilation
|
||||||
#include <unordered_set> // For unordered_set container
|
#include <unordered_set> // For unordered_set container
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -258,9 +256,9 @@ class VulkanApp {
|
||||||
try {
|
try {
|
||||||
mDevice->waitIdle();
|
mDevice->waitIdle();
|
||||||
createGraphicsPipeline();
|
createGraphicsPipeline();
|
||||||
fmt::println("Shaders reloaded successfully!");
|
std::println("Shaders reloaded successfully!");
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
fmt::println(stderr, "Failed to reload shaders: {}", e.what());
|
std::println(stderr, "Failed to reload shaders: {}", e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -406,7 +404,7 @@ class VulkanApp {
|
||||||
if (currentFrame - lastFpsUpdate > 1.0) {
|
if (currentFrame - lastFpsUpdate > 1.0) {
|
||||||
WindowManager::setTitle(
|
WindowManager::setTitle(
|
||||||
mWindow.get(),
|
mWindow.get(),
|
||||||
fmt::format("Vulkan - {:.0f}FPS", static_cast<f32>(frameCounter / (currentFrame - lastFpsUpdate)))
|
std::format("Vulkan - {:.0f}FPS", static_cast<f32>(frameCounter / (currentFrame - lastFpsUpdate)))
|
||||||
);
|
);
|
||||||
lastFpsUpdate = currentFrame;
|
lastFpsUpdate = currentFrame;
|
||||||
frameCounter = 0;
|
frameCounter = 0;
|
||||||
|
@ -2542,7 +2540,7 @@ class VulkanApp {
|
||||||
// Print the message to the console
|
// Print the message to the console
|
||||||
// Because pCallbackData already gives the message severity
|
// Because pCallbackData already gives the message severity
|
||||||
// and type, we don't need to print them, so they're unused.
|
// and type, we don't need to print them, so they're unused.
|
||||||
fmt::println("Validation layer: {}", pCallbackData->pMessage);
|
std::println("Validation layer: {}", pCallbackData->pMessage);
|
||||||
|
|
||||||
return vk::False;
|
return vk::False;
|
||||||
}
|
}
|
||||||
|
@ -2567,7 +2565,7 @@ fn main() -> i32 {
|
||||||
try {
|
try {
|
||||||
app.run();
|
app.run();
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
fmt::println("{}", e.what());
|
std::println("{}", e.what());
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fmt/format.h>
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <ios>
|
#include <ios>
|
||||||
#include <shaderc/shaderc.hpp>
|
#include <shaderc/shaderc.hpp>
|
||||||
|
@ -68,14 +67,14 @@ class ShaderCompiler {
|
||||||
// Cache is up to date, load it
|
// Cache is up to date, load it
|
||||||
vector<u32> spirvCode = loadCachedShader(cacheFile);
|
vector<u32> spirvCode = loadCachedShader(cacheFile);
|
||||||
if (!spirvCode.empty()) {
|
if (!spirvCode.empty()) {
|
||||||
fmt::println("Loaded shader from cache: {}", cacheFile.string());
|
std::println("Loaded shader from cache: {}", cacheFile.string());
|
||||||
return spirvCode;
|
return spirvCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need to compile the shader
|
// Need to compile the shader
|
||||||
fmt::println("Compiling shader: {}", absPath.string());
|
std::println("Compiling shader: {}", absPath.string());
|
||||||
|
|
||||||
// Read shader source
|
// Read shader source
|
||||||
ifstream file(absPath);
|
ifstream file(absPath);
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fmt/format.h>
|
|
||||||
|
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
#include <stb_image.h>
|
#include <stb_image.h>
|
||||||
|
@ -130,7 +129,7 @@ namespace stb {
|
||||||
fn load(const char* path) -> void {
|
fn load(const char* path) -> void {
|
||||||
mData = stbi_load(path, &mWidth, &mHeight, &mChannels, STBI_rgb_alpha);
|
mData = stbi_load(path, &mWidth, &mHeight, &mChannels, STBI_rgb_alpha);
|
||||||
if (!mData)
|
if (!mData)
|
||||||
throw std::runtime_error(fmt::format("Failed to load texture image: {}", path));
|
throw std::runtime_error(std::format("Failed to load texture image: {}", path));
|
||||||
}
|
}
|
||||||
|
|
||||||
u8* mData = nullptr; ///< Raw image data in memory
|
u8* mData = nullptr; ///< Raw image data in memory
|
||||||
|
|
|
@ -32,7 +32,7 @@ fn WindowManager::create(const char* title, const WindowCallbacks& callbacks)
|
||||||
i32 ypos = (videoMode->height - HEIGHT) / 2;
|
i32 ypos = (videoMode->height - HEIGHT) / 2;
|
||||||
|
|
||||||
// Set window position
|
// Set window position
|
||||||
// window->setPos(xpos, ypos);
|
window->setPos(xpos, ypos);
|
||||||
|
|
||||||
// Configure cursor for FPS-style camera control
|
// Configure cursor for FPS-style camera control
|
||||||
window->set<vkfw::InputMode::eCursor>(vkfw::CursorMode::eDisabled);
|
window->set<vkfw::InputMode::eCursor>(vkfw::CursorMode::eDisabled);
|
||||||
|
@ -72,5 +72,5 @@ fn WindowManager::setCursorMode(const vkfw::Window& window, vkfw::CursorMode mod
|
||||||
}
|
}
|
||||||
|
|
||||||
fn WindowManager::setPosition(const vkfw::Window& window, i32 xpos, i32 ypos) -> void {
|
fn WindowManager::setPosition(const vkfw::Window& window, i32 xpos, i32 ypos) -> void {
|
||||||
// window.setPos(xpos, ypos);
|
window.setPos(xpos, ypos);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue