#include "video/drawing_context.hpp"
#include "video/font.hpp"
#include "video/renderer.hpp"
+#include "video/video_system.hpp"
static const float MENU_REPEAT_INITIAL = 0.4f;
static const float MENU_REPEAT_RATE = 0.1f;
case SDL_MOUSEBUTTONDOWN:
if(ev.button.button == SDL_BUTTON_LEFT)
{
- Vector mouse_pos = Renderer::instance()->to_logical(ev.motion.x, ev.motion.y);
+ Vector mouse_pos = VideoSystem::current()->get_renderer().to_logical(ev.motion.x, ev.motion.y);
int x = int(mouse_pos.x);
int y = int(mouse_pos.y);
case SDL_MOUSEMOTION:
{
- Vector mouse_pos = Renderer::instance()->to_logical(ev.motion.x, ev.motion.y);
+ Vector mouse_pos = VideoSystem::current()->get_renderer().to_logical(ev.motion.x, ev.motion.y);
float x = mouse_pos.x;
float y = mouse_pos.y;
#include "supertux/globals.hpp"
#include "video/drawing_context.hpp"
#include "video/renderer.hpp"
-#include "video/sdl/sdl_renderer.hpp"
+#include "video/video_system.hpp"
MouseCursor* MouseCursor::current_ = 0;
int y;
Uint8 ispressed = SDL_GetMouseState(&x, &y);
- Vector mouse_pos = Renderer::instance()->to_logical(x, y);
+ Vector mouse_pos = VideoSystem::current()->get_renderer().to_logical(x, y);
x = int(mouse_pos.x);
y = int(mouse_pos.y);
InfoBlock::collision(GameObject& other, const CollisionHit& hit_)
{
Player* player = dynamic_cast<Player*> (&other);
- if (player)
+ if (player)
{
if (player->does_buttjump)
InfoBlock::hit(*player);
#include "supertux/world.hpp"
#include "util/gettext.hpp"
#include "video/renderer.hpp"
+#include "video/video_system.hpp"
#include "worldmap/tux.hpp"
#include "worldmap/worldmap.hpp"
void set_gamma(float gamma)
{
- Renderer::instance()->set_gamma(gamma);
+ VideoSystem::current()->get_renderer().set_gamma(gamma);
}
void quit()
#include "math/size.hpp"
#include "util/log.hpp"
-#include "video/video_systems.hpp"
+#include "video/video_system.hpp"
class Config;
#ifndef HEADER_SUPERTUX_SUPERTUX_GAMECONFIG_HPP
#define HEADER_SUPERTUX_SUPERTUX_GAMECONFIG_HPP
-#include "video/video_systems.hpp"
+#include "video/video_system.hpp"
#include "math/size.hpp"
class Config
void
Main::init_video()
{
- SDL_SetWindowTitle(Renderer::instance()->get_window(), PACKAGE_NAME " " PACKAGE_VERSION);
+ SDL_SetWindowTitle(VideoSystem::current()->get_renderer().get_window(), PACKAGE_NAME " " PACKAGE_VERSION);
const char* icon_fname = "images/engine/icons/supertux-256x256.png";
SDL_Surface* icon = IMG_Load_RW(get_physfs_SDLRWops(icon_fname), true);
}
else
{
- SDL_SetWindowIcon(Renderer::instance()->get_window(), icon);
+ SDL_SetWindowIcon(VideoSystem::current()->get_renderer().get_window(), icon);
SDL_FreeSurface(icon);
}
SDL_ShowCursor(0);
timelog("commandline");
timelog("video");
- std::unique_ptr<Renderer> renderer(VideoSystem::new_renderer());
- std::unique_ptr<Lightmap> lightmap(VideoSystem::new_lightmap());
- DrawingContext context(*renderer, *lightmap);
+ std::unique_ptr<VideoSystem> video_system = VideoSystem::create(g_config->video);
+ DrawingContext context(video_system->get_renderer(),
+ video_system->get_lightmap());
context_pointer = &context;
init_video();
if (item->list[item->selected] == _("auto"))
{
g_config->aspect_size = Size(0, 0); // Magic values
- Renderer::instance()->apply_config();
+ VideoSystem::current()->get_renderer().apply_config();
MenuManager::instance().on_window_resize();
}
else if (sscanf(item->list[item->selected].c_str(), "%d:%d",
&g_config->aspect_size.width, &g_config->aspect_size.height) == 2)
{
- Renderer::instance()->apply_config();
+ VideoSystem::current()->get_renderer().apply_config();
MenuManager::instance().on_window_resize();
}
else
{
g_config->magnification /= 100.0f;
}
- Renderer::instance()->apply_config();
+ VideoSystem::current()->get_renderer().apply_config();
MenuManager::instance().on_window_resize();
break;
case MNID_FULLSCREEN:
if(g_config->use_fullscreen != is_toggled(MNID_FULLSCREEN)) {
g_config->use_fullscreen = !g_config->use_fullscreen;
- Renderer::instance()->apply_config();
+ VideoSystem::current()->get_renderer().apply_config();
MenuManager::instance().on_window_resize();
g_config->save();
}
switch(event.window.event)
{
case SDL_WINDOWEVENT_RESIZED:
- Renderer::instance()->resize(event.window.data1,
- event.window.data2);
+ VideoSystem::current()->get_renderer().resize(event.window.data1,
+ event.window.data2);
m_menu_manager->on_window_resize();
break;
}
else if (event.key.keysym.sym == SDLK_F11)
{
g_config->use_fullscreen = !g_config->use_fullscreen;
- Renderer::instance()->apply_config();
+ VideoSystem::current()->get_renderer().apply_config();
m_menu_manager->on_window_resize();
}
else if (event.key.keysym.sym == SDLK_PRINTSCREEN ||
#include "video/surface.hpp"
#include "video/texture.hpp"
#include "video/texture_manager.hpp"
-#include "video/video_systems.hpp"
+#include "video/video_system.hpp"
DrawingContext::DrawingContext(Renderer& renderer_, Lightmap& lightmap_) :
renderer(renderer_),
m_desktop_size(0, 0),
m_fullscreen_active(false)
{
- Renderer::instance_ = this;
-
SDL_DisplayMode mode;
SDL_GetCurrentDisplayMode(0, &mode);
m_desktop_size = Size(mode.w, mode.h);
try {
glBindTexture(GL_TEXTURE_2D, m_handle);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
- m_texture_width, m_texture_height,
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
+ m_texture_width, m_texture_height,
0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
set_texture_params();
SDL_LockSurface(convert);
}
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
m_texture_width, m_texture_height, 0, sdl_format,
GL_UNSIGNED_BYTE, convert->pixels);
--- /dev/null
+// SuperTux
+// Copyright (C) 2014 Ingo Ruhnke <grumbel@gmail.com>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include "video/gl/gl_video_system.hpp"
+
+#include "video/gl/gl_lightmap.hpp"
+#include "video/gl/gl_renderer.hpp"
+#include "video/gl/gl_surface_data.hpp"
+#include "video/gl/gl_texture.hpp"
+
+GLVideoSystem::GLVideoSystem() :
+ m_renderer(new GLRenderer),
+ m_lightmap(new GLLightmap)
+{
+}
+
+Renderer&
+GLVideoSystem::get_renderer()
+{
+ return *m_renderer;
+}
+
+Lightmap&
+GLVideoSystem::get_lightmap()
+{
+ return *m_lightmap;
+}
+
+TexturePtr
+GLVideoSystem::new_texture(SDL_Surface* image)
+{
+ return TexturePtr(new GLTexture(image));
+}
+
+SurfaceData*
+GLVideoSystem::new_surface_data(const Surface& surface)
+{
+ return new GLSurfaceData(surface);
+}
+
+void
+GLVideoSystem::free_surface_data(SurfaceData* surface_data)
+{
+ delete surface_data;
+}
+
+/* EOF */
--- /dev/null
+// SuperTux
+// Copyright (C) 2014 Ingo Ruhnke <grumbel@gmail.com>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef HEADER_SUPERTUX_VIDEO_GL_GL_VIDEO_SYSTEM_HPP
+#define HEADER_SUPERTUX_VIDEO_GL_GL_VIDEO_SYSTEM_HPP
+
+#include <memory>
+#include <SDL.h>
+
+#include "video/video_system.hpp"
+
+class GLVideoSystem : public VideoSystem
+{
+private:
+ std::unique_ptr<Renderer> m_renderer;
+ std::unique_ptr<Lightmap> m_lightmap;
+
+public:
+ GLVideoSystem();
+
+ Renderer& get_renderer() override;
+ Lightmap& get_lightmap() override;
+ TexturePtr new_texture(SDL_Surface* image) override;
+ SurfaceData* new_surface_data(const Surface& surface) override;
+ void free_surface_data(SurfaceData* surface_data) override;
+
+private:
+ GLVideoSystem(const GLVideoSystem&) = delete;
+ GLVideoSystem& operator=(const GLVideoSystem&) = delete;
+};
+
+#endif
+
+/* EOF */
#include "video/renderer.hpp"
-Renderer* Renderer::instance_ = 0;
-
Renderer::Renderer()
{
}
virtual Vector to_logical(int physical_x, int physical_y) = 0;
virtual void set_gamma(float gamma) = 0;
virtual SDL_Window* get_window() const = 0;
-
- static Renderer* instance() { assert(instance_); return instance_; }
-
-protected:
- static Renderer* instance_;
};
#endif
#include "video/sdl/sdl_painter.hpp"
SDLLightmap::SDLLightmap() :
- m_renderer(static_cast<SDLRenderer*>(Renderer::instance())->get_sdl_renderer()),
+ m_renderer(static_cast<SDLRenderer&>(VideoSystem::current()->get_renderer()).get_sdl_renderer()),
m_texture(),
m_width(),
m_height(),
m_desktop_size(0, 0),
m_scale(1.0f, 1.0f)
{
- Renderer::instance_ = this;
-
SDL_DisplayMode mode;
if (SDL_GetDesktopDisplayMode(0, &mode) != 0)
{
m_width(),
m_height()
{
- m_texture = SDL_CreateTextureFromSurface(static_cast<SDLRenderer*>(Renderer::instance())->get_sdl_renderer(),
+ m_texture = SDL_CreateTextureFromSurface(static_cast<SDLRenderer&>(VideoSystem::current()->get_renderer()).get_sdl_renderer(),
image);
if (!m_texture)
{
--- /dev/null
+// SuperTux
+// Copyright (C) 2014 Ingo Ruhnke <grumbel@gmail.com>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include "video/sdl/sdl_video_system.hpp"
+
+#include "supertux/gameconfig.hpp"
+#include "video/lightmap.hpp"
+#include "video/renderer.hpp"
+#include "video/sdl/sdl_lightmap.hpp"
+#include "video/sdl/sdl_renderer.hpp"
+#include "video/sdl/sdl_surface_data.hpp"
+#include "video/sdl/sdl_texture.hpp"
+#include "video/texture.hpp"
+#include "video/video_system.hpp"
+
+SDLVideoSystem::SDLVideoSystem() :
+ m_renderer(new SDLRenderer),
+ m_lightmap(new SDLLightmap)
+{
+}
+
+Renderer&
+SDLVideoSystem::get_renderer()
+{
+ return *m_renderer;
+}
+
+Lightmap&
+SDLVideoSystem::get_lightmap()
+{
+ return *m_lightmap;
+}
+
+TexturePtr
+SDLVideoSystem::new_texture(SDL_Surface* image)
+{
+ return TexturePtr(new SDLTexture(image));
+}
+
+SurfaceData*
+SDLVideoSystem::new_surface_data(const Surface& surface)
+{
+ return new SDLSurfaceData(surface);
+}
+
+void
+SDLVideoSystem::free_surface_data(SurfaceData* surface_data)
+{
+ delete surface_data;
+}
+
+/* EOF */
--- /dev/null
+// SuperTux
+// Copyright (C) 2014 Ingo Ruhnke <grumbel@gmail.com>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef HEADER_SUPERTUX_VIDEO_SDL_SDL_VIDEO_SYSTEM_HPP
+#define HEADER_SUPERTUX_VIDEO_SDL_SDL_VIDEO_SYSTEM_HPP
+
+#include <memory>
+#include <SDL.h>
+
+#include "video/video_system.hpp"
+
+class SDLVideoSystem : public VideoSystem
+{
+private:
+ std::unique_ptr<Renderer> m_renderer;
+ std::unique_ptr<Lightmap> m_lightmap;
+
+public:
+ SDLVideoSystem();
+
+ Renderer& get_renderer();
+ Lightmap& get_lightmap();
+ TexturePtr new_texture(SDL_Surface *image) override;
+ SurfaceData* new_surface_data(const Surface& surface) override;
+ void free_surface_data(SurfaceData* surface_data) override;
+
+private:
+ SDLVideoSystem(const SDLVideoSystem&) = delete;
+ SDLVideoSystem& operator=(const SDLVideoSystem&) = delete;
+};
+
+#endif
+
+/* EOF */
#include <SDL.h>
#include "video/texture.hpp"
-#include "video/video_systems.hpp"
+#include "video/video_system.hpp"
SurfacePtr
Surface::create(const std::string& file)
texture->get_image_height())),
flipx(false)
{
- surface_data = VideoSystem::new_surface_data(*this);
+ surface_data = VideoSystem::current()->new_surface_data(*this);
}
Surface::Surface(const std::string& file, const Rect& rect_) :
rect(0, 0, Size(rect_.get_width(), rect_.get_height())),
flipx(false)
{
- surface_data = VideoSystem::new_surface_data(*this);
+ surface_data = VideoSystem::current()->new_surface_data(*this);
}
Surface::Surface(const Surface& rhs) :
rect(rhs.rect),
flipx(false)
{
- surface_data = VideoSystem::new_surface_data(*this);
+ surface_data = VideoSystem::current()->new_surface_data(*this);
}
Surface::~Surface()
{
- VideoSystem::free_surface_data(surface_data);
+ VideoSystem::current()->free_surface_data(surface_data);
}
SurfacePtr
#include "util/log.hpp"
#include "video/sdl_surface_ptr.hpp"
#include "video/texture.hpp"
-#include "video/video_systems.hpp"
+#include "video/video_system.hpp"
#ifdef HAVE_OPENGL
#include "video/gl/gl_texture.hpp"
}
#endif
- return VideoSystem::new_texture(subimage.get());
+ return VideoSystem::current()->new_texture(subimage.get());
}
TexturePtr
}
else
{
- TexturePtr texture = VideoSystem::new_texture(image.get());
+ TexturePtr texture = VideoSystem::current()->new_texture(image.get());
image.reset(NULL);
return texture;
}
else
{
log_warning << "Couldn't load texture '" << dummy_texture_fname << "' (now using empty one): " << err.what() << std::endl;
- TexturePtr texture = VideoSystem::new_texture(image.get());
+ TexturePtr texture = VideoSystem::current()->new_texture(image.get());
image.reset(NULL);
return texture;
}
--- /dev/null
+// SuperTux
+// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include "video/video_system.hpp"
+
+#include <config.h>
+
+#include "util/log.hpp"
+#include "video/sdl/sdl_video_system.hpp"
+
+#ifdef HAVE_OPENGL
+#include "video/gl/gl_video_system.hpp"
+#endif
+
+std::unique_ptr<VideoSystem>
+VideoSystem::create(VideoSystem::Enum video_system)
+{
+ switch(video_system)
+ {
+ case AUTO_VIDEO:
+#ifdef HAVE_OPENGL
+ try
+ {
+ return std::unique_ptr<VideoSystem>(new GLVideoSystem);
+ }
+ catch(std::exception& err)
+ {
+ log_warning << "Error creating GLVideoSystem, using SDL fallback: " << err.what() << std::endl;
+ return std::unique_ptr<VideoSystem>(new SDLVideoSystem);
+ }
+#else
+ log_info << "new SDL renderer\n";
+ return std::unique_ptr<VideoSystem>(new SDLVideoSystem);
+#endif
+
+ case OPENGL:
+#ifdef HAVE_OPENGL
+ return std::unique_ptr<VideoSystem>(new GLVideoSystem);
+#else
+ log_warning << "OpenGL requested, but missing using SDL fallback" << std::endl;
+ return std::unique_ptr<VideoSystem>(new SDLVideoSystem);
+#endif
+
+ case PURE_SDL:
+ log_info << "new SDL renderer\n";
+ return std::unique_ptr<VideoSystem>(new SDLVideoSystem);
+
+ default:
+ assert(!"invalid video system in config");
+ break;
+ }
+}
+
+VideoSystem::Enum
+VideoSystem::get_video_system(const std::string &video)
+{
+ if(video == "auto")
+ {
+ return AUTO_VIDEO;
+ }
+#ifdef HAVE_OPENGL
+ else if(video == "opengl")
+ {
+ return OPENGL;
+ }
+#endif
+ else if(video == "sdl")
+ {
+ return PURE_SDL;
+ }
+ else
+ {
+ return AUTO_VIDEO;
+ }
+}
+
+std::string
+VideoSystem::get_video_string(VideoSystem::Enum video)
+{
+ switch(video)
+ {
+ case AUTO_VIDEO:
+ return "auto";
+ case OPENGL:
+ return "opengl";
+ case PURE_SDL:
+ return "sdl";
+ default:
+ assert(!"invalid video system in config");
+ return "auto";
+ }
+}
+
+/* EOF */
--- /dev/null
+// SuperTux
+// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef HEADER_SUPERTUX_VIDEO_VIDEO_SYSTEM_HPP
+#define HEADER_SUPERTUX_VIDEO_VIDEO_SYSTEM_HPP
+
+#include <SDL.h>
+#include <string>
+
+#include "util/currenton.hpp"
+#include "video/texture_ptr.hpp"
+
+class Renderer;
+class Lightmap;
+class Surface;
+class SurfaceData;
+
+class VideoSystem : public Currenton<VideoSystem>
+{
+public:
+ enum Enum {
+ AUTO_VIDEO,
+ OPENGL,
+ PURE_SDL,
+ NUM_SYSTEMS
+ };
+
+ static std::unique_ptr<VideoSystem> create(VideoSystem::Enum video_system);
+
+ static Enum get_video_system(const std::string &video);
+ static std::string get_video_string(Enum video);
+
+public:
+ VideoSystem() {}
+ virtual ~VideoSystem() {}
+
+ virtual Renderer& get_renderer() = 0;
+ virtual Lightmap& get_lightmap() = 0;
+ virtual TexturePtr new_texture(SDL_Surface *image) = 0;
+ virtual SurfaceData* new_surface_data(const Surface &surface) = 0;
+ virtual void free_surface_data(SurfaceData* surface_data) = 0;
+
+private:
+ VideoSystem(const VideoSystem&) = delete;
+ VideoSystem& operator=(const VideoSystem&) = delete;
+};
+
+#endif
+
+/* EOF */
+++ /dev/null
-// SuperTux
-// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-#include <config.h>
-
-#include "supertux/gameconfig.hpp"
-#include "video/lightmap.hpp"
-#include "video/renderer.hpp"
-#include "video/sdl/sdl_lightmap.hpp"
-#include "video/sdl/sdl_renderer.hpp"
-#include "video/sdl/sdl_surface_data.hpp"
-#include "video/sdl/sdl_texture.hpp"
-#include "video/texture.hpp"
-#include "video/video_systems.hpp"
-
-#ifdef HAVE_OPENGL
-#include "video/gl/gl_lightmap.hpp"
-#include "video/gl/gl_renderer.hpp"
-#include "video/gl/gl_surface_data.hpp"
-#include "video/gl/gl_texture.hpp"
-#endif
-
-std::unique_ptr<Renderer>
-VideoSystem::new_renderer()
-{
- switch(g_config->video)
- {
- case AUTO_VIDEO:
-#ifdef HAVE_OPENGL
- try {
- log_info << "new GL renderer\n";
- return std::unique_ptr<Renderer>(new GLRenderer());
- } catch(std::runtime_error& e) {
- log_warning << "Error creating GL renderer: " << e.what() << std::endl;
-#endif
- log_warning << "new SDL renderer\n";
- return std::unique_ptr<Renderer>(new SDLRenderer());
-#ifdef HAVE_OPENGL
- }
- case OPENGL:
- log_info << "new GL renderer\n";
- return std::unique_ptr<Renderer>(new GLRenderer());
-#endif
- case PURE_SDL:
- log_info << "new SDL renderer\n";
- return std::unique_ptr<Renderer>(new SDLRenderer());
- default:
- assert(0 && "invalid video system in config");
-#ifdef HAVE_OPENGL
- log_info << "new GL renderer\n";
- return std::unique_ptr<Renderer>(new GLRenderer());
-#else
- log_warning << "new SDL renderer\n";
- return std::unique_ptr<Renderer>(new SDLRenderer());
-#endif
- }
-}
-
-std::unique_ptr<Lightmap>
-VideoSystem::new_lightmap()
-{
- switch(g_config->video)
- {
- case AUTO_VIDEO:
-#ifdef HAVE_OPENGL
- return std::unique_ptr<Lightmap>(new GLLightmap());
-#else
- return std::unique_ptr<Lightmap>(new SDLLightmap());
-#endif
-#ifdef HAVE_OPENGL
- case OPENGL:
- return std::unique_ptr<Lightmap>(new GLLightmap());
-#endif
- case PURE_SDL:
- return std::unique_ptr<Lightmap>(new SDLLightmap());
- default:
- assert(0 && "invalid video system in config");
-#ifdef HAVE_OPENGL
- return std::unique_ptr<Lightmap>(new GLLightmap());
-#else
- return std::unique_ptr<Lightmap>(new SDLLightmap());
-#endif
- }
-}
-
-TexturePtr
-VideoSystem::new_texture(SDL_Surface *image)
-{
- switch(g_config->video)
- {
- case AUTO_VIDEO:
-#ifdef HAVE_OPENGL
- return TexturePtr(new GLTexture(image));
-#else
- return TexturePtr(new SDLTexture(image));
-#endif
-#ifdef HAVE_OPENGL
- case OPENGL:
- return TexturePtr(new GLTexture(image));
-#endif
- case PURE_SDL:
- return TexturePtr(new SDLTexture(image));
- default:
- assert(0 && "invalid video system in config");
-#ifdef HAVE_OPENGL
- return TexturePtr(new GLTexture(image));
-#else
- return TexturePtr(new SDLTexture(image));
-#endif
- }
-}
-
-SurfaceData*
-VideoSystem::new_surface_data(const Surface &surface)
-{
- switch(g_config->video)
- {
- case AUTO_VIDEO:
-#ifdef HAVE_OPENGL
- return new GLSurfaceData(surface);
-#else
- return new SDLSurfaceData(surface);
-#endif
-#ifdef HAVE_OPENGL
- case OPENGL:
- return new GLSurfaceData(surface);
-#endif
- case PURE_SDL:
- return new SDLSurfaceData(surface);
- default:
- assert(0 && "invalid video system in config");
-#ifdef HAVE_OPENGL
- return new GLSurfaceData(surface);
-#else
- return new SDLSurfaceData(surface);
-#endif
- }
-}
-
-void
-VideoSystem::free_surface_data(SurfaceData* surface_data)
-{
- if(surface_data == NULL)
- return;
-
- delete surface_data;
-}
-
-VideoSystem::Enum
-VideoSystem::get_video_system(const std::string &video)
-{
- if(video == "auto")
- {
- return AUTO_VIDEO;
- }
-#ifdef HAVE_OPENGL
- else if(video == "opengl")
- {
- return OPENGL;
- }
-#endif
- else if(video == "sdl")
- {
- return PURE_SDL;
- }
- else
- {
- return AUTO_VIDEO;
- }
-}
-
-std::string
-VideoSystem::get_video_string(VideoSystem::Enum video)
-{
- switch(video)
- {
- case AUTO_VIDEO:
- return "auto";
- case OPENGL:
- return "opengl";
- case PURE_SDL:
- return "sdl";
- default:
- assert(0 && "invalid video system in config");
- return "auto";
- }
-}
-
-/* EOF */
+++ /dev/null
-// SuperTux
-// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-#ifndef HEADER_SUPERTUX_VIDEO_VIDEO_SYSTEMS_HPP
-#define HEADER_SUPERTUX_VIDEO_VIDEO_SYSTEMS_HPP
-
-#include <config.h>
-
-#include <SDL.h>
-#include <string>
-
-#include "video/texture_ptr.hpp"
-
-class Renderer;
-class Lightmap;
-class Surface;
-class SurfaceData;
-
-class VideoSystem
-{
-public:
- enum Enum {
- AUTO_VIDEO,
- OPENGL,
- PURE_SDL,
- NUM_SYSTEMS
- };
-
-public:
- static std::unique_ptr<Renderer> new_renderer();
- static std::unique_ptr<Lightmap> new_lightmap();
- static TexturePtr new_texture(SDL_Surface *image);
- static SurfaceData* new_surface_data(const Surface &surface);
- static void free_surface_data(SurfaceData* surface_data);
-
- static Enum get_video_system(const std::string &video);
- static std::string get_video_string(Enum video);
-
-private:
- VideoSystem();
- VideoSystem(const VideoSystem&);
- VideoSystem& operator=(const VideoSystem&);
-};
-
-#endif
-
-/* EOF */