changeset 554:653a9f087673

Make both double- and single-buffer available on the CLI, but default to SDL’s default.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 30 May 2014 04:06:09 +0200
parents 8f51e34d911c
children 98380e4a0ee5
files pytouhou/ui/opengl/backend.pxd pytouhou/ui/opengl/backend.pyx scripts/pytouhou
diffstat 3 files changed, 12 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/ui/opengl/backend.pxd
+++ b/pytouhou/ui/opengl/backend.pxd
@@ -2,5 +2,5 @@ cdef str flavor
 cdef float version
 cdef int major
 cdef int minor
-cdef bint double_buffer
+cdef int double_buffer
 cdef bint is_legacy
--- a/pytouhou/ui/opengl/backend.pyx
+++ b/pytouhou/ui/opengl/backend.pyx
@@ -23,7 +23,9 @@ def init(options):
     major = int(version)
     minor = <int>(version * 10) % 10
 
-    double_buffer = options['double-buffer']
+    maybe_double_buffer = options['double-buffer']
+    double_buffer = maybe_double_buffer if maybe_double_buffer is not None else -1
+
     is_legacy = flavor == 'legacy'
 
     #TODO: check for framebuffer/renderbuffer support.
@@ -34,8 +36,9 @@ def init(options):
 def create_window(title, x, y, width, height):
     sdl.gl_set_attribute(sdl.GL_CONTEXT_MAJOR_VERSION, major)
     sdl.gl_set_attribute(sdl.GL_CONTEXT_MINOR_VERSION, minor)
-    sdl.gl_set_attribute(sdl.GL_DOUBLEBUFFER, double_buffer)
     sdl.gl_set_attribute(sdl.GL_DEPTH_SIZE, 24)
+    if double_buffer >= 0:
+        sdl.gl_set_attribute(sdl.GL_DOUBLEBUFFER, double_buffer)
 
     flags = sdl.WINDOW_SHOWN | sdl.WINDOW_OPENGL
 
--- a/scripts/pytouhou
+++ b/scripts/pytouhou
@@ -59,10 +59,13 @@ graphics_group.add_argument('--no-partic
 graphics_group.add_argument('--no-sound', action='store_false', help='Disable music and sound effects.')
 
 opengl_group = parser.add_argument_group('OpenGL backend options')
-opengl_group.add_argument('--single-buffer', action='store_true', help='Disable double buffering.')
 opengl_group.add_argument('--gl-flavor', choices=['core', 'es', 'compatibility', 'legacy'], default='compatibility', help='OpenGL profile to use.')
 opengl_group.add_argument('--gl-version', default=2.1, type=float, help='OpenGL version to use.')
 
+double_buffer = opengl_group.add_mutually_exclusive_group()
+double_buffer.add_argument('--double-buffer', dest='double_buffer', action='store_true', default=None, help='Enable double buffering.')
+double_buffer.add_argument('--single-buffer', dest='double_buffer', action='store_false', default=None, help='Disable double buffering.')
+
 args = parser.parse_args()
 
 
@@ -95,9 +98,9 @@ from importlib import import_module
 for backend in args.backend:
     if backend == 'opengl':
         options = {
-            'double-buffer': not args.single_buffer,
             'flavor': args.gl_flavor,
-            'version': args.gl_version
+            'version': args.gl_version,
+            'double-buffer': args.double_buffer,
         }
     else:
         options = {}