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" 39 @implementation SDLOpenGLContext : NSOpenGLContext
41 - (
id)initWithFormat:(NSOpenGLPixelFormat *)format
42 shareContext:(NSOpenGLContext *)share
44 self = [
super initWithFormat:format shareContext:share];
52 - (
void)scheduleUpdate
58 - (
void)updateIfNeeded
71 [
self scheduleUpdate];
72 [
self updateIfNeeded];
82 NSMutableArray *contexts = oldwindowdata->
nscontexts;
83 @synchronized (contexts) {
84 [contexts removeObject:self];
88 self->window = newWindow;
94 NSMutableArray *contexts = windowdata->
nscontexts;
95 @synchronized (contexts) {
96 [contexts addObject:self];
99 if ([
self view] != [windowdata->
nswindow contentView]) {
100 [
self setView:[windowdata->nswindow contentView]];
101 if (
self == [NSOpenGLContext currentContext]) {
104 [
self scheduleUpdate];
108 [
self clearDrawable];
109 if (
self == [NSOpenGLContext currentContext]) {
112 [
self scheduleUpdate];
121 Cocoa_GL_LoadLibrary(
_THIS,
const char *
path)
128 path = DEFAULT_OPENGL;
140 Cocoa_GL_GetProcAddress(
_THIS,
const char *proc)
146 Cocoa_GL_UnloadLibrary(
_THIS)
158 SDL_bool lion_or_later =
floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6;
159 NSOpenGLPixelFormatAttribute attr[32];
160 NSOpenGLPixelFormat *fmt;
162 NSOpenGLContext *share_context = nil;
164 const char *glversion;
169 #if SDL_VIDEO_OPENGL_EGL 171 Cocoa_GL_UnloadLibrary(
_this);
182 if (Cocoa_GLES_LoadLibrary(
_this,
NULL) != 0) {
185 return Cocoa_GLES_CreateContext(
_this, window);
192 SDL_SetError (
"OpenGL Core Profile is not supported on this platform version");
196 attr[i++] = NSOpenGLPFAAllowOfflineRenderers;
200 NSOpenGLPixelFormatAttribute profile = NSOpenGLProfileVersionLegacy;
202 profile = NSOpenGLProfileVersion3_2Core;
204 attr[i++] = NSOpenGLPFAOpenGLProfile;
208 attr[i++] = NSOpenGLPFAColorSize;
211 attr[i++] = NSOpenGLPFADepthSize;
215 attr[i++] = NSOpenGLPFADoubleBuffer;
219 attr[i++] = NSOpenGLPFAStereo;
223 attr[i++] = NSOpenGLPFAStencilSize;
231 attr[i++] = NSOpenGLPFAAccumSize;
236 attr[i++] = NSOpenGLPFASampleBuffers;
241 attr[i++] = NSOpenGLPFASamples;
243 attr[i++] = NSOpenGLPFANoRecovery;
248 attr[i++] = NSOpenGLPFAAccelerated;
250 attr[i++] = NSOpenGLPFARendererID;
251 attr[i++] = kCGLRendererGenericFloatID;
255 attr[i++] = NSOpenGLPFAScreenMask;
256 attr[i++] = CGDisplayIDToOpenGLDisplayMask(displaydata->
display);
259 fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
269 context = [[SDLOpenGLContext alloc] initWithFormat:fmt shareContext:share_context];
273 if (context == nil) {
278 if ( Cocoa_GL_MakeCurrent(
_this, window, context) < 0 ) {
279 Cocoa_GL_DeleteContext(
_this, context);
292 if (!glGetStringFunc) {
293 Cocoa_GL_DeleteContext(
_this, context);
294 SDL_SetError (
"Failed getting OpenGL glGetString entry point");
298 glversion = (
const char *)glGetStringFunc(
GL_VERSION);
299 if (glversion ==
NULL) {
300 Cocoa_GL_DeleteContext(
_this, context);
305 if (
SDL_sscanf(glversion,
"%d.%d", &glversion_major, &glversion_minor) != 2) {
306 Cocoa_GL_DeleteContext(
_this, context);
311 if ((glversion_major < _this->gl_config.major_version) ||
313 Cocoa_GL_DeleteContext(
_this, context);
314 SDL_SetError (
"Failed creating OpenGL context at version requested");
332 SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context;
333 [nscontext setWindow:window];
334 [nscontext updateIfNeeded];
335 [nscontext makeCurrentContext];
337 [NSOpenGLContext clearCurrentContext];
347 NSView *contentView = [windata->
nswindow contentView];
348 NSRect
viewport = [contentView bounds];
353 if ([contentView respondsToSelector:
@selector(convertRectToBacking:)]) {
354 viewport = [contentView convertRectToBacking:viewport];
368 Cocoa_GL_SetSwapInterval(
_THIS,
int interval)
371 NSOpenGLContext *nscontext;
376 return SDL_SetError(
"Late swap tearing currently unsupported");
380 if (nscontext != nil) {
382 [nscontext setValues:&value forParameter:NSOpenGLCPSwapInterval];
392 Cocoa_GL_GetSwapInterval(
_THIS)
395 NSOpenGLContext *nscontext;
400 if (nscontext != nil) {
401 [nscontext getValues:&value forParameter:NSOpenGLCPSwapInterval];
418 [nscontext flushBuffer];
419 [nscontext updateIfNeeded];
428 SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context;
430 [nscontext setWindow:NULL];
NSMutableArray * nscontexts
GLfloat GLfloat GLfloat GLfloat h
int(* GL_SetSwapInterval)(_THIS, int interval)
static screen_context_t context
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 local skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
#define SDL_BYTESPERPIXEL(X)
CGDirectDisplayID display
int(* GL_LoadLibrary)(_THIS, const char *path)
struct SDL_VideoDevice::@33 gl_config
static SDL_VideoDevice * _this
void * SDL_GLContext
An opaque handle to an OpenGL context.
SDL_GLContext(* GL_CreateContext)(_THIS, SDL_Window *window)
int(* GL_MakeCurrent)(_THIS, SDL_Window *window, SDL_GLContext context)
#define SDL_GL_GetProcAddress
SDL_DisplayMode current_mode
GLubyte GLubyte GLubyte GLubyte w
GLsizei const GLfloat * value
void(* GL_UnloadLibrary)(_THIS)
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
int(* GL_SwapWindow)(_THIS, SDL_Window *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)
void(* GL_DeleteContext)(_THIS, SDL_GLContext context)
int(* GL_GetSwapInterval)(_THIS)
void *(* GL_GetProcAddress)(_THIS, const char *proc)