]> git.tdb.fi Git - libs/gl.git/commitdiff
Add a standard program feature for custom transforms
authorMikko Rasa <tdb@tdb.fi>
Fri, 20 Jan 2012 20:29:11 +0000 (22:29 +0200)
committerMikko Rasa <tdb@tdb.fi>
Fri, 20 Jan 2012 20:29:11 +0000 (22:29 +0200)
source/program.cpp
source/program.h

index 6fa1495387fb3280452b099dcc38dcb1ff561b38..64aa7bc57d530ec364512fec5bd041eb072bb0dd 100644 (file)
@@ -20,11 +20,15 @@ const char *standard_vertex_src[] =
        "l!n", "varying vec3 v_normal;\n",
        "l",   "varying vec3 v_light_dir;\n",
        "p",   "varying vec3 v_eye_dir;\n",
+       "r",   "vec4 transform_vertex(vec4);\n",
+       "lr",  "vec3 transform_normal(vec3);\n",
         0,    "void main()\n",
         0,    "{\n",
-        0,    "\tvec4 eye_pos = gl_ModelViewMatrix*gl_Vertex;\n",
+       "r",   "\tvec4 eye_pos = transform_vertex(gl_Vertex);\n",
+       "!r",  "\tvec4 eye_pos = gl_ModelViewMatrix*gl_Vertex;\n",
         0,    "\tgl_Position = gl_ProjectionMatrix*eye_pos;\n",
-       "l",   "\tvec3 eye_normal = gl_NormalMatrix*gl_Normal;\n",
+       "lr",  "\tvec3 eye_normal = transform_normal(gl_Normal);\n",
+       "l!r", "\tvec3 eye_normal = gl_NormalMatrix*gl_Normal;\n",
        "l!n", "\tv_normal = eye_normal;\n",
        "n",   "\tvec3 eye_tangent = gl_NormalMatrix*tangent;\n",
        "n",   "\tvec3 eye_binormal = gl_NormalMatrix*binormal;\n",
@@ -276,7 +280,8 @@ Program::StandardFeatures::StandardFeatures():
        lighting(false),
        specular(false),
        normalmap(false),
-       shadow(false)
+       shadow(false),
+       transform(false)
 { }
 
 string Program::StandardFeatures::create_flags() const
@@ -296,6 +301,8 @@ string Program::StandardFeatures::create_flags() const
        }
        if(shadow)
                flags += 's';
+       if(transform)
+               flags += 'r';
 
        return flags;
 }
@@ -349,6 +356,7 @@ Program::StandardFeatures::Loader::Loader(StandardFeatures &f):
        add("shadow",    &StandardFeatures::shadow);
        add("specular",  &StandardFeatures::specular);
        add("texture",   &StandardFeatures::texture);
+       add("transform", &StandardFeatures::transform);
 }
 
 } // namespace GL
index b875ec79f089f28e6ec629cb426ee354d9d674b5..c3c6cc03b42685a87b8aa5330b90798333438f3c 100644 (file)
@@ -43,6 +43,7 @@ public:
                bool specular;
                bool normalmap;
                bool shadow;
+               bool transform;
 
                StandardFeatures();