]> git.tdb.fi Git - libs/gl.git/blobdiff - source/programbuilder.cpp
Support OpenGL ES on Android
[libs/gl.git] / source / programbuilder.cpp
index 1706b9d4ad70c0dc8e362f7c37b754e5df7a02b8..d8fe22ed14542fe8ce93fe670daeed566f122448 100644 (file)
@@ -106,8 +106,7 @@ const ProgramBuilder::VariableDefinition ProgramBuilder::standard_variables[] =
        { FRAGMENT, "tex_sample", "vec4", "texture2D(texture, texture_coord)", 0 },
 
        { VERTEX, "gl_Position", "vec4", "projection_matrix*eye_vertex", 0 },
-       { VERTEX, "shd_vertex", "vec3", "vec3(dot(eye_vertex, gl_EyePlaneS[shadow_unit]), dot(eye_vertex, gl_EyePlaneT[shadow_unit]), dot(eye_vertex, gl_EyePlaneR[shadow_unit]))", "g" },
-       { VERTEX, "shd_vertex", "vec3", "(shd_eye_matrix*eye_vertex).xyz", "!g" },
+       { VERTEX, "shd_vertex", "vec3", "(shd_eye_matrix*eye_vertex).xyz", 0 },
        { VERTEX, "tbn_sky_dir", "vec3", "eye_sky_dir*eye_tbn_matrix", "n" },
        { VERTEX, "tbn_light_dir[i]", "vec3", "eye_light_dir[i]*eye_tbn_matrix", 0 },
        { VERTEX, "eye_light_dir[i]", "vec3", "normalize(eye_light_position[i].xyz-eye_vertex.xyz*eye_light_position[i].w)", 0 },
@@ -128,7 +127,6 @@ const ProgramBuilder::VariableDefinition ProgramBuilder::standard_variables[] =
        { ATTRIBUTE, "tangent", "vec3", 0, 0 },
        { ATTRIBUTE, "binormal", "vec3", 0, 0 },
 
-       { UNIFORM, "ShadowMap::shadow_unit", "int", 0, 0 },
        { UNIFORM, "texture", "sampler2D", 0, 0 },
        { UNIFORM, "shadow", "sampler2DShadow", 0, 0 },
        { UNIFORM, "ShadowMap::shadow_darkness", "float", 0, 0 },
@@ -347,7 +345,10 @@ void ProgramBuilder::add_shaders(Program &prog) const
 
        if(!features.legacy)
        {
-               prog.bind_fragment_data(0, "frag_color");
+               // OpenGL ES does not support binding fragment shader outputs
+               if(get_gl_api()!=OPENGL_ES2)
+                       prog.bind_fragment_data(0, "frag_color");
+
                prog.bind_attribute(VERTEX4, "vertex");
                if(features.lighting)
                        prog.bind_attribute(NORMAL3, "normal");
@@ -371,9 +372,17 @@ string ProgramBuilder::create_source(const list<ShaderVariable *> &variables, Va
 
        if(!features.legacy)
        {
-               source += "#version 130\n";
-               if(use_blocks)
-                       source += "#extension GL_ARB_uniform_buffer_object: require\n";
+               if(get_gl_api()==OPENGL_ES2)
+               {
+                       if(use_blocks)
+                               source += "#version 300 es\n";
+               }
+               else
+               {
+                       source += "#version 130\n";
+                       if(use_blocks)
+                               source += "#extension GL_ARB_uniform_buffer_object: require\n";
+               }
        }
 
        set<const VariableDefinition *> declared_types;