2010-09-07 15:34:51 +00:00
|
|
|
//========================================================================
|
2019-04-16 12:43:29 +00:00
|
|
|
// GLFW 3.4 macOS - www.glfw.org
|
2010-09-07 15:34:51 +00:00
|
|
|
//------------------------------------------------------------------------
|
2019-04-15 18:50:00 +00:00
|
|
|
// Copyright (c) 2009-2019 Camilla Löwy <elmindreda@glfw.org>
|
2010-09-07 15:34:51 +00:00
|
|
|
//
|
|
|
|
// This software is provided 'as-is', without any express or implied
|
|
|
|
// warranty. In no event will the authors be held liable for any damages
|
|
|
|
// arising from the use of this software.
|
|
|
|
//
|
|
|
|
// Permission is granted to anyone to use this software for any purpose,
|
|
|
|
// including commercial applications, and to alter it and redistribute it
|
|
|
|
// freely, subject to the following restrictions:
|
|
|
|
//
|
|
|
|
// 1. The origin of this software must not be misrepresented; you must not
|
|
|
|
// claim that you wrote the original software. If you use this software
|
|
|
|
// in a product, an acknowledgment in the product documentation would
|
|
|
|
// be appreciated but is not required.
|
|
|
|
//
|
|
|
|
// 2. Altered source versions must be plainly marked as such, and must not
|
|
|
|
// be misrepresented as being the original software.
|
|
|
|
//
|
|
|
|
// 3. This notice may not be removed or altered from any source
|
|
|
|
// distribution.
|
|
|
|
//
|
|
|
|
//========================================================================
|
2019-05-20 13:24:14 +00:00
|
|
|
// It is fine to use C99 in this file because it will not be built with VS
|
|
|
|
//========================================================================
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
#include "internal.h"
|
|
|
|
|
2021-11-09 18:44:00 +00:00
|
|
|
#if defined(_GLFW_COCOA)
|
|
|
|
|
2019-11-10 18:09:23 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
2016-06-14 10:27:19 +00:00
|
|
|
static void makeContextCurrentNSGL(_GLFWwindow* window)
|
2016-03-28 11:19:31 +00:00
|
|
|
{
|
2019-03-05 18:05:57 +00:00
|
|
|
@autoreleasepool {
|
|
|
|
|
2016-03-28 11:19:31 +00:00
|
|
|
if (window)
|
|
|
|
[window->context.nsgl.object makeCurrentContext];
|
|
|
|
else
|
|
|
|
[NSOpenGLContext clearCurrentContext];
|
|
|
|
|
2017-05-25 16:23:09 +00:00
|
|
|
_glfwPlatformSetTls(&_glfw.contextSlot, window);
|
2019-03-05 18:05:57 +00:00
|
|
|
|
|
|
|
} // autoreleasepool
|
2016-03-28 11:19:31 +00:00
|
|
|
}
|
|
|
|
|
2016-06-14 10:27:19 +00:00
|
|
|
static void swapBuffersNSGL(_GLFWwindow* window)
|
2016-03-28 11:19:31 +00:00
|
|
|
{
|
2019-03-05 18:05:57 +00:00
|
|
|
@autoreleasepool {
|
2019-11-10 18:09:23 +00:00
|
|
|
|
|
|
|
// HACK: Simulate vsync with usleep as NSGL swap interval does not apply to
|
|
|
|
// windows with a non-visible occlusion state
|
2020-04-30 20:12:21 +00:00
|
|
|
if (window->ns.occluded)
|
2019-11-10 18:09:23 +00:00
|
|
|
{
|
|
|
|
int interval = 0;
|
|
|
|
[window->context.nsgl.object getValues:&interval
|
|
|
|
forParameter:NSOpenGLContextParameterSwapInterval];
|
|
|
|
|
|
|
|
if (interval > 0)
|
|
|
|
{
|
|
|
|
const double framerate = 60.0;
|
|
|
|
const uint64_t frequency = _glfwPlatformGetTimerFrequency();
|
|
|
|
const uint64_t value = _glfwPlatformGetTimerValue();
|
|
|
|
|
|
|
|
const double elapsed = value / (double) frequency;
|
|
|
|
const double period = 1.0 / framerate;
|
|
|
|
const double delay = period - fmod(elapsed, period);
|
|
|
|
|
|
|
|
usleep(floorl(delay * 1e6));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-28 11:19:31 +00:00
|
|
|
[window->context.nsgl.object flushBuffer];
|
2019-11-10 18:09:23 +00:00
|
|
|
|
2019-03-05 18:05:57 +00:00
|
|
|
} // autoreleasepool
|
2016-03-28 11:19:31 +00:00
|
|
|
}
|
|
|
|
|
2016-06-14 10:27:19 +00:00
|
|
|
static void swapIntervalNSGL(int interval)
|
2016-03-28 11:19:31 +00:00
|
|
|
{
|
2019-03-05 18:05:57 +00:00
|
|
|
@autoreleasepool {
|
2019-11-07 14:13:49 +00:00
|
|
|
|
2019-11-10 18:09:23 +00:00
|
|
|
_GLFWwindow* window = _glfwPlatformGetTls(&_glfw.contextSlot);
|
|
|
|
if (window)
|
2019-11-07 14:13:49 +00:00
|
|
|
{
|
2019-11-10 18:09:23 +00:00
|
|
|
[window->context.nsgl.object setValues:&interval
|
|
|
|
forParameter:NSOpenGLContextParameterSwapInterval];
|
2019-11-07 14:13:49 +00:00
|
|
|
}
|
|
|
|
|
2019-03-05 18:05:57 +00:00
|
|
|
} // autoreleasepool
|
2016-03-28 11:19:31 +00:00
|
|
|
}
|
|
|
|
|
2016-06-14 10:27:19 +00:00
|
|
|
static int extensionSupportedNSGL(const char* extension)
|
2016-03-28 11:19:31 +00:00
|
|
|
{
|
|
|
|
// There are no NSGL extensions
|
|
|
|
return GLFW_FALSE;
|
|
|
|
}
|
|
|
|
|
2016-06-14 10:27:19 +00:00
|
|
|
static GLFWglproc getProcAddressNSGL(const char* procname)
|
2016-03-28 11:19:31 +00:00
|
|
|
{
|
|
|
|
CFStringRef symbolName = CFStringCreateWithCString(kCFAllocatorDefault,
|
|
|
|
procname,
|
|
|
|
kCFStringEncodingASCII);
|
|
|
|
|
|
|
|
GLFWglproc symbol = CFBundleGetFunctionPointerForName(_glfw.nsgl.framework,
|
|
|
|
symbolName);
|
|
|
|
|
|
|
|
CFRelease(symbolName);
|
|
|
|
|
|
|
|
return symbol;
|
|
|
|
}
|
|
|
|
|
2016-06-14 10:27:19 +00:00
|
|
|
static void destroyContextNSGL(_GLFWwindow* window)
|
2016-03-28 11:19:31 +00:00
|
|
|
{
|
2019-03-05 18:05:57 +00:00
|
|
|
@autoreleasepool {
|
|
|
|
|
2016-03-28 11:19:31 +00:00
|
|
|
[window->context.nsgl.pixelFormat release];
|
|
|
|
window->context.nsgl.pixelFormat = nil;
|
|
|
|
|
|
|
|
[window->context.nsgl.object release];
|
|
|
|
window->context.nsgl.object = nil;
|
2019-03-05 18:05:57 +00:00
|
|
|
|
|
|
|
} // autoreleasepool
|
2016-03-28 11:19:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-16 01:25:36 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-12-29 23:45:22 +00:00
|
|
|
////// GLFW internal API //////
|
2010-09-16 01:25:36 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2012-08-13 14:03:44 +00:00
|
|
|
// Initialize OpenGL support
|
2013-02-04 12:22:10 +00:00
|
|
|
//
|
2015-12-10 16:10:05 +00:00
|
|
|
GLFWbool _glfwInitNSGL(void)
|
2012-08-13 14:03:44 +00:00
|
|
|
{
|
2016-07-20 10:52:06 +00:00
|
|
|
if (_glfw.nsgl.framework)
|
|
|
|
return GLFW_TRUE;
|
|
|
|
|
2013-05-02 20:41:09 +00:00
|
|
|
_glfw.nsgl.framework =
|
|
|
|
CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl"));
|
|
|
|
if (_glfw.nsgl.framework == NULL)
|
|
|
|
{
|
2015-03-10 18:51:14 +00:00
|
|
|
_glfwInputError(GLFW_API_UNAVAILABLE,
|
2013-05-02 20:41:09 +00:00
|
|
|
"NSGL: Failed to locate OpenGL framework");
|
2015-08-23 17:30:04 +00:00
|
|
|
return GLFW_FALSE;
|
2013-05-02 20:41:09 +00:00
|
|
|
}
|
|
|
|
|
2015-08-23 17:30:04 +00:00
|
|
|
return GLFW_TRUE;
|
2012-08-13 14:03:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Terminate OpenGL support
|
2013-02-04 12:22:10 +00:00
|
|
|
//
|
2015-12-03 17:16:46 +00:00
|
|
|
void _glfwTerminateNSGL(void)
|
2012-08-13 14:03:44 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-12-29 23:58:18 +00:00
|
|
|
// Create the OpenGL context
|
2013-02-04 12:22:10 +00:00
|
|
|
//
|
2015-12-10 16:10:05 +00:00
|
|
|
GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window,
|
|
|
|
const _GLFWctxconfig* ctxconfig,
|
|
|
|
const _GLFWfbconfig* fbconfig)
|
2012-12-29 23:58:18 +00:00
|
|
|
{
|
2016-03-28 11:19:31 +00:00
|
|
|
if (ctxconfig->client == GLFW_OPENGL_ES_API)
|
2012-12-29 23:58:18 +00:00
|
|
|
{
|
2015-08-09 11:37:27 +00:00
|
|
|
_glfwInputError(GLFW_API_UNAVAILABLE,
|
2016-10-19 22:50:54 +00:00
|
|
|
"NSGL: OpenGL ES is not available on macOS");
|
2015-08-23 17:30:04 +00:00
|
|
|
return GLFW_FALSE;
|
2012-12-29 23:58:18 +00:00
|
|
|
}
|
|
|
|
|
2014-03-06 19:05:32 +00:00
|
|
|
if (ctxconfig->major > 2)
|
2012-12-29 23:58:18 +00:00
|
|
|
{
|
2016-12-03 18:32:00 +00:00
|
|
|
if (ctxconfig->major == 3 && ctxconfig->minor < 2)
|
2012-12-29 23:58:18 +00:00
|
|
|
{
|
2012-12-31 20:05:28 +00:00
|
|
|
_glfwInputError(GLFW_VERSION_UNAVAILABLE,
|
2016-12-06 12:58:16 +00:00
|
|
|
"NSGL: The targeted version of macOS does not support OpenGL 3.0 or 3.1 but may support 3.2 and above");
|
2015-08-23 17:30:04 +00:00
|
|
|
return GLFW_FALSE;
|
2012-12-29 23:58:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-08 13:44:07 +00:00
|
|
|
// Context robustness modes (GL_KHR_robustness) are not yet supported by
|
2016-10-19 22:50:54 +00:00
|
|
|
// macOS but are not a hard constraint, so ignore and continue
|
2012-12-29 23:58:18 +00:00
|
|
|
|
2014-08-21 17:21:45 +00:00
|
|
|
// Context release behaviors (GL_KHR_context_flush_control) are not yet
|
2017-06-08 13:44:07 +00:00
|
|
|
// supported by macOS but are not a hard constraint, so ignore and continue
|
|
|
|
|
|
|
|
// Debug contexts (GL_KHR_debug) are not yet supported by macOS but are not
|
|
|
|
// a hard constraint, so ignore and continue
|
|
|
|
|
|
|
|
// No-error contexts (GL_KHR_no_error) are not yet supported by macOS but
|
|
|
|
// are not a hard constraint, so ignore and continue
|
2014-08-21 17:21:45 +00:00
|
|
|
|
2022-01-07 10:51:12 +00:00
|
|
|
#define ADD_ATTRIB(a) \
|
2017-06-08 13:52:55 +00:00
|
|
|
{ \
|
|
|
|
assert((size_t) index < sizeof(attribs) / sizeof(attribs[0])); \
|
|
|
|
attribs[index++] = a; \
|
|
|
|
}
|
2022-01-07 10:51:12 +00:00
|
|
|
#define SET_ATTRIB(a, v) { ADD_ATTRIB(a); ADD_ATTRIB(v); }
|
2012-12-29 23:58:18 +00:00
|
|
|
|
2017-06-08 13:52:55 +00:00
|
|
|
NSOpenGLPixelFormatAttribute attribs[40];
|
|
|
|
int index = 0;
|
2012-12-29 23:58:18 +00:00
|
|
|
|
2022-01-07 10:51:12 +00:00
|
|
|
ADD_ATTRIB(NSOpenGLPFAAccelerated);
|
|
|
|
ADD_ATTRIB(NSOpenGLPFAClosestPolicy);
|
2012-12-29 23:58:18 +00:00
|
|
|
|
2017-01-27 11:02:09 +00:00
|
|
|
if (ctxconfig->nsgl.offline)
|
|
|
|
{
|
2022-01-07 10:51:12 +00:00
|
|
|
ADD_ATTRIB(NSOpenGLPFAAllowOfflineRenderers);
|
2017-01-27 11:02:09 +00:00
|
|
|
// NOTE: This replaces the NSSupportsAutomaticGraphicsSwitching key in
|
|
|
|
// Info.plist for unbundled applications
|
|
|
|
// HACK: This assumes that NSOpenGLPixelFormat will remain
|
|
|
|
// a straightforward wrapper of its CGL counterpart
|
2022-01-07 10:51:12 +00:00
|
|
|
ADD_ATTRIB(kCGLPFASupportsAutomaticGraphicsSwitching);
|
2017-01-27 11:02:09 +00:00
|
|
|
}
|
|
|
|
|
2014-12-27 21:28:13 +00:00
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101000
|
|
|
|
if (ctxconfig->major >= 4)
|
2014-11-04 23:33:43 +00:00
|
|
|
{
|
2022-01-07 10:51:12 +00:00
|
|
|
SET_ATTRIB(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion4_1Core);
|
2014-11-04 23:33:43 +00:00
|
|
|
}
|
|
|
|
else
|
2012-12-29 23:58:18 +00:00
|
|
|
#endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/
|
2014-12-27 21:28:13 +00:00
|
|
|
if (ctxconfig->major >= 3)
|
|
|
|
{
|
2022-01-07 10:51:12 +00:00
|
|
|
SET_ATTRIB(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core);
|
2014-12-27 21:28:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ctxconfig->major <= 2)
|
2014-11-04 23:33:43 +00:00
|
|
|
{
|
|
|
|
if (fbconfig->auxBuffers != GLFW_DONT_CARE)
|
2022-01-07 10:51:12 +00:00
|
|
|
SET_ATTRIB(NSOpenGLPFAAuxBuffers, fbconfig->auxBuffers);
|
2014-11-04 23:33:43 +00:00
|
|
|
|
|
|
|
if (fbconfig->accumRedBits != GLFW_DONT_CARE &&
|
|
|
|
fbconfig->accumGreenBits != GLFW_DONT_CARE &&
|
|
|
|
fbconfig->accumBlueBits != GLFW_DONT_CARE &&
|
|
|
|
fbconfig->accumAlphaBits != GLFW_DONT_CARE)
|
|
|
|
{
|
|
|
|
const int accumBits = fbconfig->accumRedBits +
|
|
|
|
fbconfig->accumGreenBits +
|
|
|
|
fbconfig->accumBlueBits +
|
|
|
|
fbconfig->accumAlphaBits;
|
|
|
|
|
2022-01-07 10:51:12 +00:00
|
|
|
SET_ATTRIB(NSOpenGLPFAAccumSize, accumBits);
|
2014-11-04 23:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
2012-12-29 23:58:18 +00:00
|
|
|
|
2014-04-08 16:57:43 +00:00
|
|
|
if (fbconfig->redBits != GLFW_DONT_CARE &&
|
|
|
|
fbconfig->greenBits != GLFW_DONT_CARE &&
|
|
|
|
fbconfig->blueBits != GLFW_DONT_CARE)
|
|
|
|
{
|
|
|
|
int colorBits = fbconfig->redBits +
|
|
|
|
fbconfig->greenBits +
|
|
|
|
fbconfig->blueBits;
|
|
|
|
|
2016-10-19 22:50:54 +00:00
|
|
|
// macOS needs non-zero color size, so set reasonable values
|
2014-04-08 16:57:43 +00:00
|
|
|
if (colorBits == 0)
|
|
|
|
colorBits = 24;
|
|
|
|
else if (colorBits < 15)
|
|
|
|
colorBits = 15;
|
2012-12-29 23:58:18 +00:00
|
|
|
|
2022-01-07 10:51:12 +00:00
|
|
|
SET_ATTRIB(NSOpenGLPFAColorSize, colorBits);
|
2014-04-08 16:57:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fbconfig->alphaBits != GLFW_DONT_CARE)
|
2022-01-07 10:51:12 +00:00
|
|
|
SET_ATTRIB(NSOpenGLPFAAlphaSize, fbconfig->alphaBits);
|
2012-12-29 23:58:18 +00:00
|
|
|
|
2014-04-08 16:57:43 +00:00
|
|
|
if (fbconfig->depthBits != GLFW_DONT_CARE)
|
2022-01-07 10:51:12 +00:00
|
|
|
SET_ATTRIB(NSOpenGLPFADepthSize, fbconfig->depthBits);
|
2012-12-29 23:58:18 +00:00
|
|
|
|
2014-04-08 16:57:43 +00:00
|
|
|
if (fbconfig->stencilBits != GLFW_DONT_CARE)
|
2022-01-07 10:51:12 +00:00
|
|
|
SET_ATTRIB(NSOpenGLPFAStencilSize, fbconfig->stencilBits);
|
2012-12-29 23:58:18 +00:00
|
|
|
|
|
|
|
if (fbconfig->stereo)
|
2016-10-08 23:39:31 +00:00
|
|
|
{
|
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101200
|
|
|
|
_glfwInputError(GLFW_FORMAT_UNAVAILABLE,
|
|
|
|
"NSGL: Stereo rendering is deprecated");
|
|
|
|
return GLFW_FALSE;
|
|
|
|
#else
|
2022-01-07 10:51:12 +00:00
|
|
|
ADD_ATTRIB(NSOpenGLPFAStereo);
|
2016-10-08 23:39:31 +00:00
|
|
|
#endif
|
|
|
|
}
|
2012-12-29 23:58:18 +00:00
|
|
|
|
2014-04-24 17:21:10 +00:00
|
|
|
if (fbconfig->doublebuffer)
|
2022-01-07 10:51:12 +00:00
|
|
|
ADD_ATTRIB(NSOpenGLPFADoubleBuffer);
|
2014-04-24 17:21:10 +00:00
|
|
|
|
2014-04-08 16:57:43 +00:00
|
|
|
if (fbconfig->samples != GLFW_DONT_CARE)
|
2012-12-29 23:58:18 +00:00
|
|
|
{
|
2014-04-08 16:57:43 +00:00
|
|
|
if (fbconfig->samples == 0)
|
|
|
|
{
|
2022-01-07 10:51:12 +00:00
|
|
|
SET_ATTRIB(NSOpenGLPFASampleBuffers, 0);
|
2014-04-08 16:57:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-07 10:51:12 +00:00
|
|
|
SET_ATTRIB(NSOpenGLPFASampleBuffers, 1);
|
|
|
|
SET_ATTRIB(NSOpenGLPFASamples, fbconfig->samples);
|
2014-04-08 16:57:43 +00:00
|
|
|
}
|
2012-12-29 23:58:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: All NSOpenGLPixelFormats on the relevant cards support sRGB
|
2015-01-05 20:55:15 +00:00
|
|
|
// framebuffer, so there's no need (and no way) to request it
|
2012-12-29 23:58:18 +00:00
|
|
|
|
2022-01-07 10:51:12 +00:00
|
|
|
ADD_ATTRIB(0);
|
2012-12-29 23:58:18 +00:00
|
|
|
|
2022-01-07 10:51:12 +00:00
|
|
|
#undef ADD_ATTRIB
|
|
|
|
#undef SET_ATTRIB
|
2012-12-29 23:58:18 +00:00
|
|
|
|
2015-11-09 15:48:55 +00:00
|
|
|
window->context.nsgl.pixelFormat =
|
2017-06-08 13:52:55 +00:00
|
|
|
[[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];
|
2015-11-09 15:48:55 +00:00
|
|
|
if (window->context.nsgl.pixelFormat == nil)
|
2012-12-29 23:58:18 +00:00
|
|
|
{
|
2015-09-16 14:24:21 +00:00
|
|
|
_glfwInputError(GLFW_FORMAT_UNAVAILABLE,
|
|
|
|
"NSGL: Failed to find a suitable pixel format");
|
2015-08-23 17:30:04 +00:00
|
|
|
return GLFW_FALSE;
|
2012-12-29 23:58:18 +00:00
|
|
|
}
|
|
|
|
|
2019-11-07 12:45:15 +00:00
|
|
|
NSOpenGLContext* share = nil;
|
2012-12-29 23:58:18 +00:00
|
|
|
|
2014-03-06 19:05:32 +00:00
|
|
|
if (ctxconfig->share)
|
2015-11-09 15:48:55 +00:00
|
|
|
share = ctxconfig->share->context.nsgl.object;
|
2012-12-29 23:58:18 +00:00
|
|
|
|
2015-11-09 15:48:55 +00:00
|
|
|
window->context.nsgl.object =
|
|
|
|
[[NSOpenGLContext alloc] initWithFormat:window->context.nsgl.pixelFormat
|
2012-12-29 23:58:18 +00:00
|
|
|
shareContext:share];
|
2015-11-09 15:48:55 +00:00
|
|
|
if (window->context.nsgl.object == nil)
|
2012-12-29 23:58:18 +00:00
|
|
|
{
|
2015-03-10 18:51:14 +00:00
|
|
|
_glfwInputError(GLFW_VERSION_UNAVAILABLE,
|
2013-08-26 20:48:07 +00:00
|
|
|
"NSGL: Failed to create OpenGL context");
|
2015-08-23 17:30:04 +00:00
|
|
|
return GLFW_FALSE;
|
2012-12-29 23:58:18 +00:00
|
|
|
}
|
|
|
|
|
2017-09-19 16:27:45 +00:00
|
|
|
if (fbconfig->transparent)
|
2015-12-16 21:28:20 +00:00
|
|
|
{
|
|
|
|
GLint opaque = 0;
|
2018-10-26 10:56:02 +00:00
|
|
|
[window->context.nsgl.object setValues:&opaque
|
|
|
|
forParameter:NSOpenGLContextParameterSurfaceOpacity];
|
2015-12-16 21:28:20 +00:00
|
|
|
}
|
|
|
|
|
2019-12-09 17:53:29 +00:00
|
|
|
[window->ns.view setWantsBestResolutionOpenGLSurface:window->ns.retina];
|
2019-03-27 16:07:44 +00:00
|
|
|
|
2015-11-09 15:48:55 +00:00
|
|
|
[window->context.nsgl.object setView:window->ns.view];
|
2012-12-29 23:58:18 +00:00
|
|
|
|
2016-06-14 10:27:19 +00:00
|
|
|
window->context.makeCurrent = makeContextCurrentNSGL;
|
|
|
|
window->context.swapBuffers = swapBuffersNSGL;
|
|
|
|
window->context.swapInterval = swapIntervalNSGL;
|
|
|
|
window->context.extensionSupported = extensionSupportedNSGL;
|
|
|
|
window->context.getProcAddress = getProcAddressNSGL;
|
|
|
|
window->context.destroy = destroyContextNSGL;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2016-03-28 11:19:31 +00:00
|
|
|
return GLFW_TRUE;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2013-01-15 21:38:14 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW native API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
GLFWAPI id glfwGetNSGLContext(GLFWwindow* handle)
|
|
|
|
{
|
|
|
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
2013-02-19 23:28:08 +00:00
|
|
|
_GLFW_REQUIRE_INIT_OR_RETURN(nil);
|
2015-06-18 12:03:02 +00:00
|
|
|
|
2021-07-13 19:50:09 +00:00
|
|
|
if (_glfw.platform.platformID != GLFW_PLATFORM_COCOA)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_UNAVAILABLE,
|
|
|
|
"NSGL: Platform not initialized");
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2021-10-23 13:17:33 +00:00
|
|
|
if (window->context.source != GLFW_NATIVE_CONTEXT_API)
|
2015-06-18 12:03:02 +00:00
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL);
|
2019-11-07 12:45:15 +00:00
|
|
|
return nil;
|
2015-06-18 12:03:02 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 15:48:55 +00:00
|
|
|
return window->context.nsgl.object;
|
2013-01-15 21:38:14 +00:00
|
|
|
}
|
|
|
|
|
2021-11-09 18:44:00 +00:00
|
|
|
#endif // _GLFW_COCOA
|
|
|
|
|