[go: up one dir, main page]

gdk4/
gl_texture.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use glib::translate::*;
4
5#[cfg(feature = "v4_12")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
7use crate::builders::GLTextureBuilder;
8use crate::{ffi, GLContext, GLTexture};
9
10impl GLTexture {
11    #[doc(alias = "gdk_gl_texture_new")]
12    #[allow(clippy::missing_safety_doc)]
13    pub unsafe fn new(context: &GLContext, id: u32, width: i32, height: i32) -> Self {
14        from_glib_full(ffi::gdk_gl_texture_new(
15            context.to_glib_none().0,
16            id,
17            width,
18            height,
19            None,
20            std::ptr::null_mut(),
21        ))
22    }
23
24    #[doc(alias = "gdk_gl_texture_new")]
25    #[allow(clippy::missing_safety_doc)]
26    pub unsafe fn with_release_func<F: FnOnce() + 'static>(
27        context: &GLContext,
28        id: u32,
29        width: i32,
30        height: i32,
31        release_func: F,
32    ) -> Self {
33        unsafe extern "C" fn destroy_closure<F: FnOnce() + 'static>(func: glib::ffi::gpointer) {
34            let released_func = Box::<F>::from_raw(func as *mut _);
35            released_func();
36        }
37        let released_func = Box::new(release_func);
38        from_glib_full(ffi::gdk_gl_texture_new(
39            context.to_glib_none().0,
40            id,
41            width,
42            height,
43            Some(destroy_closure::<F>),
44            Box::into_raw(released_func) as glib::ffi::gpointer,
45        ))
46    }
47
48    #[cfg(feature = "v4_12")]
49    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
50    // rustdoc-stripper-ignore-next
51    /// Creates a new builder-pattern struct instance to construct [`GLTexture`]
52    /// objects.
53    ///
54    /// This method returns an instance of
55    /// [`GLTextureBuilder`](crate::builders::GLTextureBuilder) which can be
56    /// used to create [`GLTexture`] objects.
57    pub fn builder() -> GLTextureBuilder {
58        GLTextureBuilder::new()
59    }
60}