CSEngine
Loading...
Searching...
No Matches
CSE::DepthOnlyRenderGroup Class Reference

#include <DepthOnlyRenderGroup.h>

Inheritance diagram for CSE::DepthOnlyRenderGroup:
CSE::SRenderGroup

Public Member Functions

 DepthOnlyRenderGroup (const RenderMgr &renderMgr)
 
void RegisterObject (SIRender *object) override
 
void RemoveObjects (SIRender *object) override
 
void RenderAll (const CameraBase &camera) const override
 
void Exterminate () override
 
- Public Member Functions inherited from CSE::SRenderGroup
 SRenderGroup (const RenderMgr &renderMgr)
 

Additional Inherited Members

- Static Protected Member Functions inherited from CSE::SRenderGroup
static void BindSourceBuffer (const SFrameBuffer &buffer, const GLProgramHandle &handle, int layout)
 
- Protected Attributes inherited from CSE::SRenderGroup
const RenderMgrm_renderMgr
 

Detailed Description

This class is responsible for rendering depth only objects for use in creating shadow maps.

Definition at line 13 of file DepthOnlyRenderGroup.h.

Constructor & Destructor Documentation

◆ DepthOnlyRenderGroup()

DepthOnlyRenderGroup::DepthOnlyRenderGroup ( const RenderMgr renderMgr)
explicit

Constructor for the DepthOnlyRenderGroup.

Parameters
renderMgrThe render manager to use.

Definition at line 15 of file DepthOnlyRenderGroup.cpp.

15 : SRenderGroup(renderMgr) {
16}

Member Function Documentation

◆ Exterminate()

void DepthOnlyRenderGroup::Exterminate ( )
overridevirtual

Removes all objects from the render group.

Implements CSE::SRenderGroup.

Definition at line 71 of file DepthOnlyRenderGroup.cpp.

71 {
72 m_depthObjects.clear();
73}

◆ RegisterObject()

void DepthOnlyRenderGroup::RegisterObject ( SIRender object)
overridevirtual

Register an object to the render group.

Parameters
objectThe object to be registered.

Implements CSE::SRenderGroup.

Definition at line 18 of file DepthOnlyRenderGroup.cpp.

18 {
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}

◆ RemoveObjects()

void DepthOnlyRenderGroup::RemoveObjects ( SIRender object)
overridevirtual

Remove an object from the render group.

Parameters
objectThe object to be removed.

Implements CSE::SRenderGroup.

Definition at line 26 of file DepthOnlyRenderGroup.cpp.

26 {
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}

◆ RenderAll()

void DepthOnlyRenderGroup::RenderAll ( const CameraBase camera) const
overridevirtual

Rendering for a depth buffer to use for shadows. The render target depends on the shadow settings.

Parameters
cameraThe light(camera) you want to render.

Implements CSE::SRenderGroup.

Definition at line 44 of file DepthOnlyRenderGroup.cpp.

44 {
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}
static constexpr float SHADOW_DISTANCE
Distance of the shadow map.
Definition LightMgr.h:21

References CSE::LightMgr::SHADOW_DISTANCE.


The documentation for this class was generated from the following files: