@@ -439,6 +439,7 @@ impl Context {
439
439
version,
440
440
pf_reqs,
441
441
surface_type,
442
+ opengl,
442
443
config_selector,
443
444
) ?
444
445
} ;
@@ -969,6 +970,26 @@ impl<'a> ContextPrototype<'a> {
969
970
}
970
971
} ;
971
972
973
+ if let Some ( surface) = surface {
974
+ // VSync defaults to enabled; disable it if it was not requested.
975
+ if !self . opengl . vsync {
976
+ let _guard = MakeCurrentGuard :: new (
977
+ self . display ,
978
+ surface,
979
+ surface,
980
+ context,
981
+ )
982
+ . map_err ( |err| CreationError :: OsError ( err) ) ?;
983
+
984
+ let egl = EGL . as_ref ( ) . unwrap ( ) ;
985
+ unsafe {
986
+ if egl. SwapInterval ( self . display , 0 ) == ffi:: egl:: FALSE {
987
+ panic ! ( "finish_impl: eglSwapInterval failed: 0x{:x}" , egl. GetError ( ) ) ;
988
+ }
989
+ }
990
+ }
991
+ }
992
+
972
993
Ok ( Context {
973
994
display : self . display ,
974
995
context,
@@ -988,6 +1009,7 @@ unsafe fn choose_fbconfig<F>(
988
1009
version : Option < ( u8 , u8 ) > ,
989
1010
pf_reqs : & PixelFormatRequirements ,
990
1011
surface_type : SurfaceType ,
1012
+ opengl : & GlAttributes < & Context > ,
991
1013
mut config_selector : F ,
992
1014
) -> Result < ( ffi:: egl:: types:: EGLConfig , PixelFormat ) , CreationError >
993
1015
where
@@ -1157,7 +1179,42 @@ where
1157
1179
) ) ;
1158
1180
}
1159
1181
1160
- if num_configs == 0 {
1182
+ // We're interested in those configs which allow our desired VSync.
1183
+ let desired_swap_interval = if opengl. vsync {
1184
+ 1
1185
+ } else {
1186
+ 0
1187
+ } ;
1188
+
1189
+ let config_ids = config_ids. into_iter ( ) . filter ( |& config| {
1190
+ let mut min_swap_interval = 0 ;
1191
+ let res = egl. GetConfigAttrib (
1192
+ display,
1193
+ config,
1194
+ ffi:: egl:: MIN_SWAP_INTERVAL as ffi:: egl:: types:: EGLint ,
1195
+ & mut min_swap_interval,
1196
+ ) ;
1197
+
1198
+ if desired_swap_interval < min_swap_interval {
1199
+ return false ;
1200
+ }
1201
+
1202
+ let mut max_swap_interval = 0 ;
1203
+ let res = egl. GetConfigAttrib (
1204
+ display,
1205
+ config,
1206
+ ffi:: egl:: MAX_SWAP_INTERVAL as ffi:: egl:: types:: EGLint ,
1207
+ & mut max_swap_interval,
1208
+ ) ;
1209
+
1210
+ if desired_swap_interval > max_swap_interval {
1211
+ return false ;
1212
+ }
1213
+
1214
+ true
1215
+ } ) . collect :: < Vec < _ > > ( ) ;
1216
+
1217
+ if config_ids. is_empty ( ) {
1161
1218
return Err ( CreationError :: NoAvailablePixelFormat ) ;
1162
1219
}
1163
1220
0 commit comments