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  http://glc-lib.sourceforge.net
00006 
00007  GLC-lib is free software; you can redistribute it and/or modify
00008  it under the terms of the GNU Lesser General Public License as published by
00009  the Free Software Foundation; either version 3 of the License, or
00010  (at your option) any later version.
00011 
00012  GLC-lib is distributed in the hope that it will be useful,
00013  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  GNU Lesser General Public License for more details.
00016 
00017  You should have received a copy of the GNU Lesser General Public License
00018  along with GLC-lib; if not, write to the Free Software
00019  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021 *****************************************************************************/
00022 
00024 
00025 #ifndef GLC_MATERIAL_H_
00026 #define GLC_MATERIAL_H_
00027 
00028 
00029 #include "../glc_object.h"
00030 #include "glc_texture.h"
00031 #include <QHash>
00032 #include <QColor>
00033 #include <QSet>
00034 
00035 #include "../glc_config.h"
00036 
00037 class GLC_Geometry;
00038 
00039 typedef QHash< GLC_uint, GLC_Geometry*> WhereUsed;
00040 
00043 
00046 
00047 
00048 
00049 class GLC_LIB_EXPORT GLC_Material : public GLC_Object
00050 {
00051         friend QDataStream &operator<<(QDataStream &, const GLC_Material &);
00052         friend QDataStream &operator>>(QDataStream &, GLC_Material &);
00053 
00055 
00057 
00058 public:
00059 
00062         GLC_Material();
00063 
00065         GLC_Material(const QColor &);
00066 
00068         GLC_Material(const QString& name, const GLfloat *);
00069 
00071         GLC_Material(GLC_Texture* pTexture, const QString& name= QString());
00072 
00074 
00076         GLC_Material(const GLC_Material &InitMaterial);
00077 
00079         virtual ~GLC_Material(void);
00081 
00083 
00085 
00086 public:
00088         static quint32 chunckID();
00089 
00091         inline bool isUnused() const
00092         {return m_WhereUsed.isEmpty() && m_OtherUsage.isEmpty();}
00093 
00095         inline bool hasTexture() const
00096         {return m_pTexture != NULL;}
00097 
00099         QColor ambientColor() const;
00100 
00102         QColor diffuseColor() const;
00103 
00105         QColor specularColor() const;
00106 
00108         QColor emissiveColor() const;
00109 
00111         inline GLfloat shininess() const
00112         {return m_Shininess;}
00113 
00115         QString textureFileName() const;
00116 
00118         GLuint textureID() const;
00119 
00121         bool textureIsLoaded() const;
00122 
00124         inline bool isTransparent() const
00125         {return  m_Opacity < 1.0;}
00126 
00128         bool operator==(const GLC_Material&) const;
00129 
00131         inline double opacity() const
00132         {return m_DiffuseColor.alphaF();}
00133 
00135         inline int numberOfUsage() const
00136         {return m_WhereUsed.size() + m_OtherUsage.size();}
00137 
00139         inline GLC_Texture* textureHandle() const
00140         {return m_pTexture;}
00141 
00143         uint hashCode() const;
00144 
00146 
00148 
00150 
00151 public:
00153 
00156         inline GLC_Material &operator=(const GLC_Material& mat)
00157         {
00158                 setMaterial(&mat);
00159                 return *this;
00160         }
00161 
00163 
00166          void setMaterial(const GLC_Material*);
00167 
00169         void setAmbientColor(const QColor& ambientColor);
00170 
00172         void setDiffuseColor(const QColor& diffuseColor);
00173 
00175         void setSpecularColor(const QColor& specularColor);
00176 
00178         void setEmissiveColor(const QColor& lightEmission);
00179 
00181         inline void setShininess(GLfloat Shininess)
00182         { m_Shininess= Shininess;}
00183 
00185         void setTexture(GLC_Texture* pTexture);
00186 
00188         void removeTexture();
00189 
00191 
00192         bool addGLC_Geom(GLC_Geometry* pGeom);
00193 
00195 
00196         bool delGLC_Geom(GLC_uint Key);
00197 
00199 
00200         bool addUsage(GLC_uint);
00201 
00203 
00204         bool delUsage(GLC_uint);
00205 
00207         void setOpacity(const qreal);
00208 
00210 
00212 
00214 
00215 public:
00216 
00218         void glLoadTexture(QGLContext* pContext= NULL);
00219 
00221         virtual void glExecute();
00222 
00224         virtual void glExecute(float);
00225 
00227 
00229 // Private services Functions
00231 private:
00233         void initDiffuseColor(void);
00234 
00236         void initOtherColor(void);
00237 
00238 
00240 // Private Member
00242 
00243 private:
00244 
00246         QColor m_AmbientColor;
00248         QColor m_DiffuseColor;
00250         QColor m_SpecularColor;
00251 
00253         QColor m_EmissiveColor;
00254 
00256         GLfloat m_Shininess;
00257 
00259         WhereUsed m_WhereUsed;
00260 
00262         QSet<GLC_uint> m_OtherUsage;
00263 
00265         GLC_Texture* m_pTexture;
00266 
00268         qreal m_Opacity;
00269 
00271         static quint32 m_ChunkId;
00272 
00273 };
00274 
00276 QDataStream &operator<<(QDataStream &, const GLC_Material &);
00277 QDataStream &operator>>(QDataStream &, GLC_Material &);
00278 
00279 #endif //GLC_MATERIAL_H_

SourceForge.net Logo

©2005-2011 Laurent Ribon