Downgrade surface format message from warning to debug
[supertux.git] / src / video / video_system.cpp
1 //  SuperTux
2 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 //
4 //  This program is free software: you can redistribute it and/or modify
5 //  it under the terms of the GNU General Public License as published by
6 //  the Free Software Foundation, either version 3 of the License, or
7 //  (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU General Public License for more details.
13 //
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 #include "video/video_system.hpp"
18
19 #include <config.h>
20
21 #include "util/log.hpp"
22 #include "video/sdl/sdl_video_system.hpp"
23
24 #ifdef HAVE_OPENGL
25 #include "video/gl/gl_video_system.hpp"
26 #endif
27
28 std::unique_ptr<VideoSystem>
29 VideoSystem::create(VideoSystem::Enum video_system)
30 {
31   switch(video_system)
32   {
33     case AUTO_VIDEO:
34 #ifdef HAVE_OPENGL
35       try
36       {
37         return std::unique_ptr<VideoSystem>(new GLVideoSystem);
38       }
39       catch(std::exception& err)
40       {
41         log_warning << "Error creating GLVideoSystem, using SDL fallback: "  << err.what() << std::endl;
42         return std::unique_ptr<VideoSystem>(new SDLVideoSystem);
43       }
44 #else
45       log_info << "new SDL renderer\n";
46       return std::unique_ptr<VideoSystem>(new SDLVideoSystem);
47 #endif
48
49     case OPENGL:
50 #ifdef HAVE_OPENGL
51       return std::unique_ptr<VideoSystem>(new GLVideoSystem);
52 #else
53       log_warning << "OpenGL requested, but missing using SDL fallback" << std::endl;
54       return std::unique_ptr<VideoSystem>(new SDLVideoSystem);
55 #endif
56
57     case PURE_SDL:
58       log_info << "new SDL renderer\n";
59       return std::unique_ptr<VideoSystem>(new SDLVideoSystem);
60
61     default:
62       assert(!"invalid video system in config");
63       return {};
64   }
65 }
66
67 VideoSystem::Enum
68 VideoSystem::get_video_system(const std::string &video)
69 {
70   if(video == "auto")
71   {
72     return AUTO_VIDEO;
73   }
74 #ifdef HAVE_OPENGL
75   else if(video == "opengl")
76   {
77     return OPENGL;
78   }
79 #endif
80   else if(video == "sdl")
81   {
82     return PURE_SDL;
83   }
84   else
85   {
86     return AUTO_VIDEO;
87   }
88 }
89
90 std::string
91 VideoSystem::get_video_string(VideoSystem::Enum video)
92 {
93   switch(video)
94   {
95     case AUTO_VIDEO:
96       return "auto";
97     case OPENGL:
98       return "opengl";
99     case PURE_SDL:
100       return "sdl";
101     default:
102       assert(!"invalid video system in config");
103       return "auto";
104   }
105 }
106
107 /* EOF */