diff --git a/modules/juce_opengl/native/juce_OpenGL_osx.h b/modules/juce_opengl/native/juce_OpenGL_osx.h index 87c3028355..517179b155 100644 --- a/modules/juce_opengl/native/juce_OpenGL_osx.h +++ b/modules/juce_opengl/native/juce_OpenGL_osx.h @@ -143,8 +143,6 @@ public: renderContext = [[[NSOpenGLContext alloc] initWithFormat: format shareContext: (NSOpenGLContext*) contextToShare] autorelease]; - setSwapInterval (1); - [view setOpenGLContext: renderContext]; [format release]; diff --git a/modules/juce_opengl/opengl/juce_OpenGLContext.cpp b/modules/juce_opengl/opengl/juce_OpenGLContext.cpp index 425714e1b3..bc214b38b4 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLContext.cpp +++ b/modules/juce_opengl/opengl/juce_OpenGLContext.cpp @@ -42,9 +42,14 @@ public: nativeContext = new NativeContext (component, pixFormat, contextToShare); if (nativeContext->createdOk()) + { + nativeContext->setSwapInterval (1); context.nativeContext = nativeContext; + } else + { nativeContext = nullptr; + } } ~CachedImage() @@ -295,10 +300,8 @@ public: while (! threadShouldExit()) { - const uint32 frameRenderStartTime = Time::getMillisecondCounter(); - - if (renderFrame()) - waitForNextFrame (frameRenderStartTime); + if (! renderFrame()) + wait (5); // failed to render, so avoid a tight fail-loop. } shutdownOnThread(); @@ -332,14 +335,6 @@ public: associatedObjects.clear(); } - void waitForNextFrame (const uint32 frameRenderStartTime) - { - const int defaultFPS = 60; - - const int elapsed = (int) (Time::getMillisecondCounter() - frameRenderStartTime); - wait (jmax (1, (1000 / defaultFPS - 1) - elapsed)); - } - //============================================================================== static CachedImage* get (Component& c) noexcept { diff --git a/modules/juce_opengl/opengl/juce_OpenGLContext.h b/modules/juce_opengl/opengl/juce_OpenGLContext.h index 14ddd0bf9c..5d5dee9e9b 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLContext.h +++ b/modules/juce_opengl/opengl/juce_OpenGLContext.h @@ -188,6 +188,8 @@ public: fairly system-dependent, but 0 turns off syncing, 1 makes it swap on frame-boundaries, and greater numbers indicate that it should swap less often. + By default, this will be set to 1. + Returns true if it sets the value successfully - some platforms won't support this setting. */