]> git.tdb.fi Git - libs/gl.git/blobdiff - source/program.cpp
Move Program::bind to its proper place
[libs/gl.git] / source / program.cpp
index 587a3fb0fa674c6c2a85689c4abee6a05d7bf2d2..8ca8e336c0d18dc3f0efb08b31914824570f36c4 100644 (file)
@@ -73,20 +73,27 @@ const char *standard_fragment_src[] =
        /* 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
@@ -130,7 +137,7 @@ void Program::init()
 
 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);
 }
@@ -153,7 +160,7 @@ void Program::attach_shader_owned(Shader *shader)
 
 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());
@@ -215,7 +222,7 @@ void Program::bind_attribute(unsigned index, const string &name)
 
 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();
 
@@ -264,20 +271,9 @@ 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]==']')
@@ -300,6 +296,17 @@ int Program::get_uniform_location(const string &n) const
        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))