classicube_sys\graphics/
owned_gfx_texture.rs1use crate::bindings::{Bitmap, Gfx_CreateTexture, Gfx_DeleteTexture, GfxResourceID};
2
3pub struct OwnedGfxTexture {
4 pub resource_id: GfxResourceID,
5}
6
7impl OwnedGfxTexture {
8 pub fn new(bmp: &mut Bitmap, managed_pool: bool, mipmaps: bool) -> Option<Self> {
12 let resource_id =
13 unsafe { Gfx_CreateTexture(bmp, u8::from(managed_pool), u8::from(mipmaps)) };
14
15 if resource_id as usize == 0 {
16 return None;
17 }
18
19 Some(Self { resource_id })
20 }
21}
22
23impl Drop for OwnedGfxTexture {
24 fn drop(&mut self) {
25 unsafe {
26 Gfx_DeleteTexture(&raw mut self.resource_id);
27 }
28 }
29}