CSEngine
Loading...
Searching...
No Matches
DepthOnlyRenderGroup.cpp
1#include "DepthOnlyRenderGroup.h"
2#include "../../Util/Render/CameraBase.h"
3#include "../../Util/Render/SFrameBuffer.h"
4#include "../../Util/Render/ShaderUtil.h"
5#include "../../Util/Render/SMaterial.h"
6#include "../../Component/CameraComponent.h"
7#include "../../Component/RenderComponent.h"
8#include "RenderMgr.h"
9#include "../LightMgr.h"
10#include "../../Util/GLProgramHandle.h"
11#include "../../Util/AssetsDef.h"
12
13using namespace CSE;
14
17
19 const auto& material = object->GetMaterialReference();
20 if (material == nullptr) return;
21
22 auto& depthGroup = m_depthObjects[material->GetShaders()];
23 depthGroup.push_back(object);
24}
25
27 const auto& material = object->GetMaterialReference();
28 if (material == nullptr) return;
29
30 const auto& shaders = material->GetShaders();
31 if (shaders == nullptr) return;
32
33 auto handlerPair = m_depthObjects.find(shaders);
34 if (handlerPair != m_depthObjects.end()) {
35 auto& layerVector = handlerPair->second;
36 layerVector.erase(std::remove(layerVector.begin(), layerVector.end(), object),
37 layerVector.end());
38
39 // 렌더링 객체가 제거된 뒤에도 공간이 비어 있는 경우, 그 공간을 제거한다.
40 if (layerVector.empty()) m_depthObjects.erase(handlerPair);
41 }
42}
43
45 const auto cameraMatrix = camera.GetCameraMatrixStruct();
46 const auto& frameBuffer = camera.GetFrameBuffer();
47 if (frameBuffer == nullptr) {
48 m_renderMgr->GetMainBuffer()->AttachFrameBuffer();
49 } else {
50 frameBuffer->AttachFrameBuffer();
51 }
52
53 glClear(GL_DEPTH_BUFFER_BIT);
54 for (const auto& shadowObject : m_depthObjects) {
55 const auto& handle = shadowObject.first->GetDepthOnlyHandle();
56 glUseProgram(handle->Program);
57 for(const auto& render : shadowObject.second) {
58 if (!render->isRenderActive) continue;
59 const auto& shadowTransform = static_cast<RenderComponent*>(render)->GetGameObject()->GetTransform();
60
61 if (LightMgr::SHADOW_DISTANCE < vec3::Distance(cameraMatrix.cameraPosition, shadowTransform->m_position))
62 continue;
63
64 render->SetMatrix(cameraMatrix, handle);
65 render->Render(handle);
66 }
67 }
68 glBindFramebuffer(GL_FRAMEBUFFER, 0);
69}
70
72 m_depthObjects.clear();
73}
void RegisterObject(SIRender *object) override
DepthOnlyRenderGroup(const RenderMgr &renderMgr)
void RemoveObjects(SIRender *object) override
void RenderAll(const CameraBase &camera) const override
static constexpr float SHADOW_DISTANCE
Distance of the shadow map.
Definition LightMgr.h:21
Class for managing rendering operations.
Definition RenderMgr.h:21