@@ -62,9 +62,9 @@ pub use self::egl::Egl;
62
62
use self :: make_current_guard:: MakeCurrentGuard ;
63
63
use crate :: platform_impl:: PlatformAttributes ;
64
64
use crate :: {
65
- Api , ContextBuilderWrapper , ContextError , CreationError , GlAttributes ,
66
- GlRequest , PixelFormat , PixelFormatRequirements , ReleaseBehavior ,
67
- Robustness ,
65
+ Api , ContextBuilderWrapper , ContextError , ContextSupports , CreationError ,
66
+ GlAttributes , GlRequest , PixelFormat , PixelFormatRequirements ,
67
+ ReleaseBehavior , Robustness ,
68
68
} ;
69
69
70
70
use glutin_egl_sys as ffi;
@@ -79,7 +79,7 @@ use parking_lot::Mutex;
79
79
target_os = "openbsd" ,
80
80
) ) ]
81
81
use winit:: dpi;
82
- use winit:: event_loop:: EventLoop ;
82
+ use winit:: event_loop:: EventLoopWindowTarget ;
83
83
84
84
use std:: ffi:: { CStr , CString } ;
85
85
use std:: marker:: PhantomData ;
@@ -387,25 +387,17 @@ fn get_native_display(native_display: &NativeDisplay) -> *const raw::c_void {
387
387
}
388
388
}
389
389
390
- #[ allow( dead_code) ] // Not all platforms use all
391
- #[ derive( Copy , Clone , PartialEq , Debug ) ]
392
- pub enum SurfaceType {
393
- PBuffer ,
394
- Window ,
395
- Surfaceless ,
396
- }
397
-
398
390
impl Context {
399
391
/// Start building an EGL context.
400
392
///
401
393
/// This function initializes some things and chooses the pixel format.
402
394
///
403
395
/// To finish the process, you must call `.finish(window)` on the
404
396
/// `ContextPrototype`.
405
- pub fn new < ' a , F > (
397
+ pub ( crate ) fn new < ' a , F > (
406
398
cb : & ' a ContextBuilderWrapper < & ' a Context > ,
407
399
native_display : NativeDisplay ,
408
- surface_type : SurfaceType ,
400
+ ctx_supports : ContextSupports ,
409
401
config_selector : F ,
410
402
) -> Result < Context , CreationError >
411
403
where
@@ -441,6 +433,19 @@ impl Context {
441
433
vec ! [ ]
442
434
} ;
443
435
436
+ // FIXME: Also check for the GL_OES_surfaceless_context *CONTEXT*
437
+ // extension
438
+ if ctx_supports. contains ( ContextSupports :: SURFACELESS )
439
+ && extensions
440
+ . iter ( )
441
+ . find ( |s| s == & "EGL_KHR_surfaceless_context" )
442
+ . is_none ( )
443
+ {
444
+ return Err ( CreationError :: NotSupported (
445
+ "EGL surfaceless not supported" . to_string ( ) ,
446
+ ) ) ;
447
+ }
448
+
444
449
// binding the right API and choosing the version
445
450
let ( version, api) =
446
451
unsafe { bind_and_get_api ( & cb. gl_attr , egl_version) ? } ;
@@ -452,7 +457,7 @@ impl Context {
452
457
api,
453
458
version,
454
459
cb,
455
- surface_type ,
460
+ ctx_supports ,
456
461
config_selector,
457
462
) ?
458
463
} ;
@@ -712,9 +717,7 @@ impl Context {
712
717
}
713
718
}
714
719
715
- unsafe fn check_make_current (
716
- ret : Option < u32 > ,
717
- ) -> Result < ( ) , ContextError > {
720
+ unsafe fn check_make_current ( ret : Option < u32 > ) -> Result < ( ) , ContextError > {
718
721
let egl = EGL . as_ref ( ) . unwrap ( ) ;
719
722
if ret == Some ( 0 ) {
720
723
match egl. GetError ( ) as u32 {
@@ -841,42 +844,6 @@ pub fn get_native_visual_id(
841
844
value
842
845
}
843
846
844
- // impl<'a> ContextPrototype<'a> {
845
- // #[cfg(any(
846
- // target_os = "linux",
847
- // target_os = "dragonfly",
848
- // target_os = "freebsd",
849
- // target_os = "netbsd",
850
- // target_os = "openbsd",
851
- // ))]
852
- // pub fn finish_surfaceless(self) -> Result<Context, CreationError> {
853
- // FIXME: Also check for the GL_OES_surfaceless_context *CONTEXT*
854
- // extension
855
- // if self
856
- // .extensions
857
- // .iter()
858
- // .find(|s| s == &"EGL_KHR_surfaceless_context")
859
- // .is_none()
860
- // {
861
- // Err(CreationError::NotSupported(
862
- // "EGL surfaceless not supported".to_string(),
863
- // ))
864
- // } else {
865
- // self.finish_impl(None)
866
- // }
867
- // }
868
- //
869
- // #[cfg(any(
870
- // target_os = "android",
871
- // target_os = "windows",
872
- // target_os = "linux",
873
- // target_os = "dragonfly",
874
- // target_os = "freebsd",
875
- // target_os = "netbsd",
876
- // target_os = "openbsd",
877
- // ))]
878
- // }
879
-
880
847
pub trait SurfaceTypeTrait { }
881
848
882
849
#[ derive( Debug ) ]
@@ -901,7 +868,7 @@ pub struct EGLSurface<T: SurfaceTypeTrait> {
901
868
impl WindowSurface {
902
869
#[ inline]
903
870
pub fn new_window_surface < T > (
904
- el : & EventLoop < T > ,
871
+ el : & EventLoopWindowTarget < T > ,
905
872
ctx : & Context ,
906
873
nwin : ffi:: EGLNativeWindowType ,
907
874
) -> Result < Self , CreationError > {
@@ -953,33 +920,12 @@ impl WindowSurface {
953
920
Ok ( ( ) )
954
921
}
955
922
}
956
-
957
- #[ inline]
958
- pub unsafe fn make_not_current ( & self ) -> Result < ( ) , ContextError > {
959
- let egl = EGL . as_ref ( ) . unwrap ( ) ;
960
-
961
- if
962
- egl. GetCurrentSurface ( ffi:: egl:: DRAW as i32 ) == self . surface
963
- || egl. GetCurrentSurface ( ffi:: egl:: READ as i32 ) == self . surface {
964
- let ret = egl. MakeCurrent (
965
- * * self . display ,
966
- ffi:: egl:: NO_SURFACE ,
967
- ffi:: egl:: NO_SURFACE ,
968
- ffi:: egl:: NO_CONTEXT ,
969
- ) ;
970
-
971
- check_make_current ( Some ( ret) )
972
- } else {
973
- check_make_current ( None )
974
- }
975
- }
976
-
977
923
}
978
924
979
925
impl PBuffer {
980
926
#[ inline]
981
927
pub fn new_pbuffer < T > (
982
- _el : & EventLoop < T > ,
928
+ _el : & EventLoopWindowTarget < T > ,
983
929
ctx : & Context ,
984
930
size : dpi:: PhysicalSize ,
985
931
) -> Result < Self , CreationError > {
@@ -1022,14 +968,30 @@ impl PBuffer {
1022
968
phantom : PhantomData ,
1023
969
} )
1024
970
}
971
+ }
972
+
973
+ impl < T : SurfaceTypeTrait > EGLSurface < T > {
974
+ #[ inline]
975
+ pub fn is_current ( & self ) -> bool {
976
+ let egl = EGL . as_ref ( ) . unwrap ( ) ;
977
+ unsafe {
978
+ egl. GetCurrentSurface ( ffi:: egl:: DRAW as i32 ) == self . surface
979
+ || egl. GetCurrentSurface ( ffi:: egl:: READ as i32 ) == self . surface
980
+ }
981
+ }
982
+
983
+ #[ inline]
984
+ pub fn get_pixel_format ( & self ) -> PixelFormat {
985
+ self . pixel_format . clone ( )
986
+ }
1025
987
1026
988
#[ inline]
1027
989
pub unsafe fn make_not_current ( & self ) -> Result < ( ) , ContextError > {
1028
990
let egl = EGL . as_ref ( ) . unwrap ( ) ;
1029
991
1030
- if
1031
- egl. GetCurrentSurface ( ffi:: egl:: DRAW as i32 ) == self . surface
1032
- || egl . GetCurrentSurface ( ffi :: egl :: READ as i32 ) == self . surface {
992
+ if egl . GetCurrentSurface ( ffi :: egl :: DRAW as i32 ) == self . surface
993
+ || egl. GetCurrentSurface ( ffi:: egl:: READ as i32 ) == self . surface
994
+ {
1033
995
let ret = egl. MakeCurrent (
1034
996
* * self . display ,
1035
997
ffi:: egl:: NO_SURFACE ,
@@ -1042,23 +1004,6 @@ impl PBuffer {
1042
1004
check_make_current ( None )
1043
1005
}
1044
1006
}
1045
-
1046
- }
1047
-
1048
- impl < T : SurfaceTypeTrait > EGLSurface < T > {
1049
- #[ inline]
1050
- pub fn is_current ( & self ) -> bool {
1051
- let egl = EGL . as_ref ( ) . unwrap ( ) ;
1052
- unsafe {
1053
- egl. GetCurrentSurface ( ffi:: egl:: DRAW as i32 ) == self . surface
1054
- || egl. GetCurrentSurface ( ffi:: egl:: READ as i32 ) == self . surface
1055
- }
1056
- }
1057
-
1058
- #[ inline]
1059
- pub fn get_pixel_format ( & self ) -> PixelFormat {
1060
- self . pixel_format . clone ( )
1061
- }
1062
1007
}
1063
1008
1064
1009
impl < T : SurfaceTypeTrait > Drop for EGLSurface < T > {
@@ -1086,7 +1031,7 @@ unsafe fn choose_fbconfig<F>(
1086
1031
api : Api ,
1087
1032
version : Option < ( u8 , u8 ) > ,
1088
1033
cb : & ContextBuilderWrapper < & Context > ,
1089
- surface_type : SurfaceType ,
1034
+ ctx_supports : ContextSupports ,
1090
1035
mut config_selector : F ,
1091
1036
) -> Result < ( ffi:: egl:: types:: EGLConfig , PixelFormat ) , CreationError >
1092
1037
where
@@ -1106,11 +1051,15 @@ where
1106
1051
}
1107
1052
1108
1053
out. push ( ffi:: egl:: SURFACE_TYPE as raw:: c_int ) ;
1109
- let surface_type = match surface_type {
1110
- SurfaceType :: Window => ffi:: egl:: WINDOW_BIT ,
1111
- SurfaceType :: PBuffer => ffi:: egl:: PBUFFER_BIT ,
1112
- SurfaceType :: Surfaceless => 0 ,
1113
- } ;
1054
+ let mut surface_type =
1055
+ if ctx_supports. contains ( ContextSupports :: WINDOW_SURFACES ) {
1056
+ ffi:: egl:: WINDOW_BIT
1057
+ } else {
1058
+ 0
1059
+ } ;
1060
+ if ctx_supports. contains ( ContextSupports :: PBUFFERS ) {
1061
+ surface_type = surface_type | ffi:: egl:: PBUFFER_BIT
1062
+ }
1114
1063
out. push ( surface_type as raw:: c_int ) ;
1115
1064
1116
1065
match ( api, version) {
@@ -1424,12 +1373,12 @@ unsafe fn create_context(
1424
1373
context_attributes. push ( ffi:: egl:: TRUE as i32 ) ;
1425
1374
}
1426
1375
1427
- // TODO: using this flag sometimes generates an error
1428
- // there was a change in the specs that added this flag, so it
1429
- // may not be supported everywhere ; however it is
1430
- // not possible to know whether it is supported or
1431
- // not flags = flags |
1432
- // ffi::egl::CONTEXT_OPENGL_DEBUG_BIT_KHR as i32;
1376
+ // TODO: using this flag sometimes generates an error there was a
1377
+ // change in the specs that added this flag, so it may not be
1378
+ // supported everywhere; however it is not possible to know whether
1379
+ // it is supported or not
1380
+ //
1381
+ // flags = flags | ffi::egl::CONTEXT_OPENGL_DEBUG_BIT_KHR as i32;
1433
1382
}
1434
1383
1435
1384
// In at least some configurations, the Android emulator’s GL
0 commit comments