From 5da5b961f1157294b0dfa9cded81fa019a9abcbd Mon Sep 17 00:00:00 2001 From: hydrogendeuteride Date: Thu, 11 Dec 2025 17:24:49 +0900 Subject: [PATCH] ADD: aspect ratio preserving part 1-add constants --- src/core/config.h | 7 +++++++ src/core/context.h | 2 ++ src/core/device/swapchain.h | 3 ++- src/core/engine.cpp | 5 +++++ src/core/engine.h | 1 + 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/core/config.h b/src/core/config.h index e968d4f..5762fab 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -11,6 +11,7 @@ inline constexpr bool kUseValidationLayers = true; // - Default: disabled to avoid noise and I/O at shutdown. // - Enable at runtime by setting environment variable `VE_VMA_DEBUG=1`. #include +#include inline constexpr bool kEnableVmaDebugByDefault = false; inline bool vmaDebugEnabled() { @@ -23,6 +24,12 @@ inline bool vmaDebugEnabled() return kEnableVmaDebugByDefault; } +// Fixed logical render resolution for letterboxed viewport. +// Internal rendering and camera aspect will target this size +// even when the window/swapchain size changes. +inline constexpr uint32_t kRenderWidth = 1920; +inline constexpr uint32_t kRenderHeight = 1080; + // Shadow mapping configuration inline constexpr int kShadowCascadeCount = 4; // Maximum shadow distance for CSM in view-space units diff --git a/src/core/context.h b/src/core/context.h index eedd7f6..4f3f2c8 100644 --- a/src/core/context.h +++ b/src/core/context.h @@ -69,6 +69,7 @@ public: // Frequently used values VkExtent2D drawExtent{}; + VkExtent2D logicalRenderExtent{}; // Optional convenience content pointers (moved to AssetManager for meshes) @@ -95,6 +96,7 @@ public: const GPUSceneData& getSceneData() const; const DrawContext& getMainDrawContext() const; VkExtent2D getDrawExtent() const { return drawExtent; } + VkExtent2D getLogicalRenderExtent() const { return logicalRenderExtent; } AssetManager* getAssets() const { return assets; } // Convenience alias (singular) requested AssetManager* getAsset() const { return assets; } diff --git a/src/core/device/swapchain.h b/src/core/device/swapchain.h index c00e1c4..6c7fc4b 100644 --- a/src/core/device/swapchain.h +++ b/src/core/device/swapchain.h @@ -1,6 +1,7 @@ #pragma once #include +#include class ResourceManager; class DeviceManager; @@ -42,7 +43,7 @@ private: VkSwapchainKHR _swapchain = nullptr; VkFormat _swapchainImageFormat = {}; VkExtent2D _swapchainExtent = {}; - VkExtent2D _windowExtent{1920, 1080}; + VkExtent2D _windowExtent{kRenderWidth, kRenderHeight}; std::vector _swapchainImages; std::vector _swapchainImageViews; diff --git a/src/core/engine.cpp b/src/core/engine.cpp index 03eb28d..3959876 100644 --- a/src/core/engine.cpp +++ b/src/core/engine.cpp @@ -145,6 +145,10 @@ void VulkanEngine::init() // We initialize SDL and create a window with it. SDL_Init(SDL_INIT_VIDEO); + // Initialize fixed logical render resolution for the engine. + _logicalRenderExtent.width = kRenderWidth; + _logicalRenderExtent.height = kRenderHeight; + constexpr auto window_flags = static_cast(SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE); _swapchainManager = std::make_unique(); @@ -182,6 +186,7 @@ void VulkanEngine::init() }; _context->descriptors->init(_deviceManager->device(), 10, sizes); } + _context->logicalRenderExtent = _logicalRenderExtent; _swapchainManager->init(_deviceManager.get(), _resourceManager.get()); _swapchainManager->init_swapchain(); diff --git a/src/core/engine.h b/src/core/engine.h index ab8aa97..0c9b1a9 100644 --- a/src/core/engine.h +++ b/src/core/engine.h @@ -84,6 +84,7 @@ public: FrameResources &get_current_frame() { return _frames[_frameNumber % FRAME_OVERLAP]; }; VkExtent2D _drawExtent; + VkExtent2D _logicalRenderExtent{}; float renderScale = 1.f; std::unique_ptr _descriptorManager;