opengl & the graphics pipeline
TRANSCRIPT
OpenGL & the Graphics Pipeline
Lecture notes provided byChris Handley
COSC342 Lecture 22 2/45
Jim Clark SGI
• PhD in Utah• Invented the ‘geometry engine’ while at
Stanford.• Founded SGI in 1982• Iris 1000 - 1984• Indigo 1990• Tezro 1995
COSC342 Lecture 22 3/45
NVIDIA
• Founded 1993 by Jen-Hsun Huang• Started with quadratic surface rendering
for game consoles all but killed by introduction of Direct X
• 1996 hired David Kirk• 1997 Riva 128• 1999 GeForce 256• 2007 CUDA
COSC342 Lecture 22 4/45
ATI
• Founded 1985 by Kwok Yuen Ho (Hong Kong)
• Made graphics boards for IBM and Commodore PC
• 1996 3D accelerator for notebooks• 2000 Radeon• 2006 bought by AMD
COSC342 Lecture 22 5/45
What is OpenGL!?
• A software interface to graphics hardware.• Consists of about 120 functions that specify the
objects and operations needed to produce high-quality colour images of three-dimensional objects.
• OpenGL Utility Library (GLU) and the OpenGL Extension to the X Window System! (GLX) provide useful supporting features.
COSC342 Lecture 22 6/45
Availability
• C/C++, Objective-C, C#, D, Haskell, Java, Lua, Perl, Python, R, Ruby, Tcl, Ada, FORTRAN, ...
• Unix/Linux, MacOS, any recent Windows flavour–OS/2 and BeOS, ...
COSC342 Lecture 22 7/45
How does it work?
• Client-server model —–Server does the drawing,–Client does the display,–May, in fact, be the same machine.
COSC342 Lecture 22 8/45
What doesn’t it have?
• Commands for performing windowing tasks or obtaining user input.
• High-level commands for describing models of three-dimensional objects.
COSC342 Lecture 22 9/45
Well, what does it do?
COSC342 Lecture 22 10/45
COSC342 Lecture 22 11/45
COSC342 Lecture 22 12/45
COSC342 Lecture 22 13/45
COSC342 Lecture 22 14/45
COSC342 Lecture 22 15/45
COSC342 Lecture 22 16/45
COSC342 Lecture 22 17/45
COSC342 Lecture 22 18/45
COSC342 Lecture 22 19/45
COSC342 Lecture 22 20/45
Structure of an OpenGL program
• Construct shapes from geometric primitives, thereby creating mathematical descriptions of objects.
• Arrange the objects in three-dimensional space and select the camera position (view point).
• Calculate the colour of all the objects.• Convert the mathematical description of objects
to pixels on the screen (rasterisation).
COSC342 Lecture 22 21/45
#include <whateverYouNeed.h>main() { OpenAWindowPlease(); glClearColor(0.0, 0.0, 1.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0, 0.0, 0.0); glBegin(GL_POLYGON); glVertex2i(100, 100); glVertex2i(100, 300); glVertex2i(300, 200); glVertex2i(200, 100); glEnd(); glFlush(); KeepTheWindowOnTheScreenForAWhile();}
COSC342 Lecture 22 22/45
COSC342 Lecture 22 23/45
OpenGL Command Syntax
• Commands use the prefix gl and initial capital letters for each word making up the command name (glClearColor()).
• Constants begin with GL_, use all capital letters, and use underscores to separate words (GL_COLOR_BUFFER_BIT).
COSC342 Lecture 22 24/45
Parameter Definition (1)
• Most functions come in several different flavours depending on type (and possibly number) of parameters.
• Consider glColor*(). We can use three values (RGB) to represent a colour, or we can include transparency ("-channel).
• Similarly we can specify the values as bytes, integers, floats, doubles, etc.
COSC342 Lecture 22 25/45
Parameter Definition (2)
• Thus we can set the colour without or with transparency using glColor3() or glColor4().
• Similarly we can set the values of the components using any one of glColor3i(), glColor3f(), glColor3d(), etc.
COSC342 Lecture 22 26/45
OpenGL as a state machine
• OpenGL maintains a variety of states (or modes) that start off with default values and that remain set until changed.
• Modes include background and fore-ground colours, viewing and projection transformations, polygon drawing modes, and so on.
COSC342 Lecture 22 27/45
Basic OpenGL Operation
Display List
CommandsEvaluator vertex
operationsRaster-isation
fragment operations
Frame Buffer
Texturememory
Pixel operations
COSC342 Lecture 22 28/45
Primitives (1)
COSC342 Lecture 22 29/45
Primitives (1)
• Points
V0
V2
V4
V5
V1
V3
COSC342 Lecture 22 30/45
Primitives (1)
• Points• Lines
V0
V2
V4
V5
V1
V3
COSC342 Lecture 22 31/45
Primitives (1)
• Points• Lines• Triangles
V0
2
V4
V5
V1
V3V
COSC342 Lecture 22 32/45
Primitives (1)
• Points• Lines• Triangles• Quads
V0
V3
V1
V2
COSC342 Lecture 22 33/45
V0
V4
V2V1
V3
Primitives (1)
• Points• Lines• Triangles• Quads• Polygons.
COSC342 Lecture 22 34/45
Primitives (2)
COSC342 Lecture 22 35/45
Primitives (2)
• Line strips and line loops.
V0
V3
V1 V2
V4
V0
V3
V1
V2
V4
COSC342 Lecture 22 36/45
Primitives (2)
• Line strips and line loops.• Triangle strips and fans.
V0
V3
V1
V2
V5
V4V0
V3V1
V2
V5
V6
V4
COSC342 Lecture 22 37/45
Primitives (2)
• Line strips and line loops.• Triangle strips and fans.• Quad strips.
V0
V3V1
V2
V5
V6V4
V9V7
V8
COSC342 Lecture 22 38/45
Buffers
• Front and Back Buffers.• Depth Buffer (Z-Buffer).• Stencil Buffer.
–Used to restrict the drawing to certain portions of the screen. Useful for constructive solid geometry.
• Accumulation Buffer.–Creating motion blur, and depth-of-field effects.
• Alpha Buffer.
COSC342 Lecture 22 39/45
GPU Fundamentals:The Graphics Pipeline
• A simplified graphics pipeline–Note that pipe widths vary–Many caches, FIFOs, and so on not shown
Graphics State
GPUCPU
Application Transform Rasterizer Shade VideoMemory
(Textures)
Vertices (3D) Xformed, LitVertices (2D)
Fragments(pre-pixels)
Final pixels(Colour, Depth)
Render-to-texture
COSC342 Lecture 22 40/45
GPU Fundamentals:The Modern Graphics Pipeline
Graphics State
Application Transform Rasterizer Shade VideoMemory
(Textures)
Vertices (3D) Xformed, LitVertices (2D)
Fragments(pre-pixels)
Final pixels(Colour, Depth)
Render-to-texture
VertexProcessor
FragmentProcessor
• Programmable vertex processor!
• Programmable pixel processor!
COSC342 Lecture 22 41/45
GPU Pipeline: Transform• Vertex Processor (multiple operate in parallel)
–Transform from “world space” to “image space”–Compute per-vertex lighting
COSC342 Lecture 22 42/45
GPU Pipeline: Rasterizer• Converts geometric representation (vertex) to
image representation ((image) fragment).• Fragment = Pixel + associated data — colour,
depth, stencil, etc.• Interpolate per-vertex quantities across pixels
COSC342 Lecture 22 43/45
GPU Pipeline: Shade• Fragment Processors (multiple in parallel)
–Compute a colour for each pixel–Optionally read colours from textures (images)
Bump map Colour map Gloss map
COSC342 Lecture 22 44/45
Less shady: CUDA, OpenCL, ...
• NVIDIA’s CUDA and Khronos OpenCL–Compute Unified Device Architecture–Open Computing Language
• C-like languages for GPU computing• Single instruction multiple data SIMD• NVIDA CUDA 128 processor (2007)• Full access to GPU programmability• Ray tracing in hardware?
COSC342 Lecture 22 45/45
Resources
•http://www.cs.wpi.edu/~matt/courses/cs563/talks/OpenGL_Presentation/OpenGL_Presentation.html
•http://www.calsoftlabs.com:80/whitepapers/open-gl.html
•http://www.opengl.org/documentation/red_book/
•http://www.opengl.org/documentation/blue_book/
•http://www.sgi.com/products/software/opengl/
•http://fly.cc.fer.hr/~unreal/theredbook/chapter01.html