21 #include "../../SDL_internal.h" 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 @implementation SDLOpenGLContext : NSOpenGLContext
40 - (
id)initWithFormat:(NSOpenGLPixelFormat *)format
41 shareContext:(NSOpenGLContext *)share
43 self = [
super initWithFormat:format shareContext:share];
51 - (
void)scheduleUpdate
57 - (
void)updateIfNeeded
70 [
self scheduleUpdate];
71 [
self updateIfNeeded];
81 NSMutableArray *contexts = oldwindowdata->
nscontexts;
82 @synchronized (contexts) {
83 [contexts removeObject:self];
87 self->window = newWindow;
93 NSMutableArray *contexts = windowdata->
nscontexts;
94 @synchronized (contexts) {
95 [contexts addObject:self];
98 if ([
self view] != [windowdata->
nswindow contentView]) {
99 [
self setView:[windowdata->nswindow contentView]];
100 if (
self == [NSOpenGLContext currentContext]) {
103 [
self scheduleUpdate];
107 [
self clearDrawable];
108 if (
self == [NSOpenGLContext currentContext]) {
111 [
self scheduleUpdate];
120 Cocoa_GL_LoadLibrary(
_THIS,
const char *
path)
127 path = DEFAULT_OPENGL;
139 Cocoa_GL_GetProcAddress(
_THIS,
const char *proc)
145 Cocoa_GL_UnloadLibrary(
_THIS)
157 SDL_bool lion_or_later =
floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6;
158 NSOpenGLPixelFormatAttribute attr[32];
159 NSOpenGLPixelFormat *fmt;
160 SDLOpenGLContext *context;
161 NSOpenGLContext *share_context = nil;
163 const char *glversion;
168 SDL_SetError (
"OpenGL ES is not supported on this platform");
172 SDL_SetError (
"OpenGL Core Profile is not supported on this platform version");
178 NSOpenGLPixelFormatAttribute profile = NSOpenGLProfileVersionLegacy;
180 profile = NSOpenGLProfileVersion3_2Core;
182 attr[i++] = NSOpenGLPFAOpenGLProfile;
186 attr[i++] = NSOpenGLPFAColorSize;
189 attr[i++] = NSOpenGLPFADepthSize;
193 attr[i++] = NSOpenGLPFADoubleBuffer;
197 attr[i++] = NSOpenGLPFAStereo;
201 attr[i++] = NSOpenGLPFAStencilSize;
209 attr[i++] = NSOpenGLPFAAccumSize;
214 attr[i++] = NSOpenGLPFASampleBuffers;
219 attr[i++] = NSOpenGLPFASamples;
221 attr[i++] = NSOpenGLPFANoRecovery;
226 attr[i++] = NSOpenGLPFAAccelerated;
228 attr[i++] = NSOpenGLPFARendererID;
229 attr[i++] = kCGLRendererGenericFloatID;
233 attr[i++] = NSOpenGLPFAScreenMask;
234 attr[i++] = CGDisplayIDToOpenGLDisplayMask(displaydata->
display);
237 fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
247 context = [[SDLOpenGLContext alloc] initWithFormat:fmt shareContext:share_context];
251 if (context == nil) {
256 if ( Cocoa_GL_MakeCurrent(
_this, window, context) < 0 ) {
257 Cocoa_GL_DeleteContext(
_this, context);
270 if (!glGetStringFunc) {
271 Cocoa_GL_DeleteContext(
_this, context);
272 SDL_SetError (
"Failed getting OpenGL glGetString entry point");
276 glversion = (
const char *)glGetStringFunc(
GL_VERSION);
277 if (glversion ==
NULL) {
278 Cocoa_GL_DeleteContext(
_this, context);
283 if (
SDL_sscanf(glversion,
"%d.%d", &glversion_major, &glversion_minor) != 2) {
284 Cocoa_GL_DeleteContext(
_this, context);
289 if ((glversion_major < _this->gl_config.major_version) ||
291 Cocoa_GL_DeleteContext(
_this, context);
292 SDL_SetError (
"Failed creating OpenGL context at version requested");
310 SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context;
311 [nscontext setWindow:window];
312 [nscontext updateIfNeeded];
313 [nscontext makeCurrentContext];
315 [NSOpenGLContext clearCurrentContext];
325 NSView *contentView = [windata->
nswindow contentView];
326 NSRect
viewport = [contentView bounds];
330 if ([contentView respondsToSelector:
@selector(convertRectToBacking:)]) {
331 viewport = [contentView convertRectToBacking:viewport];
344 Cocoa_GL_SetSwapInterval(
_THIS,
int interval)
347 NSOpenGLContext *nscontext;
352 return SDL_SetError(
"Late swap tearing currently unsupported");
356 if (nscontext != nil) {
358 [nscontext setValues:&value forParameter:NSOpenGLCPSwapInterval];
368 Cocoa_GL_GetSwapInterval(
_THIS)
371 NSOpenGLContext *nscontext;
376 if (nscontext != nil) {
377 [nscontext getValues:&value forParameter:NSOpenGLCPSwapInterval];
389 [nscontext flushBuffer];
390 [nscontext updateIfNeeded];
397 SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context;
399 [nscontext setWindow:NULL];
NSMutableArray * nscontexts
#define SDL_BYTESPERPIXEL(X)
CGDirectDisplayID display
static SDL_VideoDevice * _this
void * SDL_GLContext
An opaque handle to an OpenGL context.
GLsizei const GLfloat * value
#define SDL_GL_GetProcAddress
SDL_DisplayMode current_mode
struct SDL_VideoDevice::@27 gl_config
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)
int share_with_current_context
#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
SDL_VideoDisplay * SDL_GetDisplayForWindow(SDL_Window *window)
The type used to identify a window.
#define SDL_arraysize(array)
GLsizei const GLchar *const * path
GLubyte GLubyte GLubyte GLubyte w
void * SDL_LoadFunction(void *handle, const char *name)
GLfloat GLfloat GLfloat GLfloat h