cogl/auto/
texture2_dsliced.rs1#![allow(
2 clippy::too_many_arguments,
3 clippy::let_and_return,
4 clippy::from_over_into
5)]
6
7use crate::{Bitmap, Context, Object, PixelFormat, Texture};
8
9use glib::translate::*;
10use std::{fmt, ptr};
11
12glib_wrapper! {
13 pub struct Texture2DSliced(Object<ffi::CoglTexture2DSliced, Texture2DSlicedClass>) @extends Object, @implements Texture;
14
15 match fn {
16 get_type => || ffi::cogl_texture_2d_sliced_get_gtype(),
17 }
18}
19
20impl Texture2DSliced {
21 pub fn from_bitmap(bmp: &Bitmap, max_waste: i32) -> Texture2DSliced {
22 unsafe {
23 from_glib_full(ffi::cogl_texture_2d_sliced_new_from_bitmap(
24 bmp.to_glib_none().0,
25 max_waste,
26 ))
27 }
28 }
29
30 pub fn from_data(
31 ctx: &Context,
32 width: i32,
33 height: i32,
34 max_waste: i32,
35 format: PixelFormat,
36 rowstride: i32,
37 data: &[u8],
38 ) -> Result<Texture2DSliced, glib::Error> {
39 unsafe {
40 let mut error = ptr::null_mut();
41 let ret = ffi::cogl_texture_2d_sliced_new_from_data(
42 ctx.to_glib_none().0,
43 width,
44 height,
45 max_waste,
46 format.to_glib(),
47 rowstride,
48 data.as_ptr(),
49 &mut error,
50 );
51 if error.is_null() {
52 Ok(from_glib_full(ret))
53 } else {
54 Err(from_glib_full(error))
55 }
56 }
57 }
58
59 pub fn from_file(
60 ctx: &Context,
61 filename: &str,
62 max_waste: i32,
63 ) -> Result<Texture2DSliced, glib::Error> {
64 unsafe {
65 let mut error = ptr::null_mut();
66 let ret = ffi::cogl_texture_2d_sliced_new_from_file(
67 ctx.to_glib_none().0,
68 filename.to_glib_none().0,
69 max_waste,
70 &mut error,
71 );
72 if error.is_null() {
73 Ok(from_glib_full(ret))
74 } else {
75 Err(from_glib_full(error))
76 }
77 }
78 }
79
80 pub fn with_size(ctx: &Context, width: i32, height: i32, max_waste: i32) -> Texture2DSliced {
81 unsafe {
82 from_glib_full(ffi::cogl_texture_2d_sliced_new_with_size(
83 ctx.to_glib_none().0,
84 width,
85 height,
86 max_waste,
87 ))
88 }
89 }
90}
91
92impl fmt::Display for Texture2DSliced {
93 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
94 write!(f, "Texture2DSliced")
95 }
96}