surfman/
info.rs

1// surfman/surfman/src/info.rs
2//
3//! OpenGL information.
4
5use crate::Gl;
6use glow::HasContext;
7
8/// The API (OpenGL or OpenGL ES).
9#[derive(Clone, Copy, Debug, PartialEq)]
10pub enum GLApi {
11    /// OpenGL (full or desktop OpenGL).
12    GL,
13    /// OpenGL ES (embedded OpenGL).
14    GLES,
15}
16
17/// Describes the OpenGL version that is requested when a context is created.
18///
19/// Since OpenGL and OpenGL ES have different version numbering schemes, the valid values here
20/// depend on the value of `Device::gl_api()`.
21#[derive(Clone, Copy, Debug, PartialEq)]
22pub struct GLVersion {
23    /// The major OpenGL version (e.g. 4 in 4.2).
24    pub major: u8,
25    /// The minor OpenGL version (e.g. 2 in 4.2).
26    pub minor: u8,
27}
28
29impl GLVersion {
30    /// Creates a GL version structure with the given major and minor version numbers.
31    #[inline]
32    pub fn new(major: u8, minor: u8) -> GLVersion {
33        GLVersion { major, minor }
34    }
35
36    #[allow(dead_code)]
37    pub(crate) fn current(gl: &Gl) -> GLVersion {
38        let version = gl.version();
39        Self {
40            major: version.major as u8,
41            minor: version.minor as u8,
42        }
43    }
44}