Found a better method to limit buffer swaps during splash screen rendering.

This commit is contained in:
Leon Styhre 2023-01-22 23:24:08 +01:00
parent 8c03c97e57
commit 022446bce7
3 changed files with 16 additions and 11 deletions

View file

@ -25,6 +25,8 @@
#include "views/GamelistView.h"
#include "views/ViewController.h"
#include <SDL2/SDL_timer.h>
#include <fstream>
#include <pugixml.hpp>
#include <random>
@ -511,6 +513,7 @@ bool SystemData::loadConfig()
const bool splashScreen {Settings::getInstance()->getBool("SplashScreen")};
float systemCount {0.0f};
float loadedSystems {0.0f};
long unsigned int lastTime {0};
for (pugi::xml_node system {systemList.child("system")}; system;
system = system.next_sibling("system")) {
@ -531,10 +534,17 @@ bool SystemData::loadConfig()
path = system.child("path").text().get();
if (splashScreen) {
const long unsigned int curTime {SDL_GetTicks64()};
const long unsigned int deltaTime {curTime - lastTime};
lastTime = curTime;
++loadedSystems;
const float progress {glm::mix(0.0f, 0.5f, loadedSystems / systemCount)};
Window::getInstance()->renderSplashScreen(Window::SplashScreenState::SCANNING,
progress);
// This prevents Renderer::swapBuffers() from being called excessively which
// could lead to significantly longer application startup times.
if (deltaTime > 15) {
const float progress {glm::mix(0.0f, 0.5f, loadedSystems / systemCount)};
Window::getInstance()->renderSplashScreen(Window::SplashScreenState::SCANNING,
progress);
}
}
auto nameFindFunc = [&] {

View file

@ -707,15 +707,7 @@ int main(int argc, char* argv[])
AudioManager::getInstance();
MameNames::getInstance();
ThemeData::populateThemeSets();
// We need to temporarily disable VSync as the splash screen may otherwise slow down
// application startup significantly due to excessive swapBuffers() calls.
const bool splashScreen {Settings::getInstance()->getBool("SplashScreen")};
const bool vSync {Settings::getInstance()->getBool("VSync")};
if (splashScreen && vSync)
SDL_GL_SetSwapInterval(0);
loadSystemsReturnCode loadSystemsStatus {loadSystemConfigFile()};
if (splashScreen && vSync)
SDL_GL_SetSwapInterval(1);
if (loadSystemsStatus) {
// If there was an issue parsing the es_systems.xml file, display an error message.

View file

@ -1104,6 +1104,9 @@ void ViewController::preload()
{
unsigned int systemCount {static_cast<unsigned int>(SystemData::sSystemVector.size())};
if (Settings::getInstance()->getBool("SplashScreen"))
mWindow->renderSplashScreen(Window::SplashScreenState::POPULATING, 0.5f);
// This reduces the amount of texture pop-in when loading theme extras.
if (!SystemData::sSystemVector.empty())
getSystemListView();