Sunteți pe pagina 1din 394

The OpenGL R Graphics System:

A Specification (Version 2.1 - December 1, 2006)

Mark Segal

Kurt Akeley

Editor (version 1.1): Chris Frazier Editor (versions 1.2-2.1): Jon Leech Editor (version 2.0): Pat Brown

Copyright c 1992-2006 Silicon Graphics, Inc.

This document contains unpublished information of Silicon Graphics, Inc.

This document is protected by copyright, and contains information proprietary to Silicon Graphics, Inc. Any copying, adaptation, distribution, public performance, or public display of this document without the express written consent of Silicon Graphics, Inc. is strictly prohibited. The receipt or possession of this document does not convey any rights to reproduce, disclose, or distribute its contents, or to manufacture, use, or sell anything that it may describe, in whole or in part.

U.S. Government Restricted Rights Legend

Use, duplication, or disclosure by the Government is subject to restrictions set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or in similar or succes- sor clauses in the FAR or the DOD or NASA FAR Supplement. Unpublished rights reserved under the copyright laws of the United States. Contractor/manufacturer is Silicon Graphics, Inc., 1600 Amphitheatre Parkway, Mountain View, CA 94043.

OpenGL is a registered trademark of Silicon Graphics, Inc. Unix is a registered trademark of The Open Group. The ”X” device and X Windows System are trademarks of The Open Group.

Contents

1 Introduction

1

1.1 Formatting of Optional Features

 

1

1.2 What is the OpenGL Graphics System?

 

1

1.3 Programmer’s View of OpenGL

 

2

1.4 Implementor’s View of OpenGL

2

1.5 Our View

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

3

1.6 Companion Documents

 

.

.

.

.

.

.

.

.

3

2 OpenGL Operation

 

4

2.1 OpenGL Fundamentals

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

4

2.1.1

Floating-Point Computation

 

6

2.2 GL State .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

6

2.3 GL Command Syntax

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

7

2.4 Basic GL Operation

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

10

2.5 GL Errors

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

11

2.6 Begin/End Paradigm

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

12

2.6.1 Begin and End

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

15

2.6.2 Polygon Edges

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

19

2.6.3 GL Commands within Begin/End

 

19

2.7 Vertex Specification

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

20

2.8 Vertex Arrays

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

23

2.9 Buffer Objects

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

33

2.9.1 Vertex Arrays in Buffer Objects

 

38

2.9.2 Array Indices in Buffer Objects

39

2.9.3 Buffer Object State .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

39

2.10 Rectangles .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

40

2.11 Coordinate Transformations

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

40

2.11.1 Controlling the Viewport .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

42

2.11.2 Matrices

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

43

 

i

ii

CONTENTS

2.11.3 Normal Transformation .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

48

2.11.4 Generating Texture Coordinates .

.

.

.

.

.

.

.

.

.

.

.

2.12 Clipping

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

50

52

2.13 Current Raster Position

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

54

2.14 Colors and Coloring .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

57

2.14.1 Lighting .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

59

2.14.2 Lighting Parameter Specification

 

64

2.14.3 ColorMaterial

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

66

2.14.4 Lighting State .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

68

2.14.5 Color Index Lighting

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

68

2.14.6 Clamping or Masking

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

69

2.14.7 Flatshading

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

69

2.14.8 Color and Associated Data Clipping

 

70

2.14.9 Final Color Processing

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

71

2.15 Vertex Shaders

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

71

2.15.1 Shader Objects

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

72

2.15.2 Program Objects

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

73

2.15.3 Shader Variables

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

75

2.15.4 Shader Execution .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

84

2.15.5 Required State

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

88

3 Rasterization

90

3.1 Invariance

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

92

3.2 Antialiasing

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

92

3.2.1

3.3 Points

Multisampling

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

3.3.1 Basic Point Rasterization .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

93

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

95

97

3.3.2 Point Rasterization State

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

101

3.3.3 Point Multisample Rasterization

 

101

3.4 Line Segments

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

101

3.4.1 Basic Line Segment Rasterization

 

102

3.4.2 Other Line Segment Features

 

104

3.4.3 Line Rasterization State

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

107

3.4.4 Line Multisample Rasterization .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

3.5 Polygons

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

107

108

3.5.1 Basic Polygon Rasterization

 

108

3.5.2 Stippling

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

110

3.5.3 Antialiasing .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

111

3.5.4 Options Controlling Polygon Rasterization

 

111

3.5.5 Depth Offset

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

111

Version 2.1 - December 1, 2006

CONTENTS

iii

 

3.5.6 Polygon Multisample Rasterization

 

113

3.5.7 Polygon Rasterization State

 

113

3.6 Pixel Rectangles

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

113

3.6.1 Pixel Storage Modes and Pixel Buffer Objects .

.

.

.

.

.

.

114

3.6.2 The Imaging Subset

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

115

3.6.3 Pixel Transfer Modes .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

116

3.6.4 Rasterization of Pixel Rectangles

 

127

3.6.5 Pixel Transfer Operations

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

138

3.6.6 Pixel Rectangle Multisample Rasterization .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

3.7 Bitmaps

.

.

.

.

.

.

.

.

.

148

148

3.8 Texturing

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

150

3.8.1 Texture Image Specification

 

151

3.8.2 Alternate Texture Image Specification Commands

 

159

3.8.3 Compressed Texture Images

 

165

3.8.4 Texture Parameters

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

168

3.8.5 Depth Component Textures

 

170

3.8.6 Cube Map Texture Selection

 

170

3.8.7 Texture Wrap Modes

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

171

3.8.8 Texture Minification

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

172

3.8.9 Texture Magnification

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

178

3.8.10 Texture Completeness

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

179

3.8.11 Texture State and Proxy State

 

180

3.8.12 Texture Objects

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

182

3.8.13 Texture Environments and Texture Functions

 

184

3.8.14 Texture Comparison Modes

 

187

3.8.15 sRGB Texture Color Conversion

 

191

3.8.16 Texture Application .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

191

3.9 Color Sum .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

194

3.10 Fog

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

194

3.11 Fragment Shaders

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

196

3.11.1 Shader Variables

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

196

3.11.2 Shader Execution .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

197

3.12 Antialiasing Application

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

199

3.13 Multisample Point Fade .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

200

4

Per-Fragment Operations and the Framebuffer

 

201

4.1

Per-Fragment Operations

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

202

4.1.1 Pixel Ownership Test .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

202

4.1.2 Scissor Test

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

203

4.1.3 Multisample Fragment Operations

 

203

Version 2.1 - December 1, 2006

iv

CONTENTS

4.1.4 Alpha Test

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

204

4.1.5 Stencil Test

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

205

4.1.6 Depth Buffer Test .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

206

4.1.7 Occlusion Queries

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

207

4.1.8 Blending

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

209

4.1.9 Dithering

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

212

4.1.10 Logical Operation

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

213

4.1.11 Additional Multisample Fragment Operations

 

213

4.2 Whole Framebuffer Operations

 

215

4.2.1 Selecting a Buffer for Writing

 

215

4.2.2 Fine Control of Buffer Updates

 

217

4.2.3 Clearing the Buffers

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

218

4.2.4 The Accumulation Buffer

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

220

4.3 Drawing, Reading, and Copying Pixels

 

221

4.3.1 Writing to the Stencil Buffer

 

221

4.3.2 Reading Pixels

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

222

4.3.3 Copying Pixels

.

.

.

.

.

.

.

.

.

.

.

.

.

.