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

#include <ForwardRenderGroup.h>

Inheritance diagram for CSE::ForwardRenderGroup:
CSE::SRenderGroup

Public Member Functions

 ForwardRenderGroup (const RenderMgr &renderMgr)
 
 ~ForwardRenderGroup () override
 
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 used for forward-rendering objects. It contains a collection of objects which should be forward-rendered.

Definition at line 16 of file ForwardRenderGroup.h.

Constructor & Destructor Documentation

◆ ForwardRenderGroup()

ForwardRenderGroup::ForwardRenderGroup ( const RenderMgr renderMgr)
explicit

Constructor for the ForwardRenderGroup class.

Parameters
renderMgrThe render manager object.

Definition at line 14 of file ForwardRenderGroup.cpp.

14 : SRenderGroup(renderMgr) {
15 m_lightMgr = CORE->GetCore(LightMgr);
16}

◆ ~ForwardRenderGroup()

ForwardRenderGroup::~ForwardRenderGroup ( )
overridedefault

Destructor for the ForwardRenderGroup class.

Member Function Documentation

◆ Exterminate()

void ForwardRenderGroup::Exterminate ( )
overridevirtual

Clear all objects in the forward-rendering list.

Implements CSE::SRenderGroup.

Definition at line 98 of file ForwardRenderGroup.cpp.

98 {
99 m_rendersLayer.clear();
100}

◆ RegisterObject()

void ForwardRenderGroup::RegisterObject ( SIRender object)
overridevirtual

Register an object to be forward-rendered.

Parameters
objectThe object to be registered.

Implements CSE::SRenderGroup.

Definition at line 20 of file ForwardRenderGroup.cpp.

20 {
21 const auto& material = object->GetMaterialReference();
22 if (material == nullptr) return;
23
24 short orderLayer = material->GetOrderLayer();
25 const auto& shaders = material->GetShaders();
26 if (shaders == nullptr) return;
27
28 auto& layer = m_rendersLayer[orderLayer][shaders];
29 layer.push_back(object);
30}

◆ RemoveObjects()

void ForwardRenderGroup::RemoveObjects ( SIRender object)
overridevirtual

Remove an object from the forward-rendering list.

Parameters
objectThe object to be removed.

Implements CSE::SRenderGroup.

Definition at line 32 of file ForwardRenderGroup.cpp.

32 {
33 const auto& material = object->GetMaterialReference();
34 if (material == nullptr) return;
35
36 short orderLayer = material->GetOrderLayer();
37 const auto& shaders = material->GetShaders();
38 if (shaders == nullptr) return;
39
40 auto orderLayerIter = m_rendersLayer.find(orderLayer);
41 if (orderLayerIter != m_rendersLayer.end()) {
42 auto& programLayer = orderLayerIter->second;
43 auto handlerPair = programLayer.find(shaders);
44 if (handlerPair != programLayer.end()) {
45 auto& layerVector = handlerPair->second;
46 layerVector.erase(std::remove(layerVector.begin(), layerVector.end(), object),
47 layerVector.end());
48
49 // 렌더링 객체가 제거된 뒤에도 공간이 비어 있는 경우, 그 공간을 제거한다.
50 if (layerVector.empty()) programLayer.erase(handlerPair);
51 }
52 if (programLayer.empty()) m_rendersLayer.erase(orderLayerIter);
53 }
54}

◆ RenderAll()

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

Render the objects to be forward-rendered.

Parameters
cameraStructure containing information values of the camera to be drawn.

Implements CSE::SRenderGroup.

Definition at line 56 of file ForwardRenderGroup.cpp.

56 {
57 const auto cameraMatrix = camera.GetCameraMatrixStruct();
58 const auto& cameraBuffer = camera.GetFrameBuffer();
59 const auto& frameBuffer = cameraBuffer == nullptr
60 ? m_renderMgr->GetMainBuffer() : cameraBuffer;
61 OrderRenderLayer orderRenderLayer(m_rendersLayer.begin(), m_rendersLayer.end());
62 frameBuffer->AttachFrameBuffer();
63
64 for (const auto& orderLayerPair : orderRenderLayer) {
65 const auto& orderLayer = orderLayerPair.second;
66 ProgramRenderLayer programComp(orderLayer.begin(), orderLayer.end());
67
68 for (const auto& programPair : programComp) {
69 const auto& handler = *programPair.first->GetForwardHandle();
70 const auto& renderComp = programPair.second;
71
72 if (programPair.first == nullptr) continue;
73 if (renderComp.empty()) continue;
74
75 glUseProgram(handler.Program);
76 //Attach Light
77 m_lightMgr->AttachLightToShader(&handler);
78 const auto layoutBegin = m_lightMgr->GetShadowCount() + m_lightMgr->GetLightMapCount();
79
80 for (const auto& render : renderComp) {
81 if (render == nullptr) continue;
82 if (!render->isRenderActive) continue;
83
84 const auto& material = render->GetMaterial();
85 material->AttachElement();
86 render->SetMatrix(cameraMatrix, &handler);
87 BindSourceBuffer(*frameBuffer, handler, layoutBegin + material->GetTextureCount() + 1);
88 render->Render(&handler);
89 }
90 }
91 }
92
94 glBindBuffer(GL_ARRAY_BUFFER, 0);
95 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
96}
int GetShadowCount() const
Definition LightMgr.h:56
void AttachLightToShader(const GLProgramHandle *handle) const
Definition LightMgr.cpp:15
int GetLightMapCount() const
Definition LightMgr.h:64
static void BindSourceBuffer(const SFrameBuffer &buffer, const GLProgramHandle &handle, int layout)

References CSE::LightMgr::AttachLightToShader(), CSE::SRenderGroup::BindSourceBuffer(), CSE::LightMgr::GetLightMapCount(), and CSE::LightMgr::GetShadowCount().


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