From 9ff7e5a4efefdecea5ef51ca80afb387676e18fd Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 16 Jun 2018 09:37:01 +0200 Subject: [PATCH] - force render buffers to be active. For modern hardware the fallback path really makes no sense and this allows to simplify some things quite a bit. --- src/gl/renderer/gl_postprocess.cpp | 34 +++++++++++----------------- src/gl/renderer/gl_renderbuffers.cpp | 23 +++---------------- src/gl/renderer/gl_renderbuffers.h | 1 - src/gl/renderer/gl_renderstate.cpp | 2 +- src/gl/scene/gl_scene.cpp | 12 +++------- src/gl/shaders/gl_shader.cpp | 7 +----- src/gl/system/gl_framebuffer.cpp | 21 ++++------------- src/gl/system/gl_framebuffer.h | 1 - src/gl/system/gl_wipe.cpp | 27 +++++----------------- src/hwrenderer/utility/hw_cvars.h | 1 - src/v_video.cpp | 11 +-------- src/v_video.h | 1 - 12 files changed, 32 insertions(+), 109 deletions(-) diff --git a/src/gl/renderer/gl_postprocess.cpp b/src/gl/renderer/gl_postprocess.cpp index 637581b717..be08075994 100644 --- a/src/gl/renderer/gl_postprocess.cpp +++ b/src/gl/renderer/gl_postprocess.cpp @@ -394,7 +394,7 @@ void FGLRenderer::BlurScene(float gameinfobluramount) blurAmount = gameinfobluramount; // if blurAmount == 0 or somehow still returns negative, exit to prevent a crash, clearly we don't want this - if ((blurAmount <= 0.0) || !FGLRenderBuffers::IsEnabled()) + if (blurAmount <= 0.0) return; FGLDebug::PushGroup("BlurScene"); @@ -662,7 +662,7 @@ void FGLRenderer::Flush() const auto &mSceneViewport = screen->mSceneViewport; const auto &mScreenViewport = screen->mScreenViewport; - if (stereo3dMode.IsMono() || !FGLRenderBuffers::IsEnabled()) + if (stereo3dMode.IsMono()) { CopyToBackbuffer(nullptr, true); } @@ -701,30 +701,22 @@ void FGLRenderer::CopyToBackbuffer(const IntRect *bounds, bool applyGamma) mCustomPostProcessShaders->Run("screen"); FGLDebug::PushGroup("CopyToBackbuffer"); - if (FGLRenderBuffers::IsEnabled()) + FGLPostProcessState savedState; + mBuffers->BindOutputFB(); + + IntRect box; + if (bounds) { - FGLPostProcessState savedState; - mBuffers->BindOutputFB(); - - IntRect box; - if (bounds) - { - box = *bounds; - } - else - { - ClearBorders(); - box = screen->mOutputLetterbox; - } - - mBuffers->BindCurrentTexture(0); - DrawPresentTexture(box, applyGamma); + box = *bounds; } - else if (!bounds) + else { - FGLPostProcessState savedState; ClearBorders(); + box = screen->mOutputLetterbox; } + + mBuffers->BindCurrentTexture(0); + DrawPresentTexture(box, applyGamma); FGLDebug::PopGroup(); } diff --git a/src/gl/renderer/gl_renderbuffers.cpp b/src/gl/renderer/gl_renderbuffers.cpp index 4300bc22a8..65ca0248da 100644 --- a/src/gl/renderer/gl_renderbuffers.cpp +++ b/src/gl/renderer/gl_renderbuffers.cpp @@ -35,7 +35,6 @@ #include CVAR(Int, gl_multisample, 1, CVAR_ARCHIVE|CVAR_GLOBALCONFIG); -CVAR(Bool, gl_renderbuffers, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL) //========================================================================== // @@ -173,17 +172,6 @@ void FGLRenderBuffers::DeleteFrameBuffer(PPFrameBuffer &fb) bool FGLRenderBuffers::Setup(int width, int height, int sceneWidth, int sceneHeight) { - if (gl_renderbuffers != BuffersActive) - { - if (BuffersActive) - glBindFramebuffer(GL_FRAMEBUFFER, 0); - BuffersActive = gl_renderbuffers; - GLRenderer->mShaderManager->ResetFixedColormap(); - } - - if (!IsEnabled()) - return false; - if (width <= 0 || height <= 0) I_FatalError("Requested invalid render buffer sizes: screen = %dx%d", width, height); @@ -234,9 +222,10 @@ bool FGLRenderBuffers::Setup(int width, int height, int sceneWidth, int sceneHei mSamples = 0; mSceneWidth = 0; mSceneHeight = 0; + I_FatalError("Unable to create render buffers."); } - return !FailedCreate; + return true; } //========================================================================== @@ -615,7 +604,7 @@ bool FGLRenderBuffers::CheckFrameBufferCompleteness() if (result == GL_FRAMEBUFFER_COMPLETE) return true; - FailedCreate = true; + bool FailedCreate = true; if (gl_debug_level > 0) { @@ -926,10 +915,4 @@ void FGLRenderBuffers::BindOutputFB() // //========================================================================== -bool FGLRenderBuffers::IsEnabled() -{ - return BuffersActive && !FailedCreate; -} - bool FGLRenderBuffers::FailedCreate = false; -bool FGLRenderBuffers::BuffersActive = false; diff --git a/src/gl/renderer/gl_renderbuffers.h b/src/gl/renderer/gl_renderbuffers.h index 1b2867e4bc..41e45aaecc 100644 --- a/src/gl/renderer/gl_renderbuffers.h +++ b/src/gl/renderer/gl_renderbuffers.h @@ -192,7 +192,6 @@ private: int mCurrentShadowMapSize = 0; static bool FailedCreate; - static bool BuffersActive; }; #endif \ No newline at end of file diff --git a/src/gl/renderer/gl_renderstate.cpp b/src/gl/renderer/gl_renderstate.cpp index b526f3aef5..9ce22f1705 100644 --- a/src/gl/renderer/gl_renderstate.cpp +++ b/src/gl/renderer/gl_renderstate.cpp @@ -236,7 +236,7 @@ bool FRenderState::ApplyShader() } else if ((mColormapState >= CM_FIRSTSPECIALCOLORMAP && mColormapState < CM_MAXCOLORMAPFORCED)) { - if (FGLRenderBuffers::IsEnabled() && mColormapState < CM_FIRSTSPECIALCOLORMAPFORCED) + if (mColormapState < CM_FIRSTSPECIALCOLORMAPFORCED) { // When using postprocessing to apply the colormap, we must render the image fullbright here. activeShader->muFixedColormap.Set(2); diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index 3106ab9717..2517d3a8aa 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -488,7 +488,7 @@ void GLSceneDrawer::EndDrawScene(FDrawInfo *di, sector_t * viewsector) Reset3DViewport(); // Delay drawing psprites until after bloom has been applied, if enabled. - if (!FGLRenderBuffers::IsEnabled() || !gl_bloom || FixedColormap != CM_DEFAULT) + if (!gl_bloom || FixedColormap != CM_DEFAULT) { DrawEndScene2D(di, viewsector); } @@ -659,7 +659,7 @@ sector_t * GLSceneDrawer::RenderViewpoint (AActor * camera, IntRect * bounds, fl ProcessScene(di, toscreen); if (mainview && toscreen) EndDrawScene(di, lviewsector); // do not call this for camera textures. - if (mainview && FGLRenderBuffers::IsEnabled()) + if (mainview) { GLRenderer->PostProcessScene(FixedColormap, [&]() { if (gl_bloom && FixedColormap == CM_DEFAULT) DrawEndScene2D(di, lviewsector); }); @@ -676,7 +676,7 @@ sector_t * GLSceneDrawer::RenderViewpoint (AActor * camera, IntRect * bounds, fl } FDrawInfo::EndDrawInfo(); GLRenderer->mDrawingScene2D = false; - if (!stereo3dMode.IsMono() && FGLRenderBuffers::IsEnabled()) + if (!stereo3dMode.IsMono()) GLRenderer->mBuffers->BlitToEyeTexture(eye_ix); eye->TearDown(); } @@ -716,12 +716,6 @@ void GLSceneDrawer::WriteSavePic (player_t *player, FileWriter *file, int width, glDisable(GL_STENCIL_TEST); gl_RenderState.SetFixedColormap(CM_DEFAULT); gl_RenderState.SetSoftLightLevel(-1); - if (!FGLRenderBuffers::IsEnabled()) - { - // Since this doesn't do any of the 2D rendering it needs to draw the screen blend itself before extracting the image. - screen->DrawBlend(viewsector); - screen->Draw2D(); - } GLRenderer->CopyToBackbuffer(&bounds, false); // strictly speaking not needed as the glReadPixels should block until the scene is rendered, but this is to safeguard against shitty drivers diff --git a/src/gl/shaders/gl_shader.cpp b/src/gl/shaders/gl_shader.cpp index 24d7acf91e..f81ff79ff5 100644 --- a/src/gl/shaders/gl_shader.cpp +++ b/src/gl/shaders/gl_shader.cpp @@ -179,12 +179,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * unsigned int lightbuffersize = GLRenderer->mLights->GetBlockSize(); if (lightbuffertype == GL_UNIFORM_BUFFER) { - { - } - else - { - vp_comb.Format("#version 330 core\n#define NUM_UBO_LIGHTS %d\n", lightbuffersize); - } + vp_comb.Format("#version 330 core\n#define NUM_UBO_LIGHTS %d\n", lightbuffersize); } else { diff --git a/src/gl/system/gl_framebuffer.cpp b/src/gl/system/gl_framebuffer.cpp index 9f7a220dee..8e8905e3c1 100644 --- a/src/gl/system/gl_framebuffer.cpp +++ b/src/gl/system/gl_framebuffer.cpp @@ -238,21 +238,13 @@ uint32_t OpenGLFrameBuffer::GetCaps() // describe our basic feature set ActorRenderFeatureFlags FlagSet = RFF_FLATSPRITES | RFF_MODELS | RFF_SLOPE3DFLOORS | - RFF_TILTPITCH | RFF_ROLLSPRITES | RFF_POLYGONAL; + RFF_TILTPITCH | RFF_ROLLSPRITES | RFF_POLYGONAL | RFF_MATSHADER | RFF_POSTSHADER | RFF_BRIGHTMAP; if (r_drawvoxels) FlagSet |= RFF_VOXELS; - if (!RenderBuffersEnabled()) - { - // truecolor is always available when renderbuffers are unavailable because palette tonemap is not possible - FlagSet |= RFF_TRUECOLOR | RFF_MATSHADER | RFF_BRIGHTMAP; - } - else - { - if (gl_tonemap != 5) // not running palette tonemap shader - FlagSet |= RFF_TRUECOLOR; - FlagSet |= RFF_MATSHADER | RFF_POSTSHADER | RFF_BRIGHTMAP; - } + if (gl_tonemap != 5) // not running palette tonemap shader + FlagSet |= RFF_TRUECOLOR; + return (uint32_t)FlagSet; } @@ -393,11 +385,6 @@ void OpenGLFrameBuffer::BlurScene(float amount) GLRenderer->BlurScene(amount); } -bool OpenGLFrameBuffer::RenderBuffersEnabled() -{ - return FGLRenderBuffers::IsEnabled(); -} - void OpenGLFrameBuffer::SetViewportRects(IntRect *bounds) { Super::SetViewportRects(bounds); diff --git a/src/gl/system/gl_framebuffer.h b/src/gl/system/gl_framebuffer.h index 8aff329064..ef375c2e47 100644 --- a/src/gl/system/gl_framebuffer.h +++ b/src/gl/system/gl_framebuffer.h @@ -41,7 +41,6 @@ public: void TextureFilterChanged() override; void ResetFixedColormap() override; void BeginFrame() override; - bool RenderBuffersEnabled() override; void SetViewportRects(IntRect *bounds) override; void BlurScene(float amount) override; IUniformBuffer *CreateUniformBuffer(size_t size, bool staticuse = false) override; diff --git a/src/gl/system/gl_wipe.cpp b/src/gl/system/gl_wipe.cpp index 14d20f39f4..fba0db1a3f 100644 --- a/src/gl/system/gl_wipe.cpp +++ b/src/gl/system/gl_wipe.cpp @@ -128,19 +128,8 @@ bool OpenGLFrameBuffer::WipeStartScreen(int type) glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, viewport.left, viewport.top, viewport.width, viewport.height); }; - if (FGLRenderBuffers::IsEnabled()) - { - GLRenderer->mBuffers->BindCurrentFB(); - copyPixels(); - } - else - { - GLint readbuffer = 0; - glGetIntegerv(GL_READ_BUFFER, &readbuffer); - glReadBuffer(GL_FRONT); - copyPixels(); - glReadBuffer(readbuffer); - } + GLRenderer->mBuffers->BindCurrentFB(); + copyPixels(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); @@ -166,8 +155,7 @@ void OpenGLFrameBuffer::WipeEndScreen() glFinish(); wipeendscreen->Bind(0, false, false); - if (FGLRenderBuffers::IsEnabled()) - GLRenderer->mBuffers->BindCurrentFB(); + GLRenderer->mBuffers->BindCurrentFB(); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, viewport.left, viewport.top, viewport.width, viewport.height); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); @@ -199,12 +187,9 @@ bool OpenGLFrameBuffer::WipeDo(int ticks) glDisable(GL_DEPTH_TEST); glDepthMask(false); - if (FGLRenderBuffers::IsEnabled()) - { - GLRenderer->mBuffers->BindCurrentFB(); - const auto &bounds = screen->mScreenViewport; - glViewport(bounds.left, bounds.top, bounds.width, bounds.height); - } + GLRenderer->mBuffers->BindCurrentFB(); + const auto &bounds = screen->mScreenViewport; + glViewport(bounds.left, bounds.top, bounds.width, bounds.height); done = ScreenWipe->Run(ticks, this); glDepthMask(true); diff --git a/src/hwrenderer/utility/hw_cvars.h b/src/hwrenderer/utility/hw_cvars.h index da7c683cdd..4402659306 100644 --- a/src/hwrenderer/utility/hw_cvars.h +++ b/src/hwrenderer/utility/hw_cvars.h @@ -34,7 +34,6 @@ EXTERN_CVAR(Bool, gl_seamless) EXTERN_CVAR(Float, gl_mask_threshold) EXTERN_CVAR(Float, gl_mask_sprite_threshold) -EXTERN_CVAR(Bool, gl_renderbuffers) EXTERN_CVAR(Int, gl_multisample) EXTERN_CVAR(Bool, gl_bloom) diff --git a/src/v_video.cpp b/src/v_video.cpp index 0f754d4c3e..9404bf644f 100644 --- a/src/v_video.cpp +++ b/src/v_video.cpp @@ -1072,7 +1072,7 @@ void DFrameBuffer::SetViewportRects(IntRect *bounds) bool notScaled = ((mScreenViewport.width == ViewportScaledWidth(mScreenViewport.width, mScreenViewport.height)) && (mScreenViewport.width == ViewportScaledHeight(mScreenViewport.width, mScreenViewport.height)) && !ViewportIsScaled43()); - if ((gl_scale_viewport && !IsFullscreen() && notScaled) || !RenderBuffersEnabled()) + if (gl_scale_viewport && !IsFullscreen() && notScaled) { mScreenViewport.width = mOutputLetterbox.width; mScreenViewport.height = mOutputLetterbox.height; @@ -1080,15 +1080,6 @@ void DFrameBuffer::SetViewportRects(IntRect *bounds) mSceneViewport.top = (int)round(mSceneViewport.top * scaleY); mSceneViewport.width = (int)round(mSceneViewport.width * scaleX); mSceneViewport.height = (int)round(mSceneViewport.height * scaleY); - - // Without render buffers we have to render directly to the letterbox - if (!RenderBuffersEnabled()) - { - mScreenViewport.left += mOutputLetterbox.left; - mScreenViewport.top += mOutputLetterbox.top; - mSceneViewport.left += mOutputLetterbox.left; - mSceneViewport.top += mOutputLetterbox.top; - } } } diff --git a/src/v_video.h b/src/v_video.h index fc6569aa98..abb0d4e79e 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -412,7 +412,6 @@ public: virtual int GetClientWidth() = 0; virtual int GetClientHeight() = 0; - virtual bool RenderBuffersEnabled() { return false; }; virtual void BlurScene(float amount) {} // Interface to hardware rendering resources