GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_renderproperties.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_RENDERPROPERTIES_H_
26 #define GLC_RENDERPROPERTIES_H_
27 
28 #include "glc_material.h"
29 #include "../glc_global.h"
30 
31 #include <QSet>
32 #include <QHash>
33 #include <QtOpenGL>
34 
35 #include "../glc_config.h"
36 
38 namespace glc
39 {
42  {
51  };
52 
55  {
60  };
61 };
64 
66 
68 {
69 
71 
73 
74 public:
77 
80 
82  GLC_RenderProperties &operator=(const GLC_RenderProperties&);
83 
85  virtual ~GLC_RenderProperties();
87 
88 
90 
91 public:
93  inline bool isSelected() const
94  {return m_IsSelected;}
95 
97  inline glc::RenderMode renderingMode() const
98  {return m_RenderMode;}
99 
101  inline glc::RenderMode savedRenderingMode() const
102  {return m_SavedRenderMode;}
103 
105  inline GLC_Material* overwriteMaterial() const
106  {return m_pOverwriteMaterial;}
107 
109  inline float overwriteTransparency() const
110  {return m_OverwriteOpacity;}
111 
113  inline QSet<GLC_uint>* setOfSelectedPrimitivesId() const
114  {
115  Q_ASSERT(NULL != m_pBodySelectedPrimitvesId);
116  if (m_pBodySelectedPrimitvesId->contains(m_CurrentBody))
117  return m_pBodySelectedPrimitvesId->value(m_CurrentBody);
118  else return NULL;
119  }
120 
122  inline bool setOfSelectedPrimitiveIdIsEmpty() const
123  {return (!((NULL != m_pBodySelectedPrimitvesId) && m_pBodySelectedPrimitvesId->contains(m_CurrentBody)));}
124 
126  bool primitiveIsSelected(int index, GLC_uint id) const;
127 
129  inline QHash<GLC_uint, GLC_Material*>* hashOfOverwritePrimitiveMaterials() const
130  {
131  Q_ASSERT(NULL != m_pOverwritePrimitiveMaterialMaps);
132  if (m_pOverwritePrimitiveMaterialMaps->contains(m_CurrentBody))
133  return m_pOverwritePrimitiveMaterialMaps->value(m_CurrentBody);
134  else return NULL;
135  }
136 
138  inline bool hashOfOverwritePrimitiveMaterialsIsEmpty() const
139  {return (!((NULL != m_pOverwritePrimitiveMaterialMaps) && m_pOverwritePrimitiveMaterialMaps->contains(m_CurrentBody)));}
140 
142 
143  inline GLenum polyFaceMode() const
144  {return m_PolyFace;}
145 
147 
148  inline GLenum polygonMode() const
149  {return m_PolyMode;}
150 
152  inline glc::RenderFlag renderingFlag() const
153  {return m_RenderingFlag;}
154 
156  bool needToRenderWithTransparency() const;
157 
159  inline int currentBodyIndex() const
160  {return m_CurrentBody;}
161 
163  bool isDefault() const;
164 
166 
168 
170 
171 public:
172 
174  void clear();
176 
177 
179 
180 public:
182  inline void select(bool primitive);
183 
185  inline void unselect(void);
186 
188  inline void setRenderingMode(glc::RenderMode mode)
189  {m_RenderMode= mode;}
190 
192  void setOverwriteMaterial(GLC_Material*);
193 
195  inline void setOverwriteTransparency(float alpha)
196  {m_OverwriteOpacity= alpha;}
197 
199  void addSetOfSelectedPrimitivesId(const QSet<GLC_uint>&, int body= 0);
200 
202  void addSelectedPrimitive(GLC_uint, int body= 0);
203 
205  void clearSelectedPrimitives();
206 
208  void addOverwritePrimitiveMaterial(GLC_uint, GLC_Material*, int bodyIndex= 0);
209 
211  void clearOverwritePrimitiveMaterials();
212 
214 
216  inline void setPolygonMode(GLenum Face, GLenum Mode)
217  {
218  m_PolyFace= Face;
219  m_PolyMode= Mode;
220  }
221 
223  inline void setRenderingFlag(glc::RenderFlag flag)
224  {m_RenderingFlag= flag;}
225 
227  inline void setCurrentBodyIndex(int index)
228  {m_CurrentBody= index;}
229 
231  inline void useMaterial(GLC_Material*);
232 
234  inline void unUseMaterial(GLC_Material*);
235 
236 
238 
240 //Private attributes
242 private:
245 
248 
250  GLenum m_PolyFace;
251  GLenum m_PolyMode;
252 
255 
258 
261 
264 
266  QHash<int, QSet<GLC_uint>* >* m_pBodySelectedPrimitvesId;
267 
269  QHash<int, QHash<GLC_uint, GLC_Material* >* >* m_pOverwritePrimitiveMaterialMaps;
270 
273 
276 
278  QHash<GLC_Material*, int> m_MaterialsUsage;
279 
280 };
281 
282 // Select the instance
283 void GLC_RenderProperties::select(bool primitive)
284 {
285  m_IsSelected= true;
286  if (primitive && (m_RenderMode != glc::PrimitiveSelected))
287  {
290  }
291 }
292 
293 // Unselect the instance
295 {
296  m_IsSelected= false;
298  {
300  }
301 }
302 // Used the specified material
304 {
305  if (m_MaterialsUsage.contains(pMaterial))
306  {
307  QHash<GLC_Material*, int>::iterator iMat= m_MaterialsUsage.find(pMaterial);
308  iMat.value()= iMat.value() + 1;
309  }
310  else
311  {
312  m_MaterialsUsage.insert(pMaterial, 1);
313  pMaterial->addUsage(m_Uid);
314  }
315 
316 }
317 
318 // Unused the specified material
320 {
321  Q_ASSERT(m_MaterialsUsage.contains(pMaterial));
322  QHash<GLC_Material*, int>::iterator iMat= m_MaterialsUsage.find(pMaterial);
323  iMat.value()= iMat.value() - 1;
324  if (iMat.value() == 0)
325  {
326  pMaterial->delUsage(m_Uid);
327  if (pMaterial->isUnused()) delete pMaterial;
328  m_MaterialsUsage.remove(pMaterial);
329  }
330 }
331 
332 #endif /* GLC_RENDERPROPERTIES_H_ */

©2005-2013 Laurent Ribon