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  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_RENDERPROPERTIES_H_
00026 #define GLC_RENDERPROPERTIES_H_
00027 
00028 #include "glc_material.h"
00029 #include "../glc_global.h"
00030 
00031 #include <QSet>
00032 #include <QHash>
00033 #include <QtOpenGL>
00034 
00035 #include "../glc_config.h"
00036 
00038 namespace glc
00039 {
00041         enum RenderMode
00042         {
00043                 NormalRenderMode,
00044                 OverwriteMaterial,
00045                 OverwriteTransparency,
00046                 OverwriteTransparencyAndMaterial,
00047                 PrimitiveSelected,
00048                 OverwritePrimitiveMaterial,
00049                 BodySelection,
00050                 PrimitiveSelection
00051         };
00052 
00054         enum RenderFlag
00055         {
00056                 ShadingFlag= 800,
00057                 WireRenderFlag,
00058                 TransparentRenderFlag
00059         };
00060 };
00063 
00065 
00066 class GLC_LIB_EXPORT GLC_RenderProperties
00067 {
00068 
00070 
00072 
00073 public:
00075         GLC_RenderProperties();
00076 
00078         GLC_RenderProperties(const GLC_RenderProperties&);
00079 
00081         GLC_RenderProperties &operator=(const GLC_RenderProperties&);
00082 
00084         virtual ~GLC_RenderProperties();
00086 
00087 
00089 
00090 public:
00092         inline bool isSelected() const
00093         {return m_IsSelected;}
00094 
00096         inline glc::RenderMode renderingMode() const
00097         {return m_RenderMode;}
00098 
00100         inline glc::RenderMode savedRenderingMode() const
00101         {return m_SavedRenderMode;}
00102 
00104         inline GLC_Material* overwriteMaterial() const
00105         {return m_pOverwriteMaterial;}
00106 
00108         inline float overwriteTransparency() const
00109         {return m_OverwriteOpacity;}
00110 
00112         inline QSet<GLC_uint>* setOfSelectedPrimitivesId() const
00113         {
00114                 Q_ASSERT(NULL != m_pBodySelectedPrimitvesId);
00115                 if (m_pBodySelectedPrimitvesId->contains(m_CurrentBody))
00116                         return m_pBodySelectedPrimitvesId->value(m_CurrentBody);
00117                 else return NULL;
00118         }
00119 
00121         inline bool setOfSelectedPrimitiveIdIsEmpty() const
00122         {return (!((NULL != m_pBodySelectedPrimitvesId) && m_pBodySelectedPrimitvesId->contains(m_CurrentBody)));}
00123 
00125         bool primitiveIsSelected(int index, GLC_uint id) const;
00126 
00128         inline QHash<GLC_uint, GLC_Material*>* hashOfOverwritePrimitiveMaterials() const
00129         {
00130                 Q_ASSERT(NULL != m_pOverwritePrimitiveMaterialMaps);
00131                 if (m_pOverwritePrimitiveMaterialMaps->contains(m_CurrentBody))
00132                         return m_pOverwritePrimitiveMaterialMaps->value(m_CurrentBody);
00133                 else return NULL;
00134         }
00135 
00137         inline bool hashOfOverwritePrimitiveMaterialsIsEmpty() const
00138         {return (!((NULL != m_pOverwritePrimitiveMaterialMaps) && m_pOverwritePrimitiveMaterialMaps->contains(m_CurrentBody)));}
00139 
00141 
00142         inline GLenum polyFaceMode() const
00143         {return m_PolyFace;}
00144 
00146 
00147         inline GLenum polygonMode() const
00148         {return m_PolyMode;}
00149 
00151         inline glc::RenderFlag renderingFlag() const
00152         {return m_RenderingFlag;}
00153 
00155         bool needToRenderWithTransparency() const;
00156 
00158         inline int currentBodyIndex() const
00159         {return m_CurrentBody;}
00160 
00162         bool isDefault() const;
00163 
00165 
00167 
00169 
00170 public:
00171 
00173         void clear();
00175 
00176 
00178 
00179 public:
00181         inline void select(bool primitive);
00182 
00184         inline void unselect(void);
00185 
00187         inline void setRenderingMode(glc::RenderMode mode)
00188         {m_RenderMode= mode;}
00189 
00191         void setOverwriteMaterial(GLC_Material*);
00192 
00194         inline void setOverwriteTransparency(float alpha)
00195         {m_OverwriteOpacity= alpha;}
00196 
00198         void addSetOfSelectedPrimitivesId(const QSet<GLC_uint>&, int body= 0);
00199 
00201         void addSelectedPrimitive(GLC_uint, int body= 0);
00202 
00204         void clearSelectedPrimitives();
00205 
00207         void addOverwritePrimitiveMaterial(GLC_uint, GLC_Material*, int bodyIndex= 0);
00208 
00210         void clearOverwritePrimitiveMaterials();
00211 
00213 
00215         inline void setPolygonMode(GLenum Face, GLenum Mode)
00216         {
00217                 m_PolyFace= Face;
00218                 m_PolyMode= Mode;
00219         }
00220 
00222         inline void setRenderingFlag(glc::RenderFlag flag)
00223         {m_RenderingFlag= flag;}
00224 
00226         inline void setCurrentBodyIndex(int index)
00227         {m_CurrentBody= index;}
00228 
00230         inline void useMaterial(GLC_Material*);
00231 
00233         inline void unUseMaterial(GLC_Material*);
00234 
00235 
00237 
00239 //Private attributes
00241 private:
00243         GLC_uint m_Uid;
00244 
00246         bool m_IsSelected;
00247 
00249         GLenum m_PolyFace;
00250         GLenum m_PolyMode;
00251 
00253         glc::RenderMode m_RenderMode;
00254 
00256         glc::RenderMode m_SavedRenderMode;
00257 
00259         GLC_Material* m_pOverwriteMaterial;
00260 
00262         float m_OverwriteOpacity;
00263 
00265         QHash<int, QSet<GLC_uint>* >* m_pBodySelectedPrimitvesId;
00266 
00268         QHash<int, QHash<GLC_uint, GLC_Material* >* >* m_pOverwritePrimitiveMaterialMaps;
00269 
00271         glc::RenderFlag m_RenderingFlag;
00272 
00274         int m_CurrentBody;
00275 
00277         QHash<GLC_Material*, int> m_MaterialsUsage;
00278 
00279 };
00280 
00281 // Select the instance
00282 void GLC_RenderProperties::select(bool primitive)
00283 {
00284         m_IsSelected= true;
00285         if (primitive && (m_RenderMode != glc::PrimitiveSelected))
00286         {
00287                 m_SavedRenderMode= m_RenderMode;
00288                 m_RenderMode= glc::PrimitiveSelected;
00289         }
00290 }
00291 
00292 // Unselect the instance
00293 void GLC_RenderProperties::unselect(void)
00294 {
00295         m_IsSelected= false;
00296         if (m_RenderMode == glc::PrimitiveSelected)
00297         {
00298                 m_RenderMode= m_SavedRenderMode;
00299         }
00300 }
00301 // Used the specified material
00302 void GLC_RenderProperties::useMaterial(GLC_Material* pMaterial)
00303 {
00304         if (m_MaterialsUsage.contains(pMaterial))
00305         {
00306                 QHash<GLC_Material*, int>::iterator iMat= m_MaterialsUsage.find(pMaterial);
00307                 iMat.value()= iMat.value() + 1;
00308         }
00309         else
00310         {
00311                 m_MaterialsUsage.insert(pMaterial, 1);
00312                 pMaterial->addUsage(m_Uid);
00313         }
00314 
00315 }
00316 
00317 // Unused the specified material
00318 void GLC_RenderProperties::unUseMaterial(GLC_Material* pMaterial)
00319 {
00320         Q_ASSERT(m_MaterialsUsage.contains(pMaterial));
00321         QHash<GLC_Material*, int>::iterator iMat= m_MaterialsUsage.find(pMaterial);
00322         iMat.value()= iMat.value() - 1;
00323         if (iMat.value() == 0)
00324         {
00325                 pMaterial->delUsage(m_Uid);
00326                 if (pMaterial->isUnused()) delete pMaterial;
00327                 m_MaterialsUsage.remove(pMaterial);
00328         }
00329 }
00330 
00331 #endif /* GLC_RENDERPROPERTIES_H_ */

SourceForge.net Logo

©2005-2011 Laurent Ribon