(Apple GL context) Move gfx_context C files to Obj-C .m file

This commit is contained in:
twinaphex 2014-07-09 13:03:58 +02:00
parent ac941c18a3
commit 652499770f
5 changed files with 229 additions and 273 deletions

View File

@ -18,8 +18,6 @@
#include "../common/rarch_wrapper.h"
#include "../../general.h"
#include "../../gfx/gfx_common.h"
#include "../../gfx/gfx_context.h"
#ifdef HAVE_LOCATION
#include <CoreLocation/CoreLocation.h>
@ -453,179 +451,6 @@ static RAScreen* get_chosen_screen(void)
#endif
}
bool apple_gfx_ctx_init(void *data)
{
(void)data;
// Make sure the view was created
[RAGameView get];
g_initialized = true;
return true;
}
void apple_gfx_ctx_destroy(void *data)
{
(void)data;
g_initialized = false;
[GLContextClass clearCurrentContext];
#ifdef IOS
g_view.context = nil;
#endif
[GLContextClass clearCurrentContext];
g_context = nil;
}
bool apple_gfx_ctx_bind_api(void *data, enum gfx_ctx_api api, unsigned major, unsigned minor)
{
(void)data;
if (api != GLAPIType)
return false;
[GLContextClass clearCurrentContext];
#ifdef OSX
[g_context clearDrawable];
[g_context release], g_context = nil;
[g_format release], g_format = nil;
NSOpenGLPixelFormatAttribute attributes [] = {
NSOpenGLPFADoubleBuffer, // double buffered
NSOpenGLPFADepthSize,
(NSOpenGLPixelFormatAttribute)16, // 16 bit depth buffer
#ifdef MAC_OS_X_VERSION_10_7
(major || minor) ? NSOpenGLPFAOpenGLProfile : 0,
(major << 12) | (minor << 8),
#endif
(NSOpenGLPixelFormatAttribute)nil
};
[g_format release];
[g_context release];
g_format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
g_context = [[NSOpenGLContext alloc] initWithFormat:g_format shareContext:nil];
[g_context setView:g_view];
#else
g_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
g_view.context = g_context;
#endif
[g_context makeCurrentContext];
return true;
}
void apple_gfx_ctx_swap_interval(void *data, unsigned interval)
{
(void)data;
#ifdef IOS // < No way to disable Vsync on iOS?
// Just skip presents so fast forward still works.
g_is_syncing = interval ? true : false;
g_fast_forward_skips = interval ? 0 : 3;
#elif defined(OSX)
GLint value = interval ? 1 : 0;
[g_context setValues:&value forParameter:NSOpenGLCPSwapInterval];
#endif
}
bool apple_gfx_ctx_set_video_mode(void *data, unsigned width, unsigned height, bool fullscreen)
{
(void)data;
#ifdef OSX
// TODO: Sceen mode support
if (fullscreen && !g_has_went_fullscreen)
{
[g_view enterFullScreenMode:get_chosen_screen() withOptions:nil];
[NSCursor hide];
}
else if (!fullscreen && g_has_went_fullscreen)
{
[g_view exitFullScreenModeWithOptions:nil];
[[g_view window] makeFirstResponder:g_view];
[NSCursor unhide];
}
g_has_went_fullscreen = fullscreen;
if (!g_has_went_fullscreen)
[[g_view window] setContentSize:NSMakeSize(width, height)];
#endif
// TODO: Maybe iOS users should be apple to show/hide the status bar here?
return true;
}
void apple_gfx_ctx_get_video_size(void *data, unsigned* width, unsigned* height)
{
RAScreen *screen = (RAScreen*)get_chosen_screen();
CGRect size = screen.bounds;
(void)data;
if (g_initialized)
{
#if defined(OSX)
CGRect cgrect = (CGRect)NSRectToCGRect([g_view frame]);
size = CGRectMake(0, 0, CGRectGetWidth(cgrect), CGRectGetHeight(cgrect));
#else
size = g_view.bounds;
#endif
}
*width = CGRectGetWidth(size) * screen.scale;
*height = CGRectGetHeight(size) * screen.scale;
}
void apple_gfx_ctx_update_window_title(void *data)
{
static char buf[128], buf_fps[128];
bool fps_draw, got_text;
(void)data;
(void)got_text;
fps_draw = g_settings.fps_show;
got_text = gfx_get_fps(buf, sizeof(buf), fps_draw ? buf_fps : NULL, sizeof(buf_fps));
static const char* const text = buf; // < Can't access buf directly in the block
(void)text;
#ifdef OSX
if (got_text)
[[g_view window] setTitle:[NSString stringWithCString:text encoding:NSUTF8StringEncoding]];
#endif
if (fps_draw)
msg_queue_push(g_extern.msg_queue, buf_fps, 1, 1);
}
bool apple_gfx_ctx_has_focus(void *data)
{
(void)data;
return APP_HAS_FOCUS;
}
void apple_gfx_ctx_swap_buffers(void *data)
{
bool swap;
(void)data;
swap = --g_fast_forward_skips < 0;
if (!swap)
return;
[g_view display];
g_fast_forward_skips = g_is_syncing ? 0 : 3;
}
gfx_ctx_proc_t apple_gfx_ctx_get_proc_address(const char *symbol_name)
{
#ifdef MAC_OS_X_VERSION_10_7
return (gfx_ctx_proc_t)CFBundleGetFunctionPointerForName(CFBundleGetBundleWithIdentifier(GLFrameworkID),
(__bridge CFStringRef)BOXSTRING(symbol_name));
#else
return (gfx_ctx_proc_t)CFBundleGetFunctionPointerForName(CFBundleGetBundleWithIdentifier(GLFrameworkID),
(CFStringRef)BOXSTRING(symbol_name));
#endif
}
#ifdef IOS
void apple_bind_game_view_fbo(void)
@ -643,3 +468,5 @@ void apple_bind_game_view_fbo(void)
#ifdef HAVE_LOCATION
#include "apple_location.c.inl"
#endif
#include "apple_gfx_context.c.inl"

