Browse Source

Ensure that the initial atlas size is <= MAX_TEXTURE_SIZE

Johannes Hofmann 8 years ago
parent
commit
86d28b14fa
1 changed files with 18 additions and 3 deletions
  1. 18
    3
      src/map_view_gl.rs

+ 18
- 3
src/map_view_gl.rs View File

28
     {
28
     {
29
         unsafe {
29
         unsafe {
30
             let mut program = Program::from_paths(cx, "shader/map.vert", "shader/map.frag");
30
             let mut program = Program::from_paths(cx, "shader/map.vert", "shader/map.frag");
31
-
32
             check_gl_errors!(cx);
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
             check_gl_errors!(cx);
50
             check_gl_errors!(cx);
35
 
51
 
36
             let buf = Buffer::new(cx, &[], 0);
52
             let buf = Buffer::new(cx, &[], 0);
49
 
65
 
50
             program.before_render();
66
             program.before_render();
51
 
67
 
52
-            let tile_size = 256;
53
             let mut map_view = MapView::new(f64::from(initial_size.0), f64::from(initial_size.1), tile_size);
68
             let mut map_view = MapView::new(f64::from(initial_size.0), f64::from(initial_size.1), tile_size);
54
 
69
 
55
             // set initial zoom
70
             // set initial zoom