video: Add SDL_GL_SetSwapInterval binding.
authorDavid Thompson <dthompson2@worcester.edu>
Sat, 9 Jan 2016 02:38:32 +0000 (21:38 -0500)
committerDavid Thompson <dthompson2@worcester.edu>
Sat, 9 Jan 2016 02:38:32 +0000 (21:38 -0500)
* sdl2/bindings.scm (sdl-gl-set-swap-interval): New procedure.
* sdl2/video.scm (set-gl-swap-interval!): New procedure.

sdl2/bindings.scm
sdl2/video.scm

index 6c638ab..b6f9431 100644 (file)
@@ -202,6 +202,9 @@ RETURN-TYPE and accept arguments of ARG-TYPES."
 (define-foreign sdl-gl-set-attribute
   int "SDL_GL_SetAttribute" (list int int))
 
+(define-foreign sdl-gl-set-swap-interval
+  int "SDL_GL_SetSwapInterval" (list int))
+
 (define-public SDL_RENDERER_SOFTWARE #x00000001)
 (define-public SDL_RENDERER_ACCELERATED #x00000002)
 (define-public SDL_RENDERER_PRESENTVSYNC #x00000004)
index 7cf14ff..8c65023 100644 (file)
@@ -56,7 +56,8 @@
             delete-gl-context!
             call-with-gl-context
             swap-gl-window
-            set-gl-attribute!))
+            set-gl-attribute!
+            set-gl-swap-interval!))
 
 \f
 ;;;
@@ -318,3 +319,22 @@ Possible values for ATTR are:
            ('framebuffer-srgb-capable ffi:SDL_GL_FRAMEBUFFER_SRGB_CAPABLE))))
     (unless (zero? (ffi:sdl-gl-set-attribute attr-enum value))
       (sdl-error "set-gl-attribute!" "failed to set OpenGL attribute"))))
+
+(define (set-gl-swap-interval! interval)
+  "Set the framebuffer swap interval for the current OpenGL context to
+the type indicated by the symbol INTERVAL.  Possible values of INTERVAL are:
+
+- immediate, for immediate updates
+- vsync, for updates synchronized with the screen's vertical retrace
+- late-swap-tear, for late swap tearing
+
+Late swap tearing works the same as vsync, but if the vertical retrace
+has been missed for a given frame, buffers are swapped immediately,
+which might be less jarring for the user during occasional framerate
+drops."
+  (unless (zero? (ffi:sdl-gl-set-swap-interval
+                  (match interval
+                    ('immediate 0)
+                    ('vsync 1)
+                    ('late-swap-tear -1))))
+    (sdl-error "set-gl-swap-interval!" "failed to set OpenGL swap interval")))