Fixed resize handling of lightmaps, they are now recreated on resize()
authorIngo Ruhnke <grumbel@gmail.com>
Fri, 29 Aug 2014 06:28:38 +0000 (08:28 +0200)
committerIngo Ruhnke <grumbel@gmail.com>
Fri, 29 Aug 2014 06:28:38 +0000 (08:28 +0200)
13 files changed:
src/supertux/main.cpp
src/supertux/screen_manager.cpp
src/video/drawing_context.cpp
src/video/drawing_context.hpp
src/video/gl/gl_lightmap.hpp
src/video/gl/gl_video_system.cpp
src/video/gl/gl_video_system.hpp
src/video/lightmap.hpp
src/video/sdl/sdl_lightmap.cpp
src/video/sdl/sdl_lightmap.hpp
src/video/sdl/sdl_video_system.cpp
src/video/sdl/sdl_video_system.hpp
src/video/video_system.hpp

index 6dc7c37..1cfba9c 100644 (file)
@@ -306,8 +306,7 @@ Main::launch_game()
 
   timelog("video");
   std::unique_ptr<VideoSystem> video_system = VideoSystem::create(g_config->video);
-  DrawingContext context(video_system->get_renderer(),
-                         video_system->get_lightmap());
+  DrawingContext context(*video_system);
   init_video();
 
   timelog("audio");
index a2d2beb..580d875 100644 (file)
@@ -209,8 +209,8 @@ ScreenManager::process_events()
         switch(event.window.event)
         {
           case SDL_WINDOWEVENT_RESIZED:
-            VideoSystem::current()->get_renderer().resize(event.window.data1,
-                                                          event.window.data2);
+            VideoSystem::current()->resize(event.window.data1,
+                                           event.window.data2);
             m_menu_manager->on_window_resize();
             break;
         }
