gstreamer_gl/auto/gl_context.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
4// DO NOT EDIT
5
6use crate::{ffi, GLDisplay, GLPlatform, GLSLProfile, GLSLVersion, GLWindow, GLAPI};
7use glib::{prelude::*, translate::*};
8
9glib::wrapper! {
10 /// [`GLContext`][crate::GLContext] wraps an OpenGL context object in a uniform API. As a result
11 /// of the limitation on OpenGL context, this object is not thread safe unless
12 /// specified and must only be activated in a single thread.
13 ///
14 /// Environment variables:
15 /// - `GST_GL_API`: select which OpenGL API to create and OpenGL context for.
16 /// Depending on the platform, the available values are
17 /// 'opengl', 'opengl3' (core profile), and 'gles2'. See the
18 /// the [`GLAPI`][crate::GLAPI] enumeration for more details.
19 /// - `GST_GL_PLATFORM`: select which OpenGL platform to create an OpenGL
20 /// context with. Depending on the platform and the
21 /// dependencies available build-time, the available values
22 /// are, 'glx', 'egl', 'cgl', 'wgl', and 'eagl'
23 /// - `GST_GL_CONFIG`: select the configuration used for creating the OpenGL
24 /// context and OpenGL surface. Written out as a GstStructure
25 /// that has been serialized to string. e.g.
26 /// `GST_GL_CONFIG="gst-gl-context-config,red-size=8,green-size=8,blue-size=8,alpha-size=8,depth-size=16"`.
27 /// Not all platforms will support the same level of
28 /// functionality.
29 ///
30 /// This is an Abstract Base Class, you cannot instantiate it.
31 ///
32 /// # Implements
33 ///
34 /// [`GLContextExt`][trait@crate::prelude::GLContextExt], [`trait@gst::prelude::ObjectExt`], [`trait@glib::ObjectExt`], [`GLContextExtManual`][trait@crate::prelude::GLContextExtManual]
35 #[doc(alias = "GstGLContext")]
36 pub struct GLContext(Object<ffi::GstGLContext, ffi::GstGLContextClass>) @extends gst::Object;
37
38 match fn {
39 type_ => || ffi::gst_gl_context_get_type(),
40 }
41}
42
43impl GLContext {
44 pub const NONE: Option<&'static GLContext> = None;
45
46 /// Create a new [`GLContext`][crate::GLContext] with the specified `display`
47 /// ## `display`
48 /// a [`GLDisplay`][crate::GLDisplay]
49 ///
50 /// # Returns
51 ///
52 /// a new [`GLContext`][crate::GLContext]
53 #[doc(alias = "gst_gl_context_new")]
54 pub fn new(display: &impl IsA<GLDisplay>) -> GLContext {
55 skip_assert_initialized!();
56 unsafe { from_glib_none(ffi::gst_gl_context_new(display.as_ref().to_glib_none().0)) }
57 }
58
59 /// See also [`GLContextExt::activate()`][crate::prelude::GLContextExt::activate()].
60 ///
61 /// # Returns
62 ///
63 /// the [`GLContext`][crate::GLContext] active in the current thread or [`None`]
64 #[doc(alias = "gst_gl_context_get_current")]
65 #[doc(alias = "get_current")]
66 pub fn current() -> Option<GLContext> {
67 assert_initialized_main_thread!();
68 unsafe { from_glib_none(ffi::gst_gl_context_get_current()) }
69 }
70
71 /// If an error occurs, `major` and `minor` are not modified and `GST_GL_API_NONE` is
72 /// returned.
73 /// ## `platform`
74 /// the [`GLPlatform`][crate::GLPlatform] to retrieve the API for
75 ///
76 /// # Returns
77 ///
78 /// The version supported by the OpenGL context current in the calling
79 /// thread or `GST_GL_API_NONE`
80 ///
81 /// ## `major`
82 /// the major version
83 ///
84 /// ## `minor`
85 /// the minor version
86 #[doc(alias = "gst_gl_context_get_current_gl_api")]
87 #[doc(alias = "get_current_gl_api")]
88 pub fn current_gl_api(platform: GLPlatform) -> (GLAPI, u32, u32) {
89 assert_initialized_main_thread!();
90 unsafe {
91 let mut major = std::mem::MaybeUninit::uninit();
92 let mut minor = std::mem::MaybeUninit::uninit();
93 let ret = from_glib(ffi::gst_gl_context_get_current_gl_api(
94 platform.into_glib(),
95 major.as_mut_ptr(),
96 minor.as_mut_ptr(),
97 ));
98 (ret, major.assume_init(), minor.assume_init())
99 }
100 }
101}
102
103unsafe impl Send for GLContext {}
104unsafe impl Sync for GLContext {}
105
106/// Trait containing all [`struct@GLContext`] methods.
107///
108/// # Implementors
109///
110/// [`GLContext`][struct@crate::GLContext]
111pub trait GLContextExt: IsA<GLContext> + 'static {
112 /// (De)activate the OpenGL context represented by this `self`.
113 ///
114 /// In OpenGL terms, calls eglMakeCurrent or similar with this context and the
115 /// currently set window. See [`set_window()`][Self::set_window()] for details.
116 /// ## `activate`
117 /// [`true`] to activate, [`false`] to deactivate
118 ///
119 /// # Returns
120 ///
121 /// Whether the activation succeeded
122 #[doc(alias = "gst_gl_context_activate")]
123 fn activate(&self, activate: bool) -> Result<(), glib::error::BoolError> {
124 unsafe {
125 glib::result_from_gboolean!(
126 ffi::gst_gl_context_activate(self.as_ref().to_glib_none().0, activate.into_glib()),
127 "Failed to activate OpenGL context"
128 )
129 }
130 }
131
132 /// Note: This will always fail for two wrapped [`GLContext`][crate::GLContext]'s
133 /// ## `other_context`
134 /// another [`GLContext`][crate::GLContext]
135 ///
136 /// # Returns
137 ///
138 /// whether `self` and `other_context` are able to share OpenGL
139 /// resources.
140 #[doc(alias = "gst_gl_context_can_share")]
141 fn can_share(&self, other_context: &impl IsA<GLContext>) -> bool {
142 unsafe {
143 from_glib(ffi::gst_gl_context_can_share(
144 self.as_ref().to_glib_none().0,
145 other_context.as_ref().to_glib_none().0,
146 ))
147 }
148 }
149
150 /// Check for an OpenGL `feature` being supported.
151 ///
152 /// Note: Most features require that the context be created before it is
153 /// possible to determine their existence and so will fail if that is not the
154 /// case.
155 /// ## `feature`
156 /// a platform specific feature
157 ///
158 /// # Returns
159 ///
160 /// Whether `feature` is supported by `self`
161 #[doc(alias = "gst_gl_context_check_feature")]
162 fn check_feature(&self, feature: &str) -> bool {
163 unsafe {
164 from_glib(ffi::gst_gl_context_check_feature(
165 self.as_ref().to_glib_none().0,
166 feature.to_glib_none().0,
167 ))
168 }
169 }
170
171 /// Must be called with `self` current.
172 /// ## `fbo_target`
173 /// the GL value of the framebuffer target, GL_FRAMEBUFFER,
174 /// GL_READ_FRAMEBUFFER, GL_DRAW_FRAMEBUFFER
175 ///
176 /// # Returns
177 ///
178 /// whether whether the current framebuffer is complete
179 #[doc(alias = "gst_gl_context_check_framebuffer_status")]
180 fn check_framebuffer_status(&self, fbo_target: u32) -> bool {
181 unsafe {
182 from_glib(ffi::gst_gl_context_check_framebuffer_status(
183 self.as_ref().to_glib_none().0,
184 fbo_target,
185 ))
186 }
187 }
188
189 /// ## `api`
190 /// api type required
191 /// ## `maj`
192 /// major version required
193 /// ## `min`
194 /// minor version required
195 ///
196 /// # Returns
197 ///
198 /// whether OpenGL context implements the required api and specified
199 /// version.
200 #[doc(alias = "gst_gl_context_check_gl_version")]
201 fn check_gl_version(&self, api: GLAPI, maj: i32, min: i32) -> bool {
202 unsafe {
203 from_glib(ffi::gst_gl_context_check_gl_version(
204 self.as_ref().to_glib_none().0,
205 api.into_glib(),
206 maj,
207 min,
208 ))
209 }
210 }
211
212 /// Unbind the current framebuffer
213 #[doc(alias = "gst_gl_context_clear_framebuffer")]
214 fn clear_framebuffer(&self) {
215 unsafe {
216 ffi::gst_gl_context_clear_framebuffer(self.as_ref().to_glib_none().0);
217 }
218 }
219
220 /// Clear's the currently set shader from the GL state machine.
221 ///
222 /// Note: must be called in the GL thread.
223 #[doc(alias = "gst_gl_context_clear_shader")]
224 fn clear_shader(&self) {
225 unsafe {
226 ffi::gst_gl_context_clear_shader(self.as_ref().to_glib_none().0);
227 }
228 }
229
230 /// Creates an OpenGL context with the specified `other_context` as a context
231 /// to share shareable OpenGL objects with. See the OpenGL specification for
232 /// what is shared between OpenGL contexts.
233 ///
234 /// Since 1.20, the configuration can be overriden with the environment variable
235 /// `GST_GL_CONFIG` which is a stringified [`gst::Structure`][crate::gst::Structure] as would be returned
236 /// from [`config()`][Self::config()]. If `GST_GL_CONFIG` is not set, then the
237 /// config will be chosen from `other_context` by calling
238 /// [`config()`][Self::config()] on `other_context`. Otherwise, a default
239 /// configuration is used.
240 ///
241 /// Calling [`request_config()`][Self::request_config()]) before calling
242 /// [`create()`][Self::create()] will override the config from `other_context` but
243 /// will not override the `GST_GL_CONFIG` environment variable.
244 ///
245 /// If an error occurs, and `error` is not [`None`], then `error` will contain
246 /// details of the error and [`false`] will be returned.
247 ///
248 /// Should only be called once.
249 /// ## `other_context`
250 /// a [`GLContext`][crate::GLContext] to share OpenGL objects with
251 ///
252 /// # Returns
253 ///
254 /// whether the context could successfully be created
255 #[doc(alias = "gst_gl_context_create")]
256 fn create(&self, other_context: Option<&impl IsA<GLContext>>) -> Result<(), glib::Error> {
257 unsafe {
258 let mut error = std::ptr::null_mut();
259 let is_ok = ffi::gst_gl_context_create(
260 self.as_ref().to_glib_none().0,
261 other_context.map(|p| p.as_ref()).to_glib_none().0,
262 &mut error,
263 );
264 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
265 if error.is_null() {
266 Ok(())
267 } else {
268 Err(from_glib_full(error))
269 }
270 }
271 }
272
273 #[doc(alias = "gst_gl_context_destroy")]
274 fn destroy(&self) {
275 unsafe {
276 ffi::gst_gl_context_destroy(self.as_ref().to_glib_none().0);
277 }
278 }
279
280 /// Fills `self`'s info (version, extensions, vtable, etc) from the GL
281 /// context in the current thread. Typically used with wrapped contexts to
282 /// allow wrapped contexts to be used as regular [`GLContext`][crate::GLContext]'s.
283 #[doc(alias = "gst_gl_context_fill_info")]
284 fn fill_info(&self) -> Result<(), glib::Error> {
285 unsafe {
286 let mut error = std::ptr::null_mut();
287 let is_ok = ffi::gst_gl_context_fill_info(self.as_ref().to_glib_none().0, &mut error);
288 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
289 if error.is_null() {
290 Ok(())
291 } else {
292 Err(from_glib_full(error))
293 }
294 }
295 }
296
297 /// Retrieve the OpenGL configuration for this context. The context must
298 /// have been successfully created for this function to return a valid value.
299 ///
300 /// Not all implementations currently support retrieving the config and will
301 /// return [`None`] when not supported.
302 ///
303 /// # Returns
304 ///
305 /// the configuration chosen for this OpenGL context.
306 #[cfg(feature = "v1_20")]
307 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
308 #[doc(alias = "gst_gl_context_get_config")]
309 #[doc(alias = "get_config")]
310 fn config(&self) -> Option<gst::Structure> {
311 unsafe {
312 from_glib_full(ffi::gst_gl_context_get_config(
313 self.as_ref().to_glib_none().0,
314 ))
315 }
316 }
317
318 ///
319 /// # Returns
320 ///
321 /// the [`GLDisplay`][crate::GLDisplay] associated with this `self`
322 #[doc(alias = "gst_gl_context_get_display")]
323 #[doc(alias = "get_display")]
324 fn display(&self) -> GLDisplay {
325 unsafe {
326 from_glib_full(ffi::gst_gl_context_get_display(
327 self.as_ref().to_glib_none().0,
328 ))
329 }
330 }
331
332 /// Get the currently enabled OpenGL api.
333 ///
334 /// The currently available API may be limited by the [`GLDisplay`][crate::GLDisplay] in use and/or
335 /// the [`GLWindow`][crate::GLWindow] chosen.
336 ///
337 /// # Returns
338 ///
339 /// the available OpenGL api
340 #[doc(alias = "gst_gl_context_get_gl_api")]
341 #[doc(alias = "get_gl_api")]
342 fn gl_api(&self) -> GLAPI {
343 unsafe {
344 from_glib(ffi::gst_gl_context_get_gl_api(
345 self.as_ref().to_glib_none().0,
346 ))
347 }
348 }
349
350 /// Gets the OpenGL platform that used by `self`.
351 ///
352 /// # Returns
353 ///
354 /// The platform specific backing OpenGL context
355 #[doc(alias = "gst_gl_context_get_gl_platform")]
356 #[doc(alias = "get_gl_platform")]
357 fn gl_platform(&self) -> GLPlatform {
358 unsafe {
359 from_glib(ffi::gst_gl_context_get_gl_platform(
360 self.as_ref().to_glib_none().0,
361 ))
362 }
363 }
364
365 /// Get the version of the OpenGL platform (GLX, EGL, etc) used. Only valid
366 /// after a call to [`create()`][Self::create()].
367 ///
368 /// # Returns
369 ///
370 ///
371 /// ## `major`
372 /// return for the major version
373 ///
374 /// ## `minor`
375 /// return for the minor version
376 #[doc(alias = "gst_gl_context_get_gl_platform_version")]
377 #[doc(alias = "get_gl_platform_version")]
378 fn gl_platform_version(&self) -> (i32, i32) {
379 unsafe {
380 let mut major = std::mem::MaybeUninit::uninit();
381 let mut minor = std::mem::MaybeUninit::uninit();
382 ffi::gst_gl_context_get_gl_platform_version(
383 self.as_ref().to_glib_none().0,
384 major.as_mut_ptr(),
385 minor.as_mut_ptr(),
386 );
387 (major.assume_init(), minor.assume_init())
388 }
389 }
390
391 /// Returns the OpenGL version implemented by `self`. See
392 /// [`gl_api()`][Self::gl_api()] for retrieving the OpenGL api implemented by
393 /// `self`.
394 ///
395 /// # Returns
396 ///
397 ///
398 /// ## `maj`
399 /// resulting major version
400 ///
401 /// ## `min`
402 /// resulting minor version
403 #[doc(alias = "gst_gl_context_get_gl_version")]
404 #[doc(alias = "get_gl_version")]
405 fn gl_version(&self) -> (i32, i32) {
406 unsafe {
407 let mut maj = std::mem::MaybeUninit::uninit();
408 let mut min = std::mem::MaybeUninit::uninit();
409 ffi::gst_gl_context_get_gl_version(
410 self.as_ref().to_glib_none().0,
411 maj.as_mut_ptr(),
412 min.as_mut_ptr(),
413 );
414 (maj.assume_init(), min.assume_init())
415 }
416 }
417
418 ///
419 /// # Returns
420 ///
421 /// the currently set window
422 #[doc(alias = "gst_gl_context_get_window")]
423 #[doc(alias = "get_window")]
424 fn window(&self) -> Option<GLWindow> {
425 unsafe {
426 from_glib_full(ffi::gst_gl_context_get_window(
427 self.as_ref().to_glib_none().0,
428 ))
429 }
430 }
431
432 ///
433 /// # Returns
434 ///
435 /// Whether the [`GLContext`][crate::GLContext] has been shared with another [`GLContext`][crate::GLContext]
436 #[doc(alias = "gst_gl_context_is_shared")]
437 fn is_shared(&self) -> bool {
438 unsafe {
439 from_glib(ffi::gst_gl_context_is_shared(
440 self.as_ref().to_glib_none().0,
441 ))
442 }
443 }
444
445 /// Set the OpenGL configuration for this context. The context must not
446 /// have been created for this function to succeed. Setting a [`None`]
447 /// `config` has the affect of removing any specific configuration request.
448 ///
449 /// Not all implementations currently support retrieving the config and this
450 /// function will return FALSE when not supported.
451 ///
452 /// Note that calling this function may cause a subsequent
453 /// [`create()`][Self::create()] to fail if `config` could not be matched with
454 /// the platform-specific configuration.
455 ///
456 /// Note that the actual config used may be differ from the requested values.
457 /// ## `gl_config`
458 /// a configuration structure for
459 /// configuring the OpenGL context
460 ///
461 /// # Returns
462 ///
463 /// whether `gl_config` could be successfully set on `self`
464 #[cfg(feature = "v1_20")]
465 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
466 #[doc(alias = "gst_gl_context_request_config")]
467 fn request_config(&self, gl_config: Option<gst::Structure>) -> bool {
468 unsafe {
469 from_glib(ffi::gst_gl_context_request_config(
470 self.as_ref().to_glib_none().0,
471 gl_config.into_glib_ptr(),
472 ))
473 }
474 }
475
476 /// Will internally set `self` as shared with `share`
477 /// ## `share`
478 /// another [`GLContext`][crate::GLContext]
479 #[doc(alias = "gst_gl_context_set_shared_with")]
480 fn set_shared_with(&self, share: &impl IsA<GLContext>) {
481 unsafe {
482 ffi::gst_gl_context_set_shared_with(
483 self.as_ref().to_glib_none().0,
484 share.as_ref().to_glib_none().0,
485 );
486 }
487 }
488
489 /// Set's the current window on `self` to `window`. The window can only be
490 /// changed before [`create()`][Self::create()] has been called and the `window` is not
491 /// already running.
492 /// ## `window`
493 /// a [`GLWindow`][crate::GLWindow]
494 ///
495 /// # Returns
496 ///
497 /// Whether the window was successfully updated
498 #[doc(alias = "gst_gl_context_set_window")]
499 fn set_window(&self, window: impl IsA<GLWindow>) -> Result<(), glib::error::BoolError> {
500 unsafe {
501 glib::result_from_gboolean!(
502 ffi::gst_gl_context_set_window(
503 self.as_ref().to_glib_none().0,
504 window.upcast().into_glib_ptr()
505 ),
506 "Failed to set window"
507 )
508 }
509 }
510
511 /// ## `version`
512 /// a [`GLSLVersion`][crate::GLSLVersion]
513 /// ## `profile`
514 /// a [`GLSLProfile`][crate::GLSLProfile]
515 ///
516 /// # Returns
517 ///
518 /// Whether `self` supports the combination of `version` with `profile`
519 #[doc(alias = "gst_gl_context_supports_glsl_profile_version")]
520 fn supports_glsl_profile_version(&self, version: GLSLVersion, profile: GLSLProfile) -> bool {
521 unsafe {
522 from_glib(ffi::gst_gl_context_supports_glsl_profile_version(
523 self.as_ref().to_glib_none().0,
524 version.into_glib(),
525 profile.into_glib(),
526 ))
527 }
528 }
529
530 /// ## `version`
531 /// a [`GLSLVersion`][crate::GLSLVersion]
532 /// ## `profile`
533 /// a [`GLSLProfile`][crate::GLSLProfile]
534 ///
535 /// # Returns
536 ///
537 /// whether `self` supports the 'precision' specifier in GLSL shaders
538 #[cfg(feature = "v1_16")]
539 #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
540 #[doc(alias = "gst_gl_context_supports_precision")]
541 fn supports_precision(&self, version: GLSLVersion, profile: GLSLProfile) -> bool {
542 unsafe {
543 from_glib(ffi::gst_gl_context_supports_precision(
544 self.as_ref().to_glib_none().0,
545 version.into_glib(),
546 profile.into_glib(),
547 ))
548 }
549 }
550
551 /// ## `version`
552 /// a [`GLSLVersion`][crate::GLSLVersion]
553 /// ## `profile`
554 /// a [`GLSLProfile`][crate::GLSLProfile]
555 ///
556 /// # Returns
557 ///
558 /// whether `self` supports the 'precision highp' specifier in GLSL shaders
559 #[cfg(feature = "v1_16")]
560 #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
561 #[doc(alias = "gst_gl_context_supports_precision_highp")]
562 fn supports_precision_highp(&self, version: GLSLVersion, profile: GLSLProfile) -> bool {
563 unsafe {
564 from_glib(ffi::gst_gl_context_supports_precision_highp(
565 self.as_ref().to_glib_none().0,
566 version.into_glib(),
567 profile.into_glib(),
568 ))
569 }
570 }
571
572 /// Swap the front and back buffers on the window attached to `self`.
573 /// This will display the frame on the next refresh cycle.
574 #[doc(alias = "gst_gl_context_swap_buffers")]
575 fn swap_buffers(&self) {
576 unsafe {
577 ffi::gst_gl_context_swap_buffers(self.as_ref().to_glib_none().0);
578 }
579 }
580}
581
582impl<O: IsA<GLContext>> GLContextExt for O {}