RoboVM iOS backend

Discussions for core devs and contributors. Read only for normal forum members to keep the noise low

RoboVM iOS backend

Postby mzechner » Fri Feb 22, 2013 3:16 pm

Given my fun ride yesterday, with the latest Xamarin update (which was an error on my end, not theirs), i'd like to look into alternative ways to get libgdx onto iOS. One of the options that looks really promising is RoboVM. It's free as in beer, open-source and based on LLVM, compiling JVM bytecode to native code. It may also be a path to other platforms that have similar restrictions as iOS has.

Only caveats at the moment: no debugging support, and might not have been tested 100%. I promised to look into the later issue, by incorporating Android's libcore tests. Didn't have time for that yet though. Debugging isn't a huge deal in the immediate future i think.

Niklas Therning, creator of RoboVM, offered to help with creating a RoboVM based backend for libgdx. This thread is meant for sharing info/progress/what have you between all involved parties. So, everybody say hello to Niklas!

I guess it would make sense to go through all the interfaces and classes involved in writting a backend, and discuss in what order to tackle them. The MonoTouch based iOS backend can serve as an examplary implementation.

Let me try to summarize the general structure:

  • Libgdx is split into a core project and a handful of backend projects.
  • The core projects contains interfaces that are implemented separately for every backend. These interfaces are
    • Application, implements window managment, OpenGL context setup, stores references to other modules
    • Audio, implements the audio system, allows to create Sound and Music instances
    • Files, implements file I/O, potentially needs an extension of FileHandle
    • Graphics, exposes the rendering surface and OpenGL ES
    • GL10, GL11,GL20, Java bridges to the OpenGL ES API. We may chose to only implement GL20. Need a JNI wrapper. We already have that for GL20 on Android, can be easily ported to iOS
    • Input, wraps access to touch screen, (onscreen-)keyboard etc.
    • Net, implements simple socket based networking and HTTP access. We can reuse the LWJGL/Android backend implementation for this if RoboVM's class library works 100%
  • The core project also contains native code for various things. That is already build for iOS, as a static library. We interface with it through JNI.
  • A libgdx iOS app would hence link to the core Java classes, the core native library, the iOS backend Java classes and the iOS backend native library (containing the GLES 2.0 bindings)

I'd propose we create a branch on Github for a potential RoboVM backend. In that branch, we put the backend in backends/gdx-backend-iosrobovm. I'd start by creating an implementation of Application, and stubs that do nothing for the interfaces Application returns (including things like Music and Sound). Next i'd implement OpenGL ES context creation and make sure it works with the app life-cycle. I'd then implement the Graphics and Files interfaces to test loading and rendering of images as well as the OpenGL ES 2.0 bindings. Next i'd implement Input, accelerometer can be disregarded in the beginning, touch input is the most important to perform more testing. After that i'd look into Audio, we currently use ObjectAL in the MonoTouch backend which should be easy to wrap. The Net interface shouldn't be an issue as i said above, just copy & pasting the LWJGL/Android implementation should suffice.

For testing, I'd create a new gdx-tests-iosrobovm project in the tests/ folder. That would be a RoboVM/libgdx app, that imports the code from the tests/gdx-tests project and the assets from the tests/gdx-tests-android/assets folder. The app could use the GwtTestWrapper class as its ApplicationListener. That one is used in the GWT tests to display a list of all tests (GLES 2.0 only).

Sadly, libgdx isn't mavenized in the source repo, we are heavily based on Eclipse. That may or may not be an issue.
mzechner
Site Admin
 
Posts: 4879
Joined: Sat Jul 10, 2010 3:50 pm

Re: RoboVM iOS backend

Postby ntherning » Fri Feb 22, 2013 4:15 pm

Thanks for all the info! That should get me started. I'll start to dig into this in a few days. I guess I'll start with my own fork and we'll see what to do with the code later if it turns out ok (e.g. moving to a branch in the libgdx repo).

