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