From 5eeac830eb5de7b5f2aa345af11cfd044e844b07 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Wed, 17 Aug 2016 17:37:13 +0200 Subject: [PATCH] Clear and InvalidateFramebuffer optimization --- src/gl/scene/gl_scene.cpp | 14 +++++++------- src/gl/system/gl_interface.cpp | 2 ++ src/gl/system/gl_interface.h | 4 +++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index 91f01adf74..b96b1d3b6c 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -174,18 +174,18 @@ void FGLRenderer::Set3DViewport(bool mainview) mBuffers->BindSceneFB(); } + // Always clear all buffers with scissor test disabled. + // This is faster on newer hardware because it allows the GPU to skip + // reading from slower memory where the full buffers are stored. + glDisable(GL_SCISSOR_TEST); + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + const auto &bounds = mSceneViewport; glViewport(bounds.left, bounds.top, bounds.width, bounds.height); glScissor(bounds.left, bounds.top, bounds.width, bounds.height); glEnable(GL_SCISSOR_TEST); - - #ifdef _DEBUG - glClearColor(0.0f, 0.0f, 0.0f, 0.0f); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); - #else - glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); - #endif glEnable(GL_MULTISAMPLE); glEnable(GL_DEPTH_TEST); diff --git a/src/gl/system/gl_interface.cpp b/src/gl/system/gl_interface.cpp index 6176a2be9f..8c1e4cd9b6 100644 --- a/src/gl/system/gl_interface.cpp +++ b/src/gl/system/gl_interface.cpp @@ -244,6 +244,8 @@ void gl_LoadExtensions() gl.buffermethod = BM_PERSISTENT; } + if (gl.version >= 4.3f || CheckExtension("GL_ARB_invalidate_subdata")) gl.flags |= RFL_INVALIDATE_BUFFER; + const char *lm = Args->CheckValue("-lightmethod"); if (lm != NULL) { diff --git a/src/gl/system/gl_interface.h b/src/gl/system/gl_interface.h index fbe4e09c8e..11b0573e5d 100644 --- a/src/gl/system/gl_interface.h +++ b/src/gl/system/gl_interface.h @@ -23,7 +23,9 @@ enum RenderFlags RFL_NO_RGBA16F = 32, RFL_NO_DEPTHSTENCIL = 64, - RFL_NO_CLIP_PLANES = 128 + RFL_NO_CLIP_PLANES = 128, + + RFL_INVALIDATE_BUFFER = 256 }; enum TexMode