Browse Source

Tweaked the OSX openGL context to hopefully fix problems enabling multisampling mode.

tags/2021-05-28
jules 11 years ago
parent
commit
f146765b14
1 changed files with 43 additions and 24 deletions
  1. +43
    -24
      modules/juce_opengl/native/juce_OpenGL_osx.h

+ 43
- 24
modules/juce_opengl/native/juce_OpenGL_osx.h View File

@@ -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 <void*> (renderContext); }
void* getRawContext() const noexcept { return static_cast<void*> (renderContext); }
GLuint getFrameBufferID() const noexcept { return 0; }
bool makeActive() const noexcept
@@ -197,9 +216,9 @@ public:
int minSwapTimeMs, underrunCounter;
//==============================================================================
struct MouseForwardingNSOpenGLViewClass : public ObjCClass <NSOpenGLView>
struct MouseForwardingNSOpenGLViewClass : public ObjCClass<NSOpenGLView>
{
MouseForwardingNSOpenGLViewClass() : ObjCClass <NSOpenGLView> ("JUCEGLView_")
MouseForwardingNSOpenGLViewClass() : ObjCClass<NSOpenGLView> ("JUCEGLView_")
{
addMethod (@selector (rightMouseDown:), rightMouseDown, "v@:@");
addMethod (@selector (rightMouseUp:), rightMouseUp, "v@:@");


Loading…
Cancel
Save