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");
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];
399 SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context;
401 [nscontext setWindow:NULL];
NSMutableArray * nscontexts
static SDL_Window * 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 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
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
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.
struct SDL_VideoDevice::@28 gl_config
#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