diff --git a/modules/juce_opengl/native/juce_OpenGL_osx.h b/modules/juce_opengl/native/juce_OpenGL_osx.h index 830b067c7a..49b5880319 100644 --- a/modules/juce_opengl/native/juce_OpenGL_osx.h +++ b/modules/juce_opengl/native/juce_OpenGL_osx.h @@ -28,30 +28,12 @@ public: NativeContext (Component& component, const OpenGLPixelFormat& pixFormat, void* contextToShare, - bool /*useMultisampling*/, + bool shouldUseMultisampling, OpenGLVersion version) : lastSwapTime (0), minSwapTimeMs (0), underrunCounter (0) { - (void) version; - - NSOpenGLPixelFormatAttribute attribs[] = - { - #if JUCE_OPENGL3 - NSOpenGLPFAOpenGLProfile, version >= openGL3_2 ? NSOpenGLProfileVersion3_2Core : NSOpenGLProfileVersionLegacy, - #endif - NSOpenGLPFADoubleBuffer, - NSOpenGLPFAClosestPolicy, - NSOpenGLPFANoRecovery, - NSOpenGLPFAColorSize, (NSOpenGLPixelFormatAttribute) (pixFormat.redBits + pixFormat.greenBits + pixFormat.blueBits), - NSOpenGLPFAAlphaSize, (NSOpenGLPixelFormatAttribute) pixFormat.alphaBits, - NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute) pixFormat.depthBufferBits, - NSOpenGLPFAStencilSize, (NSOpenGLPixelFormatAttribute) pixFormat.stencilBufferBits, - NSOpenGLPFAAccumSize, (NSOpenGLPixelFormatAttribute) (pixFormat.accumulationBufferRedBits + pixFormat.accumulationBufferGreenBits - + pixFormat.accumulationBufferBlueBits + pixFormat.accumulationBufferAlphaBits), - pixFormat.multisamplingLevel > 0 ? NSOpenGLPFASamples : (NSOpenGLPixelFormatAttribute) 0, - (NSOpenGLPixelFormatAttribute) pixFormat.multisamplingLevel, - 0 - }; + NSOpenGLPixelFormatAttribute attribs[64] = { 0 }; + createAttribs (attribs, version, pixFormat, shouldUseMultisampling); NSOpenGLPixelFormat* format = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs]; @@ -87,11 +69,48 @@ public: renderContext = nil; } + static void createAttribs (NSOpenGLPixelFormatAttribute* attribs, OpenGLVersion version, + const OpenGLPixelFormat& pixFormat, bool shouldUseMultisampling) + { + (void) version; + int numAttribs = 0; + + #if JUCE_OPENGL3 + 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 + + pixFormat.accumulationBufferBlueBits + pixFormat.accumulationBufferAlphaBits); + + if (shouldUseMultisampling) + { + attribs [numAttribs++] = NSOpenGLPFAMultisample; + attribs [numAttribs++] = NSOpenGLPFASampleBuffers; + attribs [numAttribs++] = (NSOpenGLPixelFormatAttribute) 1; + attribs [numAttribs++] = NSOpenGLPFASamples; + attribs [numAttribs++] = (NSOpenGLPixelFormatAttribute) pixFormat.multisamplingLevel; + } + } + void initialiseOnRenderThread (OpenGLContext&) {} void shutdownOnRenderThread() { deactivateCurrentContext(); } bool createdOk() const noexcept { return getRawContext() != nullptr; } - void* getRawContext() const noexcept { return static_cast (renderContext); } + void* getRawContext() const noexcept { return static_cast (renderContext); } GLuint getFrameBufferID() const noexcept { return 0; } bool makeActive() const noexcept @@ -197,9 +216,9 @@ public: int minSwapTimeMs, underrunCounter; //============================================================================== - struct MouseForwardingNSOpenGLViewClass : public ObjCClass + struct MouseForwardingNSOpenGLViewClass : public ObjCClass { - MouseForwardingNSOpenGLViewClass() : ObjCClass ("JUCEGLView_") + MouseForwardingNSOpenGLViewClass() : ObjCClass ("JUCEGLView_") { addMethod (@selector (rightMouseDown:), rightMouseDown, "v@:@"); addMethod (@selector (rightMouseUp:), rightMouseUp, "v@:@");