From BlenderWiki

Jump to: navigation, search

Porting Blenderplayer to Android and OpenGL ES

Original Proposal: (outdated)

Project Target

  • Make OpenGL of game engine compatible with OpenGL ES
  • Extend Android support (ghost)
  • Make a small game chooser or packager

Long Time Targets (Probably out of scope or as time allows)

  • Make whole Blender OpenGL ES compatible


I will try to setup OpenGL ES on my desktop, and do the GL port on there also, which might save me time deploying and debugging on Android.


Various .apk installer versions of this project can be downloaded here:

Progress Report

Week 1 (May 21-25)

  • Port headless Blender and basic libs (done)
  • Test Python port (Done thanks to PY4A proj. Still need compile it myself)
  • Update SVN from 2.62 (done)
  • SDL configured and tested for Blender (done)
  • Compile gameplayer (done)
  • Almost finish dynamic loader with nucleusbridge
    • nucleusbridge is used to run makesdna and makesrna
  • Design a system to easily test partiality ported OpenGL ES code.
    • Working on it. Wrote smart stub for GL. More Integration with glew is still needed.
  • Configure and consolidate build system/apk structure (nearly done for cmake)
    • Working on it, so it would find libs. After it is done will commit
  • Writing compilation instruction
  • Started debugging BGE openGL code

Week 2 (May 28- June 1)

  • Finished SDL port config to enable OpenGL 2.0
    • Fixed exit on rotate
  • Finished Smart OpenGL Stub. Now works as intended.
    • Also fixed couple issue I had with OpenGL
  • Added support OpenGL ES 2.0 on linux
  • Did documentation and tested how to build on Android
  • Studied/Debug GE code.
    • A little more complicated than what I expected with all branching and culling test
  • Make a solid monkey for Android's BGE

Week 3 (June 4-8)

  • Wrote matrix software stack
    • Standard GL functions like glPopMatrix
    • Some needed glu functions like gluLookAt
    • Ported whole GE to it
    • Still some problems like with dome
    • Now Android has a properspective
    • Added quad conversion for usual meshes (probably is not complete)
  • Had few prroblems
    • Spend a few hours why render was weird to find out that I forgot to enable Z=buffer in EGL
    • Qt+Chrome+gcc > 4.0 GB and my computer is prone to freezes. Also ext4 is not atomic resulting in lost of ~2.5 hour of work (OpenGL ES 2.0 tester).
  • Started planing default shaders management system

Week 4 (June 11-15)

  • Fix Android App (allow install without rooting)
  • Few fixes to matrix stack (+addition to math library)
  • Prepared and committed almost all my work (took much longer than I expected )
  • Converted part of GLEW extension flags to GPU flags
  • Studied GE GLSL
    • Make tested, the compilation on my phone is 0.03 S which is not a lot
    • Converted/disabled GLSL code to make compilable on phone.
    • Existing GLSL shaders works, but without lighting
    • Converted shader code to ES/modern, dropping ARB for now
      • With current openGL stub system, it is problematic to have both

Week 5 (June 18-22)

  • Added initial SDL input
    • Some SDL functions don't work as expected
  • Fixed Z-buffer
    • Turns out SDL for Android is terrible
    • It was setting wasn't respecting own settings
    • I'm investigating to have our own Ghost implementation (as original was planned)
    • It will also allow easier installation (like py4a): One click download with WiFi
  • Created simple "Blender Archive" file format for packaging files
    • It creates single installation file which is copied into internal directory.
  • GLSL lighting works
  • Added GLSL texture support
    • with refactoring code (needs to be coordinated with Jason, then commit)
    • Remove all ARB shading code (brecht approved it). Maybe we have old code if user base is big.
  • Clean up for matrix code
  • Icon fun!

Week 6 (June 25-29)

  • First Android release!
  • Refactor OpenGL extensions. So gpu** calls gl** or gl**ARB if graphics card doesn't support it.
    • Jason made it compatible with Windows.
  • Few small OpenGL ES state fixes
  • Added VBO support.
  • Working on python GLSL
  • Added matrix rotation + double multiplication
    • +Converted blendfont to our matrix stack.
  • Fun merges fixes with my local branch
  • Worked one day on native Ghost
    • Made EGL in Java
    • Designed event queue. (hopefully it will work out very nicely. No malloc, only essential mutex)
    • There will be only one call from c to java (SwapBuffers). Many calls will be from java to c, events calls.
  • Designing Standard shading system (for text, lines) instead of glColor, glTexture...

Week 7 (July 2-6)

  • Python GLSL converted to gpu/Android
    • Not fully tested
  • DNA bug
    • I spent a day tracking down a crash to find out that dna was out of sync.
    • On a bright side:
  • I learned how to use Android's GDB
    • Through gdbserver on the device
    • There is a big lack of holistic documentation. I will post instructions later.
  • Native Ghost
    • ~60% complete
    • Figure out how to call java functions from C
    • And reverse way. So I can call SwapBuffers or have onKey event.
    • A little bit tricky with Java memory management in C
    • Implemented a nice, fast event queue
      • Did testing. Seems to be thread safe if only one thread is writing and only one is reading.
  • Figured out the problem with DNA/RNA generation on unrooted devices

