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
#![allow(unused_imports)]
use crate::Gl;
use crate::gl::types::GLuint;
use crate::gl;
use crate::info::GLVersion;
use std::ffi::CStr;
use std::os::raw::c_char;
use std::sync::Mutex;
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct ContextID(pub u64);
lazy_static! {
#[doc(hidden)]
pub static ref CREATE_CONTEXT_MUTEX: Mutex<ContextID> = Mutex::new(ContextID(0));
}
bitflags! {
pub struct ContextAttributeFlags: u8 {
const ALPHA = 0x01;
const DEPTH = 0x02;
const STENCIL = 0x04;
const COMPATIBILITY_PROFILE = 0x08;
}
}
#[derive(Clone, Copy, PartialEq, Debug)]
pub struct ContextAttributes {
pub version: GLVersion,
pub flags: ContextAttributeFlags,
}
impl ContextAttributes {
#[allow(dead_code)]
pub(crate) fn zeroed() -> ContextAttributes {
ContextAttributes { version: GLVersion::new(0, 0), flags: ContextAttributeFlags::empty() }
}
}
#[cfg(target_os = "android")]
pub(crate) fn current_context_uses_compatibility_profile(_gl: &Gl) -> bool {
false
}
#[cfg(not(target_os = "android"))]
#[allow(dead_code)]
pub(crate) fn current_context_uses_compatibility_profile(gl: &Gl) -> bool {
unsafe {
let mut context_profile_mask = 0;
gl.GetIntegerv(gl::CONTEXT_PROFILE_MASK, &mut context_profile_mask);
if gl.GetError() == gl::NO_ERROR &&
(context_profile_mask & gl::CONTEXT_COMPATIBILITY_PROFILE_BIT as i32) != 0 {
return true;
}
let mut num_extensions = 0;
gl.GetIntegerv(gl::NUM_EXTENSIONS, &mut num_extensions);
if gl.GetError() == gl::NO_ERROR {
for extension_index in 0..(num_extensions as GLuint) {
let extension = gl.GetStringi(gl::EXTENSIONS, extension_index) as *const c_char;
let extension = CStr::from_ptr(extension);
if extension.to_str() == Ok("GL_ARB_compatibility") {
return true;
}
}
}
false
}
}