1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

OpenGL: Tidy up macOS implementation

This commit is contained in:
reuk 2022-10-05 19:45:31 +01:00
parent b2d999073c
commit d8301ddc1c
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C

View file

@ -38,10 +38,9 @@ public:
OpenGLVersion version)
: owner (component)
{
NSOpenGLPixelFormatAttribute attribs[64] = { 0 };
createAttribs (attribs, version, pixFormat, shouldUseMultisampling);
const auto attribs = createAttribs (version, pixFormat, shouldUseMultisampling);
NSOpenGLPixelFormat* format = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
NSOpenGLPixelFormat* format = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs.data()];
static MouseForwardingNSOpenGLViewClass cls;
view = [cls.createInstance() initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
@ -75,48 +74,47 @@ public:
[view release];
}
static void createAttribs (NSOpenGLPixelFormatAttribute* attribs, OpenGLVersion version,
const OpenGLPixelFormat& pixFormat, bool shouldUseMultisampling)
static std::vector<NSOpenGLPixelFormatAttribute> createAttribs (OpenGLVersion version,
const OpenGLPixelFormat& pixFormat,
bool shouldUseMultisampling)
{
ignoreUnused (version);
int numAttribs = 0;
attribs[numAttribs++] = NSOpenGLPFAOpenGLProfile;
attribs[numAttribs++] = [version]
std::vector<NSOpenGLPixelFormatAttribute> attribs
{
if (version == openGL3_2)
return NSOpenGLProfileVersion3_2Core;
NSOpenGLPFAOpenGLProfile, [version]
{
if (version == openGL3_2)
return NSOpenGLProfileVersion3_2Core;
if (version != defaultGLVersion)
if (@available (macOS 10.10, *))
return NSOpenGLProfileVersion4_1Core;
if (version != defaultGLVersion)
if (@available (macOS 10.10, *))
return NSOpenGLProfileVersion4_1Core;
return NSOpenGLProfileVersionLegacy;
}();
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);
return NSOpenGLProfileVersionLegacy;
}(),
NSOpenGLPFADoubleBuffer,
NSOpenGLPFAClosestPolicy,
NSOpenGLPFANoRecovery,
NSOpenGLPFAColorSize, static_cast<NSOpenGLPixelFormatAttribute> (pixFormat.redBits + pixFormat.greenBits + pixFormat.blueBits),
NSOpenGLPFAAlphaSize, static_cast<NSOpenGLPixelFormatAttribute> (pixFormat.alphaBits),
NSOpenGLPFADepthSize, static_cast<NSOpenGLPixelFormatAttribute> (pixFormat.depthBufferBits),
NSOpenGLPFAStencilSize, static_cast<NSOpenGLPixelFormatAttribute> (pixFormat.stencilBufferBits),
NSOpenGLPFAAccumSize, static_cast<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.insert (attribs.cend(),
{
NSOpenGLPFAMultisample,
NSOpenGLPFASampleBuffers, static_cast<NSOpenGLPixelFormatAttribute> (1),
NSOpenGLPFASamples, static_cast<NSOpenGLPixelFormatAttribute> (pixFormat.multisamplingLevel)
});
}
attribs.push_back (0);
return attribs;
}
InitResult initialiseOnRenderThread (OpenGLContext&) { return InitResult::success; }
@ -274,24 +272,17 @@ public:
//==============================================================================
struct MouseForwardingNSOpenGLViewClass : public ObjCClass<NSOpenGLView>
{
MouseForwardingNSOpenGLViewClass() : ObjCClass<NSOpenGLView> ("JUCEGLView_")
MouseForwardingNSOpenGLViewClass() : ObjCClass ("JUCEGLView_")
{
addMethod (@selector (rightMouseDown:), rightMouseDown);
addMethod (@selector (rightMouseUp:), rightMouseUp);
addMethod (@selector (acceptsFirstMouse:), acceptsFirstMouse);
addMethod (@selector (accessibilityHitTest:), accessibilityHitTest);
addMethod (@selector (rightMouseDown:), [] (id self, SEL, NSEvent* ev) { [[(NSOpenGLView*) self superview] rightMouseDown: ev]; });
addMethod (@selector (rightMouseUp:), [] (id self, SEL, NSEvent* ev) { [[(NSOpenGLView*) self superview] rightMouseUp: ev]; });
addMethod (@selector (acceptsFirstMouse:), [] (id, SEL, NSEvent*) -> BOOL { return YES; });
addMethod (@selector (accessibilityHitTest:), [] (id self, SEL, NSPoint p) -> id { return [[(NSOpenGLView*) self superview] accessibilityHitTest: p]; });
registerClass();
}
private:
static void rightMouseDown (id self, SEL, NSEvent* ev) { [[(NSOpenGLView*) self superview] rightMouseDown: ev]; }
static void rightMouseUp (id self, SEL, NSEvent* ev) { [[(NSOpenGLView*) self superview] rightMouseUp: ev]; }
static BOOL acceptsFirstMouse (id, SEL, NSEvent*) { return YES; }
static id accessibilityHitTest (id self, SEL, NSPoint p) { return [[(NSOpenGLView*) self superview] accessibilityHitTest: p]; }
};
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NativeContext)
};