changeset 559:1be60813f7cb

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.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 30 May 2014 16:40:36 +0200
parents 94725968dabb
children c759b97f4f81
files pytouhou/lib/opengl.pxd pytouhou/ui/opengl/backend.pyx pytouhou/ui/opengl/renderer.pyx pytouhou/ui/opengl/shaders/eosd.py pytouhou/ui/opengl/texture.pyx
diffstat 5 files changed, 23 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/lib/opengl.pxd	Thu Dec 12 13:47:17 2013 +0100
+++ b/pytouhou/lib/opengl.pxd	Fri May 30 16:40:36 2014 +0200
@@ -52,6 +52,7 @@
         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 @@
         GL_FRAMEBUFFER
         GL_COLOR_ATTACHMENT0
         GL_RENDERBUFFER
-        GL_DEPTH_COMPONENT
+        GL_DEPTH_COMPONENT16
         GL_DEPTH_ATTACHMENT
         GL_FRAMEBUFFER_COMPLETE
 
--- a/pytouhou/ui/opengl/backend.pyx	Thu Dec 12 13:47:17 2013 +0100
+++ b/pytouhou/ui/opengl/backend.pyx	Fri May 30 16:40:36 2014 +0200
@@ -29,12 +29,18 @@
     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.
 
--- a/pytouhou/ui/opengl/renderer.pyx	Thu Dec 12 13:47:17 2013 +0100
+++ b/pytouhou/ui/opengl/renderer.pyx	Fri May 30 16:40:36 2014 +0200
@@ -29,7 +29,7 @@
           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 @@
 
         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)
--- a/pytouhou/ui/opengl/shaders/eosd.py	Thu Dec 12 13:47:17 2013 +0100
+++ b/pytouhou/ui/opengl/shaders/eosd.py	Fri May 30 16:40:36 2014 +0200
@@ -78,7 +78,7 @@
             {
                 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);
             }
         '''])
--- a/pytouhou/ui/opengl/texture.pyx	Thu Dec 12 13:47:17 2013 +0100
+++ b/pytouhou/ui/opengl/texture.pyx	Fri May 30 16:40:36 2014 +0200
@@ -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 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 @@
         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