Added Renderer::start_draw()/end_draw() to fix scale issue issue SDLRenderer/SDLLightmap
authorIngo Ruhnke <grumbel@gmail.com>
Sun, 17 Aug 2014 02:18:53 +0000 (04:18 +0200)
committerIngo Ruhnke <grumbel@gmail.com>
Sun, 17 Aug 2014 02:18:53 +0000 (04:18 +0200)
src/video/drawing_context.cpp
src/video/gl/gl_renderer.cpp
src/video/gl/gl_renderer.hpp
src/video/renderer.hpp
src/video/sdl/sdl_renderer.cpp
src/video/sdl/sdl_renderer.hpp

index 7ed0079..d312113 100644 (file)
@@ -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);
index 03dadff..d5f71fe 100644 (file)
@@ -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);
index afb7542..ae0e186 100644 (file)
@@ -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;
 };
index 03d0b91..41e2470 100644 (file)
@@ -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;
index a879665..86c85f7 100644 (file)
@@ -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
index 0206e84..2ce622b 100644 (file)
@@ -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&);