21#include "../../SDL_internal.h"
25#if SDL_VIDEO_OPENGL_CGL
30#include <OpenGL/CGLTypes.h>
31#include <OpenGL/OpenGL.h>
32#include <OpenGL/CGLRenderers.h>
37#define DEFAULT_OPENGL "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib"
41#pragma clang diagnostic push
42#pragma clang diagnostic ignored "-Wdeprecated-declarations"
45@implementation SDLOpenGLContext : NSOpenGLContext
47- (
id)initWithFormat:(NSOpenGLPixelFormat *)format
48 shareContext:(NSOpenGLContext *)share
50 self = [
super initWithFormat:format shareContext:share];
77 [
self scheduleUpdate];
78 [
self updateIfNeeded];
88 NSMutableArray *contexts = oldwindowdata->
nscontexts;
89 @synchronized (contexts) {
90 [contexts removeObject:self];
94 self->window = newWindow;
104 if (contentview == nil) {
108 contentview = [windowdata->nswindow contentView];
112 NSMutableArray *contexts = windowdata->
nscontexts;
113 @
synchronized (contexts) {
114 [contexts addObject:self];
117 if ([
self view] != contentview) {
118 [
self setView:contentview];
119 if (
self == [NSOpenGLContext currentContext]) {
122 [
self scheduleUpdate];
126 [
self clearDrawable];
127 if (
self == [NSOpenGLContext currentContext]) {
130 [
self scheduleUpdate];
139Cocoa_GL_LoadLibrary(
_THIS,
const char *
path)
146 path = DEFAULT_OPENGL;
158Cocoa_GL_GetProcAddress(
_THIS,
const char *proc)
164Cocoa_GL_UnloadLibrary(
_THIS)
176 SDL_bool lion_or_later =
floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6;
177 NSOpenGLPixelFormatAttribute attr[32];
178 NSOpenGLPixelFormat *fmt;
180 NSOpenGLContext *share_context = nil;
182 const char *glversion;
187#if SDL_VIDEO_OPENGL_EGL
189 Cocoa_GL_UnloadLibrary(
_this);
200 if (Cocoa_GLES_LoadLibrary(
_this,
NULL) != 0) {
210 SDL_SetError (
"OpenGL Core Profile is not supported on this platform version");
214 attr[i++] = NSOpenGLPFAAllowOfflineRenderers;
218 NSOpenGLPixelFormatAttribute profile = NSOpenGLProfileVersionLegacy;
220 profile = NSOpenGLProfileVersion3_2Core;
222 attr[i++] = NSOpenGLPFAOpenGLProfile;
226 attr[i++] = NSOpenGLPFAColorSize;
229 attr[i++] = NSOpenGLPFADepthSize;
233 attr[i++] = NSOpenGLPFADoubleBuffer;
237 attr[i++] = NSOpenGLPFAStereo;
241 attr[i++] = NSOpenGLPFAStencilSize;
249 attr[i++] = NSOpenGLPFAAccumSize;
254 attr[i++] = NSOpenGLPFASampleBuffers;
259 attr[i++] = NSOpenGLPFASamples;
261 attr[i++] = NSOpenGLPFANoRecovery;
266 attr[i++] = NSOpenGLPFAAccelerated;
268 attr[i++] = NSOpenGLPFARendererID;
269 attr[i++] = kCGLRendererGenericFloatID;
273 attr[i++] = NSOpenGLPFAScreenMask;
274 attr[i++] = CGDisplayIDToOpenGLDisplayMask(displaydata->
display);
277 fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
287 context = [[SDLOpenGLContext alloc] initWithFormat:fmt shareContext:share_context];
310 if (!glGetStringFunc) {
312 SDL_SetError (
"Failed getting OpenGL glGetString entry point");
316 glversion = (
const char *)glGetStringFunc(
GL_VERSION);
317 if (glversion ==
NULL) {
323 if (
SDL_sscanf(glversion,
"%d.%d", &glversion_major, &glversion_minor) != 2) {
329 if ((glversion_major < _this->gl_config.major_version) ||
332 SDL_SetError (
"Failed creating OpenGL context at version requested");
350 SDLOpenGLContext *nscontext = (SDLOpenGLContext *)
context;
351 [nscontext setWindow:window];
352 [nscontext updateIfNeeded];
353 [nscontext makeCurrentContext];
355 [NSOpenGLContext clearCurrentContext];
365 NSView *contentView = [windata->
nswindow contentView];
366 NSRect
viewport = [contentView bounds];
371 if ([contentView respondsToSelector:
@selector(convertRectToBacking:)]) {
372 viewport = [contentView convertRectToBacking:viewport];
386Cocoa_GL_SetSwapInterval(
_THIS,
int interval)
389 NSOpenGLContext *nscontext;
394 return SDL_SetError(
"Late swap tearing currently unsupported");
398 if (nscontext != nil) {
400 [nscontext setValues:&value forParameter:NSOpenGLCPSwapInterval];
410Cocoa_GL_GetSwapInterval(
_THIS)
413 NSOpenGLContext *nscontext;
418 if (nscontext != nil) {
419 [nscontext getValues:&value forParameter:NSOpenGLCPSwapInterval];
436 [nscontext flushBuffer];
437 [nscontext updateIfNeeded];
446 SDLOpenGLContext *nscontext = (SDLOpenGLContext *)
context;
448 [nscontext setWindow:NULL];
454#pragma clang diagnostic pop
#define SDL_GL_GetProcAddress
#define SDL_GL_GetCurrentContext
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 void
void * SDL_LoadFunction(void *handle, const char *name)
GLsizei const GLchar *const * path
GLsizei const GLfloat * value
GLfloat GLfloat GLfloat GLfloat h
GLubyte GLubyte GLubyte GLubyte w
#define SDL_BYTESPERPIXEL(X)
#define SDL_arraysize(array)
SDL_VideoDisplay * SDL_GetDisplayForWindow(SDL_Window *window)
static SDL_VideoDevice * _this
@ SDL_WINDOW_ALLOW_HIGHDPI
void * SDL_GLContext
An opaque handle to an OpenGL context.
@ SDL_GL_CONTEXT_PROFILE_ES
@ SDL_GL_CONTEXT_PROFILE_CORE
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
EGLSurface EGLNativeWindowType * window
CGDirectDisplayID display
void(* GL_DeleteContext)(_THIS, SDL_GLContext context)
int(* GL_MakeCurrent)(_THIS, SDL_Window *window, SDL_GLContext context)
SDL_GLContext(* GL_CreateContext)(_THIS, SDL_Window *window)
int(* GL_SetSwapInterval)(_THIS, int interval)
void(* GL_UnloadLibrary)(_THIS)
int(* GL_GetSwapInterval)(_THIS)
int(* GL_LoadLibrary)(_THIS, const char *path)
int(* GL_SwapWindow)(_THIS, SDL_Window *window)
struct SDL_VideoDevice::@262 gl_config
void *(* GL_GetProcAddress)(_THIS, const char *proc)
int share_with_current_context
SDL_DisplayMode current_mode
NSMutableArray * nscontexts
The type used to identify a window.
static screen_context_t context