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

@@ -277,10 +277,10 @@ void App::initShaders()
"in mediump vec2 uv;\n"
"out mediump vec4 frag;\n"
"void main(){\n"
" const vec4 c1 = vec4(1.0, 1.0, 1.0, 1.0);\n"
" const vec4 c2 = vec4(0.9, 0.9, 0.9, 1.0);\n"
" vec2 c = floor(fract(uv * 10.0) * 2.0);\n"
" float alpha = mix(c.x, 1.0 - c.x, c.y);\n"
" const mediump vec4 c1 = vec4(1.0, 1.0, 1.0, 1.0);\n"
" const mediump vec4 c2 = vec4(0.9, 0.9, 0.9, 1.0);\n"
" mediump vec2 c = floor(fract(uv * 10.0) * 2.0);\n"
" mediump float alpha = mix(c.x, 1.0 - c.x, c.y);\n"
" frag = mix(c1, c2, alpha);\n"
"}";
@@ -302,11 +302,11 @@ void App::initShaders()
"in mediump vec2 uv;\n"
"out mediump vec4 frag;\n"
"void main(){\n"
" float anglex = uv.x;\n"
" float angley = uv.y;\n"
" float sx = sin(anglex);\n"
" float cx = cos(anglex);\n"
" vec3 dir = vec3(0.0, 0.0, 0.0);\n"
" mediump float anglex = uv.x;\n"
" mediump float angley = uv.y;\n"
" mediump float sx = sin(anglex);\n"
" mediump float cx = cos(anglex);\n"
" mediump vec3 dir = vec3(0.0, 0.0, 0.0);\n"
" dir.x = sin(angley) * cx;\n"
" dir.y = cos(angley);\n"
" dir.z = sin(angley) * sx;\n"

View File

@@ -2,14 +2,19 @@
#include "log.h"
#include "asset.h"
#ifdef __IOS__
#include <Foundation/Foundation.h>
#endif
#ifdef __ANDROID__
AAssetManager* Asset::m_am;
#endif
bool Asset::open(const char* path)
{
//LOG("Asset::open %s", path);
LOG("Asset::open %s", path);
m_current_path = path;
std::string file_path = path;
#ifdef __ANDROID__
if (!(m_asset = AAssetManager_open(m_am, path, AASSET_MODE_RANDOM)))
{
@@ -19,8 +24,16 @@ bool Asset::open(const char* path)
m_len = (int)AAsset_getLength(m_asset);
m_data = (uint8_t*)AAsset_getBuffer(m_asset);
#else
if (!(m_fp = fopen(path, "rb")))
#ifdef __IOS__
NSString* bundle_path = [[NSBundle mainBundle] bundlePath];
std::string base = [bundle_path cStringUsingEncoding:1];
file_path = base + "/" + path;
#endif
if (!(m_fp = fopen(file_path.c_str(), "rb")))
{
LOG("errno = %d", errno);
return false;
}
fseek(m_fp, 0, SEEK_END);
m_len = (int)ftell(m_fp);
fseek(m_fp, 0, SEEK_SET);

View File

@@ -540,7 +540,8 @@ bool LayoutManager::load(const char* path)
if (m_loaded)
return true; // already loaded
#ifndef __ANDROID__
/*
#if !defined(__ANDROID__)
struct stat tmp_info;
if (stat(path, &tmp_info) != 0)
return false;
@@ -548,7 +549,8 @@ bool LayoutManager::load(const char* path)
return false;
m_file_info = tmp_info;
#endif // __ANDROID__
*/
m_path = path;
auto old = std::move(m_layouts);

View File

@@ -8,11 +8,12 @@
#include "keymap.h"
#ifdef __APPLE__
#ifdef TARGET_OS_OSX
#include <CoreFoundation/CoreFoundation.h>
#include <Cocoa/Cocoa.h>
#include <CoreVideo/CoreVideo.h>
#include <OpenGL/OpenGL.h>
@interface View : NSOpenGLView
{
CVDisplayLinkRef dl;
@@ -360,6 +361,7 @@ int main(int argc, const char * argv[])
return 0;
}
#endif
#endif
#ifdef _WIN32

View File

@@ -4,14 +4,28 @@
#define USE_SAMPLER 1
#ifdef __APPLE__
#include <OpenGL/gl3.h>
#include <OpenGL/gl3ext.h>
#include "TargetConditionals.h"
#if TARGET_OS_IPHONE && TARGET_IPHONE_SIMULATOR
#define TARGET_OS_IOS 1
#define __IOS__ 1
#include <CoreFoundation/CoreFoundation.h>
#include <OpenGLES/ES3/gl.h>
#include <OpenGLES/ES3/glext.h>
#define SHADER_VERSION "#version 300 es\n"
#elif TARGET_OS_IPHONE
// define something for iphone
#else
#define TARGET_OS_OSX 1
#include <OpenGL/gl3.h>
#include <OpenGL/gl3ext.h>
#define SHADER_VERSION "#version 150\n"
#endif
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
#define SHADER_VERSION "#version 150\n"
#elif __ANDROID__
#include <EGL/egl.h>
#include <EGL/eglext.h>
@@ -22,7 +36,7 @@
#include <android/log.h>
#include <android_native_app_glue.h>
#define SHADER_VERSION "#version 300 es\n"
#define SHADER_VERSION "#version 300 es\n"
#elif _WIN32
#define _USE_MATH_DEFINES