# HG changeset patch # User Emmanuel Gil Peyrot # Date 1413732146 -7200 # Node ID b7b4a234bf704983e5bca57bf94f2112f1531e72 # Parent 12756994a92cfae6a485f12d76ded0610fcd77c0 Fix legacy OpenGL support, and detect the absence of non-legacy context with libepoxy. diff --git a/pytouhou/ui/opengl/backend.pyx b/pytouhou/ui/opengl/backend.pyx --- a/pytouhou/ui/opengl/backend.pyx +++ b/pytouhou/ui/opengl/backend.pyx @@ -21,6 +21,8 @@ def init(options): working. ''' + cdef str flavor + global profile, major, minor, double_buffer, is_legacy, GameRenderer flavor = options['flavor'] @@ -37,23 +39,24 @@ def init(options): 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_gles = flavor == 'es' + is_legacy = flavor == 'legacy' or flavor == 'compatibility' and major < 2 #TODO: check for framebuffer/renderbuffer support. from pytouhou.ui.opengl.gamerenderer import GameRenderer -def discover_features(): +cdef void discover_features() except *: '''Discover which features are supported by our context.''' - global use_debug_group, use_vao, use_primitive_restart, use_pack_invert + global use_debug_group, use_vao, use_primitive_restart, use_framebuffer_blit, use_pack_invert global primitive_mode global shader_header + global is_legacy version = epoxy_gl_version() is_desktop = epoxy_is_desktop_gl() + is_legacy = is_desktop and version < 20 use_debug_group = (is_desktop and version >= 43) or epoxy_has_gl_extension('GL_KHR_debug') use_vao = (is_desktop and version >= 30) or epoxy_has_gl_extension('GL_ARB_vertex_array_object') @@ -63,22 +66,23 @@ def discover_features(): primitive_mode = GL_TRIANGLE_STRIP if use_primitive_restart else GL_TRIANGLES - if is_desktop: - # gl_FragColor isn’t supported anymore starting with GLSL 4.2. - if version >= 42: - version = 41 - try: - glsl_version = {20: 110, 21: 120, 30: 130, 31: 140, 32: 150}[version] - except KeyError: - assert version >= 33 - glsl_version = version * 10 - shader_header = ('#version %d\n\n' % glsl_version).encode() - else: - # The attribute keyword isn’t supported past GLSL ES 3.0. - if version >= 30: - version = 20 - glsl_version = {20: '100', 30: '300 es'}[version] - shader_header = ('#version %s\n\nprecision highp float;\n\n' % glsl_version).encode() + if not is_legacy: + if is_desktop: + # gl_FragColor isn’t supported anymore starting with GLSL 4.2. + if version >= 42: + version = 41 + try: + glsl_version = {20: 110, 21: 120, 30: 130, 31: 140, 32: 150}[version] + except KeyError: + assert version >= 33 + glsl_version = version * 10 + shader_header = ('#version %d\n\n' % glsl_version).encode() + else: + # The attribute keyword isn’t supported past GLSL ES 3.0. + if version >= 30: + version = 20 + glsl_version = {20: '100', 30: '300 es'}[version] + shader_header = ('#version %s\n\nprecision highp float;\n\n' % glsl_version).encode() def create_window(title, x, y, width, height, swap_interval): @@ -92,8 +96,6 @@ def create_window(title, x, y, width, he sdl.gl_set_attribute(sdl.GL_DOUBLEBUFFER, double_buffer) flags = sdl.WINDOW_SHOWN | sdl.WINDOW_OPENGL - - #TODO: legacy can support one of the framebuffer extensions. if not is_legacy: flags |= sdl.WINDOW_RESIZABLE @@ -102,6 +104,13 @@ def create_window(title, x, y, width, he discover_features() + #TODO: legacy could support one of the framebuffer extensions for resize, + # but for now set the window to a fixed size. + if is_legacy and flags & sdl.WINDOW_RESIZABLE: + flags &= ~sdl.WINDOW_RESIZABLE + window = Window(title, x, y, width, height, flags) + window.gl_create_context() + if use_debug_group: glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "OpenGL initialisation") @@ -129,6 +138,8 @@ def create_window(title, x, y, width, he try: sdl.gl_set_swap_interval(swap_interval) except sdl.SDLError: + # The OpenGL context doesn’t support setting the swap interval, + # we’ll probably fallback to SDL_Delay-based clocking. pass return window