glc_material.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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_fShininess;}
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 setLightEmission(const QColor& lightEmission);
00181
00183 inline void setShininess(GLfloat Shininess)
00184 { m_fShininess= 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
00233 private:
00235 void initDiffuseColor(void);
00236
00238 void initOtherColor(void);
00239
00240
00242
00244
00245 private:
00246
00248 QColor m_AmbientColor;
00250 QColor m_DiffuseColor;
00252 QColor m_SpecularColor;
00253
00255 QColor m_LightEmission;
00256
00258 GLfloat m_fShininess;
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_