rust/lib-hedgewars-engine/src/render/gear.rs
changeset 15782 ff1432e873bd
parent 15781 c929e25a7da2
child 15784 84c07aa94b61
equal deleted inserted replaced
15781:c929e25a7da2 15782:ff1432e873bd
     1 use crate::render::{
     1 use crate::render::{
     2     atlas::{AtlasCollection, SpriteIndex, SpriteLocation},
     2     atlas::{AtlasCollection, SpriteIndex, SpriteLocation},
     3     camera::Camera,
     3     camera::Camera,
     4     gl::Texture2D,
     4     gl::{Texture2D, TextureDataType, TextureFilter, TextureFormat, TextureInternalFormat},
     5 };
     5 };
     6 
     6 
     7 use integral_geometry::{Rect, Size};
     7 use integral_geometry::{Rect, Size};
     8 
     8 
     9 use png::{ColorType, Decoder, DecodingError};
     9 use png::{ColorType, Decoder, DecodingError};
    16     io::BufReader,
    16     io::BufReader,
    17     path::{Path, PathBuf},
    17     path::{Path, PathBuf},
    18 };
    18 };
    19 
    19 
    20 #[derive(PartialEq, Debug, Clone, Copy)]
    20 #[derive(PartialEq, Debug, Clone, Copy)]
    21 enum SpriteId {
    21 pub enum SpriteId {
    22     Mine = 0,
    22     Mine = 0,
    23     Grenade,
    23     Grenade,
    24 
    24 
    25     MaxSprite,
    25     MaxSprite,
    26 }
    26 }
    52 
    52 
    53 impl GearRenderer {
    53 impl GearRenderer {
    54     pub fn new() -> Self {
    54     pub fn new() -> Self {
    55         let mut atlas = AtlasCollection::new(ATLAS_SIZE);
    55         let mut atlas = AtlasCollection::new(ATLAS_SIZE);
    56 
    56 
    57         let texture = Texture2D::new(ATLAS_SIZE, gl::RGBA8, gl::LINEAR);
    57         let texture = Texture2D::new(
       
    58             ATLAS_SIZE,
       
    59             TextureInternalFormat::Rgba8,
       
    60             TextureFilter::Linear,
       
    61         );
    58 
    62 
    59         let mut allocation = Box::new([(0, Rect::at_origin(Size::EMPTY)); MAX_SPRITES]);
    63         let mut allocation = Box::new([(0, Rect::at_origin(Size::EMPTY)); MAX_SPRITES]);
    60 
    64 
    61         for (sprite, file) in SPRITE_LOAD_LIST {
    65         for (sprite, file) in SPRITE_LOAD_LIST {
    62             let path = Path::new(file);
    66             let path = Path::new(file);
    71                 .expect("Unable to load Graphics");
    75                 .expect("Unable to load Graphics");
    72 
    76 
    73             texture.update(
    77             texture.update(
    74                 rect,
    78                 rect,
    75                 mapgen::theme::slice_u32_to_u8_mut(&mut pixels[..]),
    79                 mapgen::theme::slice_u32_to_u8_mut(&mut pixels[..]),
    76                 0,
    80                 None,
    77                 gl::RGBA,
    81                 TextureFormat::Rgba,
    78                 gl::UNSIGNED_BYTE,
    82                 TextureDataType::UnsignedByte,
    79             );
    83             );
    80 
    84 
    81             allocation[*sprite as usize] = (texture_index, rect);
    85             allocation[*sprite as usize] = (texture_index, rect);
    82         }
    86         }
    83 
    87