Browse Source

Don't call glClear when map fills the whole screen

Johannes Hofmann 7 years ago
parent
commit
19e28a35d8
3 changed files with 17 additions and 3 deletions
  1. 3
    3
      src/main.rs
  2. 10
    0
      src/map_view.rs
  3. 4
    0
      src/map_view_gl.rs

+ 3
- 3
src/main.rs View File

290
             let _ = gl_window.swap_buffers();
290
             let _ = gl_window.swap_buffers();
291
 
291
 
292
             // Move glClear call out of the critical path.
292
             // Move glClear call out of the critical path.
293
-            //TODO do not call glClear when drawing fills the whole screen anyway
294
-            cx.clear_color((0.2, 0.2, 0.2, 1.0));
295
-
293
+            if !map.viewport_in_map() {
294
+                cx.clear_color((0.2, 0.2, 0.2, 1.0));
295
+            }
296
 
296
 
297
             //TODO increase atlas size earlier to avoid excessive copying to the GPU
297
             //TODO increase atlas size earlier to avoid excessive copying to the GPU
298
             //TODO increase max tile cache size?
298
             //TODO increase max tile cache size?

+ 10
- 0
src/map_view.rs View File

78
         }
78
         }
79
     }
79
     }
80
 
80
 
81
+    /// Returns true if the viewport rectangle is fully inside the map.
82
+    pub fn viewport_in_map(&self) -> bool {
83
+        let scale = f64::powf(2.0, -self.zoom) / f64::from(self.tile_size);
84
+
85
+        let y_top = self.center.y + -0.5 * self.height * scale;
86
+        let y_bottom = self.center.y + 0.5 * self.height * scale;
87
+
88
+        y_top >= 0.0 && y_bottom <= 1.0
89
+    }
90
+
81
     /// Returns the screen coordinate of the top-left corner of a tile.
91
     /// Returns the screen coordinate of the top-left corner of a tile.
82
     pub fn tile_screen_position(&self, tile: &TileCoord) -> ScreenCoord {
92
     pub fn tile_screen_position(&self, tile: &TileCoord) -> ScreenCoord {
83
         self.map_to_screen_coord(tile.map_coord_north_west())
93
         self.map_to_screen_coord(tile.map_coord_north_west())

+ 4
- 0
src/map_view_gl.rs View File

96
         self.cx.set_viewport(0, 0, width, height);
96
         self.cx.set_viewport(0, 0, width, height);
97
     }
97
     }
98
 
98
 
99
+    pub fn viewport_in_map(&self) -> bool {
100
+        self.map_view.viewport_in_map()
101
+    }
102
+
99
     pub fn increase_atlas_size(&mut self) -> Result<(), ()> {
103
     pub fn increase_atlas_size(&mut self) -> Result<(), ()> {
100
         self.tile_atlas.double_texture_size()
104
         self.tile_atlas.double_texture_size()
101
     }
105
     }