The OpenGL
R
Graphics System:
A Specification
(Version 3.3 (Compatibility Profile) - March 11,
2010)
Mark Segal
Kurt Akeley
Editor (version 1.1): Chris Frazier
Editor (versions 1.2-3.3): Jon Leech
Editor (version 2.0): Pat Brown
Copyright
c
2006-2010 The Khronos Group Inc. All Rights Reserved.
This specification is protected by copyright laws and contains material proprietary
to the Khronos Group, Inc. It or any components may not be reproduced, repub-
lished, distributed, transmitted, displayed, broadcast or otherwise exploited in any
manner without the express prior written permission of Khronos Group. You may
use this specification for implementing the functionality therein, without altering or
removing any trademark, copyright or other notice from the specification, but the
receipt or possession of this specification 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.
Khronos Group grants express permission to any current Promoter, Contributor
or Adopter member of Khronos to copy and redistribute UNMODIFIED versions
of this specification in any fashion, provided that NO CHARGE is made for the
specification and the latest available update of the specification for any version
of the API is used whenever possible. Such distributed specification may be re-
formatted AS LONG AS the contents of the specification are not changed in any
way. The specification may be incorporated into a product that is sold as long as
such product includes significant independent work developed by the seller. A link
to the current version of this specification on the Khronos Group web-site should
be included whenever possible with specification distributions.
Khronos Group makes no, and expressly disclaims any, representations or war-
ranties, express or implied, regarding this specification, including, without limita-
tion, any implied warranties of merchantability or fitness for a particular purpose
or non-infringement of any intellectual property. Khronos Group makes no, and
expressly disclaims any, warranties, express or implied, regarding the correctness,
accuracy, completeness, timeliness, and reliability of the specification. Under no
circumstances will the Khronos Group, or any of its Promoters, Contributors or
Members or their respective partners, officers, directors, employees, agents or rep-
resentatives be liable for any damages, whether direct, indirect, special or conse-
quential damages for lost revenues, lost profits, or otherwise, arising from or in
connection with these materials.
Khronos is a trademark of The Khronos Group Inc. OpenGL is a registered trade-
mark, and OpenGL ES is a trademark, of Silicon Graphics International.
Contents
1 Introduction 1
1.1 Formatting of the OpenGL Specification . . . . . . . . . . . . . . 1
1.1.1 Formatting of the Compatibility Profile . . . . . . . . . . 1
1.1.2 Formatting of Optional Features . . . . . . . . . . . . . . 1
1.1.3 Formatting of Changes . . . . . . . . . . . . . . . . . . . 1
1.2 What is the OpenGL Graphics System? . . . . . . . . . . . . . . 2
1.3 Programmer’s View of OpenGL . . . . . . . . . . . . . . . . . . 2
1.4 Implementor’s View of OpenGL . . . . . . . . . . . . . . . . . . 2
1.5 Our View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.6 The Deprecation Model . . . . . . . . . . . . . . . . . . . . . . . 3
1.7 Companion Documents . . . . . . . . . . . . . . . . . . . . . . . 3
1.7.1 OpenGL Shading Language . . . . . . . . . . . . . . . . 3
1.7.2 Window System Bindings . . . . . . . . . . . . . . . . . 4
2 OpenGL Operation 5
2.1 OpenGL Fundamentals . . . . . . . . . . . . . . . . . . . . . . . 5
2.1.1 Floating-Point Computation . . . . . . . . . . . . . . . . 7
2.1.2 16-Bit Floating-Point Numbers . . . . . . . . . . . . . . 8
2.1.3 Unsigned 11-Bit Floating-Point Numbers . . . . . . . . . 9
2.1.4 Unsigned 10-Bit Floating-Point Numbers . . . . . . . . . 9
2.1.5 Fixed-Point Data Conversions . . . . . . . . . . . . . . . 10
2.2 GL State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.2.1 Shared Object State . . . . . . . . . . . . . . . . . . . . . 13
2.3 GL Command Syntax . . . . . . . . . . . . . . . . . . . . . . . . 13
2.4 Basic GL Operation . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.5 GL Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.6 Begin/End Paradigm . . . . . . . . . . . . . . . . . . . . . . . . 18
2.6.1 Begin and End . . . . . . . . . . . . . . . . . . . . . . . 22
2.6.2 Polygon Edges . . . . . . . . . . . . . . . . . . . . . . . 29
i
CONTENTS ii
2.6.3 GL Commands within Begin / End . . . . . . . . . . . . 29
2.7 Vertex Specification . . . . . . . . . . . . . . . . . . . . . . . . . 30
2.8 Vertex Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
2.8.1 Packed Vertex Data Formats . . . . . . . . . . . . . . . . 43
2.8.2 Drawing Commands . . . . . . . . . . . . . . . . . . . . 44
2.9 Buffer Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
2.9.1 Creating and Binding Buffer Objects . . . . . . . . . . . 52
2.9.2 Creating Buffer Object Data Stores . . . . . . . . . . . . 54
2.9.3 Mapping and Unmapping Buffer Data . . . . . . . . . . . 56
2.9.4 Effects of Accessing Outside Buffer Bounds . . . . . . . 61
2.9.5 Copying Between Buffers . . . . . . . . . . . . . . . . . 61
2.9.6 Vertex Arrays in Buffer Objects . . . . . . . . . . . . . . 62
2.9.7 Array Indices in Buffer Objects . . . . . . . . . . . . . . 62
2.9.8 Buffer Object State . . . . . . . . . . . . . . . . . . . . . 63
2.10 Vertex Array Objects . . . . . . . . . . . . . . . . . . . . . . . . 63
2.11 Rectangles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
2.12 Fixed-Function Vertex Transformations . . . . . . . . . . . . . . 65
2.12.1 Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
2.12.2 Normal Transformation . . . . . . . . . . . . . . . . . . . 71
2.12.3 Generating Texture Coordinates . . . . . . . . . . . . . . 73
2.13 Fixed-Function Vertex Lighting and Coloring . . . . . . . . . . . 76
2.13.1 Lighting . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
2.13.2 Lighting Parameter Specification . . . . . . . . . . . . . . 81
2.13.3 ColorMaterial . . . . . . . . . . . . . . . . . . . . . . . 82
2.13.4 Lighting State . . . . . . . . . . . . . . . . . . . . . . . . 85
2.13.5 Color Index Lighting . . . . . . . . . . . . . . . . . . . . 85
2.13.6 Clamping or Masking . . . . . . . . . . . . . . . . . . . 86
2.14 Vertex Shaders . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
2.14.1 Shader Objects . . . . . . . . . . . . . . . . . . . . . . . 87
2.14.2 Program Objects . . . . . . . . . . . . . . . . . . . . . . 89
2.14.3 Vertex Attributes . . . . . . . . . . . . . . . . . . . . . . 91
2.14.4 Uniform Variables . . . . . . . . . . . . . . . . . . . . . 95
2.14.5 Samplers . . . . . . . . . . . . . . . . . . . . . . . . . . 111
2.14.6 Varying Variables . . . . . . . . . . . . . . . . . . . . . . 112
2.14.7 Shader Execution . . . . . . . . . . . . . . . . . . . . . . 115
2.14.8 Required State . . . . . . . . . . . . . . . . . . . . . . . 122
2.15 Geometry Shaders . . . . . . . . . . . . . . . . . . . . . . . . . . 123
2.15.1 Geometry Shader Input Primitives . . . . . . . . . . . . . 124
2.15.2 Geometry Shader Output Primitives . . . . . . . . . . . . 125
2.15.3 Geometry Shader Variables . . . . . . . . . . . . . . . . . 126
OpenGL 3.3 (Compatibility Profile) - March 11, 2010
CONTENTS iii
2.15.4 Geometry Shader Execution Environment . . . . . . . . . 126
2.16 Coordinate Transformations . . . . . . . . . . . . . . . . . . . . 131
2.16.1 Controlling the Viewport . . . . . . . . . . . . . . . . . . 132
2.17 Asynchronous Queries . . . . . . . . . . . . . . . . . . . . . . . 133
2.18 Conditional Rendering . . . . . . . . . . . . . . . . . . . . . . . 135
2.19 Transform Feedback . . . . . . . . . . . . . . . . . . . . . . . . 136
2.20 Primitive Queries . . . . . . . . . . . . . . . . . . . . . . . . . . 139
2.21 Flatshading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
2.22 Primitive Clipping . . . . . . . . . . . . . . . . . . . . . . . . . . 142
2.22.1 Color and Associated Data Clipping . . . . . . . . . . . . 144
2.23 Final Color Processing . . . . . . . . . . . . . . . . . . . . . . . 145
2.24 Current Raster Position . . . . . . . . . . . . . . . . . . . . . . . 146
3 Rasterization 150
3.1 Discarding Primitives Before Rasterization . . . . . . . . . . . . 152
3.2 Invariance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
3.3 Antialiasing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
3.3.1 Multisampling . . . . . . . . . . . . . . . . . . . . . . . 154
3.4 Points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
3.4.1 Basic Point Rasterization . . . . . . . . . . . . . . . . . . 157
3.4.2 Point Rasterization State . . . . . . . . . . . . . . . . . . 161
3.4.3 Point Multisample Rasterization . . . . . . . . . . . . . . 161
3.5 Line Segments . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
3.5.1 Basic Line Segment Rasterization . . . . . . . . . . . . . 162
3.5.2 Other Line Segment Features . . . . . . . . . . . . . . . . 165
3.5.3 Line Rasterization State . . . . . . . . . . . . . . . . . . 168
3.5.4 Line Multisample Rasterization . . . . . . . . . . . . . . 168
3.6 Polygons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
3.6.1 Basic Polygon Rasterization . . . . . . . . . . . . . . . . 169
3.6.2 Stippling . . . . . . . . . . . . . . . . . . . . . . . . . . 171
3.6.3 Antialiasing . . . . . . . . . . . . . . . . . . . . . . . . . 172
3.6.4 Options Controlling Polygon Rasterization . . . . . . . . 172
3.6.5 Depth Offset . . . . . . . . . . . . . . . . . . . . . . . . 173
3.6.6 Polygon Multisample Rasterization . . . . . . . . . . . . 174
3.6.7 Polygon Rasterization State . . . . . . . . . . . . . . . . 175
3.7 Pixel Rectangles . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
3.7.1 Pixel Storage Modes and Pixel Buffer Objects . . . . . . . 176
3.7.2 The Imaging Subset . . . . . . . . . . . . . . . . . . . . 177
3.7.3 Pixel Transfer Modes . . . . . . . . . . . . . . . . . . . . 178
3.7.4 Transfer of Pixel Rectangles . . . . . . . . . . . . . . . . 189
OpenGL 3.3 (Compatibility Profile) - March 11, 2010