Treffer: Cg and OpenGL Integration.
Weitere Informationen
The article discusses the integration of Cg or C for graphics which is a syntax program language, into OpenGL computer programs using the runtime library and OpenGL extensions. A couple of Cg language features are relevant to the Cg OpenGL runtime library. First, a single text file can contain several vertex and fragment programs. Cg does not dictate a standard name for a program entry point like the C/C++ main function. Second, there are two basic types of data available to Cg program. Uniform data is constant across multiple vertices or fragments, and varying data changes on a per-vertex or per-fragment basis. Uniform data includes texture maps, transformation matrices and constant vertex colors. Varying data includes vertex positions, normals, texture coordinates and other interpolated quantities. Uniform and varying parameters are handled differently by the Cg OpenGL runtime library. The Cg OpenGL runtime library provides runtime access to the Cg compiler, as well as providing functionality for managing parameters, attributes and other data than the OpenGL ARB interfaces. The runtime library consists of two parts, a core library that is independent of OpenGL and an OpenGL-specific library. The core library handles access to the compiler and manages programs, and the OpenGL library handles parameters and other data specific to OpenGL. The header files cg.h and cgGL.h contain the function declarations for the core Cg runtime and the Cg OpenGL runtime library, respectively. The Cg runtime library uses a technique of parameter shadowing for uniform parameters. Whenever the value of a uniform program parameter is set with a Cg library call, the value is stored internally and the appropriate OpenGL functions are called. This avoids having to reset uniform parameter values every time the Cg program is about to execute. However, varying data, such as vertex position and texture coordinates, must be set every time the program executes.