ios: Change ioseagl_ctx to a C file that uses external functions to interact with obj-c.

This commit is contained in:
meancoot 2013-02-07 08:58:36 -05:00
parent 8315a05f5f
commit ec51c819a3
6 changed files with 80 additions and 51 deletions

View File

@ -26,42 +26,6 @@
#include "../shader_glsl.h"
#endif
#import "../../ios/RetroArch/ViewController.h"
static GLKView *gl_view;
static float screen_scale;
// Objective-C interface used to interact with the GLES context and display.
@interface ViewController ()
@property (strong, nonatomic) EAGLContext *context;
@property (strong, nonatomic) GLKView *view;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
self.view = [[GLKView alloc] initWithFrame:CGRectMake(0, 0, 640, 480) context:self.context];
[EAGLContext setCurrentContext:self.context];
gl_view = self.view;
screen_scale = [[UIScreen mainScreen] scale];
}
- (void)dealloc
{
if ([EAGLContext currentContext] == self.context) [EAGLContext setCurrentContext:nil];
}
@end
// C interface
static void gfx_ctx_set_swap_interval(unsigned interval)
{
@ -75,8 +39,8 @@ static void gfx_ctx_destroy(void)
static void gfx_ctx_get_video_size(unsigned *width, unsigned *height)
{
*width = gl_view.bounds.size.width * screen_scale;
*height = gl_view.bounds.size.height * screen_scale;
extern void get_game_view_size(unsigned *, unsigned *);
get_game_view_size(width, height);
}
static bool gfx_ctx_init(void)
@ -86,8 +50,8 @@ static bool gfx_ctx_init(void)
static void gfx_ctx_swap_buffers(void)
{
[gl_view setNeedsDisplay];
[gl_view bindDrawable];
extern void flip_game_view();
flip_game_view();
}
static void gfx_ctx_check_window(bool *quit,

View File

@ -8,6 +8,8 @@
/* Begin PBXBuildFile section */
9629797716C3CD2400E6DCE0 /* dirlist.m in Sources */ = {isa = PBXBuildFile; fileRef = 9629797616C3CD2400E6DCE0 /* dirlist.m */; };
962979ED16C3E86F00E6DCE0 /* gameview.m in Sources */ = {isa = PBXBuildFile; fileRef = 962979EB16C3E86F00E6DCE0 /* gameview.m */; };
962979EF16C3EA3E00E6DCE0 /* ioseagl_ctx.c in Sources */ = {isa = PBXBuildFile; fileRef = 962979EE16C3EA3E00E6DCE0 /* ioseagl_ctx.c */; };
968A572A16C2A06800BE12F8 /* test.img in Resources */ = {isa = PBXBuildFile; fileRef = 968A572816C2A06800BE12F8 /* test.img */; };
96AFAE2A16C1D4EA009DE44C /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96AFAE2916C1D4EA009DE44C /* UIKit.framework */; };
96AFAE2C16C1D4EA009DE44C /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96AFAE2B16C1D4EA009DE44C /* Foundation.framework */; };
@ -70,7 +72,6 @@
96AFAFAD16C1EEE9009DE44C /* sinc.c in Sources */ = {isa = PBXBuildFile; fileRef = 96AFAEF716C1DC73009DE44C /* sinc.c */; };
96AFAFD416C1FBC0009DE44C /* input_common.c in Sources */ = {isa = PBXBuildFile; fileRef = 96AFAFC916C1FBC0009DE44C /* input_common.c */; };
96AFAFD716C1FBC0009DE44C /* null.c in Sources */ = {isa = PBXBuildFile; fileRef = 96AFAFCD16C1FBC0009DE44C /* null.c */; };
96AFAFDD16C2149A009DE44C /* ioseagl_ctx.m in Sources */ = {isa = PBXBuildFile; fileRef = 96AFAFDC16C2149A009DE44C /* ioseagl_ctx.m */; };
96CF014F16C2BB9E00ABF9C9 /* libretro.dylib in Resources */ = {isa = PBXBuildFile; fileRef = 96CF014A16C2BA1900ABF9C9 /* libretro.dylib */; };
96CF015016C2C0B700ABF9C9 /* overlay.c in Sources */ = {isa = PBXBuildFile; fileRef = 96AFAFCE16C1FBC0009DE44C /* overlay.c */; };
96CF015C16C2F72900ABF9C9 /* ios_input.c in Sources */ = {isa = PBXBuildFile; fileRef = 96CF015B16C2F72900ABF9C9 /* ios_input.c */; };
@ -79,6 +80,9 @@
/* Begin PBXFileReference section */
9629797516C3CD2400E6DCE0 /* dirlist.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = dirlist.h; sourceTree = "<group>"; };
9629797616C3CD2400E6DCE0 /* dirlist.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = dirlist.m; sourceTree = "<group>"; };
962979EB16C3E86F00E6DCE0 /* gameview.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = gameview.m; sourceTree = "<group>"; };
962979EC16C3E86F00E6DCE0 /* gameview.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = gameview.h; sourceTree = "<group>"; };
962979EE16C3EA3E00E6DCE0 /* ioseagl_ctx.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ioseagl_ctx.c; sourceTree = "<group>"; };
968A572816C2A06800BE12F8 /* test.img */ = {isa = PBXFileReference; lastKnownFileType = file; path = test.img; sourceTree = "<group>"; };
96AFAE2516C1D4EA009DE44C /* RetroArch.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RetroArch.app; sourceTree = BUILT_PRODUCTS_DIR; };
96AFAE2916C1D4EA009DE44C /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
@ -95,7 +99,6 @@
96AFAE3F16C1D4EA009DE44C /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Default.png; sourceTree = "<group>"; };
96AFAE4116C1D4EA009DE44C /* Default@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default@2x.png"; sourceTree = "<group>"; };
96AFAE4316C1D4EA009DE44C /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = "<group>"; };
96AFAE4916C1D4EA009DE44C /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = "<group>"; };
96AFAE4D16C1D4EA009DE44C /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/ViewController_iPhone.xib; sourceTree = "<group>"; };
96AFAE5016C1D4EA009DE44C /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/ViewController_iPad.xib; sourceTree = "<group>"; };
96AFAE9D16C1D9A9009DE44C /* autosave.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = autosave.c; path = ../autosave.c; sourceTree = "<group>"; };
@ -265,7 +268,6 @@
96AFAFD016C1FBC0009DE44C /* sdl_input.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sdl_input.c; sourceTree = "<group>"; };
96AFAFD116C1FBC0009DE44C /* sdl_joypad.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sdl_joypad.c; sourceTree = "<group>"; };
96AFAFD216C1FBC0009DE44C /* x11_input.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = x11_input.c; sourceTree = "<group>"; };
96AFAFDC16C2149A009DE44C /* ioseagl_ctx.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ioseagl_ctx.m; sourceTree = "<group>"; };
96CF014A16C2BA1900ABF9C9 /* libretro.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; path = libretro.dylib; sourceTree = "<group>"; };
96CF015B16C2F72900ABF9C9 /* ios_input.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ios_input.c; sourceTree = "<group>"; };
/* End PBXFileReference section */
@ -325,9 +327,10 @@
96AFAE3316C1D4EA009DE44C /* RetroArch */ = {
isa = PBXGroup;
children = (
962979EB16C3E86F00E6DCE0 /* gameview.m */,
962979EC16C3E86F00E6DCE0 /* gameview.h */,
96AFAE3C16C1D4EA009DE44C /* AppDelegate.h */,
96AFAE3D16C1D4EA009DE44C /* AppDelegate.m */,
96AFAE4916C1D4EA009DE44C /* ViewController.h */,
96AFAE4C16C1D4EA009DE44C /* ViewController_iPhone.xib */,
96AFAE4F16C1D4EA009DE44C /* ViewController_iPad.xib */,
96AFAE3416C1D4EA009DE44C /* Supporting Files */,
@ -543,7 +546,7 @@
96AFAF3216C1E00A009DE44C /* context */ = {
isa = PBXGroup;
children = (
96AFAFDC16C2149A009DE44C /* ioseagl_ctx.m */,
962979EE16C3EA3E00E6DCE0 /* ioseagl_ctx.c */,
96AFAF3316C1E00A009DE44C /* androidegl_ctx.c */,
96AFAF3416C1E00A009DE44C /* drm_egl_ctx.c */,
96AFAF3516C1E00A009DE44C /* glx_ctx.c */,
@ -775,10 +778,11 @@
96AFAFAD16C1EEE9009DE44C /* sinc.c in Sources */,
96AFAFD416C1FBC0009DE44C /* input_common.c in Sources */,
96AFAFD716C1FBC0009DE44C /* null.c in Sources */,
96AFAFDD16C2149A009DE44C /* ioseagl_ctx.m in Sources */,
96CF015016C2C0B700ABF9C9 /* overlay.c in Sources */,
96CF015C16C2F72900ABF9C9 /* ios_input.c in Sources */,
9629797716C3CD2400E6DCE0 /* dirlist.m in Sources */,
962979ED16C3E86F00E6DCE0 /* gameview.m in Sources */,
962979EF16C3EA3E00E6DCE0 /* ioseagl_ctx.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@ -13,6 +13,6 @@
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ViewController *viewController;
@property (strong, nonatomic) UIViewController *viewController;
@end

View File

@ -7,7 +7,7 @@
#import "AppDelegate.h"
#import "ViewController.h"
#import "gameview.h"
#include "general.h"
@ -101,9 +101,9 @@ extern int16_t IOS_full_x, IOS_full_y;
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
self.viewController = [[game_view alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
else
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
self.viewController = [[game_view alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];

View File

@ -8,6 +8,6 @@
#import <UIKit/UIKit.h>
#import <GLKit/GLKit.h>
@interface ViewController : UIViewController
@interface game_view : UIViewController
@end

61
ios/RetroArch/gameview.m Normal file
View File

@ -0,0 +1,61 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2013 - Hans-Kristian Arntzen
* Copyright (C) 2011-2013 - 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/>.
*/
#import "gameview.h"
static GLKView *gl_view;
static float screen_scale;
@interface game_view ()
@property (strong, nonatomic) EAGLContext *context;
@property (strong, nonatomic) GLKView *view;
@end
@implementation game_view
- (void)viewDidLoad
{
[super viewDidLoad];
self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
self.view = [[GLKView alloc] initWithFrame:CGRectMake(0, 0, 640, 480) context:self.context];
[EAGLContext setCurrentContext:self.context];
gl_view = self.view;
screen_scale = [[UIScreen mainScreen] scale];
}
- (void)dealloc
{
if ([EAGLContext currentContext] == self.context) [EAGLContext setCurrentContext:nil];
}
@end
void flip_game_view()
{
[gl_view setNeedsDisplay];
[gl_view bindDrawable];
}
void get_game_view_size(unsigned *width, unsigned *height)
{
*width = gl_view.bounds.size.width * screen_scale;
*height = gl_view.bounds.size.height * screen_scale;
}