From 565455c3ea11f723736f98bdb005ee4a47170f73 Mon Sep 17 00:00:00 2001 From: niki Date: Sun, 10 Jul 2022 03:46:12 +0200 Subject: [PATCH] proper selection of vulkan renderer --- src/common/config.h | 6 +++- src/modules/graphics/Graphics.cpp | 13 +++++--- src/modules/window/sdl/Window.cpp | 51 ++++++++++++------------------- 3 files changed, 33 insertions(+), 37 deletions(-) diff --git a/src/common/config.h b/src/common/config.h index 1df87b98a..7a5ec0a02 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -126,7 +126,11 @@ # define LOVE_LEGENDARY_ACCELEROMETER_AS_JOYSTICK_HACK #endif -#define LOVE_GRAPHICS_VULKAN +// fixme: vulkan graphics only tested on windows for now +// adjust this later on when testing is successful on other platforms +#ifdef LOVE_WINDOWS +# define LOVE_GRAPHICS_VULKAN +#endif #if defined(LOVE_MACOS) || defined(LOVE_IOS) # define LOVE_GRAPHICS_METAL diff --git a/src/modules/graphics/Graphics.cpp b/src/modules/graphics/Graphics.cpp index 4cc56f0a4..17b7350dc 100644 --- a/src/modules/graphics/Graphics.cpp +++ b/src/modules/graphics/Graphics.cpp @@ -109,16 +109,20 @@ namespace opengl { extern love::graphics::Graphics *createInstance(); } #ifdef LOVE_GRAPHICS_METAL namespace metal { extern love::graphics::Graphics *createInstance(); } #endif +#ifdef LOVE_GRAPHICS_VULKAN namespace vulkan { extern love::graphics::Graphics* createInstance(); } +#endif static const Renderer rendererOrder[] = { RENDERER_METAL, + RENDERER_VULKAN, RENDERER_OPENGL, }; static std::vector defaultRenderers = { RENDERER_METAL, + RENDERER_VULKAN, RENDERER_OPENGL, }; @@ -149,14 +153,14 @@ Graphics *Graphics::createInstance() { for (auto r : rendererOrder) { -#ifdef LOVE_GRAPHICS_VULKAN - // FIX ME: proper selection of vulkan backend - instance = vulkan::createInstance(); -#endif if (std::find(_renderers.begin(), _renderers.end(), r) == _renderers.end()) continue; +#ifdef LOVE_GRAPHICS_VULKAN + if (r == RENDERER_VULKAN) + instance = vulkan::createInstance(); +#endif if (r == RENDERER_OPENGL) instance = opengl::createInstance(); #ifdef LOVE_GRAPHICS_METAL @@ -2554,6 +2558,7 @@ STRINGMAP_CLASS_END(Graphics, Graphics::StackType, Graphics::STACK_MAX_ENUM, sta STRINGMAP_BEGIN(Renderer, RENDERER_MAX_ENUM, renderer) { { "opengl", RENDERER_OPENGL }, + { "vulkan", RENDERER_VULKAN }, { "metal", RENDERER_METAL }, } STRINGMAP_END(Renderer, RENDERER_MAX_ENUM, renderer) diff --git a/src/modules/window/sdl/Window.cpp b/src/modules/window/sdl/Window.cpp index 7fde747c8..93e54f0c3 100644 --- a/src/modules/window/sdl/Window.cpp +++ b/src/modules/window/sdl/Window.cpp @@ -144,7 +144,6 @@ void Window::setGLFramebufferAttributes(bool sRGB) void Window::setGLContextAttributes(const ContextAttribs &attribs) { -#ifndef LOVE_GRAPHICS_VULKAN int profilemask = 0; int contextflags = 0; @@ -162,12 +161,10 @@ void Window::setGLContextAttributes(const ContextAttribs &attribs) SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, attribs.versionMinor); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profilemask); SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, contextflags); -#endif } bool Window::checkGLVersion(const ContextAttribs &attribs, std::string &outversion) { -#ifndef LOVE_GRAPHICS_VULKAN typedef unsigned char GLubyte; typedef unsigned int GLenum; typedef const GLubyte *(APIENTRY *glGetStringPtr)(GLenum name); @@ -212,9 +209,6 @@ bool Window::checkGLVersion(const ContextAttribs &attribs, std::string &outversi return false; return true; -#else - return true; -#endif } std::vector Window::getContextAttribsList() const @@ -327,13 +321,11 @@ bool Window::createWindowAndContext(int x, int y, int w, int h, Uint32 windowfla const auto create = [&](const ContextAttribs *attribs) -> bool { -#ifndef LOVE_GRAPHICS_VULKAN if (glcontext) { SDL_GL_DeleteContext(glcontext); glcontext = nullptr; } -#endif #ifdef LOVE_GRAPHICS_METAL if (metalView) @@ -350,7 +342,6 @@ bool Window::createWindowAndContext(int x, int y, int w, int h, Uint32 windowfla window = nullptr; } -#ifndef LOVE_GRAPHICS_VULKAN window = SDL_CreateWindow(title.c_str(), x, y, w, h, windowflags); if (!window) @@ -359,35 +350,31 @@ bool Window::createWindowAndContext(int x, int y, int w, int h, Uint32 windowfla return false; } - if (attribs != nullptr) - { - glcontext = SDL_GL_CreateContext(window); - - if (!glcontext) - contexterror = std::string(SDL_GetError()); - - // Make sure the context's version is at least what we requested. - if (glcontext && !checkGLVersion(*attribs, glversion)) + if (renderer == love::graphics::Renderer::RENDERER_OPENGL) { + if (attribs != nullptr) { - SDL_GL_DeleteContext(glcontext); - glcontext = nullptr; - } + glcontext = SDL_GL_CreateContext(window); - if (!glcontext) - { - SDL_DestroyWindow(window); - window = nullptr; - return false; + if (!glcontext) + contexterror = std::string(SDL_GetError()); + + // Make sure the context's version is at least what we requested. + if (glcontext && !checkGLVersion(*attribs, glversion)) + { + SDL_GL_DeleteContext(glcontext); + glcontext = nullptr; + } + + if (!glcontext) + { + SDL_DestroyWindow(window); + window = nullptr; + return false; + } } } return true; - -#else - window = SDL_CreateWindow(title.c_str(), x, y, w, h, windowflags | SDL_WINDOW_VULKAN); - - return true; -#endif }; if (renderer == graphics::RENDERER_OPENGL)