@@ -555,58 +555,61 @@ impl Context {
555
555
} )
556
556
}
557
557
558
- unsafe fn check_make_current (
558
+ unsafe fn make_current (
559
559
& self ,
560
- ret : Option < u32 > ,
560
+ surface : ffi :: egl :: types :: EGLSurface ,
561
561
) -> Result < ( ) , ContextError > {
562
562
let egl = EGL . as_ref ( ) . unwrap ( ) ;
563
- if ret == Some ( 0 ) {
564
- match egl. GetError ( ) as u32 {
565
- ffi:: egl:: CONTEXT_LOST => Err ( ContextError :: ContextLost ) ,
566
- err => panic ! (
567
- "make_current: eglMakeCurrent failed (eglGetError returned 0x{:x})" ,
568
- err
569
- ) ,
570
- }
571
- } else {
572
- Ok ( ( ) )
573
- }
563
+ let ret =
564
+ egl. MakeCurrent ( * * self . display , surface, surface, self . context ) ;
565
+
566
+ check_make_current ( Some ( ret) )
574
567
}
575
568
576
- pub unsafe fn make_current ( & self ) -> Result < ( ) , ContextError > {
569
+ #[ inline]
570
+ pub unsafe fn make_current_surfaceless ( & self ) -> Result < ( ) , ContextError > {
577
571
let egl = EGL . as_ref ( ) . unwrap ( ) ;
578
- let surface = if self . surface . is_null ( ) {
579
- ffi:: egl:: NO_SURFACE
580
- } else {
581
- self . surface
582
- } ;
583
- let ret =
584
- egl. MakeCurrent ( * * self . display , surface, surface, self . context ) ;
572
+ let ret = egl. MakeCurrent (
573
+ * * self . display ,
574
+ ffi:: egl:: NO_SURFACE ,
575
+ ffi:: egl:: NO_SURFACE ,
576
+ self . context ,
577
+ ) ;
578
+
579
+ check_make_current ( Some ( ret) )
580
+ }
585
581
586
- self . check_make_current ( Some ( ret) )
582
+ #[ inline]
583
+ pub unsafe fn make_current_window (
584
+ & self ,
585
+ surface : & WindowSurface ,
586
+ ) -> Result < ( ) , ContextError > {
587
+ self . make_current ( surface. surface )
587
588
}
588
589
590
+ #[ inline]
591
+ pub unsafe fn make_current_pbuffer (
592
+ & self ,
593
+ pbuffer : & PBuffer ,
594
+ ) -> Result < ( ) , ContextError > {
595
+ self . make_current ( pbuffer. surface )
596
+ }
597
+
598
+ #[ inline]
589
599
pub unsafe fn make_not_current ( & self ) -> Result < ( ) , ContextError > {
590
600
let egl = EGL . as_ref ( ) . unwrap ( ) ;
591
601
592
- let surface_eq = if let Some ( surface) = self . surface {
593
- egl. GetCurrentSurface ( ffi:: egl:: DRAW as i32 ) == surface
594
- || egl. GetCurrentSurface ( ffi:: egl:: READ as i32 ) == surface
595
- } else {
596
- false
597
- } ;
598
-
599
- if surface_eq || egl. GetCurrentContext ( ) == self . context {
602
+ if egl. GetCurrentContext ( ) == self . context {
600
603
let ret = egl. MakeCurrent (
601
604
* * self . display ,
602
605
ffi:: egl:: NO_SURFACE ,
603
606
ffi:: egl:: NO_SURFACE ,
604
607
ffi:: egl:: NO_CONTEXT ,
605
608
) ;
606
609
607
- self . check_make_current ( Some ( ret) )
610
+ check_make_current ( Some ( ret) )
608
611
} else {
609
- self . check_make_current ( None )
612
+ check_make_current ( None )
610
613
}
611
614
}
612
615
@@ -709,6 +712,23 @@ impl Context {
709
712
}
710
713
}
711
714
715
+ unsafe fn check_make_current (
716
+ ret : Option < u32 > ,
717
+ ) -> Result < ( ) , ContextError > {
718
+ let egl = EGL . as_ref ( ) . unwrap ( ) ;
719
+ if ret == Some ( 0 ) {
720
+ match egl. GetError ( ) as u32 {
721
+ ffi:: egl:: CONTEXT_LOST => Err ( ContextError :: ContextLost ) ,
722
+ err => panic ! (
723
+ "make_current: eglMakeCurrent failed (eglGetError returned 0x{:x})" ,
724
+ err
725
+ ) ,
726
+ }
727
+ } else {
728
+ Ok ( ( ) )
729
+ }
730
+ }
731
+
712
732
unsafe impl Send for Context { }
713
733
unsafe impl Sync for Context { }
714
734
@@ -857,12 +877,12 @@ pub fn get_native_visual_id(
857
877
// ))]
858
878
// }
859
879
860
- trait SurfaceTypeTrait { }
880
+ pub trait SurfaceTypeTrait { }
861
881
862
882
#[ derive( Debug ) ]
863
- enum WindowSurfaceType { }
883
+ pub enum WindowSurfaceType { }
864
884
#[ derive( Debug ) ]
865
- enum PBufferSurfaceType { }
885
+ pub enum PBufferSurfaceType { }
866
886
867
887
impl SurfaceTypeTrait for WindowSurfaceType { }
868
888
impl SurfaceTypeTrait for PBufferSurfaceType { }
@@ -933,6 +953,27 @@ impl WindowSurface {
933
953
Ok ( ( ) )
934
954
}
935
955
}
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
+
936
977
}
937
978
938
979
impl PBuffer {
@@ -961,17 +1002,17 @@ impl PBuffer {
961
1002
] ;
962
1003
963
1004
let surface = unsafe {
964
- let surface = egl. CreatePbufferSurface (
1005
+ let pbuffer = egl. CreatePbufferSurface (
965
1006
* * ctx. display ,
966
1007
ctx. config_id ,
967
1008
attrs. as_ptr ( ) ,
968
1009
) ;
969
- if surface . is_null ( ) || surface == ffi:: egl:: NO_SURFACE {
1010
+ if pbuffer . is_null ( ) || pbuffer == ffi:: egl:: NO_SURFACE {
970
1011
return Err ( CreationError :: OsError (
971
1012
"eglCreatePbufferSurface failed" . to_string ( ) ,
972
1013
) ) ;
973
1014
}
974
- surface
1015
+ pbuffer
975
1016
} ;
976
1017
977
1018
Ok ( PBuffer {
@@ -981,6 +1022,27 @@ impl PBuffer {
981
1022
phantom : PhantomData ,
982
1023
} )
983
1024
}
1025
+
1026
+ #[ inline]
1027
+ pub unsafe fn make_not_current ( & self ) -> Result < ( ) , ContextError > {
1028
+ let egl = EGL . as_ref ( ) . unwrap ( ) ;
1029
+
1030
+ if
1031
+ egl. GetCurrentSurface ( ffi:: egl:: DRAW as i32 ) == self . surface
1032
+ || egl. GetCurrentSurface ( ffi:: egl:: READ as i32 ) == self . surface {
1033
+ let ret = egl. MakeCurrent (
1034
+ * * self . display ,
1035
+ ffi:: egl:: NO_SURFACE ,
1036
+ ffi:: egl:: NO_SURFACE ,
1037
+ ffi:: egl:: NO_CONTEXT ,
1038
+ ) ;
1039
+
1040
+ check_make_current ( Some ( ret) )
1041
+ } else {
1042
+ check_make_current ( None )
1043
+ }
1044
+ }
1045
+
984
1046
}
985
1047
986
1048
impl < T : SurfaceTypeTrait > EGLSurface < T > {
0 commit comments