glc_3dviewcollection.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 
00003  This file is part of the GLC-lib library.
00004  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
00005  Version 2.0.0 Beta 1, packaged on April 2010.
00006 
00007  http://glc-lib.sourceforge.net
00008 
00009  GLC-lib is free software; you can redistribute it and/or modify
00010  it under the terms of the GNU General Public License as published by
00011  the Free Software Foundation; either version 2 of the License, or
00012  (at your option) any later version.
00013 
00014  GLC-lib is distributed in the hope that it will be useful,
00015  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  GNU General Public License for more details.
00018 
00019  You should have received a copy of the GNU General Public License
00020  along with GLC-lib; if not, write to the Free Software
00021  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00022 
00023 *****************************************************************************/
00024 
00026 
00027 #ifndef GLC_3DVIEWCOLLECTION_H_
00028 #define GLC_3DVIEWCOLLECTION_H_
00029 
00030 
00031 #include <QHash>
00032 #include "glc_3dviewinstance.h"
00033 #include "../glc_global.h"
00034 #include "../viewport/glc_frustum.h"
00035 
00036 #include "../glc_config.h"
00037 
00038 class GLC_SpacePartitioning;
00039 class GLC_Material;
00040 class GLC_Shader;
00041 class GLC_Viewport;
00042 
00044 typedef QHash< GLC_uint, GLC_3DViewInstance> ViewInstancesHash;
00045 
00047 typedef QHash<GLC_uint, GLC_3DViewInstance*> PointerViewInstanceHash;
00048 
00050 typedef QHash<GLuint, PointerViewInstanceHash*> HashList;
00051 
00053 typedef QHash<GLC_uint, GLuint> ShaderIdToInstancesId;
00054 
00057 
00063 
00064 
00065 class GLC_LIB_EXPORT GLC_3DViewCollection
00066 {
00067 
00069 
00071 
00072 public:
00074         GLC_3DViewCollection();
00075 
00077 
00078         virtual ~GLC_3DViewCollection();
00079 
00081 
00083 
00085 
00086 public:
00087 
00089         inline bool isEmpty() const
00090         {return m_3DViewInstanceHash.size() == 0;}
00091 
00093         inline int size(void) const
00094         {return m_3DViewInstanceHash.size();}
00095 
00097         QList<GLC_3DViewInstance*> instancesHandle();
00098 
00100         QList<GLC_3DViewInstance*> visibleInstancesHandle();
00101 
00103         QList<GLC_3DViewInstance*> viewableInstancesHandle();
00104 
00106 
00107         GLC_3DViewInstance* instanceHandle(GLC_uint Key);
00108 
00110         GLC_BoundingBox boundingBox(void);
00111 
00113         inline int selectionSize(void) const
00114         {return m_SelectedInstances.size();}
00115 
00117         inline PointerViewInstanceHash* selection()
00118         {return &m_SelectedInstances;}
00119 
00121         inline bool contains(GLC_uint key) const
00122         {return m_3DViewInstanceHash.contains(key);}
00123 
00125         inline bool isSelected(GLC_uint key) const
00126         {return m_SelectedInstances.contains(key);}
00127 
00129         inline bool showState() const
00130         {return m_IsInShowSate;}
00131 
00133         int drawableObjectsSize() const;
00134 
00136         inline GLuint shadingGroup(GLC_uint key) const
00137         { return m_ShaderGroup.value(key);}
00138 
00140         inline bool isInAShadingGroup(GLC_uint key) const
00141         { return m_ShaderGroup.contains(key);}
00142 
00144         QList<QString> instanceNamesFromShadingGroup(GLuint) const;
00145 
00147         int numberOfUsedShadingGroup() const;
00148 
00150         inline bool spacePartitioningIsUsed() const
00151         {return m_UseSpacePartitioning;}
00152 
00154         inline GLC_SpacePartitioning* spacePartitioningHandle()
00155         {return m_pSpacePartitioning;}
00156 
00157 
00159 
00161 
00163 
00164 public:
00165 
00167          /* return true if success false if shader is already bind*/
00168         bool bindShader(GLuint);
00169 
00171         /* return true if success false otherwise*/
00172         bool unBindShader(GLuint);
00173 
00175         bool unBindAllShader();
00176 
00178 
00180         bool add(const GLC_3DViewInstance& ,GLuint shaderID=0);
00181 
00183         /* Move the specified instances into
00184          * the specified shading group
00185          * Return true if success false otherwise*/
00186         void changeShadingGroup(GLC_uint, GLuint);
00187 
00189 
00196         bool remove(GLC_uint Key);
00197 
00199         void clear(void);
00200 
00202         bool select(GLC_uint, bool primitive= false);
00203 
00205         void selectAll();
00206 
00208         bool unselect(GLC_uint);
00209 
00211         void unselectAll();
00212 
00214         void setPolygonModeForAll(GLenum, GLenum);
00215 
00217         void setVisibility(const GLC_uint, const bool);
00218 
00220         void showAll();
00221 
00223         void hideAll();
00224 
00226         inline void swapShowState()
00227         {
00228                 m_IsInShowSate= !m_IsInShowSate;
00229                 // Bounding box validity
00230                 if (NULL != m_pBoundingBox)
00231                 {
00232                         delete m_pBoundingBox;
00233                         m_pBoundingBox= NULL;
00234                 }
00235         }
00236 
00238         inline void setLodUsage(const bool usage, GLC_Viewport* pView)
00239         {
00240                 m_UseLod= usage;
00241                 m_pViewport= pView;
00242         }
00243 
00245         void bindSpacePartitioning(GLC_SpacePartitioning*);
00246 
00248         void unbindSpacePartitioning();
00249 
00251         inline void setSpacePartitionningUsage(bool use)
00252         {m_UseSpacePartitioning= use;}
00253 
00255 
00257         void updateInstanceViewableState(GLC_Matrix4x4* pMatrix= NULL);
00258 
00260         void updateInstanceViewableState(const GLC_Frustum&);
00261 
00262 
00264 
00266 
00268 
00269 public:
00271 
00275         void render(GLuint, glc::RenderFlag);
00276 
00278         void renderShaderGroup(glc::RenderFlag);
00279 
00281 
00283 
00285 
00286 
00287 private:
00289         void glDraw(GLuint, glc::RenderFlag);
00290 
00292         inline void glDrawInstancesOf(PointerViewInstanceHash*, glc::RenderFlag);
00293 
00295 
00297 
00299 
00300 
00301 private:
00303         void setBoundingBoxValidity(void);
00304 
00306 
00308 // Private members
00310 private:
00312         ViewInstancesHash m_3DViewInstanceHash;
00313 
00315         GLC_BoundingBox* m_pBoundingBox;
00316 
00318         PointerViewInstanceHash m_SelectedInstances;
00319 
00321         HashList m_ShadedPointerViewInstanceHash;
00322 
00324         ShaderIdToInstancesId m_ShaderGroup;
00325 
00327         PointerViewInstanceHash m_MainInstances;
00328 
00330         bool m_IsInShowSate;
00331 
00333         bool m_UseLod;
00334 
00336         GLC_Viewport* m_pViewport;
00337 
00339         GLC_SpacePartitioning* m_pSpacePartitioning;
00340 
00342         bool m_UseSpacePartitioning;
00343 
00344 
00345 };
00346 
00347 // Draw instances of a PointerViewInstanceHash
00348 void GLC_3DViewCollection::glDrawInstancesOf(PointerViewInstanceHash* pHash, glc::RenderFlag renderFlag)
00349 {
00350         bool forceDisplay= false;
00351         if (GLC_State::isInSelectionMode())
00352         {
00353                 forceDisplay= true;
00354         }
00355 
00356         PointerViewInstanceHash::iterator iEntry= pHash->begin();
00357         // The current instance
00358         GLC_3DViewInstance* pCurInstance;
00359         if (forceDisplay)
00360         {
00361                 while (iEntry != pHash->constEnd())
00362                 {
00363                         pCurInstance= iEntry.value();
00364                         if ((pCurInstance->viewableFlag() != GLC_3DViewInstance::NoViewable) && (pCurInstance->isVisible() == m_IsInShowSate))
00365                         {
00366                                 pCurInstance->render(renderFlag, m_UseLod, m_pViewport);
00367                         }
00368                         ++iEntry;
00369                 }
00370         }
00371         else
00372         {
00373                 if (!(renderFlag == glc::TransparentRenderFlag))
00374                 {
00375                         while (iEntry != pHash->constEnd())
00376                         {
00377                                 pCurInstance= iEntry.value();
00378                                 if ((pCurInstance->viewableFlag() != GLC_3DViewInstance::NoViewable) && (pCurInstance->isVisible() == m_IsInShowSate))
00379                                 {
00380                                         if (!pCurInstance->isTransparent() || pCurInstance->renderPropertiesHandle()->isSelected() || (renderFlag == glc::WireRenderFlag))
00381                                         {
00382                                                 pCurInstance->render(renderFlag, m_UseLod, m_pViewport);
00383                                         }
00384                                 }
00385 
00386                                 ++iEntry;
00387                         }
00388 
00389                 }
00390                 else
00391                 {
00392                         while (iEntry != pHash->constEnd())
00393                         {
00394                                 pCurInstance= iEntry.value();
00395                                 if ((pCurInstance->viewableFlag() != GLC_3DViewInstance::NoViewable) && (pCurInstance->isVisible() == m_IsInShowSate))
00396                                 {
00397                                         if (pCurInstance->hasTransparentMaterials())
00398                                         {
00399                                                 pCurInstance->render(renderFlag, m_UseLod, m_pViewport);
00400                                         }
00401                                 }
00402 
00403                                 ++iEntry;
00404                         }
00405            }
00406 
00407         }
00408 }
00409 
00410 #endif //GLC_3DVIEWCOLLECTION_H_

SourceForge.net Logo

©2005 Laurent Ribon