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                 PrimitiveSelected,
00047                 OverwritePrimitiveMaterial,
00048                 BodySelection,
00049                 PrimitiveSelection
00050         };
00051 
00053         enum RenderFlag
00054         {
00055                 ShadingFlag= 800,
00056                 WireRenderFlag,
00057                 TransparentRenderFlag
00058         };
00059 };
00062 
00064 
00065 class GLC_LIB_EXPORT GLC_RenderProperties
00066 {
00067 
00069 
00071 
00072 public:
00074         GLC_RenderProperties();
00075 
00077         GLC_RenderProperties(const GLC_RenderProperties&);
00078 
00080         GLC_RenderProperties &operator=(const GLC_RenderProperties&);
00081 
00083         virtual ~GLC_RenderProperties();
00085 
00086 
00088 
00089 public:
00091         inline bool isSelected() const
00092         {return m_IsSelected;}
00093 
00095         inline glc::RenderMode renderingMode() const
00096         {return m_RenderMode;}
00097 
00099         inline glc::RenderMode savedRenderingMode() const
00100         {return m_SavedRenderMode;}
00101 
00103         inline GLC_Material* overwriteMaterial() const
00104         {return m_pOverwriteMaterial;}
00105 
00107         inline float overwriteTransparency() const
00108         {return m_OverwriteOpacity;}
00109 
00111         inline QSet<GLC_uint>* setOfSelectedPrimitivesId() const
00112         {
00113                 Q_ASSERT(NULL != m_pBodySelectedPrimitvesId);
00114                 if (m_pBodySelectedPrimitvesId->contains(m_CurrentBody))
00115                         return m_pBodySelectedPrimitvesId->value(m_CurrentBody);
00116                 else return NULL;
00117         }
00118 
00120         inline bool setOfSelectedPrimitiveIdIsEmpty() const
00121         {return (!((NULL != m_pBodySelectedPrimitvesId) && m_pBodySelectedPrimitvesId->contains(m_CurrentBody)));}
00122 
00124         bool primitiveIsSelected(int index, GLC_uint id) const;
00125 
00127         inline QHash<GLC_uint, GLC_Material*>* hashOfOverwritePrimitiveMaterials() const
00128         {
00129                 Q_ASSERT(NULL != m_pOverwritePrimitiveMaterialMaps);
00130                 if (m_pOverwritePrimitiveMaterialMaps->contains(m_CurrentBody))
00131                         return m_pOverwritePrimitiveMaterialMaps->value(m_CurrentBody);
00132                 else return NULL;
00133         }
00134 
00136         inline bool hashOfOverwritePrimitiveMaterialsIsEmpty() const
00137         {return (!((NULL != m_pOverwritePrimitiveMaterialMaps) && m_pOverwritePrimitiveMaterialMaps->contains(m_CurrentBody)));}
00138 
00140 
00141         inline GLenum polyFaceMode() const
00142         {return m_PolyFace;}
00143 
00145 
00146         inline GLenum polygonMode() const
00147         {return m_PolyMode;}
00148 
00150         inline glc::RenderFlag renderingFlag() const
00151         {return m_RenderingFlag;}
00152 
00154         bool needToRenderWithTransparency() const;
00155 
00157         inline int currentBodyIndex() const
00158         {return m_CurrentBody;}
00159 
00161         bool isDefault() const;
00162 
00164 
00166 
00168 
00169 public:
00170 
00172         void clear();
00174 
00175 
00177 
00178 public:
00180         inline void select(bool primitive);
00181 
00183         inline void unselect(void);
00184 
00186         inline void setRenderingMode(glc::RenderMode mode)
00187         {m_RenderMode= mode;}
00188 
00190         void setOverwriteMaterial(GLC_Material*);
00191 
00193         inline void setOverwriteTransparency(float alpha)
00194         {m_OverwriteOpacity= alpha;}
00195 
00197         void addSetOfSelectedPrimitivesId(const QSet<GLC_uint>&, int body= 0);
00198 
00200         void addSelectedPrimitive(GLC_uint, int body= 0);
00201 
00203         void clearSelectedPrimitives();
00204 
00206         void addOverwritePrimitiveMaterial(GLC_uint, GLC_Material*, int bodyIndex= 0);
00207 
00209         void clearOverwritePrimitiveMaterials();
00210 
00212 
00214         inline void setPolygonMode(GLenum Face, GLenum Mode)
00215         {
00216                 m_PolyFace= Face;
00217                 m_PolyMode= Mode;
00218         }
00219 
00221         inline void setRenderingFlag(glc::RenderFlag flag)
00222         {m_RenderingFlag= flag;}
00223 
00225         inline void setCurrentBodyIndex(int index)
00226         {m_CurrentBody= index;}
00227 
00229         inline void useMaterial(GLC_Material*);
00230 
00232         inline void unUseMaterial(GLC_Material*);
00233 
00234 
00236 
00238 //Private attributes
00240 private:
00242         GLC_uint m_Uid;
00243 
00245         bool m_IsSelected;
00246 
00248         GLenum m_PolyFace;
00249         GLenum m_PolyMode;
00250 
00252         glc::RenderMode m_RenderMode;
00253 
00255         glc::RenderMode m_SavedRenderMode;
00256 
00258         GLC_Material* m_pOverwriteMaterial;
00259 
00261         float m_OverwriteOpacity;
00262 
00264         QHash<int, QSet<GLC_uint>* >* m_pBodySelectedPrimitvesId;
00265 
00267         QHash<int, QHash<GLC_uint, GLC_Material* >* >* m_pOverwritePrimitiveMaterialMaps;
00268 
00270         glc::RenderFlag m_RenderingFlag;
00271 
00273         int m_CurrentBody;
00274 
00276         QHash<GLC_Material*, int> m_MaterialsUsage;
00277 
00278 };
00279 
00280 // Select the instance
00281 void GLC_RenderProperties::select(bool primitive)
00282 {
00283         m_IsSelected= true;
00284         if (primitive && (m_RenderMode != glc::PrimitiveSelected))
00285         {
00286                 m_SavedRenderMode= m_RenderMode;
00287                 m_RenderMode= glc::PrimitiveSelected;
00288         }
00289 }
00290 
00291 // Unselect the instance
00292 void GLC_RenderProperties::unselect(void)
00293 {
00294         m_IsSelected= false;
00295         if (m_RenderMode == glc::PrimitiveSelected)
00296         {
00297                 m_RenderMode= m_SavedRenderMode;
00298         }
00299 }
00300 // Used the specified material
00301 void GLC_RenderProperties::useMaterial(GLC_Material* pMaterial)
00302 {
00303         if (m_MaterialsUsage.contains(pMaterial))
00304         {
00305                 QHash<GLC_Material*, int>::iterator iMat= m_MaterialsUsage.find(pMaterial);
00306                 iMat.value()= iMat.value() + 1;
00307         }
00308         else
00309         {
00310                 m_MaterialsUsage.insert(pMaterial, 1);
00311                 pMaterial->addUsage(m_Uid);
00312         }
00313 
00314 }
00315 
00316 // Unused the specified material
00317 void GLC_RenderProperties::unUseMaterial(GLC_Material* pMaterial)
00318 {
00319         Q_ASSERT(m_MaterialsUsage.contains(pMaterial));
00320         QHash<GLC_Material*, int>::iterator iMat= m_MaterialsUsage.find(pMaterial);
00321         iMat.value()= iMat.value() - 1;
00322         if (iMat.value() == 0)
00323         {
00324                 pMaterial->delUsage(m_Uid);
00325                 if (pMaterial->isUnused()) delete pMaterial;
00326                 m_MaterialsUsage.remove(pMaterial);
00327         }
00328 }
00329 
00330 #endif /* GLC_RENDERPROPERTIES_H_ */

SourceForge.net Logo

©2005-2011 Laurent Ribon