ppy / osu-framework

A game framework written with osu! in mind.
MIT License
1.66k stars 418 forks source link

iOS targeting support #682

Closed peppy closed 5 years ago

peppy commented 7 years ago

We need to add full iOS support for the framework.

This should not be too difficult as everything has been designed with cross-platform support in mind. Will require hooking up Xamarin, adding the iOS version of bass (any probably other) native libraries.

I welcome anyone who has an interest in cross-platform targeting support, especially if you have experience with xamarin.

swoolcock commented 7 years ago

Once .NET Standard is a merged thing, I'll get on this.

swoolcock commented 6 years ago

The main issue at the moment is the namespace conflict with Xamarin’s OpenTK, which can theoretically be solved by renaming ours. However, including two versions of OpenTK will mean two lots of OpenGL bindings, and our fork currently only targets desktop.

My initial thoughts on possible solutions:

1) Dynamic pinvoke OpenGL in osu.Framework (will probably require JIT and thus not work on iOS).

2) Include all OpenGL native implementations in our OpenTK fork and redirect to the correct one for the platform at runtime. We can either make OpenTK’s iOS bindings work, or grab the Xamarin implementation directly from github. Hopefully there are no Xamarin dependencies.

3) Similar to 2, but use precompiler directives and provide separate osu.Framework assemblies for Xamarin platforms.

4) Encapsulate OpenGL in osu.Framework, grab the correct native implementation via GameHost OpenGL implementation for desktop goes in osu.Framework.Desktop OpenGL implementation for iOS goes in osu.Framework.iOS OpenGL implementation for Android goes in osu.Framework.Android

5) Similar to 4, but encapsulate in a less OpenGL-specific way such that we can plug in Metal/Vulkan later.

This is a tricky one and I welcome any other solutions.

tangalbert919 commented 6 years ago

I would recommend taking on Metal first because Apple deprecated OpenGL earlier this year, which affects not just adding iOS support, but also existing macOS support. Unfortunately, OpenTK doesn't seem to support Metal, and I already looked at the source code.

I think this project might help, since that's the closest I can get to Metal in C# for macOS, while Xamarin itself does have Metal for iOS.

swoolcock commented 6 years ago

Apple’s deprecation of OpenGL will not be a problem in the short term. They’re not switching it off entirely any time soon.

Writing for Metal is nontrivial but is the direction I would like to go eventually. For now we should be fine with OpenGL. I will check out that project when I get a chance, thanks.

peppy commented 6 years ago

We may want to consider that library as a potential OpenTK alternative for graphics portions. This is a relatively low priority task for short-term, but if anyone's looking to have some fun please give it a try and see how it fits.

They also use ImageSharp, which is nice to see.

mellinoe commented 6 years ago

Veldrid developer here -- I'd be happy to give pointers if anyone does end up trying out the library. If a refactor for Metal is being considered, then IMO Veldrid would be a good alternative since it also gets you support for Vulkan, D3D11, GLES, etc. without writing multiple backends yourself. It's also fully .NET Standard (unlike e.g. Xamarin's Metal wrapper), so it should integrate pretty smoothly. Feel free to reach out to me if anyone is interested in experimenting with it.

swoolcock commented 6 years ago

My current goal is to get it at least building and running with the latest OpenTK, even if I have to rename namespaces, delete assemblies, and sell my soul to the devil. I may look into Veldrid if I can successfully decouple OpenGL from OpenTK even if it's just for our project.