src/video/video_systems.cpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #include <config.h>
00018 
00019 #include "supertux/gameconfig.hpp"
00020 #include "video/lightmap.hpp"
00021 #include "video/renderer.hpp"
00022 #include "video/sdl/sdl_lightmap.hpp"
00023 #include "video/sdl/sdl_renderer.hpp"
00024 #include "video/sdl/sdl_surface_data.hpp"
00025 #include "video/sdl/sdl_texture.hpp"
00026 #include "video/texture.hpp"
00027 #include "video/video_systems.hpp"
00028 
00029 #ifdef HAVE_OPENGL
00030 #include "video/gl/gl_lightmap.hpp"
00031 #include "video/gl/gl_renderer.hpp"
00032 #include "video/gl/gl_surface_data.hpp"
00033 #include "video/gl/gl_texture.hpp"
00034 #endif
00035 
00036 Renderer*
00037 VideoSystem::new_renderer()
00038 {
00039   switch(g_config->video)
00040   {
00041     case AUTO_VIDEO:
00042 #ifdef HAVE_OPENGL
00043       try {
00044         log_info << "new GL renderer\n";
00045         return new GLRenderer();
00046       } catch(std::runtime_error& e) {
00047         log_warning << "Error creating GL renderer: "  << e.what() << std::endl;
00048 #endif
00049         log_warning << "new SDL renderer\n";
00050         return new SDLRenderer();
00051 #ifdef HAVE_OPENGL
00052       }
00053     case OPENGL:
00054       log_info << "new GL renderer\n";
00055       return new GLRenderer();
00056 #endif
00057     case PURE_SDL:
00058       log_info << "new SDL renderer\n";
00059       return new SDLRenderer();
00060     default:
00061       assert(0 && "invalid video system in config");
00062 #ifdef HAVE_OPENGL
00063       log_info << "new GL renderer\n";
00064       return new GLRenderer();
00065 #else
00066       log_warning << "new SDL renderer\n";
00067       return new SDLRenderer();
00068 #endif
00069   }
00070 }
00071 
00072 Lightmap*
00073 VideoSystem::new_lightmap()
00074 {
00075   switch(g_config->video)
00076   {
00077     case AUTO_VIDEO:
00078 #ifdef HAVE_OPENGL
00079       return new GLLightmap();
00080 #else
00081       return new SDLLightmap();
00082 #endif
00083 #ifdef HAVE_OPENGL
00084     case OPENGL:
00085       return new GLLightmap();
00086 #endif
00087     case PURE_SDL:
00088       return new SDLLightmap();
00089     default:
00090       assert(0 && "invalid video system in config");
00091 #ifdef HAVE_OPENGL
00092       return new GLLightmap();
00093 #else
00094       return new SDLLightmap();
00095 #endif
00096   }
00097 }
00098 
00099 TexturePtr
00100 VideoSystem::new_texture(SDL_Surface *image)
00101 {
00102   switch(g_config->video)
00103   {
00104     case AUTO_VIDEO:
00105 #ifdef HAVE_OPENGL
00106       return TexturePtr(new GLTexture(image));
00107 #else
00108       return TexturePtr(new SDLTexture(image));
00109 #endif
00110 #ifdef HAVE_OPENGL
00111     case OPENGL:
00112       return TexturePtr(new GLTexture(image));
00113 #endif
00114     case PURE_SDL:
00115       return TexturePtr(new SDLTexture(image));
00116     default:
00117       assert(0 && "invalid video system in config");
00118 #ifdef HAVE_OPENGL
00119       return TexturePtr(new GLTexture(image));
00120 #else
00121       return TexturePtr(new SDLTexture(image));
00122 #endif
00123   }
00124 }
00125 
00126 SurfaceData*
00127 VideoSystem::new_surface_data(const Surface &surface)
00128 {
00129   switch(g_config->video)
00130   {
00131     case AUTO_VIDEO:
00132 #ifdef HAVE_OPENGL
00133       return new GLSurfaceData(surface);
00134 #else
00135       return new SDLSurfaceData(surface);
00136 #endif
00137 #ifdef HAVE_OPENGL
00138     case OPENGL:
00139       return new GLSurfaceData(surface);
00140 #endif
00141     case PURE_SDL:
00142       return new SDLSurfaceData(surface);
00143     default:
00144       assert(0 && "invalid video system in config");
00145 #ifdef HAVE_OPENGL
00146       return new GLSurfaceData(surface);
00147 #else
00148       return new SDLSurfaceData(surface);
00149 #endif
00150   }
00151 }
00152 
00153 void
00154 VideoSystem::free_surface_data(SurfaceData* surface_data)
00155 {
00156   delete surface_data;
00157 }
00158 
00159 VideoSystem::Enum
00160 VideoSystem::get_video_system(const std::string &video)
00161 {
00162   if(video == "auto")
00163   {
00164     return AUTO_VIDEO;
00165   }
00166 #ifdef HAVE_OPENGL
00167   else if(video == "opengl")
00168   {
00169     return OPENGL;
00170   }
00171 #endif
00172   else if(video == "sdl")
00173   {
00174     return PURE_SDL;
00175   }
00176   else
00177   {
00178     return AUTO_VIDEO;
00179   }
00180 }
00181 
00182 std::string
00183 VideoSystem::get_video_string(VideoSystem::Enum video)
00184 {
00185   switch(video)
00186   {
00187     case AUTO_VIDEO:
00188       return "auto";
00189     case OPENGL:
00190       return "opengl";
00191     case PURE_SDL:
00192       return "sdl";
00193     default:
00194       assert(0 && "invalid video system in config");
00195       return "auto";
00196   }
00197 }
00198 
00199 /* EOF */

Generated on Mon Apr 14 03:38:28 2014 for SuperTux by  doxygen 1.5.1