various fixes

This commit is contained in:
Richard Ward
2025-12-18 21:21:12 +00:00
parent c5073fe6ef
commit 0832cd0fc7
7 changed files with 30 additions and 19 deletions

View File

@@ -22,6 +22,8 @@
namespace sdl3cpp::app {
namespace script = sdl3cpp::script;
constexpr uint32_t kWidth = 1024;
constexpr uint32_t kHeight = 768;
@@ -120,10 +122,10 @@ private:
VkDeviceMemory indexBufferMemory_ = VK_NULL_HANDLE;
VkSemaphore imageAvailableSemaphore_ = VK_NULL_HANDLE;
VkSemaphore renderFinishedSemaphore_ = VK_NULL_HANDLE;
CubeScript cubeScript_;
script::CubeScript cubeScript_;
std::vector<core::Vertex> vertices_;
std::vector<uint16_t> indices_;
std::unordered_map<std::string, CubeScript::ShaderPaths> shaderPathMap_;
std::unordered_map<std::string, script::CubeScript::ShaderPaths> shaderPathMap_;
std::unordered_map<std::string, VkPipeline> graphicsPipelines_;
std::string defaultShaderKey_;
VkFence inFlightFence_ = VK_NULL_HANDLE;

View File

@@ -32,8 +32,7 @@ void Sdl3App::InitSDL() {
throw std::runtime_error(std::string("SDL_Init failed: ") + SDL_GetError());
}
SDL_Vulkan_LoadLibrary(nullptr);
window_ = SDL_CreateWindow("SDL3 Vulkan Demo", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
kWidth, kHeight, SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE);
window_ = SDL_CreateWindow("SDL3 Vulkan Demo", kWidth, kHeight, SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE);
if (!window_) {
throw std::runtime_error(std::string("SDL_CreateWindow failed: ") + SDL_GetError());
}
@@ -65,7 +64,7 @@ void Sdl3App::MainLoop() {
while (SDL_PollEvent(&event)) {
if (event.type == SDL_EVENT_QUIT) {
running = false;
} else if (event.type == SDL_EVENT_WINDOW_SIZE_CHANGED) {
} else if (event.type == SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED) {
framebufferResized_ = true;
}
}

View File

@@ -16,20 +16,18 @@ void Sdl3App::CreateInstance() {
appInfo.apiVersion = VK_API_VERSION_1_2;
uint32_t extensionCount = 0;
if (!SDL_Vulkan_GetInstanceExtensions(window_, &extensionCount, nullptr)) {
const char* const* extensions = SDL_Vulkan_GetInstanceExtensions(&extensionCount);
if (!extensions) {
throw std::runtime_error("Failed to query Vulkan extensions from SDL");
}
std::vector<const char*> extensions(extensionCount);
if (!SDL_Vulkan_GetInstanceExtensions(window_, &extensionCount, extensions.data())) {
throw std::runtime_error("Failed to store Vulkan extensions from SDL");
}
std::vector<const char*> extensionList(extensions, extensions + extensionCount);
VkInstanceCreateInfo createInfo{};
createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
createInfo.pApplicationInfo = &appInfo;
createInfo.enabledExtensionCount = static_cast<uint32_t>(extensions.size());
createInfo.ppEnabledExtensionNames = extensions.data();
createInfo.enabledExtensionCount = static_cast<uint32_t>(extensionList.size());
createInfo.ppEnabledExtensionNames = extensionList.data();
if (vkCreateInstance(&createInfo, nullptr, &instance_) != VK_SUCCESS) {
throw std::runtime_error("Failed to create Vulkan instance");
@@ -37,7 +35,7 @@ void Sdl3App::CreateInstance() {
}
void Sdl3App::CreateSurface() {
if (!SDL_Vulkan_CreateSurface(window_, instance_, &surface_)) {
if (!SDL_Vulkan_CreateSurface(window_, instance_, nullptr, &surface_)) {
throw std::runtime_error("Failed to create Vulkan surface");
}
}

View File

@@ -143,7 +143,7 @@ void Sdl3App::RecreateSwapChain() {
int width = 0;
int height = 0;
while (width == 0 || height == 0) {
SDL_Vulkan_GetDrawableSize(window_, &width, &height);
SDL_GetWindowSize(window_, &width, &height);
SDL_Event event;
SDL_WaitEvent(&event);
}
@@ -179,7 +179,7 @@ VkPresentModeKHR Sdl3App::ChooseSwapPresentMode(const std::vector<VkPresentModeK
VkExtent2D Sdl3App::ChooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities) {
int width, height;
SDL_Vulkan_GetDrawableSize(window_, &width, &height);
SDL_GetWindowSize(window_, &width, &height);
VkExtent2D actualExtent = {
static_cast<uint32_t>(std::clamp(width, static_cast<int>(capabilities.minImageExtent.width),
static_cast<int>(capabilities.maxImageExtent.width))),