1 /*
2 	This file is part of Warzone 2100.
3 	Copyright (C) 2019  Warzone 2100 Project
4 
5 	Warzone 2100 is free software; you can redistribute it and/or modify
6 	it under the terms of the GNU General Public License as published by
7 	the Free Software Foundation; either version 2 of the License, or
8 	(at your option) any later version.
9 
10 	Warzone 2100 is distributed in the hope that it will be useful,
11 	but WITHOUT ANY WARRANTY; without even the implied warranty of
12 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 	GNU General Public License for more details.
14 
15 	You should have received a copy of the GNU General Public License
16 	along with Warzone 2100; if not, write to the Free Software
17 	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 
20 #include "gfx_api_sdl.h"
21 #include "gfx_api_null_sdl.h"
22 #include "gfx_api_gl_sdl.h"
23 #include "gfx_api_vk_sdl.h"
24 #include <SDL_version.h>
25 #include <SDL_messagebox.h>
26 
SDL_gfx_api_Impl_Factory(SDL_Window * _window,SDL_gfx_api_Impl_Factory::Configuration _config)27 SDL_gfx_api_Impl_Factory::SDL_gfx_api_Impl_Factory(SDL_Window* _window, SDL_gfx_api_Impl_Factory::Configuration _config)
28 {
29 	window = _window;
30 	config = _config;
31 }
32 
createNullBackendImpl() const33 std::unique_ptr<gfx_api::backend_Null_Impl> SDL_gfx_api_Impl_Factory::createNullBackendImpl() const
34 {
35 	return std::unique_ptr<gfx_api::backend_Null_Impl>(new sdl_Null_Impl());
36 }
37 
createOpenGLBackendImpl() const38 std::unique_ptr<gfx_api::backend_OpenGL_Impl> SDL_gfx_api_Impl_Factory::createOpenGLBackendImpl() const
39 {
40 	ASSERT(window != nullptr, "Invalid SDL_Window*");
41 	return std::unique_ptr<gfx_api::backend_OpenGL_Impl>(new sdl_OpenGL_Impl(window, config.useOpenGLES, config.useOpenGLESLibrary));
42 }
43 
44 #if defined(WZ_VULKAN_ENABLED)
createVulkanBackendImpl() const45 std::unique_ptr<gfx_api::backend_Vulkan_Impl> SDL_gfx_api_Impl_Factory::createVulkanBackendImpl() const
46 {
47 	ASSERT(window != nullptr, "Invalid SDL_Window*");
48 #if defined(HAVE_SDL_VULKAN_H)
49 	return std::unique_ptr<gfx_api::backend_Vulkan_Impl>(new sdl_Vulkan_Impl(window));
50 #else // !defined(HAVE_SDL_VULKAN_H)
51 	SDL_version compiled_version;
52 	SDL_VERSION(&compiled_version);
53 	debug(LOG_ERROR, "The version of SDL used for compilation (%u.%u.%u) did not have the \"SDL_vulkan.h\" header", (unsigned int)compiled_version.major, (unsigned int)compiled_version.minor, (unsigned int)compiled_version.patch);
54 
55 	char errorMessage[512];
56 	ssprintf(errorMessage, "Unable to initialize SDL Vulkan implementation.\nThe version of SDL used for compilation (%u.%u.%u) did not have the \"SDL_vulkan.h\" header", (unsigned int)compiled_version.major, (unsigned int)compiled_version.minor, (unsigned int)compiled_version.patch);
57 
58 	SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
59 							 "Error: SDL Vulkan init",
60 							 errorMessage,
61 							 window);
62 
63 	return std::unique_ptr<gfx_api::backend_Vulkan_Impl>();
64 #endif
65 }
66 #endif
67