-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathmod.rs
More file actions
101 lines (86 loc) · 2.27 KB
/
mod.rs
File metadata and controls
101 lines (86 loc) · 2.27 KB
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
use std::ffi::c_void;
use std::rc::{Rc, Weak};
#[cfg(target_os = "windows")]
pub(crate) mod win;
#[cfg(target_os = "windows")]
pub(crate) use win as platform;
#[cfg(target_os = "linux")]
pub(crate) mod x11;
#[cfg(target_os = "linux")]
pub(crate) use x11 as platform;
#[cfg(target_os = "macos")]
pub(crate) mod macos;
#[cfg(target_os = "macos")]
pub(crate) use macos as platform;
#[derive(Clone, Debug)]
pub struct GlConfig {
pub version: (u8, u8),
pub profile: Profile,
pub red_bits: u8,
pub blue_bits: u8,
pub green_bits: u8,
pub alpha_bits: u8,
pub depth_bits: u8,
pub stencil_bits: u8,
pub samples: Option<u8>,
pub srgb: bool,
pub double_buffer: bool,
pub vsync: bool,
}
impl Default for GlConfig {
fn default() -> Self {
GlConfig {
version: (3, 2),
profile: Profile::Core,
red_bits: 8,
blue_bits: 8,
green_bits: 8,
alpha_bits: 8,
depth_bits: 24,
stencil_bits: 8,
samples: None,
srgb: true,
double_buffer: true,
vsync: false,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Profile {
Compatibility,
Core,
}
#[derive(Debug)]
pub enum GlError {
InvalidWindowHandle,
VersionNotSupported,
CreationFailed(platform::CreationFailedError),
}
pub struct GlContext {
context: Weak<platform::GlContext>,
}
impl GlContext {
pub(crate) fn new(context: Weak<platform::GlContext>) -> GlContext {
GlContext { context }
}
fn context(&self) -> Rc<platform::GlContext> {
self.context.upgrade().expect("GL context has been destroyed")
}
pub unsafe fn make_current(&self) {
self.context().make_current();
}
pub unsafe fn make_not_current(&self) {
self.context().make_not_current();
}
pub fn get_proc_address(&self, symbol: &str) -> *const c_void {
self.context().get_proc_address(symbol)
}
pub fn swap_buffers(&self) {
self.context().swap_buffers();
}
/// On macOS the `NSOpenGLView` needs to be resized separtely from our main view.
#[cfg(target_os = "macos")]
pub(crate) fn resize(&self, size: cocoa::foundation::NSSize) {
self.context().resize(size);
}
}