cogl/auto/gles2_context.rs
1use crate::{Context, Object};
2
3use glib::translate::*;
4use std::{fmt, ptr};
5
6glib_wrapper! {
7 pub struct GLES2Context(Object<ffi::CoglGLES2Context, GLES2ContextClass>) @extends Object;
8
9 match fn {
10 get_type => || ffi::cogl_gles2_context_get_gtype(),
11 }
12}
13
14impl GLES2Context {
15 /// Allocates a new OpenGLES 2.0 context that can be used to render to
16 /// `CoglOffscreen` framebuffers (Rendering to `Onscreen`
17 /// framebuffers is not currently supported).
18 ///
19 /// To actually access the OpenGLES 2.0 api itself you need to use
20 /// `GLES2Context::get_vtable`. You should not try to directly link
21 /// to and use the symbols provided by the a system OpenGLES 2.0
22 /// driver.
23 ///
24 /// Once you have allocated an OpenGLES 2.0 context you can make it
25 /// current using `cogl_push_gles2_context`. For those familiar with
26 /// using the EGL api, this serves a similar purpose to eglMakeCurrent.
27 ///
28 /// `<note>`Before using this api applications can check for OpenGLES 2.0
29 /// api support by checking for `FeatureID::OglFeatureIdGles2Context` support
30 /// with `cogl_has_feature`. This function will return `false` and
31 /// return an `GLES2ContextError::Unsupported` error if the
32 /// feature isn't available.`</note>`
33 ///
34 /// ## `ctx`
35 /// A `Context`
36 ///
37 /// # Returns
38 ///
39 /// A newly allocated `GLES2Context` or `None` if there
40 /// was an error and `error` will be updated in that case.
41 pub fn new(ctx: &Context) -> Result<GLES2Context, glib::Error> {
42 unsafe {
43 let mut error = ptr::null_mut();
44 let ret = ffi::cogl_gles2_context_new(ctx.to_glib_none().0, &mut error);
45 if error.is_null() {
46 Ok(from_glib_full(ret))
47 } else {
48 Err(from_glib_full(error))
49 }
50 }
51 }
52
53 // /// Queries the OpenGLES 2.0 api function pointers that should be
54 // /// used for rendering with the given `self`.
55 // ///
56 // /// `<note>`You should not try to directly link to and use the symbols
57 // /// provided by any system OpenGLES 2.0 driver.`</note>`
58 // ///
59 // ///
60 // /// # Returns
61 // ///
62 // /// A pointer to a `GLES2Vtable` providing pointers
63 // /// to functions for the full OpenGLES 2.0 api.
64 // pub fn get_vtable(&self) -> Option<GLES2Vtable> {
65 // unsafe {
66 // from_glib_none(ffi::cogl_gles2_context_get_vtable(
67 // self.to_glib_none().0,
68 // ))
69 // }
70 // }
71}
72
73impl fmt::Display for GLES2Context {
74 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
75 write!(f, "GLES2Context")
76 }
77}