From: Ingo Ruhnke Date: Fri, 29 Aug 2014 06:28:38 +0000 (+0200) Subject: Fixed resize handling of lightmaps, they are now recreated on resize() X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=cbf531acc2e6462780dc8c713839f1e745ef7f95;p=supertux.git Fixed resize handling of lightmaps, they are now recreated on resize() --- diff --git a/src/supertux/main.cpp b/src/supertux/main.cpp index 6dc7c3744..1cfba9c4c 100644 --- a/src/supertux/main.cpp +++ b/src/supertux/main.cpp @@ -306,8 +306,7 @@ Main::launch_game() timelog("video"); std::unique_ptr 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"); diff --git a/src/supertux/screen_manager.cpp b/src/supertux/screen_manager.cpp index a2d2beb75..580d8753a 100644 --- a/src/supertux/screen_manager.cpp +++ b/src/supertux/screen_manager.cpp @@ -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 || diff --git a/src/video/drawing_context.cpp b/src/video/drawing_context.cpp index e093e5bf1..f600246ed 100644 --- a/src/video/drawing_context.cpp +++ b/src/video/drawing_context.cpp @@ -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; diff --git a/src/video/drawing_context.hpp b/src/video/drawing_context.hpp index cc2bc0104..ef55b8fa8 100644 --- a/src/video/drawing_context.hpp +++ b/src/video/drawing_context.hpp @@ -31,10 +31,9 @@ #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 transformstack; diff --git a/src/video/gl/gl_lightmap.hpp b/src/video/gl/gl_lightmap.hpp index 5c4ad5da4..9225cd745 100644 --- a/src/video/gl/gl_lightmap.hpp +++ b/src/video/gl/gl_lightmap.hpp @@ -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; diff --git a/src/video/gl/gl_video_system.cpp b/src/video/gl/gl_video_system.cpp index dde614dba..87b0ab74b 100644 --- a/src/video/gl/gl_video_system.cpp +++ b/src/video/gl/gl_video_system.cpp @@ -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 */ diff --git a/src/video/gl/gl_video_system.hpp b/src/video/gl/gl_video_system.hpp index 6928f7152..488d88018 100644 --- a/src/video/gl/gl_video_system.hpp +++ b/src/video/gl/gl_video_system.hpp @@ -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; diff --git a/src/video/lightmap.hpp b/src/video/lightmap.hpp index 905a237e1..544e81b5f 100644 --- a/src/video/lightmap.hpp +++ b/src/video/lightmap.hpp @@ -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; }; diff --git a/src/video/sdl/sdl_lightmap.cpp b/src/video/sdl/sdl_lightmap.cpp index 1d7f6c43e..4f91e68f6 100644 --- a/src/video/sdl/sdl_lightmap.cpp +++ b/src/video/sdl/sdl_lightmap.cpp @@ -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 diff --git a/src/video/sdl/sdl_lightmap.hpp b/src/video/sdl/sdl_lightmap.hpp index e13b61c63..1247a6446 100644 --- a/src/video/sdl/sdl_lightmap.hpp +++ b/src/video/sdl/sdl_lightmap.hpp @@ -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; diff --git a/src/video/sdl/sdl_video_system.cpp b/src/video/sdl/sdl_video_system.cpp index 4bb6cef73..6251fbae5 100644 --- a/src/video/sdl/sdl_video_system.cpp +++ b/src/video/sdl/sdl_video_system.cpp @@ -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 */ diff --git a/src/video/sdl/sdl_video_system.hpp b/src/video/sdl/sdl_video_system.hpp index ecd22978a..bc2d306e2 100644 --- a/src/video/sdl/sdl_video_system.hpp +++ b/src/video/sdl/sdl_video_system.hpp @@ -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; diff --git a/src/video/video_system.hpp b/src/video/video_system.hpp index 3ad7559e6..729f6ef15 100644 --- a/src/video/video_system.hpp +++ b/src/video/video_system.hpp @@ -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;