新增交换链创建功能
This commit is contained in:
@@ -2,7 +2,10 @@
|
||||
|
||||
#include <SDL3/SDL_vulkan.h>
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "core/logger.h"
|
||||
#include "gpu_resource/swapchain.h"
|
||||
#include "render/vulkan_context.h"
|
||||
|
||||
namespace mirai {
|
||||
@@ -42,7 +45,15 @@ namespace mirai {
|
||||
}
|
||||
|
||||
void window::update(duration_ms delta_time) {
|
||||
|
||||
if (closing_) {
|
||||
return;
|
||||
}
|
||||
if (need_rebuild_swapchain()) {
|
||||
auto result = rebuild_swapchain();
|
||||
if (!result) {
|
||||
MIRAI_LOG_ERROR("窗口 {} 交换链重建失败: {}", get_window_title(), result.error().full_description());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void window::show_window(bool show) {
|
||||
@@ -70,20 +81,58 @@ namespace mirai {
|
||||
vec2i window::get_pos() const {
|
||||
int x, y;
|
||||
if (!SDL_GetWindowPosition(window_, &x, &y)) {
|
||||
MIRAI_LOG_ERROR("SDL_GetWindowPosition failed: %s", SDL_GetError());
|
||||
MIRAI_LOG_ERROR("SDL_GetWindowPosition 失败: {}", SDL_GetError());
|
||||
x = 0;
|
||||
y = 0;
|
||||
}
|
||||
return vec2i{x, y};
|
||||
}
|
||||
|
||||
vec2i window::get_framebuffer_size() const {
|
||||
int width, height;
|
||||
if (!SDL_GetWindowSizeInPixels(window_, &width, &height)) {
|
||||
MIRAI_LOG_ERROR("SDL_Vulkan_GetDrawableSize 失败: {}", SDL_GetError());
|
||||
width = 0;
|
||||
height = 0;
|
||||
}
|
||||
return vec2i{width, height};
|
||||
}
|
||||
|
||||
vec2i window::get_window_size() const {
|
||||
int width, height;
|
||||
if (!SDL_GetWindowSize(window_, &width, &height)) {
|
||||
MIRAI_LOG_ERROR("SDL_GetWindowSize 失败: {}", SDL_GetError());
|
||||
width = 0;
|
||||
height = 0;
|
||||
}
|
||||
return vec2i{width, height};
|
||||
}
|
||||
|
||||
bool window::need_rebuild_swapchain() const {
|
||||
if (!swapchain_)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void_result_t window::rebuild_swapchain(bool hdr_enabled, vec2i new_extent) {
|
||||
swapchain_create_info info{};
|
||||
info.surface = surface_;
|
||||
info.hdr_enabled = hdr_enabled;
|
||||
info.initial_extent = std::move(new_extent);
|
||||
swapchain_ = make_obj<swapchain>(info);
|
||||
if (!swapchain_) {
|
||||
return MAKE_ERROR_INFO(error_code::swapchain_creation_failed, "交换链创建失败");
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void window::on_created() {
|
||||
object::on_created();
|
||||
|
||||
}
|
||||
|
||||
void window::on_destroying() {
|
||||
object::on_destroying();
|
||||
swapchain_.reset();
|
||||
MIRAI_LOG_INFO("窗口 {} 销毁", get_window_title());
|
||||
SDL_Vulkan_DestroySurface(vulkan_context::get().get_vk_instance(), surface_, nullptr);
|
||||
SDL_DestroyWindow(window_);
|
||||
|
||||
Reference in New Issue
Block a user