BVB Source Codes

CRYENGINE Show ClipVolumeManager.cpp Source code

Return Download CRYENGINE: download ClipVolumeManager.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #include "StdAfx.h"
  4.  
  5. #include "ClipVolume.h"
  6. #include "ClipVolumeManager.h"
  7. #include "LightEntity.h"
  8. #include "FogVolumeRenderNode.h"
  9.  
  10. CClipVolumeManager::~CClipVolumeManager()
  11. {
  12.         assert(m_ClipVolumes.empty());
  13. }
  14.  
  15. IClipVolume* CClipVolumeManager::CreateClipVolume()
  16. {
  17.         SClipVolumeInfo volumeInfo(new CClipVolume());
  18.         m_ClipVolumes.push_back(volumeInfo);
  19.  
  20.         return m_ClipVolumes.back().m_pVolume;
  21. }
  22.  
  23. bool CClipVolumeManager::DeleteClipVolume(IClipVolume* pClipVolume)
  24. {
  25.         if (m_ClipVolumes.Delete(static_cast<CClipVolume*>(pClipVolume)))
  26.         {
  27.                 delete pClipVolume;
  28.                 return true;
  29.         }
  30.         return false;
  31. }
  32.  
  33. bool CClipVolumeManager::UpdateClipVolume(IClipVolume* pClipVolume, _smart_ptr<IRenderMesh> pRenderMesh, IBSPTree3D* pBspTree, const Matrix34& worldTM, bool bActive, uint32 flags, const char* szName)
  34. {
  35.         int nVolumeIndex = m_ClipVolumes.Find((CClipVolume*)pClipVolume);
  36.         if (nVolumeIndex >= 0)
  37.         {
  38.                 SClipVolumeInfo& volumeInfo = m_ClipVolumes[nVolumeIndex];
  39.                 volumeInfo.m_pVolume->Update(pRenderMesh, pBspTree, worldTM, flags);
  40.                 volumeInfo.m_pVolume->SetName(szName);
  41.                 volumeInfo.m_bActive = bActive;
  42.  
  43.                 AABB volumeBBox = pClipVolume->GetClipVolumeBBox();
  44.                 Get3DEngine()->m_pObjManager->ReregisterEntitiesInArea(volumeBBox.min, volumeBBox.max);
  45.                 return true;
  46.         }
  47.  
  48.         return false;
  49. }
  50.  
  51. void CClipVolumeManager::PrepareVolumesForRendering(const SRenderingPassInfo& passInfo)
  52. {
  53.         for (size_t i = 0; i < m_ClipVolumes.size(); ++i)
  54.         {
  55.                 SClipVolumeInfo& volInfo = m_ClipVolumes[i];
  56.                 volInfo.m_pVolume->SetStencilRef(InactiveVolumeStencilRef);
  57.  
  58.                 if (volInfo.m_bActive && passInfo.GetCamera().IsAABBVisible_F(volInfo.m_pVolume->GetClipVolumeBBox()))
  59.                 {
  60.                         uint8 nStencilRef = passInfo.GetIRenderView()->AddClipVolume(volInfo.m_pVolume);
  61.                         volInfo.m_pVolume->SetStencilRef(nStencilRef);
  62.                 }
  63.         }
  64. }
  65.  
  66. void CClipVolumeManager::UpdateEntityClipVolume(const Vec3& pos, IRenderNode* pRenderNode)
  67. {
  68.         FRAME_PROFILER("CClipVolumeManager::UpdateEntityClipVolume", GetSystem(), PROFILE_3DENGINE);
  69.  
  70.         if (!pRenderNode || !pRenderNode->m_pTempData)
  71.                 return;
  72.  
  73.         IClipVolume* pPreviousVolume = pRenderNode->m_pTempData->userData.m_pClipVolume;
  74.         UnregisterRenderNode(pRenderNode);
  75.  
  76.         // user assigned clip volume
  77.         CLightEntity* pLight = static_cast<CLightEntity*>(pRenderNode);
  78.         if (pRenderNode->GetRenderNodeType() == eERType_Light && (pLight->m_light.m_Flags & DLF_HAS_CLIP_VOLUME) != 0)
  79.         {
  80.                 for (int i = 1; i >= 0; --i)
  81.                 {
  82.                         if (CClipVolume* pVolume = static_cast<CClipVolume*>(pLight->m_light.m_pClipVolumes[i]))
  83.                                 pVolume->RegisterRenderNode(pRenderNode);
  84.                 }
  85.         }
  86.         else // assign by position
  87.         {
  88.                 // Check if entity is in same clip volume as before
  89.                 if (pPreviousVolume && (pPreviousVolume->GetClipVolumeFlags() & IClipVolume::eClipVolumeIsVisArea) == 0)
  90.                 {
  91.                         CClipVolume* pVolume = static_cast<CClipVolume*>(pPreviousVolume);
  92.                         if (pVolume->IsPointInsideClipVolume(pos))
  93.                         {
  94.                                 pVolume->RegisterRenderNode(pRenderNode);
  95.                                 return;
  96.                         }
  97.                 }
  98.  
  99.                 if (CClipVolume* pVolume = GetClipVolumeByPos(pos, pPreviousVolume))
  100.                         pVolume->RegisterRenderNode(pRenderNode);
  101.         }
  102. }
  103.  
  104. void CClipVolumeManager::UnregisterRenderNode(IRenderNode* pRenderNode)
  105. {
  106.         if (!pRenderNode)
  107.                 return;
  108.  
  109.         for (size_t i = 0; i < m_ClipVolumes.size(); ++i)
  110.                 m_ClipVolumes[i].m_pVolume->UnregisterRenderNode(pRenderNode);
  111.  
  112.         if (pRenderNode->m_pTempData)
  113.                 pRenderNode->m_pTempData->userData.m_pClipVolume = NULL;
  114. }
  115.  
  116. bool CClipVolumeManager::IsClipVolumeRequired(IRenderNode* pRenderNode) const
  117. {
  118.         const uint32 NoClipVolumeLights = DLF_SUN | DLF_ATTACH_TO_SUN;
  119.  
  120.         const bool bForwardObject = (pRenderNode->m_nInternalFlags & IRenderNode::REQUIRES_FORWARD_RENDERING) != 0;
  121.         const EERType ertype = pRenderNode->GetRenderNodeType();
  122.         const bool bIsValidLight = ertype == eERType_Light &&
  123.                                    (static_cast<CLightEntity*>(pRenderNode)->m_light.m_Flags & NoClipVolumeLights) == 0;
  124.         const bool bIsValidFogVolume = (ertype == eERType_FogVolume) &&
  125.                                        static_cast<CFogVolumeRenderNode*>(pRenderNode)->IsAffectsThisAreaOnly();
  126.  
  127.         return bIsValidLight || bForwardObject || bIsValidFogVolume;
  128. }
  129.  
  130. CClipVolume* CClipVolumeManager::GetClipVolumeByPos(const Vec3& pos, const IClipVolume* pIgnoreVolume) const
  131. {
  132.         for (size_t i = 0; i < m_ClipVolumes.size(); ++i)
  133.         {
  134.                 const SClipVolumeInfo& volInfo = m_ClipVolumes[i];
  135.  
  136.                 if (volInfo.m_bActive && volInfo.m_pVolume != pIgnoreVolume && volInfo.m_pVolume->IsPointInsideClipVolume(pos))
  137.                         return m_ClipVolumes[i].m_pVolume;
  138.         }
  139.  
  140.         return NULL;
  141. }
  142.  
  143. void CClipVolumeManager::GetMemoryUsage(class ICrySizer* pSizer) const
  144. {
  145.         pSizer->AddObject(this, sizeof(this));
  146.         for (size_t i = 0; i < m_ClipVolumes.size(); ++i)
  147.                 pSizer->AddObject(m_ClipVolumes[i].m_pVolume);
  148. }
  149.  
downloadClipVolumeManager.cpp Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top