View File

@ -0,0 +1,227 @@
#include "../../gfx/gfx_common.h"
#include "../../gfx/gfx_context.h"
static bool apple_gfx_ctx_init(void *data)
{
(void)data;
// Make sure the view was created
[RAGameView get];
g_initialized = true;
return true;
}
static void apple_gfx_ctx_destroy(void *data)
{
(void)data;
g_initialized = false;
[GLContextClass clearCurrentContext];
#ifdef IOS
g_view.context = nil;
#endif
[GLContextClass clearCurrentContext];
g_context = nil;
}
static bool apple_gfx_ctx_bind_api(void *data, enum gfx_ctx_api api, unsigned major, unsigned minor)
{
(void)data;
if (api != GLAPIType)
return false;
[GLContextClass clearCurrentContext];
#ifdef OSX
[g_context clearDrawable];
[g_context release], g_context = nil;
[g_format release], g_format = nil;
NSOpenGLPixelFormatAttribute attributes [] = {
NSOpenGLPFADoubleBuffer, // double buffered
NSOpenGLPFADepthSize,
(NSOpenGLPixelFormatAttribute)16, // 16 bit depth buffer
#ifdef MAC_OS_X_VERSION_10_7
(major || minor) ? NSOpenGLPFAOpenGLProfile : 0,
(major << 12) | (minor << 8),
#endif
(NSOpenGLPixelFormatAttribute)nil
};
[g_format release];
[g_context release];
g_format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
g_context = [[NSOpenGLContext alloc] initWithFormat:g_format shareContext:nil];
[g_context setView:g_view];
#else
g_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
g_view.context = g_context;
#endif
[g_context makeCurrentContext];
return true;
}
static void apple_gfx_ctx_swap_interval(void *data, unsigned interval)
{
(void)data;
#ifdef IOS // < No way to disable Vsync on iOS?
// Just skip presents so fast forward still works.
g_is_syncing = interval ? true : false;
g_fast_forward_skips = interval ? 0 : 3;
#elif defined(OSX)
GLint value = interval ? 1 : 0;
[g_context setValues:&value forParameter:NSOpenGLCPSwapInterval];
#endif
}
static bool apple_gfx_ctx_set_video_mode(void *data, unsigned width, unsigned height, bool fullscreen)
{
(void)data;
#ifdef OSX
// TODO: Sceen mode support
if (fullscreen && !g_has_went_fullscreen)
{
[g_view enterFullScreenMode:get_chosen_screen() withOptions:nil];
[NSCursor hide];
}
else if (!fullscreen && g_has_went_fullscreen)
{
[g_view exitFullScreenModeWithOptions:nil];
[[g_view window] makeFirstResponder:g_view];
[NSCursor unhide];
}
g_has_went_fullscreen = fullscreen;
if (!g_has_went_fullscreen)
[[g_view window] setContentSize:NSMakeSize(width, height)];
#endif
// TODO: Maybe iOS users should be apple to show/hide the status bar here?
return true;
}
static void apple_gfx_ctx_get_video_size(void *data, unsigned* width, unsigned* height)
{
RAScreen *screen = (RAScreen*)get_chosen_screen();
CGRect size = screen.bounds;
(void)data;
if (g_initialized)
{
#if defined(OSX)
CGRect cgrect = (CGRect)NSRectToCGRect([g_view frame]);
size = CGRectMake(0, 0, CGRectGetWidth(cgrect), CGRectGetHeight(cgrect));
#else
size = g_view.bounds;
#endif
}
*width = CGRectGetWidth(size) * screen.scale;
*height = CGRectGetHeight(size) * screen.scale;
}
static void apple_gfx_ctx_update_window_title(void *data)
{
static char buf[128], buf_fps[128];
bool fps_draw, got_text;
(void)data;
(void)got_text;
fps_draw = g_settings.fps_show;
got_text = gfx_get_fps(buf, sizeof(buf), fps_draw ? buf_fps : NULL, sizeof(buf_fps));
static const char* const text = buf; // < Can't access buf directly in the block
(void)text;
#ifdef OSX
if (got_text)
[[g_view window] setTitle:[NSString stringWithCString:text encoding:NSUTF8StringEncoding]];
#endif
if (fps_draw)
msg_queue_push(g_extern.msg_queue, buf_fps, 1, 1);
}
static bool apple_gfx_ctx_has_focus(void *data)
{
(void)data;
return APP_HAS_FOCUS;
}
static void apple_gfx_ctx_swap_buffers(void *data)
{
bool swap;
(void)data;
swap = --g_fast_forward_skips < 0;
if (!swap)
return;
[g_view display];
g_fast_forward_skips = g_is_syncing ? 0 : 3;
}
static gfx_ctx_proc_t apple_gfx_ctx_get_proc_address(const char *symbol_name)
{
#ifdef MAC_OS_X_VERSION_10_7
return (gfx_ctx_proc_t)CFBundleGetFunctionPointerForName(CFBundleGetBundleWithIdentifier(GLFrameworkID),
(__bridge CFStringRef)BOXSTRING(symbol_name));
#else
return (gfx_ctx_proc_t)CFBundleGetFunctionPointerForName(CFBundleGetBundleWithIdentifier(GLFrameworkID),
(CFStringRef)BOXSTRING(symbol_name));
#endif
}
static void gfx_ctx_check_window(void *data, bool *quit,
bool *resize, unsigned *width, unsigned *height, unsigned frame_count)
{
(void)frame_count;
*quit = false;
unsigned new_width, new_height;
apple_gfx_ctx_get_video_size(data, &new_width, &new_height);
if (new_width != *width || new_height != *height)
{
*width = new_width;
*height = new_height;
*resize = true;
}
}
static void gfx_ctx_set_resize(void *data, unsigned width, unsigned height)
{
(void)data;
(void)width;
(void)height;
}
static void gfx_ctx_input_driver(void *data, const input_driver_t **input, void **input_data)
{
(void)data;
*input = NULL;
*input_data = NULL;
}
// The apple_* functions are implemented in apple/RetroArch/RAGameView.m
const gfx_ctx_driver_t gfx_ctx_apple = {
apple_gfx_ctx_init,
apple_gfx_ctx_destroy,
apple_gfx_ctx_bind_api,
apple_gfx_ctx_swap_interval,
apple_gfx_ctx_set_video_mode,
apple_gfx_ctx_get_video_size,
NULL,
apple_gfx_ctx_update_window_title,
gfx_ctx_check_window,
gfx_ctx_set_resize,
apple_gfx_ctx_has_focus,
apple_gfx_ctx_swap_buffers,
gfx_ctx_input_driver,
apple_gfx_ctx_get_proc_address,
NULL,
"apple",
};

