-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[rcore] Porting raylib to iOS and implement rcore_ios.c
#3880
base: master
Are you sure you want to change the base?
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
rcore_ios.c
rcore_ios.c
rcore_ios.c
rcore_ios.c
Hi @raysan5 . I need your help. iOS always use a int main(int argc, char * argv[]) {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
} It seems does not expose detailed control to allow us to achieve the following:
What we can do is registering render callbacks via CADisplayLink. I cannot find a way to give users full control of the game loop. I can try a callback-based api like this. However, this requires a minor change of existing raylib projects if they want to run on iOS. extern void ios_ready();
extern void ios_update();
extern void ios_destroy(); Old project should adapt their main function into this in order to be cross-platform between iOS and other platforms: #ifndef PLATFORM_IOS
int main(int argc, char** argv){
// store as global variables if you need
ios_ready();
while(!WindowShouldClose()) ios_update();
ios_destroy();
return 0;
}
#endif |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Question: I see there is a feature: Should I override |
Now |
This comment was marked as outdated.
This comment was marked as outdated.
Interesting.. will colaborate soon |
Any new progress? |
also interested :D? |
I am a bit busy recently |
@blueloveTH do you have local changes on your branch? I have this running on my mac/iphone now and planning on allocating some free time on this as I also need raylib ios for a project I'm working on. Anything you need for collaboration? Do you have your Makefile/CMake changes to compile Raylib to ios local? |
To use raylib with Emscripten it's already necessary to give up the main loop control(unless one's willing to add So I like the idea of a callback based design. Maybe something along the lines of SDL3 main callback functions. Here's how they handle the quirks of each platform, including iOS. |
Definitely interested in this. This is the dream, being able to make cross platform mobile apps and games with raylib would be amazing. |
@leftbones Unfortunately the code structure required for this iOS implementation is hardly compatible with raylib structure, not sure if it's possible to use another structure, more similar to Android one. |
There may be internal functions that Apple does not expose allowing us to take full control of the main loop. |
Perhaps the newly merged SDL_GPU as a backend would be a better approach for targeting iOS, and consoles!!! |
sokol seems support IOS event loop, can we learn some idea from them.... |
I'm totally new to this discussion (and raylib), but familiar with iOS and Apple APIs in general. So maybe the following totally misses the problem, but I thought I'd share it 🙂 Sokol subclasses MTKView when using Metal, or GLKView when using OpenGL ES. Then creates this view and sets the FPS. This is done inside application:didFinishLaunchingWithOptions:, and I would recommend doing it there on iOS. So in iOS touch events arrive in touchesBegan/Moved/Ended/Cancelled. From there, we would need to "feed them" into raylib. Maybe a queue that raylib polls every frame, when we call |
I've now tested and looked over the I think the only way to support iOS is to do it via UIApplicationMain and then getting called back for rendering, touch events, etc. |
@martinfinke thank you very much for looking into this new iOS platform. All raylib platform backends, including Android, allow building the examples with no change for target platform. Is it possible same behaviour for iOS? |
Hi @raysan5, thank you for creating raylib! Just for the sake of sharing information: I came across a StackOverflow discussion, which is about GLFW on macOS (not iOS). It creates the app manually, then calls run, which would normally block until exit. However, they override applicationDidFinishLaunching:, and in there they "stop" the app, which exits the app's own blocking event loop. Problems with this approach on iOS: To my knowledge,
I also checked GLFM, but it uses the "official" UIApplicationMain approach and you implement |
SDL has prior art in this domain which, in addition to callback APIs (as previously discussed), can use a macro to transform It involves a bit of macro trickery, but perhaps a similar solution could be implemented in Raylib so that existing examples are able to build for iOS without platform-specific changes as @raysan5 mentioned. |
it feels we are close! |
Creating and loading a dynamic library just so I can name the entry point function To me, the best compromise seems to not even attempt to run the Raylib examples unmodified on iOS. Instead, add the basic support from this PR, and then just provide a guide: "How to bring your Raylib project to iOS: Implement
Apart from a lot of opportunities for deadlock, an immediate major problem with this: Cocoa code must be called from the main thread only. The dynamic framework's |
You may not need that, but I guess it's important for the project, or else raysan wouldn't be asking for it.
There would be little opportunities for deadlock actually. The main points of sync between the view controller and the game thread would be input handling, window flags change and making
You can actually make all graphics / draw calls in the game thread, even swap render buffers. There are few call stacks to lose in this case, I don't think people will bother debugging platform code after we implement it correctly. Every thread has its own call stack, the game thread call stack is still there, in full, if you need to debug your game, it will be there for you to debug like in all other platforms. |
I would like to take the initial step to add iOS support for raylib.
I am going to add
rcore_ios.c
and implement an iOS's platform layer.I will update this pr on my progress.
Current Demo (iPhone 8)
RPReplay_Final1711259172.MP4
Steps
libEGL.xcframework
andlibGLESv2.xcframework
rcore_ios.c
and compile raylibFunctions
void PollInputEvents(void)
int InitPlatform(void)
void ClosePlatform(void)
Prebuilt ANGLE libraries for iOS
Users need to add the following ANGLE libraries into Xcode.
libEGL.xcframework.zip
libGLESv2.xcframework.zip
References