From: Ingo Ruhnke Date: Sun, 17 Aug 2014 02:18:53 +0000 (+0200) Subject: Added Renderer::start_draw()/end_draw() to fix scale issue issue SDLRenderer/SDLLightmap X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=d8857573c93d23338945424f65a57901bbc390b7;p=supertux.git Added Renderer::start_draw()/end_draw() to fix scale issue issue SDLRenderer/SDLLightmap --- diff --git a/src/video/drawing_context.cpp b/src/video/drawing_context.cpp index 7ed007934..d31211368 100644 --- a/src/video/drawing_context.cpp +++ b/src/video/drawing_context.cpp @@ -328,7 +328,9 @@ DrawingContext::do_drawing() request->layer = LAYER_HUD - 1; drawing_requests.push_back(request); } + renderer.start_draw(); handle_drawing_requests(drawing_requests); + renderer.end_draw(); clear_drawing_requests(lightmap_requests); clear_drawing_requests(drawing_requests); diff --git a/src/video/gl/gl_renderer.cpp b/src/video/gl/gl_renderer.cpp index 03dadfffc..d5f71fed7 100644 --- a/src/video/gl/gl_renderer.cpp +++ b/src/video/gl/gl_renderer.cpp @@ -352,6 +352,16 @@ GLRenderer::apply_video_mode() } void +GLRenderer::start_draw() +{ +} + +void +GLRenderer::end_draw() +{ +} + +void GLRenderer::draw_surface(const DrawingRequest& request) { GLPainter::draw_surface(request); diff --git a/src/video/gl/gl_renderer.hpp b/src/video/gl/gl_renderer.hpp index afb7542d1..ae0e186ef 100644 --- a/src/video/gl/gl_renderer.hpp +++ b/src/video/gl/gl_renderer.hpp @@ -37,21 +37,26 @@ public: GLRenderer(); ~GLRenderer(); - 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 do_take_screenshot(); - void flip(); - void resize(int w, int h); - void apply_config(); - void apply_video_mode(); - Vector to_logical(int physical_x, int physical_y); - void set_gamma(float gamma); + void start_draw() override; + void end_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 do_take_screenshot() override; + void flip() override; + void resize(int w, int h) override; + void apply_config() override; + Vector to_logical(int physical_x, int physical_y) override; + void set_gamma(float gamma) override; + SDL_Window* get_window() const { return window; } private: + void apply_video_mode(); + +private: GLRenderer(const GLRenderer&) = delete; GLRenderer& operator=(const GLRenderer&) = delete; }; diff --git a/src/video/renderer.hpp b/src/video/renderer.hpp index 03d0b91ea..41e24708c 100644 --- a/src/video/renderer.hpp +++ b/src/video/renderer.hpp @@ -43,6 +43,8 @@ public: Renderer(); virtual ~Renderer(); + virtual void start_draw() = 0; + virtual void end_draw() = 0; virtual void draw_surface(const DrawingRequest& request) = 0; virtual void draw_surface_part(const DrawingRequest& request) = 0; virtual void draw_gradient(const DrawingRequest& request) = 0; diff --git a/src/video/sdl/sdl_renderer.cpp b/src/video/sdl/sdl_renderer.cpp index a8796656c..86c85f775 100644 --- a/src/video/sdl/sdl_renderer.cpp +++ b/src/video/sdl/sdl_renderer.cpp @@ -36,7 +36,8 @@ SDLRenderer::SDLRenderer() : window(), renderer(), viewport(), - desktop_size(0, 0) + desktop_size(0, 0), + m_scale(1.0f, 1.0f) { Renderer::instance_ = this; @@ -127,6 +128,17 @@ SDLRenderer::~SDLRenderer() } void +SDLRenderer::start_draw() +{ + SDL_RenderSetScale(renderer, m_scale.x, m_scale.y); +} + +void +SDLRenderer::end_draw() +{ +} + +void SDLRenderer::draw_surface(const DrawingRequest& request) { SDLPainter::draw_surface(renderer, request); @@ -314,13 +326,12 @@ SDLRenderer::apply_viewport() Size max_size(1280, 800); Size min_size(640, 480); - Vector scale; Size logical_size; calculate_viewport(min_size, max_size, target_size, pixel_aspect_ratio, g_config->magnification, - scale, logical_size, viewport); + m_scale, logical_size, viewport); SCREEN_WIDTH = logical_size.width; SCREEN_HEIGHT = logical_size.height; @@ -336,9 +347,11 @@ SDLRenderer::apply_viewport() SDL_RenderClear(renderer); } + // SetViewport() works in scaled screen coordinates, so we have to + // reset it to 1.0, 1.0 to get meaningful results SDL_RenderSetScale(renderer, 1.0f, 1.0f); SDL_RenderSetViewport(renderer, &viewport); - SDL_RenderSetScale(renderer, scale.x, scale.y); + SDL_RenderSetScale(renderer, m_scale.x, m_scale.y); } void diff --git a/src/video/sdl/sdl_renderer.hpp b/src/video/sdl/sdl_renderer.hpp index 0206e84f9..2ce622b53 100644 --- a/src/video/sdl/sdl_renderer.hpp +++ b/src/video/sdl/sdl_renderer.hpp @@ -26,17 +26,20 @@ public: SDLRenderer(); ~SDLRenderer(); - 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 do_take_screenshot(); - void flip(); - void resize(int w, int h); - void apply_config(); - Vector to_logical(int physical_x, int physical_y); - void set_gamma(float gamma); + void start_draw() override; + void end_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 do_take_screenshot() override; + void flip() override; + void resize(int w, int h) override; + void apply_config() override; + Vector to_logical(int physical_x, int physical_y) override; + void set_gamma(float gamma) override; + SDL_Window* get_window() const { return window; } SDL_Renderer* get_sdl_renderer() const { return renderer; }; @@ -49,6 +52,7 @@ private: SDL_Renderer* renderer; SDL_Rect viewport; Size desktop_size; + Vector m_scale; private: SDLRenderer(const SDLRenderer&);