]> git.tdb.fi Git - libs/gl.git/blobdiff - source/programbuilder.cpp
Fix some warnings about uninitialized variables
[libs/gl.git] / source / programbuilder.cpp
index 2f38c93c10eb03a3b48d2dcbb8948151ddf98deb..30457838e89bae1270ff3648a79250624a82d69e 100644 (file)
@@ -68,9 +68,12 @@ const ProgramBuilder::StandardVariable ProgramBuilder::standard_variables[] =
        { FRAGMENT, "l_specular", "float", "pow(max(dot(n_zzz_half_vec, n_zzz_normal), 0.0), gl_FrontMaterial.shininess)", 0 },
        { FRAGMENT, "n_zzz_half_vec", "vec3", "normalize(zzz_light_dir-zzz_incident_dir)", 0 },
        { FRAGMENT, "n_zzz_light_dir", "vec3", "normalize(zzz_light_dir)", 0 },
-       { FRAGMENT, "n_tbn_normal", "vec3", "texture2D(normalmap, texture_coord).xyz*2.0-1.0", "n" },
+       { FRAGMENT, "n_tbn_normal", "vec3", "normal_sample*2.0-1.0", "n" },
        { FRAGMENT, "n_eye_normal", "vec3", "normalize(eye_normal)", "!n" },
-       { FRAGMENT, "tex_sample", "vec4", "texture2D(texture, texture_coord)", 0 },
+       { FRAGMENT, "normal_sample", "vec3", "texture2D(normalmap, texture_coord).xyz", "!c" },
+       { FRAGMENT, "normal_sample", "vec3", "sample_normalmap(texture_coord)", "c" },
+       { FRAGMENT, "tex_sample", "vec4", "texture2D(texture, texture_coord)", "!c" },
+       { FRAGMENT, "tex_sample", "vec4", "sample_texture(texture_coord)", "c" },
 
        { VERTEX, "gl_Position", 0, "gl_ProjectionMatrix*eye_vertex", 0 },
        { VERTEX, "shd_vertex", "vec3", "(eye_vertex*eye_shd_rmatrix).xyz", 0 },
@@ -232,6 +235,13 @@ string ProgramBuilder::create_source(const list<ShaderVariable *> &variables, Va
                source += "vec4 transform_vertex(vec4);\n";
                source += "vec3 transform_normal(vec3);\n";
        }
+       else if(scope==FRAGMENT && features.colorify)
+       {
+               if(features.texture)
+                       source += "vec4 sample_texture(vec2);\n";
+               if(features.normalmap)
+                       source += "vec3 sample_normalmap(vec2);\n";
+       }
 
        source += "void main()\n{\n";
 
@@ -365,7 +375,8 @@ vector<string> ProgramBuilder::extract_identifiers(const char *expression)
 {
        vector<string> result;
        const char *ptr = expression;
-       unsigned start, length;
+       unsigned start = 0;
+       unsigned length = 0;
        while(parse_identifier(ptr, start, length))
        {
                result.push_back(string(ptr+start, length));
@@ -378,7 +389,8 @@ string ProgramBuilder::replace_identifiers(const char *expression, const map<str
 {
        string result;
        const char *ptr = expression;
-       unsigned start, length;
+       unsigned start = 0;
+       unsigned length = 0;
        while(parse_identifier(ptr, start, length))
        {
                result.append(ptr, start);
@@ -403,7 +415,8 @@ ProgramBuilder::StandardFeatures::StandardFeatures():
        normalmap(false),
        shadow(false),
        reflection(false),
-       transform(false)
+       transform(false),
+       colorify(false)
 { }
 
 string ProgramBuilder::StandardFeatures::create_flags() const
@@ -427,6 +440,8 @@ string ProgramBuilder::StandardFeatures::create_flags() const
                flags += 'e';
        if(transform)
                flags += 'r';
+       if(colorify)
+               flags += 'c';
 
        return flags;
 }
@@ -555,6 +570,7 @@ string ProgramBuilder::ShaderVariable::get_expression() const
 ProgramBuilder::StandardFeatures::Loader::Loader(StandardFeatures &f):
        DataFile::ObjectLoader<StandardFeatures>(f)
 {
+       add("colorify",  &StandardFeatures::colorify);
        add("lighting",  &StandardFeatures::lighting);
        add("material",  &StandardFeatures::material);
        add("normalmap", &StandardFeatures::normalmap);