1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
// DO NOT EDIT

use crate::GLContext;
use crate::GLSLProfile;
use crate::GLSLVersion;
use glib::object::IsA;
use glib::translate::*;
use std::ptr;

glib::wrapper! {
    /// [`crate::GLSLStage`] holds and represents a single OpenGL shader stage.
    ///
    /// # Implements
    ///
    /// [`trait@gst::prelude::ObjectExt`], [`trait@glib::object::ObjectExt`]
    pub struct GLSLStage(Object<ffi::GstGLSLStage, ffi::GstGLSLStageClass>) @extends gst::Object;

    match fn {
        type_ => || ffi::gst_glsl_stage_get_type(),
    }
}

impl GLSLStage {
    /// ## `context`
    /// a [`crate::GLContext`]
    /// ## `type_`
    /// the GL enum shader stage type
    ///
    /// # Returns
    ///
    /// a new [`crate::GLSLStage`] of the specified `type_`
    #[doc(alias = "gst_glsl_stage_new")]
    pub fn new<P: IsA<GLContext>>(context: &P, type_: u32) -> GLSLStage {
        skip_assert_initialized!();
        unsafe {
            from_glib_none(ffi::gst_glsl_stage_new(
                context.as_ref().to_glib_none().0,
                type_,
            ))
        }
    }

    #[doc(alias = "gst_glsl_stage_new_default_fragment")]
    pub fn new_default_fragment<P: IsA<GLContext>>(context: &P) -> GLSLStage {
        skip_assert_initialized!();
        unsafe {
            from_glib_none(ffi::gst_glsl_stage_new_default_fragment(
                context.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "gst_glsl_stage_new_default_vertex")]
    pub fn new_default_vertex<P: IsA<GLContext>>(context: &P) -> GLSLStage {
        skip_assert_initialized!();
        unsafe {
            from_glib_none(ffi::gst_glsl_stage_new_default_vertex(
                context.as_ref().to_glib_none().0,
            ))
        }
    }

    /// ## `context`
    /// a [`crate::GLContext`]
    /// ## `type_`
    /// the GL enum shader stage type
    /// ## `version`
    /// the [`crate::GLSLVersion`]
    /// ## `profile`
    /// the [`crate::GLSLProfile`]
    /// ## `str`
    /// a shader string
    ///
    /// # Returns
    ///
    /// a new [`crate::GLSLStage`] of the specified `type_`
    #[doc(alias = "gst_glsl_stage_new_with_string")]
    #[doc(alias = "new_with_string")]
    pub fn with_string<P: IsA<GLContext>>(
        context: &P,
        type_: u32,
        version: GLSLVersion,
        profile: GLSLProfile,
        str: &str,
    ) -> GLSLStage {
        skip_assert_initialized!();
        unsafe {
            from_glib_none(ffi::gst_glsl_stage_new_with_string(
                context.as_ref().to_glib_none().0,
                type_,
                version.into_glib(),
                profile.into_glib(),
                str.to_glib_none().0,
            ))
        }
    }

    /// ## `context`
    /// a [`crate::GLContext`]
    /// ## `type_`
    /// the GL enum shader stage type
    /// ## `version`
    /// the [`crate::GLSLVersion`]
    /// ## `profile`
    /// the [`crate::GLSLProfile`]
    /// ## `n_strings`
    /// the number of strings in `str`
    /// ## `str`
    ///
    ///  an array of strings concatted together to produce a shader
    ///
    /// # Returns
    ///
    /// a new [`crate::GLSLStage`] of the specified `type_`
    #[doc(alias = "gst_glsl_stage_new_with_strings")]
    #[doc(alias = "new_with_strings")]
    pub fn with_strings<P: IsA<GLContext>>(
        context: &P,
        type_: u32,
        version: GLSLVersion,
        profile: GLSLProfile,
        str: &[&str],
    ) -> GLSLStage {
        skip_assert_initialized!();
        let n_strings = str.len() as i32;
        unsafe {
            from_glib_none(ffi::gst_glsl_stage_new_with_strings(
                context.as_ref().to_glib_none().0,
                type_,
                version.into_glib(),
                profile.into_glib(),
                n_strings,
                str.to_glib_none().0,
            ))
        }
    }

    ///
    /// # Returns
    ///
    /// whether the compilation succeeded
    #[doc(alias = "gst_glsl_stage_compile")]
    pub fn compile(&self) -> Result<(), glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let _ = ffi::gst_glsl_stage_compile(self.to_glib_none().0, &mut error);
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    ///
    /// # Returns
    ///
    /// The GL handle for this shader stage
    #[doc(alias = "gst_glsl_stage_get_handle")]
    #[doc(alias = "get_handle")]
    pub fn handle(&self) -> u32 {
        unsafe { ffi::gst_glsl_stage_get_handle(self.to_glib_none().0) }
    }

    ///
    /// # Returns
    ///
    /// The GLSL profile for the current shader stage
    #[doc(alias = "gst_glsl_stage_get_profile")]
    #[doc(alias = "get_profile")]
    pub fn profile(&self) -> GLSLProfile {
        unsafe { from_glib(ffi::gst_glsl_stage_get_profile(self.to_glib_none().0)) }
    }

    ///
    /// # Returns
    ///
    /// The GL shader type for this shader stage
    #[doc(alias = "gst_glsl_stage_get_shader_type")]
    #[doc(alias = "get_shader_type")]
    pub fn shader_type(&self) -> u32 {
        unsafe { ffi::gst_glsl_stage_get_shader_type(self.to_glib_none().0) }
    }

    ///
    /// # Returns
    ///
    /// The GLSL version for the current shader stage
    #[doc(alias = "gst_glsl_stage_get_version")]
    #[doc(alias = "get_version")]
    pub fn version(&self) -> GLSLVersion {
        unsafe { from_glib(ffi::gst_glsl_stage_get_version(self.to_glib_none().0)) }
    }

    /// Replaces the current shader string with `str`.
    /// ## `version`
    /// a [`crate::GLSLVersion`]
    /// ## `profile`
    /// a [`crate::GLSLProfile`]
    /// ## `n_strings`
    /// number of strings in `str`
    /// ## `str`
    /// a GLSL shader string
    #[doc(alias = "gst_glsl_stage_set_strings")]
    pub fn set_strings(
        &self,
        version: GLSLVersion,
        profile: GLSLProfile,
        str: &[&str],
    ) -> Result<(), glib::error::BoolError> {
        let n_strings = str.len() as i32;
        unsafe {
            glib::result_from_gboolean!(
                ffi::gst_glsl_stage_set_strings(
                    self.to_glib_none().0,
                    version.into_glib(),
                    profile.into_glib(),
                    n_strings,
                    str.to_glib_none().0
                ),
                "Failed to attach stage to set strings"
            )
        }
    }
}

unsafe impl Send for GLSLStage {}
unsafe impl Sync for GLSLStage {}