Fix the problem. Still need to leave the loop with SDL even if we supply a swap function.

This commit is contained in:
Henrik Rydgård 2023-01-30 15:45:05 +01:00
parent d43452f0ce
commit cb16f193ec
5 changed files with 10 additions and 4 deletions

View File

@ -515,6 +515,10 @@ bool GLRenderManager::Run(GLRRenderThreadTask &task) {
if (swapFunction_) { if (swapFunction_) {
VLOG(" PULL: SwapFunction()"); VLOG(" PULL: SwapFunction()");
swapFunction_(); swapFunction_();
if (!retainControl_) {
// get out of here.
swapRequest = true;
}
} else { } else {
VLOG(" PULL: SwapRequested"); VLOG(" PULL: SwapRequested");
swapRequest = true; swapRequest = true;

View File

@ -992,8 +992,9 @@ public:
_dbg_assert_(foundCount == 1); _dbg_assert_(foundCount == 1);
} }
void SetSwapFunction(std::function<void()> swapFunction) { void SetSwapFunction(std::function<void()> swapFunction, bool retainControl) {
swapFunction_ = swapFunction; swapFunction_ = swapFunction;
retainControl_ = retainControl;
} }
void SetSwapIntervalFunction(std::function<void(int)> swapIntervalFunction) { void SetSwapIntervalFunction(std::function<void(int)> swapIntervalFunction) {
@ -1086,6 +1087,7 @@ private:
std::function<void()> swapFunction_; std::function<void()> swapFunction_;
std::function<void(int)> swapIntervalFunction_; std::function<void(int)> swapIntervalFunction_;
bool retainControl_ = false;
GLBufferStrategy bufferStrategy_ = GLBufferStrategy::SUBDATA; GLBufferStrategy bufferStrategy_ = GLBufferStrategy::SUBDATA;
int inflightFrames_ = MAX_INFLIGHT_FRAMES; int inflightFrames_ = MAX_INFLIGHT_FRAMES;

View File

@ -429,7 +429,7 @@ int SDLGLGraphicsContext::Init(SDL_Window *&window, int x, int y, int mode, std:
#else #else
SDL_GL_SwapWindow(window_); SDL_GL_SwapWindow(window_);
#endif #endif
}); }, false);
renderManager_->SetSwapIntervalFunction([&](int interval) { renderManager_->SetSwapIntervalFunction([&](int interval) {
INFO_LOG(G3D, "SDL SwapInterval: %d", interval); INFO_LOG(G3D, "SDL SwapInterval: %d", interval);

View File

@ -432,7 +432,7 @@ bool WindowsGLContext::InitFromRenderThread(std::string *error_message) {
renderManager_ = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER); renderManager_ = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
renderManager_->SetInflightFrames(g_Config.iInflightFrames); renderManager_->SetInflightFrames(g_Config.iInflightFrames);
SetGPUBackend(GPUBackend::OPENGL); SetGPUBackend(GPUBackend::OPENGL);
renderManager_->SetSwapFunction([&]() {::SwapBuffers(hDC); }); renderManager_->SetSwapFunction([&]() {::SwapBuffers(hDC); }, true);
if (wglSwapIntervalEXT) { if (wglSwapIntervalEXT) {
// glew loads wglSwapIntervalEXT if available // glew loads wglSwapIntervalEXT if available
renderManager_->SetSwapIntervalFunction([&](int interval) { renderManager_->SetSwapIntervalFunction([&](int interval) {

View File

@ -166,7 +166,7 @@ bool GLDummyGraphicsContext::InitFromRenderThread(std::string *errorMessage) {
_assert_(success); _assert_(success);
renderManager_->SetSwapFunction([&]() { renderManager_->SetSwapFunction([&]() {
SDL_GL_SwapWindow(screen_); SDL_GL_SwapWindow(screen_);
}); }, false);
return success; return success;
} }