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 ﬁrst. The amount of work needed to
update a legacy OpenGL or OpenGL ES code base to a more modern proﬁle, i.e.,
at least version 2.x of either speciﬁcation, 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 ﬁxed-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 ﬁxed-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 conﬁg, context, and surface management using the EGL
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–speciﬁc work.