#include <algorithm>
+#include <msp/core/hash.h>
+#include <msp/strings/format.h>
#include "arb_shader_objects.h"
#include "arb_vertex_shader.h"
#include "error.h"
"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",
+ "nr", "\tvec3 eye_tangent = transform_normal(tangent);\n",
+ "n!r", "\tvec3 eye_tangent = gl_NormalMatrix*tangent;\n",
+ "nr", "\tvec3 eye_binormal = transform_normal(binormal);\n",
+ "n!r", "\tvec3 eye_binormal = gl_NormalMatrix*binormal;\n",
"l", "\tvec3 eye_light_dir = normalize(gl_LightSource[0].position.xyz-eye_pos.xyz*gl_LightSource[0].position.w);\n",
"n", "\tv_light_dir = vec3(dot(eye_tangent, eye_light_dir), dot(eye_binormal, eye_light_dir), dot(eye_normal, eye_light_dir));\n",
"l!n", "\tv_light_dir = eye_light_dir;\n",
/* XXX This is incorrect with normal mapping, since the vectors are in TBN
space but environment map is expected to be in eye space */
"e", "\tvec4 reflection = textureCube(environment, n_normal*(dot(n_normal, v_eye_dir)*2.0)-v_eye_dir);\n",
- 0, "\tgl_FragColor = ",
- "!t!l!m", "vec4(1.0, 1.0, 1.0, 1.0)",
- "t", "texture2D(texture, v_texcoord)",
+ "t", "\tvec4 tex_sample = texture2D(texture, v_texcoord);\n",
+ 0, "\tgl_FragColor.rgb = ",
+ "!t!l!m", "vec3(1.0)",
+ "t", "tex_sample.rgb",
"l|mt", "*",
- "!lm", "v_color",
+ "!lm", "v_color.rgb",
"l", "((l_diffuse",
- "lm", "*gl_FrontLightProduct[0].diffuse",
+ "lm", "*gl_FrontLightProduct[0].diffuse.rgb",
"p", "+l_specular",
- "pm", "*gl_FrontLightProduct[0].specular",
+ "pm", "*gl_FrontLightProduct[0].specular.rgb",
"l", ")",
"s", "*l_shadow",
- "lm", "+gl_FrontLightModelProduct.sceneColor",
+ "lm", "+gl_FrontLightModelProduct.sceneColor.rgb",
"l", ")",
- "e", "+reflection*reflectivity",
+ "e", "+reflection.rgb*reflectivity",
+ 0, ";\n",
+ 0, "\tgl_FragColor.a = ",
+ "!m", "1.0",
+ "!lm", "v_color.a",
+ "lm", "gl_FrontMaterial.diffuse.a",
+ "t", "*tex_sample.a",
0, ";\n",
0, "}\n",
0, 0
Program::~Program()
{
- for(list<Shader *>::iterator i=owned_data.begin(); i!=owned_data.end(); ++i)
+ for(ShaderList::iterator i=owned_data.begin(); i!=owned_data.end(); ++i)
delete *i;
glDeleteObjectARB(id);
}
void Program::detach_shader(Shader &shader)
{
- list<Shader *>::iterator i = remove(shaders.begin(), shaders.end(), &shader);
+ ShaderList::iterator i = remove(shaders.begin(), shaders.end(), &shader);
if(i!=shaders.end())
{
shaders.erase(i, shaders.end());
void Program::link()
{
- for(list<Shader *>::iterator i=shaders.begin(); i!=shaders.end(); ++i)
+ for(ShaderList::iterator i=shaders.begin(); i!=shaders.end(); ++i)
if(!(*i)->is_compiled())
(*i)->compile();
uniforms[name] = info;
}
}
+
+ string layout_descriptor;
+ for(map<string, UniformInfo>::const_iterator i = uniforms.begin(); i!=uniforms.end(); ++i)
+ if(i->second.location>=0)
+ {
+ if(!layout_descriptor.empty())
+ layout_descriptor += '\n';
+ layout_descriptor += format("%d:%s:%x", i->second.location, i->second.name, i->second.type);
+ }
+ uniform_layout_hash = hash32(layout_descriptor);
}
string Program::get_info_log() const
return log;
}
-void Program::bind() const
-{
- if(!linked)
- throw invalid_operation("Program::bind");
-
- if(!set_current(this))
- return;
-
- glUseProgramObjectARB(id);
-}
-
int Program::get_uniform_location(const string &n) const
{
- map<string, UniformInfo>::const_iterator i = uniforms.find(n);
+ UniformMap::const_iterator i = uniforms.find(n);
if(i==uniforms.end())
{
if(n[n.size()-1]==']')
return i->second.location;
}
+void Program::bind() const
+{
+ if(!linked)
+ throw invalid_operation("Program::bind");
+
+ if(!set_current(this))
+ return;
+
+ glUseProgramObjectARB(id);
+}
+
void Program::unbind()
{
if(!set_current(0))