12/02/2005

OpenGL ES against OpenGL

Introduction

OpenGL on an embedded system is the biggest challenge to overcome to run BlenderCE. In fact, Blender uses deeply OpenGL to draw everything and we need for Blender a full OpenGL implementation.

I considered several implementations for Blender:
There is a real effort to specify and develop an OpenGL implementation for embedded devices. This is driven by the Khronos Group building the new  OpenGL ES standard. Vincent (Open Source) and Rasteroid (free for non commercial use) are two implementations of OpenGL ES available.
We can use this wonderful work optimized for embedded device to run BlenderCE. But OpenGL ES is only a subset of OpenGL and of course, vital gl_functions for BlenderCE are missing. Excluding all functions only called by BGL.c (Python), here is a summary of features needed by BlenderCE but not included in OpenGL ES specifications:
  1. Begin/End
  2. Pixel drawing (e.g. bitmap, Draw/Copypixel)
  3. Selection and Feedback
  4. Draw/Read buffer (no access to specified buffer)
  5. Evaluators and Nurbs (used for curves)
Different solutions were considered.

Mesa3d

Because of these missing gl_functions, I considered Mesa (full Open Source OpenGL implementation). Mesa successfully compiled for the PocketPC and worked properly but there was a problem of performances. If this solution was retained, Mesa should have been optimized for embedded system: that would have meant at least converting the whole floating point math in fixed point. This is not a small task and after some considerations, I preferred spend energy working on a common OpenGL ES basis taking advantage of this great work deployed especially for embedded devices. But Mesa is still considered at least for educational purpose.

Klimt/KlimtES

At the first beginning of BlenderCE project, I was using Klimt (Open Source) including all indispensable Begin/end paradigm. Daniel Wagner (author of Klimt) provided me also KlimtES, an amazing library implementing additional Klimt functions on top of OpenGL ES. But the source code of KlimtES is closed. KlimtES, associated with Vincent, was the first able to "run" Blender.

Please notice that Klimt implements a very interesting fixed-point math approach (overloading the float type by a generic klfloat type) that could be used later on in the optimization phase.

OpenGL ES wrapper

For Blender, I decided to use the same approach as KlimtES. I wrote an OpenGL wrapper running on top of OpenGL ES to implement gl_functions needed by Blender. Of course, given that KlimtES sources are closed , it was not question here to stole KlimtES code and reproduce what Daniel Wagner does.
The first inspiration of this wrapper was based on the Quake III for PocketPC. Only Open Source projects are considered (including Klimt) and I take care to not take inspiration from KlimtES.

This wrapper (OGLES2OGL) is today able to run all functions needed by Blender except evaluator and front buffer drawing pixel.

Rasteroid or Vincent?

Vincent is an Open Source OpenGL ES implementation. Vincent supports the SIP (Virtual keyboard) because it doesn’t use GAPI today. But there are some bugs (nothing preventing Blender to run) and performance are not so good as Rasteroid. Finally, we should for performance reasons, use fixed-point math to avoid Vincent making to many conversions.

Rasteroid is not an Open Source project. A whole company is working hard on it so it offers better performance as Vincent. We cannot use the SIP with Rasteroid because it uses GAPI (but we will probably not use the SIP in BlenderCE anyway). An other difference is that Rasteroid implements its own floating-point math so there is no real need to provide Rasteroid fixed point parameters.

BlenderCE today supports only Rasteroid because it is using a function not implemented in Vincent. But I would like to restore the compatibility with Vincent. As soon as I have more time, I will try to implement the missing function in Vincent.

For everybody interested in this part of the Blender port, the Redbook is an indispensable reference.

Don’t hesitate to share any comments.
Salvatore