Skip to content

Commit

Permalink
Add more comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
hzqst committed Jan 14, 2024
1 parent 54327ca commit 91e7337
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
17 changes: 9 additions & 8 deletions Plugins/Renderer/gl_light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
26 changes: 16 additions & 10 deletions Plugins/Renderer/gl_water.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down

0 comments on commit 91e7337

Please sign in to comment.