GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_3dviewcollection.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_3DVIEWCOLLECTION_H_
26 #define GLC_3DVIEWCOLLECTION_H_
27 
28 
29 #include <QHash>
30 #include "glc_3dviewinstance.h"
31 #include "../glc_global.h"
32 #include "../viewport/glc_frustum.h"
33 
34 #include "../glc_config.h"
35 
37 class GLC_Material;
38 class GLC_Shader;
40 
42 typedef QHash< GLC_uint, GLC_3DViewInstance> ViewInstancesHash;
43 
45 typedef QHash<GLC_uint, GLC_3DViewInstance*> PointerViewInstanceHash;
46 
48 typedef QHash<GLC_uint, PointerViewInstanceHash*> HashList;
49 
51 typedef QHash<GLC_uint, GLC_uint> ShaderIdToInstancesId;
52 
55 
61 
62 
64 {
65 
67 
69 
70 public:
73 
75 
76  virtual ~GLC_3DViewCollection();
77 
79 
81 
83 
84 public:
85 
87  inline bool isEmpty() const
88  {return m_3DViewInstanceHash.size() == 0;}
89 
91  inline int size(void) const
92  {return m_3DViewInstanceHash.size();}
93 
95  QList<GLC_3DViewInstance*> instancesHandle();
96 
98  QList<GLC_3DViewInstance*> visibleInstancesHandle();
99 
101  QList<GLC_3DViewInstance*> viewableInstancesHandle();
102 
104 
105  GLC_3DViewInstance* instanceHandle(GLC_uint Key);
106 
108 
109  GLC_BoundingBox boundingBox(bool allObject= false);
110 
112  inline int selectionSize(void) const
113  {return m_SelectedInstances.size();}
114 
116  inline PointerViewInstanceHash* selection()
117  {return &m_SelectedInstances;}
118 
120  inline bool contains(GLC_uint key) const
121  {return m_3DViewInstanceHash.contains(key);}
122 
124  inline bool isSelected(GLC_uint key) const
125  {return m_SelectedInstances.contains(key);}
126 
128  inline bool showState() const
129  {return m_IsInShowSate;}
130 
132  int drawableObjectsSize() const;
133 
135  inline GLC_uint shadingGroup(GLC_uint key) const
136  { return m_ShaderGroup.value(key);}
137 
139  inline bool isInAShadingGroup(GLC_uint key) const
140  { return m_ShaderGroup.contains(key);}
141 
143  QList<QString> instanceNamesFromShadingGroup(GLuint) const;
144 
146  int numberOfUsedShadingGroup() const;
147 
149  inline bool spacePartitioningIsUsed() const
150  {return m_UseSpacePartitioning;}
151 
153  inline GLC_SpacePartitioning* spacePartitioningHandle()
154  {return m_pSpacePartitioning;}
155 
157  inline bool isViewable() const
158  {return m_IsViewable;}
159 
161 
163 
165 
166 public:
167 
169  /* return true if success false if shader is already bind*/
170  bool bindShader(GLC_uint shaderId);
171 
173  /* return true if success false otherwise*/
174  bool unBindShader(GLC_uint shaderId);
175 
177  bool unBindAllShader();
178 
180 
182  bool add(const GLC_3DViewInstance& ,GLC_uint shaderID=0);
183 
185  /* Move the specified instances into
186  * the specified shading group
187  * Return true if success false otherwise*/
188  void changeShadingGroup(GLC_uint instanceId, GLC_uint shaderId);
189 
191 
198  bool remove(GLC_uint instanceId);
199 
201  void clear(void);
202 
204  bool select(GLC_uint instanceId, bool primitive= false);
205 
207  void selectAll(bool allShowState= false);
208 
210  bool unselect(GLC_uint instanceId);
211 
213  void unselectAll();
214 
216  void setPolygonModeForAll(GLenum face, GLenum mode);
217 
219  void setVisibility(const GLC_uint instanceId, const bool visible);
220 
222  void showAll();
223 
225  void hideAll();
226 
228  inline void swapShowState()
229  {m_IsInShowSate= !m_IsInShowSate;}
230 
232  inline void setLodUsage(const bool usage, GLC_Viewport* pView)
233  {
234  m_UseLod= usage;
235  m_pViewport= pView;
236  }
237 
239  void bindSpacePartitioning(GLC_SpacePartitioning*);
240 
242  void unbindSpacePartitioning();
243 
245  inline void setSpacePartitionningUsage(bool use)
246  {m_UseSpacePartitioning= use;}
247 
249 
251  void updateInstanceViewableState(GLC_Matrix4x4* pMatrix= NULL);
252 
254  void updateInstanceViewableState(const GLC_Frustum&);
255 
257  void updateSpacePartitionning();
258 
260  inline void setAttachedViewport(GLC_Viewport* pViewport)
261  {m_pViewport= pViewport;}
262 
264  inline void setViewable(bool viewable)
265  {m_IsViewable= viewable;}
266 
268  void setVboUsage(bool usage);
269 
271 
273 
275 
276 public:
278 
282  void render(GLuint, glc::RenderFlag);
283 
285  void renderShaderGroup(glc::RenderFlag);
286 
288 
290 
292 
293 
294 private:
296  void glDraw(GLC_uint groupID, glc::RenderFlag renderFlag);
297 
299  inline void glDrawInstancesOf(PointerViewInstanceHash*, glc::RenderFlag);
300 
302 
304 // Private members
306 private:
309 
312 
315 
318 
321 
324 
326  bool m_UseLod;
327 
330 
333 
336 
339 
340 private:
341  Q_DISABLE_COPY(GLC_3DViewCollection)
342 };
343 
344 // Draw instances of a PointerViewInstanceHash
346 {
347  bool forceDisplay= false;
349  {
350  forceDisplay= true;
351  }
352 
353  PointerViewInstanceHash::iterator iEntry= pHash->begin();
354  // The current instance
355  GLC_3DViewInstance* pCurInstance;
356  if (forceDisplay)
357  {
358  while (iEntry != pHash->constEnd())
359  {
360  pCurInstance= iEntry.value();
361  if ((pCurInstance->viewableFlag() != GLC_3DViewInstance::NoViewable) && (pCurInstance->isVisible() == m_IsInShowSate))
362  {
363  pCurInstance->render(renderFlag, m_UseLod, m_pViewport);
364  }
365  ++iEntry;
366  }
367  }
368  else
369  {
370  if (!(renderFlag == glc::TransparentRenderFlag))
371  {
372  while (iEntry != pHash->constEnd())
373  {
374  pCurInstance= iEntry.value();
375  if ((pCurInstance->viewableFlag() != GLC_3DViewInstance::NoViewable) && (pCurInstance->isVisible() == m_IsInShowSate))
376  {
377  if (!pCurInstance->isTransparent() || pCurInstance->renderPropertiesHandle()->isSelected() || (renderFlag == glc::WireRenderFlag))
378  {
379  pCurInstance->render(renderFlag, m_UseLod, m_pViewport);
380  }
381  }
382 
383  ++iEntry;
384  }
385 
386  }
387  else
388  {
389  while (iEntry != pHash->constEnd())
390  {
391  pCurInstance= iEntry.value();
392  if ((pCurInstance->viewableFlag() != GLC_3DViewInstance::NoViewable) && (pCurInstance->isVisible() == m_IsInShowSate))
393  {
394  if (pCurInstance->hasTransparentMaterials())
395  {
396  pCurInstance->render(renderFlag, m_UseLod, m_pViewport);
397  }
398  }
399 
400  ++iEntry;
401  }
402  }
403 
404  }
405 }
406 
407 #endif //GLC_3DVIEWCOLLECTION_H_

©2005-2013 Laurent Ribon