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

#include <DeferredRenderGroup.h>

Inheritance diagram for CSE::DeferredRenderGroup:
CSE::SRenderGroup

Public Member Functions

 DeferredRenderGroup (const RenderMgr &renderMgr)
 
void RegisterObject (SIRender *object) override
 
void RemoveObjects (SIRender *object) override
 
void RenderAll (const CameraBase &camera) const override
 
void RenderGbuffer (const CameraBase &camera, const SGBuffer &gbuffer, const SShaderGroup &shaders) const
 
void SetViewport ()
 
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 deferred rendering of G-Buffer objects.

Definition at line 15 of file DeferredRenderGroup.h.

Constructor & Destructor Documentation

◆ DeferredRenderGroup()

DeferredRenderGroup::DeferredRenderGroup ( const RenderMgr renderMgr)
explicit

Constructor for DeferredRenderGroup

Parameters
renderMgrReference to the RenderMgr object.

Definition at line 15 of file DeferredRenderGroup.cpp.

15 : SRenderGroup(renderMgr) {
16 m_width = renderMgr.GetWidth();
17 m_height = renderMgr.GetHeight();
18
19 m_lightMgr = CORE->GetCore(LightMgr);
20}
unsigned int * GetWidth() const
Get the width of the screen.
Definition RenderMgr.h:50
unsigned int * GetHeight() const
Get the height of the screen.
Definition RenderMgr.h:59

References CSE::RenderMgr::GetHeight(), and CSE::RenderMgr::GetWidth().

Member Function Documentation

◆ Exterminate()

void DeferredRenderGroup::Exterminate ( )
overridevirtual

Free all allocated resources.

Implements CSE::SRenderGroup.

Definition at line 136 of file DeferredRenderGroup.cpp.

136 {
137 for (auto gbuffer_pair : m_gbufferLayer) {
138 auto gbuffer = gbuffer_pair.second;
139 SAFE_DELETE(gbuffer);
140 }
141 m_gbufferLayer.clear();
142}

◆ RegisterObject()

void DeferredRenderGroup::RegisterObject ( SIRender object)
overridevirtual

Register an object to the render group.

Parameters
objectA pointer to the object to be registered.

Implements CSE::SRenderGroup.

Definition at line 24 of file DeferredRenderGroup.cpp.

24 {
25 const auto& material = object->GetMaterialReference();
26 const auto& shaders = material->GetShaders();
27 if (shaders == nullptr) return;
28 auto* handle = const_cast<GLProgramHandle*>(shaders->GetHandle("deferred"));
29
30 auto gbuffer = m_gbufferLayer[shaders];
31 if (!gbuffer) {
32 gbuffer = new SGBuffer();
33 gbuffer->GenerateGBuffer(*m_width, *m_height);
34 m_gbufferLayer[shaders] = gbuffer;
35 }
36 gbuffer->PushBackToLayer(object);
37 gbuffer->BindLightPass(handle);
38}

◆ RemoveObjects()

void DeferredRenderGroup::RemoveObjects ( SIRender object)
overridevirtual

Remove an object from the render group.

Parameters
objectA pointer to the object to be removed.

Implements CSE::SRenderGroup.

Definition at line 40 of file DeferredRenderGroup.cpp.

40 {
41 const auto& material = object->GetMaterialReference();
42 const auto& programLayer = m_gbufferLayer;
43 auto it = std::find_if(programLayer.begin(), programLayer.end(), [&material](const auto& elem) {
44 return elem.first == material->GetShaders();
45 });
46 if (it != programLayer.end()) {
47 it->second->RemoveToLayer(object);
48 }
49}

◆ RenderAll()

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

Deferred rendering for each G-Buffer object.

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

Implements CSE::SRenderGroup.

Definition at line 51 of file DeferredRenderGroup.cpp.

51 {
52 for (const auto& gbuffer_pair : m_gbufferLayer) {
53 const auto& shaders = gbuffer_pair.first;
54 const auto& gbuffer = gbuffer_pair.second;
55 RenderGbuffer(camera, *gbuffer, *shaders);
56 }
57}
void RenderGbuffer(const CameraBase &camera, const SGBuffer &gbuffer, const SShaderGroup &shaders) const

References RenderGbuffer().

◆ RenderGbuffer()

