changeset 556:c34b23e29d16

Make the OpenGL flavor and version options work.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 30 May 2014 16:40:36 +0200
parents 98380e4a0ee5
children 0f2af7552462
files pytouhou/lib/_sdl.pxd pytouhou/lib/sdl.pxd pytouhou/lib/sdl.pyx pytouhou/ui/opengl/backend.pxd pytouhou/ui/opengl/backend.pyx
diffstat 5 files changed, 31 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/lib/_sdl.pxd
+++ b/pytouhou/lib/_sdl.pxd
@@ -36,9 +36,15 @@ cdef extern from "SDL_video.h" nogil:
     ctypedef enum SDL_GLattr:
         SDL_GL_CONTEXT_MAJOR_VERSION
         SDL_GL_CONTEXT_MINOR_VERSION
+        SDL_GL_CONTEXT_PROFILE_MASK
         SDL_GL_DOUBLEBUFFER
         SDL_GL_DEPTH_SIZE
 
+    ctypedef enum SDL_GLprofile:
+        SDL_GL_CONTEXT_PROFILE_CORE
+        SDL_GL_CONTEXT_PROFILE_COMPATIBILITY
+        SDL_GL_CONTEXT_PROFILE_ES
+
     ctypedef enum SDL_WindowFlags:
         SDL_WINDOWPOS_CENTERED
         SDL_WINDOW_OPENGL
--- a/pytouhou/lib/sdl.pxd
+++ b/pytouhou/lib/sdl.pxd
@@ -17,9 +17,14 @@ from _sdl cimport *
 
 cdef SDL_GLattr GL_CONTEXT_MAJOR_VERSION
 cdef SDL_GLattr GL_CONTEXT_MINOR_VERSION
+cdef SDL_GLattr GL_CONTEXT_PROFILE_MASK
 cdef SDL_GLattr GL_DOUBLEBUFFER
 cdef SDL_GLattr GL_DEPTH_SIZE
 
+cdef SDL_GLprofile GL_CONTEXT_PROFILE_CORE
+cdef SDL_GLprofile GL_CONTEXT_PROFILE_COMPATIBILITY
+cdef SDL_GLprofile GL_CONTEXT_PROFILE_ES
+
 cdef SDL_WindowFlags WINDOWPOS_CENTERED
 cdef SDL_WindowFlags WINDOW_OPENGL
 cdef SDL_WindowFlags WINDOW_SHOWN
--- a/pytouhou/lib/sdl.pyx
+++ b/pytouhou/lib/sdl.pyx
@@ -19,9 +19,14 @@ logger = get_logger(__name__)
 
 GL_CONTEXT_MAJOR_VERSION = SDL_GL_CONTEXT_MAJOR_VERSION
 GL_CONTEXT_MINOR_VERSION = SDL_GL_CONTEXT_MINOR_VERSION
+GL_CONTEXT_PROFILE_MASK = SDL_GL_CONTEXT_PROFILE_MASK
 GL_DOUBLEBUFFER = SDL_GL_DOUBLEBUFFER
 GL_DEPTH_SIZE = SDL_GL_DEPTH_SIZE
 
+GL_CONTEXT_PROFILE_CORE = SDL_GL_CONTEXT_PROFILE_CORE
+GL_CONTEXT_PROFILE_COMPATIBILITY = SDL_GL_CONTEXT_PROFILE_COMPATIBILITY
+GL_CONTEXT_PROFILE_ES = SDL_GL_CONTEXT_PROFILE_ES
+
 WINDOWPOS_CENTERED = SDL_WINDOWPOS_CENTERED
 WINDOW_OPENGL = SDL_WINDOW_OPENGL
 WINDOW_RESIZABLE = SDL_WINDOW_RESIZABLE
--- a/pytouhou/ui/opengl/backend.pxd
+++ b/pytouhou/ui/opengl/backend.pxd
@@ -1,5 +1,7 @@
-cdef str flavor
-cdef float version
+from pytouhou.lib.sdl cimport SDL_GLprofile
+
+cdef SDL_GLprofile flavor
+cdef str version
 cdef int major
 cdef int minor
 cdef int double_buffer
--- a/pytouhou/ui/opengl/backend.pyx
+++ b/pytouhou/ui/opengl/backend.pyx
@@ -13,17 +13,21 @@ GameRenderer = None
 def init(options):
     global flavor, version, major, minor, double_buffer, is_legacy, GameRenderer
 
-    flavor = options['flavor']
-    assert flavor in ('core', 'es', 'compatibility', 'legacy')
+    flavor_name = options['flavor']
+    assert flavor_name in ('core', 'es', 'compatibility', 'legacy')
+    flavor = (sdl.GL_CONTEXT_PROFILE_CORE if flavor_name == 'core' else
+              sdl.GL_CONTEXT_PROFILE_ES if flavor_name == 'es' else
+              sdl.GL_CONTEXT_PROFILE_COMPATIBILITY)
 
-    version = options['version']
-    major = int(version)
-    minor = <int>(version * 10) % 10
+    version = str(options['version'])
+    assert len(version) == 3 and version[1] == '.'
+    major = int(version[0])
+    minor = int(version[2])
 
     maybe_double_buffer = options['double-buffer']
     double_buffer = maybe_double_buffer if maybe_double_buffer is not None else -1
 
-    is_legacy = flavor == 'legacy'
+    is_legacy = flavor_name == 'legacy'
 
     #TODO: check for framebuffer/renderbuffer support.
 
@@ -31,6 +35,7 @@ def init(options):
 
 
 def create_window(title, x, y, width, height):
+    sdl.gl_set_attribute(sdl.GL_CONTEXT_PROFILE_MASK, flavor)
     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_DEPTH_SIZE, 24)