glc_renderproperties.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_RENDERPROPERTIES_H_
00028 #define GLC_RENDERPROPERTIES_H_
00029 
00030 #include "glc_material.h"
00031 #include "../glc_global.h"
00032 
00033 #include <QSet>
00034 #include <QHash>
00035 #include <QtOpenGL>
00036 
00037 #include "../glc_config.h"
00038 
00040 namespace glc
00041 {
00043         enum RenderMode
00044         {
00045                 NormalRenderMode,
00046                 OverwriteMaterial,
00047                 OverwriteTransparency,
00048                 PrimitiveSelected,
00049                 OverwritePrimitiveMaterial,
00050                 BodySelection,
00051                 PrimitiveSelection
00052         };
00053 
00055         enum RenderFlag
00056         {
00057                 ShadingFlag= 800,
00058                 WireRenderFlag,
00059                 TransparentRenderFlag
00060         };
00061 };
00064 
00066 
00067 class GLC_LIB_EXPORT GLC_RenderProperties
00068 {
00069 
00071 
00073 
00074 public:
00076         GLC_RenderProperties();
00077 
00079         GLC_RenderProperties(const GLC_RenderProperties&);
00080 
00082         GLC_RenderProperties &operator=(const GLC_RenderProperties&);
00083 
00085         virtual ~GLC_RenderProperties();
00087 
00088 
00090 
00091 public:
00093         inline bool isSelected() const
00094         {return m_IsSelected;}
00095 
00097         inline glc::RenderMode renderingMode() const
00098         {return m_RenderMode;}
00099 
00101         inline glc::RenderMode savedRenderingMode() const
00102         {return m_SavedRenderMode;}
00103 
00105         inline GLC_Material* overwriteMaterial() const
00106         {return m_pOverwriteMaterial;}
00107 
00109         inline float overwriteTransparency() const
00110         {return m_OverwriteTransparency;}
00111 
00113         inline QSet<GLC_uint>* setOfSelectedPrimitivesId() const
00114         {
00115                 Q_ASSERT(NULL != m_pBodySelectedPrimitvesId);
00116                 if (m_pBodySelectedPrimitvesId->contains(m_CurrentBody))
00117                         return m_pBodySelectedPrimitvesId->value(m_CurrentBody);
00118                 else return NULL;
00119         }
00120 
00122         inline bool setOfSelectedPrimitiveIdIsEmpty() const
00123         {return (!((NULL != m_pBodySelectedPrimitvesId) && m_pBodySelectedPrimitvesId->contains(m_CurrentBody)));}
00124 
00126         bool primitiveIsSelected(int index, GLC_uint id) const;
00127 
00129         inline QHash<GLC_uint, GLC_Material*>* hashOfOverwritePrimitiveMaterials() const
00130         {
00131                 Q_ASSERT(NULL != m_pOverwritePrimitiveMaterialMaps);
00132                 if (m_pOverwritePrimitiveMaterialMaps->contains(m_CurrentBody))
00133                         return m_pOverwritePrimitiveMaterialMaps->value(m_CurrentBody);
00134                 else return NULL;
00135         }
00136 
00138         inline bool hashOfOverwritePrimitiveMaterialsIsEmpty() const
00139         {return (!((NULL != m_pOverwritePrimitiveMaterialMaps) && m_pOverwritePrimitiveMaterialMaps->contains(m_CurrentBody)));}
00140 
00142 
00143         inline GLenum polyFaceMode() const
00144         {return m_PolyFace;}
00145 
00147 
00148         inline GLenum polygonMode() const
00149         {return m_PolyMode;}
00150 
00152         inline glc::RenderFlag renderingFlag() const
00153         {return m_RenderingFlag;}
00154 
00156         bool needToRenderWithTransparency() const;
00157 
00159         inline int currentBodyIndex() const
00160         {return m_CurrentBody;}
00161 
00163         bool isDefault() const;
00164 
00166 
00168 
00170 
00171 public:
00172 
00174         void clear();
00176 
00177 
00179 
00180 public:
00182         inline void select(bool primitive);
00183 
00185         inline void unselect(void);
00186 
00188         inline void setRenderingMode(glc::RenderMode mode)
00189         {m_RenderMode= mode;}
00190 
00192         void setOverwriteMaterial(GLC_Material*);
00193 
00195         inline void setOverwriteTransparency(float alpha)
00196         {m_OverwriteTransparency= alpha;}
00197 
00199         void addSetOfSelectedPrimitivesId(const QSet<GLC_uint>&, int body= 0);
00200 
00202         void addSelectedPrimitive(GLC_uint, int body= 0);
00203 
00205         void clearSelectedPrimitives();
00206 
00208         void addOverwritePrimitiveMaterial(GLC_uint, GLC_Material*, int bodyIndex= 0);
00209 
00211         void clearOverwritePrimitiveMaterials();
00212 
00214 
00216         inline void setPolygonMode(GLenum Face, GLenum Mode)
00217         {
00218                 m_PolyFace= Face;
00219                 m_PolyMode= Mode;
00220         }
00221 
00223         inline void setRenderingFlag(glc::RenderFlag flag)
00224         {m_RenderingFlag= flag;}
00225 
00227         inline void setCurrentBodyIndex(int index)
00228         {m_CurrentBody= index;}
00229 
00231         inline void useMaterial(GLC_Material*);
00232 
00234         inline void unUseMaterial(GLC_Material*);
00235 
00236 
00238 
00240 //Private attributes
00242 private:
00244         GLC_uint m_Uid;
00245 
00247         bool m_IsSelected;
00248 
00250         GLenum m_PolyFace;
00251         GLenum m_PolyMode;
00252 
00254         glc::RenderMode m_RenderMode;
00255 
00257         glc::RenderMode m_SavedRenderMode;
00258 
00260         GLC_Material* m_pOverwriteMaterial;
00261 
00263         float m_OverwriteTransparency;
00264 
00266         QHash<int, QSet<GLC_uint>* >* m_pBodySelectedPrimitvesId;
00267 
00269         QHash<int, QHash<GLC_uint, GLC_Material* >* >* m_pOverwritePrimitiveMaterialMaps;
00270 
00272         glc::RenderFlag m_RenderingFlag;
00273 
00275         int m_CurrentBody;
00276 
00278         QHash<GLC_Material*, int> m_MaterialsUsage;
00279 
00280 };
00281 
00282 // Select the instance
00283 void GLC_RenderProperties::select(bool primitive)
00284 {
00285         m_IsSelected= true;
00286         if (primitive && (m_RenderMode != glc::PrimitiveSelected))
00287         {
00288                 m_SavedRenderMode= m_RenderMode;
00289                 m_RenderMode= glc::PrimitiveSelected;
00290         }
00291 }
00292 
00293 // Unselect the instance
00294 void GLC_RenderProperties::unselect(void)
00295 {
00296         m_IsSelected= false;
00297         if (m_RenderMode == glc::PrimitiveSelected)
00298         {
00299                 m_RenderMode= m_SavedRenderMode;
00300         }
00301 }
00302 // Used the specified material
00303 void GLC_RenderProperties::useMaterial(GLC_Material* pMaterial)
00304 {
00305         if (m_MaterialsUsage.contains(pMaterial))
00306         {
00307                 QHash<GLC_Material*, int>::iterator iMat= m_MaterialsUsage.find(pMaterial);
00308                 iMat.value()= iMat.value() + 1;
00309         }
00310         else
00311         {
00312                 m_MaterialsUsage.insert(pMaterial, 1);
00313                 pMaterial->addUsage(m_Uid);
00314         }
00315 
00316 }
00317 
00318 // Unused the specified material
00319 void GLC_RenderProperties::unUseMaterial(GLC_Material* pMaterial)
00320 {
00321         Q_ASSERT(m_MaterialsUsage.contains(pMaterial));
00322         QHash<GLC_Material*, int>::iterator iMat= m_MaterialsUsage.find(pMaterial);
00323         iMat.value()= iMat.value() - 1;
00324         if (iMat.value() == 0)
00325         {
00326                 pMaterial->delUsage(m_Uid);
00327                 if (pMaterial->isUnused()) delete pMaterial;
00328                 m_MaterialsUsage.remove(pMaterial);
00329         }
00330 }
00331 
00332 #endif /* GLC_RENDERPROPERTIES_H_ */

SourceForge.net Logo

©2005 Laurent Ribon