Cocoa: Change pixel format initialization to CGL

This commit is contained in:
Konstantin Käfer 2017-01-25 12:14:08 +01:00
parent 5a11d19940
commit 70f8d1fd3d
2 changed files with 33 additions and 23 deletions

View File

@ -341,12 +341,13 @@ if (_GLFW_COCOA)
list(APPEND glfw_LIBRARIES
"-framework Cocoa"
"-framework OpenGL"
"-framework IOKit"
"-framework CoreFoundation"
"-framework CoreVideo")
set(glfw_PKG_DEPS "")
set(glfw_PKG_LIBS "-framework Cocoa -framework IOKit -framework CoreFoundation -framework CoreVideo")
set(glfw_PKG_LIBS "-framework Cocoa -framework OpenGL -framework IOKit -framework CoreFoundation -framework CoreVideo")
endif()
#--------------------------------------------------------------------

View File

@ -152,30 +152,30 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window,
// supported on macOS but are not a hard constraint, so ignore and continue
#define ADD_ATTR(x) { attributes[attributeCount++] = x; }
#define ADD_ATTR2(x, y) { ADD_ATTR(x); ADD_ATTR(y); }
#define ADD_ATTR2(x, y) { ADD_ATTR(x); ADD_ATTR((CGLPixelFormatAttribute)y); }
// Arbitrary array size here
NSOpenGLPixelFormatAttribute attributes[40];
CGLPixelFormatAttribute attributes[40];
ADD_ATTR(NSOpenGLPFAAccelerated);
ADD_ATTR(NSOpenGLPFAClosestPolicy);
ADD_ATTR(kCGLPFAAccelerated);
ADD_ATTR(kCGLPFAClosestPolicy);
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101000
if (ctxconfig->major >= 4)
{
ADD_ATTR2(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion4_1Core);
ADD_ATTR2(kCGLPFAOpenGLProfile, kCGLOGLPVersion_GL4_Core);
}
else
#endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/
if (ctxconfig->major >= 3)
{
ADD_ATTR2(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core);
ADD_ATTR2(kCGLPFAOpenGLProfile, kCGLOGLPVersion_GL3_Core);
}
if (ctxconfig->major <= 2)
{
if (fbconfig->auxBuffers != GLFW_DONT_CARE)
ADD_ATTR2(NSOpenGLPFAAuxBuffers, fbconfig->auxBuffers);
ADD_ATTR2(kCGLPFAAuxBuffers, fbconfig->auxBuffers);
if (fbconfig->accumRedBits != GLFW_DONT_CARE &&
fbconfig->accumGreenBits != GLFW_DONT_CARE &&
@ -187,7 +187,7 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window,
fbconfig->accumBlueBits +
fbconfig->accumAlphaBits;
ADD_ATTR2(NSOpenGLPFAAccumSize, accumBits);
ADD_ATTR2(kCGLPFAAccumSize, accumBits);
}
}
@ -205,17 +205,17 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window,
else if (colorBits < 15)
colorBits = 15;
ADD_ATTR2(NSOpenGLPFAColorSize, colorBits);
ADD_ATTR2(kCGLPFAColorSize, colorBits);
}
if (fbconfig->alphaBits != GLFW_DONT_CARE)
ADD_ATTR2(NSOpenGLPFAAlphaSize, fbconfig->alphaBits);
ADD_ATTR2(kCGLPFAAlphaSize, fbconfig->alphaBits);
if (fbconfig->depthBits != GLFW_DONT_CARE)
ADD_ATTR2(NSOpenGLPFADepthSize, fbconfig->depthBits);
ADD_ATTR2(kCGLPFADepthSize, fbconfig->depthBits);
if (fbconfig->stencilBits != GLFW_DONT_CARE)
ADD_ATTR2(NSOpenGLPFAStencilSize, fbconfig->stencilBits);
ADD_ATTR2(kCGLPFAStencilSize, fbconfig->stencilBits);
if (fbconfig->stereo)
{
@ -224,27 +224,27 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window,
"NSGL: Stereo rendering is deprecated");
return GLFW_FALSE;
#else
ADD_ATTR(NSOpenGLPFAStereo);
ADD_ATTR(kCGLPFAStereo);
#endif
}
if (fbconfig->doublebuffer)
ADD_ATTR(NSOpenGLPFADoubleBuffer);
ADD_ATTR(kCGLPFADoubleBuffer);
if (fbconfig->samples != GLFW_DONT_CARE)
{
if (fbconfig->samples == 0)
{
ADD_ATTR2(NSOpenGLPFASampleBuffers, 0);
ADD_ATTR2(kCGLPFASampleBuffers, 0);
}
else
{
ADD_ATTR2(NSOpenGLPFASampleBuffers, 1);
ADD_ATTR2(NSOpenGLPFASamples, fbconfig->samples);
ADD_ATTR2(kCGLPFASampleBuffers, 1);
ADD_ATTR2(kCGLPFASamples, fbconfig->samples);
}
}
// NOTE: All NSOpenGLPixelFormats on the relevant cards support sRGB
// NOTE: All CGLPixelFormats on the relevant cards support sRGB
// framebuffer, so there's no need (and no way) to request it
ADD_ATTR(0);
@ -252,15 +252,24 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window,
#undef ADD_ATTR
#undef ADD_ATTR2
window->context.nsgl.pixelFormat =
[[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
if (window->context.nsgl.pixelFormat == nil)
{
CGLPixelFormatObj pixelFormat = NULL;
GLint num;
CGLError error = CGLChoosePixelFormat(attributes, &pixelFormat, &num);
if (error != kCGLNoError) {
_glfwInputError(GLFW_FORMAT_UNAVAILABLE,
"NSGL: Error choosing pixel format: %s", CGLErrorString(error));
return GLFW_FALSE;
}
if (pixelFormat == NULL || num <= 0) {
_glfwInputError(GLFW_FORMAT_UNAVAILABLE,
"NSGL: Failed to find a suitable pixel format");
return GLFW_FALSE;
}
window->context.nsgl.pixelFormat =
[[NSOpenGLPixelFormat alloc] initWithCGLPixelFormatObj:pixelFormat];
CGLReleasePixelFormat(pixelFormat);
NSOpenGLContext* share = NULL;
if (ctxconfig->share)