This commit is contained in:
Konstantin Käfer 2017-06-07 18:13:23 +00:00 committed by GitHub
commit d28ca5e4f1
5 changed files with 46 additions and 23 deletions

View File

@ -332,12 +332,13 @@ if (_GLFW_COCOA)
list(APPEND glfw_LIBRARIES list(APPEND glfw_LIBRARIES
"-framework Cocoa" "-framework Cocoa"
"-framework OpenGL"
"-framework IOKit" "-framework IOKit"
"-framework CoreFoundation" "-framework CoreFoundation"
"-framework CoreVideo") "-framework CoreVideo")
set(glfw_PKG_DEPS "") 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() endif()
#-------------------------------------------------------------------- #--------------------------------------------------------------------

View File

@ -833,6 +833,11 @@ extern "C" {
* Framebuffer double buffering [hint](@ref GLFW_DOUBLEBUFFER). * Framebuffer double buffering [hint](@ref GLFW_DOUBLEBUFFER).
*/ */
#define GLFW_DOUBLEBUFFER 0x00021010 #define GLFW_DOUBLEBUFFER 0x00021010
/*! @brief Graphics switching hint.
*
* Graphics switching [hint](@ref GLFW_ALLOW_GRAPHICS_SWITCHING).
*/
#define GLFW_ALLOW_GRAPHICS_SWITCHING 0x00021011
/*! @brief Context client API hint and attribute. /*! @brief Context client API hint and attribute.
* *
* Context client API [hint](@ref GLFW_CLIENT_API_hint) and * Context client API [hint](@ref GLFW_CLIENT_API_hint) and

View File

@ -344,6 +344,7 @@ struct _GLFWfbconfig
int samples; int samples;
GLFWbool sRGB; GLFWbool sRGB;
GLFWbool doublebuffer; GLFWbool doublebuffer;
GLFWbool graphicsSwitching;
uintptr_t handle; uintptr_t handle;
}; };

View File

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

View File

@ -262,6 +262,7 @@ void glfwDefaultWindowHints(void)
_glfw.hints.framebuffer.depthBits = 24; _glfw.hints.framebuffer.depthBits = 24;
_glfw.hints.framebuffer.stencilBits = 8; _glfw.hints.framebuffer.stencilBits = 8;
_glfw.hints.framebuffer.doublebuffer = GLFW_TRUE; _glfw.hints.framebuffer.doublebuffer = GLFW_TRUE;
_glfw.hints.framebuffer.graphicsSwitching = GLFW_FALSE;
// The default is to select the highest available refresh rate // The default is to select the highest available refresh rate
_glfw.hints.refreshRate = GLFW_DONT_CARE; _glfw.hints.refreshRate = GLFW_DONT_CARE;
@ -315,6 +316,9 @@ GLFWAPI void glfwWindowHint(int hint, int value)
case GLFW_DOUBLEBUFFER: case GLFW_DOUBLEBUFFER:
_glfw.hints.framebuffer.doublebuffer = value ? GLFW_TRUE : GLFW_FALSE; _glfw.hints.framebuffer.doublebuffer = value ? GLFW_TRUE : GLFW_FALSE;
break; break;
case GLFW_ALLOW_GRAPHICS_SWITCHING:
_glfw.hints.framebuffer.graphicsSwitching = value ? GLFW_TRUE : GLFW_FALSE;
break;
case GLFW_SAMPLES: case GLFW_SAMPLES:
_glfw.hints.framebuffer.samples = value; _glfw.hints.framebuffer.samples = value;
break; break;