Skip to content

Commit

Permalink
Fixed resize handling of lightmaps, they are now recreated on resize()
Browse files Browse the repository at this point in the history
  • Loading branch information
Grumbel committed Aug 29, 2014
1 parent 98eb08a commit cbf531a
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 32 deletions.
3 changes: 1 addition & 2 deletions src/supertux/main.cpp
Expand Up @@ -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");
Expand Down
6 changes: 3 additions & 3 deletions src/supertux/screen_manager.cpp
Expand Up @@ -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;
}
Expand All @@ -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 ||
Expand Down
12 changes: 9 additions & 3 deletions src/video/drawing_context.cpp
Expand Up @@ -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(),
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 3 additions & 5 deletions src/video/drawing_context.hpp
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -191,8 +190,7 @@ class DrawingContext
void clear_drawing_requests(DrawingRequests& requests);

private:
Renderer& renderer;
Lightmap& lightmap;
VideoSystem& video_system;

/// the transform stack
std::vector<Transform> transformstack;
Expand Down
18 changes: 9 additions & 9 deletions src/video/gl/gl_lightmap.hpp
Expand Up @@ -29,15 +29,15 @@ class GLLightmap : public Lightmap
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;
Expand Down
13 changes: 13 additions & 0 deletions src/video/gl/gl_video_system.cpp
Expand Up @@ -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 */
3 changes: 3 additions & 0 deletions src/video/gl/gl_video_system.hpp
Expand Up @@ -40,6 +40,9 @@ class GLVideoSystem : public VideoSystem
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;
Expand Down
1 change: 1 addition & 0 deletions src/video/lightmap.hpp
Expand Up @@ -47,6 +47,7 @@ class Lightmap
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;
};

Expand Down
6 changes: 6 additions & 0 deletions src/video/sdl/sdl_lightmap.cpp
Expand Up @@ -111,6 +111,12 @@ SDLLightmap::draw_filled_rect(const DrawingRequest& request)
SDLPainter::draw_filled_rect(m_renderer, request);
}

void
SDLLightmap::draw_inverse_ellipse(const DrawingRequest& request)
{
SDLPainter::draw_inverse_ellipse(m_renderer, request);
}

void
SDLLightmap::get_light(const DrawingRequest& request) const
{
Expand Down
19 changes: 9 additions & 10 deletions src/video/sdl/sdl_lightmap.hpp
Expand Up @@ -30,16 +30,15 @@ class SDLLightmap : public Lightmap
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;
Expand Down
13 changes: 13 additions & 0 deletions src/video/sdl/sdl_video_system.cpp
Expand Up @@ -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 */
3 changes: 3 additions & 0 deletions src/video/sdl/sdl_video_system.hpp
Expand Up @@ -40,6 +40,9 @@ class SDLVideoSystem : public VideoSystem
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;
Expand Down
3 changes: 3 additions & 0 deletions src/video/video_system.hpp
Expand Up @@ -53,6 +53,9 @@ class VideoSystem : public Currenton<VideoSystem>
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;
Expand Down

0 comments on commit cbf531a

Please sign in to comment.