Precalculated renderer specific surface data, better management of multiple renderers...
[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 #ifdef HAVE_OPENGL
40     case OPENGL:
41       return new GL::Renderer();
42 #endif
43     case PURE_SDL:
44       return new SDL::Renderer();
45     default:
46       assert(0 && "invalid video system in config");
47       return new SDL::Renderer();
48   }
49 }
50
51 Lightmap *new_lightmap()
52 {
53   switch(config->video)
54   {
55 #ifdef HAVE_OPENGL
56     case OPENGL:
57       return new GL::Lightmap();
58 #endif
59     case PURE_SDL:
60       return new SDL::Lightmap();
61     default:
62       assert(0 && "invalid video system in config");
63       return new SDL::Lightmap();
64   }
65 }
66
67 Texture *new_texture(SDL_Surface *image)
68 {
69   switch(config->video)
70   {
71 #ifdef HAVE_OPENGL
72     case OPENGL:
73       return new GL::Texture(image);
74 #endif
75     case PURE_SDL:
76       return new SDL::Texture(image);
77     default:
78       assert(0 && "invalid video system in config");
79       return new SDL::Texture(image);
80   }
81 }
82
83 void *new_surface_data(const Surface &surface)
84 {
85   switch(config->video)
86   {
87 #ifdef HAVE_OPENGL
88     case OPENGL:
89       return new GL::SurfaceData(surface);
90 #endif
91     case PURE_SDL:
92       return new SDL::SurfaceData(surface);
93     default:
94       assert(0 && "invalid video system in config");
95       return new SDL::SurfaceData(surface);
96   }
97 }
98
99 void free_surface_data(void *surface_data)
100 {
101   delete reinterpret_cast<char *>(surface_data);
102 }
103
104 VideoSystem get_video_system(const std::string &video)
105 {
106   if(0) {}
107 #ifdef HAVE_OPENGL
108   else if(video == "opengl")
109   {
110     return OPENGL;
111   }
112 #endif
113   else if(video == "sdl")
114   {
115     return PURE_SDL;
116   }
117   else
118   {
119 #ifdef HAVE_OPENGL
120     return OPENGL;
121 #else
122     return PURE_SDL;
123 #endif
124   }
125 }
126
127 std::string get_video_string(VideoSystem video)
128 {
129   switch(video)
130   {
131     case OPENGL:
132       return "opengl";
133     case PURE_SDL:
134       return "sdl";
135     default:
136       assert(0 && "invalid video system in config");
137       return "sdl";
138   }
139 }