equal
deleted
inserted
replaced
49 @implementation SDLOpenGLContext : NSOpenGLContext |
49 @implementation SDLOpenGLContext : NSOpenGLContext |
50 |
50 |
51 - (id)initWithFormat:(NSOpenGLPixelFormat *)format |
51 - (id)initWithFormat:(NSOpenGLPixelFormat *)format |
52 shareContext:(NSOpenGLContext *)share |
52 shareContext:(NSOpenGLContext *)share |
53 { |
53 { |
54 SDL_AtomicSet(&self->dirty, 0); |
54 self = [super initWithFormat:format shareContext:share]; |
55 return [super initWithFormat:format shareContext:share]; |
55 if (self) { |
|
56 SDL_AtomicSet(&self->dirty, 0); |
|
57 self->window = NULL; |
|
58 } |
|
59 return self; |
56 } |
60 } |
57 |
61 |
58 - (void)scheduleUpdate |
62 - (void)scheduleUpdate |
59 { |
63 { |
60 SDL_AtomicAdd(&self->dirty, 1); |
64 SDL_AtomicAdd(&self->dirty, 1); |
74 - (void)update |
78 - (void)update |
75 { |
79 { |
76 /* This ensures that regular 'update' calls clear the atomic dirty flag. */ |
80 /* This ensures that regular 'update' calls clear the atomic dirty flag. */ |
77 [self scheduleUpdate]; |
81 [self scheduleUpdate]; |
78 [self updateIfNeeded]; |
82 [self updateIfNeeded]; |
|
83 } |
|
84 |
|
85 /* Updates the drawable for the contexts and manages related state. */ |
|
86 - (void)setWindow:(SDL_Window *)newWindow |
|
87 { |
|
88 if (self->window) { |
|
89 SDL_WindowData *oldwindowdata = (SDL_WindowData *)self->window->driverdata; |
|
90 |
|
91 /* Make sure to remove us from the old window's context list, or we'll get scheduled updates from it too. */ |
|
92 NSMutableArray *contexts = oldwindowdata->nscontexts; |
|
93 @synchronized (contexts) { |
|
94 [contexts removeObject:self]; |
|
95 } |
|
96 } |
|
97 |
|
98 self->window = newWindow; |
|
99 |
|
100 if (newWindow) { |
|
101 SDL_WindowData *windowdata = (SDL_WindowData *)newWindow->driverdata; |
|
102 |
|
103 /* Now sign up for scheduled updates for the new window. */ |
|
104 NSMutableArray *contexts = windowdata->nscontexts; |
|
105 @synchronized (contexts) { |
|
106 [contexts addObject:self]; |
|
107 } |
|
108 |
|
109 if ([self view] != [windowdata->nswindow contentView]) { |
|
110 [self setView:[windowdata->nswindow contentView]]; |
|
111 [self scheduleUpdate]; |
|
112 } |
|
113 } else { |
|
114 [self clearDrawable]; |
|
115 [self scheduleUpdate]; |
|
116 } |
79 } |
117 } |
80 |
118 |
81 @end |
119 @end |
82 |
120 |
83 |
121 |
242 NSAutoreleasePool *pool; |
280 NSAutoreleasePool *pool; |
243 |
281 |
244 pool = [[NSAutoreleasePool alloc] init]; |
282 pool = [[NSAutoreleasePool alloc] init]; |
245 |
283 |
246 if (context) { |
284 if (context) { |
247 SDL_WindowData *windowdata = (SDL_WindowData *)window->driverdata; |
|
248 SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context; |
285 SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context; |
249 windowdata->nscontext = nscontext; |
286 [nscontext setWindow:window]; |
250 if ([nscontext view] != [windowdata->nswindow contentView]) { |
|
251 [nscontext setView:[windowdata->nswindow contentView]]; |
|
252 [nscontext scheduleUpdate]; |
|
253 } |
|
254 |
|
255 [nscontext updateIfNeeded]; |
287 [nscontext updateIfNeeded]; |
256 [nscontext makeCurrentContext]; |
288 [nscontext makeCurrentContext]; |
257 } else { |
289 } else { |
258 [NSOpenGLContext clearCurrentContext]; |
290 [NSOpenGLContext clearCurrentContext]; |
259 } |
291 } |
307 |
339 |
308 void |
340 void |
309 Cocoa_GL_SwapWindow(_THIS, SDL_Window * window) |
341 Cocoa_GL_SwapWindow(_THIS, SDL_Window * window) |
310 { |
342 { |
311 NSAutoreleasePool *pool; |
343 NSAutoreleasePool *pool; |
312 SDL_WindowData *windowdata = (SDL_WindowData *)window->driverdata; |
344 |
313 SDLOpenGLContext *nscontext = windowdata->nscontext; |
345 pool = [[NSAutoreleasePool alloc] init]; |
314 |
346 |
315 pool = [[NSAutoreleasePool alloc] init]; |
347 SDLOpenGLContext* nscontext = (NSOpenGLContext*)SDL_GL_GetCurrentContext(); |
316 |
|
317 [nscontext flushBuffer]; |
348 [nscontext flushBuffer]; |
318 [nscontext updateIfNeeded]; |
349 [nscontext updateIfNeeded]; |
319 |
350 |
320 [pool release]; |
351 [pool release]; |
321 } |
352 } |
322 |
353 |
323 void |
354 void |
324 Cocoa_GL_DeleteContext(_THIS, SDL_GLContext context) |
355 Cocoa_GL_DeleteContext(_THIS, SDL_GLContext context) |
325 { |
356 { |
326 NSAutoreleasePool *pool; |
357 NSAutoreleasePool *pool; |
327 NSOpenGLContext *nscontext = (NSOpenGLContext *)context; |
358 SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context; |
328 |
359 |
329 pool = [[NSAutoreleasePool alloc] init]; |
360 pool = [[NSAutoreleasePool alloc] init]; |
330 |
361 |
331 [nscontext clearDrawable]; |
362 [nscontext setWindow:NULL]; |
332 [nscontext release]; |
363 [nscontext release]; |
333 |
364 |
334 [pool release]; |
365 [pool release]; |
335 } |
366 } |
336 |
367 |