Adding more Window validation

This commit is contained in:
2026-04-06 14:28:58 +02:00
parent 7271fe8a0b
commit 87390db80d
4 changed files with 50 additions and 23 deletions
+10 -19
View File
@@ -59,7 +59,12 @@ target_include_directories(Engine PRIVATE src/Engine)
target_link_libraries(Engine PUBLIC Vulkan::Vulkan)
target_link_libraries(Engine PUBLIC GPUOpen::VulkanMemoryAllocator)
if(NOT APPLE)
target_link_libraries(Engine PUBLIC slang::slang-glslang)
# slang-glslang is a MODULE library (plugin) - copy it instead of linking
add_custom_command(TARGET Engine POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:slang::slang-glslang>
$<TARGET_FILE_DIR:Engine>
)
endif()
target_link_libraries(Engine PUBLIC EnTT::EnTT)
target_link_libraries(Engine PUBLIC glfw)
@@ -121,31 +126,17 @@ if(APPLE)
target_compile_options(Engine PUBLIC -Wno-gnu-anonymous-struct -Wno-nested-anon-types)
target_compile_options(Editor PUBLIC -Wno-gnu-anonymous-struct -Wno-nested-anon-types)
endif()
target_compile_options(Engine PUBLIC "$<$<CONFIG:DEBUG>:-DENABLE_VALIDATION>")
target_compile_options(Engine PUBLIC "$<$<CONFIG:DEBUG>:-DSEELE_DEBUG>")
add_subdirectory(src/)
#add_subdirectory(tests/)
if(WIN32)
add_custom_target(dll_copy ALL
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_RUNTIME_DLLS:Engine> $<TARGET_FILE_DIR:Editor>
COMMAND_EXPAND_LISTS
DEPENDS Editor)
elseif(APPLE)
add_custom_target(dll_copy ALL
COMMAND ${CMAKE_COMMAND} -E true
COMMAND_EXPAND_LISTS
DEPENDS Editor)
else()
add_custom_target(dll_copy ALL
COMMAND ${CMAKE_COMMAND} -E true)
add_custom_command(TARGET Engine POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_RUNTIME_DLLS:Engine> $<TARGET_FILE_DIR:Editor>)
endif()
add_custom_target(SeeleEngine ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/res $<TARGET_FILE_DIR:Engine>
COMMAND_EXPAND_LISTS
DEPENDS Editor dll_copy)
add_custom_command(TARGET Engine POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/res $<TARGET_FILE_DIR:Engine>)
install(
TARGETS
+1 -1
View File
@@ -4,7 +4,7 @@
#include "MinimalEngine.h"
#include "RenderTarget.h"
#include "Resources.h"
#define ENABLE_VALIDATION
namespace Seele {
namespace Gfx {
+17 -2
View File
@@ -667,6 +667,17 @@ Array<const char*> Graphics::getRequiredExtensions() {
unsigned int glfwExtensionCount = 0;
const char** glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
if (glfwExtensions == nullptr || glfwExtensionCount == 0) {
const char* glfwError = nullptr;
glfwGetError(&glfwError);
std::string message = "GLFW did not report required Vulkan instance extensions";
if (glfwError != nullptr) {
message += ": ";
message += glfwError;
}
throw std::runtime_error(message);
}
for (unsigned int i = 0; i < glfwExtensionCount; i++) {
extensions.add(glfwExtensions[i]);
}
@@ -677,8 +688,12 @@ Array<const char*> Graphics::getRequiredExtensions() {
}
void Graphics::initInstance(GraphicsInitializer initInfo) {
glfwInit();
assert(glfwVulkanSupported());
if (!glfwInit()) {
throw std::runtime_error("Failed to initialize GLFW");
}
if (!glfwVulkanSupported()) {
throw std::runtime_error("GLFW: Vulkan not supported");
}
VkApplicationInfo appInfo = {
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
.pNext = nullptr,
+22 -1
View File
@@ -4,6 +4,7 @@
#include "Graphics.h"
#include "Resources.h"
#include <GLFW/glfw3.h>
#include <sstream>
using namespace Seele;
using namespace Seele::Vulkan;
@@ -61,6 +62,16 @@ Window::Window(PGraphics graphics, const WindowCreateInfo& createInfo)
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
GLFWwindow* handle = glfwCreateWindow(createInfo.width / contentScaleX, createInfo.height / contentScaleY, createInfo.title, nullptr, nullptr);
if (handle == nullptr) {
const char* glfwError = nullptr;
glfwGetError(&glfwError);
std::string message = "Failed to create GLFW window";
if (glfwError != nullptr) {
message += ": ";
message += glfwError;
}
throw std::runtime_error(message);
}
windowHandle = handle;
glfwSetWindowUserPointer(handle, this);
@@ -73,7 +84,17 @@ Window::Window(PGraphics graphics, const WindowCreateInfo& createInfo)
glfwSetFramebufferSizeCallback(handle, &glfwFramebufferResizeCallback);
// glfwSetWindowSizeCallback(handle, &glfwResizeCallback);
glfwCreateWindowSurface(instance, handle, nullptr, &surface);
VkResult surfaceResult = glfwCreateWindowSurface(instance, handle, nullptr, &surface);
if (surfaceResult != VK_SUCCESS || surface == VK_NULL_HANDLE) {
const char* glfwError = nullptr;
glfwGetError(&glfwError);
std::ostringstream oss;
oss << "Failed to create Vulkan surface via GLFW (VkResult=" << surfaceResult << ")";
if (glfwError != nullptr) {
oss << ": " << glfwError;
}
throw std::runtime_error(oss.str());
}
querySurface();
chooseSwapSurfaceFormat();