/* $Id$
This file is part of libmspgl
-Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2008 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
shininess=s;
}
-void Material::apply() const
+void Material::bind() const
{
- glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, &ambient.r);
- glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, &diffuse.r);
- glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, &specular.r);
- glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, &emission.r);
- glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
+ if(current!=this)
+ {
+ glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, &ambient.r);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, &diffuse.r);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, &specular.r);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, &emission.r);
+ glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
+ current=this;
+ }
}
+void Material::unbind()
+{
+ current=0;
+}
+
+const Material *Material::current=0;
+
Material::Loader::Loader(Material &m):
mat(m)
/* $Id$
This file is part of libmspgl
-Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2008 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
const Color &get_specular() const { return specular; }
const Color &get_emission() const { return emission; }
float get_shininess() const { return shininess; }
- void apply() const;
+ void bind() const;
+
+ static void unbind();
+private:
+ static const Material *current;
};
} // namespace GL
main_texture->bind();
if(material)
- material->apply();
+ material->bind();
}
void Object::finish_render(const ObjectPass &pass) const
}
else if(main_texture)
Texture::unbind();
+
+ if(material)
+ Material::unbind();
}
void Object::render(const ObjectPass &pass, const ObjectInstance *inst) const
--- /dev/null
+/* $Id$
+
+This file is part of libmspgl
+Copyright © 2008 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
+#include "texenv.h"
+#include "texunit.h"
+
+namespace Msp {
+namespace GL {
+
+TexEnv::TexEnv():
+ mode(MODULATE)
+{ }
+
+void TexEnv::set_mode(TexEnvMode m)
+{
+ mode=m;
+}
+
+void TexEnv::set_color(const Color &c)
+{
+ color=c;
+}
+
+void TexEnv::bind()
+{
+ if(TexUnit::current().set_texenv(this))
+ {
+ glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, mode);
+ glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, &color.r);
+ }
+}
+
+void TexEnv::unbind()
+{
+ TexUnit::current().set_texenv(0);
+}
+
+} // namespace GL
+} // namespace Msp
/* $Id$
This file is part of libmspgl
-Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2008 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
#ifndef MSP_GL_TEXENV_H_
#define MSP_GL_TEXENV_H_
+#include "color.h"
+#include "gl.h"
+
namespace Msp {
namespace GL {
class TexEnv
{
+private:
+ TexEnvMode mode;
+ Color color;
+
public:
- void mode(TexEnvMode);
- void color(float, float, float, float);
+ TexEnv();
+ void set_mode(TexEnvMode);
+ void set_color(const Color &);
+ TexEnvMode get_mode() const { return mode; }
+ const Color &get_color() const { return color; }
+ void bind();
+
+ static void unbind();
};
} // namespace GL
/* $Id$
This file is part of libmspgl
-Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2008 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
return result;
}
+bool TexUnit::set_texenv(const TexEnv *env)
+{
+ bool result=(texenv!=env);
+ texenv=env;
+ return result;
+}
+
TexUnit &TexUnit::activate(unsigned n)
{
if(units.size()<=n)
/* $Id$
This file is part of libmspgl
-Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2008 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
namespace Msp {
namespace GL {
+class TexEnv;
class Texture;
class TexUnit
public:
TexUnit();
bool set_texture(const Texture *);
- const Texture *get_texture() { return texture; }
- //TexEnv &get_env() { return env; }
+ const Texture *get_texture() const { return texture; }
+ bool set_texenv(const TexEnv *);
+ const TexEnv *get_texenv() const { return texenv; }
static TexUnit &activate(unsigned);
static TexUnit ¤t();
private:
const Texture *texture;
- //TexEnv env;
+ const TexEnv *texenv;
static std::vector<TexUnit> units;
static TexUnit *cur_unit;