1#![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 Texture3D(Object<ffi::CoglTexture3D, Texture3DClass>) @extends Object, @implements Texture;
14
15 match fn {
16 get_type => || ffi::cogl_texture_3d_get_gtype(),
17 }
18}
19
20impl Texture3D {
21 pub fn from_bitmap(bitmap: &Bitmap, height: i32, depth: i32) -> Texture3D {
22 unsafe {
23 from_glib_full(ffi::cogl_texture_3d_new_from_bitmap(
24 bitmap.to_glib_none().0,
25 height,
26 depth,
27 ))
28 }
29 }
30
31 pub fn from_data(
32 context: &Context,
33 width: i32,
34 height: i32,
35 depth: i32,
36 format: PixelFormat,
37 rowstride: i32,
38 image_stride: i32,
39 data: &[u8],
40 ) -> Result<Texture3D, glib::Error> {
41 unsafe {
42 let mut error = ptr::null_mut();
43 let ret = ffi::cogl_texture_3d_new_from_data(
44 context.to_glib_none().0,
45 width,
46 height,
47 depth,
48 format.to_glib(),
49 rowstride,
50 image_stride,
51 data.as_ptr(),
52 &mut error,
53 );
54 if error.is_null() {
55 Ok(from_glib_full(ret))
56 } else {
57 Err(from_glib_full(error))
58 }
59 }
60 }
61
62 pub fn with_size(context: &Context, width: i32, height: i32, depth: i32) -> Texture3D {
63 unsafe {
64 from_glib_full(ffi::cogl_texture_3d_new_with_size(
65 context.to_glib_none().0,
66 width,
67 height,
68 depth,
69 ))
70 }
71 }
72}
73
74impl fmt::Display for Texture3D {
75 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
76 write!(f, "Texture3D")
77 }
78}