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
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

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

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

    match fn {
        get_type => || gst_gl_sys::gst_glsl_stage_get_type(),
    }
}

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

    pub fn new_default_fragment<P: IsA<GLContext>>(context: &P) -> GLSLStage {
        skip_assert_initialized!();
        unsafe {
            from_glib_none(gst_gl_sys::gst_glsl_stage_new_default_fragment(
                context.as_ref().to_glib_none().0,
            ))
        }
    }

    pub fn new_default_vertex<P: IsA<GLContext>>(context: &P) -> GLSLStage {
        skip_assert_initialized!();
        unsafe {
            from_glib_none(gst_gl_sys::gst_glsl_stage_new_default_vertex(
                context.as_ref().to_glib_none().0,
            ))
        }
    }

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

    /// ## `context`
    /// a `GLContext`
    /// ## `type_`
    /// the GL enum shader stage type
    /// ## `version`
    /// the `GLSLVersion`
    /// ## `profile`
    /// the `GLSLProfile`
    /// ## `n_strings`
    /// the number of strings in `str`
    /// ## `str`
    ///
    ///  an array of strings concatted together to produce a shader
    ///
    /// # Returns
    ///
    /// a new `GLSLStage` of the specified `type_`
    pub fn new_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(gst_gl_sys::gst_glsl_stage_new_with_strings(
                context.as_ref().to_glib_none().0,
                type_,
                version.to_glib(),
                profile.to_glib(),
                n_strings,
                str.to_glib_none().0,
            ))
        }
    }

    ///
    /// # Returns
    ///
    /// whether the compilation suceeded
    pub fn compile(&self) -> Result<(), glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let _ = gst_gl_sys::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
    pub fn get_handle(&self) -> u32 {
        unsafe { gst_gl_sys::gst_glsl_stage_get_handle(self.to_glib_none().0) }
    }

    ///
    /// # Returns
    ///
    /// The GLSL profile for the current shader stage
    pub fn get_profile(&self) -> GLSLProfile {
        unsafe {
            from_glib(gst_gl_sys::gst_glsl_stage_get_profile(
                self.to_glib_none().0,
            ))
        }
    }

    ///
    /// # Returns
    ///
    /// The GL shader type for this shader stage
    pub fn get_shader_type(&self) -> u32 {
        unsafe { gst_gl_sys::gst_glsl_stage_get_shader_type(self.to_glib_none().0) }
    }

    ///
    /// # Returns
    ///
    /// The GLSL version for the current shader stage
    pub fn get_version(&self) -> GLSLVersion {
        unsafe {
            from_glib(gst_gl_sys::gst_glsl_stage_get_version(
                self.to_glib_none().0,
            ))
        }
    }

    /// Replaces the current shader string with `str`.
    /// ## `version`
    /// a `GLSLVersion`
    /// ## `profile`
    /// a `GLSLProfile`
    /// ## `n_strings`
    /// number of strings in `str`
    /// ## `str`
    /// a GLSL shader string
    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!(
                gst_gl_sys::gst_glsl_stage_set_strings(
                    self.to_glib_none().0,
                    version.to_glib(),
                    profile.to_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 {}