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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#![allow(
    clippy::too_many_arguments,
    clippy::let_and_return,
    clippy::from_over_into
)]

use crate::Bitmap;
use crate::{Context, Object, PixelFormat, Texture};

use glib::translate::*;
use std::fmt;

glib_wrapper! {
    pub struct TextureRectangle(Object<ffi::CoglTextureRectangle, TextureRectangleClass>) @extends Object, @implements Texture;

    match fn {
        get_type => || ffi::cogl_texture_rectangle_get_gtype(),
    }
}

impl TextureRectangle {
    pub fn from_bitmap(bitmap: &Bitmap) -> TextureRectangle {
        unsafe {
            from_glib_full(ffi::cogl_texture_rectangle_new_from_bitmap(
                bitmap.to_glib_none().0,
            ))
        }
    }

    pub fn from_foreign(
        ctx: &Context,
        gl_handle: u32,
        width: i32,
        height: i32,
        format: PixelFormat,
    ) -> TextureRectangle {
        unsafe {
            from_glib_full(ffi::cogl_texture_rectangle_new_from_foreign(
                ctx.to_glib_none().0,
                gl_handle,
                width,
                height,
                format.to_glib(),
            ))
        }
    }

    pub fn with_size(ctx: &Context, width: i32, height: i32) -> TextureRectangle {
        unsafe {
            from_glib_full(ffi::cogl_texture_rectangle_new_with_size(
                ctx.to_glib_none().0,
                width,
                height,
            ))
        }
    }
}

impl fmt::Display for TextureRectangle {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "TextureRectangle")
    }
}