Panda3D: iOS Support


Panda3D is a mature 3D rendering engine both in age and functionality, addressing the need for the rapid prototyping of games while still providing stability for large projects. As a result of this maturity, however, Panda has been slow to take advantage of newer platforms and devices, with no support for iOS and only experimental support for Android. Adding support for iOS will make the engine much more appealing to new developers, while also creating the opportunity to update more antiquated areas of the engine. Many of these features will aid in future work on Android support as well.

Project Goals

iOS support for Panda’s new CMake build system
Although makepanda is Panda’s primary build system, the CMake build system has been making great progress and is close to completion. Given makepanda’s imminent deprecation, supporting it would take an disproportionate amount of time when compared to the amount of use it will see, so I will be focusing on CMake support instead.

Adding iOS support to the current CMake system would roughly involve:
  • Updating the CMake script to support CMake 3.14’s integrated iOS support.
  • Adding the ability to build for any combination of supported architectures.
  • Implementing support for cross-compiling Python as well as essential third party libraries using rdb’s panda3d-thirdparty repository. I have managed to get this partially working already.

Support for dedicated Panda apps (with the potential to embed Panda inside existing apps as a stretch goal)
Panda is used to having control over the application life-cycle and event loop, so if the goal of making Panda embeddable into existing apps is to be achieved, the Panda startup process will need to be customized slightly for iOS applications. Early on in the development of this project, a Panda app will simply do the job of creating a UIApplication itself, since this is a relatively easy first feature to implement. But by the end, I hope to support both Panda-exclusive apps as well as embedding Panda inside existing apps. This is not a requirement for the completion of the project, but it is definitely something I would like to finish.

To achieve this end-goal, a PandaGLViewController will be created to manage the Panda lifecycle in an iOS-friendly way. Rather than applications starting directly through Python, a “wrapper app” will be used to run Python games. This would simply be an app containing this view controller filling the entire screen. A PandaGLViewController will be initialized by pointing it to a script contained in the app bundle. If an instance of this script is not yet running, it will invoke it in a separate thread, similar to the Android port. Panda will initialize normally, and the GraphicsWindow instance will send a pointer to the UIView it created over to the main thread so it can be attached to the view controller.

A PandaGLViewController is meant to be analogous to a GraphicsWindow. Creating the first instance of a PandaGLViewController will automatically initialize Panda, and any additional instances will act like additional windows being opened. This opens the door to advanced applications that integrate UIKit controls and the use of multiple view controllers. This will likely not be of use to games or other dedicated Panda apps, but it means existing apps will easily be able to integrate with Panda.

Basic touch support (multi-touch as a stretch goal)
At the moment, Panda only supports single-pointer inputs. At minimum, I aim to have touch input on iOS be on par with other platforms, with touches being translated to mouse clicks as appropriate.

With the prevalence of multi-touch gestures like pinching to zoom or using two fingers on the screen at once for on-screen controls, multi-touch support will be a vital part of Panda’s success on iOS. rdb has already begun writing a spec for multi-touch support, and has begun implementing it on the multitouch branch. If time permits, I plan on continuing that work and implementing the most important features than pertain to iOS, but this is by no means a requirement for the completion of the project.

Xcode project templates (stretch goal)
Xcode includes the ability for projects to define custom templates for apps, so it would be nice to be able to do so for Panda. It would include a Python and C++ template, making it easy to for newcomers to start up an iOS project. It would also streamline deployment to the app store. A developer should also be able to change the default Python app location to their existing codebase. This functionality would be added only if the other base features are implemented in time.

Documentation and unit tests for all of the above
All of the above will need to be documented in Panda’s manual. I plan on writing the documentation for any new features that are implemented and a small tutorial showing new users how to set up their projects for iOS.

In summary, the minimum work completed at the end of the coding period will be:
  • CMake support
  • Panda apps through managing a UIApplication
  • Basic touch support
  • Documentation and unit tests


Below is my expected timeline for completion. Because this is such a large undertaking, it is quite difficult to know what issues I will run into at different stages of the project. As the project progresses, this schedule will be adjusted as appropriate. Additionally, this is meant as more of an outline for what order I will complete the project in rather than a true week-by-week breakdown (as in, some weeks may blend into each other). Regardless, I will have at least one deliverable at the end of each week to be evaluated.

May 6 - 27: Research, planning, and experimenting
During the community bonding period, I will attempt to re-familiarize myself with the ins and outs of Panda’s codebase, and how each component interacts. I want to be sure I will be spending time implementing the features I would like to, instead of second-guessing myself later about the design choices I have made. I will create a list of potential pain points for iOS specifically while doing this, so I will have a better idea of what bugs I may need to fix. During this time I will also be setting up VMs for testing on various macOS hosts and iOS versions.

A few things other things to do during this period include:
  • Experiment with Apple’s threading systems (comparing POSIX threads with Apple’s GCD system).
  • Wrap my head around the features added in the recently merged input-overhaul branch to see how multi-touch can fit into it.
  • Fiddle with CMake’s ability to support cross platform builds, since CMake is unable to build for multiple platforms at once (this will be an issue when we need to run interrogate on the host).

May 27 - Jun 2nd: Add ability for panda3d-thirdparty to build third party libraries for iOS.
I will be ensuring that the most important third party libraries are compilable for iOS. Additionally, I would like to add the ability to build a custom Python as well, since there is no official iOS distribution. Two viable open-source projects to achieve this are:
  • - Used by Kivy to run on iOS devices. It is able to build both Python 2 and 3, but may require some modification to support dynamic library loading.