From cc7cda7252d88e06e1cb31d35ff899b7e4bc048d Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 1 Dec 2013 14:41:18 +0100 Subject: [PATCH] (iOS) Skeleton camera driver --- apple/RetroArch_iOS.xcodeproj/project.pbxproj | 4 + camera/ios.c | 110 ++++++++++++++++++ config.def.h | 3 + driver.c | 3 + driver.h | 1 + griffin/griffin.c | 2 + settings.c | 2 + 7 files changed, 125 insertions(+) create mode 100644 camera/ios.c diff --git a/apple/RetroArch_iOS.xcodeproj/project.pbxproj b/apple/RetroArch_iOS.xcodeproj/project.pbxproj index 714c4e8745..24061f5980 100644 --- a/apple/RetroArch_iOS.xcodeproj/project.pbxproj +++ b/apple/RetroArch_iOS.xcodeproj/project.pbxproj @@ -339,6 +339,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 6.0; ONLY_ACTIVE_ARCH = YES; OTHER_CFLAGS = ( + "-DHAVE_CAMERA", "-DHAVE_GRIFFIN", "-DHAVE_RGUI", "-DHAVE_MENU", @@ -389,6 +390,7 @@ OTHER_CFLAGS = ( "-DNS_BLOCK_ASSERTIONS=1", "-DNDEBUG", + "-DHAVE_CAMERA", "-DHAVE_GRIFFIN", "-DHAVE_RGUI", "-DHAVE_MENU", @@ -433,6 +435,7 @@ LIBRARY_SEARCH_PATHS = ""; OTHER_CFLAGS = ( "-DHAVE_RARCH_MAIN_WRAP", + "-DHAVE_CAMERA", "-DHAVE_GRIFFIN", "-DHAVE_RGUI", "-DHAVE_MENU", @@ -476,6 +479,7 @@ "-DNS_BLOCK_ASSERTIONS=1", "-DNDEBUG", "-DHAVE_RARCH_MAIN_WRAP", + "-DHAVE_CAMERA", "-DHAVE_GRIFFIN", "-DHAVE_RGUI", "-DHAVE_MENU", diff --git a/camera/ios.c b/camera/ios.c new file mode 100644 index 0000000000..6378e9b2d7 --- /dev/null +++ b/camera/ios.c @@ -0,0 +1,110 @@ +/* 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 . + */ + +#include +#include +#include "../driver.h" + +typedef struct ios_camera +{ + GLuint tex; +} ioscamera_t; + +static void *ios_camera_init(const char *device, uint64_t caps, unsigned width, unsigned height) +{ + if ((caps & (1ULL << RETRO_CAMERA_BUFFER_OPENGL_TEXTURE)) == 0) + { + RARCH_ERR("ioscamera returns OpenGL texture.\n"); + return NULL; + } + + ioscamera_t *ioscamera = (ioscamera_t*)calloc(1, sizeof(ioscamera_t)); + if (!ioscamera) + return NULL; + + return ioscamera; +dealloc: + free(ioscamera); + return NULL; +} + +static void ios_camera_free(void *data) +{ + ioscamera_t *ioscamera = (ioscamera_t*)data; + + if (ioscamera) + free(ioscamera); + ioscamera = NULL; +} + +static bool ios_camera_start(void *data) +{ + ioscamera_t *ioscamera = (ioscamera_t*)data; + + glGenTextures(1, &ioscamera->tex); + glBindTexture(GL_TEXTURE_2D, ioscamera->tex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + return true; +} + +static void ios_camera_stop(void *data) +{ + ioscamera_t *ioscamera = (ioscamera_t*)data; + + if (ioscamera->tex) + glDeleteTextures(1, &ioscamera->tex); +} + +static bool ios_camera_poll(void *data, retro_camera_frame_raw_framebuffer_t frame_raw_cb, + retro_camera_frame_opengl_texture_t frame_gl_cb) +{ + ioscamera_t *ioscamera = (ioscamera_t*)data; + + bool newFrame = false; + (void)frame_raw_cb; + (void)newFrame; + + if (newFrame) + { + // FIXME: Identity for now. Use proper texture matrix as returned by iOS Camera (if at all?). + static const float affine[] = { + 1.0f, 0.0f, 0.0f, + 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 1.0f + }; + + if (frame_gl_cb) + frame_gl_cb(ioscamera->tex, + GL_TEXTURE_2D, + affine); + return true; + } + + return false; +} + +const camera_driver_t camera_ios = { + ios_camera_init, + ios_camera_free, + ios_camera_start, + ios_camera_stop, + ios_camera_poll, + "ios", +}; diff --git a/config.def.h b/config.def.h index 4f2d6500f4..e73d8e8643 100644 --- a/config.def.h +++ b/config.def.h @@ -84,6 +84,7 @@ enum CAMERA_V4L2, CAMERA_RWEBCAM, CAMERA_ANDROID, + CAMERA_IOS, CAMERA_NULL, OSK_PS3, @@ -192,6 +193,8 @@ enum #define CAMERA_DEFAULT_DRIVER CAMERA_RWEBCAM #elif defined(ANDROID) #define CAMERA_DEFAULT_DRIVER CAMERA_ANDROID +#elif defined(IOS) +#define CAMERA_DEFAULT_DRIVER CAMERA_IOS #else #define CAMERA_DEFAULT_DRIVER CAMERA_NULL #endif diff --git a/driver.c b/driver.c index 9e5db4a792..3e2207348e 100644 --- a/driver.c +++ b/driver.c @@ -242,6 +242,9 @@ static const camera_driver_t *camera_drivers[] = { #endif #ifdef ANDROID &camera_android, +#endif +#ifdef IOS + &camera_ios, #endif NULL, }; diff --git a/driver.h b/driver.h index 30e6d94ccc..60905b5427 100644 --- a/driver.h +++ b/driver.h @@ -620,6 +620,7 @@ extern const input_driver_t input_null; extern const camera_driver_t camera_v4l2; extern const camera_driver_t camera_android; extern const camera_driver_t camera_rwebcam; +extern const camera_driver_t camera_ios; extern const input_osk_driver_t input_ps3_osk; #include "driver_funcs.h" diff --git a/griffin/griffin.c b/griffin/griffin.c index 459655624f..92e75f0870 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -358,6 +358,8 @@ CAMERA #ifdef HAVE_CAMERA #if defined(ANDROID) #include "../camera/android.c" +#elif defined(IOS) +#include "../camera/ios.c" #elif defined(EMSCRIPTEN) #include "../camera/rwebcam.c" #endif diff --git a/settings.c b/settings.c index 48f6d48e4c..30695b0e72 100644 --- a/settings.c +++ b/settings.c @@ -176,6 +176,8 @@ const char *config_get_default_camera(void) return "null"; case CAMERA_ANDROID: return "android"; + case CAMERA_IOS: + return "ios"; default: return NULL; }