34static void makeContextCurrentNSGL(
_GLFWwindow* window)
39 [window->context.nsgl.object makeCurrentContext];
41 [NSOpenGLContext clearCurrentContext];
54 if (window->ns.occluded)
57 [window->context.nsgl.object getValues:&interval
58 forParameter:NSOpenGLContextParameterSwapInterval];
62 const double framerate = 60.0;
66 const double elapsed = value / (double) frequency;
67 const double period = 1.0 / framerate;
68 const double delay = period - fmod(elapsed, period);
70 usleep(floorl(delay * 1e6));
74 [window->context.nsgl.object flushBuffer];
79static void swapIntervalNSGL(
int interval)
86 [window->context.nsgl.object setValues:&interval
87 forParameter:NSOpenGLContextParameterSwapInterval];
93static int extensionSupportedNSGL(
const char* extension)
99static GLFWglproc getProcAddressNSGL(
const char* procname)
101 CFStringRef symbolName = CFStringCreateWithCString(kCFAllocatorDefault,
103 kCFStringEncodingASCII);
105 GLFWglproc symbol = CFBundleGetFunctionPointerForName(
_glfw.nsgl.framework,
108 CFRelease(symbolName);
117 [window->context.nsgl.pixelFormat release];
118 window->
context.nsgl.pixelFormat = nil;
120 [window->context.nsgl.object release];
121 window->
context.nsgl.object = nil;
135 if (
_glfw.nsgl.framework)
138 _glfw.nsgl.framework =
139 CFBundleGetBundleWithIdentifier(CFSTR(
"com.apple.opengl"));
143 "NSGL: Failed to locate OpenGL framework");
165 "NSGL: OpenGL ES is not available on macOS");
169 if (ctxconfig->
major > 2)
171 if (ctxconfig->
major == 3 && ctxconfig->
minor < 2)
174 "NSGL: The targeted version of macOS does not support OpenGL 3.0 or 3.1 but may support 3.2 and above");
191#define addAttrib(a) \
193 assert((size_t) index < sizeof(attribs) / sizeof(attribs[0])); \
194 attribs[index++] = a; \
196#define setAttrib(a, v) { addAttrib(a); addAttrib(v); }
198 NSOpenGLPixelFormatAttribute attribs[40];
206 addAttrib(NSOpenGLPFAAllowOfflineRenderers);
211 addAttrib(kCGLPFASupportsAutomaticGraphicsSwitching);
214#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101000
215 if (ctxconfig->
major >= 4)
217 setAttrib(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion4_1Core);
221 if (ctxconfig->
major >= 3)
223 setAttrib(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core);
226 if (ctxconfig->
major <= 2)
241 setAttrib(NSOpenGLPFAAccumSize, accumBits);
249 int colorBits = fbconfig->
redBits +
256 else if (colorBits < 15)
259 setAttrib(NSOpenGLPFAColorSize, colorBits);
273#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101200
275 "NSGL: Stereo rendering is deprecated");
306 window->
context.nsgl.pixelFormat =
307 [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];
308 if (window->
context.nsgl.pixelFormat == nil)
311 "NSGL: Failed to find a suitable pixel format");
315 NSOpenGLContext* share = nil;
317 if (ctxconfig->
share)
321 [[NSOpenGLContext alloc] initWithFormat:window->context.nsgl.pixelFormat
323 if (window->
context.nsgl.object == nil)
326 "NSGL: Failed to create OpenGL context");
333 [window->context.nsgl.object setValues:&opaque
334 forParameter:NSOpenGLContextParameterSurfaceOpacity];
337 [window->ns.view setWantsBestResolutionOpenGLSurface:window->ns.retina];
339 [window->context.nsgl.object setView:window->ns.view];
367 return window->
context.nsgl.object;
uint64_t _glfwPlatformGetTimerValue(void)
uint64_t _glfwPlatformGetTimerFrequency(void)
#define GLFW_OPENGL_ES_API
void(* GLFWglproc)(void)
GLFW API types.
#define GLFW_FORMAT_UNAVAILABLE
The requested format is not supported or available.
#define GLFW_API_UNAVAILABLE
GLFW could not find support for the requested API on the system.
#define GLFW_NO_WINDOW_CONTEXT
The specified window does not have an OpenGL or OpenGL ES context.
#define GLFW_VERSION_UNAVAILABLE
The requested OpenGL or OpenGL ES version is not available.
struct GLFWwindow GLFWwindow
Opaque window object.
void _glfwInputError(int code, const char *format,...)
void _glfwPlatformSetTls(_GLFWtls *tls, void *value)
#define _GLFW_REQUIRE_INIT_OR_RETURN(x)
void * _glfwPlatformGetTls(_GLFWtls *tls)
GLFWbool _glfwCreateContextNSGL(_GLFWwindow *window, const _GLFWctxconfig *ctxconfig, const _GLFWfbconfig *fbconfig)
GLFWAPI id glfwGetNSGLContext(GLFWwindow *handle)
GLFWbool _glfwInitNSGL(void)
void _glfwTerminateNSGL(void)
unsigned __int64 uint64_t
_GLFWswapintervalfun swapInterval
_GLFWswapbuffersfun swapBuffers
_GLFWdestroycontextfun destroy
_GLFWmakecontextcurrentfun makeCurrent
_GLFWextensionsupportedfun extensionSupported
_GLFWgetprocaddressfun getProcAddress
struct _GLFWctxconfig::@21 nsgl