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"));
30 auto gbuffer = m_gbufferLayer[shaders];
33 gbuffer->GenerateGBuffer(*m_width, *m_height);
34 m_gbufferLayer[shaders] = gbuffer;
36 gbuffer->PushBackToLayer(
object);
37 gbuffer->BindLightPass(handle);
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();
46 if (it != programLayer.end()) {
47 it->second->RemoveToLayer(
object);
62 const auto cameraMatrix = camera.GetCameraMatrixStruct();
63 const auto& frameBuffer = camera.GetFrameBuffer();
64 const bool hasFrameBuffer = frameBuffer !=
nullptr;
65 const auto& lightPassHandle = gbuffer.GetLightPassHandle();
67 const int bufferWidth = hasFrameBuffer ? frameBuffer->GetWidth() : (int) *m_width;
68 const int bufferHeight = hasFrameBuffer ? frameBuffer->GetHeight() : (int) *m_height;
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);
81 for (
const auto& render : renderLayer) {
82 if (render ==
nullptr)
continue;
83 if (!render->isRenderActive)
continue;
85 const auto& material = render->GetMaterial();
86 material->AttachElement();
87 render->SetMatrix(cameraMatrix, handle);
88 render->Render(handle);
94 const auto& deferredBuffer =
95 frameBuffer ==
nullptr ? m_renderMgr->GetMainBuffer() : frameBuffer;
96 deferredBuffer->AttachFrameBuffer();
97 gbuffer.AttachLightPass();
102 gbuffer.AttachLightPassTexture(layoutBegin);
106 cameraMatrix.projection, cameraMatrix.camera);
108 gbuffer.RenderLightPass();
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.