From aafc423a7298b0fc595c0209480474dc50c277f0 Mon Sep 17 00:00:00 2001 From: LaG1924 Date: Sun, 21 Nov 2021 13:56:28 +0500 Subject: Added Gbuffer --- src/GalOgl.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/GalOgl.cpp') diff --git a/src/GalOgl.cpp b/src/GalOgl.cpp index 29e7fc0..c250539 100644 --- a/src/GalOgl.cpp +++ b/src/GalOgl.cpp @@ -137,6 +137,7 @@ public: if (activeTexture[textureUnit] != texture) { SetTextureUnit(textureUnit); glBindTexture(type, texture); + activeTexture[textureUnit] = texture; } glCheckError(); } @@ -690,6 +691,7 @@ struct FramebufferOgl : public Framebuffer { size_t vpX = 0, vpY = 0, vpW = 1, vpH = 1; std::shared_ptr depthStencil; std::vector> colors; + std::vector attachments; GlResource fbo; @@ -853,6 +855,8 @@ struct PipelineOgl : public Pipeline { oglState.UseProgram(program); oglState.BindFbo(target->fbo); oglState.SetViewport(target->vpX, target->vpY, target->vpW, target->vpH); + if (target->fbo) + glDrawBuffers(target->attachments.size(), target->attachments.data()); for (size_t i = 0; i < staticTextures.size(); i++) { oglState.BindTexture(staticTextures[i]->type, staticTextures[i]->texture, i); @@ -1226,6 +1230,7 @@ struct ImplOgl : public Impl { glUniform1i(location, usedTextureBlocks); pipeline->staticTextures.push_back(texture); + usedTextureBlocks++; } glCheckError(); @@ -1299,6 +1304,7 @@ struct ImplOgl : public Impl { for (auto&& [location, texture] : conf->colors) { glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + location, texture->type, texture->texture, 0); fb->colors.emplace_back(std::move(texture)); + fb->attachments.push_back(GL_COLOR_ATTACHMENT0 + location); } if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { @@ -1315,6 +1321,7 @@ struct ImplOgl : public Impl { if (!fbDefault) fbDefault = std::make_shared(); fbDefault->fbo = GlResource(0, GlResourceType::None); + fbDefault->attachments.push_back(GL_COLOR_ATTACHMENT0); return std::static_pointer_cast(fbDefault); } -- cgit v1.2.3