GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_material.h
Go to the documentation of this file.
1 /****************************************************************************
2 
3  This file is part of the GLC-lib library.
4  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
5  http://glc-lib.sourceforge.net
6 
7  GLC-lib is free software; you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  GLC-lib is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with GLC-lib; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21 *****************************************************************************/
22 
24 
25 #ifndef GLC_MATERIAL_H_
26 #define GLC_MATERIAL_H_
27 
28 
29 #include "../glc_object.h"
30 #include "glc_texture.h"
31 #include <QHash>
32 #include <QColor>
33 #include <QSet>
34 
35 #include "../glc_config.h"
36 
38 
39 typedef QHash< GLC_uint, GLC_Geometry*> WhereUsed;
40 
43 
46 
47 
48 
50 {
51  friend QDataStream &operator<<(QDataStream &, const GLC_Material &);
52  friend QDataStream &operator>>(QDataStream &, GLC_Material &);
53 
55 
57 
58 public:
59 
62  GLC_Material();
63 
65  GLC_Material(const QColor &);
66 
68  GLC_Material(const QString& name, const GLfloat *);
69 
71  GLC_Material(GLC_Texture* pTexture, const QString& name= QString());
72 
74 
76  GLC_Material(const GLC_Material &InitMaterial);
77 
79  virtual ~GLC_Material(void);
81 
83 
85 
86 public:
88  static quint32 chunckID();
89 
91  inline bool isUnused() const
92  {return m_WhereUsed.isEmpty() && m_OtherUsage.isEmpty();}
93 
95  inline bool hasTexture() const
96  {return m_pTexture != NULL;}
97 
99  QColor ambientColor() const;
100 
102  QColor diffuseColor() const;
103 
105  QColor specularColor() const;
106 
108  QColor emissiveColor() const;
109 
111  inline GLfloat shininess() const
112  {return m_Shininess;}
113 
115  QString textureFileName() const;
116 
118  GLuint textureID() const;
119 
121  bool textureIsLoaded() const;
122 
124  inline bool isTransparent() const
125  {return m_Opacity < 1.0;}
126 
128  bool operator==(const GLC_Material&) const;
129 
131  inline double opacity() const
132  {return m_DiffuseColor.alphaF();}
133 
135  inline int numberOfUsage() const
136  {return m_WhereUsed.size() + m_OtherUsage.size();}
137 
139  inline GLC_Texture* textureHandle() const
140  {return m_pTexture;}
141 
143  uint hashCode() const;
144 
146 
148 
150 
151 public:
153 
156  inline GLC_Material &operator=(const GLC_Material& mat)
157  {
158  setMaterial(&mat);
159  return *this;
160  }
161 
163 
166  void setMaterial(const GLC_Material*);
167 
169  void setAmbientColor(const QColor& ambientColor);
170 
172  void setDiffuseColor(const QColor& diffuseColor);
173 
175  void setSpecularColor(const QColor& specularColor);
176 
178  void setEmissiveColor(const QColor& lightEmission);
179 
181  inline void setShininess(GLfloat Shininess)
182  { m_Shininess= Shininess;}
183 
185  void setTexture(GLC_Texture* pTexture);
186 
188  void removeTexture();
189 
191 
192  bool addGLC_Geom(GLC_Geometry* pGeom);
193 
195 
196  bool delGLC_Geom(GLC_uint Key);
197 
199 
200  bool addUsage(GLC_uint);
201 
203 
204  bool delUsage(GLC_uint);
205 
207  void setOpacity(const qreal);
208 
210 
212 
214 
215 public:
216 
218  void glLoadTexture(QGLContext* pContext= NULL);
219 
221  virtual void glExecute();
222 
224  virtual void glExecute(float);
225 
227 
229 // Private services Functions
231 private:
233  void initDiffuseColor(void);
234 
236  void initOtherColor(void);
237 
238 
240 // Private Member
242 
243 private:
244 
251 
254 
256  GLfloat m_Shininess;
257 
260 
262  QSet<GLC_uint> m_OtherUsage;
263 
266 
268  qreal m_Opacity;
269 
271  static quint32 m_ChunkId;
272 
273 };
274 
276 QDataStream &operator<<(QDataStream &, const GLC_Material &);
277 QDataStream &operator>>(QDataStream &, GLC_Material &);
278 
279 #endif //GLC_MATERIAL_H_

©2005-2013 Laurent Ribon