1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use crate::bindings::*;

pub struct OwnedGfxTexture {
    pub resource_id: GfxResourceID,
}

impl OwnedGfxTexture {
    /// # Panics
    ///
    /// Will panic if `bmp` doesn't have a power of two dimensions.
    pub fn new(bmp: &mut Bitmap, managed_pool: bool, mipmaps: bool) -> Self {
        let resource_id =
            unsafe { Gfx_CreateTexture(bmp, u8::from(managed_pool), u8::from(mipmaps)) };

        assert!(resource_id as usize != 0);

        Self { resource_id }
    }
}

impl Drop for OwnedGfxTexture {
    fn drop(&mut self) {
        unsafe {
            Gfx_DeleteTexture(&mut self.resource_id);
        }
    }
}