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 /// 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 from_glib_full(ffi::gdk_gl_texture_new(
38 context.to_glib_none().0,
39 id,
40 width,
41 height,
42 None,
43 std::ptr::null_mut(),
44 ))
45 }
46
47 #[doc(alias = "gdk_gl_texture_new")]
48 #[allow(clippy::missing_safety_doc)]
49 pub unsafe fn with_release_func<F: FnOnce() + 'static>(
50 context: &GLContext,
51 id: u32,
52 width: i32,
53 height: i32,
54 release_func: F,
55 ) -> Self {
56 unsafe extern "C" fn destroy_closure<F: FnOnce() + 'static>(func: glib::ffi::gpointer) {
57 let released_func = Box::<F>::from_raw(func as *mut _);
58 released_func();
59 }
60 let released_func = Box::new(release_func);
61 from_glib_full(ffi::gdk_gl_texture_new(
62 context.to_glib_none().0,
63 id,
64 width,
65 height,
66 Some(destroy_closure::<F>),
67 Box::into_raw(released_func) as glib::ffi::gpointer,
68 ))
69 }
70
71 #[cfg(feature = "v4_12")]
72 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
73 // rustdoc-stripper-ignore-next
74 /// Creates a new builder-pattern struct instance to construct [`GLTexture`]
75 /// objects.
76 ///
77 /// This method returns an instance of
78 /// [`GLTextureBuilder`](crate::builders::GLTextureBuilder) which can be
79 /// used to create [`GLTexture`] objects.
80 pub fn builder() -> GLTextureBuilder {
81 GLTextureBuilder::new()
82 }
83}