O'Reilly logo

OpenGL Insights by Christophe Riccio, Patrick Cozzi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A Subset Approach to Using
OpenGL and OpenGL ES
Jesse Barker and Alexandros Frantzis
43.1 Introduction
The modern GPU is no longer a specialized processor with discrete bits of fixed func-
tionality, many of which are mutually exclusive. It is a powerful, fully programmable
compute engine, in most cases on par with or even surpassing the computational
power of the CPU.
The modern versions of the OpenGL and OpenGL ES APIs reflect this evolu-
tion, though much of the code written against them does not, which limits use on
many platforms. Many of the features that were removed from the core profile of
OpenGL or omitted from OpenGL ES, while not directly supported by the GPU,
must now be implemented by the developer. This represents significant effort, both
in terms of understanding and implementation, on the part of developers, which
impedes their ability to keep their code current.
In our work with opensource software projects at Linaro, we have encountered
a wealth of existing OpenGL code in a variety of a pplications and toolkit libraries.
F or us, this presents a couple of problems. F irst, we required OpenGL ES 2.0,
and second, the upstream maintainers of the code required that their code continue
to work with desktop OpenGL. We needed compatibility with both API variants.
One option (and one that we have encountered on a number of projects) is to have
multiple code paths, governed by #ifdef constructs. This satisfies the conditions
but makes the code ugly, hard to maintain, and prone to lots of bugs that occur in
one path and not the other. Our team is not large, and this approach is not scalable
to the number of projects in which we participate. We found another solution.
621
43
622 VII Software Design
The solution is to take advantage of the similarity between the modern desktop
OpenGL and OpenGL ES 2.0 APIs in order to produce a single code base that can
be compiled with minimal compile-time code-path selections against both versions.
We call this approach the subset approach, and in our experience, it has proved an
excellent way to simplify supporting code across multiple API versions. We have
successfully applied it to a number of production code bases, making them easier to
maintain and make available across a variety of platforms.
43.2 Making Legacy Code Modern
Since our work has tended to include a fair amount of porting along the way to a
clean Subset code base, we cover porting topics first. The amount of work needed to
update a legacy OpenGL or OpenGL ES code base to a more modern profile, i.e.,
at least version 2.x of either specification, is largely proportional to the complexity
of the application. However, we have found that there is a coarse subset of common
topics that applies to all such efforts. This partial list largely applies whether targeting
OpenGL ES 2.0, OpenGL 2.1, or later. The programmer
Converts immediate-mode draw-call sequences to vertex- and index-array call
sequences, preferably stored in buffer objects.
Reduces the set of rendering primitives.
Needs to handle fixed-function vertex processing—matrix stacks, transforma-
tion APIs, per-vertex lighting, material properties, etc.—either directly in the
application or in vertex shaders.
Needs to handle fixed-function fragment processing—per-fragment lighting,
fog, texenv, related texture, and fog enables, etc.—in fragment shaders.
Does not use bitmaps or polygon stipples anymore.
Does not use glCopyPixels anymore.
Needs to provide config, context, and surface management using the EGL
API.
Executing the API conversion in the order presented in the above list helps pre-
vent breakage and regression of existing OpenGL functionality independently of any
OpenGL ES–specific work.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required