Преглед на файлове

Don't call glClear when map fills the whole screen

Johannes Hofmann преди 7 години
родител
ревизия
19e28a35d8
променени са 3 файла, в които са добавени 17 реда и са изтрити 3 реда
  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 Целия файл

@@ -290,9 +290,9 @@ fn run() -> Result<(), Box<Error>> {
290 290
             let _ = gl_window.swap_buffers();
291 291
 
292 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 297
             //TODO increase atlas size earlier to avoid excessive copying to the GPU
298 298
             //TODO increase max tile cache size?

+ 10
- 0
src/map_view.rs Целия файл

@@ -78,6 +78,16 @@ impl MapView {
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 91
     /// Returns the screen coordinate of the top-left corner of a tile.
82 92
     pub fn tile_screen_position(&self, tile: &TileCoord) -> ScreenCoord {
83 93
         self.map_to_screen_coord(tile.map_coord_north_west())

+ 4
- 0
src/map_view_gl.rs Целия файл

@@ -96,6 +96,10 @@ impl<'a> MapViewGl<'a> {
96 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 103
     pub fn increase_atlas_size(&mut self) -> Result<(), ()> {
100 104
         self.tile_atlas.double_texture_size()
101 105
     }