Next: 6 Example: Three Kinds Up: The OpenGL Graphics Interface Previous: 4.7.4 OpenGL State

5 Integration in a Window System

OpenGL draws 3D and 2D scenes into a framebuffer, but to be useful in a heterogeneous environment, OpenGL must be made subordinate to a window system that allocates and controls framebuffer resources. We describe how OpenGL is integrated into the X Window System, but integration into other window systems (Windows NT, for instance) is similar.

X provides both a procedural interface and a network protocol for creating and manipulating framebuffer windows and drawing certain 2D objects into those windows. OpenGL is integrated into X by making it a formal X extension called GLX. GLX consists of about a dozen calls (with corresponding network encodings) that provide a compact, general embedding of OpenGL in X. As with other X extensions (two examples are Display PostScript and PEX), there is a specific network protocol for OpenGL rendering commands encapsulated in the X byte stream.

OpenGL requires a region of a framebuffer into which primitives may be rendered. In X, such a region is called a drawable. A window, one type of drawable, has associated with it a visual that describes the window's framebuffer configuration. In GLX, the visual is extended to include information about OpenGL buffers that are not present in unadorned X (depth, stencil, accumulation, front, back, etc.).

X also provides a second type of drawable, the pixmap, which is an off-screen framebuffer. GLX provides a GLX pixmap that corresponds to an X pixmap, but with additional buffers as indicated by some visual. The GLX pixmap provides a means for OpenGL applications to render off-screen into a software buffer.

To make use of an OpenGL-capable drawable, the programmer creates an OpenGL context targeted to that drawable. When the context is created, a copy of an OpenGL renderer is initialized with the visual information about the drawable. This OpenGL renderer is conceptually (if not actually) part of the X server, so that, once created, an X client may connect to the OpenGL context and issue OpenGL commands (Figure 5). Multiple OpenGL contexts may be created that are targeted to distinct or shared drawables. Any OpenGL-capable drawable may also be used for standard X drawing (those buffers of the drawable that are unused by X are ignored by it). Calls are provided to synchronize drawing between OpenGL and X; it is the client's responsibility to carry out this synchronization if required.

A GLX client that is running on a computer of which the graphics subsystem is a part may avoid passing OpenGL tokens through the X server. Such direct rendering may result in increased graphics performance since the overhead of token encoding, decoding, and dispatching is eliminated. Direct rendering is supported but not required by GLX (a client may determine whether or not a server provides direct rendering). Direct rendering is feasible because sequentiality need not be maintained between X commands and OpenGL commands except where commands are explicitly synchronized.



Next: 6 Example: Three Kinds Up: The OpenGL Graphics Interface Previous: 4.7.4 OpenGL State


segal@asd.sgi.com
Fri Sep 23 16:08:14 PDT 1994