2121#include < memory>
2222#include < cstring>
2323#include < stdexcept>
24+ #include < mutex>
25+ #include < condition_variable>
2426
2527#ifndef _WIN32
2628#include " ../utils/linux_helpers.h"
@@ -143,7 +145,7 @@ void GPUDisplay::ResizeScene(int32_t width, int32_t height, bool init)
143145 mBackend ->resizeScene (width, height);
144146
145147 if (init) {
146- mResetScene = 1 ;
148+ mResetScene = true ;
147149 mViewMatrix = MY_HMM_IDENTITY;
148150 mModelMatrix = MY_HMM_IDENTITY;
149151 }
@@ -220,6 +222,14 @@ int32_t GPUDisplay::DrawGLScene()
220222 GPUError (" Runtime error %s during display" , e.what ());
221223 retVal = 1 ;
222224 }
225+
226+ if (mLoadAndShowEvent ) {
227+ {
228+ std::lock_guard<std::mutex> lock (mMutexLoadAndShowEvent );
229+ mLoadAndShowEvent = false ;
230+ }
231+ mCVLoadAndShowEvent .notify_one ();
232+ }
223233 mSemLockDisplay .Unlock ();
224234
225235 return retVal;
@@ -266,9 +276,9 @@ void GPUDisplay::DrawGLScene_cameraAndAnimation(float animateTime, float& mixSla
266276 mCfgR .camLookOrigin = mCfgR .camYUp = false ;
267277 mAngleRollOrigin = -1e9f;
268278 mCfgR .fov = 45 .f ;
269- mUpdateDrawCommands = 1 ;
279+ mUpdateDrawCommands = true ;
270280
271- mResetScene = 0 ;
281+ mResetScene = false ;
272282 } else {
273283 float moveZ = scalefactor * ((float )mMouseWheelTmp / 150 + (float )(mFrontend ->mKeys [(uint8_t )' W' ] - mFrontend ->mKeys [(uint8_t )' S' ]) * (!mFrontend ->mKeys [mFrontend ->KEY_SHIFT ]) * 0 .2f * mFPSScale );
274284 float moveY = scalefactor * ((float )(mFrontend ->mKeys [mFrontend ->KEY_PAGEDOWN ] - mFrontend ->mKeys [mFrontend ->KEY_PAGEUP ]) * 0 .2f * mFPSScale );
@@ -386,7 +396,7 @@ void GPUDisplay::DrawGLScene_cameraAndAnimation(float animateTime, float& mixSla
386396 }
387397 if (deltaLine) {
388398 SetInfo (" %s line width: %f" , deltaLine > 0 ? " Increasing" : " Decreasing" , mCfgL .lineWidth );
389- mUpdateDrawCommands = 1 ;
399+ mUpdateDrawCommands = true ;
390400 }
391401 minSize *= 2 ;
392402 int32_t deltaPoint = mFrontend ->mKeys [(uint8_t )' +' ] * (!mFrontend ->mKeysShift [(uint8_t )' +' ]) - mFrontend ->mKeys [(uint8_t )' -' ] * (!mFrontend ->mKeysShift [(uint8_t )' -' ]);
@@ -396,7 +406,7 @@ void GPUDisplay::DrawGLScene_cameraAndAnimation(float animateTime, float& mixSla
396406 }
397407 if (deltaPoint) {
398408 SetInfo (" %s point size: %f" , deltaPoint > 0 ? " Increasing" : " Decreasing" , mCfgL .pointSize );
399- mUpdateDrawCommands = 1 ;
409+ mUpdateDrawCommands = true ;
400410 }
401411 }
402412
@@ -616,7 +626,7 @@ void GPUDisplay::DrawGLScene_internal(float animateTime, bool renderToMixBuffer)
616626 disableUnsupportedOptions ();
617627 }
618628 if (mUpdateEventData || mUpdateVertexLists ) {
619- mUpdateDrawCommands = 1 ;
629+ mUpdateDrawCommands = true ;
620630 }
621631
622632 if (animateTime < 0 && (mUpdateEventData || mResetScene ) && mIOPtrs ) {
@@ -625,8 +635,8 @@ void GPUDisplay::DrawGLScene_internal(float animateTime, bool renderToMixBuffer)
625635 mTimerFPS .ResetStart ();
626636 mFramesDoneFPS = 0 ;
627637 mFPSScaleadjust = 0 ;
628- mUpdateVertexLists = 1 ;
629- mUpdateEventData = 0 ;
638+ mUpdateVertexLists = true ;
639+ mUpdateEventData = false ;
630640 }
631641
632642 hmm_mat4 nextViewMatrix = MY_HMM_IDENTITY;
@@ -658,7 +668,7 @@ void GPUDisplay::DrawGLScene_internal(float animateTime, bool renderToMixBuffer)
658668 mBackend ->drawField ();
659669 }
660670
661- mUpdateDrawCommands = mUpdateRenderPipeline = 0 ;
671+ mUpdateDrawCommands = mUpdateRenderPipeline = false ;
662672 mBackend ->finishDraw (doScreenshot, renderToMixBuffer, mixSlaveImage);
663673
664674 if (animateTime < 0 ) {
@@ -708,15 +718,25 @@ void GPUDisplay::ShowNextEvent(const GPUTrackingInOutPointers* ptrs)
708718 if (mMaxClusterZ <= 0 ) {
709719 mResetScene = true ;
710720 }
711- mSemLockDisplay .Unlock ();
712721 mFrontend ->mNeedUpdate = 1 ;
713722 mUpdateEventData = true ;
723+ mLoadAndShowEvent = true ;
724+ mSemLockDisplay .Unlock ();
714725}
715726
716- void GPUDisplay::WaitForNextEvent () { mSemLockDisplay .Lock (); }
727+ void GPUDisplay::BlockTillNextEvent () { mSemLockDisplay .Lock (); }
728+
729+ void GPUDisplay::WaitTillEventShown ()
730+ {
731+ std::unique_lock<std::mutex> lock (mMutexLoadAndShowEvent );
732+ while (mLoadAndShowEvent ) {
733+ mCVLoadAndShowEvent .wait (lock);
734+ }
735+ }
717736
718737int32_t GPUDisplay::StartDisplay ()
719738{
739+ mLoadAndShowEvent = true ;
720740 if (mFrontend ->StartDisplay ()) {
721741 return (1 );
722742 }
0 commit comments