Skip to content

Commit c3dc3b6

Browse files
committed
OsMesa
Signed-off-by: Hal Gentz <zegentzy@protonmail.com>
1 parent 2371bc9 commit c3dc3b6

File tree

6 files changed

+164
-54
lines changed

6 files changed

+164
-54
lines changed

glutin/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ serde = ["winit/serde"]
1919
[dependencies]
2020
lazy_static = "1.3"
2121
winit = "0.20.0-alpha1"
22-
log = "0.4"
2322
bitflags = "1.1"
2423

2524
[target.'cfg(target_os = "android")'.dependencies]
@@ -60,3 +59,4 @@ glutin_egl_sys = { version = "0.1.3", path = "../glutin_egl_sys" }
6059
glutin_glx_sys = { version = "0.1.5", path = "../glutin_glx_sys" }
6160
derivative = "1.0"
6261
parking_lot = "0.8"
62+
log = "0.4"

glutin/src/api/osmesa.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use crate::{
1919
use winit::dpi;
2020

2121
use std::ffi::CString;
22-
use std::os::raw;
2322
use std::mem::MaybeUninit;
23+
use std::os::raw;
2424

2525
#[derive(Debug)]
2626
pub struct OsMesaContext {
@@ -159,7 +159,7 @@ impl OsMesaContext {
159159
#[inline]
160160
pub unsafe fn make_current_osmesa_buffer(
161161
&self,
162-
buffer: &mut OsMesaBuffer,
162+
buffer: &OsMesaBuffer,
163163
) -> Result<(), ContextError> {
164164
let ret = osmesa_sys::OSMesaMakeCurrent(
165165
self.context,

glutin/src/lib.rs

+7
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ extern crate lazy_static;
8383
#[cfg(any(target_os = "macos", target_os = "ios"))]
8484
#[macro_use]
8585
extern crate objc;
86+
#[cfg(any(
87+
target_os = "linux",
88+
target_os = "dragonfly",
89+
target_os = "freebsd",
90+
target_os = "netbsd",
91+
target_os = "openbsd",
92+
))]
8693
#[macro_use]
8794
extern crate log;
8895
#[cfg(any(

glutin/src/platform/unix.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
target_os = "openbsd",
77
))]
88

9+
pub mod osmesa;
910
// mod rawext;
1011

1112
use crate::platform::ContextTraitExt;

glutin/src/platform/unix/osmesa.rs

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
use crate::api::osmesa;
2+
use crate::{
3+
Api, ContextBuilderWrapper, ContextError, CreationError, PixelFormat,
4+
};
5+
use winit::dpi;
6+
7+
#[derive(Debug)]
8+
pub struct OsMesaContext {
9+
pub(crate) context: osmesa::OsMesaContext,
10+
}
11+
12+
pub trait OsMesaContextExt {
13+
fn build_osmesa(self) -> Result<OsMesaContext, CreationError>
14+
where
15+
Self: Sized;
16+
}
17+
18+
impl<'a> OsMesaContextExt for OsMesaContextBuilder<'a> {
19+
#[inline]
20+
fn build_osmesa(self) -> Result<OsMesaContext, CreationError>
21+
where
22+
Self: Sized,
23+
{
24+
let cb = self.map_sharing(|ctx| &ctx.context);
25+
osmesa::OsMesaContext::new(cb).map(|context| OsMesaContext { context })
26+
}
27+
}
28+
29+
pub type OsMesaContextBuilder<'a> = ContextBuilderWrapper<&'a OsMesaContext>;
30+
31+
#[derive(Debug)]
32+
pub struct OsMesaBuffer {
33+
pub(crate) buffer: osmesa::OsMesaBuffer,
34+
}
35+
36+
impl OsMesaContext {
37+
/// Returns the address of an OpenGL function.
38+
pub fn get_proc_address(&self, addr: &str) -> *const () {
39+
self.context.get_proc_address(addr)
40+
}
41+
42+
pub fn is_current(&self) -> bool {
43+
self.context.is_current()
44+
}
45+
46+
pub fn get_api(&self) -> Api {
47+
self.context.get_api()
48+
}
49+
50+
pub unsafe fn make_current_osmesa_buffer(
51+
&self,
52+
buffer: &OsMesaBuffer,
53+
) -> Result<(), ContextError> {
54+
self.context.make_current_osmesa_buffer(buffer.inner())
55+
}
56+
57+
pub unsafe fn make_not_current(&self) -> Result<(), ContextError> {
58+
self.context.make_not_current()
59+
}
60+
61+
pub(crate) fn inner(&self) -> &osmesa::OsMesaContext {
62+
&self.context
63+
}
64+
}
65+
66+
impl OsMesaBuffer {
67+
pub(crate) fn inner(&self) -> &osmesa::OsMesaBuffer {
68+
&self.buffer
69+
}
70+
71+
pub fn get_pixel_format(&self) -> PixelFormat {
72+
self.buffer.get_pixel_format()
73+
}
74+
75+
pub fn new(
76+
ctx: &OsMesaContext,
77+
size: dpi::PhysicalSize,
78+
) -> Result<OsMesaBuffer, CreationError> {
79+
let ctx = ctx.inner();
80+
osmesa::OsMesaBuffer::new(ctx, size)
81+
.map(|buffer| OsMesaBuffer { buffer })
82+
}
83+
}

0 commit comments

Comments
 (0)