use the message queue for GL context init/deinit

This commit is contained in:
Arisotura 2024-06-14 19:30:10 +02:00
parent 77548ac086
commit 9b13b5e492
2 changed files with 17 additions and 28 deletions

View File

@ -443,22 +443,6 @@ void EmuThread::run()
{ {
emuInstance->drawScreenGL(); emuInstance->drawScreenGL();
} }
ContextRequestKind contextRequest = ContextRequest;
if (contextRequest == contextRequest_InitGL)
{
emuInstance->initOpenGL();
useOpenGL = true;
ContextRequest = contextRequest_None;
}
else if (contextRequest == contextRequest_DeInitGL)
{
emuInstance->deinitOpenGL();
useOpenGL = false;
ContextRequest = contextRequest_None;
}
} }
handleMessages(); handleMessages();
@ -510,6 +494,16 @@ void EmuThread::handleMessages()
emuInstance->audioDisable(); emuInstance->audioDisable();
emit windowEmuStop(); emit windowEmuStop();
break; break;
case msg_InitGL:
emuInstance->initOpenGL();
useOpenGL = true;
break;
case msg_DeInitGL:
emuInstance->deinitOpenGL();
useOpenGL = false;
break;
} }
msgSemaphore.release(); msgSemaphore.release();
@ -535,14 +529,14 @@ void EmuThread::emuRun()
void EmuThread::initContext() void EmuThread::initContext()
{ {
ContextRequest = contextRequest_InitGL; sendMessage(msg_InitGL);
while (ContextRequest != contextRequest_None); waitMessage();
} }
void EmuThread::deinitContext() void EmuThread::deinitContext()
{ {
ContextRequest = contextRequest_DeInitGL; sendMessage(msg_DeInitGL);
while (ContextRequest != contextRequest_None); waitMessage();
} }
void EmuThread::emuPause() void EmuThread::emuPause()

View File

@ -58,6 +58,9 @@ public:
enum MessageType enum MessageType
{ {
msg_EmuStop, msg_EmuStop,
msg_InitGL,
msg_DeInitGL,
}; };
struct Message struct Message
@ -146,14 +149,6 @@ private:
QSemaphore msgSemaphore; QSemaphore msgSemaphore;
QQueue<Message> msgQueue; QQueue<Message> msgQueue;
enum ContextRequestKind
{
contextRequest_None = 0,
contextRequest_InitGL,
contextRequest_DeInitGL
};
std::atomic<ContextRequestKind> ContextRequest = contextRequest_None;
EmuInstance* emuInstance; EmuInstance* emuInstance;
int autoScreenSizing; int autoScreenSizing;