@@ -131,10 +131,21 @@ fn test_wayland_display() -> Option<libloading::Library> {
131
131
Some ( library)
132
132
}
133
133
134
+ #[ derive( Clone , Copy , Debug ) ]
135
+ enum SrgbFrameBufferKind {
136
+ /// No support for SRGB surface
137
+ None ,
138
+ /// Using EGL 1.5's support for colorspaces
139
+ Core ,
140
+ /// Using EGL_KHR_gl_colorspace
141
+ Khr ,
142
+ }
143
+
134
144
/// Choose GLES framebuffer configuration.
135
145
fn choose_config (
136
146
egl : & egl:: DynamicInstance < egl:: EGL1_4 > ,
137
147
display : egl:: Display ,
148
+ srgb_kind : SrgbFrameBufferKind ,
138
149
) -> Result < ( egl:: Config , bool ) , crate :: InstanceError > {
139
150
//TODO: EGL_SLOW_CONFIG
140
151
let tiers = [
@@ -147,7 +158,7 @@ fn choose_config(
147
158
( "native-render" , & [ egl:: NATIVE_RENDERABLE , egl:: TRUE as _ ] ) ,
148
159
] ;
149
160
150
- let mut attributes = Vec :: with_capacity ( 7 ) ;
161
+ let mut attributes = Vec :: with_capacity ( 9 ) ;
151
162
for tier_max in ( 0 ..tiers. len ( ) ) . rev ( ) {
152
163
let name = tiers[ tier_max] . 0 ;
153
164
log:: info!( "\t Trying {}" , name) ;
@@ -156,6 +167,14 @@ fn choose_config(
156
167
for & ( _, tier_attr) in tiers[ ..=tier_max] . iter ( ) {
157
168
attributes. extend_from_slice ( tier_attr) ;
158
169
}
170
+ // make sure the Alpha is enough to support sRGB
171
+ match srgb_kind {
172
+ SrgbFrameBufferKind :: None => { }
173
+ _ => {
174
+ attributes. push ( egl:: ALPHA_SIZE ) ;
175
+ attributes. push ( 8 ) ;
176
+ }
177
+ }
159
178
attributes. push ( egl:: NONE ) ;
160
179
161
180
match egl. choose_first_config ( display, & attributes) {
@@ -227,16 +246,6 @@ fn gl_debug_message_callback(source: u32, gltype: u32, id: u32, severity: u32, m
227
246
}
228
247
}
229
248
230
- #[ derive( Debug ) ]
231
- enum SrgbFrameBufferKind {
232
- /// No support for SRGB surface
233
- None ,
234
- /// Using EGL 1.5's support for colorspaces
235
- Core ,
236
- /// Using EGL_KHR_gl_colorspace
237
- Khr ,
238
- }
239
-
240
249
/// A wrapper around a [`glow::Context`] and the required EGL context that uses locking to guarantee
241
250
/// exclusive access when shared with multiple threads.
242
251
pub struct AdapterContext {
@@ -356,22 +365,34 @@ impl Inner {
356
365
display_extensions. split_whitespace( ) . collect:: <Vec <_>>( )
357
366
) ;
358
367
368
+ let srgb_kind = if version >= ( 1 , 5 ) {
369
+ log:: info!( "\t EGL surface: +srgb" ) ;
370
+ SrgbFrameBufferKind :: Core
371
+ } else if display_extensions. contains ( "EGL_KHR_gl_colorspace" ) {
372
+ log:: info!( "\t EGL surface: +srgb khr" ) ;
373
+ SrgbFrameBufferKind :: Khr
374
+ } else {
375
+ log:: warn!( "\t EGL surface: -srgb" ) ;
376
+ SrgbFrameBufferKind :: None
377
+ } ;
378
+
359
379
if log:: max_level ( ) >= log:: LevelFilter :: Trace {
360
380
log:: trace!( "Configurations:" ) ;
361
381
let config_count = egl. get_config_count ( display) . unwrap ( ) ;
362
382
let mut configurations = Vec :: with_capacity ( config_count) ;
363
383
egl. get_configs ( display, & mut configurations) . unwrap ( ) ;
364
384
for & config in configurations. iter ( ) {
365
- log:: trace!( "\t CONFORMANT=0x{:X}, RENDERABLE=0x{:X}, NATIVE_RENDERABLE=0x{:X}, SURFACE_TYPE=0x{:X}" ,
385
+ log:: trace!( "\t CONFORMANT=0x{:X}, RENDERABLE=0x{:X}, NATIVE_RENDERABLE=0x{:X}, SURFACE_TYPE=0x{:X}, ALPHA_SIZE={} " ,
366
386
egl. get_config_attrib( display, config, egl:: CONFORMANT ) . unwrap( ) ,
367
387
egl. get_config_attrib( display, config, egl:: RENDERABLE_TYPE ) . unwrap( ) ,
368
388
egl. get_config_attrib( display, config, egl:: NATIVE_RENDERABLE ) . unwrap( ) ,
369
389
egl. get_config_attrib( display, config, egl:: SURFACE_TYPE ) . unwrap( ) ,
390
+ egl. get_config_attrib( display, config, egl:: ALPHA_SIZE ) . unwrap( ) ,
370
391
) ;
371
392
}
372
393
}
373
394
374
- let ( config, supports_native_window) = choose_config ( & egl, display) ?;
395
+ let ( config, supports_native_window) = choose_config ( & egl, display, srgb_kind ) ?;
375
396
egl. bind_api ( egl:: OPENGL_ES_API ) . unwrap ( ) ;
376
397
377
398
let needs_robustness = true ;
@@ -439,17 +460,6 @@ impl Inner {
439
460
} ) ?
440
461
} ;
441
462
442
- let srgb_kind = if version >= ( 1 , 5 ) {
443
- log:: info!( "\t EGL surface: +srgb" ) ;
444
- SrgbFrameBufferKind :: Core
445
- } else if display_extensions. contains ( "EGL_KHR_gl_colorspace" ) {
446
- log:: info!( "\t EGL surface: +srgb khr" ) ;
447
- SrgbFrameBufferKind :: Khr
448
- } else {
449
- log:: warn!( "\t EGL surface: -srgb" ) ;
450
- SrgbFrameBufferKind :: None
451
- } ;
452
-
453
463
Ok ( Self {
454
464
egl,
455
465
display,
0 commit comments