opengl & the graphics pipeline

45
OpenGL & the Graphics Pipeline Lecture notes provided by Chris Handley

Upload: others

Post on 02-Nov-2021

20 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: OpenGL & the Graphics Pipeline

OpenGL & the Graphics Pipeline

Lecture notes provided byChris Handley

Page 2: OpenGL & the Graphics Pipeline

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

Page 3: OpenGL & the Graphics Pipeline

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

Page 4: OpenGL & the Graphics Pipeline

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

Page 5: OpenGL & the Graphics Pipeline

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.

Page 6: OpenGL & the Graphics Pipeline

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, ...

Page 7: OpenGL & the Graphics Pipeline

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.

Page 8: OpenGL & the Graphics Pipeline

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.

Page 9: OpenGL & the Graphics Pipeline

COSC342 Lecture 22 9/45

Well, what does it do?

Page 10: OpenGL & the Graphics Pipeline

COSC342 Lecture 22 10/45

Page 11: OpenGL & the Graphics Pipeline

COSC342 Lecture 22 11/45

Page 12: OpenGL & the Graphics Pipeline

COSC342 Lecture 22 12/45

Page 13: OpenGL & the Graphics Pipeline

COSC342 Lecture 22 13/45

Page 14: OpenGL & the Graphics Pipeline

COSC342 Lecture 22 14/45

Page 15: OpenGL & the Graphics Pipeline

COSC342 Lecture 22 15/45

Page 16: OpenGL & the Graphics Pipeline

COSC342 Lecture 22 16/45

Page 17: OpenGL & the Graphics Pipeline

COSC342 Lecture 22 17/45

Page 18: OpenGL & the Graphics Pipeline

COSC342 Lecture 22 18/45

Page 19: OpenGL & the Graphics Pipeline

COSC342 Lecture 22 19/45

Page 20: OpenGL & the Graphics Pipeline

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).

Page 21: OpenGL & the Graphics Pipeline

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();}

Page 22: OpenGL & the Graphics Pipeline

COSC342 Lecture 22 22/45

Page 23: OpenGL & the Graphics Pipeline

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).

Page 24: OpenGL & the Graphics Pipeline

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.

Page 25: OpenGL & the Graphics Pipeline

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.

Page 26: OpenGL & the Graphics Pipeline

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.

Page 27: OpenGL & the Graphics Pipeline

COSC342 Lecture 22 27/45

Basic OpenGL Operation

Display List

CommandsEvaluator vertex

operationsRaster-isation

fragment operations

Frame Buffer

Texturememory

Pixel operations

Page 28: OpenGL & the Graphics Pipeline

COSC342 Lecture 22 28/45

Primitives (1)

Page 29: OpenGL & the Graphics Pipeline

COSC342 Lecture 22 29/45

Primitives (1)

• Points

V0

V2

V4

V5

V1

V3

Page 30: OpenGL & the Graphics Pipeline

COSC342 Lecture 22 30/45

Primitives (1)

• Points• Lines

V0

V2

V4

V5

V1

V3

Page 31: OpenGL & the Graphics Pipeline

COSC342 Lecture 22 31/45

Primitives (1)

• Points• Lines• Triangles

V0

2

V4

V5

V1

V3V

Page 32: OpenGL & the Graphics Pipeline

COSC342 Lecture 22 32/45

Primitives (1)

• Points• Lines• Triangles• Quads

V0

V3

V1

V2

Page 33: OpenGL & the Graphics Pipeline

COSC342 Lecture 22 33/45

V0

V4

V2V1

V3

Primitives (1)

• Points• Lines• Triangles• Quads• Polygons.

Page 34: OpenGL & the Graphics Pipeline

COSC342 Lecture 22 34/45

Primitives (2)

Page 35: OpenGL & the Graphics Pipeline

COSC342 Lecture 22 35/45

Primitives (2)

• Line strips and line loops.

V0

V3

V1 V2

V4

V0

V3

V1

V2

V4

Page 36: OpenGL & the Graphics Pipeline

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

Page 37: OpenGL & the Graphics Pipeline

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

Page 38: OpenGL & the Graphics Pipeline

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.

Page 39: OpenGL & the Graphics Pipeline

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

Page 40: OpenGL & the Graphics Pipeline

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!

Page 41: OpenGL & the Graphics Pipeline

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

Page 42: OpenGL & the Graphics Pipeline

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

Page 43: OpenGL & the Graphics Pipeline

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

Page 44: OpenGL & the Graphics Pipeline

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?