mirror of
https://github.com/libretro/RetroArch
synced 2025-03-03 04:14:00 +00:00
Move more functionaliy to cocoa_gl_shared.h
This commit is contained in:
parent
35ce4dcadc
commit
a49d0a50b9
@ -16,113 +16,6 @@
|
||||
|
||||
#include "cocoa_gl_shared.h"
|
||||
|
||||
static void *cocoagl_gfx_ctx_init(video_frame_info_t *video_info, void *video_driver)
|
||||
{
|
||||
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)
|
||||
calloc(1, sizeof(cocoa_ctx_data_t));
|
||||
|
||||
if (!cocoa_ctx)
|
||||
return NULL;
|
||||
|
||||
return cocoa_ctx;
|
||||
}
|
||||
|
||||
static bool cocoagl_gfx_ctx_set_video_mode(void *data,
|
||||
video_frame_info_t *video_info,
|
||||
unsigned width, unsigned height, bool fullscreen)
|
||||
{
|
||||
#if defined(HAVE_COCOA)
|
||||
CocoaView *g_view = (CocoaView*)nsview_get_ptr();
|
||||
if ([g_view respondsToSelector: @selector(setWantsBestResolutionOpenGLSurface:)])
|
||||
[g_view setWantsBestResolutionOpenGLSurface:YES];
|
||||
|
||||
NSOpenGLPixelFormatAttribute attributes [] = {
|
||||
NSOpenGLPFAColorSize,
|
||||
24,
|
||||
NSOpenGLPFADoubleBuffer,
|
||||
NSOpenGLPFAAllowOfflineRenderers,
|
||||
NSOpenGLPFADepthSize,
|
||||
(NSOpenGLPixelFormatAttribute)16, // 16 bit depth buffer
|
||||
0, /* profile */
|
||||
0, /* profile enum */
|
||||
(NSOpenGLPixelFormatAttribute)0
|
||||
};
|
||||
|
||||
#if MAC_OS_X_VERSION_10_7
|
||||
if (g_major == 3 && (g_minor >= 1 && g_minor <= 3))
|
||||
{
|
||||
attributes[6] = NSOpenGLPFAOpenGLProfile;
|
||||
attributes[7] = NSOpenGLProfileVersion3_2Core;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if MAC_OS_X_VERSION_10_10
|
||||
if (g_major == 4 && g_minor == 1)
|
||||
{
|
||||
attributes[6] = NSOpenGLPFAOpenGLProfile;
|
||||
attributes[7] = NSOpenGLProfileVersion4_1Core;
|
||||
}
|
||||
#endif
|
||||
|
||||
g_format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
|
||||
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1050
|
||||
if (g_format == nil)
|
||||
{
|
||||
/* NSOpenGLFPAAllowOfflineRenderers is
|
||||
not supported on this OS version. */
|
||||
attributes[3] = (NSOpenGLPixelFormatAttribute)0;
|
||||
g_format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
|
||||
}
|
||||
#endif
|
||||
|
||||
if (g_use_hw_ctx)
|
||||
g_hw_ctx = [[NSOpenGLContext alloc] initWithFormat:g_format shareContext:nil];
|
||||
g_context = [[NSOpenGLContext alloc] initWithFormat:g_format shareContext:(g_use_hw_ctx) ? g_hw_ctx : nil];
|
||||
[g_context setView:g_view];
|
||||
#else
|
||||
if (g_use_hw_ctx)
|
||||
g_hw_ctx = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
||||
g_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
||||
g_view.context = g_context;
|
||||
#endif
|
||||
|
||||
[g_context makeCurrentContext];
|
||||
|
||||
#if defined(HAVE_COCOA)
|
||||
static bool has_went_fullscreen = false;
|
||||
/* TODO: Screen mode support. */
|
||||
|
||||
if (fullscreen)
|
||||
{
|
||||
if (!has_went_fullscreen)
|
||||
{
|
||||
[g_view enterFullScreenMode:get_chosen_screen() withOptions:nil];
|
||||
cocoagl_gfx_ctx_show_mouse(data, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (has_went_fullscreen)
|
||||
{
|
||||
[g_view exitFullScreenModeWithOptions:nil];
|
||||
[[g_view window] makeFirstResponder:g_view];
|
||||
cocoagl_gfx_ctx_show_mouse(data, true);
|
||||
}
|
||||
|
||||
[[g_view window] setContentSize:NSMakeSize(width, height)];
|
||||
}
|
||||
|
||||
has_went_fullscreen = fullscreen;
|
||||
#endif
|
||||
|
||||
(void)data;
|
||||
|
||||
/* TODO: Maybe iOS users should be able to show/hide the status bar here? */
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const gfx_ctx_driver_t gfx_ctx_cocoagl = {
|
||||
cocoagl_gfx_ctx_init,
|
||||
cocoagl_gfx_ctx_destroy,
|
||||
|
@ -15,172 +15,6 @@
|
||||
|
||||
#include "cocoa_gl_shared.h"
|
||||
|
||||
static void *cocoagl_gfx_ctx_init(video_frame_info_t *video_info, void *video_driver)
|
||||
{
|
||||
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)
|
||||
calloc(1, sizeof(cocoa_ctx_data_t));
|
||||
|
||||
if (!cocoa_ctx)
|
||||
return NULL;
|
||||
|
||||
switch (cocoagl_api)
|
||||
{
|
||||
#if defined(HAVE_COCOATOUCH)
|
||||
case GFX_CTX_OPENGL_ES_API:
|
||||
// setViewType is not (yet?) defined for iOS
|
||||
// [apple_platform setViewType:APPLE_VIEW_TYPE_OPENGL_ES];
|
||||
break;
|
||||
#elif defined(HAVE_COCOA_METAL)
|
||||
case GFX_CTX_OPENGL_API:
|
||||
[apple_platform setViewType:APPLE_VIEW_TYPE_OPENGL];
|
||||
break;
|
||||
#endif
|
||||
case GFX_CTX_VULKAN_API:
|
||||
#ifdef HAVE_VULKAN
|
||||
[apple_platform setViewType:APPLE_VIEW_TYPE_VULKAN];
|
||||
if (!vulkan_context_init(&cocoa_ctx->vk, VULKAN_WSI_MVK_MACOS))
|
||||
goto error;
|
||||
#endif
|
||||
break;
|
||||
case GFX_CTX_NONE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return cocoa_ctx;
|
||||
|
||||
error:
|
||||
free(cocoa_ctx);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool cocoagl_gfx_ctx_set_video_mode(void *data,
|
||||
video_frame_info_t *video_info,
|
||||
unsigned width, unsigned height, bool fullscreen)
|
||||
{
|
||||
#if defined(HAVE_COCOA_METAL)
|
||||
NSView *g_view = apple_platform.renderView;
|
||||
#elif defined(HAVE_COCOA)
|
||||
CocoaView *g_view = (CocoaView*)nsview_get_ptr();
|
||||
#endif
|
||||
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)data;
|
||||
|
||||
cocoa_ctx->width = width;
|
||||
cocoa_ctx->height = height;
|
||||
|
||||
switch (cocoagl_api)
|
||||
{
|
||||
case GFX_CTX_OPENGL_API:
|
||||
case GFX_CTX_OPENGL_ES_API:
|
||||
{
|
||||
#if defined(HAVE_COCOA_METAL)
|
||||
if ([g_view respondsToSelector: @selector(setWantsBestResolutionOpenGLSurface:)])
|
||||
[g_view setWantsBestResolutionOpenGLSurface:YES];
|
||||
|
||||
NSOpenGLPixelFormatAttribute attributes [] = {
|
||||
NSOpenGLPFAColorSize,
|
||||
24,
|
||||
NSOpenGLPFADoubleBuffer,
|
||||
NSOpenGLPFAAllowOfflineRenderers,
|
||||
NSOpenGLPFADepthSize,
|
||||
(NSOpenGLPixelFormatAttribute)16, // 16 bit depth buffer
|
||||
0, /* profile */
|
||||
0, /* profile enum */
|
||||
(NSOpenGLPixelFormatAttribute)0
|
||||
};
|
||||
|
||||
#if MAC_OS_X_VERSION_10_7
|
||||
if (g_major == 3 && (g_minor >= 1 && g_minor <= 3))
|
||||
{
|
||||
attributes[6] = NSOpenGLPFAOpenGLProfile;
|
||||
attributes[7] = NSOpenGLProfileVersion3_2Core;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if MAC_OS_X_VERSION_10_10
|
||||
if (g_major == 4 && g_minor == 1)
|
||||
{
|
||||
attributes[6] = NSOpenGLPFAOpenGLProfile;
|
||||
attributes[7] = NSOpenGLProfileVersion4_1Core;
|
||||
}
|
||||
#endif
|
||||
|
||||
g_format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
|
||||
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1050
|
||||
if (g_format == nil)
|
||||
{
|
||||
/* NSOpenGLFPAAllowOfflineRenderers is
|
||||
not supported on this OS version. */
|
||||
attributes[3] = (NSOpenGLPixelFormatAttribute)0;
|
||||
g_format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
|
||||
}
|
||||
#endif
|
||||
|
||||
if (g_use_hw_ctx)
|
||||
g_hw_ctx = [[NSOpenGLContext alloc] initWithFormat:g_format shareContext:nil];
|
||||
g_context = [[NSOpenGLContext alloc] initWithFormat:g_format shareContext:(g_use_hw_ctx) ? g_hw_ctx : nil];
|
||||
[g_context setView:g_view];
|
||||
#else
|
||||
if (g_use_hw_ctx)
|
||||
g_hw_ctx = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
||||
g_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
||||
g_view.context = g_context;
|
||||
#endif
|
||||
|
||||
[g_context makeCurrentContext];
|
||||
break;
|
||||
}
|
||||
case GFX_CTX_VULKAN_API:
|
||||
#ifdef HAVE_VULKAN
|
||||
RARCH_LOG("[macOS]: Native window size: %u x %u.\n", cocoa_ctx->width, cocoa_ctx->height);
|
||||
if (!vulkan_surface_create(&cocoa_ctx->vk,
|
||||
VULKAN_WSI_MVK_MACOS, NULL,
|
||||
(BRIDGE void *)g_view, cocoa_ctx->width, cocoa_ctx->height,
|
||||
cocoa_ctx->swap_interval))
|
||||
{
|
||||
RARCH_ERR("[macOS]: Failed to create surface.\n");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case GFX_CTX_NONE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
#if defined(HAVE_COCOA_METAL)
|
||||
static bool has_went_fullscreen = false;
|
||||
/* TODO: Screen mode support. */
|
||||
|
||||
if (fullscreen)
|
||||
{
|
||||
if (!has_went_fullscreen)
|
||||
{
|
||||
[g_view enterFullScreenMode:(BRIDGE NSScreen *)get_chosen_screen() withOptions:nil];
|
||||
cocoagl_gfx_ctx_show_mouse(data, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (has_went_fullscreen)
|
||||
{
|
||||
[g_view exitFullScreenModeWithOptions:nil];
|
||||
[[g_view window] makeFirstResponder:g_view];
|
||||
cocoagl_gfx_ctx_show_mouse(data, true);
|
||||
}
|
||||
|
||||
[[g_view window] setContentSize:NSMakeSize(width, height)];
|
||||
}
|
||||
|
||||
has_went_fullscreen = fullscreen;
|
||||
#endif
|
||||
|
||||
/* TODO: Maybe iOS users should be able to show/hide the status bar here? */
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool cocoagl_gfx_ctx_set_resize(void *data, unsigned width, unsigned height)
|
||||
{
|
||||
#ifdef HAVE_VULKAN
|
||||
|
@ -654,3 +654,175 @@ static void *cocoagl_gfx_ctx_get_context_data(void *data)
|
||||
return &cocoa_ctx->vk.context;
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool cocoagl_gfx_ctx_set_video_mode(void *data,
|
||||
video_frame_info_t *video_info,
|
||||
unsigned width, unsigned height, bool fullscreen)
|
||||
{
|
||||
#if defined(HAVE_COCOA_METAL)
|
||||
NSView *g_view = apple_platform.renderView;
|
||||
#elif defined(HAVE_COCOA)
|
||||
CocoaView *g_view = (CocoaView*)nsview_get_ptr();
|
||||
#endif
|
||||
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)data;
|
||||
|
||||
#if defined(HAVE_COCOA_METAL)
|
||||
cocoa_ctx->width = width;
|
||||
cocoa_ctx->height = height;
|
||||
#endif
|
||||
|
||||
switch (cocoagl_api)
|
||||
{
|
||||
case GFX_CTX_OPENGL_API:
|
||||
case GFX_CTX_OPENGL_ES_API:
|
||||
{
|
||||
#if defined(HAVE_COCOA) || defined(HAVE_COCOA_METAL)
|
||||
if ([g_view respondsToSelector: @selector(setWantsBestResolutionOpenGLSurface:)])
|
||||
[g_view setWantsBestResolutionOpenGLSurface:YES];
|
||||
|
||||
NSOpenGLPixelFormatAttribute attributes [] = {
|
||||
NSOpenGLPFAColorSize,
|
||||
24,
|
||||
NSOpenGLPFADoubleBuffer,
|
||||
NSOpenGLPFAAllowOfflineRenderers,
|
||||
NSOpenGLPFADepthSize,
|
||||
(NSOpenGLPixelFormatAttribute)16, // 16 bit depth buffer
|
||||
0, /* profile */
|
||||
0, /* profile enum */
|
||||
(NSOpenGLPixelFormatAttribute)0
|
||||
};
|
||||
|
||||
#if MAC_OS_X_VERSION_10_7
|
||||
if (g_major == 3 && (g_minor >= 1 && g_minor <= 3))
|
||||
{
|
||||
attributes[6] = NSOpenGLPFAOpenGLProfile;
|
||||
attributes[7] = NSOpenGLProfileVersion3_2Core;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if MAC_OS_X_VERSION_10_10
|
||||
if (g_major == 4 && g_minor == 1)
|
||||
{
|
||||
attributes[6] = NSOpenGLPFAOpenGLProfile;
|
||||
attributes[7] = NSOpenGLProfileVersion4_1Core;
|
||||
}
|
||||
#endif
|
||||
|
||||
g_format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
|
||||
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1050
|
||||
if (g_format == nil)
|
||||
{
|
||||
/* NSOpenGLFPAAllowOfflineRenderers is
|
||||
not supported on this OS version. */
|
||||
attributes[3] = (NSOpenGLPixelFormatAttribute)0;
|
||||
g_format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
|
||||
}
|
||||
#endif
|
||||
|
||||
if (g_use_hw_ctx)
|
||||
g_hw_ctx = [[NSOpenGLContext alloc] initWithFormat:g_format shareContext:nil];
|
||||
g_context = [[NSOpenGLContext alloc] initWithFormat:g_format shareContext:(g_use_hw_ctx) ? g_hw_ctx : nil];
|
||||
[g_context setView:g_view];
|
||||
#else
|
||||
if (g_use_hw_ctx)
|
||||
g_hw_ctx = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
||||
g_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
||||
g_view.context = g_context;
|
||||
#endif
|
||||
|
||||
[g_context makeCurrentContext];
|
||||
break;
|
||||
}
|
||||
case GFX_CTX_VULKAN_API:
|
||||
#ifdef HAVE_VULKAN
|
||||
RARCH_LOG("[macOS]: Native window size: %u x %u.\n", cocoa_ctx->width, cocoa_ctx->height);
|
||||
if (!vulkan_surface_create(&cocoa_ctx->vk,
|
||||
VULKAN_WSI_MVK_MACOS, NULL,
|
||||
(BRIDGE void *)g_view, cocoa_ctx->width, cocoa_ctx->height,
|
||||
cocoa_ctx->swap_interval))
|
||||
{
|
||||
RARCH_ERR("[macOS]: Failed to create surface.\n");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case GFX_CTX_NONE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
#if defined(HAVE_COCOA_METAL)
|
||||
static bool has_went_fullscreen = false;
|
||||
/* TODO: Screen mode support. */
|
||||
|
||||
if (fullscreen)
|
||||
{
|
||||
if (!has_went_fullscreen)
|
||||
{
|
||||
#if defined(HAVE_COCOA_METAL)
|
||||
[g_view enterFullScreenMode:(BRIDGE NSScreen *)get_chosen_screen() withOptions:nil];
|
||||
#elif defined(HAVE_COCOA)
|
||||
[g_view enterFullScreenMode:get_chosen_screen() withOptions:nil];
|
||||
#endif
|
||||
cocoagl_gfx_ctx_show_mouse(data, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (has_went_fullscreen)
|
||||
{
|
||||
[g_view exitFullScreenModeWithOptions:nil];
|
||||
[[g_view window] makeFirstResponder:g_view];
|
||||
cocoagl_gfx_ctx_show_mouse(data, true);
|
||||
}
|
||||
|
||||
[[g_view window] setContentSize:NSMakeSize(width, height)];
|
||||
}
|
||||
|
||||
has_went_fullscreen = fullscreen;
|
||||
#endif
|
||||
|
||||
/* TODO: Maybe iOS users should be able to show/hide the status bar here? */
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void *cocoagl_gfx_ctx_init(video_frame_info_t *video_info, void *video_driver)
|
||||
{
|
||||
cocoa_ctx_data_t *cocoa_ctx = (cocoa_ctx_data_t*)
|
||||
calloc(1, sizeof(cocoa_ctx_data_t));
|
||||
|
||||
if (!cocoa_ctx)
|
||||
return NULL;
|
||||
|
||||
switch (cocoagl_api)
|
||||
{
|
||||
#if defined(HAVE_COCOATOUCH)
|
||||
case GFX_CTX_OPENGL_ES_API:
|
||||
// setViewType is not (yet?) defined for iOS
|
||||
// [apple_platform setViewType:APPLE_VIEW_TYPE_OPENGL_ES];
|
||||
break;
|
||||
#elif defined(HAVE_COCOA_METAL)
|
||||
case GFX_CTX_OPENGL_API:
|
||||
[apple_platform setViewType:APPLE_VIEW_TYPE_OPENGL];
|
||||
break;
|
||||
#endif
|
||||
case GFX_CTX_VULKAN_API:
|
||||
#ifdef HAVE_VULKAN
|
||||
[apple_platform setViewType:APPLE_VIEW_TYPE_VULKAN];
|
||||
if (!vulkan_context_init(&cocoa_ctx->vk, VULKAN_WSI_MVK_MACOS))
|
||||
goto error;
|
||||
#endif
|
||||
break;
|
||||
case GFX_CTX_NONE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return cocoa_ctx;
|
||||
|
||||
error:
|
||||
free(cocoa_ctx);
|
||||
return NULL;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user