-/* $Id$
-
-This file is part of libmspgl
-Copyright © 2007 Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
#include <algorithm>
#include "arb_shader_objects.h"
#include "arb_vertex_shader.h"
-#include "except.h"
+#include "error.h"
#include "extension.h"
#include "program.h"
#include "shader.h"
"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",
"n", "\tvec3 n_normal = texture2D(normalmap, v_texcoord).xyz*2.0-1.0;\n",
"l!n", "\tvec3 n_normal = normalize(v_normal);\n",
"l", "\tfloat l_diffuse = max(dot(n_normal, normalize(v_light_dir)), 0.0);\n",
- "p", "\tvec3 half = normalize(v_eye_dir+v_light_dir);\n",
- "p", "\tfloat l_specular = pow(max(dot(half, n_normal), 0.0), gl_FrontMaterial.shininess);\n",
+ "p", "\tvec3 half_dir = normalize(v_eye_dir+v_light_dir);\n",
+ "p", "\tfloat l_specular = pow(max(dot(half_dir, n_normal), 0.0), gl_FrontMaterial.shininess);\n",
"s", "\tfloat l_shadow = shadow2D(shadow, v_shadowcoord).r;\n",
0, "\tgl_FragColor = ",
"!t!l!m", "vec4(1.0, 1.0, 1.0, 1.0)",
int value;
glGetObjectParameterivARB(id, GL_OBJECT_LINK_STATUS_ARB, &value);
if(!(linked = value))
- throw CompileError(get_info_log());
+ throw compile_error(get_info_log());
glGetObjectParameterivARB(id, GL_OBJECT_ACTIVE_UNIFORMS_ARB, &value);
for(int i=0; i<value; ++i)
{
GLsizei len = 0;
glGetObjectParameterivARB(id, GL_OBJECT_INFO_LOG_LENGTH_ARB, &len);
- char log[len+1];
- glGetInfoLogARB(id, len+1, &len, log);
- return string(log, len);
+ char *buf = new char[len+1];
+ glGetInfoLogARB(id, len+1, &len, buf);
+ string log(buf, len);
+ delete[] buf;
+ return log;
}
void Program::bind() const
{
if(!linked)
- throw InvalidState("Program is not linked");
+ throw invalid_operation("Program::bind");
if(!set_current(this))
return;
lighting(false),
specular(false),
normalmap(false),
- shadow(false)
+ shadow(false),
+ transform(false)
{ }
string Program::StandardFeatures::create_flags() const
}
if(shadow)
flags += 's';
+ if(transform)
+ flags += 'r';
return flags;
}
add("shadow", &StandardFeatures::shadow);
add("specular", &StandardFeatures::specular);
add("texture", &StandardFeatures::texture);
+ add("transform", &StandardFeatures::transform);
}
} // namespace GL