ca86eb1e232bfac169de019aba98d6df3984e64a
[supertux.git] / src / video / video_systems.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 <config.h>
18
19 #include "supertux/gameconfig.hpp"
20 #include "video/gl/gl_lightmap.hpp"
21 #include "video/gl/gl_renderer.hpp"
22 #include "video/gl/gl_surface_data.hpp"
23 #include "video/gl/gl_texture.hpp"
24 #include "video/lightmap.hpp"
25 #include "video/renderer.hpp"
26 #include "video/sdl/sdl_lightmap.hpp"
27 #include "video/sdl/sdl_renderer.hpp"
28 #include "video/sdl/sdl_surface_data.hpp"
29 #include "video/sdl/sdl_texture.hpp"
30 #include "video/texture.hpp"
31 #include "video/video_systems.hpp"
32
33 Renderer*
34 VideoSystem::new_renderer()
35 {
36   switch(g_config->video)
37   {
38     case AUTO_VIDEO:
39 #ifdef HAVE_OPENGL
40       log_info << "new GL renderer\n";
41       return new GLRenderer();
42 #else
43       log_warning << "new SDL renderer\n";
44       return new SDLRenderer();
45 #endif
46 #ifdef HAVE_OPENGL
47     case OPENGL:
48       log_info << "new GL renderer\n";
49       return new GLRenderer();
50 #endif
51     case PURE_SDL:
52       log_warning << "new SDL renderer\n";
53       return new SDLRenderer();
54     default:
55       assert(0 && "invalid video system in config");
56 #ifdef HAVE_OPENGL
57       log_info << "new GL renderer\n";
58       return new GLRenderer();
59 #else
60       log_warning << "new SDL renderer\n";
61       return new SDLRenderer();
62 #endif
63   }
64 }
65
66 Lightmap*
67 VideoSystem::new_lightmap()
68 {
69   switch(g_config->video)
70   {
71     case AUTO_VIDEO:
72 #ifdef HAVE_OPENGL
73       return new GLLightmap();
74 #else
75       return new SDLLightmap();
76 #endif
77 #ifdef HAVE_OPENGL
78     case OPENGL:
79       return new GLLightmap();
80 #endif
81     case PURE_SDL:
82       return new SDLLightmap();
83     default:
84       assert(0 && "invalid video system in config");
85 #ifdef HAVE_OPENGL
86       return new GLLightmap();
87 #else
88       return new SDLLightmap();
89 #endif
90   }
91 }
92
93 Texture*
94 VideoSystem::new_texture(SDL_Surface *image)
95 {
96   switch(g_config->video)
97   {
98     case AUTO_VIDEO:
99 #ifdef HAVE_OPENGL
100       return new GLTexture(image);
101 #else
102       return new SDLTexture(image);
103 #endif
104 #ifdef HAVE_OPENGL
105     case OPENGL:
106       return new GLTexture(image);
107 #endif
108     case PURE_SDL:
109       return new SDLTexture(image);
110     default:
111       assert(0 && "invalid video system in config");
112 #ifdef HAVE_OPENGL
113       return new GLTexture(image);
114 #else
115       return new SDLTexture(image);
116 #endif
117   }
118 }
119
120 SurfaceData*
121 VideoSystem::new_surface_data(const Surface &surface)
122 {
123   switch(g_config->video)
124   {
125     case AUTO_VIDEO:
126 #ifdef HAVE_OPENGL
127       return new GLSurfaceData(surface);
128 #else
129       return new SDLSurfaceData(surface);
130 #endif
131 #ifdef HAVE_OPENGL
132     case OPENGL:
133       return new GLSurfaceData(surface);
134 #endif
135     case PURE_SDL:
136       return new SDLSurfaceData(surface);
137     default:
138       assert(0 && "invalid video system in config");
139 #ifdef HAVE_OPENGL
140       return new GLSurfaceData(surface);
141 #else
142       return new SDLSurfaceData(surface);
143 #endif
144   }
145 }
146
147 void
148 VideoSystem::free_surface_data(SurfaceData* surface_data)
149 {
150   delete surface_data;
151 }
152
153 VideoSystem::Enum
154 VideoSystem::get_video_system(const std::string &video)
155 {
156   if(video == "auto")
157   {
158     return AUTO_VIDEO;
159   }
160 #ifdef HAVE_OPENGL
161   else if(video == "opengl")
162   {
163     return OPENGL;
164   }
165 #endif
166   else if(video == "sdl")
167   {
168     return PURE_SDL;
169   }
170   else
171   {
172     return AUTO_VIDEO;
173   }
174 }
175
176 std::string
177 VideoSystem::get_video_string(VideoSystem::Enum video)
178 {
179   switch(video)
180   {
181     case AUTO_VIDEO:
182       return "auto";
183     case OPENGL:
184       return "opengl";
185     case PURE_SDL:
186       return "sdl";
187     default:
188       assert(0 && "invalid video system in config");
189       return "auto";
190   }
191 }
192
193 /* EOF */