|
| 1 | +#ifdef DISABLE_X11 |
| 2 | + |
1 | 3 | #include "../fb_gfx.h"
|
2 | 4 | #include "../fb_gfx_gl.h"
|
3 | 5 | #include "fb_gfx_cocoa.h"
|
|
20 | 22 |
|
21 | 23 | /* GFXDRIVER */
|
22 | 24 | const GFXDRIVER fb_gfxDriverCocoaOpenGL = {
|
23 |
| - "Cocoa OpenGL", /* char *name; */ |
24 |
| - driver_init, /* int (*init)(char *title, int w, int h, int depth, int |
25 |
| - refresh_rate, int flags); */ |
26 |
| - driver_exit, /* void (*exit)(void); */ |
27 |
| - fb_hCocoaLock, /* void (*lock)(void); */ |
28 |
| - fb_hCocoaUnlock, /* void (*unlock)(void); */ |
29 |
| - fb_hGL_SetPalette, /* void (*set_palette)(int index, int r, int g, int b); |
30 |
| - */ |
31 |
| - fb_hCocoaWaitVSync, /* void (*wait_vsync)(void); */ |
32 |
| - fb_hCocoaGetMouse, /* int (*get_mouse)(int *x, int *y, int *z, int *buttons, |
33 |
| - int *clip); */ |
34 |
| - fb_hCocoaSetMouse, /* void (*set_mouse)(int x, int y, int cursor, int clip); |
35 |
| - */ |
| 25 | + "Cocoa OpenGL", /* char *name; */ |
| 26 | + driver_init, /* int (*init)(char *title, int w, int h, int depth, int refresh_rate, int flags); */ |
| 27 | + driver_exit, /* void (*exit)(void); */ |
| 28 | + fb_hCocoaLock, /* void (*lock)(void); */ |
| 29 | + fb_hCocoaUnlock, /* void (*unlock)(void); */ |
| 30 | + fb_hGL_SetPalette, /* void (*set_palette)(int index, int r, int g, int b); */ |
| 31 | + fb_hCocoaWaitVSync, /* void (*wait_vsync)(void); */ |
| 32 | + fb_hCocoaGetMouse, /* int (*get_mouse)(int *x, int *y, int *z, int *buttons, int *clip); */ |
| 33 | + fb_hCocoaSetMouse, /* void (*set_mouse)(int x, int y, int cursor, int clip); */ |
36 | 34 | fb_hCocoaSetWindowTitle, /* void (*set_window_title)(char *title); */
|
37 | 35 | fb_hCocoaSetWindowPos, /* int (*set_window_pos)(int x, int y); */
|
38 | 36 | fb_hCocoaFetchModes, /* int *(*fetch_modes)(void); */
|
39 | 37 | driver_flip, /* void (*flip)(void); */
|
40 |
| - driver_poll_events, /* void (*poll_events)(void); */ |
41 |
| - NULL /* void (*update)(void); */ |
| 38 | + driver_poll_events, /* void (*poll_events)(void); */ |
| 39 | + NULL, /* void (*update)(void); */ |
42 | 40 | };
|
43 | 41 |
|
44 | 42 | static dispatch_semaphore_t vsyncSema = NULL;
|
@@ -251,40 +249,48 @@ static int driver_init(char *title, int w, int h, int depth, int refresh_rate,
|
251 | 249 | driver.frame = NSMakeRect(0, 0, w, h);
|
252 | 250 |
|
253 | 251 | fb_hGL_NormalizeParameters(flags);
|
254 |
| - NSOpenGLPixelFormatAttribute attrs[32] = {0}; |
255 |
| - NSOpenGLPixelFormatAttribute* attr = attrs; |
256 |
| - *attr++ = NSOpenGLPFADoubleBuffer; |
257 |
| - *attr++ = NSOpenGLPFAAccelerated; |
258 |
| - *attr++ = NSOpenGLPFAOpenGLProfile; |
259 |
| - *attr++ = NSOpenGLProfileVersionLegacy; |
260 |
| - *attr++ = NSOpenGLPFAColorSize; |
261 |
| - *attr++ = __fb_gl_params.color_bits; |
262 |
| - *attr++ = NSOpenGLPFAAlphaSize; |
263 |
| - *attr++ = __fb_gl_params.color_alpha_bits; |
264 |
| - *attr++ = NSOpenGLPFADepthSize; |
265 |
| - *attr++ = depth; |
266 |
| - *attr++ = NSOpenGLPFAStencilSize; |
267 |
| - *attr++ = __fb_gl_params.stencil_bits; |
268 |
| - *attr++ = NSOpenGLPFAAccumSize; |
269 |
| - *attr++ = __fb_gl_params.accum_bits; |
270 |
| - if (flags & HAS_MULTISAMPLE) { |
271 |
| - *attr++ = NSOpenGLPFAMultisample; |
272 |
| - *attr++ = NSOpenGLPFASampleBuffers; |
273 |
| - *attr++ = 1; |
274 |
| - *attr++ = NSOpenGLPFASamples; |
275 |
| - *attr++ = __fb_gl_params.num_samples; |
| 252 | + NSOpenGLPixelFormatAttribute attribs[32] = {0}; |
| 253 | + NSOpenGLPixelFormatAttribute* attrib = attribs; |
| 254 | + NSOpenGLPixelFormatAttribute* samples_attrib = NULL; |
| 255 | + |
| 256 | + *attrib++ = NSOpenGLPFADoubleBuffer; |
| 257 | + *attrib++ = NSOpenGLPFAAccelerated; |
| 258 | + *attrib++ = NSOpenGLPFAOpenGLProfile; |
| 259 | + *attrib++ = NSOpenGLProfileVersionLegacy; |
| 260 | + *attrib++ = NSOpenGLPFAColorSize; |
| 261 | + *attrib++ = __fb_gl_params.color_bits; |
| 262 | + *attrib++ = NSOpenGLPFAAlphaSize; |
| 263 | + *attrib++ = __fb_gl_params.color_alpha_bits; |
| 264 | + *attrib++ = NSOpenGLPFADepthSize; |
| 265 | + *attrib++ = depth; |
| 266 | + if (__fb_gl_params.stencil_bits > 0) { |
| 267 | + *attrib++ = NSOpenGLPFAStencilSize; |
| 268 | + *attrib++ = __fb_gl_params.stencil_bits; |
| 269 | + } |
| 270 | + if (__fb_gl_params.accum_bits > 0) { |
| 271 | + *attrib++ = NSOpenGLPFAAccumSize; |
| 272 | + *attrib++ = __fb_gl_params.accum_bits; |
| 273 | + } |
| 274 | + if (__fb_gl_params.num_samples > 0) { |
| 275 | + *attrib++ = NSOpenGLPFAMultisample; |
| 276 | + *attrib++ = NSOpenGLPFASampleBuffers; |
| 277 | + *attrib++ = 1; |
| 278 | + *attrib++ = NSOpenGLPFASamples; |
| 279 | + *attrib++ = __fb_gl_params.num_samples; |
| 280 | + samples_attrib = attrib; |
276 | 281 | }
|
277 | 282 |
|
278 | 283 | if (!gl_lib) gl_lib = dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current", RTLD_LAZY);
|
279 | 284 | if (!gl_lib) gl_lib = dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", RTLD_LAZY);
|
280 | 285 | if (!gl_lib) return -1;
|
281 | 286 |
|
282 |
| - NSOpenGLPixelFormat *format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs]; |
| 287 | + NSOpenGLPixelFormat *format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs]; |
283 | 288 | driver.context = [[NSOpenGLContext alloc] initWithFormat:format shareContext:nil];
|
284 | 289 | if (!driver.context) return -1;
|
285 | 290 | driver.view = [[OpenGLView alloc] initWithFrame:driver.frame];
|
286 | 291 | if (!driver.view) return -1;
|
287 | 292 | [driver.view setOpenGLContext:driver.context];
|
| 293 | + [driver.view setWantsBestResolutionOpenGLSurface:YES]; |
288 | 294 |
|
289 | 295 | driver.window =
|
290 | 296 | [[OpenGLWindow alloc] initWithContentRect:driver.frame
|
@@ -312,12 +318,30 @@ static int driver_init(char *title, int w, int h, int depth, int refresh_rate,
|
312 | 318 |
|
313 | 319 | [driver.context makeCurrentContext];
|
314 | 320 |
|
| 321 | + __fb_gl_params.mode_2d = __fb_gl_params.init_mode_2d; |
| 322 | + if (__fb_gl_params.init_scale>=1){ |
| 323 | + __fb_gl_params.scale = __fb_gl_params.init_scale; |
| 324 | + } |
| 325 | + |
| 326 | + if (__fb_gl_params.scale>1){ |
| 327 | + free(__fb_gfx->dirty); |
| 328 | + __fb_gfx->dirty = (char *)calloc(1, __fb_gfx->h * __fb_gfx->scanline_size * __fb_gl_params.scale); |
| 329 | + } |
| 330 | + |
315 | 331 | if (fb_hGL_Init(gl_lib, NULL)) return -1;
|
316 | 332 |
|
| 333 | + if ((samples_attrib) && (*samples_attrib > 0)) |
| 334 | + __fb_gl.Enable(GL_MULTISAMPLE_ARB); |
| 335 | + |
| 336 | + if (__fb_gl_params.mode_2d != DRIVER_OGL_2D_NONE) |
| 337 | + fb_hGL_ScreenCreate(); |
| 338 | + |
317 | 339 | CGDirectDisplayID mainDisplay = CGMainDisplayID();
|
318 | 340 | CGDisplayModeRef mode = CGDisplayCopyDisplayMode(mainDisplay);
|
319 | 341 | __fb_gfx->refresh_rate = round(CGDisplayModeGetRefreshRate(mode));
|
320 | 342 | CFRelease(mode);
|
| 343 | + |
| 344 | + [driver.view createDisplayLink]; |
321 | 345 | }
|
322 | 346 | return 0;
|
323 | 347 | }
|
@@ -464,3 +488,5 @@ int fb_hCocoaScreenInfo(ssize_t *width, ssize_t *height, ssize_t *depth, ssize_t
|
464 | 488 | void* fb_hGL_GetProcAddress(const char *name) {
|
465 | 489 | return dlsym(gl_lib, name);
|
466 | 490 | }
|
| 491 | + |
| 492 | +#endif |
0 commit comments