rust/lib-hedgewars-engine/src/render/map.rs
changeset 14718 5915a199cb81
parent 14714 4df1aac5f090
child 14719 abc6aaf481c4
equal deleted inserted replaced
14717:16024046d458 14718:5915a199cb81
     1 use integral_geometry::{GridIndex, Point, Rect, Size};
     1 use integral_geometry::{GridIndex, Point, Rect, Size};
     2 use land2d::Land2D;
     2 use land2d::Land2D;
     3 use vec2d::Vec2D;
     3 use vec2d::Vec2D;
     4 
     4 
     5 use super::gl::{
     5 use super::{
     6     Buffer, InputElement, InputFormat, InputLayout, Shader, Texture2D, VariableBinding,
     6     camera::Camera,
       
     7     gl::{
       
     8         Buffer, InputElement, InputFormat, InputLayout, Shader, Texture2D, VariableBinding,
       
     9     }
     7 };
    10 };
     8 
    11 
     9 // TODO: temp
    12 // TODO: temp
    10 const VERTEX_SHADER: &'static str = r#"
    13 const VERTEX_SHADER: &'static str = r#"
    11 #version 150
    14 #version 150
   204         }
   207         }
   205     }
   208     }
   206 
   209 
   207     pub fn update(&mut self, land: &Land2D<u32>, region: Rect) {}
   210     pub fn update(&mut self, land: &Land2D<u32>, region: Rect) {}
   208 
   211 
   209     pub fn render(&mut self, viewport: Rect) {
   212     pub fn render(&mut self, camera: &Camera) {
       
   213         let viewport = camera.viewport();
   210         self.tile_vertices.clear();
   214         self.tile_vertices.clear();
   211         self.tile_indices.clear();
   215         self.tile_indices.clear();
   212         self.tile_draw_calls.clear();
   216         self.tile_draw_calls.clear();
   213         self.index_offset = 0;
   217         self.index_offset = 0;
   214 
   218 
   268         let _g = self.tile_layout.bind(
   272         let _g = self.tile_layout.bind(
   269             &[(0, &self.tile_vertex_buffer)],
   273             &[(0, &self.tile_vertex_buffer)],
   270             Some(&self.tile_index_buffer),
   274             Some(&self.tile_index_buffer),
   271         );
   275         );
   272 
   276 
   273         let ortho = {
   277         let projection = camera.projection();
   274             let l = viewport.left() as f32;
       
   275             let w = viewport.width() as f32;
       
   276             let h = viewport.height() as f32;
       
   277             let t = viewport.top() as f32;
       
   278 
       
   279             [
       
   280                 2f32 / w,
       
   281                 0f32,
       
   282                 0f32,
       
   283                 0f32,
       
   284                 0f32,
       
   285                 2f32 / -h,
       
   286                 0f32,
       
   287                 0f32,
       
   288                 0f32,
       
   289                 0f32,
       
   290                 0.5f32,
       
   291                 0f32,
       
   292                 -(2.0 * l + w) / w,
       
   293                 (2.0 * t + h) / h,
       
   294                 0.5f32,
       
   295                 1f32,
       
   296             ]
       
   297         };
       
   298 
   278 
   299         self.tile_shader.bind();
   279         self.tile_shader.bind();
   300         self.tile_shader.set_matrix("Projection", ortho.as_ptr());
   280         self.tile_shader.set_matrix("Projection", projection.as_ptr());
   301 
   281 
   302         let mut draw_offset = 0;
   282         let mut draw_offset = 0;
   303         for draw_call in &self.tile_draw_calls {
   283         for draw_call in &self.tile_draw_calls {
   304             unsafe {
   284             unsafe {
   305                 self.tile_shader
   285                 self.tile_shader