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];
58 - (
void)scheduleUpdate
64 - (
void)updateIfNeeded
69 [
self explicitUpdate];
77 [
self scheduleUpdate];
78 [
self updateIfNeeded];
88 NSMutableArray *contexts = oldwindowdata->
nscontexts;
89 @synchronized (contexts) {
90 [contexts removeObject:self];
94 self->window = newWindow;
101 NSMutableArray *contexts = windowdata->
nscontexts;
102 @synchronized (contexts) {
103 [contexts addObject:self];
106 if ([
self view] != contentview) {
107 if ([NSThread isMainThread]) {
108 [
self setView:contentview];
110 dispatch_sync(dispatch_get_main_queue(), ^{ [
self setView:contentview]; });
112 if (
self == [NSOpenGLContext currentContext]) {
113 [
self explicitUpdate];
115 [
self scheduleUpdate];
119 [
self clearDrawable];
120 if (
self == [NSOpenGLContext currentContext]) {
121 [
self explicitUpdate];
123 [
self scheduleUpdate];
133 - (
void)explicitUpdate
135 if ([NSThread isMainThread]) {
138 dispatch_sync(dispatch_get_main_queue(), ^{ [
super update]; });
146 Cocoa_GL_LoadLibrary(
_THIS,
const char *
path)
153 path = DEFAULT_OPENGL;
165 Cocoa_GL_GetProcAddress(
_THIS,
const char *proc)
171 Cocoa_GL_UnloadLibrary(
_THIS)
183 SDL_bool lion_or_later =
floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6;
184 NSOpenGLPixelFormatAttribute attr[32];
185 NSOpenGLPixelFormat *fmt;
187 NSOpenGLContext *share_context = nil;
189 const char *glversion;
194 #if SDL_VIDEO_OPENGL_EGL
196 Cocoa_GL_UnloadLibrary(
_this);
207 if (Cocoa_GLES_LoadLibrary(
_this,
NULL) != 0) {
217 SDL_SetError (
"OpenGL Core Profile is not supported on this platform version");
221 attr[i++] = NSOpenGLPFAAllowOfflineRenderers;
225 NSOpenGLPixelFormatAttribute profile = NSOpenGLProfileVersionLegacy;
227 profile = NSOpenGLProfileVersion3_2Core;
229 attr[i++] = NSOpenGLPFAOpenGLProfile;
233 attr[i++] = NSOpenGLPFAColorSize;
236 attr[i++] = NSOpenGLPFADepthSize;
240 attr[i++] = NSOpenGLPFADoubleBuffer;
244 attr[i++] = NSOpenGLPFAStereo;
248 attr[i++] = NSOpenGLPFAStencilSize;
256 attr[i++] = NSOpenGLPFAAccumSize;
261 attr[i++] = NSOpenGLPFASampleBuffers;
266 attr[i++] = NSOpenGLPFASamples;
268 attr[i++] = NSOpenGLPFANoRecovery;
273 attr[i++] = NSOpenGLPFAAccelerated;
275 attr[i++] = NSOpenGLPFARendererID;
276 attr[i++] = kCGLRendererGenericFloatID;
280 attr[i++] = NSOpenGLPFAScreenMask;
281 attr[i++] = CGDisplayIDToOpenGLDisplayMask(displaydata->
display);
284 fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
294 context = [[SDLOpenGLContext alloc] initWithFormat:fmt shareContext:share_context];
317 if (!glGetStringFunc) {
319 SDL_SetError (
"Failed getting OpenGL glGetString entry point");
323 glversion = (
const char *)glGetStringFunc(
GL_VERSION);
324 if (glversion ==
NULL) {
330 if (
SDL_sscanf(glversion,
"%d.%d", &glversion_major, &glversion_minor) != 2) {
336 if ((glversion_major < _this->gl_config.major_version) ||
339 SDL_SetError (
"Failed creating OpenGL context at version requested");
357 SDLOpenGLContext *nscontext = (SDLOpenGLContext *)
context;
359 [nscontext setWindow:window];
360 [nscontext updateIfNeeded];
362 [nscontext makeCurrentContext];
364 [NSOpenGLContext clearCurrentContext];
375 NSRect
viewport = [contentView bounds];
380 if ([contentView respondsToSelector:
@selector(convertRectToBacking:)]) {
381 viewport = [contentView convertRectToBacking:viewport];
395 Cocoa_GL_SetSwapInterval(
_THIS,
int interval)
398 NSOpenGLContext *nscontext;
403 return SDL_SetError(
"Late swap tearing currently unsupported");
407 if (nscontext != nil) {
409 [nscontext setValues:&value forParameter:NSOpenGLCPSwapInterval];
419 Cocoa_GL_GetSwapInterval(
_THIS)
422 NSOpenGLContext *nscontext;
427 if (nscontext != nil) {
428 [nscontext getValues:&value forParameter:NSOpenGLCPSwapInterval];
445 [nscontext flushBuffer];
446 [nscontext updateIfNeeded];
455 SDLOpenGLContext *nscontext = (SDLOpenGLContext *)
context;
457 [nscontext setWindow:NULL];
463 #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
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d ®2 endm macro vzip8 reg2 vzip d d ®2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
CGDirectDisplayID display
void(* GL_DeleteContext)(_THIS, SDL_GLContext context)
int(* GL_MakeCurrent)(_THIS, SDL_Window *window, SDL_GLContext context)
struct SDL_VideoDevice::@440 gl_config
SDL_GLContext(* GL_CreateContext)(_THIS, SDL_Window *window)
int(* GL_SetSwapInterval)(_THIS, int interval)
void(* GL_UnloadLibrary)(_THIS)
void *(* GL_GetProcAddress)(_THIS, const char *proc)
int(* GL_GetSwapInterval)(_THIS)
int(* GL_LoadLibrary)(_THIS, const char *path)
int(* GL_SwapWindow)(_THIS, SDL_Window *window)
int share_with_current_context
SDL_DisplayMode current_mode
NSMutableArray * nscontexts
The type used to identify a window.
static screen_context_t context
typedef int(__stdcall *FARPROC)()