2019-10-18 19:57:08 +00:00
|
|
|
/*
|
|
|
|
Created on: Oct 18, 2019
|
|
|
|
|
|
|
|
Copyright 2019 flyinghead
|
|
|
|
|
|
|
|
This file is part of Flycast.
|
|
|
|
|
|
|
|
Flycast is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Flycast is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Flycast. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2021-07-06 11:22:54 +00:00
|
|
|
#ifndef LIBRETRO
|
2019-10-18 19:57:08 +00:00
|
|
|
#include "context.h"
|
2019-10-19 16:34:24 +00:00
|
|
|
#include "rend/gui.h"
|
2021-03-01 09:13:40 +00:00
|
|
|
#include "cfg/option.h"
|
2019-10-18 19:57:08 +00:00
|
|
|
|
2021-11-10 19:35:30 +00:00
|
|
|
#include "gl_context.h"
|
|
|
|
#include "rend/dx9/dxcontext.h"
|
2021-11-26 17:08:41 +00:00
|
|
|
#include "rend/dx11/dx11context.h"
|
2019-10-18 19:57:08 +00:00
|
|
|
#ifdef USE_VULKAN
|
2021-11-10 19:35:30 +00:00
|
|
|
#include "rend/vulkan/vulkan_context.h"
|
|
|
|
|
2019-10-18 19:57:08 +00:00
|
|
|
VulkanContext theVulkanContext;
|
|
|
|
#endif
|
|
|
|
|
2021-11-10 19:35:30 +00:00
|
|
|
GraphicsContext *GraphicsContext::instance;
|
|
|
|
|
|
|
|
void initRenderApi(void *window, void *display)
|
2019-10-18 19:57:08 +00:00
|
|
|
{
|
|
|
|
#ifdef USE_VULKAN
|
2021-11-10 19:35:30 +00:00
|
|
|
if (isVulkan(config::RendererType))
|
2019-10-18 19:57:08 +00:00
|
|
|
{
|
2021-11-10 19:35:30 +00:00
|
|
|
theVulkanContext.setWindow(window, display);
|
|
|
|
if (theVulkanContext.init())
|
2019-10-18 19:57:08 +00:00
|
|
|
return;
|
|
|
|
// Fall back to Open GL
|
2019-11-29 18:28:22 +00:00
|
|
|
WARN_LOG(RENDERER, "Vulkan init failed. Falling back to Open GL.");
|
2021-03-01 09:13:40 +00:00
|
|
|
config::RendererType = RenderType::OpenGL;
|
2019-10-18 19:57:08 +00:00
|
|
|
}
|
2021-04-12 20:49:04 +00:00
|
|
|
#endif
|
2021-11-26 17:08:41 +00:00
|
|
|
#ifdef _WIN32
|
2021-12-11 17:53:35 +00:00
|
|
|
if (config::RendererType == RenderType::DirectX11 || config::RendererType == RenderType::DirectX11_OIT)
|
2021-11-26 17:08:41 +00:00
|
|
|
{
|
|
|
|
theDX11Context.setWindow(window, display);
|
|
|
|
if (theDX11Context.init())
|
|
|
|
return;
|
|
|
|
WARN_LOG(RENDERER, "DirectX 11 init failed. Falling back to DirectX 9.");
|
|
|
|
config::RendererType = RenderType::DirectX9;
|
|
|
|
}
|
|
|
|
#endif
|
2021-11-19 22:18:45 +00:00
|
|
|
#ifdef USE_DX9
|
2021-11-10 19:35:30 +00:00
|
|
|
if (config::RendererType == RenderType::DirectX9)
|
2021-04-12 20:49:04 +00:00
|
|
|
{
|
2021-11-10 19:35:30 +00:00
|
|
|
theDXContext.setWindow(window, display);
|
|
|
|
if (theDXContext.init())
|
2021-04-12 20:49:04 +00:00
|
|
|
return;
|
|
|
|
// Fall back to Open GL
|
2021-11-26 17:08:41 +00:00
|
|
|
WARN_LOG(RENDERER, "DirectX 9 init failed. Falling back to Open GL.");
|
2021-04-12 20:49:04 +00:00
|
|
|
config::RendererType = RenderType::OpenGL;
|
|
|
|
}
|
2019-10-18 19:57:08 +00:00
|
|
|
#endif
|
2021-11-10 19:35:30 +00:00
|
|
|
if (!isOpenGL(config::RendererType))
|
2021-10-14 08:52:35 +00:00
|
|
|
config::RendererType = RenderType::OpenGL;
|
2021-11-10 19:35:30 +00:00
|
|
|
theGLContext.setWindow(window, display);
|
|
|
|
if (!theGLContext.init())
|
2019-10-18 19:57:08 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2021-11-10 19:35:30 +00:00
|
|
|
void termRenderApi()
|
2019-10-18 19:57:08 +00:00
|
|
|
{
|
2021-11-10 19:35:30 +00:00
|
|
|
if (GraphicsContext::Instance() != nullptr)
|
|
|
|
GraphicsContext::Instance()->term();
|
|
|
|
verify(GraphicsContext::Instance() == nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void switchRenderApi()
|
|
|
|
{
|
|
|
|
void *window = nullptr;
|
|
|
|
void *display = nullptr;
|
|
|
|
if (GraphicsContext::Instance() != nullptr)
|
|
|
|
GraphicsContext::Instance()->getWindow(&window, &display);
|
|
|
|
termRenderApi();
|
|
|
|
initRenderApi(window, display);
|
2019-10-18 19:57:08 +00:00
|
|
|
}
|
2021-07-06 11:22:54 +00:00
|
|
|
#endif
|