Vulcan Nightmare

Experimentally bringing up vulcan support
This commit is contained in:
Kelsi 2026-02-21 19:41:21 -08:00
parent 863a786c48
commit 83b576e8d9
189 changed files with 12147 additions and 7820 deletions

View file

@ -1,6 +1,7 @@
#include "core/window.hpp"
#include "core/logger.hpp"
#include <GL/glew.h>
#include "rendering/vk_context.hpp"
#include <SDL2/SDL_vulkan.h>
namespace wowee {
namespace core {
@ -28,18 +29,8 @@ bool Window::initialize() {
return false;
}
// Set OpenGL attributes
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);
// Create window
Uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN;
// Create Vulkan window (no GL attributes needed)
Uint32 flags = SDL_WINDOW_VULKAN | SDL_WINDOW_SHOWN;
if (config.fullscreen) {
flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
}
@ -61,49 +52,21 @@ bool Window::initialize() {
return false;
}
// Create OpenGL context
glContext = SDL_GL_CreateContext(window);
if (!glContext) {
LOG_ERROR("Failed to create OpenGL context: ", SDL_GetError());
// Initialize Vulkan context
vkContext = std::make_unique<rendering::VkContext>();
if (!vkContext->initialize(window)) {
LOG_ERROR("Failed to initialize Vulkan context");
return false;
}
// Set VSync
if (SDL_GL_SetSwapInterval(config.vsync ? 1 : 0) != 0) {
LOG_WARNING("Failed to set VSync: ", SDL_GetError());
}
vsync = config.vsync;
// Initialize GLEW
glewExperimental = GL_TRUE;
GLenum glewError = glewInit();
if (glewError != GLEW_OK) {
LOG_ERROR("Failed to initialize GLEW: ", glewGetErrorString(glewError));
return false;
}
// Log OpenGL info
LOG_INFO("OpenGL Version: ", glGetString(GL_VERSION));
LOG_INFO("GLSL Version: ", glGetString(GL_SHADING_LANGUAGE_VERSION));
LOG_INFO("Renderer: ", glGetString(GL_RENDERER));
LOG_INFO("Vendor: ", glGetString(GL_VENDOR));
// Set up OpenGL defaults
glEnable(GL_MULTISAMPLE);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glFrontFace(GL_CCW);
LOG_INFO("Window initialized successfully");
LOG_INFO("Window initialized successfully (Vulkan)");
return true;
}
void Window::shutdown() {
if (glContext) {
SDL_GL_DeleteContext(glContext);
glContext = nullptr;
if (vkContext) {
vkContext->shutdown();
vkContext.reset();
}
if (window) {
@ -115,15 +78,9 @@ void Window::shutdown() {
LOG_INFO("Window shutdown complete");
}
void Window::swapBuffers() {
SDL_GL_SwapWindow(window);
}
void Window::pollEvents() {
SDL_Event event;
while (SDL_PollEvent(&event)) {
// ImGui will handle events in UI manager
// For now, just handle quit
if (event.type == SDL_QUIT) {
shouldCloseFlag = true;
}
@ -131,7 +88,9 @@ void Window::pollEvents() {
if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
width = event.window.data1;
height = event.window.data2;
glViewport(0, 0, width, height);
if (vkContext) {
vkContext->recreateSwapchain(width, height);
}
LOG_DEBUG("Window resized to ", width, "x", height);
}
}
@ -160,15 +119,16 @@ void Window::setFullscreen(bool enable) {
width = windowedWidth;
height = windowedHeight;
}
glViewport(0, 0, width, height);
if (vkContext) {
vkContext->recreateSwapchain(width, height);
}
}
void Window::setVsync(bool enable) {
if (SDL_GL_SetSwapInterval(enable ? 1 : 0) != 0) {
LOG_WARNING("Failed to set VSync: ", SDL_GetError());
return;
}
void Window::setVsync([[maybe_unused]] bool enable) {
// VSync in Vulkan is controlled by present mode (set at swapchain creation)
// For now, store the preference — applied on next swapchain recreation
vsync = enable;
LOG_INFO("VSync preference set to ", enable ? "on" : "off", " (applied on swapchain recreation)");
}
void Window::applyResolution(int w, int h) {
@ -184,7 +144,9 @@ void Window::applyResolution(int w, int h) {
height = h;
windowedWidth = w;
windowedHeight = h;
glViewport(0, 0, width, height);
if (vkContext) {
vkContext->recreateSwapchain(width, height);
}
}
} // namespace core