# HG changeset patch # User Emmanuel Gil Peyrot # Date 1401460836 -7200 # Node ID 1be60813f7cb1fc19d06002771d8b213cbcc46be # Parent 94725968dabbc70048fe8171b80f763e2a1982e9 Get OpenGL ES 2.0 to work thanks to libepoxy. PCB textures will need swizzle in the shaders since BGRA isn’t natively supported on GLES. diff --git a/pytouhou/lib/opengl.pxd b/pytouhou/lib/opengl.pxd --- a/pytouhou/lib/opengl.pxd +++ b/pytouhou/lib/opengl.pxd @@ -52,6 +52,7 @@ cdef extern from 'epoxy/gl.h' nogil: GL_RGB GL_LUMINANCE GL_UNSIGNED_SHORT_5_6_5 + GL_UNSIGNED_SHORT_4_4_4_4 GL_UNSIGNED_SHORT_4_4_4_4_REV GL_COLOR_BUFFER_BIT @@ -83,7 +84,7 @@ cdef extern from 'epoxy/gl.h' nogil: GL_FRAMEBUFFER GL_COLOR_ATTACHMENT0 GL_RENDERBUFFER - GL_DEPTH_COMPONENT + GL_DEPTH_COMPONENT16 GL_DEPTH_ATTACHMENT GL_FRAMEBUFFER_COMPLETE 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 @@ -29,12 +29,18 @@ def init(options): use_vao = (major == 3 and minor >= 1) or major > 3 is_legacy = flavor_name == 'legacy' + is_gles = flavor_name == 'es' - try: - glsl_version = {'2.0': 110, '2.1': 120, '3.0': 130, '3.1': 140, '3.2': 150}[version] - except KeyError: - glsl_version = 100 * major + 10 * minor - shader_header = '#version %d\n' % glsl_version + if not is_gles: + try: + glsl_version = {'2.0': 110, '2.1': 120, '3.0': 130, '3.1': 140, '3.2': 150}[version] + except KeyError: + assert (major == 3 and minor == 3) or major > 3 + glsl_version = 100 * major + 10 * minor + shader_header = '#version %d\n' % glsl_version + else: + glsl_version = {'2.0': 100, '3.0': 300}[version] + shader_header = '#version %d\n\nprecision highp float;\n' % glsl_version #TODO: check for framebuffer/renderbuffer support. diff --git a/pytouhou/ui/opengl/renderer.pyx b/pytouhou/ui/opengl/renderer.pyx --- a/pytouhou/ui/opengl/renderer.pyx +++ b/pytouhou/ui/opengl/renderer.pyx @@ -29,7 +29,7 @@ from pytouhou.lib.opengl cimport \ glFramebufferTexture2D, glFramebufferRenderbuffer, glCheckFramebufferStatus, GL_FRAMEBUFFER, GL_TEXTURE_MIN_FILTER, GL_LINEAR, GL_TEXTURE_MAG_FILTER, GL_RGBA, GL_RENDERBUFFER, - GL_DEPTH_COMPONENT, GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT, + GL_DEPTH_COMPONENT16, GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT, GL_FRAMEBUFFER_COMPLETE, glClear, GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, GLuint, glDeleteTextures, GL_ELEMENT_ARRAY_BUFFER, GL_STATIC_DRAW, glGenVertexArrays, @@ -336,7 +336,7 @@ cdef class Framebuffer: glGenRenderbuffers(1, &self.rbo) glBindRenderbuffer(GL_RENDERBUFFER, self.rbo) - glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height) + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height) glBindRenderbuffer(GL_RENDERBUFFER, 0) glGenFramebuffers(1, &self.fbo) diff --git a/pytouhou/ui/opengl/shaders/eosd.py b/pytouhou/ui/opengl/shaders/eosd.py --- a/pytouhou/ui/opengl/shaders/eosd.py +++ b/pytouhou/ui/opengl/shaders/eosd.py @@ -78,7 +78,7 @@ class BackgroundShader(Shader): { vec4 temp_color = texture2D(color_map, texcoord) * color; float depth = gl_FragCoord.z / gl_FragCoord.w; - float fog_density = clamp((fog_end - depth) * fog_scale, 0.0f, 1.0f); + float fog_density = clamp((fog_end - depth) * fog_scale, 0.0, 1.0); gl_FragColor = vec4(mix(fog_color, temp_color, fog_density).rgb, temp_color.a); } ''']) diff --git a/pytouhou/ui/opengl/texture.pyx b/pytouhou/ui/opengl/texture.pyx --- a/pytouhou/ui/opengl/texture.pyx +++ b/pytouhou/ui/opengl/texture.pyx @@ -15,7 +15,7 @@ from pytouhou.lib.opengl cimport \ (glTexParameteri, GL_TEXTURE_MIN_FILTER, GL_TEXTURE_MAG_FILTER, GL_LINEAR, GL_BGRA, GL_RGBA, GL_RGB, GL_LUMINANCE, GL_UNSIGNED_BYTE, - GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_4_4_4_4_REV, + GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_4_4_4_4, glGenTextures, glBindTexture, glTexImage2D, GL_TEXTURE_2D, GLuint) from pytouhou.lib.sdl cimport load_png, create_rgb_surface @@ -109,7 +109,8 @@ cdef GLuint load_texture(thtx) except? 6 cdef long fmt = thtx.fmt if fmt == 1: - format_ = GL_BGRA + #format_ = GL_BGRA + format_ = GL_RGBA #XXX: should be GL_BGRA type_ = GL_UNSIGNED_BYTE composants = GL_RGBA elif fmt == 3: @@ -117,8 +118,10 @@ cdef GLuint load_texture(thtx) except? 6 type_ = GL_UNSIGNED_SHORT_5_6_5 composants = GL_RGB elif fmt == 5: - format_ = GL_BGRA - type_ = GL_UNSIGNED_SHORT_4_4_4_4_REV + #format_ = GL_BGRA + format_ = GL_RGBA #XXX: should be GL_BGRA + #type_ = GL_UNSIGNED_SHORT_4_4_4_4_REV + type_ = GL_UNSIGNED_SHORT_4_4_4_4 #XXX: should be GL_UNSIGNED_SHORT_4_4_4_4_REV composants = GL_RGBA elif fmt == 7: format_ = GL_LUMINANCE