1use glib::{prelude::*, translate::*};
23use crate::{ffi, GLFramebuffer, GLMemoryRef};
45mod sealed {
6pub trait Sealed {}
7impl<T: super::IsA<super::GLFramebuffer>> Sealed for T {}
8}
910pub trait GLFramebufferExtManual: sealed::Sealed + IsA<GLFramebuffer> + 'static {
11/// Perform the steps necessary to have the output of a glDraw* command in
12 /// `func` update the contents of `mem`.
13 ///
14 /// Note: this function does not map `mem` for writing with OpenGL and that must
15 /// be done manually by the caller using any of the mapping functions such as
16 /// [`gst::Memory::map()`][crate::gst::Memory::map()] with the map flags `GST_MAP_WRITE` | `GST_MAP_GL`.
17 ///
18 /// Must be called with the same OpenGL context current that `self` was created
19 /// with.
20 /// ## `mem`
21 /// the [`GLMemory`][crate::GLMemory] to draw to
22 /// ## `func`
23 /// the function to run
24 ///
25 /// # Returns
26 ///
27 /// the result of executing `func`
28#[doc(alias = "gst_gl_framebuffer_draw_to_texture")]
29fn draw_to_texture<F: FnOnce()>(&self, mem: &mut GLMemoryRef, func: F) {
30let mut func = std::mem::ManuallyDrop::new(func);
31let user_data: *mut F = &mut *func;
3233unsafe extern "C" fn trampoline<F: FnOnce()>(
34 data: glib::ffi::gpointer,
35 ) -> glib::ffi::gboolean {
36let func = std::ptr::read(data as *mut F);
37 func();
38 glib::ffi::GTRUE
39 }
4041unsafe {
42 ffi::gst_gl_framebuffer_draw_to_texture(
43self.as_ref().to_glib_none().0,
44 mem.as_mut_ptr(),
45Some(trampoline::<F>),
46 user_data as glib::ffi::gpointer,
47 );
48 }
49 }
50}
5152impl<O: IsA<GLFramebuffer>> GLFramebufferExtManual for O {}