Browse Source

proper selection of vulkan renderer

niki 3 years ago
parent
commit
565455c3ea
3 changed files with 34 additions and 38 deletions
  1. 5 1
      src/common/config.h
  2. 9 4
      src/modules/graphics/Graphics.cpp
  3. 20 33
      src/modules/window/sdl/Window.cpp

+ 5 - 1
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

+ 9 - 4
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<Renderer> 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)

+ 20 - 33
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::ContextAttribs> 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;
-			}
-
-			if (!glcontext)
-			{
-				SDL_DestroyWindow(window);
-				window = nullptr;
-				return false;
+				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))
+				{
+					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)