@@ -12,7 +12,7 @@ pub mod ffi {
12
12
13
13
use crate :: {
14
14
Api , ContextError , CreationError , GlAttributes , GlProfile , GlRequest ,
15
- PixelFormatRequirements , Robustness ,
15
+ PixelFormatRequirements , Robustness , ContextBuilderWrapper , PixelFormat
16
16
} ;
17
17
use crate :: platform_impl:: PlatformAttributes ;
18
18
@@ -24,6 +24,10 @@ use std::os::raw;
24
24
#[ derive( Debug ) ]
25
25
pub struct OsMesaContext {
26
26
context : osmesa_sys:: OSMesaContext ,
27
+ }
28
+
29
+ #[ derive( Debug ) ]
30
+ pub struct OsMesaBuffer {
27
31
buffer : Vec < u32 > ,
28
32
width : u32 ,
29
33
height : u32 ,
@@ -70,20 +74,17 @@ impl std::error::Error for LoadingError {
70
74
71
75
impl OsMesaContext {
72
76
pub fn new (
73
- _pf_reqs : & PixelFormatRequirements ,
74
- opengl : & GlAttributes < & OsMesaContext > ,
75
- _: & PlatformAttributes ,
76
- size : dpi:: PhysicalSize ,
77
+ cb : ContextBuilderWrapper < & ' _ OsMesaContext > ,
77
78
) -> Result < Self , CreationError > {
78
79
osmesa_sys:: OsMesa :: try_loading ( )
79
80
. map_err ( LoadingError :: new)
80
81
. map_err ( |e| CreationError :: NoBackendAvailable ( Box :: new ( e) ) ) ?;
81
82
82
- if opengl . sharing . is_some ( ) {
83
+ if cb . gl_attr . sharing . is_some ( ) {
83
84
panic ! ( "Context sharing not possible with OsMesa" )
84
85
}
85
86
86
- match opengl . robustness {
87
+ match cb . gl_attr . robustness {
87
88
Robustness :: RobustNoResetNotification
88
89
| Robustness :: RobustLoseContextOnReset => {
89
90
return Err ( CreationError :: RobustnessNotSupported . into ( ) ) ;
@@ -95,7 +96,7 @@ impl OsMesaContext {
95
96
96
97
let mut attribs = Vec :: new ( ) ;
97
98
98
- if let Some ( profile) = opengl . profile {
99
+ if let Some ( profile) = cb . gl_attr . profile {
99
100
attribs. push ( osmesa_sys:: OSMESA_PROFILE ) ;
100
101
101
102
match profile {
@@ -108,7 +109,7 @@ impl OsMesaContext {
108
109
}
109
110
}
110
111
111
- match opengl . version {
112
+ match cb . gl_attr . version {
112
113
GlRequest :: Latest => { }
113
114
GlRequest :: Specific ( Api :: OpenGl , ( major, minor) ) => {
114
115
attribs. push ( osmesa_sys:: OSMESA_CONTEXT_MAJOR_VERSION ) ;
@@ -136,14 +137,7 @@ impl OsMesaContext {
136
137
// attribs array must be NULL terminated.
137
138
attribs. push ( 0 ) ;
138
139
139
- let size: ( u32 , u32 ) = size. into ( ) ;
140
-
141
140
Ok ( OsMesaContext {
142
- width : size. 0 ,
143
- height : size. 1 ,
144
- buffer : std:: iter:: repeat ( unsafe { std:: mem:: uninitialized ( ) } )
145
- . take ( ( size. 0 * size. 1 ) as usize )
146
- . collect ( ) ,
147
141
context : unsafe {
148
142
let ctx = osmesa_sys:: OSMesaCreateContextAttribs (
149
143
attribs. as_ptr ( ) ,
@@ -160,13 +154,13 @@ impl OsMesaContext {
160
154
}
161
155
162
156
#[ inline]
163
- pub unsafe fn make_current ( & self ) -> Result < ( ) , ContextError > {
157
+ pub unsafe fn make_current_osmesa_buffer ( & self , buffer : & mut OsMesaBuffer ) -> Result < ( ) , ContextError > {
164
158
let ret = osmesa_sys:: OSMesaMakeCurrent (
165
159
self . context ,
166
- self . buffer . as_ptr ( ) as * mut _ ,
160
+ buffer . buffer . as_ptr ( ) as * mut _ ,
167
161
0x1401 ,
168
- self . width as raw:: c_int ,
169
- self . height as raw:: c_int ,
162
+ buffer . width as raw:: c_int ,
163
+ buffer . height as raw:: c_int ,
170
164
) ;
171
165
172
166
// an error can only happen in case of invalid parameter, which would
@@ -190,6 +184,11 @@ impl OsMesaContext {
190
184
// and seeing if it work.
191
185
//
192
186
// https://gitlab.freedesktop.org/mesa/mesa/merge_requests/533
187
+ //
188
+ // EDIT: 2019/06/13: This PR has recieved no attention, and will
189
+ // likely never be merged in my lifetime :/
190
+ //
191
+ // Honestly, just go use EGL-Surfaceless!
193
192
let ret = osmesa_sys:: OSMesaMakeCurrent (
194
193
std:: ptr:: null_mut ( ) ,
195
194
std:: ptr:: null_mut ( ) ,
@@ -243,3 +242,26 @@ impl Drop for OsMesaContext {
243
242
244
243
unsafe impl Send for OsMesaContext { }
245
244
unsafe impl Sync for OsMesaContext { }
245
+
246
+ impl OsMesaBuffer {
247
+ pub fn new ( ctx : & OsMesaContext , size : dpi:: PhysicalSize ) -> Result < Self , CreationError > {
248
+ let size: ( u32 , u32 ) = size. into ( ) ;
249
+ Ok ( OsMesaBuffer {
250
+ width : size. 0 ,
251
+ height : size. 1 ,
252
+ buffer : std:: iter:: repeat ( unsafe { std:: mem:: uninitialized ( ) } )
253
+ . take ( ( size. 0 * size. 1 ) as usize )
254
+ . collect ( ) ,
255
+ } )
256
+ }
257
+
258
+ #[ inline]
259
+ pub fn is_current ( & self ) -> bool {
260
+ panic ! ( "This cannot be implemented with OsMesa." )
261
+ }
262
+
263
+ #[ inline]
264
+ pub fn get_pixel_format ( & self ) -> PixelFormat {
265
+ unimplemented ! ( )
266
+ }
267
+ }
0 commit comments