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