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::{GLContext, GLTexture, ffi};
9
10impl GLTexture {
11 /// Creates a new texture for an existing GL texture.
12 ///
13 /// Note that the GL texture must not be modified until @destroy is called,
14 /// which will happen when the GdkTexture object is finalized, or due to
15 /// an explicit call of [`release()`][Self::release()].
16 ///
17 /// # Deprecated since 4.12
18 ///
19 /// [`GLTextureBuilder`][crate::GLTextureBuilder] supersedes this function
20 /// and provides extended functionality for creating GL textures.
21 /// ## `context`
22 /// a [`GLContext`][crate::GLContext]
23 /// ## `id`
24 /// the ID of a texture that was created with @context
25 /// ## `width`
26 /// the nominal width of the texture
27 /// ## `height`
28 /// the nominal height of the texture
29 ///
30 /// # Returns
31 ///
32 /// A newly-created
33 /// [`Texture`][crate::Texture]
34 #[doc(alias = "gdk_gl_texture_new")]
35 #[allow(clippy::missing_safety_doc)]
36 pub unsafe fn new(context: &GLContext, id: u32, width: i32, height: i32) -> Self {
37 unsafe {
38 from_glib_full(ffi::gdk_gl_texture_new(
39 context.to_glib_none().0,
40 id,
41 width,
42 height,
43 None,
44 std::ptr::null_mut(),
45 ))
46 }
47 }
48
49 #[doc(alias = "gdk_gl_texture_new")]
50 #[allow(clippy::missing_safety_doc)]
51 pub unsafe fn with_release_func<F: FnOnce() + 'static>(
52 context: &GLContext,
53 id: u32,
54 width: i32,
55 height: i32,
56 release_func: F,
57 ) -> Self {
58 unsafe {
59 unsafe extern "C" fn destroy_closure<F: FnOnce() + 'static>(func: glib::ffi::gpointer) {
60 unsafe {
61 let released_func = Box::<F>::from_raw(func as *mut _);
62 released_func();
63 }
64 }
65 let released_func = Box::new(release_func);
66 from_glib_full(ffi::gdk_gl_texture_new(
67 context.to_glib_none().0,
68 id,
69 width,
70 height,
71 Some(destroy_closure::<F>),
72 Box::into_raw(released_func) as glib::ffi::gpointer,
73 ))
74 }
75 }
76
77 #[cfg(feature = "v4_12")]
78 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
79 // rustdoc-stripper-ignore-next
80 /// Creates a new builder-pattern struct instance to construct [`GLTexture`]
81 /// objects.
82 ///
83 /// This method returns an instance of
84 /// [`GLTextureBuilder`](crate::builders::GLTextureBuilder) which can be
85 /// used to create [`GLTexture`] objects.
86 pub fn builder() -> GLTextureBuilder {
87 GLTextureBuilder::new()
88 }
89}