glc_3dviewcollection.cpp

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 
00026 #include "glc_3dviewcollection.h"
00027 #include "../shading/glc_material.h"
00028 #include "../glc_openglexception.h"
00029 #include "../shading/glc_selectionmaterial.h"
00030 #include "../glc_state.h"
00031 #include "../shading/glc_shader.h"
00032 #include "../viewport/glc_viewport.h"
00033 #include "glc_spacepartitioning.h"
00034 
00035 #include <QtDebug>
00036 
00038 // Constructor/Destructor
00040 
00041 GLC_3DViewCollection::GLC_3DViewCollection()
00042 : m_3DViewInstanceHash()
00043 , m_SelectedInstances()
00044 , m_ShadedPointerViewInstanceHash()
00045 , m_ShaderGroup()
00046 , m_MainInstances()
00047 , m_IsInShowSate(true)
00048 , m_UseLod(false)
00049 , m_pViewport(NULL)
00050 , m_pSpacePartitioning(NULL)
00051 , m_UseSpacePartitioning(false)
00052 , m_IsViewable(true)
00053 {
00054 }
00055 
00056 GLC_3DViewCollection::~GLC_3DViewCollection()
00057 {
00058         // Delete all collection's elements and the collection bounding box
00059         clear();
00060 }
00062 // Set Functions
00064 
00065 bool GLC_3DViewCollection::bindShader(GLC_uint shaderId)
00066 {
00067         if (m_ShadedPointerViewInstanceHash.contains(shaderId))
00068         {
00069                 return false;
00070         }
00071         else
00072         {
00073                 PointerViewInstanceHash* pNodeHash= new PointerViewInstanceHash;
00074                 m_ShadedPointerViewInstanceHash.insert(shaderId, pNodeHash);
00075                 return true;
00076         }
00077 }
00078 
00079 bool GLC_3DViewCollection::unBindShader(GLC_uint shaderId)
00080 {
00081         bool result= false;
00082         if (m_ShadedPointerViewInstanceHash.contains(shaderId))
00083         {
00084                 // Find node which use the shader
00085                 QList<GLC_uint> nodeId(m_ShaderGroup.keys(shaderId));
00086 
00087                 // Move these node in the standard hash and remove them from shader group
00088                 PointerViewInstanceHash* pShaderNodeHash= m_ShadedPointerViewInstanceHash.take(shaderId);
00089                 for (int i= 0; i < nodeId.size(); ++i)
00090                 {
00091                         const GLC_uint id= nodeId[i];
00092                         GLC_3DViewInstance* pInstance= pShaderNodeHash->value(id);
00093 
00094                         if (!pInstance->isSelected())
00095                         {
00096                                 m_MainInstances.insert(id, pInstance);
00097                         }
00098                         else
00099                         {
00100                                 m_SelectedInstances.insert(id, pInstance);
00101                         }
00102                         m_ShaderGroup.remove(id);
00103                 }
00104                 pShaderNodeHash->clear();
00105                 delete pShaderNodeHash;
00106                 result= true;
00107         }
00108         Q_ASSERT(!m_ShadedPointerViewInstanceHash.contains(shaderId));
00109         return result;
00110 }
00111 
00112 bool GLC_3DViewCollection::unBindAllShader()
00113 {
00114         bool result= true;
00115         HashList::iterator iEntry= m_ShadedPointerViewInstanceHash.begin();
00116         QList<GLuint> shaderList;
00117     while (iEntry != m_ShadedPointerViewInstanceHash.constEnd())
00118     {
00119         shaderList.append(iEntry.key());
00120         ++iEntry;
00121     }
00122     const int size= shaderList.size();
00123     for (int i=0; i < size; ++i)
00124     {
00125         result= result && unBindShader(shaderList[i]);
00126     }
00127     return result;
00128 }
00129 
00130 bool GLC_3DViewCollection::add(const GLC_3DViewInstance& node, GLC_uint shaderID)
00131 {
00132         bool result= false;
00133         const GLC_uint key= node.id();
00134         if (m_3DViewInstanceHash.contains(key))
00135         {
00136                 return false;
00137         }
00138 
00139         m_3DViewInstanceHash.insert(key, node);
00140         // Create an GLC_3DViewInstance pointer of the inserted instance
00141         ViewInstancesHash::iterator iNode= m_3DViewInstanceHash.find(key);
00142         GLC_3DViewInstance* pInstance= &(iNode.value());
00143         // Chose the hash where instance is
00144         if(0 != shaderID)
00145         {
00146                 // Test if shaderId group exist
00147                 if (m_ShadedPointerViewInstanceHash.contains(shaderID))
00148                 {
00149                         m_ShaderGroup.insert(key, shaderID);
00150 
00151                         if(pInstance->isSelected())
00152                         {
00153                                 m_SelectedInstances.insert(key, pInstance);
00154                         }
00155                         else
00156                         {
00157                                 m_ShadedPointerViewInstanceHash.value(shaderID)->insert(key, pInstance);
00158                         }
00159                         result=true;
00160                 }
00161         }
00162         else if (!pInstance->isSelected())
00163         {
00164                 m_MainInstances.insert(key, pInstance);
00165                 result=true;
00166         }
00167         else
00168         {
00169                 m_SelectedInstances.insert(key, pInstance);
00170                 result=true;
00171         }
00172 
00173         return result;
00174 }
00175 
00176 void GLC_3DViewCollection::changeShadingGroup(GLC_uint instanceId, GLC_uint shaderId)
00177 {
00178         // Test if the specified instance exist
00179         Q_ASSERT(m_3DViewInstanceHash.contains(instanceId));
00180         // Get the instance shading group
00181         const GLuint instanceShadingGroup= shadingGroup(instanceId);
00182         // Get a pointer to the instance
00183         GLC_3DViewInstance* pInstance= NULL;
00184         if (0 == instanceShadingGroup)
00185         {
00186                 // The instance is not in a shading group
00187                 if (m_MainInstances.contains(instanceId))
00188                 {
00189                         pInstance= m_MainInstances.take(instanceId);
00190                 }
00191                 else if (m_SelectedInstances.contains(instanceId))
00192                 {
00193                         // The instance is selected don't take it
00194                         pInstance= m_SelectedInstances.value(instanceId);
00195                 }
00196                 else
00197                 {
00198                         Q_ASSERT(false);
00199                 }
00200         }
00201         else
00202         {
00203                 m_ShaderGroup.remove(instanceId);
00204                 // The instance is in a shading group
00205                 if (m_SelectedInstances.contains(instanceId))
00206                 {
00207                         // The instance is selected don't take it
00208                         pInstance= m_SelectedInstances.value(instanceId);
00209                 }
00210                 else
00211                 {
00212                         pInstance= m_ShadedPointerViewInstanceHash.value(instanceShadingGroup)->take(instanceId);
00213                 }
00214 
00215         }
00216         // Put the instance in specified shading group
00217         if (0 != shaderId)
00218         {
00219                 m_ShaderGroup.insert(instanceId, shaderId);
00220                 if (!pInstance->isSelected())
00221                 {
00222                         m_ShadedPointerViewInstanceHash.value(shaderId)->insert(instanceId, pInstance);
00223                 }
00224         }
00225         else if (!pInstance->isSelected())
00226         {
00227                 m_MainInstances.insert(instanceId, pInstance);
00228         }
00229 }
00230 
00231 bool GLC_3DViewCollection::remove(GLC_uint Key)
00232 {
00233         ViewInstancesHash::iterator iNode= m_3DViewInstanceHash.find(Key);
00234 
00235         if (iNode != m_3DViewInstanceHash.end())
00236         {       // Ok, the key exist
00237 
00238                 if (selectionSize() > 0)
00239                 {
00240                         // if the geometry is selected, unselect it
00241                         unselect(Key);
00242                 }
00243 
00244                 m_MainInstances.remove(Key);
00245 
00246                 m_3DViewInstanceHash.remove(Key);               // Delete the conteneur
00247 
00248                 //qDebug("GLC_3DViewCollection::removeNode : Element succesfuly deleted");
00249                 return true;
00250 
00251         }
00252         else
00253         {       // KO, key doesn't exist
00254                 return false;
00255         }
00256 
00257 }
00258 
00259 void GLC_3DViewCollection::clear(void)
00260 {
00261         // Clear Selected node Hash Table
00262         m_SelectedInstances.clear();
00263         // Clear the not transparent Hash Table
00264         m_MainInstances.clear();
00265         // Clear Other Node Hash List
00266         HashList::iterator iEntry= m_ShadedPointerViewInstanceHash.begin();
00267     while (iEntry != m_ShadedPointerViewInstanceHash.constEnd())
00268     {
00269         iEntry.value()->clear();
00270         delete iEntry.value();
00271         iEntry= m_ShadedPointerViewInstanceHash.erase(iEntry);
00272     }
00273 
00274         m_ShadedPointerViewInstanceHash.clear();
00275         m_ShaderGroup.clear();
00276 
00277         // Clear main Hash table
00278     m_3DViewInstanceHash.clear();
00279 
00280         // delete the space partitioning
00281         delete m_pSpacePartitioning;
00282 }
00283 
00284 bool GLC_3DViewCollection::select(GLC_uint key, bool primitive)
00285 {
00286         if (!m_3DViewInstanceHash.contains(key)) return false;
00287         //qDebug() << "GLC_Collection::select " << key;
00288 
00289         GLC_3DViewInstance* pSelectedInstance;
00290         ViewInstancesHash::iterator iNode= m_3DViewInstanceHash.find(key);
00291         PointerViewInstanceHash::iterator iSelectedNode= m_SelectedInstances.find(key);
00292 
00293         if ((iNode != m_3DViewInstanceHash.end()) && (iSelectedNode == m_SelectedInstances.end()))
00294         {       // Ok, the key exist and the node is not selected
00295                 pSelectedInstance= &(iNode.value());
00296                 m_SelectedInstances.insert(pSelectedInstance->id(), pSelectedInstance);
00297 
00298                 // Remove Selected Node from is previous collection
00299                 if (isInAShadingGroup(key))
00300                 {
00301                         m_ShadedPointerViewInstanceHash.value(shadingGroup(key))->remove(key);
00302                         //qDebug() << "remove from shader list";
00303                 }
00304                 else
00305                 {
00306                         m_MainInstances.remove(key);
00307                 }
00308                 pSelectedInstance->select(primitive);
00309 
00310                 //qDebug("GLC_3DViewCollection::selectNode : Element succesfuly selected");
00311                 return true;
00312         }
00313         else
00314         {       // KO, instance allready selected
00315                 return false;
00316         }
00317 }
00318 
00319 void GLC_3DViewCollection::selectAll(bool allShowState)
00320 {
00321         unselectAll();
00322         ViewInstancesHash::iterator iNode= m_3DViewInstanceHash.begin();
00323         while (iNode != m_3DViewInstanceHash.end())
00324         {
00325                 GLC_3DViewInstance *pCurrentInstance= &(iNode.value());
00326                 const GLC_uint instanceId= pCurrentInstance->id();
00327 
00328                 if (allShowState || (pCurrentInstance->isVisible() == m_IsInShowSate))
00329                 {
00330                         pCurrentInstance->select(false);
00331                         m_SelectedInstances.insert(instanceId, pCurrentInstance);
00332                         m_MainInstances.remove(instanceId);
00333                         if(isInAShadingGroup(instanceId))
00334                         {
00335                                 m_ShadedPointerViewInstanceHash.value(shadingGroup(instanceId))->remove(instanceId);
00336                         }
00337                 }
00338                 iNode++;
00339         }
00340 }
00341 
00342 bool GLC_3DViewCollection::unselect(GLC_uint key)
00343 {
00344         GLC_3DViewInstance* pSelectedNode;
00345 
00346         PointerViewInstanceHash::iterator iSelectedNode= m_SelectedInstances.find(key);
00347 
00348         if (iSelectedNode != m_SelectedInstances.end())
00349         {       // Ok, the key exist and the node is selected
00350                 iSelectedNode.value()->unselect();
00351 
00352                 pSelectedNode= iSelectedNode.value();
00353                 m_SelectedInstances.remove(key);
00354 
00355                 // Insert Selected Node to the right collection
00356                 if (isInAShadingGroup(key))
00357                 {
00358                         m_ShadedPointerViewInstanceHash.value(shadingGroup(key))->insert(key, pSelectedNode);
00359                 }
00360                 else
00361                 {
00362                         m_MainInstances.insert(key, pSelectedNode);
00363                 }
00364 
00365                 //qDebug("GLC_3DViewCollection::unselectNode : Node succesfuly unselected");
00366                 return true;
00367 
00368         }
00369         else
00370         {       // KO, key doesn't exist or node allready selected
00371                 //qDebug("GLC_3DViewCollection::unselectNode : Node not unselected");
00372                 return false;
00373         }
00374 }
00375 
00376 void GLC_3DViewCollection::unselectAll()
00377 {
00378         PointerViewInstanceHash::iterator iSelectedNode= m_SelectedInstances.begin();
00379 
00380     while (iSelectedNode != m_SelectedInstances.end())
00381     {
00382         GLC_3DViewInstance* pInstance= iSelectedNode.value();
00383         pInstance->unselect();
00384                 if (isInAShadingGroup(pInstance->id()))
00385                 {
00386                         m_ShadedPointerViewInstanceHash.value(shadingGroup(pInstance->id()))->insert(pInstance->id(), pInstance);
00387                 }
00388                 else
00389                 {
00390                         m_MainInstances.insert(pInstance->id(), pInstance);
00391                 }
00392 
00393         ++iSelectedNode;
00394     }
00395     // Clear selected node hash table
00396     m_SelectedInstances.clear();
00397 }
00398 
00399 void GLC_3DViewCollection::setPolygonModeForAll(GLenum face, GLenum mode)
00400 {
00401         ViewInstancesHash::iterator iEntry= m_3DViewInstanceHash.begin();
00402 
00403     while (iEntry != m_3DViewInstanceHash.constEnd())
00404     {
00405         // Update Instance Polygon Mode
00406         iEntry.value().setPolygonMode(face, mode);
00407         iEntry++;
00408     }
00409 
00410 }
00411 
00412 void GLC_3DViewCollection::setVisibility(const GLC_uint key, const bool visibility)
00413 {
00414         ViewInstancesHash::iterator iNode= m_3DViewInstanceHash.find(key);
00415         if (iNode != m_3DViewInstanceHash.end())
00416         {       // Ok, the key exist
00417                 iNode.value().setVisibility(visibility);
00418         }
00419 }
00420 
00421 void GLC_3DViewCollection::showAll()
00422 {
00423         ViewInstancesHash::iterator iEntry= m_3DViewInstanceHash.begin();
00424 
00425     while (iEntry != m_3DViewInstanceHash.constEnd())
00426     {
00427         // Update Instance Polygon Mode
00428         iEntry.value().setVisibility(true);
00429         iEntry++;
00430     }
00431 }
00432 
00433 void GLC_3DViewCollection::hideAll()
00434 {
00435         ViewInstancesHash::iterator iEntry= m_3DViewInstanceHash.begin();
00436 
00437     while (iEntry != m_3DViewInstanceHash.constEnd())
00438     {
00439         // Update Instance Polygon Mode
00440         iEntry.value().setVisibility(false);
00441         iEntry++;
00442     }
00443 
00444 }
00445 
00446 void GLC_3DViewCollection::bindSpacePartitioning(GLC_SpacePartitioning* pSpacePartitioning)
00447 {
00448         Q_ASSERT(NULL != pSpacePartitioning);
00449         Q_ASSERT(pSpacePartitioning->collectionHandle() == this);
00450 
00451         delete m_pSpacePartitioning;
00452         m_pSpacePartitioning= pSpacePartitioning;
00453 }
00454 
00455 void GLC_3DViewCollection::unbindSpacePartitioning()
00456 {
00457         delete m_pSpacePartitioning;
00458         m_pSpacePartitioning= NULL;
00459         m_UseSpacePartitioning= false;
00460 
00461         ViewInstancesHash::iterator iEntry= m_3DViewInstanceHash.begin();
00462     while (iEntry != m_3DViewInstanceHash.constEnd())
00463     {
00464         // Update Instance viewable flag
00465         iEntry.value().setViewable(GLC_3DViewInstance::FullViewable);
00466         iEntry++;
00467     }
00468 
00469 }
00470 
00471 void GLC_3DViewCollection::updateInstanceViewableState(GLC_Matrix4x4* pMatrix)
00472 {
00473         if ((NULL != m_pViewport) && m_UseSpacePartitioning && (NULL != m_pSpacePartitioning))
00474         {
00475                 if (m_pViewport->updateFrustum(pMatrix))
00476                         m_pSpacePartitioning->updateViewableInstances(m_pViewport->frustum());
00477         }
00478 }
00479 
00480 void GLC_3DViewCollection::updateInstanceViewableState(const GLC_Frustum& frustum)
00481 {
00482         m_pSpacePartitioning->updateViewableInstances(frustum);
00483 }
00484 
00485 void GLC_3DViewCollection::setVboUsage(bool usage)
00486 {
00487         ViewInstancesHash::iterator iEntry= m_3DViewInstanceHash.begin();
00488 
00489     while (iEntry != m_3DViewInstanceHash.constEnd())
00490     {
00491         iEntry.value().setVboUsage(usage);
00492         iEntry++;
00493     }
00494 }
00495 
00496 QList<GLC_3DViewInstance*> GLC_3DViewCollection::instancesHandle()
00497 {
00498         QList<GLC_3DViewInstance*> instancesList;
00499 
00500         ViewInstancesHash::iterator iEntry= m_3DViewInstanceHash.begin();
00501 
00502     while (iEntry != m_3DViewInstanceHash.constEnd())
00503     {
00504         instancesList.append(&(iEntry.value()));
00505         iEntry++;
00506     }
00507         return instancesList;
00508 }
00509 
00510 QList<GLC_3DViewInstance*> GLC_3DViewCollection::visibleInstancesHandle()
00511 {
00512         QList<GLC_3DViewInstance*> instancesList;
00513 
00514         ViewInstancesHash::iterator iEntry= m_3DViewInstanceHash.begin();
00515 
00516     while (iEntry != m_3DViewInstanceHash.constEnd())
00517     {
00518         if (iEntry.value().isVisible())
00519         {
00520                 instancesList.append(&(iEntry.value()));
00521         }
00522         iEntry++;
00523     }
00524         return instancesList;
00525 
00526 }
00527 
00528 QList<GLC_3DViewInstance*> GLC_3DViewCollection::viewableInstancesHandle()
00529 {
00530         QList<GLC_3DViewInstance*> instancesList;
00531 
00532         ViewInstancesHash::iterator iEntry= m_3DViewInstanceHash.begin();
00533 
00534     while (iEntry != m_3DViewInstanceHash.constEnd())
00535     {
00536         if (iEntry.value().isVisible() == m_IsInShowSate)
00537         {
00538                 instancesList.append(&(iEntry.value()));
00539         }
00540         iEntry++;
00541     }
00542         return instancesList;
00543 }
00544 
00545 GLC_3DViewInstance* GLC_3DViewCollection::instanceHandle(GLC_uint Key)
00546 {
00547         Q_ASSERT(m_3DViewInstanceHash.contains(Key));
00548         return &(m_3DViewInstanceHash[Key]);
00549 }
00550 
00551 GLC_BoundingBox GLC_3DViewCollection::boundingBox(bool allObject)
00552 {
00553         GLC_BoundingBox boundingBox;
00554         // Check if the bounding box have to be updated
00555         if (!m_3DViewInstanceHash.isEmpty())
00556         {
00557                 ViewInstancesHash::iterator iEntry= m_3DViewInstanceHash.begin();
00558             while (iEntry != m_3DViewInstanceHash.constEnd())
00559             {
00560                 if(allObject || iEntry.value().isVisible() == m_IsInShowSate)
00561                 {
00562                         // Combine Collection BoundingBox with element Bounding Box
00563                         boundingBox.combine(iEntry.value().boundingBox());
00564                 }
00565                 ++iEntry;
00566             }
00567         }
00568         return boundingBox;
00569 }
00570 
00571 int GLC_3DViewCollection::drawableObjectsSize() const
00572 {
00573         // The number of object to drw
00574         int numberOffDrawnHit= 0;
00575 
00576         // Count the number off instance to draw
00577         ViewInstancesHash::const_iterator i= m_3DViewInstanceHash.begin();
00578         while (i != m_3DViewInstanceHash.constEnd())
00579         {
00580                 //qDebug() << "transparent";
00581                 if (i.value().isVisible() == m_IsInShowSate)
00582                 {
00583                         ++numberOffDrawnHit;
00584                 }
00585                 ++i;
00586         }
00587         return numberOffDrawnHit;
00588 }
00589 
00590 QList<QString> GLC_3DViewCollection::instanceNamesFromShadingGroup(GLuint shaderId) const
00591 {
00592         QList<QString> listOfInstanceName;
00593         QList<GLC_uint> listOfInstanceNameId= m_ShaderGroup.keys(shaderId);
00594         if (!listOfInstanceNameId.isEmpty())
00595         {
00596                 const int size= listOfInstanceNameId.size();
00597                 for (int i= 0; i < size; ++i)
00598                 {
00599                         listOfInstanceName << m_3DViewInstanceHash.value(listOfInstanceNameId[i]).name();
00600                 }
00601         }
00602         return listOfInstanceName;
00603 }
00604 
00605 int GLC_3DViewCollection::numberOfUsedShadingGroup() const
00606 {
00607         return m_ShaderGroup.values().toSet().size();
00608 }
00609 
00611 // OpenGL Functions
00613 
00614 void GLC_3DViewCollection::render(GLuint groupId, glc::RenderFlag renderFlag)
00615 {
00616         if (!isEmpty() && m_IsViewable)
00617         {
00618                 if (renderFlag == glc::WireRenderFlag)
00619                 {
00620                 glEnable(GL_POLYGON_OFFSET_FILL);
00621                 glPolygonOffset (1.0, 1.0);
00622                 }
00623                 if (GLC_State::isInSelectionMode())
00624                 {
00625                         glDisable(GL_BLEND);
00626                         GLC_Context::current()->glcEnableLighting(false);
00627                         glDisable(GL_TEXTURE_2D);
00628                 }
00629                 else
00630                 {
00631                         GLC_Context::current()->glcEnableLighting(true);
00632                 }
00633                 glDraw(groupId, renderFlag);
00634 
00635                 if (renderFlag == glc::WireRenderFlag)
00636                 {
00637                 glDisable(GL_POLYGON_OFFSET_FILL);
00638                 }
00639         }
00640 }
00641 void GLC_3DViewCollection::renderShaderGroup(glc::RenderFlag renderFlag)
00642 {
00643         if (!isEmpty() && m_IsViewable)
00644         {
00645                 if (GLC_State::isInSelectionMode())
00646                 {
00647                         glDisable(GL_BLEND);
00648                         GLC_Context::current()->glcEnableLighting(false);
00649                         glDisable(GL_TEXTURE_2D);
00650                 }
00651 
00652                 HashList::iterator iEntry= m_ShadedPointerViewInstanceHash.begin();
00653             while (iEntry != m_ShadedPointerViewInstanceHash.constEnd())
00654             {
00655                 glDraw(iEntry.key(), renderFlag);
00656                 ++iEntry;
00657             }
00658         }
00659 }
00660 
00661 void GLC_3DViewCollection::glDraw(GLC_uint groupId, glc::RenderFlag renderFlag)
00662 {
00663         // Set render Mode and OpenGL state
00664         if (!GLC_State::isInSelectionMode() && (groupId == 0))
00665         {
00666                 if (renderFlag == glc::TransparentRenderFlag)
00667                 {
00668                 glEnable(GL_BLEND);
00669                 glDepthMask(GL_FALSE);
00670                 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00671 
00672                 }
00673                 else
00674                 {
00675                     glDisable(GL_BLEND);
00676                     glDepthMask(GL_TRUE);
00677                     glEnable(GL_DEPTH_TEST);
00678                 }
00679         }
00680 
00681         // Normal GLC_3DViewInstance
00682         if ((groupId == 0) && !m_MainInstances.isEmpty())
00683         {
00684                 glDrawInstancesOf(&m_MainInstances, renderFlag);
00685 
00686         }
00687         // Selected GLC_3DVIewInstance
00688         else if ((groupId == 1) && !m_SelectedInstances.isEmpty())
00689         {
00690                 if (GLC_State::selectionShaderUsed()) GLC_SelectionMaterial::useShader();
00691 
00692                 glDrawInstancesOf(&m_SelectedInstances, renderFlag);
00693 
00694                 if (GLC_State::selectionShaderUsed()) GLC_SelectionMaterial::unUseShader();
00695         }
00696         // GLC_3DViewInstance with shader
00697         else if (!m_ShadedPointerViewInstanceHash.isEmpty())
00698         {
00699             if(m_ShadedPointerViewInstanceHash.contains(groupId) && !m_ShadedPointerViewInstanceHash.value(groupId)->isEmpty())
00700             {
00701                 PointerViewInstanceHash* pNodeHash= m_ShadedPointerViewInstanceHash.value(groupId);
00702 
00703                 GLC_Shader::use(groupId);
00704                 glDrawInstancesOf(pNodeHash, renderFlag);
00705                 GLC_Shader::unuse();
00706             }
00707         }
00708 
00709         // Restore OpenGL state
00710         if (renderFlag && !GLC_State::isInSelectionMode() && (groupId == 0))
00711         {
00712                 glDisable(GL_BLEND);
00713                 glDepthMask(GL_TRUE);
00714                 glEnable(GL_DEPTH_TEST);
00715         }
00716 }

SourceForge.net Logo

©2005-2011 Laurent Ribon