gstreamer_gl/
gl_framebuffer.rs

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