glc_3dviewcollection.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
00024
00025 #ifndef GLC_3DVIEWCOLLECTION_H_
00026 #define GLC_3DVIEWCOLLECTION_H_
00027
00028
00029 #include <QHash>
00030 #include "glc_3dviewinstance.h"
00031 #include "../glc_global.h"
00032 #include "../viewport/glc_frustum.h"
00033
00034 #include "../glc_config.h"
00035
00036 class GLC_SpacePartitioning;
00037 class GLC_Material;
00038 class GLC_Shader;
00039 class GLC_Viewport;
00040
00042 typedef QHash< GLC_uint, GLC_3DViewInstance> ViewInstancesHash;
00043
00045 typedef QHash<GLC_uint, GLC_3DViewInstance*> PointerViewInstanceHash;
00046
00048 typedef QHash<GLuint, PointerViewInstanceHash*> HashList;
00049
00051 typedef QHash<GLC_uint, GLuint> ShaderIdToInstancesId;
00052
00055
00061
00062
00063 class GLC_LIB_EXPORT GLC_3DViewCollection
00064 {
00065
00067
00069
00070 public:
00072 GLC_3DViewCollection();
00073
00075
00076 virtual ~GLC_3DViewCollection();
00077
00079
00081
00083
00084 public:
00085
00087 inline bool isEmpty() const
00088 {return m_3DViewInstanceHash.size() == 0;}
00089
00091 inline int size(void) const
00092 {return m_3DViewInstanceHash.size();}
00093
00095 QList<GLC_3DViewInstance*> instancesHandle();
00096
00098 QList<GLC_3DViewInstance*> visibleInstancesHandle();
00099
00101 QList<GLC_3DViewInstance*> viewableInstancesHandle();
00102
00104
00105 GLC_3DViewInstance* instanceHandle(GLC_uint Key);
00106
00108
00109 GLC_BoundingBox boundingBox(bool allObject= false);
00110
00112 inline int selectionSize(void) const
00113 {return m_SelectedInstances.size();}
00114
00116 inline PointerViewInstanceHash* selection()
00117 {return &m_SelectedInstances;}
00118
00120 inline bool contains(GLC_uint key) const
00121 {return m_3DViewInstanceHash.contains(key);}
00122
00124 inline bool isSelected(GLC_uint key) const
00125 {return m_SelectedInstances.contains(key);}
00126
00128 inline bool showState() const
00129 {return m_IsInShowSate;}
00130
00132 int drawableObjectsSize() const;
00133
00135 inline GLuint shadingGroup(GLC_uint key) const
00136 { return m_ShaderGroup.value(key);}
00137
00139 inline bool isInAShadingGroup(GLC_uint key) const
00140 { return m_ShaderGroup.contains(key);}
00141
00143 QList<QString> instanceNamesFromShadingGroup(GLuint) const;
00144
00146 int numberOfUsedShadingGroup() const;
00147
00149 inline bool spacePartitioningIsUsed() const
00150 {return m_UseSpacePartitioning;}
00151
00153 inline GLC_SpacePartitioning* spacePartitioningHandle()
00154 {return m_pSpacePartitioning;}
00155
00156
00158
00160
00162
00163 public:
00164
00166
00167 bool bindShader(GLuint);
00168
00170
00171 bool unBindShader(GLuint);
00172
00174 bool unBindAllShader();
00175
00177
00179 bool add(const GLC_3DViewInstance& ,GLuint shaderID=0);
00180
00182
00183
00184
00185 void changeShadingGroup(GLC_uint, GLuint);
00186
00188
00195 bool remove(GLC_uint Key);
00196
00198 void clear(void);
00199
00201 bool select(GLC_uint, bool primitive= false);
00202
00204 void selectAll(bool allShowState= false);
00205
00207 bool unselect(GLC_uint);
00208
00210 void unselectAll();
00211
00213 void setPolygonModeForAll(GLenum, GLenum);
00214
00216 void setVisibility(const GLC_uint, const bool);
00217
00219 void showAll();
00220
00222 void hideAll();
00223
00225 inline void swapShowState()
00226 {m_IsInShowSate= !m_IsInShowSate;}
00227
00229 inline void setLodUsage(const bool usage, GLC_Viewport* pView)
00230 {
00231 m_UseLod= usage;
00232 m_pViewport= pView;
00233 }
00234
00236 void bindSpacePartitioning(GLC_SpacePartitioning*);
00237
00239 void unbindSpacePartitioning();
00240
00242 inline void setSpacePartitionningUsage(bool use)
00243 {m_UseSpacePartitioning= use;}
00244
00246
00248 void updateInstanceViewableState(GLC_Matrix4x4* pMatrix= NULL);
00249
00251 void updateInstanceViewableState(const GLC_Frustum&);
00252
00254 inline void setAttachedViewport(GLC_Viewport* pViewport)
00255 {m_pViewport= pViewport;}
00257
00259
00261
00262 public:
00264
00268 void render(GLuint, glc::RenderFlag);
00269
00271 void renderShaderGroup(glc::RenderFlag);
00272
00274
00276
00278
00279
00280 private:
00282 void glDraw(GLuint, glc::RenderFlag);
00283
00285 inline void glDrawInstancesOf(PointerViewInstanceHash*, glc::RenderFlag);
00286
00288
00290
00292 private:
00294 ViewInstancesHash m_3DViewInstanceHash;
00295
00297 PointerViewInstanceHash m_SelectedInstances;
00298
00300 HashList m_ShadedPointerViewInstanceHash;
00301
00303 ShaderIdToInstancesId m_ShaderGroup;
00304
00306 PointerViewInstanceHash m_MainInstances;
00307
00309 bool m_IsInShowSate;
00310
00312 bool m_UseLod;
00313
00315 GLC_Viewport* m_pViewport;
00316
00318 GLC_SpacePartitioning* m_pSpacePartitioning;
00319
00321 bool m_UseSpacePartitioning;
00322
00323
00324 };
00325
00326
00327 void GLC_3DViewCollection::glDrawInstancesOf(PointerViewInstanceHash* pHash, glc::RenderFlag renderFlag)
00328 {
00329 bool forceDisplay= false;
00330 if (GLC_State::isInSelectionMode())
00331 {
00332 forceDisplay= true;
00333 }
00334
00335 PointerViewInstanceHash::iterator iEntry= pHash->begin();
00336
00337 GLC_3DViewInstance* pCurInstance;
00338 if (forceDisplay)
00339 {
00340 while (iEntry != pHash->constEnd())
00341 {
00342 pCurInstance= iEntry.value();
00343 if ((pCurInstance->viewableFlag() != GLC_3DViewInstance::NoViewable) && (pCurInstance->isVisible() == m_IsInShowSate))
00344 {
00345 pCurInstance->render(renderFlag, m_UseLod, m_pViewport);
00346 }
00347 ++iEntry;
00348 }
00349 }
00350 else
00351 {
00352 if (!(renderFlag == glc::TransparentRenderFlag))
00353 {
00354 while (iEntry != pHash->constEnd())
00355 {
00356 pCurInstance= iEntry.value();
00357 if ((pCurInstance->viewableFlag() != GLC_3DViewInstance::NoViewable) && (pCurInstance->isVisible() == m_IsInShowSate))
00358 {
00359 if (!pCurInstance->isTransparent() || pCurInstance->renderPropertiesHandle()->isSelected() || (renderFlag == glc::WireRenderFlag))
00360 {
00361 pCurInstance->render(renderFlag, m_UseLod, m_pViewport);
00362 }
00363 }
00364
00365 ++iEntry;
00366 }
00367
00368 }
00369 else
00370 {
00371 while (iEntry != pHash->constEnd())
00372 {
00373 pCurInstance= iEntry.value();
00374 if ((pCurInstance->viewableFlag() != GLC_3DViewInstance::NoViewable) && (pCurInstance->isVisible() == m_IsInShowSate))
00375 {
00376 if (pCurInstance->hasTransparentMaterials())
00377 {
00378 pCurInstance->render(renderFlag, m_UseLod, m_pViewport);
00379 }
00380 }
00381
00382 ++iEntry;
00383 }
00384 }
00385
00386 }
00387 }
00388
00389 #endif //GLC_3DVIEWCOLLECTION_H_