
and Windows PCs, OpenGL is supported by Apple for its Macintosh personal computers. Linux users can use
either the Mesa open-source implementation of OpenGL or a hardware-accelerated implementation such as
NVIDIA's OpenGL driver for Linux. This flexibility makes OpenGL the industry's best cross-platform
programming interface for 3D graphics.
Over the last decade, OpenGL has evolved along with graphics hardware. OpenGL is extensible, meaning that
OpenGL implementers can add new functionality to OpenGL in an incremental way. Today, scores of OpenGL
extensions provide access to all the latest GPU features. This includes ARB-standardized extensions for vertex
and fragment programmability. As extensions are established, they are often rolled into the core OpenGL
standard so that the standard as a whole advances. At the time of this writing, the current version of OpenGL
is 1.4. Ongoing work to evolve OpenGL is underway in various OpenGL ARB working groups. This work
includes both assembly-level and high-level programmable interfaces. Because Cg operates as a layer above
such interfaces, it will continue to function with future revisions of OpenGL in a compatible manner.
Direct3D
Microsoft began developing the Direct3D programming interface about 1995 as part of its DirectX multimedia
initiative. Direct3D is one of the programming interfaces that make up DirectX. Microsoft introduced DirectX
and Direct3D to jump-start the consumer market for 3D graphics, particularly gaming, on Windows PCs.
Microsoft's Xbox game console also supports Direct3D. Direct3D is the most popular graphics API for games
on Windows, due to its history of closely matching the capabilities of available graphics hardware.
Every year or so, Microsoft has updated DirectX, including Direct3D, to keep up with the rapid pace of PC
hardware innovation. The current version of DirectX at the time of this writing is DirectX 9, which includes
HLSL, Microsoft's implementation of the same language syntax and constructs found in Cg.
3D Programming Interface D ente
A few years ago, OpenGL and Direct3D competed to see which programming interface would dominate,
particularly in the domain of Windows PCs. The competition continues to be good for both programming
interfaces, and each has improved in performance, quality, and functionality. In the area of GPU
programmability that Cg addresses, both programming interfaces have comparable capabilities. This is
because both OpenGL and Direct3D run on the same GPU hardware and the graphics hardware determines
the available functionality and performance. OpenGL has a slight advantage in functionality because hardware
vendors are better able to expose their entire feature set through OpenGL, though vendor-specific extensions
do add some complexity for developers.
Most software developers now choose a 3D programming interface based on programmer preference,
history, and their target market and hardware platform, rather than on technical grounds.
Cg supports either programming interface. You can write C g programs so that they work with either the
OpenGL or Direct3D programming interface. This is a huge boon for 3D content developers. They can pair
their 3D content with programs written in Cg and then render the content no matter what programming
interface the final application uses for 3D rendering.
1.4.2 The Cg Compiler and Runtime
No GPU can execute Cg programs directly from their textual form. A process known as compilation must
translate Cg programs into a form that the GPU can execute. The Cg compiler first translates your C g
program into a form accepted by the application's choice of 3D programming interface, either OpenGL or
Direct3D. Then your application transfers the OpenGL or Direct3D translation of your Cg program to the GPU
using the appropriate OpenGL or Direct3D commands. The OpenGL or Direct3D driver performs the final
translation into the hardware-executable form your GPU requires.
The details of this translation depend on the combined capabilities of the GPU and 3D programming interface.
How a Cg program compiles its intermediate OpenGL or Direct3D form depends on the type and generation of
GPU in your computer. It may be that your GPU is not capable of supporting a particular valid Cg program
because of limitations of the GPU itself. For example, your Cg fragment program will not compile if your
program accesses more texture units than your target GPU supports.
Support for Dynamic Compilation
When you compile a program with a conventional programming language such as C or C ++, compilation is an
offline process. Your compiler compiles the program into an executable that runs directly on the CPU. Once
compiled, your program does not need to be recompiled, unless you change the program code. We call this
static compilation.
C g is different because it encourages dynamic compilation, although static compilation is also supported. The
Cg compiler is not a separate program but part of a library known as the Cg runtime. 3D applications and
games using Cg programs must link with the C g runtime. Applications using C g then call C g runtime routines,
all prefixed with the letters
cg
, to compile and manipulate Cg programs. Dynamic compilation allows C g
programs to be optimized for the particular model of GPU installed in the user's machine.
Page 16
ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html