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;
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");
176 attr[i++] = NSOpenGLPFAAllowOfflineRenderers;
180 NSOpenGLPixelFormatAttribute profile = NSOpenGLProfileVersionLegacy;
182 profile = NSOpenGLProfileVersion3_2Core;
184 attr[i++] = NSOpenGLPFAOpenGLProfile;
188 attr[i++] = NSOpenGLPFAColorSize;
191 attr[i++] = NSOpenGLPFADepthSize;
195 attr[i++] = NSOpenGLPFADoubleBuffer;
199 attr[i++] = NSOpenGLPFAStereo;
203 attr[i++] = NSOpenGLPFAStencilSize;
211 attr[i++] = NSOpenGLPFAAccumSize;
216 attr[i++] = NSOpenGLPFASampleBuffers;
221 attr[i++] = NSOpenGLPFASamples;
223 attr[i++] = NSOpenGLPFANoRecovery;
228 attr[i++] = NSOpenGLPFAAccelerated;
230 attr[i++] = NSOpenGLPFARendererID;
231 attr[i++] = kCGLRendererGenericFloatID;
235 attr[i++] = NSOpenGLPFAScreenMask;
236 attr[i++] = CGDisplayIDToOpenGLDisplayMask(displaydata->
display);
239 fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
249 context = [[SDLOpenGLContext alloc] initWithFormat:fmt shareContext:share_context];
253 if (context == nil) {
258 if ( Cocoa_GL_MakeCurrent(
_this, window, context) < 0 ) {
259 Cocoa_GL_DeleteContext(
_this, context);
272 if (!glGetStringFunc) {
273 Cocoa_GL_DeleteContext(
_this, context);
274 SDL_SetError (
"Failed getting OpenGL glGetString entry point");
278 glversion = (
const char *)glGetStringFunc(
GL_VERSION);
279 if (glversion ==
NULL) {
280 Cocoa_GL_DeleteContext(
_this, context);
285 if (
SDL_sscanf(glversion,
"%d.%d", &glversion_major, &glversion_minor) != 2) {
286 Cocoa_GL_DeleteContext(
_this, context);
291 if ((glversion_major < _this->gl_config.major_version) ||
293 Cocoa_GL_DeleteContext(
_this, context);
294 SDL_SetError (
"Failed creating OpenGL context at version requested");
312 SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context;
313 [nscontext setWindow:window];
314 [nscontext updateIfNeeded];
315 [nscontext makeCurrentContext];
317 [NSOpenGLContext clearCurrentContext];
327 NSView *contentView = [windata->
nswindow contentView];
328 NSRect
viewport = [contentView bounds];
332 if ([contentView respondsToSelector:
@selector(convertRectToBacking:)]) {
333 viewport = [contentView convertRectToBacking:viewport];
346 Cocoa_GL_SetSwapInterval(
_THIS,
int interval)
349 NSOpenGLContext *nscontext;
354 return SDL_SetError(
"Late swap tearing currently unsupported");
358 if (nscontext != nil) {
360 [nscontext setValues:&value forParameter:NSOpenGLCPSwapInterval];
370 Cocoa_GL_GetSwapInterval(
_THIS)
373 NSOpenGLContext *nscontext;
378 if (nscontext != nil) {
379 [nscontext getValues:&value forParameter:NSOpenGLCPSwapInterval];
391 [nscontext flushBuffer];
392 [nscontext updateIfNeeded];
400 SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context;
402 [nscontext setWindow:NULL];
NSMutableArray * nscontexts
GLfloat GLfloat GLfloat GLfloat h
static screen_context_t context
#define SDL_BYTESPERPIXEL(X)
CGDirectDisplayID display
struct SDL_VideoDevice::@33 gl_config
static SDL_VideoDevice * _this
void * SDL_GLContext
An opaque handle to an OpenGL context.
#define SDL_GL_GetProcAddress
SDL_DisplayMode current_mode
GLubyte GLubyte GLubyte GLubyte w
GLsizei const GLfloat * value
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_VideoDisplay * SDL_GetDisplayForWindow(SDL_Window *window)
EGLSurface EGLNativeWindowType * window
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
The type used to identify a window.
#define SDL_arraysize(array)
GLsizei const GLchar *const * path
void * SDL_LoadFunction(void *handle, const char *name)