move changes to the right branch
[supertux.git] / src / src / video / video_systems.cpp
1 //  $Id: video_systems.cpp 5063 2007-05-27 11:32:00Z matzeb $
2 //
3 //  SuperTux
4 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 #include <config.h>
20
21 #include "video_systems.hpp"
22 #include "gameconfig.hpp"
23 #include "renderer.hpp"
24 #include "gl_renderer.hpp"
25 #include "sdl_renderer.hpp"
26 #include "lightmap.hpp"
27 #include "gl_lightmap.hpp"
28 #include "sdl_lightmap.hpp"
29 #include "texture.hpp"
30 #include "gl_texture.hpp"
31 #include "sdl_texture.hpp"
32 #include "gl_surface_data.hpp"
33 #include "sdl_surface_data.hpp"
34
35 Renderer *new_renderer()
36 {
37   switch(config->video)
38   {
39     case AUTO_VIDEO:
40 #ifdef HAVE_OPENGL
41       return new GL::Renderer();
42 #else
43       return new SDL::Renderer();
44 #endif
45 #ifdef HAVE_OPENGL
46     case OPENGL:
47       return new GL::Renderer();
48 #endif
49     case PURE_SDL:
50       return new SDL::Renderer();
51     default:
52       assert(0 && "invalid video system in config");
53 #ifdef HAVE_OPENGL
54       return new GL::Renderer();
55 #else
56       return new SDL::Renderer();
57 #endif
58   }
59 }
60
61 Lightmap *new_lightmap()
62 {
63   switch(config->video)
64   {
65     case AUTO_VIDEO:
66 #ifdef HAVE_OPENGL
67       return new GL::Lightmap();
68 #else
69       return new SDL::Lightmap();
70 #endif
71 #ifdef HAVE_OPENGL
72     case OPENGL:
73       return new GL::Lightmap();
74 #endif
75     case PURE_SDL:
76       return new SDL::Lightmap();
77     default:
78       assert(0 && "invalid video system in config");
79 #ifdef HAVE_OPENGL
80       return new GL::Lightmap();
81 #else
82       return new SDL::Lightmap();
83 #endif
84   }
85 }
86
87 Texture *new_texture(SDL_Surface *image)
88 {
89   switch(config->video)
90   {
91     case AUTO_VIDEO:
92 #ifdef HAVE_OPENGL
93       return new GL::Texture(image);
94 #else
95       return new SDL::Texture(image);
96 #endif
97 #ifdef HAVE_OPENGL
98     case OPENGL:
99       return new GL::Texture(image);
100 #endif
101     case PURE_SDL:
102       return new SDL::Texture(image);
103     default:
104       assert(0 && "invalid video system in config");
105 #ifdef HAVE_OPENGL
106       return new GL::Texture(image);
107 #else
108       return new SDL::Texture(image);
109 #endif
110   }
111 }
112
113 void *new_surface_data(const Surface &surface)
114 {
115   switch(config->video)
116   {
117     case AUTO_VIDEO:
118 #ifdef HAVE_OPENGL
119       return new GL::SurfaceData(surface);
120 #else
121       return new SDL::SurfaceData(surface);
122 #endif
123 #ifdef HAVE_OPENGL
124     case OPENGL:
125       return new GL::SurfaceData(surface);
126 #endif
127     case PURE_SDL:
128       return new SDL::SurfaceData(surface);
129     default:
130       assert(0 && "invalid video system in config");
131 #ifdef HAVE_OPENGL
132       return new GL::SurfaceData(surface);
133 #else
134       return new SDL::SurfaceData(surface);
135 #endif
136   }
137 }
138
139 void free_surface_data(void *surface_data)
140 {
141   delete reinterpret_cast<char *>(surface_data);
142 }
143
144 VideoSystem get_video_system(const std::string &video)
145 {
146   if(video == "auto")
147   {
148     return AUTO_VIDEO;
149   }
150 #ifdef HAVE_OPENGL
151   else if(video == "opengl")
152   {
153     return OPENGL;
154   }
155 #endif
156   else if(video == "sdl")
157   {
158     return PURE_SDL;
159   }
160   else
161   {
162     return AUTO_VIDEO;
163   }
164 }
165
166 std::string get_video_string(VideoSystem video)
167 {
168   switch(video)
169   {
170     case AUTO_VIDEO:
171       return "auto";
172     case OPENGL:
173       return "opengl";
174     case PURE_SDL:
175       return "sdl";
176     default:
177       assert(0 && "invalid video system in config");
178       return "auto";
179   }
180 }