Browse Source

OpenGL: removed the artifical render-throttling code, allowing the rendering to be kept in sync by the native GL swap-interval.

tags/2021-05-28
jules 13 years ago
parent
commit
0abd7a3fa1
3 changed files with 9 additions and 14 deletions
  1. +0
    -2
      modules/juce_opengl/native/juce_OpenGL_osx.h
  2. +7
    -12
      modules/juce_opengl/opengl/juce_OpenGLContext.cpp
  3. +2
    -0
      modules/juce_opengl/opengl/juce_OpenGLContext.h

+ 0
- 2
modules/juce_opengl/native/juce_OpenGL_osx.h View File

@@ -143,8 +143,6 @@ public:
renderContext = [[[NSOpenGLContext alloc] initWithFormat: format renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
shareContext: (NSOpenGLContext*) contextToShare] autorelease]; shareContext: (NSOpenGLContext*) contextToShare] autorelease];
setSwapInterval (1);
[view setOpenGLContext: renderContext]; [view setOpenGLContext: renderContext];
[format release]; [format release];


+ 7
- 12
modules/juce_opengl/opengl/juce_OpenGLContext.cpp View File

@@ -42,9 +42,14 @@ public:
nativeContext = new NativeContext (component, pixFormat, contextToShare); nativeContext = new NativeContext (component, pixFormat, contextToShare);
if (nativeContext->createdOk()) if (nativeContext->createdOk())
{
nativeContext->setSwapInterval (1);
context.nativeContext = nativeContext; context.nativeContext = nativeContext;
}
else else
{
nativeContext = nullptr; nativeContext = nullptr;
}
} }
~CachedImage() ~CachedImage()
@@ -295,10 +300,8 @@ public:
while (! threadShouldExit()) 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(); shutdownOnThread();
@@ -332,14 +335,6 @@ public:
associatedObjects.clear(); 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 static CachedImage* get (Component& c) noexcept
{ {


+ 2
- 0
modules/juce_opengl/opengl/juce_OpenGLContext.h View File

@@ -188,6 +188,8 @@ public:
fairly system-dependent, but 0 turns off syncing, 1 makes it swap on frame-boundaries, 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. 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 Returns true if it sets the value successfully - some platforms won't support
this setting. this setting.
*/ */


Loading…
Cancel
Save