25 #if SDL_VIDEO_OPENGL_CGL
29 #include <OpenGL/CGLTypes.h>
30 #include <OpenGL/OpenGL.h>
31 #include <OpenGL/CGLRenderers.h>
36 #define DEFAULT_OPENGL "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib"
38 #if MAC_OS_X_VERSION_MAX_ALLOWED < 1070
41 @interface NSView (Backing)
42 - (NSPoint)convertPointToBacking:(NSPoint)aPoint;
43 - (NSPoint)convertPointFromBacking:(NSPoint)aPoint;
44 - (NSSize)convertSizeToBacking:(NSSize)aSize;
45 - (NSSize)convertSizeFromBacking:(NSSize)aSize;
46 - (NSRect)convertRectToBacking:(NSRect)aRect;
47 - (NSRect)convertRectFromBacking:(NSRect)aRect;
51 #ifndef kCGLPFAOpenGLProfile
52 #define kCGLPFAOpenGLProfile 99
54 #ifndef kCGLOGLPVersion_Legacy
55 #define kCGLOGLPVersion_Legacy 0x1000
57 #ifndef kCGLOGLPVersion_3_2_Core
58 #define kCGLOGLPVersion_3_2_Core 0x3200
61 @implementation SDLOpenGLContext : NSOpenGLContext
63 - (
id)initWithFormat:(NSOpenGLPixelFormat *)format
64 shareContext:(NSOpenGLContext *)share
66 self = [
super initWithFormat:format shareContext:share];
74 - (
void)scheduleUpdate
80 - (
void)updateIfNeeded
93 [
self scheduleUpdate];
94 [
self updateIfNeeded];
104 NSMutableArray *contexts = oldwindowdata->
nscontexts;
105 @synchronized (contexts) {
106 [contexts removeObject:self];
110 self->window = newWindow;
116 NSMutableArray *contexts = windowdata->
nscontexts;
117 @synchronized (contexts) {
118 [contexts addObject:self];
121 if ([
self view] != [windowdata->
nswindow contentView]) {
122 [
self setView:[windowdata->nswindow contentView]];
123 [
self scheduleUpdate];
126 [
self clearDrawable];
127 [
self scheduleUpdate];
135 Cocoa_GL_LoadLibrary(
_THIS,
const char *
path)
142 path = DEFAULT_OPENGL;
154 Cocoa_GL_GetProcAddress(
_THIS,
const char *proc)
160 Cocoa_GL_UnloadLibrary(
_THIS)
172 NSAutoreleasePool *pool;
175 NSOpenGLPixelFormatAttribute attr[32];
176 NSOpenGLPixelFormat *fmt;
178 NSOpenGLContext *share_context = nil;
182 SDL_SetError (
"OpenGL ES not supported on this platform");
188 if (wantver > 0x0302) {
189 SDL_SetError (
"OpenGL > 3.2 is not supported on this platform");
193 pool = [[NSAutoreleasePool alloc] init];
197 NSOpenGLPixelFormatAttribute
profile = kCGLOGLPVersion_Legacy;
199 if (wantver == 0x0302) {
200 profile = kCGLOGLPVersion_3_2_Core;
203 attr[i++] = kCGLPFAOpenGLProfile;
207 attr[i++] = NSOpenGLPFAColorSize;
210 attr[i++] = NSOpenGLPFADepthSize;
214 attr[i++] = NSOpenGLPFADoubleBuffer;
218 attr[i++] = NSOpenGLPFAStereo;
222 attr[i++] = NSOpenGLPFAStencilSize;
230 attr[i++] = NSOpenGLPFAAccumSize;
235 attr[i++] = NSOpenGLPFASampleBuffers;
240 attr[i++] = NSOpenGLPFASamples;
242 attr[i++] = NSOpenGLPFANoRecovery;
247 attr[i++] = NSOpenGLPFAAccelerated;
249 attr[i++] = NSOpenGLPFARendererID;
250 attr[i++] = kCGLRendererGenericFloatID;
254 attr[i++] = NSOpenGLPFAScreenMask;
255 attr[i++] = CGDisplayIDToOpenGLDisplayMask(displaydata->
display);
258 fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
269 context = [[SDLOpenGLContext alloc] initWithFormat:fmt shareContext:share_context];
281 if ( Cocoa_GL_MakeCurrent(
_this, window,
context) < 0 ) {
292 NSAutoreleasePool *pool;
294 pool = [[NSAutoreleasePool alloc] init];
297 SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context;
298 [nscontext setWindow:window];
299 [nscontext updateIfNeeded];
300 [nscontext makeCurrentContext];
302 [NSOpenGLContext clearCurrentContext];
313 NSView *contentView = [windata->
nswindow contentView];
314 NSRect viewport = [contentView bounds];
318 if ([contentView respondsToSelector:
@selector(convertRectToBacking:)]) {
319 viewport = [contentView convertRectToBacking:viewport];
323 *w = viewport.size.width;
327 *h = viewport.size.height;
332 Cocoa_GL_SetSwapInterval(
_THIS,
int interval)
334 NSAutoreleasePool *pool;
335 NSOpenGLContext *nscontext;
340 return SDL_SetError(
"Late swap tearing currently unsupported");
343 pool = [[NSAutoreleasePool alloc] init];
346 if (nscontext != nil) {
348 [nscontext setValues:&value forParameter:NSOpenGLCPSwapInterval];
359 Cocoa_GL_GetSwapInterval(
_THIS)
361 NSAutoreleasePool *pool;
362 NSOpenGLContext *nscontext;
366 pool = [[NSAutoreleasePool alloc] init];
369 if (nscontext != nil) {
370 [nscontext getValues:&value forParameter:NSOpenGLCPSwapInterval];
381 NSAutoreleasePool *pool;
383 pool = [[NSAutoreleasePool alloc] init];
386 [nscontext flushBuffer];
387 [nscontext updateIfNeeded];
395 NSAutoreleasePool *pool;
396 SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context;
398 pool = [[NSAutoreleasePool alloc] init];
400 [nscontext setWindow:NULL];
NSMutableArray * nscontexts
GLfloat GLfloat GLfloat GLfloat h
GLvoid **typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
SDL_FORCE_INLINE int SDL_AtomicAdd(SDL_atomic_t *a, int v)
Add to an atomic variable.
void * SDL_GLContext
An opaque handle to an OpenGL context.
#define SDL_BYTESPERPIXEL(X)
CGDirectDisplayID display
GLsizei const GLchar *const * path
static SDL_VideoDevice * _this
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
DECLSPEC void *SDLCALL SDL_LoadObject(const char *sofile)
DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src, size_t maxlen)
DECLSPEC void SDLCALL SDL_UnloadObject(void *handle)
DECLSPEC int SDLCALL SDL_SetError(const char *fmt,...)
int share_with_current_context
#define SDL_arraysize(array)
EGLSurface EGLint void ** value
SDL_VideoDisplay * SDL_GetDisplayForWindow(SDL_Window *window)
SDL_FORCE_INLINE int SDL_AtomicSet(SDL_atomic_t *a, int v)
Set an atomic variable to a value.
GLint GLint GLint GLint GLint w
DECLSPEC char *SDLCALL SDL_getenv(const char *name)
DECLSPEC void *SDLCALL SDL_LoadFunction(void *handle, const char *name)
struct SDL_VideoDevice::@87 gl_config
DECLSPEC SDL_GLContext SDLCALL SDL_GL_GetCurrentContext(void)
Get the currently active OpenGL context.