|
|
@@ -35,7 +35,6 @@ public: |
|
|
|
void* contextToShare,
|
|
|
|
bool shouldUseMultisampling,
|
|
|
|
OpenGLVersion version)
|
|
|
|
: lastSwapTime (0), minSwapTimeMs (0), underrunCounter (0)
|
|
|
|
{
|
|
|
|
NSOpenGLPixelFormatAttribute attribs[64] = { 0 };
|
|
|
|
createAttribs (attribs, version, pixFormat, shouldUseMultisampling);
|
|
|
@@ -71,7 +70,7 @@ public: |
|
|
|
[renderContext clearDrawable];
|
|
|
|
[renderContext setView: nil];
|
|
|
|
[view setOpenGLContext: nil];
|
|
|
|
renderContext = nil;
|
|
|
|
[view release];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void createAttribs (NSOpenGLPixelFormatAttribute* attribs, OpenGLVersion version,
|
|
|
@@ -81,33 +80,33 @@ public: |
|
|
|
int numAttribs = 0;
|
|
|
|
|
|
|
|
#if JUCE_OPENGL3
|
|
|
|
attribs [numAttribs++] = NSOpenGLPFAOpenGLProfile;
|
|
|
|
attribs [numAttribs++] = version >= openGL3_2 ? NSOpenGLProfileVersion3_2Core
|
|
|
|
: NSOpenGLProfileVersionLegacy;
|
|
|
|
attribs[numAttribs++] = NSOpenGLPFAOpenGLProfile;
|
|
|
|
attribs[numAttribs++] = version >= openGL3_2 ? NSOpenGLProfileVersion3_2Core
|
|
|
|
: NSOpenGLProfileVersionLegacy;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
attribs [numAttribs++] = NSOpenGLPFADoubleBuffer;
|
|
|
|
attribs [numAttribs++] = NSOpenGLPFAClosestPolicy;
|
|
|
|
attribs [numAttribs++] = NSOpenGLPFANoRecovery;
|
|
|
|
attribs [numAttribs++] = NSOpenGLPFAColorSize;
|
|
|
|
attribs [numAttribs++] = (NSOpenGLPixelFormatAttribute) (pixFormat.redBits + pixFormat.greenBits + pixFormat.blueBits);
|
|
|
|
attribs [numAttribs++] = NSOpenGLPFAAlphaSize;
|
|
|
|
attribs [numAttribs++] = (NSOpenGLPixelFormatAttribute) pixFormat.alphaBits;
|
|
|
|
attribs [numAttribs++] = NSOpenGLPFADepthSize;
|
|
|
|
attribs [numAttribs++] = (NSOpenGLPixelFormatAttribute) pixFormat.depthBufferBits;
|
|
|
|
attribs [numAttribs++] = NSOpenGLPFAStencilSize;
|
|
|
|
attribs [numAttribs++] = (NSOpenGLPixelFormatAttribute) pixFormat.stencilBufferBits;
|
|
|
|
attribs [numAttribs++] = NSOpenGLPFAAccumSize;
|
|
|
|
attribs [numAttribs++] = (NSOpenGLPixelFormatAttribute) (pixFormat.accumulationBufferRedBits + pixFormat.accumulationBufferGreenBits
|
|
|
|
attribs[numAttribs++] = NSOpenGLPFADoubleBuffer;
|
|
|
|
attribs[numAttribs++] = NSOpenGLPFAClosestPolicy;
|
|
|
|
attribs[numAttribs++] = NSOpenGLPFANoRecovery;
|
|
|
|
attribs[numAttribs++] = NSOpenGLPFAColorSize;
|
|
|
|
attribs[numAttribs++] = (NSOpenGLPixelFormatAttribute) (pixFormat.redBits + pixFormat.greenBits + pixFormat.blueBits);
|
|
|
|
attribs[numAttribs++] = NSOpenGLPFAAlphaSize;
|
|
|
|
attribs[numAttribs++] = (NSOpenGLPixelFormatAttribute) pixFormat.alphaBits;
|
|
|
|
attribs[numAttribs++] = NSOpenGLPFADepthSize;
|
|
|
|
attribs[numAttribs++] = (NSOpenGLPixelFormatAttribute) pixFormat.depthBufferBits;
|
|
|
|
attribs[numAttribs++] = NSOpenGLPFAStencilSize;
|
|
|
|
attribs[numAttribs++] = (NSOpenGLPixelFormatAttribute) pixFormat.stencilBufferBits;
|
|
|
|
attribs[numAttribs++] = NSOpenGLPFAAccumSize;
|
|
|
|
attribs[numAttribs++] = (NSOpenGLPixelFormatAttribute) (pixFormat.accumulationBufferRedBits + pixFormat.accumulationBufferGreenBits
|
|
|
|
+ pixFormat.accumulationBufferBlueBits + pixFormat.accumulationBufferAlphaBits);
|
|
|
|
|
|
|
|
if (shouldUseMultisampling)
|
|
|
|
{
|
|
|
|
attribs [numAttribs++] = NSOpenGLPFAMultisample;
|
|
|
|
attribs [numAttribs++] = NSOpenGLPFASampleBuffers;
|
|
|
|
attribs [numAttribs++] = (NSOpenGLPixelFormatAttribute) 1;
|
|
|
|
attribs [numAttribs++] = NSOpenGLPFASamples;
|
|
|
|
attribs [numAttribs++] = (NSOpenGLPixelFormatAttribute) pixFormat.multisamplingLevel;
|
|
|
|
attribs[numAttribs++] = NSOpenGLPFAMultisample;
|
|
|
|
attribs[numAttribs++] = NSOpenGLPFASampleBuffers;
|
|
|
|
attribs[numAttribs++] = (NSOpenGLPixelFormatAttribute) 1;
|
|
|
|
attribs[numAttribs++] = NSOpenGLPFASamples;
|
|
|
|
attribs[numAttribs++] = (NSOpenGLPixelFormatAttribute) pixFormat.multisamplingLevel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
@@ -162,7 +161,7 @@ public: |
|
|
|
|
|
|
|
void swapBuffers()
|
|
|
|
{
|
|
|
|
double now = Time::getMillisecondCounterHiRes();
|
|
|
|
auto now = Time::getMillisecondCounterHiRes();
|
|
|
|
[renderContext flushBuffer];
|
|
|
|
|
|
|
|
if (minSwapTimeMs > 0)
|
|
|
@@ -172,8 +171,8 @@ public: |
|
|
|
// speed, burning CPU. This hack detects when things are going too fast
|
|
|
|
// and sleeps if necessary.
|
|
|
|
|
|
|
|
const double swapTime = Time::getMillisecondCounterHiRes() - now;
|
|
|
|
const int frameTime = (int) (now - lastSwapTime);
|
|
|
|
auto swapTime = Time::getMillisecondCounterHiRes() - now;
|
|
|
|
auto frameTime = (int) (now - lastSwapTime);
|
|
|
|
|
|
|
|
if (swapTime < 0.5 && frameTime < minSwapTimeMs - 3)
|
|
|
|
{
|
|
|
@@ -183,7 +182,9 @@ public: |
|
|
|
now = Time::getMillisecondCounterHiRes();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++underrunCounter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
@@ -215,11 +216,11 @@ public: |
|
|
|
return numFrames;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSOpenGLContext* renderContext;
|
|
|
|
NSOpenGLView* view;
|
|
|
|
NSOpenGLContext* renderContext = nil;
|
|
|
|
NSOpenGLView* view = nil;
|
|
|
|
ReferenceCountedObjectPtr<ReferenceCountedObject> viewAttachment;
|
|
|
|
double lastSwapTime;
|
|
|
|
int minSwapTimeMs, underrunCounter;
|
|
|
|
double lastSwapTime = 0;
|
|
|
|
int minSwapTimeMs = 0, underrunCounter = 0;
|
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
struct MouseForwardingNSOpenGLViewClass : public ObjCClass<NSOpenGLView>
|
|
|
|