(Apple) Improvements:

Add core gl context support on OSX
	Add support for multiple game pads on OSX
 	Remove block on analog input for Player 2-4's game pads
This commit is contained in:
meancoot 2013-08-15 19:28:51 -04:00
parent 7d25e64fb4
commit a4dfd35ab7
6 changed files with 61 additions and 21 deletions

View File

@ -19,6 +19,7 @@
// NOTE: I pieced this together through trial and error, any corrections are welcome
static IOHIDManagerRef g_hid_manager;
static uint32_t g_num_pads;
static void hid_input_callback(void* inContext, IOReturn inResult, void* inSender, IOHIDValueRef inIOHIDValueRef)
{
@ -83,9 +84,18 @@ static void hid_input_callback(void* inContext, IOReturn inResult, void* inSende
static void hid_device_attached(void* inContext, IOReturn inResult, void* inSender, IOHIDDeviceRef inDevice)
{
void* context = 0;
if (IOHIDDeviceConformsTo(inDevice, kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick))
{
if (g_num_pads > 4)
return;
context = (void*)(g_num_pads++);
}
IOHIDDeviceOpen(inDevice, kIOHIDOptionsTypeNone);
IOHIDDeviceScheduleWithRunLoop(inDevice, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
IOHIDDeviceRegisterInputValueCallback(inDevice, hid_input_callback, 0);
IOHIDDeviceRegisterInputValueCallback(inDevice, hid_input_callback, context);
}
static void hid_device_removed(void* inContext, IOReturn inResult, void* inSender, IOHIDDeviceRef inDevice)

View File

@ -19,7 +19,7 @@
#import <AppKit/AppKit.h>
@interface RAGameView : NSOpenGLView
@interface RAGameView : NSView
+ (RAGameView*)get;
- (void)display;

View File

@ -35,6 +35,7 @@ static UIView* g_pause_indicator_view;
static RAGameView* g_instance;
static NSOpenGLContext* g_context;
static NSOpenGLPixelFormat* g_format;
#define g_view g_instance // < RAGameView is a container on iOS; on OSX these are both the same object
@ -57,25 +58,22 @@ static float g_screen_scale = 1.0f;
- (id)init
{
static const NSOpenGLPixelFormatAttribute attributes [] = {
NSOpenGLPFAWindow,
NSOpenGLPFADoubleBuffer, // double buffered
NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)16, // 16 bit depth buffer
(NSOpenGLPixelFormatAttribute)nil
};
self = [super initWithFrame:CGRectMake(0, 0, 100, 100) pixelFormat:[[NSOpenGLPixelFormat alloc] initWithAttributes:attributes]];
self.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
g_context = self.openGLContext;
[g_context makeCurrentContext];
self = [super init];
self.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
return self;
}
- (void)setFrame:(NSRect)frameRect
{
[super setFrame:frameRect];
if (g_view && g_context)
[g_context update];
}
- (void)display
{
[self.openGLContext flushBuffer];
[g_context flushBuffer];
}
- (void)bindDrawable
@ -237,6 +235,38 @@ void apple_destroy_game_view()
#endif
}
bool apple_create_gl_context(uint32_t version)
{
#ifdef OSX
[NSOpenGLContext clearCurrentContext];
dispatch_sync(dispatch_get_main_queue(), ^{
[NSOpenGLContext clearCurrentContext];
[g_context clearDrawable];
g_context = nil;
g_format = nil;
NSOpenGLPixelFormatAttribute attributes [] = {
NSOpenGLPFADoubleBuffer, // double buffered
NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)16, // 16 bit depth buffer
version ? NSOpenGLPFAOpenGLProfile : 0, version,
(NSOpenGLPixelFormatAttribute)nil
};
g_format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
g_context = [[NSOpenGLContext alloc] initWithFormat:g_format shareContext:nil];
g_context.view = g_view;
[g_context makeCurrentContext];
});
[g_context makeCurrentContext];
#endif
return true;
}
void apple_flip_game_view()
{
if (--g_fast_forward_skips < 0)
@ -255,7 +285,7 @@ void apple_set_game_view_sync(unsigned interval)
g_fast_forward_skips = interval ? 0 : 3;
#elif defined(OSX)
GLint value = interval ? 1 : 0;
[g_view.openGLContext setValues:&value forParameter:NSOpenGLCPSwapInterval];
[g_context setValues:&value forParameter:NSOpenGLCPSwapInterval];
#endif
}

View File

@ -56,7 +56,7 @@ static bool apple_joypad_button(unsigned port, uint16_t joykey)
static int16_t apple_joypad_axis(unsigned port, uint32_t joyaxis)
{
if (joyaxis == AXIS_NONE || port != 0)
if (joyaxis == AXIS_NONE)
return 0;
int16_t val = 0;

View File

@ -34,7 +34,7 @@ static bool gfx_ctx_bind_api(enum gfx_ctx_api api, unsigned major, unsigned mino
#ifdef IOS
return api == GFX_CTX_OPENGL_ES_API;
#else
return api == GFX_CTX_OPENGL_API;
return apple_create_gl_context((major << 12) | (minor << 8));
#endif
}

View File

@ -153,7 +153,7 @@ static bool check_sync_proc(gl_t *gl)
#ifndef HAVE_OPENGLES
static bool init_vao(gl_t *gl)
{
if (!gl_query_extension(gl, "ARB_vertex_array_object"))
if (!gl->core_context && !gl_query_extension(gl, "ARB_vertex_array_object"))
return false;
bool present = glGenVertexArrays && glBindVertexArray && glDeleteVertexArrays;
@ -184,7 +184,7 @@ static bool init_vao(gl_t *gl)
#elif !defined(HAVE_OPENGLES2)
static bool check_fbo_proc(gl_t *gl)
{
if (!gl_query_extension(gl, "ARB_framebuffer_object"))
if (!gl->core_context && !gl_query_extension(gl, "ARB_framebuffer_object"))
return false;
return glGenFramebuffers && glBindFramebuffer && glFramebufferTexture2D &&