glc_material.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 
00003  This file is part of the GLC-lib library.
00004  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
00005  Version 2.0.0, packaged on July 2010.
00006 
00007  http://glc-lib.sourceforge.net
00008 
00009  GLC-lib is free software; you can redistribute it and/or modify
00010  it under the terms of the GNU Lesser General Public License as published by
00011  the Free Software Foundation; either version 3 of the License, or
00012  (at your option) any later version.
00013 
00014  GLC-lib is distributed in the hope that it will be useful,
00015  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  GNU Lesser General Public License for more details.
00018 
00019  You should have received a copy of the GNU Lesser General Public License
00020  along with GLC-lib; if not, write to the Free Software
00021  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00022 
00023 *****************************************************************************/
00024 
00026 
00027 #ifndef GLC_MATERIAL_H_
00028 #define GLC_MATERIAL_H_
00029 
00030 
00031 #include "../glc_object.h"
00032 #include "glc_texture.h"
00033 #include <QHash>
00034 #include <QColor>
00035 #include <QSet>
00036 
00037 #include "../glc_config.h"
00038 
00039 class GLC_Geometry;
00040 
00041 typedef QHash< GLC_uint, GLC_Geometry*> WhereUsed;
00042 
00045 
00048 
00049 
00050 
00051 class GLC_LIB_EXPORT GLC_Material : public GLC_Object
00052 {
00053         friend QDataStream &operator<<(QDataStream &, const GLC_Material &);
00054         friend QDataStream &operator>>(QDataStream &, GLC_Material &);
00055 
00057 
00059 
00060 public:
00061 
00064         GLC_Material();
00065 
00067         GLC_Material(const QColor &);
00068 
00070         GLC_Material(const QString& name, const GLfloat *);
00071 
00073         GLC_Material(GLC_Texture* pTexture, const char *pName);
00074 
00076 
00078         GLC_Material(const GLC_Material &InitMaterial);
00079 
00081         virtual ~GLC_Material(void);
00083 
00085 
00087 
00088 public:
00090         static quint32 chunckID();
00091 
00093         bool isUnused() const
00094         {return m_WhereUsed.isEmpty() && m_OtherUsage.isEmpty();}
00095 
00097         inline bool hasTexture() const
00098         {return m_pTexture != NULL;}
00099 
00101         QColor ambientColor() const;
00102 
00104         QColor diffuseColor() const;
00105 
00107         QColor specularColor() const;
00108 
00110         QColor emissiveColor() const;
00111 
00113         inline GLfloat shininess() const
00114         {return m_Shininess;}
00115 
00117         QString textureFileName() const;
00118 
00120         GLuint textureID() const;
00121 
00123         bool textureIsLoaded() const;
00124 
00126         inline bool isTransparent() const
00127         {return  m_Opacity < 1.0;}
00128 
00130         bool operator==(const GLC_Material&) const;
00131 
00133         inline double opacity() const
00134         {return m_DiffuseColor.alphaF();}
00135 
00137         inline int numberOfUsage() const
00138         {return m_WhereUsed.size() + m_OtherUsage.size();}
00139 
00141         inline GLC_Texture* textureHandle() const
00142         {return m_pTexture;}
00143 
00145         uint hashCode() const;
00146 
00148 
00150 
00152 
00153 public:
00155 
00158         inline GLC_Material &operator=(const GLC_Material& mat)
00159         {
00160                 setMaterial(&mat);
00161                 return *this;
00162         }
00163 
00165 
00168          void setMaterial(const GLC_Material*);
00169 
00171         void setAmbientColor(const QColor& ambientColor);
00172 
00174         void setDiffuseColor(const QColor& diffuseColor);
00175 
00177         void setSpecularColor(const QColor& specularColor);
00178 
00180         void setEmissiveColor(const QColor& lightEmission);
00181 
00183         inline void setShininess(GLfloat Shininess)
00184         { m_Shininess= Shininess;}
00185 
00187         void setTexture(GLC_Texture* pTexture);
00188 
00190         void removeTexture();
00191 
00193 
00194         bool addGLC_Geom(GLC_Geometry* pGeom);
00195 
00197 
00198         bool delGLC_Geom(GLC_uint Key);
00199 
00201 
00202         bool addUsage(GLC_uint);
00203 
00205 
00206         bool delUsage(GLC_uint);
00207 
00209         void setOpacity(const qreal);
00210 
00212 
00214 
00216 
00217 public:
00218 
00220         void glLoadTexture(void);
00221 
00223         virtual void glExecute();
00224 
00226         virtual void glExecute(float);
00227 
00229 
00231 // Private services Functions
00233 private:
00235         void initDiffuseColor(void);
00236 
00238         void initOtherColor(void);
00239 
00240 
00242 // Private Member
00244 
00245 private:
00246 
00248         QColor m_AmbientColor;
00250         QColor m_DiffuseColor;
00252         QColor m_SpecularColor;
00253 
00255         QColor m_EmissiveColor;
00256 
00258         GLfloat m_Shininess;
00259 
00261         WhereUsed m_WhereUsed;
00262 
00264         QSet<GLC_uint> m_OtherUsage;
00265 
00267         GLC_Texture* m_pTexture;
00268 
00270         qreal m_Opacity;
00271 
00273         static quint32 m_ChunkId;
00274 
00275 };
00276 
00278 QDataStream &operator<<(QDataStream &, const GLC_Material &);
00279 QDataStream &operator>>(QDataStream &, GLC_Material &);
00280 
00281 #endif //GLC_MATERIAL_H_

SourceForge.net Logo

©2005-2010 Laurent Ribon