add iOS support

This commit is contained in:
2017-05-07 23:49:46 +01:00
parent b50011babf
commit d1ce547abd
16 changed files with 682 additions and 20 deletions

View File

@@ -0,0 +1,119 @@
//
// GameViewController.m
// PanoPainter
//
// Created by Omar Mohamed Ali Mudhir on 07/05/17.
// Copyright © 2017 Omar Mohamed Ali Mudhir. All rights reserved.
//
#include "pch.h"
#import "GameViewController.h"
#import <OpenGLES/ES3/glext.h>
#include "app.h"
@interface GameViewController () {
}
@property (strong, nonatomic) EAGLContext *context;
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator;
- (void)setupGL;
- (void)tearDownGL;
//- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event;
@end
@implementation GameViewController
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:self.view];
float scale = self.view.contentScaleFactor;
App::I.mouse_move(touchLocation.x * scale, touchLocation.y * scale);
}
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
App::I.resize(size.width * self.view.contentScaleFactor,
size.height * self.view.contentScaleFactor);
}
- (void)viewDidLoad
{
[super viewDidLoad];
App::I.initLog();
self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3];
if (!self.context) {
NSLog(@"Failed to create ES context");
}
GLKView *view = (GLKView *)self.view;
view.context = self.context;
view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
App::I.width = view.frame.size.width * view.contentScaleFactor;
App::I.height = view.frame.size.height * view.contentScaleFactor;
[self setupGL];
}
- (void)dealloc
{
[self tearDownGL];
if ([EAGLContext currentContext] == self.context) {
[EAGLContext setCurrentContext:nil];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
if ([self isViewLoaded] && ([[self view] window] == nil)) {
self.view = nil;
[self tearDownGL];
if ([EAGLContext currentContext] == self.context) {
[EAGLContext setCurrentContext:nil];
}
self.context = nil;
}
// Dispose of any resources that can be recreated.
}
- (BOOL)prefersStatusBarHidden {
return YES;
}
- (void)setupGL
{
[EAGLContext setCurrentContext:self.context];
App::I.init();
}
- (void)tearDownGL
{
[EAGLContext setCurrentContext:self.context];
}
#pragma mark - GLKView and GLKViewController delegate methods
- (void)update
{
}
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
App::I.clear();
App::I.update(0);
}
@end