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
106mod sealed {
107 pub trait Sealed {}
108 impl<T: super::IsA<super::GLContext>> Sealed for T {}
109}
110
111/// Trait containing all [`struct@GLContext`] methods.
112///
113/// # Implementors
114///
115/// [`GLContext`][struct@crate::GLContext]
116pub trait GLContextExt: IsA<GLContext> + sealed::Sealed + 'static {
117 /// (De)activate the OpenGL context represented by this `self`.
118 ///
119 /// In OpenGL terms, calls eglMakeCurrent or similar with this context and the
120 /// currently set window. See [`set_window()`][Self::set_window()] for details.
121 /// ## `activate`
122 /// [`true`] to activate, [`false`] to deactivate
123 ///
124 /// # Returns
125 ///
126 /// Whether the activation succeeded
127 #[doc(alias = "gst_gl_context_activate")]
128 fn activate(&self, activate: bool) -> Result<(), glib::error::BoolError> {
129 unsafe {
130 glib::result_from_gboolean!(
131 ffi::gst_gl_context_activate(self.as_ref().to_glib_none().0, activate.into_glib()),
132 "Failed to activate OpenGL context"
133 )
134 }
135 }
136
137 /// Note: This will always fail for two wrapped [`GLContext`][crate::GLContext]'s
138 /// ## `other_context`
139 /// another [`GLContext`][crate::GLContext]
140 ///
141 /// # Returns
142 ///
143 /// whether `self` and `other_context` are able to share OpenGL
144 /// resources.
145 #[doc(alias = "gst_gl_context_can_share")]
146 fn can_share(&self, other_context: &impl IsA<GLContext>) -> bool {
147 unsafe {
148 from_glib(ffi::gst_gl_context_can_share(
149 self.as_ref().to_glib_none().0,
150 other_context.as_ref().to_glib_none().0,
151 ))
152 }
153 }
154
155 /// Check for an OpenGL `feature` being supported.
156 ///
157 /// Note: Most features require that the context be created before it is
158 /// possible to determine their existence and so will fail if that is not the
159 /// case.
160 /// ## `feature`
161 /// a platform specific feature
162 ///
163 /// # Returns
164 ///
165 /// Whether `feature` is supported by `self`
166 #[doc(alias = "gst_gl_context_check_feature")]
167 fn check_feature(&self, feature: &str) -> bool {
168 unsafe {
169 from_glib(ffi::gst_gl_context_check_feature(
170 self.as_ref().to_glib_none().0,
171 feature.to_glib_none().0,
172 ))
173 }
174 }
175
176 /// Must be called with `self` current.
177 /// ## `fbo_target`
178 /// the GL value of the framebuffer target, GL_FRAMEBUFFER,
179 /// GL_READ_FRAMEBUFFER, GL_DRAW_FRAMEBUFFER
180 ///
181 /// # Returns
182 ///
183 /// whether whether the current framebuffer is complete
184 #[doc(alias = "gst_gl_context_check_framebuffer_status")]
185 fn check_framebuffer_status(&self, fbo_target: u32) -> bool {
186 unsafe {
187 from_glib(ffi::gst_gl_context_check_framebuffer_status(
188 self.as_ref().to_glib_none().0,
189 fbo_target,
190 ))
191 }
192 }
193
194 /// ## `api`
195 /// api type required
196 /// ## `maj`
197 /// major version required
198 /// ## `min`
199 /// minor version required
200 ///
201 /// # Returns
202 ///
203 /// whether OpenGL context implements the required api and specified
204 /// version.
205 #[doc(alias = "gst_gl_context_check_gl_version")]
206 fn check_gl_version(&self, api: GLAPI, maj: i32, min: i32) -> bool {
207 unsafe {
208 from_glib(ffi::gst_gl_context_check_gl_version(
209 self.as_ref().to_glib_none().0,
210 api.into_glib(),
211 maj,
212 min,
213 ))
214 }
215 }
216
217 /// Unbind the current framebuffer
218 #[doc(alias = "gst_gl_context_clear_framebuffer")]
219 fn clear_framebuffer(&self) {
220 unsafe {
221 ffi::gst_gl_context_clear_framebuffer(self.as_ref().to_glib_none().0);
222 }
223 }
224
225 /// Clear's the currently set shader from the GL state machine.
226 ///
227 /// Note: must be called in the GL thread.
228 #[doc(alias = "gst_gl_context_clear_shader")]
229 fn clear_shader(&self) {
230 unsafe {
231 ffi::gst_gl_context_clear_shader(self.as_ref().to_glib_none().0);
232 }
233 }
234
235 /// Creates an OpenGL context with the specified `other_context` as a context
236 /// to share shareable OpenGL objects with. See the OpenGL specification for
237 /// what is shared between OpenGL contexts.
238 ///
239 /// Since 1.20, the configuration can be overriden with the environment variable
240 /// `GST_GL_CONFIG` which is a stringified [`gst::Structure`][crate::gst::Structure] as would be returned
241 /// from [`config()`][Self::config()]. If `GST_GL_CONFIG` is not set, then the
242 /// config will be chosen from `other_context` by calling
243 /// [`config()`][Self::config()] on `other_context`. Otherwise, a default
244 /// configuration is used.
245 ///
246 /// Calling [`request_config()`][Self::request_config()]) before calling
247 /// [`create()`][Self::create()] will override the config from `other_context` but
248 /// will not override the `GST_GL_CONFIG` environment variable.
249 ///
250 /// If an error occurs, and `error` is not [`None`], then `error` will contain
251 /// details of the error and [`false`] will be returned.
252 ///
253 /// Should only be called once.
254 /// ## `other_context`
255 /// a [`GLContext`][crate::GLContext] to share OpenGL objects with
256 ///
257 /// # Returns
258 ///
259 /// whether the context could successfully be created
260 #[doc(alias = "gst_gl_context_create")]
261 fn create(&self, other_context: Option<&impl IsA<GLContext>>) -> Result<(), glib::Error> {
262 unsafe {
263 let mut error = std::ptr::null_mut();
264 let is_ok = ffi::gst_gl_context_create(
265 self.as_ref().to_glib_none().0,
266 other_context.map(|p| p.as_ref()).to_glib_none().0,
267 &mut error,
268 );
269 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
270 if error.is_null() {
271 Ok(())
272 } else {
273 Err(from_glib_full(error))
274 }
275 }
276 }
277
278 #[doc(alias = "gst_gl_context_destroy")]
279 fn destroy(&self) {
280 unsafe {
281 ffi::gst_gl_context_destroy(self.as_ref().to_glib_none().0);
282 }
283 }
284
285 /// Fills `self`'s info (version, extensions, vtable, etc) from the GL
286 /// context in the current thread. Typically used with wrapped contexts to
287 /// allow wrapped contexts to be used as regular [`GLContext`][crate::GLContext]'s.
288 #[doc(alias = "gst_gl_context_fill_info")]
289 fn fill_info(&self) -> Result<(), glib::Error> {
290 unsafe {
291 let mut error = std::ptr::null_mut();
292 let is_ok = ffi::gst_gl_context_fill_info(self.as_ref().to_glib_none().0, &mut error);
293 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
294 if error.is_null() {
295 Ok(())
296 } else {
297 Err(from_glib_full(error))
298 }
299 }
300 }
301
302 /// Retrieve the OpenGL configuration for this context. The context must
303 /// have been successfully created for this function to return a valid value.
304 ///
305 /// Not all implementations currently support retrieving the config and will
306 /// return [`None`] when not supported.
307 ///
308 /// # Returns
309 ///
310 /// the configuration chosen for this OpenGL context.
311 #[cfg(feature = "v1_20")]
312 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
313 #[doc(alias = "gst_gl_context_get_config")]
314 #[doc(alias = "get_config")]
315 fn config(&self) -> Option<gst::Structure> {
316 unsafe {
317 from_glib_full(ffi::gst_gl_context_get_config(
318 self.as_ref().to_glib_none().0,
319 ))
320 }
321 }
322
323 ///
324 /// # Returns
325 ///
326 /// the [`GLDisplay`][crate::GLDisplay] associated with this `self`
327 #[doc(alias = "gst_gl_context_get_display")]
328 #[doc(alias = "get_display")]
329 fn display(&self) -> GLDisplay {
330 unsafe {
331 from_glib_full(ffi::gst_gl_context_get_display(
332 self.as_ref().to_glib_none().0,
333 ))
334 }
335 }
336
337 /// Get the currently enabled OpenGL api.
338 ///
339 /// The currently available API may be limited by the [`GLDisplay`][crate::GLDisplay] in use and/or
340 /// the [`GLWindow`][crate::GLWindow] chosen.
341 ///
342 /// # Returns
343 ///
344 /// the available OpenGL api
345 #[doc(alias = "gst_gl_context_get_gl_api")]
346 #[doc(alias = "get_gl_api")]
347 fn gl_api(&self) -> GLAPI {
348 unsafe {
349 from_glib(ffi::gst_gl_context_get_gl_api(
350 self.as_ref().to_glib_none().0,
351 ))
352 }
353 }
354
355 /// Gets the OpenGL platform that used by `self`.
356 ///
357 /// # Returns
358 ///
359 /// The platform specific backing OpenGL context
360 #[doc(alias = "gst_gl_context_get_gl_platform")]
361 #[doc(alias = "get_gl_platform")]
362 fn gl_platform(&self) -> GLPlatform {
363 unsafe {
364 from_glib(ffi::gst_gl_context_get_gl_platform(
365 self.as_ref().to_glib_none().0,
366 ))
367 }
368 }
369
370 /// Get the version of the OpenGL platform (GLX, EGL, etc) used. Only valid
371 /// after a call to [`create()`][Self::create()].
372 ///
373 /// # Returns
374 ///
375 ///
376 /// ## `major`
377 /// return for the major version
378 ///
379 /// ## `minor`
380 /// return for the minor version
381 #[doc(alias = "gst_gl_context_get_gl_platform_version")]
382 #[doc(alias = "get_gl_platform_version")]
383 fn gl_platform_version(&self) -> (i32, i32) {
384 unsafe {
385 let mut major = std::mem::MaybeUninit::uninit();
386 let mut minor = std::mem::MaybeUninit::uninit();
387 ffi::gst_gl_context_get_gl_platform_version(
388 self.as_ref().to_glib_none().0,
389 major.as_mut_ptr(),
390 minor.as_mut_ptr(),
391 );
392 (major.assume_init(), minor.assume_init())
393 }
394 }
395
396 /// Returns the OpenGL version implemented by `self`. See
397 /// [`gl_api()`][Self::gl_api()] for retrieving the OpenGL api implemented by
398 /// `self`.
399 ///
400 /// # Returns
401 ///
402 ///
403 /// ## `maj`
404 /// resulting major version
405 ///
406 /// ## `min`
407 /// resulting minor version
408 #[doc(alias = "gst_gl_context_get_gl_version")]
409 #[doc(alias = "get_gl_version")]
410 fn gl_version(&self) -> (i32, i32) {
411 unsafe {
412 let mut maj = std::mem::MaybeUninit::uninit();
413 let mut min = std::mem::MaybeUninit::uninit();
414 ffi::gst_gl_context_get_gl_version(
415 self.as_ref().to_glib_none().0,
416 maj.as_mut_ptr(),
417 min.as_mut_ptr(),
418 );
419 (maj.assume_init(), min.assume_init())
420 }
421 }
422
423 ///
424 /// # Returns
425 ///
426 /// the currently set window
427 #[doc(alias = "gst_gl_context_get_window")]
428 #[doc(alias = "get_window")]
429 fn window(&self) -> Option<GLWindow> {
430 unsafe {
431 from_glib_full(ffi::gst_gl_context_get_window(
432 self.as_ref().to_glib_none().0,
433 ))
434 }
435 }
436
437 ///
438 /// # Returns
439 ///
440 /// Whether the [`GLContext`][crate::GLContext] has been shared with another [`GLContext`][crate::GLContext]
441 #[doc(alias = "gst_gl_context_is_shared")]
442 fn is_shared(&self) -> bool {
443 unsafe {
444 from_glib(ffi::gst_gl_context_is_shared(
445 self.as_ref().to_glib_none().0,
446 ))
447 }
448 }
449
450 /// Set the OpenGL configuration for this context. The context must not
451 /// have been created for this function to succeed. Setting a [`None`]
452 /// `config` has the affect of removing any specific configuration request.
453 ///
454 /// Not all implementations currently support retrieving the config and this
455 /// function will return FALSE when not supported.
456 ///
457 /// Note that calling this function may cause a subsequent
458 /// [`create()`][Self::create()] to fail if `config` could not be matched with
459 /// the platform-specific configuration.
460 ///
461 /// Note that the actual config used may be differ from the requested values.
462 /// ## `gl_config`
463 /// a configuration structure for
464 /// configuring the OpenGL context
465 ///
466 /// # Returns
467 ///
468 /// whether `gl_config` could be successfully set on `self`
469 #[cfg(feature = "v1_20")]
470 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
471 #[doc(alias = "gst_gl_context_request_config")]
472 fn request_config(&self, gl_config: Option<gst::Structure>) -> bool {
473 unsafe {
474 from_glib(ffi::gst_gl_context_request_config(
475 self.as_ref().to_glib_none().0,
476 gl_config.into_glib_ptr(),
477 ))
478 }
479 }
480
481 /// Will internally set `self` as shared with `share`
482 /// ## `share`
483 /// another [`GLContext`][crate::GLContext]
484 #[doc(alias = "gst_gl_context_set_shared_with")]
485 fn set_shared_with(&self, share: &impl IsA<GLContext>) {
486 unsafe {
487 ffi::gst_gl_context_set_shared_with(
488 self.as_ref().to_glib_none().0,
489 share.as_ref().to_glib_none().0,
490 );
491 }
492 }
493
494 /// Set's the current window on `self` to `window`. The window can only be
495 /// changed before [`create()`][Self::create()] has been called and the `window` is not
496 /// already running.
497 /// ## `window`
498 /// a [`GLWindow`][crate::GLWindow]
499 ///
500 /// # Returns
501 ///
502 /// Whether the window was successfully updated
503 #[doc(alias = "gst_gl_context_set_window")]
504 fn set_window(&self, window: impl IsA<GLWindow>) -> Result<(), glib::error::BoolError> {
505 unsafe {
506 glib::result_from_gboolean!(
507 ffi::gst_gl_context_set_window(
508 self.as_ref().to_glib_none().0,
509 window.upcast().into_glib_ptr()
510 ),
511 "Failed to set window"
512 )
513 }
514 }
515
516 /// ## `version`
517 /// a [`GLSLVersion`][crate::GLSLVersion]
518 /// ## `profile`
519 /// a [`GLSLProfile`][crate::GLSLProfile]
520 ///
521 /// # Returns
522 ///
523 /// Whether `self` supports the combination of `version` with `profile`
524 #[doc(alias = "gst_gl_context_supports_glsl_profile_version")]
525 fn supports_glsl_profile_version(&self, version: GLSLVersion, profile: GLSLProfile) -> bool {
526 unsafe {
527 from_glib(ffi::gst_gl_context_supports_glsl_profile_version(
528 self.as_ref().to_glib_none().0,
529 version.into_glib(),
530 profile.into_glib(),
531 ))
532 }
533 }
534
535 /// ## `version`
536 /// a [`GLSLVersion`][crate::GLSLVersion]
537 /// ## `profile`
538 /// a [`GLSLProfile`][crate::GLSLProfile]
539 ///
540 /// # Returns
541 ///
542 /// whether `self` supports the 'precision' specifier in GLSL shaders
543 #[cfg(feature = "v1_16")]
544 #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
545 #[doc(alias = "gst_gl_context_supports_precision")]
546 fn supports_precision(&self, version: GLSLVersion, profile: GLSLProfile) -> bool {
547 unsafe {
548 from_glib(ffi::gst_gl_context_supports_precision(
549 self.as_ref().to_glib_none().0,
550 version.into_glib(),
551 profile.into_glib(),
552 ))
553 }
554 }
555
556 /// ## `version`
557 /// a [`GLSLVersion`][crate::GLSLVersion]
558 /// ## `profile`
559 /// a [`GLSLProfile`][crate::GLSLProfile]
560 ///
561 /// # Returns
562 ///
563 /// whether `self` supports the 'precision highp' specifier in GLSL shaders
564 #[cfg(feature = "v1_16")]
565 #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
566 #[doc(alias = "gst_gl_context_supports_precision_highp")]
567 fn supports_precision_highp(&self, version: GLSLVersion, profile: GLSLProfile) -> bool {
568 unsafe {
569 from_glib(ffi::gst_gl_context_supports_precision_highp(
570 self.as_ref().to_glib_none().0,
571 version.into_glib(),
572 profile.into_glib(),
573 ))
574 }
575 }
576
577 /// Swap the front and back buffers on the window attached to `self`.
578 /// This will display the frame on the next refresh cycle.
579 #[doc(alias = "gst_gl_context_swap_buffers")]
580 fn swap_buffers(&self) {
581 unsafe {
582 ffi::gst_gl_context_swap_buffers(self.as_ref().to_glib_none().0);
583 }
584 }
585}
586
587impl<O: IsA<GLContext>> GLContextExt for O {}