X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fprogram.cpp;h=f6eaed1ee4eeb8bdb0853af07423ecbdbae5ef4d;hb=2be605933f62521bb22780256386a14b371c8b17;hp=77fe7e7510d9e09597712803ade770267486b26e;hpb=953f041e904e97c4435e0229b8d88eabe31e5c3d;p=libs%2Fgl.git diff --git a/source/program.cpp b/source/program.cpp index 77fe7e75..f6eaed1e 100644 --- a/source/program.cpp +++ b/source/program.cpp @@ -1,14 +1,7 @@ -/* $Id$ - -This file is part of libmspgl -Copyright © 2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - #include #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" @@ -27,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", @@ -64,8 +61,8 @@ const char *standard_fragment_src[] = "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)", @@ -215,26 +212,45 @@ void Program::link() if(!(*i)->is_compiled()) (*i)->compile(); + uniforms.clear(); + glLinkProgramARB(id); 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::const_iterator i = uniforms.find(n); + if(i==uniforms.end()) + return -1; + + return i->second.location; } void Program::unbind() @@ -262,7 +282,8 @@ Program::StandardFeatures::StandardFeatures(): lighting(false), specular(false), normalmap(false), - shadow(false) + shadow(false), + transform(false) { } string Program::StandardFeatures::create_flags() const @@ -282,6 +303,8 @@ string Program::StandardFeatures::create_flags() const } if(shadow) flags += 's'; + if(transform) + flags += 'r'; return flags; } @@ -335,6 +358,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