BTW, I tried to contact you on the RoboVM Google Group about the libcore tests. Asked if you had had the time to look at it. I didn't get a reply so I've started looking at it already. Sorry for not letting you know directly. I should have realized that not everyone gets new messages in the group by e-mail. Anyways, there are plenty of other things that need to be done should you have the time and desire to contribute! ;)
ntherning
 
Posts: 18
Joined: Fri Feb 22, 2013 3:07 pm

Re: RoboVM iOS backend

Postby davedes » Fri Feb 22, 2013 9:45 pm

mzechner wrote:based on LLVM, compiling JVM bytecode to native code

Does this mean that theoretically we could use RoboVM to compile any LibGDX app to a native executable that can be run without JRE? As in: fast startup, small distribution, no Mac+LWJGL issue, etc.

Forgive my complete ignorance with LLVM...
davedes
 
Posts: 434
Joined: Thu Oct 11, 2012 7:51 pm

Re: RoboVM iOS backend

Postby mzechner » Fri Feb 22, 2013 11:53 pm

Theoretically, yes, if we wrote a new backend that doesn't rely on LWJGL :)
mzechner
Site Admin
 
Posts: 4879
Joined: Sat Jul 10, 2010 3:50 pm

Re: RoboVM iOS backend

Postby ntherning » Sat Mar 09, 2013 4:53 pm

I've now managed to get a basic RoboVM backend up and running: http://blog.robovm.org/2013/03/gdxinvad ... obovm.html

There's still a lot to be done (sound/music/input/...). I will push the code to my fork in a couple of days.

A quesiton: Where's the native code sources used by the MonoTouch backend (iosgles20.cpp)? I've managed to find code from a few months back and am using that at the moment but since then the native code seems to have been removed from the libgdx repo?
ntherning
 
Posts: 18
Joined: Fri Feb 22, 2013 3:07 pm

Re: RoboVM iOS backend

Postby arielsan » Sat Mar 09, 2013 11:02 pm

Looks really promising, good work!

About the iosgles20, we changed to use directly OpenGL through Monotouch OpenTK instead using simulated JNI since it worked a lot of times better than the other implementation, I suppose that was the reason it was removed but I am not sure, I thought it was optional. You can go through history though to get that file if you still need it.
Image
arielsan
 
Posts: 195
Joined: Sat Apr 02, 2011 3:58 pm

Re: RoboVM iOS backend

Postby mzechner » Mon Mar 11, 2013 10:15 am

Or you can get the original Android sources here: https://code.google.com/p/gl2-android/

Since RoboVM uses the Harmony classpath implementation, the buffer offset methods should work as well i hope (provided the relevant JNI functions are implemented in RoboVM).
mzechner
Site Admin
 
Posts: 4879
Joined: Sat Jul 10, 2010 3:50 pm

Re: RoboVM iOS backend

Postby ntherning » Tue Mar 12, 2013 9:19 pm

I have now pushed this to my libgdx fork, https://github.com/ntherning/libgdx. In order to run the invaders you will need to use the latest RoboVM from github and build it first. See https://github.com/robovm/robovm/wiki/Hacking-on-RoboVM for instructions on how to build from source.

The gdx backend relies on some native code. There's a Makefile in backends/gdx-backends-iosrobovm/jni which has to be run.

Next you will need to import the robovm-rt, robovm-objc and robovm-cocoatouch projects in Eclipse (Import -> Existing Maven Projects).

You should now be able to run GdxInvadersIOS by using the "GdxInvadersIOS (Simulator).launch" file in the gdx-invaders-iosrobovm project. There's also a "GdxInvadersIOS (Device).launch" file which will build and run on a device. Unfortunately that doesn't seem to work at the moment. Will need to look into that.
ntherning
 
Posts: 18
Joined: Fri Feb 22, 2013 3:07 pm


Return to Libgdx Development

Who is online

Users browsing this forum: No registered users and 1 guest