From 91e7337143d3c35b99b6a42b6e72c8960ca948db Mon Sep 17 00:00:00 2001 From: hzqst <113660872@qq.com> Date: Sun, 14 Jan 2024 10:37:08 +0800 Subject: [PATCH] Add more comments. --- Plugins/Renderer/gl_light.cpp | 17 +++++++++-------- Plugins/Renderer/gl_water.cpp | 26 ++++++++++++++++---------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/Plugins/Renderer/gl_light.cpp b/Plugins/Renderer/gl_light.cpp index cce1053d..74b96cdc 100644 --- a/Plugins/Renderer/gl_light.cpp +++ b/Plugins/Renderer/gl_light.cpp @@ -1104,29 +1104,29 @@ void R_EndRenderGBuffer(FBO_Container_t *dst) gbuffer_mask = -1; } -void R_BlitGBufferToFrameBuffer(FBO_Container_t *fbo, bool color, bool depth, bool stencil) +void R_BlitGBufferToFrameBuffer(FBO_Container_t *dst, bool color, bool depth, bool stencil) { if (depth && stencil) { - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo->s_hBackBufferFBO); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, dst->s_hBackBufferFBO); glBindFramebuffer(GL_READ_FRAMEBUFFER, s_GBufferFBO.s_hBackBufferFBO); - glBlitFramebuffer(0, 0, s_GBufferFBO.iWidth, s_GBufferFBO.iHeight, 0, 0, fbo->iWidth, fbo->iHeight, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, GL_NEAREST); + glBlitFramebuffer(0, 0, s_GBufferFBO.iWidth, s_GBufferFBO.iHeight, 0, 0, dst->iWidth, dst->iHeight, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, GL_NEAREST); } else if (depth && !stencil) { - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo->s_hBackBufferFBO); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, dst->s_hBackBufferFBO); glBindFramebuffer(GL_READ_FRAMEBUFFER, s_GBufferFBO.s_hBackBufferFBO); - glBlitFramebuffer(0, 0, s_GBufferFBO.iWidth, s_GBufferFBO.iHeight, 0, 0, fbo->iWidth, fbo->iHeight, GL_DEPTH_BUFFER_BIT, GL_NEAREST); + glBlitFramebuffer(0, 0, s_GBufferFBO.iWidth, s_GBufferFBO.iHeight, 0, 0, dst->iWidth, dst->iHeight, GL_DEPTH_BUFFER_BIT, GL_NEAREST); } else if (!depth && stencil) { - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo->s_hBackBufferFBO); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, dst->s_hBackBufferFBO); glBindFramebuffer(GL_READ_FRAMEBUFFER, s_GBufferFBO.s_hBackBufferFBO); - glBlitFramebuffer(0, 0, s_GBufferFBO.iWidth, s_GBufferFBO.iHeight, 0, 0, fbo->iWidth, fbo->iHeight, GL_STENCIL_BUFFER_BIT, GL_NEAREST); + glBlitFramebuffer(0, 0, s_GBufferFBO.iWidth, s_GBufferFBO.iHeight, 0, 0, dst->iWidth, dst->iHeight, GL_STENCIL_BUFFER_BIT, GL_NEAREST); } //Shading pass - GL_BindFrameBuffer(fbo); + GL_BindFrameBuffer(dst); glDrawBuffer(GL_COLOR_ATTACHMENT0); if (color) @@ -1167,6 +1167,7 @@ void R_BlitGBufferToFrameBuffer(FBO_Container_t *fbo, bool color, bool depth, bo glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D_ARRAY, 0); glEnable(GL_TEXTURE_2D); + (*currenttexture) = -1; GL_UseProgram(0); diff --git a/Plugins/Renderer/gl_water.cpp b/Plugins/Renderer/gl_water.cpp index 7a481135..21251142 100644 --- a/Plugins/Renderer/gl_water.cpp +++ b/Plugins/Renderer/gl_water.cpp @@ -976,14 +976,17 @@ void R_DrawWaterVBO(water_vbo_t *WaterVBO, water_reflect_cache_t *ReflectCache, { R_DrawWaterVBOEnd(); + //Purpose : Blit color and depth of s_GBuffers into ReflectCache->refractmap and ReflectCache->depthrefrmap + GL_BindFrameBufferWithTextures(&s_BackBufferFBO2, ReflectCache->refractmap, 0, ReflectCache->depthrefrmap, ReflectCache->texwidth, ReflectCache->texheight); //The output is in linear space R_BlitGBufferToFrameBuffer(&s_BackBufferFBO2, true, true, true); - //Restore BackBufferFBO2 + //Restore BackBufferFBO2 to it's original states. GL_BindFrameBufferWithTextures(&s_BackBufferFBO2, s_BackBufferFBO2.s_hBackBufferTex, 0, s_BackBufferFBO2.s_hBackBufferDepthTex, glwidth, glheight); - //Restore Previous FrameBuffer + + //Restore previous framebuffer GL_BindFrameBuffer(&s_GBufferFBO); R_DrawWaterVBOBegin(WaterVBO); @@ -992,25 +995,28 @@ void R_DrawWaterVBO(water_vbo_t *WaterVBO, water_reflect_cache_t *ReflectCache, { R_DrawWaterVBOEnd(); + //Purpose : Blit color and depth of SceneFBO into ReflectCache->refractmap and ReflectCache->depthrefrmap + GL_BindFrameBufferWithTextures(&s_BackBufferFBO2, ReflectCache->refractmap, 0, ReflectCache->depthrefrmap, ReflectCache->texwidth, ReflectCache->texheight); if (r_draw_gammablend) { - //s_BackBufferFBO is in gamma space - GL_BlitFrameBufferToFrameBufferDepthStencil(&s_BackBufferFBO, &s_BackBufferFBO2); + //The SceneFBO is in gamma space + GL_BlitFrameBufferToFrameBufferDepthStencil(GL_GetCurrentSceneFBO(), &s_BackBufferFBO2); //Convert back to linear space - R_GammaUncorrection(&s_BackBufferFBO, &s_BackBufferFBO2); + R_GammaUncorrection(GL_GetCurrentSceneFBO(), &s_BackBufferFBO2); } else { - //s_BackBufferFBO is in linear space - GL_BlitFrameBufferToFrameBufferColorDepthStencil(&s_BackBufferFBO, &s_BackBufferFBO2); + //The SceneFBO is in linear space + GL_BlitFrameBufferToFrameBufferColorDepthStencil(GL_GetCurrentSceneFBO(), &s_BackBufferFBO2); } - //Restore BackBufferFBO2 states + //Restore BackBufferFBO2 to it's original states. GL_BindFrameBufferWithTextures(&s_BackBufferFBO2, s_BackBufferFBO2.s_hBackBufferTex, 0, s_BackBufferFBO2.s_hBackBufferDepthTex, glwidth, glheight); - //Restore Previous FrameBuffer - GL_BindFrameBuffer(&s_BackBufferFBO); + + //Restore previous framebuffer + GL_BindFrameBuffer(GL_GetCurrentSceneFBO()); R_DrawWaterVBOBegin(WaterVBO); }