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