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  http://glc-lib.sourceforge.net
00006 
00007  GLC-lib is free software; you can redistribute it and/or modify
00008  it under the terms of the GNU Lesser General Public License as published by
00009  the Free Software Foundation; either version 3 of the License, or
00010  (at your option) any later version.
00011 
00012  GLC-lib is distributed in the hope that it will be useful,
00013  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  GNU Lesser General Public License for more details.
00016 
00017  You should have received a copy of the GNU Lesser General Public License
00018  along with GLC-lib; if not, write to the Free Software
00019  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
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<GLC_uint, PointerViewInstanceHash*> HashList;
00049 
00051 typedef QHash<GLC_uint, GLC_uint> 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 GLC_uint 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 
00157         inline bool isViewable() const
00158         {return m_IsViewable;}
00159 
00161 
00163 
00165 
00166 public:
00167 
00169          /* return true if success false if shader is already bind*/
00170         bool bindShader(GLC_uint shaderId);
00171 
00173         /* return true if success false otherwise*/
00174         bool unBindShader(GLC_uint shaderId);
00175 
00177         bool unBindAllShader();
00178 
00180 
00182         bool add(const GLC_3DViewInstance& ,GLC_uint shaderID=0);
00183 
00185         /* Move the specified instances into
00186          * the specified shading group
00187          * Return true if success false otherwise*/
00188         void changeShadingGroup(GLC_uint instanceId, GLC_uint shaderId);
00189 
00191 
00198         bool remove(GLC_uint instanceId);
00199 
00201         void clear(void);
00202 
00204         bool select(GLC_uint instanceId, bool primitive= false);
00205 
00207         void selectAll(bool allShowState= false);
00208 
00210         bool unselect(GLC_uint instanceId);
00211 
00213         void unselectAll();
00214 
00216         void setPolygonModeForAll(GLenum face, GLenum mode);
00217 
00219         void setVisibility(const GLC_uint instanceId, const bool visible);
00220 
00222         void showAll();
00223 
00225         void hideAll();
00226 
00228         inline void swapShowState()
00229         {m_IsInShowSate= !m_IsInShowSate;}
00230 
00232         inline void setLodUsage(const bool usage, GLC_Viewport* pView)
00233         {
00234                 m_UseLod= usage;
00235                 m_pViewport= pView;
00236         }
00237 
00239         void bindSpacePartitioning(GLC_SpacePartitioning*);
00240 
00242         void unbindSpacePartitioning();
00243 
00245         inline void setSpacePartitionningUsage(bool use)
00246         {m_UseSpacePartitioning= use;}
00247 
00249 
00251         void updateInstanceViewableState(GLC_Matrix4x4* pMatrix= NULL);
00252 
00254         void updateInstanceViewableState(const GLC_Frustum&);
00255 
00257         inline void setAttachedViewport(GLC_Viewport* pViewport)
00258         {m_pViewport= pViewport;}
00259 
00261         inline void setViewable(bool viewable)
00262         {m_IsViewable= viewable;}
00263 
00265         void setVboUsage(bool usage);
00266 
00268 
00270 
00272 
00273 public:
00275 
00279         void render(GLuint, glc::RenderFlag);
00280 
00282         void renderShaderGroup(glc::RenderFlag);
00283 
00285 
00287 
00289 
00290 
00291 private:
00293         void glDraw(GLC_uint groupID, glc::RenderFlag renderFlag);
00294 
00296         inline void glDrawInstancesOf(PointerViewInstanceHash*, glc::RenderFlag);
00297 
00299 
00301 // Private members
00303 private:
00305         ViewInstancesHash m_3DViewInstanceHash;
00306 
00308         PointerViewInstanceHash m_SelectedInstances;
00309 
00311         HashList m_ShadedPointerViewInstanceHash;
00312 
00314         ShaderIdToInstancesId m_ShaderGroup;
00315 
00317         PointerViewInstanceHash m_MainInstances;
00318 
00320         bool m_IsInShowSate;
00321 
00323         bool m_UseLod;
00324 
00326         GLC_Viewport* m_pViewport;
00327 
00329         GLC_SpacePartitioning* m_pSpacePartitioning;
00330 
00332         bool m_UseSpacePartitioning;
00333 
00335         bool m_IsViewable;
00336 
00337 
00338 };
00339 
00340 // Draw instances of a PointerViewInstanceHash
00341 void GLC_3DViewCollection::glDrawInstancesOf(PointerViewInstanceHash* pHash, glc::RenderFlag renderFlag)
00342 {
00343         bool forceDisplay= false;
00344         if (GLC_State::isInSelectionMode())
00345         {
00346                 forceDisplay= true;
00347         }
00348 
00349         PointerViewInstanceHash::iterator iEntry= pHash->begin();
00350         // The current instance
00351         GLC_3DViewInstance* pCurInstance;
00352         if (forceDisplay)
00353         {
00354                 while (iEntry != pHash->constEnd())
00355                 {
00356                         pCurInstance= iEntry.value();
00357                         if ((pCurInstance->viewableFlag() != GLC_3DViewInstance::NoViewable) && (pCurInstance->isVisible() == m_IsInShowSate))
00358                         {
00359                                 pCurInstance->render(renderFlag, m_UseLod, m_pViewport);
00360                         }
00361                         ++iEntry;
00362                 }
00363         }
00364         else
00365         {
00366                 if (!(renderFlag == glc::TransparentRenderFlag))
00367                 {
00368                         while (iEntry != pHash->constEnd())
00369                         {
00370                                 pCurInstance= iEntry.value();
00371                                 if ((pCurInstance->viewableFlag() != GLC_3DViewInstance::NoViewable) && (pCurInstance->isVisible() == m_IsInShowSate))
00372                                 {
00373                                         if (!pCurInstance->isTransparent() || pCurInstance->renderPropertiesHandle()->isSelected() || (renderFlag == glc::WireRenderFlag))
00374                                         {
00375                                                 pCurInstance->render(renderFlag, m_UseLod, m_pViewport);
00376                                         }
00377                                 }
00378 
00379                                 ++iEntry;
00380                         }
00381 
00382                 }
00383                 else
00384                 {
00385                         while (iEntry != pHash->constEnd())
00386                         {
00387                                 pCurInstance= iEntry.value();
00388                                 if ((pCurInstance->viewableFlag() != GLC_3DViewInstance::NoViewable) && (pCurInstance->isVisible() == m_IsInShowSate))
00389                                 {
00390                                         if (pCurInstance->hasTransparentMaterials())
00391                                         {
00392                                                 pCurInstance->render(renderFlag, m_UseLod, m_pViewport);
00393                                         }
00394                                 }
00395 
00396                                 ++iEntry;
00397                         }
00398            }
00399 
00400         }
00401 }
00402 
00403 #endif //GLC_3DVIEWCOLLECTION_H_

SourceForge.net Logo

©2005-2011 Laurent Ribon