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