@@ -224,7 +224,7 @@ ScreenManager::process_events()
         else if (event.key.keysym.sym == SDLK_F11)
         {
           g_config->use_fullscreen = !g_config->use_fullscreen;
-          VideoSystem::current()->get_renderer().apply_config();
+          VideoSystem::current()->apply_config();
           m_menu_manager->on_window_resize();
         }
         else if (event.key.keysym.sym == SDLK_PRINTSCREEN ||
index e093e5b..f600246 100644 (file)
@@ -31,9 +31,8 @@
 #include "video/texture_manager.hpp"
 #include "video/video_system.hpp"
 
-DrawingContext::DrawingContext(Renderer& renderer_, Lightmap& lightmap_) :
-  renderer(renderer_),
-  lightmap(lightmap_),
+DrawingContext::DrawingContext(VideoSystem& video_system_) :
+  video_system(video_system_),
   transformstack(),
   transform(),
   blend_stack(),
@@ -318,6 +317,8 @@ DrawingContext::do_drawing()
 
   // PART1: create lightmap
   if(use_lightmap) {
+    Lightmap& lightmap = video_system.get_lightmap();
+
     lightmap.start_draw(ambient_color);
     handle_drawing_requests(lightmap_requests);
     lightmap.end_draw();
@@ -328,6 +329,8 @@ DrawingContext::do_drawing()
     request->layer = LAYER_HUD - 1;
     drawing_requests.push_back(request);
   }
+
+  Renderer& renderer = video_system.get_renderer();
   renderer.start_draw();
   handle_drawing_requests(drawing_requests);
   renderer.end_draw();
@@ -361,6 +364,9 @@ DrawingContext::handle_drawing_requests(DrawingRequests& requests_)
 {
   std::stable_sort(requests_.begin(), requests_.end(), RequestPtrCompare());
 
+  Renderer& renderer = video_system.get_renderer();
+  Lightmap& lightmap = video_system.get_lightmap();
+
   DrawingRequests::const_iterator i;
   for(i = requests_.begin(); i != requests_.end(); ++i) {
     const DrawingRequest& request = **i;
index cc2bc01..ef55b8f 100644 (file)
 #include "video/texture.hpp"
 
 class DrawingRequest;
-class Lightmap;
-class Renderer;
 class Surface;
 class Texture;
+class VideoSystem;
 
 // some constants for predefined layer values
 enum {
@@ -88,7 +87,7 @@ enum Target {
 class DrawingContext
 {
 public:
-  DrawingContext(Renderer& renderer, Lightmap& lightmap);
+  DrawingContext(VideoSystem& video_system);
   ~DrawingContext();
 
   /// Adds a drawing request for a surface into the request list.
@@ -191,8 +190,7 @@ private:
   void clear_drawing_requests(DrawingRequests& requests);
 
 private:
-  Renderer& renderer;
-  Lightmap& lightmap;
+  VideoSystem& video_system;
 
   /// the transform stack
   std::vector<Transform> transformstack;
index 5c4ad5d..9225cd7 100644 (file)
@@ -29,15 +29,15 @@ public:
   GLLightmap();
   ~GLLightmap();
 
-  void start_draw(const Color &ambient_color);
-  void end_draw();
-  void do_draw();
-  void draw_surface(const DrawingRequest& request);
-  void draw_surface_part(const DrawingRequest& request);
-  void draw_gradient(const DrawingRequest& request);
-  void draw_filled_rect(const DrawingRequest& request);
-  void draw_inverse_ellipse(const DrawingRequest& request);
-  void get_light(const DrawingRequest& request) const;
+  void start_draw(const Color &ambient_color) override;
+  void end_draw() override;
+  void do_draw() override;
+  void draw_surface(const DrawingRequest& request) override;
+  void draw_surface_part(const DrawingRequest& request) override;
+  void draw_gradient(const DrawingRequest& request) override;
+  void draw_filled_rect(const DrawingRequest& request) override;
+  void draw_inverse_ellipse(const DrawingRequest& request) override;
+  void get_light(const DrawingRequest& request) const override;
 
 private:
   static const int s_LIGHTMAP_DIV = 5;
index dde614d..87b0ab7 100644 (file)
@@ -59,4 +59,17 @@ GLVideoSystem::free_surface_data(SurfaceData* surface_data)
   delete surface_data;
 }
 
+void
+GLVideoSystem::apply_config()
+{
+  m_renderer->apply_config();
+}
+
+void
+GLVideoSystem::resize(int w, int h)
+{
+  m_renderer->resize(w, h);
+  m_lightmap.reset(new GLLightmap);
+}
+
 /* EOF */
index 6928f71..488d880 100644 (file)
@@ -40,6 +40,9 @@ public:
   SurfaceData* new_surface_data(const Surface& surface) override;
   void free_surface_data(SurfaceData* surface_data) override;
 
+  void apply_config() override;
+  void resize(int w, int h) override;
+
 private:
   GLVideoSystem(const GLVideoSystem&) = delete;
   GLVideoSystem& operator=(const GLVideoSystem&) = delete;
index 905a237..544e81b 100644 (file)
@@ -47,6 +47,7 @@ public:
   virtual void draw_surface_part(const DrawingRequest& request) = 0;
   virtual void draw_gradient(const DrawingRequest& request) = 0;
   virtual void draw_filled_rect(const DrawingRequest& request) = 0;
+  virtual void draw_inverse_ellipse(const DrawingRequest& request) = 0;
   virtual void get_light(const DrawingRequest& request) const = 0;
 };
 
index 1d7f6c4..4f91e68 100644 (file)
@@ -112,6 +112,12 @@ SDLLightmap::draw_filled_rect(const DrawingRequest& request)
 }
 
 void
+SDLLightmap::draw_inverse_ellipse(const DrawingRequest& request)
+{
+  SDLPainter::draw_inverse_ellipse(m_renderer, request);
+}
+
+void
 SDLLightmap::get_light(const DrawingRequest& request) const
 {
   const GetLightRequest* getlightrequest
index e13b61c..1247a64 100644 (file)
@@ -30,16 +30,15 @@ public:
   SDLLightmap();
   ~SDLLightmap();
 
-  void start_draw(const Color &ambient_color);
-  void end_draw();
-  void do_draw();
-
-  void draw_surface(const DrawingRequest& request);
-  void draw_surface_part(const DrawingRequest& request);
-  void draw_gradient(const DrawingRequest& request);
-  void draw_filled_rect(const DrawingRequest& request);
-
-  void get_light(const DrawingRequest& request) const;
+  void start_draw(const Color &ambient_color) override;
+  void end_draw() override;
+  void do_draw() override;
+  void draw_surface(const DrawingRequest& request) override;
+  void draw_surface_part(const DrawingRequest& request) override;
+  void draw_gradient(const DrawingRequest& request) override;
+  void draw_filled_rect(const DrawingRequest& request) override;
+  void draw_inverse_ellipse(const DrawingRequest& request) override;
+  void get_light(const DrawingRequest& request) const override;
 
 private:
   SDL_Renderer* m_renderer;
index 4bb6cef..6251fba 100644 (file)
@@ -63,4 +63,17 @@ SDLVideoSystem::free_surface_data(SurfaceData* surface_data)
   delete surface_data;
 }
 
+void
+SDLVideoSystem::apply_config()
+{
+  m_renderer->apply_config();
+}
+
+void
+SDLVideoSystem::resize(int w, int h)
+{
+  m_renderer->resize(w, h);
+  m_lightmap.reset(new SDLLightmap);
+}
+
 /* EOF */
index ecd2297..bc2d306 100644 (file)
@@ -40,6 +40,9 @@ public:
   SurfaceData* new_surface_data(const Surface& surface) override;
   void free_surface_data(SurfaceData* surface_data) override;
 
+  void apply_config() override;
+  void resize(int w, int h) override;
+
 private:
   SDLVideoSystem(const SDLVideoSystem&) = delete;
   SDLVideoSystem& operator=(const SDLVideoSystem&) = delete;
index 3ad7559..729f6ef 100644 (file)
@@ -53,6 +53,9 @@ public:
   virtual SurfaceData* new_surface_data(const Surface &surface) = 0;
   virtual void free_surface_data(SurfaceData* surface_data) = 0;
 
+  virtual void apply_config() = 0;
+  virtual void resize(int w, int h) = 0;
+
 private:
   VideoSystem(const VideoSystem&) = delete;
   VideoSystem& operator=(const VideoSystem&) = delete;