Преглед изворни кода

Ensure that the initial atlas size is <= MAX_TEXTURE_SIZE

Johannes Hofmann пре 8 година
родитељ
комит
86d28b14fa
1 измењених фајлова са 18 додато и 3 уклоњено
  1. 18
    3
      src/map_view_gl.rs

+ 18
- 3
src/map_view_gl.rs Прегледај датотеку

@@ -28,9 +28,25 @@ impl<'a> MapViewGl<'a> {
28 28
     {
29 29
         unsafe {
30 30
             let mut program = Program::from_paths(cx, "shader/map.vert", "shader/map.frag");
31
-
32 31
             check_gl_errors!(cx);
33
-            let tex = Texture::empty(cx, 2048, 2048, TextureFormat::Rgb8);
32
+
33
+            let tile_size = 256;
34
+
35
+            let atlas_size = {
36
+                let default_size = 2048;
37
+                let max_size = cx.max_texture_size() as u32;
38
+                if default_size <= max_size {
39
+                    default_size
40
+                } else {
41
+                    if tile_size * 3 > max_size {
42
+                        error!("maximal tile size ({}) is too small", max_size);
43
+                    }
44
+
45
+                    max_size
46
+                }
47
+            };
48
+
49
+            let tex = Texture::empty(cx, atlas_size, atlas_size, TextureFormat::Rgb8);
34 50
             check_gl_errors!(cx);
35 51
 
36 52
             let buf = Buffer::new(cx, &[], 0);
@@ -49,7 +65,6 @@ impl<'a> MapViewGl<'a> {
49 65
 
50 66
             program.before_render();
51 67
 
52
-            let tile_size = 256;
53 68
             let mut map_view = MapView::new(f64::from(initial_size.0), f64::from(initial_size.1), tile_size);
54 69
 
55 70
             // set initial zoom