diff --git a/es-core/src/Window.cpp b/es-core/src/Window.cpp index af3ba4f98..efce803e2 100644 --- a/es-core/src/Window.cpp +++ b/es-core/src/Window.cpp @@ -45,6 +45,8 @@ Window::Window() noexcept , mAllowFileAnimation(true) , mCachedBackground(false) , mInvalidatedCachedBackground(false) + , mInitiateCacheTimer{false} + , mInvalidateCacheTimer{0} , mVideoPlayerCount(0) , mTopScale(0.5) , mChangedThemeSet(false) @@ -304,6 +306,9 @@ void Window::logInput(InputConfig* config, Input input) void Window::update(int deltaTime) { + if (mInvalidateCacheTimer > 0) + mInvalidateCacheTimer = glm::clamp(mInvalidateCacheTimer - deltaTime, 0, 500); + if (mNormalizeNextUpdate) { mNormalizeNextUpdate = false; mTimeSinceLastInput = 0; @@ -397,6 +402,13 @@ bool Window::isBackgroundDimmed() void Window::render() { + // Short 50 ms delay before invalidating the cached background which will give the various + // components a chance to render so they don't get exclued from the new cached image. + if (mInitiateCacheTimer) { + mInvalidateCacheTimer = 50; + mInitiateCacheTimer = false; + } + glm::mat4 trans{Renderer::getIdentity()}; mRenderedHelpPrompts = false; @@ -431,7 +443,7 @@ void Window::render() if (bottom != top || mRenderLaunchScreen) { #if defined(USE_OPENGL_21) - if (!mCachedBackground) { + if (!mCachedBackground && mInvalidateCacheTimer == 0) { // Generate a cache texture of the shaded background when opening the menu, which // will remain valid until the menu is closed. This is way faster than having to // render the shaders for every frame. @@ -839,6 +851,7 @@ void Window::invalidateCachedBackground() { mCachedBackground = false; mInvalidatedCachedBackground = true; + mInitiateCacheTimer = true; } bool Window::isProcessing() diff --git a/es-core/src/Window.h b/es-core/src/Window.h index 8823c2c10..e96bc6983 100644 --- a/es-core/src/Window.h +++ b/es-core/src/Window.h @@ -137,6 +137,7 @@ public: void setLaunchedGame(); void unsetLaunchedGame(); void invalidateCachedBackground(); + bool isInvalidatingCachedBackground() { return mInvalidateCacheTimer > 0; } bool getGameLaunchedState() { return mGameLaunchedState; } void setAllowTextScrolling(bool value) { mAllowTextScrolling = value; } @@ -198,6 +199,8 @@ private: bool mAllowFileAnimation; bool mCachedBackground; bool mInvalidatedCachedBackground; + bool mInitiateCacheTimer; + int mInvalidateCacheTimer; std::atomic mVideoPlayerCount;