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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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)
Note: See TracChangeset for help on using the changeset viewer.