mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
proper selection of vulkan renderer
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user