void DeferredRenderGroup::RenderGbuffer ( const CameraBase camera,
const SGBuffer gbuffer,
const SShaderGroup shaders 
) const

Deferred rendering for each G-Buffer object.

Parameters
cameraStructure containing information values of the camera to be drawn.
gbufferG-Buffer object to be drawn.

======================

  1. Geometry Pass

======================

  1. Light Pass

======================

  1. Blit the depth buffer

Definition at line 60 of file DeferredRenderGroup.cpp.

61 {
62 const auto cameraMatrix = camera.GetCameraMatrixStruct();
63 const auto& frameBuffer = camera.GetFrameBuffer();
64 const bool hasFrameBuffer = frameBuffer != nullptr;
65 const auto& lightPassHandle = gbuffer.GetLightPassHandle();
66
67 const int bufferWidth = hasFrameBuffer ? frameBuffer->GetWidth() : (int) *m_width;
68 const int bufferHeight = hasFrameBuffer ? frameBuffer->GetHeight() : (int) *m_height;
69
73 gbuffer.AttachGeometryFrameBuffer();
74 glViewport(0, 0, *m_width, *m_height);
75 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
76 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
77 const auto& renderLayer = gbuffer.GetRendersLayer();
78 const auto& handle = shaders.GetGeometryHandle();
79 glUseProgram(handle->Program);
80
81 for (const auto& render : renderLayer) {
82 if (render == nullptr) continue;
83 if (!render->isRenderActive) continue;
84
85 const auto& material = render->GetMaterial();
86 material->AttachElement();
87 render->SetMatrix(cameraMatrix, handle);
88 render->Render(handle);
89 }
90
94 const auto& deferredBuffer =
95 frameBuffer == nullptr ? m_renderMgr->GetMainBuffer() : frameBuffer;
96 deferredBuffer->AttachFrameBuffer();
97 gbuffer.AttachLightPass();
98 //Attach Light
99 m_lightMgr->AttachLightToShader(lightPassHandle);
100 m_lightMgr->AttachLightMapToShader(lightPassHandle, m_lightMgr->GetShadowCount());
101 const auto layoutBegin = m_lightMgr->GetShadowCount() + m_lightMgr->GetLightMapCount();
102 gbuffer.AttachLightPassTexture(layoutBegin);
103 BindSourceBuffer(*deferredBuffer, *lightPassHandle, layoutBegin + 3);
104
105 ShaderUtil::BindCameraToShader(*lightPassHandle, cameraMatrix.camera, cameraMatrix.cameraPosition,
106 cameraMatrix.projection, cameraMatrix.camera);
107
108 gbuffer.RenderLightPass();
109
113// if (frameBuffer == nullptr) {
114// m_renderMgr->GetMainBuffer()->BlitFrameBuffer(*deferredBuffer);
115// } else {
116// frameBuffer->BlitFrameBuffer(*deferredBuffer);
117// }
118// gbuffer.AttachGeometryFrameBuffer(GL_READ_FRAMEBUFFER);
119// if(frameBuffer == nullptr) {
120// GetMainBuffer()->AttachFrameBuffer(GL_DRAW_FRAMEBUFFER);
121// }
122// else {
123// frameBuffer->AttachFrameBuffer(GL_DRAW_FRAMEBUFFER);
124// }
125//
126// glBlitFramebuffer(0, 0, *m_width, *m_height, 0, 0, bufferWidth, bufferHeight, GL_DEPTH_BUFFER_BIT, GL_NEAREST);
127}
int GetShadowCount() const
Definition LightMgr.h:56
void AttachLightMapToShader(const GLProgramHandle *handle, int textureLayout) const
Definition LightMgr.cpp:47
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)
static void BindCameraToShader(const GLProgramHandle &handle, const mat4 &camera, const vec3 &cameraPosition, const mat4 &projection, const mat4 &transform)
Binds the camera data to the shader.

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

Referenced by RenderAll().

◆ SetViewport()

void DeferredRenderGroup::SetViewport ( )

Set the viewport size.

Definition at line 129 of file DeferredRenderGroup.cpp.

129 {
130 for (const auto& gbufferPair : m_gbufferLayer) {
131 const auto& gbuffer = gbufferPair.second;
132 gbuffer->ResizeGBuffer((int) *m_width, (int) *m_height);
133 }
134}

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