Week 8 (July 9-13)

  • Java-C side with Ghost is working together
    • Apparently EGL context is not valid from another thread.
      • Had to refractor code
      • Still, we have support for only one display/Window.
    • Had to track down redrawing bug which took a lot of time
  • Native mouse input is implemented.
    • Mouse motion
    • Events system is very flexible and extendable
  • makesdna and makesrna is rewritten
    • Using Intent
    • Work on non rooted phones
    • Separate activity
  • Started working on opening .blend file
    • +Installation file
    • Based on "Intent" filters

P.S. Currently there are limitations for Ghost system

  • Only one window is supported
  • You cannot restart Blender from inside the app
    • memory leaks, lib loads, function registration etc.

Week 9 (July 16-20)

  • Added support for opening .blend
  • Created initial CenterControl activity (app menu) from which files can be also selected
    • In future we can add update/downloader/"blend store" functionality to it
    • And also latter will have options how to start a game
  • .bla are now .zip files
    • Unpackaged to internal folder
      • A little insecure
  • Wrote video mode selections
    • App tries to get highest video mode available starting from 8,8,8 color + 24 depth + 8 alpha
  • Added single lib installation for developers
  • A lot ghost/native fixes
  • Was able to get GE working in full blender (on linux openGL ES)
  • Started Accelerometer and gyroscope API

Week 10 (July 23-27)

  • Fix for initial screen size
  • Added ability to download blender from inside the app
    • Was investigating packing libraries into apk itself.
  • Added accelerometer and gyroscope support on android side
    • Did a little of reorganization of android app and jni
  • Added accelerometer and gyroscope to ghost
    • Data stored as 3d vector
    • Or smaller length according to the type
    • So it is easily extendable for other sensors
    • Had trouble with implementing sensor inside GE logic
      • Hopefully Mitchell Stoke or Dalai Felinto will help me out next week
  • Did some openGL wrapper addition
    • Trying to make more flexible for adding OpenGL 4.2 on desktop
  • OpenGL bug hunting/fixing
    • Alpha now works in Swiss and GLES
  • Did optimization and game testing
    • Was able to speed up GE
    • With -02 (for physics)
    • VBO improved performance
    • Use System Framerate decreases performance between 1/2 and 1/3 times (Blender issue)

Week 11 (July 30- August 3)

  • All libs are bundled in one apk
    • The future releases will automatically overwrite libs (no need to delete the app)
  • Moved python also to apk
  • Did part of Sensor manager
    • 3 step hierarchy in GE is confusing (and probably unnecessary)
  • Resolved some merges conflicts
  • Spend a lot of time fixing crashes on Tegra 2
    • All libs were built with float optimization with NDK r7
    • NDK 7b fails on Tegra 2
      • Because gnu stl (including math functions) were built with NEON optimization in NDK
    • Updated to r8b
    • Downgraded to r8
      • Solved the problem
    • Will file a bug report
  • Ported whole Blender to soft matrix stack (only GE was ported before)
    • New gpu matrix functions
      • Rotate-s and gpuProject
    • Still few bugs to resolve
    • also GE clean up/optimization

Week 12 (August 6 - 10)

  • Merged software matrix stack
    • Resolved selection and other important issues
    • Still we relay on gluUnProject for now
  • Make VBO compatibility interface (if glMapBuffer is available)
    • Very simple for now
  • Renamed gpu functions to gpu_gl for clarity
  • Added gpu view for setting and clearing the view
    • To avoid setting REAL_GL_MODE for GLES
  • Converted unsupported drawing types like GL_POLYGON, GL_QUAD_STRIP, and some GL_QUADS to analogus.
    • Did testing, doesn't effect rendering
    • Multiple drawing of GL_QUADS are harder. Probably, I will write converter.
    • GL_QUADS are depricated. With n-gons there is no advantage of GL_QUADS. They should be probably removed eventually from code.
  • Was investigating what should be done to complete the port.
  • Code clean up

Week 13 (August 13 - 17)

  • Visual Report
  • Fixed glMapBuffer on Android
  • Some code rearrangements to support OpenGL 3.0+ with soft switch in the future
  • Added emulations to GL_QUADS
    • by using glDrawElements with prebaked map, much better than sending 2 triangles.
  • Initial builtin shaders/gpuImmediate OpenGL ES implementation
    • Simple color shader is enough for most elements (although inefficient due to redraws for effects)
    • Alpha Texture shader for text.
    • Was looking how many shaders do we need:
      • 4-5 flat shaders for UI
      • 3 shaders * number of light sources * (alpha blending?) for 3d
    • Icons are done with deprecated gl*Pixels (needs to be converted to texture)
    • Blender on my phone crash on most of the start up files due to driver implementation/error not-checking
      • But it works on Mesa linux GL ES driver
      • And when the blender works, I can open the files that crash on start up
      • Will look into it.
  • Started documentation on code and how to build for Android
    • Will finish over the weekend.


  • There is a lot to be done
    • From graphic code and UI+multitouch changes to Android API and iOS port
  • I plan to take a 1-2 weeks break from coding
    • After it, it probably will be a weekend project as University will start