CSEngine
Loading...
Searching...
No Matches
ForwardRenderGroup.cpp
1#include "ForwardRenderGroup.h"
2#include "../../Util/Render/CameraBase.h"
3#include "../../Util/Render/SMaterial.h"
4#include "../../Util/Render/SShaderGroup.h"
5#include "../../Util/Render/SFrameBuffer.h"
6#include "../../Component/CameraComponent.h"
7#include "RenderMgr.h"
8#include "../LightMgr.h"
9#include "../EngineCore.h"
10
11using namespace CSE;
12
13
15 m_lightMgr = CORE->GetCore(LightMgr);
16}
17
19
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}
31
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}
55
56void ForwardRenderGroup::RenderAll(const CameraBase& camera) const {
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}
97
99 m_rendersLayer.clear();
100}
void RenderAll(const CameraBase &camera) const override
~ForwardRenderGroup() override
void RegisterObject(SIRender *object) override
void RemoveObjects(SIRender *object) override
ForwardRenderGroup(const RenderMgr &renderMgr)
int GetShadowCount() const
Definition LightMgr.h:56
void AttachLightToShader(const GLProgramHandle *handle) const
Definition LightMgr.cpp:15
int GetLightMapCount() const
Definition LightMgr.h:64
Class for managing rendering operations.
Definition RenderMgr.h:21
static void BindSourceBuffer(const SFrameBuffer &buffer, const GLProgramHandle &handle, int layout)