View File

@ -19,20 +19,4 @@
#include "../../gfx/gfx_context.h"
// These functions must only be called in gfx/context/apple_gl_context.c
bool apple_gfx_ctx_init(void *data);
void apple_gfx_ctx_destroy(void *data);
bool apple_gfx_ctx_bind_api(void *data, enum gfx_ctx_api api, unsigned major, unsigned minor);
void apple_gfx_ctx_swap_interval(void *data, unsigned interval);
bool apple_gfx_ctx_set_video_mode(void *data, unsigned width, unsigned height, bool fullscreen);
void apple_gfx_ctx_get_video_size(void *data, unsigned* width, unsigned* height);
void apple_gfx_ctx_update_window_title(void *data);
bool apple_gfx_ctx_has_focus(void *data);
void apple_gfx_ctx_swap_buffers(void *data);
gfx_ctx_proc_t apple_gfx_ctx_get_proc_address(const char *symbol_name);
#ifdef IOS
void apple_bind_game_view_fbo(void);
#endif
#endif

View File

@ -1,80 +0,0 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2012-2014 - Jason Fetters
* Copyright (C) 2011-2014 - Daniel De Matteis
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "../../driver.h"
#include "../gfx_common.h"
#include "../gl_common.h"
#include "../image/image.h"
#include "../fonts/gl_font.h"
#include <stdint.h>
#ifdef HAVE_GLSL
#include "../shader_glsl.h"
#endif
#include "../../apple/common/rarch_wrapper.h"
static void gfx_ctx_check_window(void *data, bool *quit,
bool *resize, unsigned *width, unsigned *height, unsigned frame_count)
{
(void)frame_count;
*quit = false;
unsigned new_width, new_height;
apple_gfx_ctx_get_video_size(data, &new_width, &new_height);
if (new_width != *width || new_height != *height)
{
*width = new_width;
*height = new_height;
*resize = true;
}
}
static void gfx_ctx_set_resize(void *data, unsigned width, unsigned height)
{
(void)data;
(void)width;
(void)height;
}
static void gfx_ctx_input_driver(void *data, const input_driver_t **input, void **input_data)
{
(void)data;
*input = NULL;
*input_data = NULL;
}
// The apple_* functions are implemented in apple/RetroArch/RAGameView.m
const gfx_ctx_driver_t gfx_ctx_apple = {
apple_gfx_ctx_init,
apple_gfx_ctx_destroy,
apple_gfx_ctx_bind_api,
apple_gfx_ctx_swap_interval,
apple_gfx_ctx_set_video_mode,
apple_gfx_ctx_get_video_size,
NULL,
apple_gfx_ctx_update_window_title,
gfx_ctx_check_window,
gfx_ctx_set_resize,
apple_gfx_ctx_has_focus,
apple_gfx_ctx_swap_buffers,
gfx_ctx_input_driver,
apple_gfx_ctx_get_proc_address,
NULL,
"apple",
};

View File

@ -114,8 +114,6 @@ VIDEO CONTEXT
#include "../gfx/context/androidegl_ctx.c"
#elif defined(__QNX__)
#include "../gfx/context/bbqnx_ctx.c"
#elif defined(IOS) || defined(OSX)
#include "../gfx/context/apple_gl_ctx.c"
#elif defined(EMSCRIPTEN)
#include "../gfx/context/emscriptenegl_ctx.c"
#endif