00001 /* -*- C++ -*- */ 00002 00003 /* COPYRIGHT 00004 * 00005 * This file is part of the Visual Effects Engine - VEE 00006 * 00007 * Read the "VEE-LICENSE" file for the license. 00008 * 00009 * Authors & Copyright: 00010 * 00011 * Tommi Ilmonen, Tuukka Heikura, Marko Myllymaa and 00012 * Janne Kontkanen 2001-2004 00013 * 00014 * Additional copyrights: Tekes 2003-2004 00015 * 00016 * firstname.lastname@hut.fi 00017 * 00018 */ 00019 00020 #ifndef GEE_GL_MATERIAL_HPP 00021 #define GEE_GL_MATERIAL_HPP 00022 00023 #include <gee_material.h> 00024 00025 #include <GL/gl.h> 00026 00027 #include <vee_color.h> 00028 00029 #include <map> 00030 #include <string> 00031 00032 class GEE_GlRenderer; 00033 00034 00037 class GEE_GlMaterial 00038 { 00039 public: 00040 00041 GEE_GlMaterial(float shine, 00042 const VEE_Rgba & color, 00043 GLuint textureId = (GLuint) -1, 00044 int flags = GEE_MAT_LIGHTING | GEE_MAT_SMOOTH | GEE_MAT_TWO_SIDED); 00045 GEE_GlMaterial(); 00046 00047 virtual ~GEE_GlMaterial(); 00048 00049 void set(float shine, const VEE_Rgba & color, GLuint textureId = (GLuint) -1) 00050 { m_textureId = textureId; m_shine = shine; setColor(color); } 00051 00052 void setShine(float s) { m_shine = s; } 00053 void setFlags(int f) { m_flags = f; } 00054 void setTextureId(GLuint i) { m_textureId = i; } 00056 00057 void setColor(const VEE_Rgba & c) { m_ambient = m_diffuse = m_specular = c; } 00058 void setAmbient(const VEE_Rgba & color) { m_ambient = color; } 00059 void setDiffuse(const VEE_Rgba & color) { m_diffuse = color; } 00060 void setSpecular(const VEE_Rgba & color) { m_specular = color; } 00061 00062 void applyGl(GEE_GlRenderer *) const; 00063 00064 GLuint textureId() const { return m_textureId; } 00065 00066 const VEE_Rgba & ambient() const { return m_ambient; } 00067 const VEE_Rgba & diffuse() const { return m_diffuse; } 00068 const VEE_Rgba & specular() const { return m_specular; } 00069 00070 float uvScale() const { return m_uvScale; } 00071 void setUvScale(float uvScale) { m_uvScale = uvScale; } 00072 00073 bool useVertexColors() const { return m_flags & GEE_MAT_VERTEX_COLORS; } 00074 void setUseVertexColors(bool useColors) 00075 { 00076 if(useColors) m_flags |= GEE_MAT_VERTEX_COLORS; 00077 else m_flags &= ~(GEE_MAT_VERTEX_COLORS); 00078 } 00079 00080 protected: 00081 00082 GLuint m_textureId; 00083 float m_shine; 00084 VEE_Rgba m_ambient, m_diffuse, m_specular; 00085 float m_uvScale; 00086 00087 int m_flags; 00088 }; 00089 00092 00095 class GEE_GlMaterialBank 00096 { 00097 public: 00098 GEE_GlMaterialBank(); 00099 virtual ~GEE_GlMaterialBank(); 00100 00101 void addMaterial(const std::string &, const GEE_GlMaterial &); 00102 00103 const GEE_GlMaterial & getMaterial(const std::string &); 00104 00105 void addUsualColors(); 00106 00107 void forceMaterial(const std::string & mat) { m_forceMaterial = mat; } 00108 void unforceMaterial() { m_forceMaterial.clear(); } 00109 00110 static GEE_GlMaterial & defaultMaterial() { return m_default; } 00111 00112 protected: 00113 00114 static GEE_GlMaterial m_default; 00115 00116 std::map<std::string, GEE_GlMaterial> m_materials; 00117 00118 std::string m_forceMaterial; 00119 }; 00120 00121 00122 #endif