From 83ce72db486d16f09f4ca722288aefaa28146087 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 6 Jan 2019 13:35:31 +0100 Subject: [PATCH] - check the shader timer only once per frame, not once per draw call. --- src/gl/renderer/gl_renderer.cpp | 4 +++- src/gl/renderer/gl_renderstate.cpp | 14 ++++++++------ src/gl/renderer/gl_renderstate.h | 3 +++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/gl/renderer/gl_renderer.cpp b/src/gl/renderer/gl_renderer.cpp index 6d6f38287b..3857f5e4f6 100644 --- a/src/gl/renderer/gl_renderer.cpp +++ b/src/gl/renderer/gl_renderer.cpp @@ -254,7 +254,9 @@ sector_t *FGLRenderer::RenderView(player_t* player) bool saved_niv = NoInterpolateView; NoInterpolateView = false; // prepare all camera textures that have been used in the last frame - level.canvasTextureInfo.UpdateAll([&](AActor *camera, FCanvasTexture *camtex, double fov) + auto Level = player->mo->__GetLevel(); + gl_RenderState.CheckTimer(Level->ShaderStartTime); + Level->canvasTextureInfo.UpdateAll([&](AActor *camera, FCanvasTexture *camtex, double fov) { RenderTextureView(camtex, camera, fov); }); diff --git a/src/gl/renderer/gl_renderstate.cpp b/src/gl/renderer/gl_renderstate.cpp index 9af56aac8a..18657e7487 100644 --- a/src/gl/renderer/gl_renderstate.cpp +++ b/src/gl/renderer/gl_renderstate.cpp @@ -93,12 +93,6 @@ void FGLRenderState::Reset() bool FGLRenderState::ApplyShader() { - static uint64_t firstFrame = 0; - // if firstFrame is not yet initialized, initialize it to current time - // if we're going to overflow a float (after ~4.6 hours, or 24 bits), re-init to regain precision - if ((firstFrame == 0) || (screen->FrameTime - firstFrame >= 1<<24) || level.ShaderStartTime >= firstFrame) - firstFrame = screen->FrameTime; - static const float nulvec[] = { 0.f, 0.f, 0.f, 0.f }; if (mSpecialEffect > EFF_NONE) { @@ -595,4 +589,12 @@ bool FGLRenderState::SetDepthClamp(bool on) return res; } +void FGLRenderState::CheckTimer(uint64_t ShaderStartTime) +{ + // if firstFrame is not yet initialized, initialize it to current time + // if we're going to overflow a float (after ~4.6 hours, or 24 bits), re-init to regain precision + if ((firstFrame == 0) || (screen->FrameTime - firstFrame >= 1 << 24) || ShaderStartTime >= firstFrame) + firstFrame = screen->FrameTime; +} + } diff --git a/src/gl/renderer/gl_renderstate.h b/src/gl/renderer/gl_renderstate.h index f72b1a61ef..671a7e506e 100644 --- a/src/gl/renderer/gl_renderstate.h +++ b/src/gl/renderer/gl_renderstate.h @@ -50,6 +50,8 @@ enum EPassType class FGLRenderState : public FRenderState { + uint64_t firstFrame = 0; + uint8_t mLastDepthClamp : 1; float mGlossiness, mSpecularLevel; @@ -102,6 +104,7 @@ public: void Apply(); void ApplyBuffers(); void ApplyBlendMode(); + void CheckTimer(uint64_t ShaderStartTime); void ResetVertexBuffer() {