Changeset 1690


Ignore:
Timestamp:
Aug 2, 2012, 11:23:09 PM (7 years ago)
Author:
sam
Message:

gpu: try to patch some simple GLSL shaders on the fly so that they
work on OpenGL ES contexts.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/easymesh/shiny.lolfx

    r1687 r1690  
    11
    22-- GLSL.Vert --
    3 #if defined GL_ES
    4 #version 100
    5 #else
    63#version 120
    7 #endif
    84
    95attribute vec3 in_Vertex;
     
    1410uniform mat4 in_Proj;
    1511uniform mat3 in_NormalMat;
    16 uniform vec3 in_LightDir = vec3(0.3, 0.3, 0.7);
     12// FIXME: the light direction should be passed in the code
     13vec3 in_LightDir = vec3(0.3, 0.3, 0.7);
    1714uniform float in_Damage;
    1815
     
    5451
    5552-- GLSL.Frag --
    56 #if defined GL_ES
    57 #version 100
    58 #else
    5953#version 120
    60 #endif
    6154
    6255#if defined GL_ES
  • trunk/src/gpu/shader.cpp

    r1513 r1690  
    217217        Log::Error("shader source:\n%s\n", buf);
    218218    }
    219     else if (len > 1)
     219    else if (len > 16)
    220220    {
    221221        Log::Debug("compile log for vertex shader: %s", errbuf);
     
    261261        Log::Error("shader source:\n%s\n", buf);
    262262    }
    263     else if (len > 1)
     263    else if (len > 16)
    264264    {
    265265        Log::Debug("compile log for fragment shader: %s", errbuf);
     
    309309        Log::Error("failed to link program: %s", errbuf);
    310310    }
    311     else if (len > 1)
     311    else if (len > 16)
    312312    {
    313313        Log::Debug("link log for program: %s", errbuf);
     
    611611    if (!version)
    612612    {
     613#if defined HAVE_GLES_2X
     614        /* GLES 2.x supports #version 100, that's all. */
     615        return 100;
     616#else
    613617        char buf[4096];
    614618        GLsizei len;
     
    644648
    645649        glDeleteShader(id);
     650#endif
    646651    }
    647652#endif
     
    651656
    652657/* Simple shader source patching for old GLSL versions.
    653  * If supported version is 1.30, do nothing.
    654  * If supported version is 1.20:
    655  *  - replace "#version 130" with "#version 120"
    656658 */
    657659void ShaderData::Patch(char *dst, char const *vert, char const *frag)
     
    667669    if (parser)
    668670        ver_shader = atoi(parser + strlen("#version"));
     671
     672    /* This is GL ES, we only know version 100. */
     673    if (ver_shader > 100 && ver_driver == 100)
     674    {
     675        /* FIXME: this isn't elegant but honestly, we don't care, this
     676         * whole file is going to die soon. */
     677        char *p = strstr(dst, "#version");
     678        if (p)
     679        {
     680            p += 8;
     681            while (*p == ' ')
     682                p++;
     683            if (p[0] == '1' && p[1] && p[2])
     684                p[1] = p[2] = '0';
     685        }
     686    }
    669687
    670688    if (ver_shader > 120 && ver_driver <= 120)
  • trunk/tutorial/11_fractal.lolfx

    r1518 r1690  
    33#version 120
    44
    5 #if defined HAVE_GLES_2X
     5#if defined GL_ES
    66precision highp float;
    77#endif
     
    5454#version 120
    5555
    56 #if defined HAVE_GLES_2X
     56#if defined GL_ES
    5757precision highp float;
    5858#endif
Note: See TracChangeset for help on using the changeset viewer.