diff --git a/src/gl/renderer/gl_postprocess.cpp b/src/gl/renderer/gl_postprocess.cpp index 142358af68..463895e8ca 100644 --- a/src/gl/renderer/gl_postprocess.cpp +++ b/src/gl/renderer/gl_postprocess.cpp @@ -161,12 +161,13 @@ void FGLRenderer::RenderScreenQuad() GLRenderer->mVBO->RenderArray(GL_TRIANGLE_STRIP, FFlatVertexBuffer::PRESENT_INDEX, 4); } -void FGLRenderer::PostProcessScene(int fixedcm) +void FGLRenderer::PostProcessScene(int fixedcm, const std::function &afterBloomDrawEndScene2D) { mBuffers->BlitSceneToTexture(); UpdateCameraExposure(); mCustomPostProcessShaders->Run("beforebloom"); BloomScene(fixedcm); + afterBloomDrawEndScene2D(); TonemapScene(); ColormapScene(fixedcm); LensDistortScene(); diff --git a/src/gl/renderer/gl_renderer.h b/src/gl/renderer/gl_renderer.h index 8b6ba46df5..eb71cd4bed 100644 --- a/src/gl/renderer/gl_renderer.h +++ b/src/gl/renderer/gl_renderer.h @@ -7,6 +7,7 @@ #include "r_renderer.h" #include "r_data/matrix.h" #include "gl/dynlights/gl_shadowmap.h" +#include struct particle_t; class FCanvasTexture; @@ -43,6 +44,7 @@ class F2DDrawer; class FHardwareTexture; class FShadowMapShader; class FCustomPostProcessShaders; +class GLSceneDrawer; inline float DEG2RAD(float deg) { @@ -174,7 +176,7 @@ public: void RenderView(player_t* player); void RenderScreenQuad(); - void PostProcessScene(int fixedcm); + void PostProcessScene(int fixedcm, const std::function &afterBloomDrawEndScene2D); void AmbientOccludeScene(); void UpdateCameraExposure(); void BloomScene(int fixedcm); diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index bbead77371..1ce74404ca 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -681,10 +681,29 @@ void GLSceneDrawer::EndDrawScene(sector_t * viewsector) Reset3DViewport(); - // [BB] Only draw the sprites if we didn't render a HUD model before. - if ( renderHUDModel == false ) + // Delay drawing psprites until after bloom has been applied, if enabled. + if (!FGLRenderBuffers::IsEnabled() || !gl_bloom) { - DrawPlayerSprites (viewsector, false); + DrawEndScene2D(viewsector); + } + else + { + // Restore standard rendering state + gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + gl_RenderState.ResetColor(); + gl_RenderState.EnableTexture(true); + glDisable(GL_SCISSOR_TEST); + } +} + +void GLSceneDrawer::DrawEndScene2D(sector_t * viewsector) +{ + const bool renderHUDModel = gl_IsHUDModelForPlayerAvailable(players[consoleplayer].camera->player); + + // [BB] Only draw the sprites if we didn't render a HUD model before. + if (renderHUDModel == false) + { + DrawPlayerSprites(viewsector, false); } if (gl.legacyMode) { @@ -706,7 +725,6 @@ void GLSceneDrawer::EndDrawScene(sector_t * viewsector) glDisable(GL_SCISSOR_TEST); } - //----------------------------------------------------------------------------- // // R_RenderView - renders one view - either the screen or a camera texture @@ -846,7 +864,7 @@ sector_t * GLSceneDrawer::RenderViewpoint (AActor * camera, GL_IRECT * bounds, f if (mainview && toscreen) EndDrawScene(lviewsector); // do not call this for camera textures. if (mainview && FGLRenderBuffers::IsEnabled()) { - GLRenderer->PostProcessScene(FixedColormap); + GLRenderer->PostProcessScene(FixedColormap, [&]() { if (gl_bloom) DrawEndScene2D(lviewsector); }); // This should be done after postprocessing, not before. GLRenderer->mBuffers->BindCurrentFB(); diff --git a/src/gl/scene/gl_scenedrawer.h b/src/gl/scene/gl_scenedrawer.h index 9209e6dad9..9ade64b739 100644 --- a/src/gl/scene/gl_scenedrawer.h +++ b/src/gl/scene/gl_scenedrawer.h @@ -55,6 +55,7 @@ public: void ProcessScene(bool toscreen = false); void DrawBlend(sector_t * viewsector); void EndDrawScene(sector_t * viewsector); + void DrawEndScene2D(sector_t * viewsector); void RenderActorsInPortal(FGLLinePortal *glport); void CheckViewArea(vertex_t *v1, vertex_t *v2, sector_t *frontsector, sector_t *backsector);