©zachary wartell review: 3d graphics with opengl revision 1.1 copyright zachary wartell at...

58
Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Post on 19-Dec-2015

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Review3D Graphics with OpenGL

Revision 11

Copyright Zachary Wartell at University of North CarolinaAll Rights Reserved

Overview

bull OpenGL Pipeline

bull OpenGL transformation pipeline

bull rasterization and perspective correct interpolation

bull Standard lighting

Notation

bull xyz ndash real number (Times)bull pqr ndash 3D point or vector (Bold Lowercase Arial)bull M ndash 4x4 matrix (Bold Arial Uppercase M)bull ABC ndashcoordinate system (Bold Uppercase

Script)

bull MAlarrB ndash 4x4 matrix mapping coordinate from coordinate space B to space A

bull pAqArA ndash coordinate of point or vector relative to coordinate system A

bull PQR ndash a plane (Bold Uppercase Arial)bull lpo ndash a line (Bold Italic Times)

OpenGL Graphics Pipeline

OpenGL Transform Pipeline

dev clip j

1 1 1 1

c cw c c e e od

c cw c c e e od

c cw c c e ed

c c

x xx x w x x xx

y yy y w y y yy

z zz z w z z zz

w w

win eye eye wld wld obM M M M

1o

GL_MODELVIEWGL_PROJECTIONViewportTransformation

(glViewport ampglDepthRange)

ldquoeye coordinatesrdquo(lighting)

ldquoclip coordinatesrdquo(3D clipping)

ldquowindow coordinatesrdquo(rasterization)

McliplarreyeM0 = Meyelarrwld

M1 = Meyelarrwld M wldlarrobj

ldquoobject coordinatesrdquo

ldquonormalized devicecoordinatesrdquo

Clipdiv

Vertex ProcessorClip Proj Vp CullF P

Affine Transformations

00 01 02 03

10 11 12 13

20 21 22 23

0 0 0 1

x a a a a x

y a a a a y

z a a a a z

w w

M

bulltranslate (T) ndash preserve area length angles orientationbullrotate (R) ndash preserve area length anglesbullscale (S) ndash preserve perpendicularity of axisbullrigid-bodycongruency ndash (T R) preserve area length anglesbulluniform scalerdquosimilarityrdquo ndash preserve angles orientation

All affine transformations

preserve linespreserve parallelismpreserve distance ratio (rarrequal spacing)map points to points amp vectors to vectors

Starttypically GL_MODELVIEW stack contains affine transformations

Preserve Lines

l

l

M transforming entire grid

l p = p0 + t (p1-p0 ) rarr l M(p) =M(p0) + t (M(p1)-M(p0))

p0

p1

p

p0

p

p1

Parallelism

la lb

la

lb

M transforming entire grid

la || lb rarr M(la) || M(lb) = la || lb

Distance Ratios

l

l

M transforming entire grid

abbc = abbc

a

b

c

a

b c

Object Coordinates to Eye Coordinates

far clipping plane

y

xz

near clippingplane

y

xz

World Coordinates

W

Eye Coordinates

y

xz

Body Coord

y

xz

Head Coord

Perspective Collineation

00 01 02 03

10 11 12 13

20 21 22 23

30 31 32 33

a a a ax x

a a a ay y

a a a az z

a a a aw w

M

bulltypically GL_PROJECTION stack contains a dimension preserving perspective collineation

bullexample of non-dimension preserving perspective collineation

+Z

-Z

(0 0 0)

(xyz)

(xprojyproj-d)

x

proj

proj

proj

xx

z dy

yz d

z d

Properties of Perspective Collineation

bull preserve lines

bull does not preserve parallelism

bull does not preserve distance ratios

eye

P

view window

bull 3D2D collapse loses depth informationndash zbuffer needs depth information but only works for

parallel projection

bull fastest frustum clipping algorithm would clip to unit cube ndash not arbitrary frustum

Non-dimension preserving persp collineation problem 1

eye b0

b1

a1a0a

b

y

z

b0b1

a1a0a

b

yz

eye at infin=(0010)

bull fastest frustum clipping algorithm would clip to unit cube ndash not against an arbitrary frustum

Non-dimension preserving persp collineation problem 2

(-1-1-1)

(111)

xdev

ydev

zdev

clipping planes have most trivial equation posible (z=1z=-1x=1x=-1 etc) Hence solving clipping intersection

equations is fast as possible

Perspective Collineation (Dimension Preserving)

near clippingplane

far clipping plane

eye

View Window

near clippingplane

far clipping plane

Mpers

Mpers2D Mparallel(3Drarr2D)

3Drarr3D

=

(3Drarr2D)

Rasterization ndash Pixel Window Coordinates

a

b

c

Rasterization - zBuffer(x1y1z1)

(x2y2z2)(x3y3z3)

(xryrzr)(xlylzl)

(xyz)

bull Generally to compute z

bull Incremental in x

bull Incremental in y

Ax By Dz

C

( 1)

A x By Dz z A C

C

1

So

or if =

x x m

A m Bz z z z B C m

C

Rasterization ndash Texture Coordinates

bull assign 3 (st)-coordinates to 3 vertices of geometric primitive

linearly interpolate (st) to map texture space to object-space

v1t1

v0t0

v2t2

t

s

t0 t1

t2 t=(st)

t=(st)

(11)

v1t1

v0t0

v2t2

t

s

t0 t1

t2t=(st)t=(st)

(11)

texture spaceobject space

window space

t=(st)t=(st) non-affine

affine

Mobjlarrtex

Mwinlarrobj

Rasterization Need Rational linear interpolation

Rational linear interpolation in Scan-Conversion

t

s

t0 t1

t2

t=(st)

(11)

texture spacewindow space

t=(st)t=(st)non-affine

MwinlarrobjMobjlarrtex

(sqtqq)bulllinearly interpolate 3 variables

sqtqqbullcompute st with a division per pixel

s=sqq t=tqq

Rasterization Who does what

bull Rasterize unit does ndash scan conversion (generate (xy))ndash rational linear interpolation of texture coordinatesndash linear interpolation of depth coordinatendash rational linear () interpolation of vertex color

bull Fragment Processorndash if using fragment shader you can further modify the

depth coordinate and texture coordinate from those generated by Rasterize unit

Rasterization GL state

bull GL_POINTS ndash glPointSize glPointParameter POINT SPRITE texture

bull GL_LINESGL_LINE_LOOP ndash glLineWidth glLineStipple

bull GL_TRIANGLES etc ndash glPolygonStipple glPolygonMode glPolygonOffset glFrontFace

bull crude anti-aliasing ndash glEnable GL_POINT_SMOOTH GL_LINE_SMOOTH GL_POLYGON_SMOOTH

bull Is color interpolated - glShadeModel

Per-Fragment Operations - I

bull pixel ownership test ndash is the destination pixel visible or obscured by other window

bull scissor test ndash clips fragment against rectangle given by glScissor

bull alpha test ndash decides whether to discard fragment based on comparison of fragrsquos alpha value with target given by glAlphaFunc

bull stencil test ndash compares stencil buffer value with reference value and decides whether to discard pixel (glStencilFunc glStencilOp)

bull depth test ndash use function set by glDepthFunc to compare depth of fragment to depth of destination pixel in framebuffer

Per-Fragment Operations - II

bull blending ndash color stored in pixel is blend of fragment color and original pixel color and blend state (glBlendFunc glBlendColor glBlendEquation)

bull logical operations ndashbitwise boolean operations (glLogicOp)

bull dithering - old

Frame Buffer Operations

bull which buffer(s) are written too GL_FRONT GL_FRONT_LEFTGL_AUX0 etc (glDrawBuffer glDrawBuffers)

bull write protection ndash which bitsbytes are affected (glColorMask glDepthMask glStencilMask)

bull clear framebuffer ndash glClear glClearColor glClearDepth glClearStencil glClearAccum

bull glFlush ndash make sure all primitives are progressing toward completion (noone waiting around in queue)

bull glFinish ndash block () until all pending GL calls have executed

Graphics Workstation

DisplayProcessor Display

ProcessorMemory

FramebufferVideo

Controller

PeripheralDevices

CPU SystemMemory

System Bus

Nvidia 8800 Ultra Peak 103GBs

PCIExpress Input 4GBs

Bandwidth Discrepancy Demands Data on Graphics Card

bull Since transfer from CPU to GPU is much slower than GPU to graphics memory we have

ndash texture objects (OGL ge 11)ndash vertex buffer objects (OGL ge 15)ndash pixel buffer objects (OGL ge 21)ndash display lists (OGL ge 10)

Texture Sampling

bull Fragment Processor gets interpolated texture coordinates from Rasterize unit and does a texel lookup from some of the texture units (GL_MAX_TEXTURE_UNITS)

bull Each texture unit is a piece of GPU hardware () and hasndash Enabledisabled statendash Texture matrix stackndash state for automatic generation of texture coordinatesndash Texture environment statendash Current 1D 2D 3D and cube map texture

GL_TEXTUREi

1D

2D

3D

CUBE

Texture Unit rarr glBindTexturelarrTexture Object

GL_TEXTURE0

hellip

GL_ACTIVE_TEXTURE

glActiveTexture

Texture UnitsTexture Objects

GLuint=1

GLuint=2

GLuint=3

GLuint=N

GL_

MA

X_T

EX

TU

RE

_UN

ITS

hellip

as many as m

emory allow

s

glBindTexture

bind texture object to one of the four texture targets of the active texture unit

1D

2D

3D

CUBE

GL_TEXTURE1

1D

2D

3D

CUBE

GL_TEXTUREN

1D

2D

3D

CUBE

hellip

Transfer pixel data to GPU texture memory

bull data is associated with texture object

bull glTexImage(3D|2D|1D) ndash load whole image from CPU

bull glTexSubImage(3D|2D|1D) ndash load sub image from CPU

bull glCopyTexImage(1D|2D) ndash load whole image from framebuffer

bull glCopyTexSubImage(1D|2D|3D) ndash load sub-image from framebuffer

bull MIPMAP and compression supported

Texture Object - glTexParameter

bull wrapping behavior ndash repeat clamp mirror

bull minification ndash GL_NEARESTGL_LINEAR

xxx_MIPMAP_xxx

bull magnification ndash GL_NEARESTGL_LINEAR

bull border color ndash when using clamped wrapping

bull priority

bull level-of-detail control for MIPMAP

bull hellip

Texture Unit - glTexEnv

bull many options for how texel is combined with framebuffer pixel colorndash blendingndash replacementndash decalndash addingndash enable point sprites

hellip

Other Texture issues

bull multi-texturingndash texture units work seriallyndash glMultiTexCoord vs glTexCoord

bull glTexGen ndash generate texcoordrsquos from vertex coordinatesndash define function that computes tex coord

Vertex Buffer Objects - Preliminaries

bull builds off of client side vertex arrays1 glEnableClientState(GLenum array)

array from GL_VERTEX_ARRAY GL_COLOR_ARRAY GL_NORMAL_ARRAY etc

2 glVertexPointer(int size enum type sizei stride void pointer)size = 234 type = GL_FLOATGL_INT etc

3 glDrawArrays(GLenum mode GLint first GLsizei count) helliporhellip glDrawElements(GLenum mode GLsizei count GLenum

type void indices) index helliporhellip

glBegin(GL_TRIANGLE) glArrayElement(2) index hellip

Vertex Buffer Objects ndash Create and Initialize

bull VBOrsquos instead of lsquopointerrsquo pointing to CPU memory itrsquos treated as a offset to a vertex buffer in GPU memory

bull glGenBuffers(GLsizei n GLuint buffers) create namebull glBindBuffer(GLenum target GLuint buffer) create buffer

target=GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER

bull glBufferData(GLenum target GLsizeiptr size const GLvoid data GLenum usage) copy data to buffer

size = elements size of elementdata = pointer to CPU memory or NULL (no initialize)usage = GL_(STREAM|STATIC|DYNAMIC)_(DRAW|READ|COPY)

usage is a performance hint

Vertex Buffer Objects - usage

bull _DRAW - data used as vertex data for renderingbull _READ ndash data read from an OGL buffer (such as

framebuffer) and used in application for computations not immediately related to rendering (OGL ge 21)

bull _COPY ndash data values are read from OGL buffer and then used as vertex data for rendering (OGL ge 21)

bull _STREAM_ - frequent updates to buffer but only used a few times in drawing or other operations (updatedraw asymp 11)

bull _STATIC_ - set data once and use many times (updatedraw = 1N)

bull _DYNAMIC_ - you may update buffer often and use it many times as well (updatedraw = NN)

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 2: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Overview

bull OpenGL Pipeline

bull OpenGL transformation pipeline

bull rasterization and perspective correct interpolation

bull Standard lighting

Notation

bull xyz ndash real number (Times)bull pqr ndash 3D point or vector (Bold Lowercase Arial)bull M ndash 4x4 matrix (Bold Arial Uppercase M)bull ABC ndashcoordinate system (Bold Uppercase

Script)

bull MAlarrB ndash 4x4 matrix mapping coordinate from coordinate space B to space A

bull pAqArA ndash coordinate of point or vector relative to coordinate system A

bull PQR ndash a plane (Bold Uppercase Arial)bull lpo ndash a line (Bold Italic Times)

OpenGL Graphics Pipeline

OpenGL Transform Pipeline

dev clip j

1 1 1 1

c cw c c e e od

c cw c c e e od

c cw c c e ed

c c

x xx x w x x xx

y yy y w y y yy

z zz z w z z zz

w w

win eye eye wld wld obM M M M

1o

GL_MODELVIEWGL_PROJECTIONViewportTransformation

(glViewport ampglDepthRange)

ldquoeye coordinatesrdquo(lighting)

ldquoclip coordinatesrdquo(3D clipping)

ldquowindow coordinatesrdquo(rasterization)

McliplarreyeM0 = Meyelarrwld

M1 = Meyelarrwld M wldlarrobj

ldquoobject coordinatesrdquo

ldquonormalized devicecoordinatesrdquo

Clipdiv

Vertex ProcessorClip Proj Vp CullF P

Affine Transformations

00 01 02 03

10 11 12 13

20 21 22 23

0 0 0 1

x a a a a x

y a a a a y

z a a a a z

w w

M

bulltranslate (T) ndash preserve area length angles orientationbullrotate (R) ndash preserve area length anglesbullscale (S) ndash preserve perpendicularity of axisbullrigid-bodycongruency ndash (T R) preserve area length anglesbulluniform scalerdquosimilarityrdquo ndash preserve angles orientation

All affine transformations

preserve linespreserve parallelismpreserve distance ratio (rarrequal spacing)map points to points amp vectors to vectors

Starttypically GL_MODELVIEW stack contains affine transformations

Preserve Lines

l

l

M transforming entire grid

l p = p0 + t (p1-p0 ) rarr l M(p) =M(p0) + t (M(p1)-M(p0))

p0

p1

p

p0

p

p1

Parallelism

la lb

la

lb

M transforming entire grid

la || lb rarr M(la) || M(lb) = la || lb

Distance Ratios

l

l

M transforming entire grid

abbc = abbc

a

b

c

a

b c

Object Coordinates to Eye Coordinates

far clipping plane

y

xz

near clippingplane

y

xz

World Coordinates

W

Eye Coordinates

y

xz

Body Coord

y

xz

Head Coord

Perspective Collineation

00 01 02 03

10 11 12 13

20 21 22 23

30 31 32 33

a a a ax x

a a a ay y

a a a az z

a a a aw w

M

bulltypically GL_PROJECTION stack contains a dimension preserving perspective collineation

bullexample of non-dimension preserving perspective collineation

+Z

-Z

(0 0 0)

(xyz)

(xprojyproj-d)

x

proj

proj

proj

xx

z dy

yz d

z d

Properties of Perspective Collineation

bull preserve lines

bull does not preserve parallelism

bull does not preserve distance ratios

eye

P

view window

bull 3D2D collapse loses depth informationndash zbuffer needs depth information but only works for

parallel projection

bull fastest frustum clipping algorithm would clip to unit cube ndash not arbitrary frustum

Non-dimension preserving persp collineation problem 1

eye b0

b1

a1a0a

b

y

z

b0b1

a1a0a

b

yz

eye at infin=(0010)

bull fastest frustum clipping algorithm would clip to unit cube ndash not against an arbitrary frustum

Non-dimension preserving persp collineation problem 2

(-1-1-1)

(111)

xdev

ydev

zdev

clipping planes have most trivial equation posible (z=1z=-1x=1x=-1 etc) Hence solving clipping intersection

equations is fast as possible

Perspective Collineation (Dimension Preserving)

near clippingplane

far clipping plane

eye

View Window

near clippingplane

far clipping plane

Mpers

Mpers2D Mparallel(3Drarr2D)

3Drarr3D

=

(3Drarr2D)

Rasterization ndash Pixel Window Coordinates

a

b

c

Rasterization - zBuffer(x1y1z1)

(x2y2z2)(x3y3z3)

(xryrzr)(xlylzl)

(xyz)

bull Generally to compute z

bull Incremental in x

bull Incremental in y

Ax By Dz

C

( 1)

A x By Dz z A C

C

1

So

or if =

x x m

A m Bz z z z B C m

C

Rasterization ndash Texture Coordinates

bull assign 3 (st)-coordinates to 3 vertices of geometric primitive

linearly interpolate (st) to map texture space to object-space

v1t1

v0t0

v2t2

t

s

t0 t1

t2 t=(st)

t=(st)

(11)

v1t1

v0t0

v2t2

t

s

t0 t1

t2t=(st)t=(st)

(11)

texture spaceobject space

window space

t=(st)t=(st) non-affine

affine

Mobjlarrtex

Mwinlarrobj

Rasterization Need Rational linear interpolation

Rational linear interpolation in Scan-Conversion

t

s

t0 t1

t2

t=(st)

(11)

texture spacewindow space

t=(st)t=(st)non-affine

MwinlarrobjMobjlarrtex

(sqtqq)bulllinearly interpolate 3 variables

sqtqqbullcompute st with a division per pixel

s=sqq t=tqq

Rasterization Who does what

bull Rasterize unit does ndash scan conversion (generate (xy))ndash rational linear interpolation of texture coordinatesndash linear interpolation of depth coordinatendash rational linear () interpolation of vertex color

bull Fragment Processorndash if using fragment shader you can further modify the

depth coordinate and texture coordinate from those generated by Rasterize unit

Rasterization GL state

bull GL_POINTS ndash glPointSize glPointParameter POINT SPRITE texture

bull GL_LINESGL_LINE_LOOP ndash glLineWidth glLineStipple

bull GL_TRIANGLES etc ndash glPolygonStipple glPolygonMode glPolygonOffset glFrontFace

bull crude anti-aliasing ndash glEnable GL_POINT_SMOOTH GL_LINE_SMOOTH GL_POLYGON_SMOOTH

bull Is color interpolated - glShadeModel

Per-Fragment Operations - I

bull pixel ownership test ndash is the destination pixel visible or obscured by other window

bull scissor test ndash clips fragment against rectangle given by glScissor

bull alpha test ndash decides whether to discard fragment based on comparison of fragrsquos alpha value with target given by glAlphaFunc

bull stencil test ndash compares stencil buffer value with reference value and decides whether to discard pixel (glStencilFunc glStencilOp)

bull depth test ndash use function set by glDepthFunc to compare depth of fragment to depth of destination pixel in framebuffer

Per-Fragment Operations - II

bull blending ndash color stored in pixel is blend of fragment color and original pixel color and blend state (glBlendFunc glBlendColor glBlendEquation)

bull logical operations ndashbitwise boolean operations (glLogicOp)

bull dithering - old

Frame Buffer Operations

bull which buffer(s) are written too GL_FRONT GL_FRONT_LEFTGL_AUX0 etc (glDrawBuffer glDrawBuffers)

bull write protection ndash which bitsbytes are affected (glColorMask glDepthMask glStencilMask)

bull clear framebuffer ndash glClear glClearColor glClearDepth glClearStencil glClearAccum

bull glFlush ndash make sure all primitives are progressing toward completion (noone waiting around in queue)

bull glFinish ndash block () until all pending GL calls have executed

Graphics Workstation

DisplayProcessor Display

ProcessorMemory

FramebufferVideo

Controller

PeripheralDevices

CPU SystemMemory

System Bus

Nvidia 8800 Ultra Peak 103GBs

PCIExpress Input 4GBs

Bandwidth Discrepancy Demands Data on Graphics Card

bull Since transfer from CPU to GPU is much slower than GPU to graphics memory we have

ndash texture objects (OGL ge 11)ndash vertex buffer objects (OGL ge 15)ndash pixel buffer objects (OGL ge 21)ndash display lists (OGL ge 10)

Texture Sampling

bull Fragment Processor gets interpolated texture coordinates from Rasterize unit and does a texel lookup from some of the texture units (GL_MAX_TEXTURE_UNITS)

bull Each texture unit is a piece of GPU hardware () and hasndash Enabledisabled statendash Texture matrix stackndash state for automatic generation of texture coordinatesndash Texture environment statendash Current 1D 2D 3D and cube map texture

GL_TEXTUREi

1D

2D

3D

CUBE

Texture Unit rarr glBindTexturelarrTexture Object

GL_TEXTURE0

hellip

GL_ACTIVE_TEXTURE

glActiveTexture

Texture UnitsTexture Objects

GLuint=1

GLuint=2

GLuint=3

GLuint=N

GL_

MA

X_T

EX

TU

RE

_UN

ITS

hellip

as many as m

emory allow

s

glBindTexture

bind texture object to one of the four texture targets of the active texture unit

1D

2D

3D

CUBE

GL_TEXTURE1

1D

2D

3D

CUBE

GL_TEXTUREN

1D

2D

3D

CUBE

hellip

Transfer pixel data to GPU texture memory

bull data is associated with texture object

bull glTexImage(3D|2D|1D) ndash load whole image from CPU

bull glTexSubImage(3D|2D|1D) ndash load sub image from CPU

bull glCopyTexImage(1D|2D) ndash load whole image from framebuffer

bull glCopyTexSubImage(1D|2D|3D) ndash load sub-image from framebuffer

bull MIPMAP and compression supported

Texture Object - glTexParameter

bull wrapping behavior ndash repeat clamp mirror

bull minification ndash GL_NEARESTGL_LINEAR

xxx_MIPMAP_xxx

bull magnification ndash GL_NEARESTGL_LINEAR

bull border color ndash when using clamped wrapping

bull priority

bull level-of-detail control for MIPMAP

bull hellip

Texture Unit - glTexEnv

bull many options for how texel is combined with framebuffer pixel colorndash blendingndash replacementndash decalndash addingndash enable point sprites

hellip

Other Texture issues

bull multi-texturingndash texture units work seriallyndash glMultiTexCoord vs glTexCoord

bull glTexGen ndash generate texcoordrsquos from vertex coordinatesndash define function that computes tex coord

Vertex Buffer Objects - Preliminaries

bull builds off of client side vertex arrays1 glEnableClientState(GLenum array)

array from GL_VERTEX_ARRAY GL_COLOR_ARRAY GL_NORMAL_ARRAY etc

2 glVertexPointer(int size enum type sizei stride void pointer)size = 234 type = GL_FLOATGL_INT etc

3 glDrawArrays(GLenum mode GLint first GLsizei count) helliporhellip glDrawElements(GLenum mode GLsizei count GLenum

type void indices) index helliporhellip

glBegin(GL_TRIANGLE) glArrayElement(2) index hellip

Vertex Buffer Objects ndash Create and Initialize

bull VBOrsquos instead of lsquopointerrsquo pointing to CPU memory itrsquos treated as a offset to a vertex buffer in GPU memory

bull glGenBuffers(GLsizei n GLuint buffers) create namebull glBindBuffer(GLenum target GLuint buffer) create buffer

target=GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER

bull glBufferData(GLenum target GLsizeiptr size const GLvoid data GLenum usage) copy data to buffer

size = elements size of elementdata = pointer to CPU memory or NULL (no initialize)usage = GL_(STREAM|STATIC|DYNAMIC)_(DRAW|READ|COPY)

usage is a performance hint

Vertex Buffer Objects - usage

bull _DRAW - data used as vertex data for renderingbull _READ ndash data read from an OGL buffer (such as

framebuffer) and used in application for computations not immediately related to rendering (OGL ge 21)

bull _COPY ndash data values are read from OGL buffer and then used as vertex data for rendering (OGL ge 21)

bull _STREAM_ - frequent updates to buffer but only used a few times in drawing or other operations (updatedraw asymp 11)

bull _STATIC_ - set data once and use many times (updatedraw = 1N)

bull _DYNAMIC_ - you may update buffer often and use it many times as well (updatedraw = NN)

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 3: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Notation

bull xyz ndash real number (Times)bull pqr ndash 3D point or vector (Bold Lowercase Arial)bull M ndash 4x4 matrix (Bold Arial Uppercase M)bull ABC ndashcoordinate system (Bold Uppercase

Script)

bull MAlarrB ndash 4x4 matrix mapping coordinate from coordinate space B to space A

bull pAqArA ndash coordinate of point or vector relative to coordinate system A

bull PQR ndash a plane (Bold Uppercase Arial)bull lpo ndash a line (Bold Italic Times)

OpenGL Graphics Pipeline

OpenGL Transform Pipeline

dev clip j

1 1 1 1

c cw c c e e od

c cw c c e e od

c cw c c e ed

c c

x xx x w x x xx

y yy y w y y yy

z zz z w z z zz

w w

win eye eye wld wld obM M M M

1o

GL_MODELVIEWGL_PROJECTIONViewportTransformation

(glViewport ampglDepthRange)

ldquoeye coordinatesrdquo(lighting)

ldquoclip coordinatesrdquo(3D clipping)

ldquowindow coordinatesrdquo(rasterization)

McliplarreyeM0 = Meyelarrwld

M1 = Meyelarrwld M wldlarrobj

ldquoobject coordinatesrdquo

ldquonormalized devicecoordinatesrdquo

Clipdiv

Vertex ProcessorClip Proj Vp CullF P

Affine Transformations

00 01 02 03

10 11 12 13

20 21 22 23

0 0 0 1

x a a a a x

y a a a a y

z a a a a z

w w

M

bulltranslate (T) ndash preserve area length angles orientationbullrotate (R) ndash preserve area length anglesbullscale (S) ndash preserve perpendicularity of axisbullrigid-bodycongruency ndash (T R) preserve area length anglesbulluniform scalerdquosimilarityrdquo ndash preserve angles orientation

All affine transformations

preserve linespreserve parallelismpreserve distance ratio (rarrequal spacing)map points to points amp vectors to vectors

Starttypically GL_MODELVIEW stack contains affine transformations

Preserve Lines

l

l

M transforming entire grid

l p = p0 + t (p1-p0 ) rarr l M(p) =M(p0) + t (M(p1)-M(p0))

p0

p1

p

p0

p

p1

Parallelism

la lb

la

lb

M transforming entire grid

la || lb rarr M(la) || M(lb) = la || lb

Distance Ratios

l

l

M transforming entire grid

abbc = abbc

a

b

c

a

b c

Object Coordinates to Eye Coordinates

far clipping plane

y

xz

near clippingplane

y

xz

World Coordinates

W

Eye Coordinates

y

xz

Body Coord

y

xz

Head Coord

Perspective Collineation

00 01 02 03

10 11 12 13

20 21 22 23

30 31 32 33

a a a ax x

a a a ay y

a a a az z

a a a aw w

M

bulltypically GL_PROJECTION stack contains a dimension preserving perspective collineation

bullexample of non-dimension preserving perspective collineation

+Z

-Z

(0 0 0)

(xyz)

(xprojyproj-d)

x

proj

proj

proj

xx

z dy

yz d

z d

Properties of Perspective Collineation

bull preserve lines

bull does not preserve parallelism

bull does not preserve distance ratios

eye

P

view window

bull 3D2D collapse loses depth informationndash zbuffer needs depth information but only works for

parallel projection

bull fastest frustum clipping algorithm would clip to unit cube ndash not arbitrary frustum

Non-dimension preserving persp collineation problem 1

eye b0

b1

a1a0a

b

y

z

b0b1

a1a0a

b

yz

eye at infin=(0010)

bull fastest frustum clipping algorithm would clip to unit cube ndash not against an arbitrary frustum

Non-dimension preserving persp collineation problem 2

(-1-1-1)

(111)

xdev

ydev

zdev

clipping planes have most trivial equation posible (z=1z=-1x=1x=-1 etc) Hence solving clipping intersection

equations is fast as possible

Perspective Collineation (Dimension Preserving)

near clippingplane

far clipping plane

eye

View Window

near clippingplane

far clipping plane

Mpers

Mpers2D Mparallel(3Drarr2D)

3Drarr3D

=

(3Drarr2D)

Rasterization ndash Pixel Window Coordinates

a

b

c

Rasterization - zBuffer(x1y1z1)

(x2y2z2)(x3y3z3)

(xryrzr)(xlylzl)

(xyz)

bull Generally to compute z

bull Incremental in x

bull Incremental in y

Ax By Dz

C

( 1)

A x By Dz z A C

C

1

So

or if =

x x m

A m Bz z z z B C m

C

Rasterization ndash Texture Coordinates

bull assign 3 (st)-coordinates to 3 vertices of geometric primitive

linearly interpolate (st) to map texture space to object-space

v1t1

v0t0

v2t2

t

s

t0 t1

t2 t=(st)

t=(st)

(11)

v1t1

v0t0

v2t2

t

s

t0 t1

t2t=(st)t=(st)

(11)

texture spaceobject space

window space

t=(st)t=(st) non-affine

affine

Mobjlarrtex

Mwinlarrobj

Rasterization Need Rational linear interpolation

Rational linear interpolation in Scan-Conversion

t

s

t0 t1

t2

t=(st)

(11)

texture spacewindow space

t=(st)t=(st)non-affine

MwinlarrobjMobjlarrtex

(sqtqq)bulllinearly interpolate 3 variables

sqtqqbullcompute st with a division per pixel

s=sqq t=tqq

Rasterization Who does what

bull Rasterize unit does ndash scan conversion (generate (xy))ndash rational linear interpolation of texture coordinatesndash linear interpolation of depth coordinatendash rational linear () interpolation of vertex color

bull Fragment Processorndash if using fragment shader you can further modify the

depth coordinate and texture coordinate from those generated by Rasterize unit

Rasterization GL state

bull GL_POINTS ndash glPointSize glPointParameter POINT SPRITE texture

bull GL_LINESGL_LINE_LOOP ndash glLineWidth glLineStipple

bull GL_TRIANGLES etc ndash glPolygonStipple glPolygonMode glPolygonOffset glFrontFace

bull crude anti-aliasing ndash glEnable GL_POINT_SMOOTH GL_LINE_SMOOTH GL_POLYGON_SMOOTH

bull Is color interpolated - glShadeModel

Per-Fragment Operations - I

bull pixel ownership test ndash is the destination pixel visible or obscured by other window

bull scissor test ndash clips fragment against rectangle given by glScissor

bull alpha test ndash decides whether to discard fragment based on comparison of fragrsquos alpha value with target given by glAlphaFunc

bull stencil test ndash compares stencil buffer value with reference value and decides whether to discard pixel (glStencilFunc glStencilOp)

bull depth test ndash use function set by glDepthFunc to compare depth of fragment to depth of destination pixel in framebuffer

Per-Fragment Operations - II

bull blending ndash color stored in pixel is blend of fragment color and original pixel color and blend state (glBlendFunc glBlendColor glBlendEquation)

bull logical operations ndashbitwise boolean operations (glLogicOp)

bull dithering - old

Frame Buffer Operations

bull which buffer(s) are written too GL_FRONT GL_FRONT_LEFTGL_AUX0 etc (glDrawBuffer glDrawBuffers)

bull write protection ndash which bitsbytes are affected (glColorMask glDepthMask glStencilMask)

bull clear framebuffer ndash glClear glClearColor glClearDepth glClearStencil glClearAccum

bull glFlush ndash make sure all primitives are progressing toward completion (noone waiting around in queue)

bull glFinish ndash block () until all pending GL calls have executed

Graphics Workstation

DisplayProcessor Display

ProcessorMemory

FramebufferVideo

Controller

PeripheralDevices

CPU SystemMemory

System Bus

Nvidia 8800 Ultra Peak 103GBs

PCIExpress Input 4GBs

Bandwidth Discrepancy Demands Data on Graphics Card

bull Since transfer from CPU to GPU is much slower than GPU to graphics memory we have

ndash texture objects (OGL ge 11)ndash vertex buffer objects (OGL ge 15)ndash pixel buffer objects (OGL ge 21)ndash display lists (OGL ge 10)

Texture Sampling

bull Fragment Processor gets interpolated texture coordinates from Rasterize unit and does a texel lookup from some of the texture units (GL_MAX_TEXTURE_UNITS)

bull Each texture unit is a piece of GPU hardware () and hasndash Enabledisabled statendash Texture matrix stackndash state for automatic generation of texture coordinatesndash Texture environment statendash Current 1D 2D 3D and cube map texture

GL_TEXTUREi

1D

2D

3D

CUBE

Texture Unit rarr glBindTexturelarrTexture Object

GL_TEXTURE0

hellip

GL_ACTIVE_TEXTURE

glActiveTexture

Texture UnitsTexture Objects

GLuint=1

GLuint=2

GLuint=3

GLuint=N

GL_

MA

X_T

EX

TU

RE

_UN

ITS

hellip

as many as m

emory allow

s

glBindTexture

bind texture object to one of the four texture targets of the active texture unit

1D

2D

3D

CUBE

GL_TEXTURE1

1D

2D

3D

CUBE

GL_TEXTUREN

1D

2D

3D

CUBE

hellip

Transfer pixel data to GPU texture memory

bull data is associated with texture object

bull glTexImage(3D|2D|1D) ndash load whole image from CPU

bull glTexSubImage(3D|2D|1D) ndash load sub image from CPU

bull glCopyTexImage(1D|2D) ndash load whole image from framebuffer

bull glCopyTexSubImage(1D|2D|3D) ndash load sub-image from framebuffer

bull MIPMAP and compression supported

Texture Object - glTexParameter

bull wrapping behavior ndash repeat clamp mirror

bull minification ndash GL_NEARESTGL_LINEAR

xxx_MIPMAP_xxx

bull magnification ndash GL_NEARESTGL_LINEAR

bull border color ndash when using clamped wrapping

bull priority

bull level-of-detail control for MIPMAP

bull hellip

Texture Unit - glTexEnv

bull many options for how texel is combined with framebuffer pixel colorndash blendingndash replacementndash decalndash addingndash enable point sprites

hellip

Other Texture issues

bull multi-texturingndash texture units work seriallyndash glMultiTexCoord vs glTexCoord

bull glTexGen ndash generate texcoordrsquos from vertex coordinatesndash define function that computes tex coord

Vertex Buffer Objects - Preliminaries

bull builds off of client side vertex arrays1 glEnableClientState(GLenum array)

array from GL_VERTEX_ARRAY GL_COLOR_ARRAY GL_NORMAL_ARRAY etc

2 glVertexPointer(int size enum type sizei stride void pointer)size = 234 type = GL_FLOATGL_INT etc

3 glDrawArrays(GLenum mode GLint first GLsizei count) helliporhellip glDrawElements(GLenum mode GLsizei count GLenum

type void indices) index helliporhellip

glBegin(GL_TRIANGLE) glArrayElement(2) index hellip

Vertex Buffer Objects ndash Create and Initialize

bull VBOrsquos instead of lsquopointerrsquo pointing to CPU memory itrsquos treated as a offset to a vertex buffer in GPU memory

bull glGenBuffers(GLsizei n GLuint buffers) create namebull glBindBuffer(GLenum target GLuint buffer) create buffer

target=GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER

bull glBufferData(GLenum target GLsizeiptr size const GLvoid data GLenum usage) copy data to buffer

size = elements size of elementdata = pointer to CPU memory or NULL (no initialize)usage = GL_(STREAM|STATIC|DYNAMIC)_(DRAW|READ|COPY)

usage is a performance hint

Vertex Buffer Objects - usage

bull _DRAW - data used as vertex data for renderingbull _READ ndash data read from an OGL buffer (such as

framebuffer) and used in application for computations not immediately related to rendering (OGL ge 21)

bull _COPY ndash data values are read from OGL buffer and then used as vertex data for rendering (OGL ge 21)

bull _STREAM_ - frequent updates to buffer but only used a few times in drawing or other operations (updatedraw asymp 11)

bull _STATIC_ - set data once and use many times (updatedraw = 1N)

bull _DYNAMIC_ - you may update buffer often and use it many times as well (updatedraw = NN)

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 4: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

OpenGL Graphics Pipeline

OpenGL Transform Pipeline

dev clip j

1 1 1 1

c cw c c e e od

c cw c c e e od

c cw c c e ed

c c

x xx x w x x xx

y yy y w y y yy

z zz z w z z zz

w w

win eye eye wld wld obM M M M

1o

GL_MODELVIEWGL_PROJECTIONViewportTransformation

(glViewport ampglDepthRange)

ldquoeye coordinatesrdquo(lighting)

ldquoclip coordinatesrdquo(3D clipping)

ldquowindow coordinatesrdquo(rasterization)

McliplarreyeM0 = Meyelarrwld

M1 = Meyelarrwld M wldlarrobj

ldquoobject coordinatesrdquo

ldquonormalized devicecoordinatesrdquo

Clipdiv

Vertex ProcessorClip Proj Vp CullF P

Affine Transformations

00 01 02 03

10 11 12 13

20 21 22 23

0 0 0 1

x a a a a x

y a a a a y

z a a a a z

w w

M

bulltranslate (T) ndash preserve area length angles orientationbullrotate (R) ndash preserve area length anglesbullscale (S) ndash preserve perpendicularity of axisbullrigid-bodycongruency ndash (T R) preserve area length anglesbulluniform scalerdquosimilarityrdquo ndash preserve angles orientation

All affine transformations

preserve linespreserve parallelismpreserve distance ratio (rarrequal spacing)map points to points amp vectors to vectors

Starttypically GL_MODELVIEW stack contains affine transformations

Preserve Lines

l

l

M transforming entire grid

l p = p0 + t (p1-p0 ) rarr l M(p) =M(p0) + t (M(p1)-M(p0))

p0

p1

p

p0

p

p1

Parallelism

la lb

la

lb

M transforming entire grid

la || lb rarr M(la) || M(lb) = la || lb

Distance Ratios

l

l

M transforming entire grid

abbc = abbc

a

b

c

a

b c

Object Coordinates to Eye Coordinates

far clipping plane

y

xz

near clippingplane

y

xz

World Coordinates

W

Eye Coordinates

y

xz

Body Coord

y

xz

Head Coord

Perspective Collineation

00 01 02 03

10 11 12 13

20 21 22 23

30 31 32 33

a a a ax x

a a a ay y

a a a az z

a a a aw w

M

bulltypically GL_PROJECTION stack contains a dimension preserving perspective collineation

bullexample of non-dimension preserving perspective collineation

+Z

-Z

(0 0 0)

(xyz)

(xprojyproj-d)

x

proj

proj

proj

xx

z dy

yz d

z d

Properties of Perspective Collineation

bull preserve lines

bull does not preserve parallelism

bull does not preserve distance ratios

eye

P

view window

bull 3D2D collapse loses depth informationndash zbuffer needs depth information but only works for

parallel projection

bull fastest frustum clipping algorithm would clip to unit cube ndash not arbitrary frustum

Non-dimension preserving persp collineation problem 1

eye b0

b1

a1a0a

b

y

z

b0b1

a1a0a

b

yz

eye at infin=(0010)

bull fastest frustum clipping algorithm would clip to unit cube ndash not against an arbitrary frustum

Non-dimension preserving persp collineation problem 2

(-1-1-1)

(111)

xdev

ydev

zdev

clipping planes have most trivial equation posible (z=1z=-1x=1x=-1 etc) Hence solving clipping intersection

equations is fast as possible

Perspective Collineation (Dimension Preserving)

near clippingplane

far clipping plane

eye

View Window

near clippingplane

far clipping plane

Mpers

Mpers2D Mparallel(3Drarr2D)

3Drarr3D

=

(3Drarr2D)

Rasterization ndash Pixel Window Coordinates

a

b

c

Rasterization - zBuffer(x1y1z1)

(x2y2z2)(x3y3z3)

(xryrzr)(xlylzl)

(xyz)

bull Generally to compute z

bull Incremental in x

bull Incremental in y

Ax By Dz

C

( 1)

A x By Dz z A C

C

1

So

or if =

x x m

A m Bz z z z B C m

C

Rasterization ndash Texture Coordinates

bull assign 3 (st)-coordinates to 3 vertices of geometric primitive

linearly interpolate (st) to map texture space to object-space

v1t1

v0t0

v2t2

t

s

t0 t1

t2 t=(st)

t=(st)

(11)

v1t1

v0t0

v2t2

t

s

t0 t1

t2t=(st)t=(st)

(11)

texture spaceobject space

window space

t=(st)t=(st) non-affine

affine

Mobjlarrtex

Mwinlarrobj

Rasterization Need Rational linear interpolation

Rational linear interpolation in Scan-Conversion

t

s

t0 t1

t2

t=(st)

(11)

texture spacewindow space

t=(st)t=(st)non-affine

MwinlarrobjMobjlarrtex

(sqtqq)bulllinearly interpolate 3 variables

sqtqqbullcompute st with a division per pixel

s=sqq t=tqq

Rasterization Who does what

bull Rasterize unit does ndash scan conversion (generate (xy))ndash rational linear interpolation of texture coordinatesndash linear interpolation of depth coordinatendash rational linear () interpolation of vertex color

bull Fragment Processorndash if using fragment shader you can further modify the

depth coordinate and texture coordinate from those generated by Rasterize unit

Rasterization GL state

bull GL_POINTS ndash glPointSize glPointParameter POINT SPRITE texture

bull GL_LINESGL_LINE_LOOP ndash glLineWidth glLineStipple

bull GL_TRIANGLES etc ndash glPolygonStipple glPolygonMode glPolygonOffset glFrontFace

bull crude anti-aliasing ndash glEnable GL_POINT_SMOOTH GL_LINE_SMOOTH GL_POLYGON_SMOOTH

bull Is color interpolated - glShadeModel

Per-Fragment Operations - I

bull pixel ownership test ndash is the destination pixel visible or obscured by other window

bull scissor test ndash clips fragment against rectangle given by glScissor

bull alpha test ndash decides whether to discard fragment based on comparison of fragrsquos alpha value with target given by glAlphaFunc

bull stencil test ndash compares stencil buffer value with reference value and decides whether to discard pixel (glStencilFunc glStencilOp)

bull depth test ndash use function set by glDepthFunc to compare depth of fragment to depth of destination pixel in framebuffer

Per-Fragment Operations - II

bull blending ndash color stored in pixel is blend of fragment color and original pixel color and blend state (glBlendFunc glBlendColor glBlendEquation)

bull logical operations ndashbitwise boolean operations (glLogicOp)

bull dithering - old

Frame Buffer Operations

bull which buffer(s) are written too GL_FRONT GL_FRONT_LEFTGL_AUX0 etc (glDrawBuffer glDrawBuffers)

bull write protection ndash which bitsbytes are affected (glColorMask glDepthMask glStencilMask)

bull clear framebuffer ndash glClear glClearColor glClearDepth glClearStencil glClearAccum

bull glFlush ndash make sure all primitives are progressing toward completion (noone waiting around in queue)

bull glFinish ndash block () until all pending GL calls have executed

Graphics Workstation

DisplayProcessor Display

ProcessorMemory

FramebufferVideo

Controller

PeripheralDevices

CPU SystemMemory

System Bus

Nvidia 8800 Ultra Peak 103GBs

PCIExpress Input 4GBs

Bandwidth Discrepancy Demands Data on Graphics Card

bull Since transfer from CPU to GPU is much slower than GPU to graphics memory we have

ndash texture objects (OGL ge 11)ndash vertex buffer objects (OGL ge 15)ndash pixel buffer objects (OGL ge 21)ndash display lists (OGL ge 10)

Texture Sampling

bull Fragment Processor gets interpolated texture coordinates from Rasterize unit and does a texel lookup from some of the texture units (GL_MAX_TEXTURE_UNITS)

bull Each texture unit is a piece of GPU hardware () and hasndash Enabledisabled statendash Texture matrix stackndash state for automatic generation of texture coordinatesndash Texture environment statendash Current 1D 2D 3D and cube map texture

GL_TEXTUREi

1D

2D

3D

CUBE

Texture Unit rarr glBindTexturelarrTexture Object

GL_TEXTURE0

hellip

GL_ACTIVE_TEXTURE

glActiveTexture

Texture UnitsTexture Objects

GLuint=1

GLuint=2

GLuint=3

GLuint=N

GL_

MA

X_T

EX

TU

RE

_UN

ITS

hellip

as many as m

emory allow

s

glBindTexture

bind texture object to one of the four texture targets of the active texture unit

1D

2D

3D

CUBE

GL_TEXTURE1

1D

2D

3D

CUBE

GL_TEXTUREN

1D

2D

3D

CUBE

hellip

Transfer pixel data to GPU texture memory

bull data is associated with texture object

bull glTexImage(3D|2D|1D) ndash load whole image from CPU

bull glTexSubImage(3D|2D|1D) ndash load sub image from CPU

bull glCopyTexImage(1D|2D) ndash load whole image from framebuffer

bull glCopyTexSubImage(1D|2D|3D) ndash load sub-image from framebuffer

bull MIPMAP and compression supported

Texture Object - glTexParameter

bull wrapping behavior ndash repeat clamp mirror

bull minification ndash GL_NEARESTGL_LINEAR

xxx_MIPMAP_xxx

bull magnification ndash GL_NEARESTGL_LINEAR

bull border color ndash when using clamped wrapping

bull priority

bull level-of-detail control for MIPMAP

bull hellip

Texture Unit - glTexEnv

bull many options for how texel is combined with framebuffer pixel colorndash blendingndash replacementndash decalndash addingndash enable point sprites

hellip

Other Texture issues

bull multi-texturingndash texture units work seriallyndash glMultiTexCoord vs glTexCoord

bull glTexGen ndash generate texcoordrsquos from vertex coordinatesndash define function that computes tex coord

Vertex Buffer Objects - Preliminaries

bull builds off of client side vertex arrays1 glEnableClientState(GLenum array)

array from GL_VERTEX_ARRAY GL_COLOR_ARRAY GL_NORMAL_ARRAY etc

2 glVertexPointer(int size enum type sizei stride void pointer)size = 234 type = GL_FLOATGL_INT etc

3 glDrawArrays(GLenum mode GLint first GLsizei count) helliporhellip glDrawElements(GLenum mode GLsizei count GLenum

type void indices) index helliporhellip

glBegin(GL_TRIANGLE) glArrayElement(2) index hellip

Vertex Buffer Objects ndash Create and Initialize

bull VBOrsquos instead of lsquopointerrsquo pointing to CPU memory itrsquos treated as a offset to a vertex buffer in GPU memory

bull glGenBuffers(GLsizei n GLuint buffers) create namebull glBindBuffer(GLenum target GLuint buffer) create buffer

target=GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER

bull glBufferData(GLenum target GLsizeiptr size const GLvoid data GLenum usage) copy data to buffer

size = elements size of elementdata = pointer to CPU memory or NULL (no initialize)usage = GL_(STREAM|STATIC|DYNAMIC)_(DRAW|READ|COPY)

usage is a performance hint

Vertex Buffer Objects - usage

bull _DRAW - data used as vertex data for renderingbull _READ ndash data read from an OGL buffer (such as

framebuffer) and used in application for computations not immediately related to rendering (OGL ge 21)

bull _COPY ndash data values are read from OGL buffer and then used as vertex data for rendering (OGL ge 21)

bull _STREAM_ - frequent updates to buffer but only used a few times in drawing or other operations (updatedraw asymp 11)

bull _STATIC_ - set data once and use many times (updatedraw = 1N)

bull _DYNAMIC_ - you may update buffer often and use it many times as well (updatedraw = NN)

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 5: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

OpenGL Transform Pipeline

dev clip j

1 1 1 1

c cw c c e e od

c cw c c e e od

c cw c c e ed

c c

x xx x w x x xx

y yy y w y y yy

z zz z w z z zz

w w

win eye eye wld wld obM M M M

1o

GL_MODELVIEWGL_PROJECTIONViewportTransformation

(glViewport ampglDepthRange)

ldquoeye coordinatesrdquo(lighting)

ldquoclip coordinatesrdquo(3D clipping)

ldquowindow coordinatesrdquo(rasterization)

McliplarreyeM0 = Meyelarrwld

M1 = Meyelarrwld M wldlarrobj

ldquoobject coordinatesrdquo

ldquonormalized devicecoordinatesrdquo

Clipdiv

Vertex ProcessorClip Proj Vp CullF P

Affine Transformations

00 01 02 03

10 11 12 13

20 21 22 23

0 0 0 1

x a a a a x

y a a a a y

z a a a a z

w w

M

bulltranslate (T) ndash preserve area length angles orientationbullrotate (R) ndash preserve area length anglesbullscale (S) ndash preserve perpendicularity of axisbullrigid-bodycongruency ndash (T R) preserve area length anglesbulluniform scalerdquosimilarityrdquo ndash preserve angles orientation

All affine transformations

preserve linespreserve parallelismpreserve distance ratio (rarrequal spacing)map points to points amp vectors to vectors

Starttypically GL_MODELVIEW stack contains affine transformations

Preserve Lines

l

l

M transforming entire grid

l p = p0 + t (p1-p0 ) rarr l M(p) =M(p0) + t (M(p1)-M(p0))

p0

p1

p

p0

p

p1

Parallelism

la lb

la

lb

M transforming entire grid

la || lb rarr M(la) || M(lb) = la || lb

Distance Ratios

l

l

M transforming entire grid

abbc = abbc

a

b

c

a

b c

Object Coordinates to Eye Coordinates

far clipping plane

y

xz

near clippingplane

y

xz

World Coordinates

W

Eye Coordinates

y

xz

Body Coord

y

xz

Head Coord

Perspective Collineation

00 01 02 03

10 11 12 13

20 21 22 23

30 31 32 33

a a a ax x

a a a ay y

a a a az z

a a a aw w

M

bulltypically GL_PROJECTION stack contains a dimension preserving perspective collineation

bullexample of non-dimension preserving perspective collineation

+Z

-Z

(0 0 0)

(xyz)

(xprojyproj-d)

x

proj

proj

proj

xx

z dy

yz d

z d

Properties of Perspective Collineation

bull preserve lines

bull does not preserve parallelism

bull does not preserve distance ratios

eye

P

view window

bull 3D2D collapse loses depth informationndash zbuffer needs depth information but only works for

parallel projection

bull fastest frustum clipping algorithm would clip to unit cube ndash not arbitrary frustum

Non-dimension preserving persp collineation problem 1

eye b0

b1

a1a0a

b

y

z

b0b1

a1a0a

b

yz

eye at infin=(0010)

bull fastest frustum clipping algorithm would clip to unit cube ndash not against an arbitrary frustum

Non-dimension preserving persp collineation problem 2

(-1-1-1)

(111)

xdev

ydev

zdev

clipping planes have most trivial equation posible (z=1z=-1x=1x=-1 etc) Hence solving clipping intersection

equations is fast as possible

Perspective Collineation (Dimension Preserving)

near clippingplane

far clipping plane

eye

View Window

near clippingplane

far clipping plane

Mpers

Mpers2D Mparallel(3Drarr2D)

3Drarr3D

=

(3Drarr2D)

Rasterization ndash Pixel Window Coordinates

a

b

c

Rasterization - zBuffer(x1y1z1)

(x2y2z2)(x3y3z3)

(xryrzr)(xlylzl)

(xyz)

bull Generally to compute z

bull Incremental in x

bull Incremental in y

Ax By Dz

C

( 1)

A x By Dz z A C

C

1

So

or if =

x x m

A m Bz z z z B C m

C

Rasterization ndash Texture Coordinates

bull assign 3 (st)-coordinates to 3 vertices of geometric primitive

linearly interpolate (st) to map texture space to object-space

v1t1

v0t0

v2t2

t

s

t0 t1

t2 t=(st)

t=(st)

(11)

v1t1

v0t0

v2t2

t

s

t0 t1

t2t=(st)t=(st)

(11)

texture spaceobject space

window space

t=(st)t=(st) non-affine

affine

Mobjlarrtex

Mwinlarrobj

Rasterization Need Rational linear interpolation

Rational linear interpolation in Scan-Conversion

t

s

t0 t1

t2

t=(st)

(11)

texture spacewindow space

t=(st)t=(st)non-affine

MwinlarrobjMobjlarrtex

(sqtqq)bulllinearly interpolate 3 variables

sqtqqbullcompute st with a division per pixel

s=sqq t=tqq

Rasterization Who does what

bull Rasterize unit does ndash scan conversion (generate (xy))ndash rational linear interpolation of texture coordinatesndash linear interpolation of depth coordinatendash rational linear () interpolation of vertex color

bull Fragment Processorndash if using fragment shader you can further modify the

depth coordinate and texture coordinate from those generated by Rasterize unit

Rasterization GL state

bull GL_POINTS ndash glPointSize glPointParameter POINT SPRITE texture

bull GL_LINESGL_LINE_LOOP ndash glLineWidth glLineStipple

bull GL_TRIANGLES etc ndash glPolygonStipple glPolygonMode glPolygonOffset glFrontFace

bull crude anti-aliasing ndash glEnable GL_POINT_SMOOTH GL_LINE_SMOOTH GL_POLYGON_SMOOTH

bull Is color interpolated - glShadeModel

Per-Fragment Operations - I

bull pixel ownership test ndash is the destination pixel visible or obscured by other window

bull scissor test ndash clips fragment against rectangle given by glScissor

bull alpha test ndash decides whether to discard fragment based on comparison of fragrsquos alpha value with target given by glAlphaFunc

bull stencil test ndash compares stencil buffer value with reference value and decides whether to discard pixel (glStencilFunc glStencilOp)

bull depth test ndash use function set by glDepthFunc to compare depth of fragment to depth of destination pixel in framebuffer

Per-Fragment Operations - II

bull blending ndash color stored in pixel is blend of fragment color and original pixel color and blend state (glBlendFunc glBlendColor glBlendEquation)

bull logical operations ndashbitwise boolean operations (glLogicOp)

bull dithering - old

Frame Buffer Operations

bull which buffer(s) are written too GL_FRONT GL_FRONT_LEFTGL_AUX0 etc (glDrawBuffer glDrawBuffers)

bull write protection ndash which bitsbytes are affected (glColorMask glDepthMask glStencilMask)

bull clear framebuffer ndash glClear glClearColor glClearDepth glClearStencil glClearAccum

bull glFlush ndash make sure all primitives are progressing toward completion (noone waiting around in queue)

bull glFinish ndash block () until all pending GL calls have executed

Graphics Workstation

DisplayProcessor Display

ProcessorMemory

FramebufferVideo

Controller

PeripheralDevices

CPU SystemMemory

System Bus

Nvidia 8800 Ultra Peak 103GBs

PCIExpress Input 4GBs

Bandwidth Discrepancy Demands Data on Graphics Card

bull Since transfer from CPU to GPU is much slower than GPU to graphics memory we have

ndash texture objects (OGL ge 11)ndash vertex buffer objects (OGL ge 15)ndash pixel buffer objects (OGL ge 21)ndash display lists (OGL ge 10)

Texture Sampling

bull Fragment Processor gets interpolated texture coordinates from Rasterize unit and does a texel lookup from some of the texture units (GL_MAX_TEXTURE_UNITS)

bull Each texture unit is a piece of GPU hardware () and hasndash Enabledisabled statendash Texture matrix stackndash state for automatic generation of texture coordinatesndash Texture environment statendash Current 1D 2D 3D and cube map texture

GL_TEXTUREi

1D

2D

3D

CUBE

Texture Unit rarr glBindTexturelarrTexture Object

GL_TEXTURE0

hellip

GL_ACTIVE_TEXTURE

glActiveTexture

Texture UnitsTexture Objects

GLuint=1

GLuint=2

GLuint=3

GLuint=N

GL_

MA

X_T

EX

TU

RE

_UN

ITS

hellip

as many as m

emory allow

s

glBindTexture

bind texture object to one of the four texture targets of the active texture unit

1D

2D

3D

CUBE

GL_TEXTURE1

1D

2D

3D

CUBE

GL_TEXTUREN

1D

2D

3D

CUBE

hellip

Transfer pixel data to GPU texture memory

bull data is associated with texture object

bull glTexImage(3D|2D|1D) ndash load whole image from CPU

bull glTexSubImage(3D|2D|1D) ndash load sub image from CPU

bull glCopyTexImage(1D|2D) ndash load whole image from framebuffer

bull glCopyTexSubImage(1D|2D|3D) ndash load sub-image from framebuffer

bull MIPMAP and compression supported

Texture Object - glTexParameter

bull wrapping behavior ndash repeat clamp mirror

bull minification ndash GL_NEARESTGL_LINEAR

xxx_MIPMAP_xxx

bull magnification ndash GL_NEARESTGL_LINEAR

bull border color ndash when using clamped wrapping

bull priority

bull level-of-detail control for MIPMAP

bull hellip

Texture Unit - glTexEnv

bull many options for how texel is combined with framebuffer pixel colorndash blendingndash replacementndash decalndash addingndash enable point sprites

hellip

Other Texture issues

bull multi-texturingndash texture units work seriallyndash glMultiTexCoord vs glTexCoord

bull glTexGen ndash generate texcoordrsquos from vertex coordinatesndash define function that computes tex coord

Vertex Buffer Objects - Preliminaries

bull builds off of client side vertex arrays1 glEnableClientState(GLenum array)

array from GL_VERTEX_ARRAY GL_COLOR_ARRAY GL_NORMAL_ARRAY etc

2 glVertexPointer(int size enum type sizei stride void pointer)size = 234 type = GL_FLOATGL_INT etc

3 glDrawArrays(GLenum mode GLint first GLsizei count) helliporhellip glDrawElements(GLenum mode GLsizei count GLenum

type void indices) index helliporhellip

glBegin(GL_TRIANGLE) glArrayElement(2) index hellip

Vertex Buffer Objects ndash Create and Initialize

bull VBOrsquos instead of lsquopointerrsquo pointing to CPU memory itrsquos treated as a offset to a vertex buffer in GPU memory

bull glGenBuffers(GLsizei n GLuint buffers) create namebull glBindBuffer(GLenum target GLuint buffer) create buffer

target=GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER

bull glBufferData(GLenum target GLsizeiptr size const GLvoid data GLenum usage) copy data to buffer

size = elements size of elementdata = pointer to CPU memory or NULL (no initialize)usage = GL_(STREAM|STATIC|DYNAMIC)_(DRAW|READ|COPY)

usage is a performance hint

Vertex Buffer Objects - usage

bull _DRAW - data used as vertex data for renderingbull _READ ndash data read from an OGL buffer (such as

framebuffer) and used in application for computations not immediately related to rendering (OGL ge 21)

bull _COPY ndash data values are read from OGL buffer and then used as vertex data for rendering (OGL ge 21)

bull _STREAM_ - frequent updates to buffer but only used a few times in drawing or other operations (updatedraw asymp 11)

bull _STATIC_ - set data once and use many times (updatedraw = 1N)

bull _DYNAMIC_ - you may update buffer often and use it many times as well (updatedraw = NN)

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 6: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Affine Transformations

00 01 02 03

10 11 12 13

20 21 22 23

0 0 0 1

x a a a a x

y a a a a y

z a a a a z

w w

M

bulltranslate (T) ndash preserve area length angles orientationbullrotate (R) ndash preserve area length anglesbullscale (S) ndash preserve perpendicularity of axisbullrigid-bodycongruency ndash (T R) preserve area length anglesbulluniform scalerdquosimilarityrdquo ndash preserve angles orientation

All affine transformations

preserve linespreserve parallelismpreserve distance ratio (rarrequal spacing)map points to points amp vectors to vectors

Starttypically GL_MODELVIEW stack contains affine transformations

Preserve Lines

l

l

M transforming entire grid

l p = p0 + t (p1-p0 ) rarr l M(p) =M(p0) + t (M(p1)-M(p0))

p0

p1

p

p0

p

p1

Parallelism

la lb

la

lb

M transforming entire grid

la || lb rarr M(la) || M(lb) = la || lb

Distance Ratios

l

l

M transforming entire grid

abbc = abbc

a

b

c

a

b c

Object Coordinates to Eye Coordinates

far clipping plane

y

xz

near clippingplane

y

xz

World Coordinates

W

Eye Coordinates

y

xz

Body Coord

y

xz

Head Coord

Perspective Collineation

00 01 02 03

10 11 12 13

20 21 22 23

30 31 32 33

a a a ax x

a a a ay y

a a a az z

a a a aw w

M

bulltypically GL_PROJECTION stack contains a dimension preserving perspective collineation

bullexample of non-dimension preserving perspective collineation

+Z

-Z

(0 0 0)

(xyz)

(xprojyproj-d)

x

proj

proj

proj

xx

z dy

yz d

z d

Properties of Perspective Collineation

bull preserve lines

bull does not preserve parallelism

bull does not preserve distance ratios

eye

P

view window

bull 3D2D collapse loses depth informationndash zbuffer needs depth information but only works for

parallel projection

bull fastest frustum clipping algorithm would clip to unit cube ndash not arbitrary frustum

Non-dimension preserving persp collineation problem 1

eye b0

b1

a1a0a

b

y

z

b0b1

a1a0a

b

yz

eye at infin=(0010)

bull fastest frustum clipping algorithm would clip to unit cube ndash not against an arbitrary frustum

Non-dimension preserving persp collineation problem 2

(-1-1-1)

(111)

xdev

ydev

zdev

clipping planes have most trivial equation posible (z=1z=-1x=1x=-1 etc) Hence solving clipping intersection

equations is fast as possible

Perspective Collineation (Dimension Preserving)

near clippingplane

far clipping plane

eye

View Window

near clippingplane

far clipping plane

Mpers

Mpers2D Mparallel(3Drarr2D)

3Drarr3D

=

(3Drarr2D)

Rasterization ndash Pixel Window Coordinates

a

b

c

Rasterization - zBuffer(x1y1z1)

(x2y2z2)(x3y3z3)

(xryrzr)(xlylzl)

(xyz)

bull Generally to compute z

bull Incremental in x

bull Incremental in y

Ax By Dz

C

( 1)

A x By Dz z A C

C

1

So

or if =

x x m

A m Bz z z z B C m

C

Rasterization ndash Texture Coordinates

bull assign 3 (st)-coordinates to 3 vertices of geometric primitive

linearly interpolate (st) to map texture space to object-space

v1t1

v0t0

v2t2

t

s

t0 t1

t2 t=(st)

t=(st)

(11)

v1t1

v0t0

v2t2

t

s

t0 t1

t2t=(st)t=(st)

(11)

texture spaceobject space

window space

t=(st)t=(st) non-affine

affine

Mobjlarrtex

Mwinlarrobj

Rasterization Need Rational linear interpolation

Rational linear interpolation in Scan-Conversion

t

s

t0 t1

t2

t=(st)

(11)

texture spacewindow space

t=(st)t=(st)non-affine

MwinlarrobjMobjlarrtex

(sqtqq)bulllinearly interpolate 3 variables

sqtqqbullcompute st with a division per pixel

s=sqq t=tqq

Rasterization Who does what

bull Rasterize unit does ndash scan conversion (generate (xy))ndash rational linear interpolation of texture coordinatesndash linear interpolation of depth coordinatendash rational linear () interpolation of vertex color

bull Fragment Processorndash if using fragment shader you can further modify the

depth coordinate and texture coordinate from those generated by Rasterize unit

Rasterization GL state

bull GL_POINTS ndash glPointSize glPointParameter POINT SPRITE texture

bull GL_LINESGL_LINE_LOOP ndash glLineWidth glLineStipple

bull GL_TRIANGLES etc ndash glPolygonStipple glPolygonMode glPolygonOffset glFrontFace

bull crude anti-aliasing ndash glEnable GL_POINT_SMOOTH GL_LINE_SMOOTH GL_POLYGON_SMOOTH

bull Is color interpolated - glShadeModel

Per-Fragment Operations - I

bull pixel ownership test ndash is the destination pixel visible or obscured by other window

bull scissor test ndash clips fragment against rectangle given by glScissor

bull alpha test ndash decides whether to discard fragment based on comparison of fragrsquos alpha value with target given by glAlphaFunc

bull stencil test ndash compares stencil buffer value with reference value and decides whether to discard pixel (glStencilFunc glStencilOp)

bull depth test ndash use function set by glDepthFunc to compare depth of fragment to depth of destination pixel in framebuffer

Per-Fragment Operations - II

bull blending ndash color stored in pixel is blend of fragment color and original pixel color and blend state (glBlendFunc glBlendColor glBlendEquation)

bull logical operations ndashbitwise boolean operations (glLogicOp)

bull dithering - old

Frame Buffer Operations

bull which buffer(s) are written too GL_FRONT GL_FRONT_LEFTGL_AUX0 etc (glDrawBuffer glDrawBuffers)

bull write protection ndash which bitsbytes are affected (glColorMask glDepthMask glStencilMask)

bull clear framebuffer ndash glClear glClearColor glClearDepth glClearStencil glClearAccum

bull glFlush ndash make sure all primitives are progressing toward completion (noone waiting around in queue)

bull glFinish ndash block () until all pending GL calls have executed

Graphics Workstation

DisplayProcessor Display

ProcessorMemory

FramebufferVideo

Controller

PeripheralDevices

CPU SystemMemory

System Bus

Nvidia 8800 Ultra Peak 103GBs

PCIExpress Input 4GBs

Bandwidth Discrepancy Demands Data on Graphics Card

bull Since transfer from CPU to GPU is much slower than GPU to graphics memory we have

ndash texture objects (OGL ge 11)ndash vertex buffer objects (OGL ge 15)ndash pixel buffer objects (OGL ge 21)ndash display lists (OGL ge 10)

Texture Sampling

bull Fragment Processor gets interpolated texture coordinates from Rasterize unit and does a texel lookup from some of the texture units (GL_MAX_TEXTURE_UNITS)

bull Each texture unit is a piece of GPU hardware () and hasndash Enabledisabled statendash Texture matrix stackndash state for automatic generation of texture coordinatesndash Texture environment statendash Current 1D 2D 3D and cube map texture

GL_TEXTUREi

1D

2D

3D

CUBE

Texture Unit rarr glBindTexturelarrTexture Object

GL_TEXTURE0

hellip

GL_ACTIVE_TEXTURE

glActiveTexture

Texture UnitsTexture Objects

GLuint=1

GLuint=2

GLuint=3

GLuint=N

GL_

MA

X_T

EX

TU

RE

_UN

ITS

hellip

as many as m

emory allow

s

glBindTexture

bind texture object to one of the four texture targets of the active texture unit

1D

2D

3D

CUBE

GL_TEXTURE1

1D

2D

3D

CUBE

GL_TEXTUREN

1D

2D

3D

CUBE

hellip

Transfer pixel data to GPU texture memory

bull data is associated with texture object

bull glTexImage(3D|2D|1D) ndash load whole image from CPU

bull glTexSubImage(3D|2D|1D) ndash load sub image from CPU

bull glCopyTexImage(1D|2D) ndash load whole image from framebuffer

bull glCopyTexSubImage(1D|2D|3D) ndash load sub-image from framebuffer

bull MIPMAP and compression supported

Texture Object - glTexParameter

bull wrapping behavior ndash repeat clamp mirror

bull minification ndash GL_NEARESTGL_LINEAR

xxx_MIPMAP_xxx

bull magnification ndash GL_NEARESTGL_LINEAR

bull border color ndash when using clamped wrapping

bull priority

bull level-of-detail control for MIPMAP

bull hellip

Texture Unit - glTexEnv

bull many options for how texel is combined with framebuffer pixel colorndash blendingndash replacementndash decalndash addingndash enable point sprites

hellip

Other Texture issues

bull multi-texturingndash texture units work seriallyndash glMultiTexCoord vs glTexCoord

bull glTexGen ndash generate texcoordrsquos from vertex coordinatesndash define function that computes tex coord

Vertex Buffer Objects - Preliminaries

bull builds off of client side vertex arrays1 glEnableClientState(GLenum array)

array from GL_VERTEX_ARRAY GL_COLOR_ARRAY GL_NORMAL_ARRAY etc

2 glVertexPointer(int size enum type sizei stride void pointer)size = 234 type = GL_FLOATGL_INT etc

3 glDrawArrays(GLenum mode GLint first GLsizei count) helliporhellip glDrawElements(GLenum mode GLsizei count GLenum

type void indices) index helliporhellip

glBegin(GL_TRIANGLE) glArrayElement(2) index hellip

Vertex Buffer Objects ndash Create and Initialize

bull VBOrsquos instead of lsquopointerrsquo pointing to CPU memory itrsquos treated as a offset to a vertex buffer in GPU memory

bull glGenBuffers(GLsizei n GLuint buffers) create namebull glBindBuffer(GLenum target GLuint buffer) create buffer

target=GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER

bull glBufferData(GLenum target GLsizeiptr size const GLvoid data GLenum usage) copy data to buffer

size = elements size of elementdata = pointer to CPU memory or NULL (no initialize)usage = GL_(STREAM|STATIC|DYNAMIC)_(DRAW|READ|COPY)

usage is a performance hint

Vertex Buffer Objects - usage

bull _DRAW - data used as vertex data for renderingbull _READ ndash data read from an OGL buffer (such as

framebuffer) and used in application for computations not immediately related to rendering (OGL ge 21)

bull _COPY ndash data values are read from OGL buffer and then used as vertex data for rendering (OGL ge 21)

bull _STREAM_ - frequent updates to buffer but only used a few times in drawing or other operations (updatedraw asymp 11)

bull _STATIC_ - set data once and use many times (updatedraw = 1N)

bull _DYNAMIC_ - you may update buffer often and use it many times as well (updatedraw = NN)

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 7: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Preserve Lines

l

l

M transforming entire grid

l p = p0 + t (p1-p0 ) rarr l M(p) =M(p0) + t (M(p1)-M(p0))

p0

p1

p

p0

p

p1

Parallelism

la lb

la

lb

M transforming entire grid

la || lb rarr M(la) || M(lb) = la || lb

Distance Ratios

l

l

M transforming entire grid

abbc = abbc

a

b

c

a

b c

Object Coordinates to Eye Coordinates

far clipping plane

y

xz

near clippingplane

y

xz

World Coordinates

W

Eye Coordinates

y

xz

Body Coord

y

xz

Head Coord

Perspective Collineation

00 01 02 03

10 11 12 13

20 21 22 23

30 31 32 33

a a a ax x

a a a ay y

a a a az z

a a a aw w

M

bulltypically GL_PROJECTION stack contains a dimension preserving perspective collineation

bullexample of non-dimension preserving perspective collineation

+Z

-Z

(0 0 0)

(xyz)

(xprojyproj-d)

x

proj

proj

proj

xx

z dy

yz d

z d

Properties of Perspective Collineation

bull preserve lines

bull does not preserve parallelism

bull does not preserve distance ratios

eye

P

view window

bull 3D2D collapse loses depth informationndash zbuffer needs depth information but only works for

parallel projection

bull fastest frustum clipping algorithm would clip to unit cube ndash not arbitrary frustum

Non-dimension preserving persp collineation problem 1

eye b0

b1

a1a0a

b

y

z

b0b1

a1a0a

b

yz

eye at infin=(0010)

bull fastest frustum clipping algorithm would clip to unit cube ndash not against an arbitrary frustum

Non-dimension preserving persp collineation problem 2

(-1-1-1)

(111)

xdev

ydev

zdev

clipping planes have most trivial equation posible (z=1z=-1x=1x=-1 etc) Hence solving clipping intersection

equations is fast as possible

Perspective Collineation (Dimension Preserving)

near clippingplane

far clipping plane

eye

View Window

near clippingplane

far clipping plane

Mpers

Mpers2D Mparallel(3Drarr2D)

3Drarr3D

=

(3Drarr2D)

Rasterization ndash Pixel Window Coordinates

a

b

c

Rasterization - zBuffer(x1y1z1)

(x2y2z2)(x3y3z3)

(xryrzr)(xlylzl)

(xyz)

bull Generally to compute z

bull Incremental in x

bull Incremental in y

Ax By Dz

C

( 1)

A x By Dz z A C

C

1

So

or if =

x x m

A m Bz z z z B C m

C

Rasterization ndash Texture Coordinates

bull assign 3 (st)-coordinates to 3 vertices of geometric primitive

linearly interpolate (st) to map texture space to object-space

v1t1

v0t0

v2t2

t

s

t0 t1

t2 t=(st)

t=(st)

(11)

v1t1

v0t0

v2t2

t

s

t0 t1

t2t=(st)t=(st)

(11)

texture spaceobject space

window space

t=(st)t=(st) non-affine

affine

Mobjlarrtex

Mwinlarrobj

Rasterization Need Rational linear interpolation

Rational linear interpolation in Scan-Conversion

t

s

t0 t1

t2

t=(st)

(11)

texture spacewindow space

t=(st)t=(st)non-affine

MwinlarrobjMobjlarrtex

(sqtqq)bulllinearly interpolate 3 variables

sqtqqbullcompute st with a division per pixel

s=sqq t=tqq

Rasterization Who does what

bull Rasterize unit does ndash scan conversion (generate (xy))ndash rational linear interpolation of texture coordinatesndash linear interpolation of depth coordinatendash rational linear () interpolation of vertex color

bull Fragment Processorndash if using fragment shader you can further modify the

depth coordinate and texture coordinate from those generated by Rasterize unit

Rasterization GL state

bull GL_POINTS ndash glPointSize glPointParameter POINT SPRITE texture

bull GL_LINESGL_LINE_LOOP ndash glLineWidth glLineStipple

bull GL_TRIANGLES etc ndash glPolygonStipple glPolygonMode glPolygonOffset glFrontFace

bull crude anti-aliasing ndash glEnable GL_POINT_SMOOTH GL_LINE_SMOOTH GL_POLYGON_SMOOTH

bull Is color interpolated - glShadeModel

Per-Fragment Operations - I

bull pixel ownership test ndash is the destination pixel visible or obscured by other window

bull scissor test ndash clips fragment against rectangle given by glScissor

bull alpha test ndash decides whether to discard fragment based on comparison of fragrsquos alpha value with target given by glAlphaFunc

bull stencil test ndash compares stencil buffer value with reference value and decides whether to discard pixel (glStencilFunc glStencilOp)

bull depth test ndash use function set by glDepthFunc to compare depth of fragment to depth of destination pixel in framebuffer

Per-Fragment Operations - II

bull blending ndash color stored in pixel is blend of fragment color and original pixel color and blend state (glBlendFunc glBlendColor glBlendEquation)

bull logical operations ndashbitwise boolean operations (glLogicOp)

bull dithering - old

Frame Buffer Operations

bull which buffer(s) are written too GL_FRONT GL_FRONT_LEFTGL_AUX0 etc (glDrawBuffer glDrawBuffers)

bull write protection ndash which bitsbytes are affected (glColorMask glDepthMask glStencilMask)

bull clear framebuffer ndash glClear glClearColor glClearDepth glClearStencil glClearAccum

bull glFlush ndash make sure all primitives are progressing toward completion (noone waiting around in queue)

bull glFinish ndash block () until all pending GL calls have executed

Graphics Workstation

DisplayProcessor Display

ProcessorMemory

FramebufferVideo

Controller

PeripheralDevices

CPU SystemMemory

System Bus

Nvidia 8800 Ultra Peak 103GBs

PCIExpress Input 4GBs

Bandwidth Discrepancy Demands Data on Graphics Card

bull Since transfer from CPU to GPU is much slower than GPU to graphics memory we have

ndash texture objects (OGL ge 11)ndash vertex buffer objects (OGL ge 15)ndash pixel buffer objects (OGL ge 21)ndash display lists (OGL ge 10)

Texture Sampling

bull Fragment Processor gets interpolated texture coordinates from Rasterize unit and does a texel lookup from some of the texture units (GL_MAX_TEXTURE_UNITS)

bull Each texture unit is a piece of GPU hardware () and hasndash Enabledisabled statendash Texture matrix stackndash state for automatic generation of texture coordinatesndash Texture environment statendash Current 1D 2D 3D and cube map texture

GL_TEXTUREi

1D

2D

3D

CUBE

Texture Unit rarr glBindTexturelarrTexture Object

GL_TEXTURE0

hellip

GL_ACTIVE_TEXTURE

glActiveTexture

Texture UnitsTexture Objects

GLuint=1

GLuint=2

GLuint=3

GLuint=N

GL_

MA

X_T

EX

TU

RE

_UN

ITS

hellip

as many as m

emory allow

s

glBindTexture

bind texture object to one of the four texture targets of the active texture unit

1D

2D

3D

CUBE

GL_TEXTURE1

1D

2D

3D

CUBE

GL_TEXTUREN

1D

2D

3D

CUBE

hellip

Transfer pixel data to GPU texture memory

bull data is associated with texture object

bull glTexImage(3D|2D|1D) ndash load whole image from CPU

bull glTexSubImage(3D|2D|1D) ndash load sub image from CPU

bull glCopyTexImage(1D|2D) ndash load whole image from framebuffer

bull glCopyTexSubImage(1D|2D|3D) ndash load sub-image from framebuffer

bull MIPMAP and compression supported

Texture Object - glTexParameter

bull wrapping behavior ndash repeat clamp mirror

bull minification ndash GL_NEARESTGL_LINEAR

xxx_MIPMAP_xxx

bull magnification ndash GL_NEARESTGL_LINEAR

bull border color ndash when using clamped wrapping

bull priority

bull level-of-detail control for MIPMAP

bull hellip

Texture Unit - glTexEnv

bull many options for how texel is combined with framebuffer pixel colorndash blendingndash replacementndash decalndash addingndash enable point sprites

hellip

Other Texture issues

bull multi-texturingndash texture units work seriallyndash glMultiTexCoord vs glTexCoord

bull glTexGen ndash generate texcoordrsquos from vertex coordinatesndash define function that computes tex coord

Vertex Buffer Objects - Preliminaries

bull builds off of client side vertex arrays1 glEnableClientState(GLenum array)

array from GL_VERTEX_ARRAY GL_COLOR_ARRAY GL_NORMAL_ARRAY etc

2 glVertexPointer(int size enum type sizei stride void pointer)size = 234 type = GL_FLOATGL_INT etc

3 glDrawArrays(GLenum mode GLint first GLsizei count) helliporhellip glDrawElements(GLenum mode GLsizei count GLenum

type void indices) index helliporhellip

glBegin(GL_TRIANGLE) glArrayElement(2) index hellip

Vertex Buffer Objects ndash Create and Initialize

bull VBOrsquos instead of lsquopointerrsquo pointing to CPU memory itrsquos treated as a offset to a vertex buffer in GPU memory

bull glGenBuffers(GLsizei n GLuint buffers) create namebull glBindBuffer(GLenum target GLuint buffer) create buffer

target=GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER

bull glBufferData(GLenum target GLsizeiptr size const GLvoid data GLenum usage) copy data to buffer

size = elements size of elementdata = pointer to CPU memory or NULL (no initialize)usage = GL_(STREAM|STATIC|DYNAMIC)_(DRAW|READ|COPY)

usage is a performance hint

Vertex Buffer Objects - usage

bull _DRAW - data used as vertex data for renderingbull _READ ndash data read from an OGL buffer (such as

framebuffer) and used in application for computations not immediately related to rendering (OGL ge 21)

bull _COPY ndash data values are read from OGL buffer and then used as vertex data for rendering (OGL ge 21)

bull _STREAM_ - frequent updates to buffer but only used a few times in drawing or other operations (updatedraw asymp 11)

bull _STATIC_ - set data once and use many times (updatedraw = 1N)

bull _DYNAMIC_ - you may update buffer often and use it many times as well (updatedraw = NN)

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 8: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Parallelism

la lb

la

lb

M transforming entire grid

la || lb rarr M(la) || M(lb) = la || lb

Distance Ratios

l

l

M transforming entire grid

abbc = abbc

a

b

c

a

b c

Object Coordinates to Eye Coordinates

far clipping plane

y

xz

near clippingplane

y

xz

World Coordinates

W

Eye Coordinates

y

xz

Body Coord

y

xz

Head Coord

Perspective Collineation

00 01 02 03

10 11 12 13

20 21 22 23

30 31 32 33

a a a ax x

a a a ay y

a a a az z

a a a aw w

M

bulltypically GL_PROJECTION stack contains a dimension preserving perspective collineation

bullexample of non-dimension preserving perspective collineation

+Z

-Z

(0 0 0)

(xyz)

(xprojyproj-d)

x

proj

proj

proj

xx

z dy

yz d

z d

Properties of Perspective Collineation

bull preserve lines

bull does not preserve parallelism

bull does not preserve distance ratios

eye

P

view window

bull 3D2D collapse loses depth informationndash zbuffer needs depth information but only works for

parallel projection

bull fastest frustum clipping algorithm would clip to unit cube ndash not arbitrary frustum

Non-dimension preserving persp collineation problem 1

eye b0

b1

a1a0a

b

y

z

b0b1

a1a0a

b

yz

eye at infin=(0010)

bull fastest frustum clipping algorithm would clip to unit cube ndash not against an arbitrary frustum

Non-dimension preserving persp collineation problem 2

(-1-1-1)

(111)

xdev

ydev

zdev

clipping planes have most trivial equation posible (z=1z=-1x=1x=-1 etc) Hence solving clipping intersection

equations is fast as possible

Perspective Collineation (Dimension Preserving)

near clippingplane

far clipping plane

eye

View Window

near clippingplane

far clipping plane

Mpers

Mpers2D Mparallel(3Drarr2D)

3Drarr3D

=

(3Drarr2D)

Rasterization ndash Pixel Window Coordinates

a

b

c

Rasterization - zBuffer(x1y1z1)

(x2y2z2)(x3y3z3)

(xryrzr)(xlylzl)

(xyz)

bull Generally to compute z

bull Incremental in x

bull Incremental in y

Ax By Dz

C

( 1)

A x By Dz z A C

C

1

So

or if =

x x m

A m Bz z z z B C m

C

Rasterization ndash Texture Coordinates

bull assign 3 (st)-coordinates to 3 vertices of geometric primitive

linearly interpolate (st) to map texture space to object-space

v1t1

v0t0

v2t2

t

s

t0 t1

t2 t=(st)

t=(st)

(11)

v1t1

v0t0

v2t2

t

s

t0 t1

t2t=(st)t=(st)

(11)

texture spaceobject space

window space

t=(st)t=(st) non-affine

affine

Mobjlarrtex

Mwinlarrobj

Rasterization Need Rational linear interpolation

Rational linear interpolation in Scan-Conversion

t

s

t0 t1

t2

t=(st)

(11)

texture spacewindow space

t=(st)t=(st)non-affine

MwinlarrobjMobjlarrtex

(sqtqq)bulllinearly interpolate 3 variables

sqtqqbullcompute st with a division per pixel

s=sqq t=tqq

Rasterization Who does what

bull Rasterize unit does ndash scan conversion (generate (xy))ndash rational linear interpolation of texture coordinatesndash linear interpolation of depth coordinatendash rational linear () interpolation of vertex color

bull Fragment Processorndash if using fragment shader you can further modify the

depth coordinate and texture coordinate from those generated by Rasterize unit

Rasterization GL state

bull GL_POINTS ndash glPointSize glPointParameter POINT SPRITE texture

bull GL_LINESGL_LINE_LOOP ndash glLineWidth glLineStipple

bull GL_TRIANGLES etc ndash glPolygonStipple glPolygonMode glPolygonOffset glFrontFace

bull crude anti-aliasing ndash glEnable GL_POINT_SMOOTH GL_LINE_SMOOTH GL_POLYGON_SMOOTH

bull Is color interpolated - glShadeModel

Per-Fragment Operations - I

bull pixel ownership test ndash is the destination pixel visible or obscured by other window

bull scissor test ndash clips fragment against rectangle given by glScissor

bull alpha test ndash decides whether to discard fragment based on comparison of fragrsquos alpha value with target given by glAlphaFunc

bull stencil test ndash compares stencil buffer value with reference value and decides whether to discard pixel (glStencilFunc glStencilOp)

bull depth test ndash use function set by glDepthFunc to compare depth of fragment to depth of destination pixel in framebuffer

Per-Fragment Operations - II

bull blending ndash color stored in pixel is blend of fragment color and original pixel color and blend state (glBlendFunc glBlendColor glBlendEquation)

bull logical operations ndashbitwise boolean operations (glLogicOp)

bull dithering - old

Frame Buffer Operations

bull which buffer(s) are written too GL_FRONT GL_FRONT_LEFTGL_AUX0 etc (glDrawBuffer glDrawBuffers)

bull write protection ndash which bitsbytes are affected (glColorMask glDepthMask glStencilMask)

bull clear framebuffer ndash glClear glClearColor glClearDepth glClearStencil glClearAccum

bull glFlush ndash make sure all primitives are progressing toward completion (noone waiting around in queue)

bull glFinish ndash block () until all pending GL calls have executed

Graphics Workstation

DisplayProcessor Display

ProcessorMemory

FramebufferVideo

Controller

PeripheralDevices

CPU SystemMemory

System Bus

Nvidia 8800 Ultra Peak 103GBs

PCIExpress Input 4GBs

Bandwidth Discrepancy Demands Data on Graphics Card

bull Since transfer from CPU to GPU is much slower than GPU to graphics memory we have

ndash texture objects (OGL ge 11)ndash vertex buffer objects (OGL ge 15)ndash pixel buffer objects (OGL ge 21)ndash display lists (OGL ge 10)

Texture Sampling

bull Fragment Processor gets interpolated texture coordinates from Rasterize unit and does a texel lookup from some of the texture units (GL_MAX_TEXTURE_UNITS)

bull Each texture unit is a piece of GPU hardware () and hasndash Enabledisabled statendash Texture matrix stackndash state for automatic generation of texture coordinatesndash Texture environment statendash Current 1D 2D 3D and cube map texture

GL_TEXTUREi

1D

2D

3D

CUBE

Texture Unit rarr glBindTexturelarrTexture Object

GL_TEXTURE0

hellip

GL_ACTIVE_TEXTURE

glActiveTexture

Texture UnitsTexture Objects

GLuint=1

GLuint=2

GLuint=3

GLuint=N

GL_

MA

X_T

EX

TU

RE

_UN

ITS

hellip

as many as m

emory allow

s

glBindTexture

bind texture object to one of the four texture targets of the active texture unit

1D

2D

3D

CUBE

GL_TEXTURE1

1D

2D

3D

CUBE

GL_TEXTUREN

1D

2D

3D

CUBE

hellip

Transfer pixel data to GPU texture memory

bull data is associated with texture object

bull glTexImage(3D|2D|1D) ndash load whole image from CPU

bull glTexSubImage(3D|2D|1D) ndash load sub image from CPU

bull glCopyTexImage(1D|2D) ndash load whole image from framebuffer

bull glCopyTexSubImage(1D|2D|3D) ndash load sub-image from framebuffer

bull MIPMAP and compression supported

Texture Object - glTexParameter

bull wrapping behavior ndash repeat clamp mirror

bull minification ndash GL_NEARESTGL_LINEAR

xxx_MIPMAP_xxx

bull magnification ndash GL_NEARESTGL_LINEAR

bull border color ndash when using clamped wrapping

bull priority

bull level-of-detail control for MIPMAP

bull hellip

Texture Unit - glTexEnv

bull many options for how texel is combined with framebuffer pixel colorndash blendingndash replacementndash decalndash addingndash enable point sprites

hellip

Other Texture issues

bull multi-texturingndash texture units work seriallyndash glMultiTexCoord vs glTexCoord

bull glTexGen ndash generate texcoordrsquos from vertex coordinatesndash define function that computes tex coord

Vertex Buffer Objects - Preliminaries

bull builds off of client side vertex arrays1 glEnableClientState(GLenum array)

array from GL_VERTEX_ARRAY GL_COLOR_ARRAY GL_NORMAL_ARRAY etc

2 glVertexPointer(int size enum type sizei stride void pointer)size = 234 type = GL_FLOATGL_INT etc

3 glDrawArrays(GLenum mode GLint first GLsizei count) helliporhellip glDrawElements(GLenum mode GLsizei count GLenum

type void indices) index helliporhellip

glBegin(GL_TRIANGLE) glArrayElement(2) index hellip

Vertex Buffer Objects ndash Create and Initialize

bull VBOrsquos instead of lsquopointerrsquo pointing to CPU memory itrsquos treated as a offset to a vertex buffer in GPU memory

bull glGenBuffers(GLsizei n GLuint buffers) create namebull glBindBuffer(GLenum target GLuint buffer) create buffer

target=GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER

bull glBufferData(GLenum target GLsizeiptr size const GLvoid data GLenum usage) copy data to buffer

size = elements size of elementdata = pointer to CPU memory or NULL (no initialize)usage = GL_(STREAM|STATIC|DYNAMIC)_(DRAW|READ|COPY)

usage is a performance hint

Vertex Buffer Objects - usage

bull _DRAW - data used as vertex data for renderingbull _READ ndash data read from an OGL buffer (such as

framebuffer) and used in application for computations not immediately related to rendering (OGL ge 21)

bull _COPY ndash data values are read from OGL buffer and then used as vertex data for rendering (OGL ge 21)

bull _STREAM_ - frequent updates to buffer but only used a few times in drawing or other operations (updatedraw asymp 11)

bull _STATIC_ - set data once and use many times (updatedraw = 1N)

bull _DYNAMIC_ - you may update buffer often and use it many times as well (updatedraw = NN)

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 9: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Distance Ratios

l

l

M transforming entire grid

abbc = abbc

a

b

c

a

b c

Object Coordinates to Eye Coordinates

far clipping plane

y

xz

near clippingplane

y

xz

World Coordinates

W

Eye Coordinates

y

xz

Body Coord

y

xz

Head Coord

Perspective Collineation

00 01 02 03

10 11 12 13

20 21 22 23

30 31 32 33

a a a ax x

a a a ay y

a a a az z

a a a aw w

M

bulltypically GL_PROJECTION stack contains a dimension preserving perspective collineation

bullexample of non-dimension preserving perspective collineation

+Z

-Z

(0 0 0)

(xyz)

(xprojyproj-d)

x

proj

proj

proj

xx

z dy

yz d

z d

Properties of Perspective Collineation

bull preserve lines

bull does not preserve parallelism

bull does not preserve distance ratios

eye

P

view window

bull 3D2D collapse loses depth informationndash zbuffer needs depth information but only works for

parallel projection

bull fastest frustum clipping algorithm would clip to unit cube ndash not arbitrary frustum

Non-dimension preserving persp collineation problem 1

eye b0

b1

a1a0a

b

y

z

b0b1

a1a0a

b

yz

eye at infin=(0010)

bull fastest frustum clipping algorithm would clip to unit cube ndash not against an arbitrary frustum

Non-dimension preserving persp collineation problem 2

(-1-1-1)

(111)

xdev

ydev

zdev

clipping planes have most trivial equation posible (z=1z=-1x=1x=-1 etc) Hence solving clipping intersection

equations is fast as possible

Perspective Collineation (Dimension Preserving)

near clippingplane

far clipping plane

eye

View Window

near clippingplane

far clipping plane

Mpers

Mpers2D Mparallel(3Drarr2D)

3Drarr3D

=

(3Drarr2D)

Rasterization ndash Pixel Window Coordinates

a

b

c

Rasterization - zBuffer(x1y1z1)

(x2y2z2)(x3y3z3)

(xryrzr)(xlylzl)

(xyz)

bull Generally to compute z

bull Incremental in x

bull Incremental in y

Ax By Dz

C

( 1)

A x By Dz z A C

C

1

So

or if =

x x m

A m Bz z z z B C m

C

Rasterization ndash Texture Coordinates

bull assign 3 (st)-coordinates to 3 vertices of geometric primitive

linearly interpolate (st) to map texture space to object-space

v1t1

v0t0

v2t2

t

s

t0 t1

t2 t=(st)

t=(st)

(11)

v1t1

v0t0

v2t2

t

s

t0 t1

t2t=(st)t=(st)

(11)

texture spaceobject space

window space

t=(st)t=(st) non-affine

affine

Mobjlarrtex

Mwinlarrobj

Rasterization Need Rational linear interpolation

Rational linear interpolation in Scan-Conversion

t

s

t0 t1

t2

t=(st)

(11)

texture spacewindow space

t=(st)t=(st)non-affine

MwinlarrobjMobjlarrtex

(sqtqq)bulllinearly interpolate 3 variables

sqtqqbullcompute st with a division per pixel

s=sqq t=tqq

Rasterization Who does what

bull Rasterize unit does ndash scan conversion (generate (xy))ndash rational linear interpolation of texture coordinatesndash linear interpolation of depth coordinatendash rational linear () interpolation of vertex color

bull Fragment Processorndash if using fragment shader you can further modify the

depth coordinate and texture coordinate from those generated by Rasterize unit

Rasterization GL state

bull GL_POINTS ndash glPointSize glPointParameter POINT SPRITE texture

bull GL_LINESGL_LINE_LOOP ndash glLineWidth glLineStipple

bull GL_TRIANGLES etc ndash glPolygonStipple glPolygonMode glPolygonOffset glFrontFace

bull crude anti-aliasing ndash glEnable GL_POINT_SMOOTH GL_LINE_SMOOTH GL_POLYGON_SMOOTH

bull Is color interpolated - glShadeModel

Per-Fragment Operations - I

bull pixel ownership test ndash is the destination pixel visible or obscured by other window

bull scissor test ndash clips fragment against rectangle given by glScissor

bull alpha test ndash decides whether to discard fragment based on comparison of fragrsquos alpha value with target given by glAlphaFunc

bull stencil test ndash compares stencil buffer value with reference value and decides whether to discard pixel (glStencilFunc glStencilOp)

bull depth test ndash use function set by glDepthFunc to compare depth of fragment to depth of destination pixel in framebuffer

Per-Fragment Operations - II

bull blending ndash color stored in pixel is blend of fragment color and original pixel color and blend state (glBlendFunc glBlendColor glBlendEquation)

bull logical operations ndashbitwise boolean operations (glLogicOp)

bull dithering - old

Frame Buffer Operations

bull which buffer(s) are written too GL_FRONT GL_FRONT_LEFTGL_AUX0 etc (glDrawBuffer glDrawBuffers)

bull write protection ndash which bitsbytes are affected (glColorMask glDepthMask glStencilMask)

bull clear framebuffer ndash glClear glClearColor glClearDepth glClearStencil glClearAccum

bull glFlush ndash make sure all primitives are progressing toward completion (noone waiting around in queue)

bull glFinish ndash block () until all pending GL calls have executed

Graphics Workstation

DisplayProcessor Display

ProcessorMemory

FramebufferVideo

Controller

PeripheralDevices

CPU SystemMemory

System Bus

Nvidia 8800 Ultra Peak 103GBs

PCIExpress Input 4GBs

Bandwidth Discrepancy Demands Data on Graphics Card

bull Since transfer from CPU to GPU is much slower than GPU to graphics memory we have

ndash texture objects (OGL ge 11)ndash vertex buffer objects (OGL ge 15)ndash pixel buffer objects (OGL ge 21)ndash display lists (OGL ge 10)

Texture Sampling

bull Fragment Processor gets interpolated texture coordinates from Rasterize unit and does a texel lookup from some of the texture units (GL_MAX_TEXTURE_UNITS)

bull Each texture unit is a piece of GPU hardware () and hasndash Enabledisabled statendash Texture matrix stackndash state for automatic generation of texture coordinatesndash Texture environment statendash Current 1D 2D 3D and cube map texture

GL_TEXTUREi

1D

2D

3D

CUBE

Texture Unit rarr glBindTexturelarrTexture Object

GL_TEXTURE0

hellip

GL_ACTIVE_TEXTURE

glActiveTexture

Texture UnitsTexture Objects

GLuint=1

GLuint=2

GLuint=3

GLuint=N

GL_

MA

X_T

EX

TU

RE

_UN

ITS

hellip

as many as m

emory allow

s

glBindTexture

bind texture object to one of the four texture targets of the active texture unit

1D

2D

3D

CUBE

GL_TEXTURE1

1D

2D

3D

CUBE

GL_TEXTUREN

1D

2D

3D

CUBE

hellip

Transfer pixel data to GPU texture memory

bull data is associated with texture object

bull glTexImage(3D|2D|1D) ndash load whole image from CPU

bull glTexSubImage(3D|2D|1D) ndash load sub image from CPU

bull glCopyTexImage(1D|2D) ndash load whole image from framebuffer

bull glCopyTexSubImage(1D|2D|3D) ndash load sub-image from framebuffer

bull MIPMAP and compression supported

Texture Object - glTexParameter

bull wrapping behavior ndash repeat clamp mirror

bull minification ndash GL_NEARESTGL_LINEAR

xxx_MIPMAP_xxx

bull magnification ndash GL_NEARESTGL_LINEAR

bull border color ndash when using clamped wrapping

bull priority

bull level-of-detail control for MIPMAP

bull hellip

Texture Unit - glTexEnv

bull many options for how texel is combined with framebuffer pixel colorndash blendingndash replacementndash decalndash addingndash enable point sprites

hellip

Other Texture issues

bull multi-texturingndash texture units work seriallyndash glMultiTexCoord vs glTexCoord

bull glTexGen ndash generate texcoordrsquos from vertex coordinatesndash define function that computes tex coord

Vertex Buffer Objects - Preliminaries

bull builds off of client side vertex arrays1 glEnableClientState(GLenum array)

array from GL_VERTEX_ARRAY GL_COLOR_ARRAY GL_NORMAL_ARRAY etc

2 glVertexPointer(int size enum type sizei stride void pointer)size = 234 type = GL_FLOATGL_INT etc

3 glDrawArrays(GLenum mode GLint first GLsizei count) helliporhellip glDrawElements(GLenum mode GLsizei count GLenum

type void indices) index helliporhellip

glBegin(GL_TRIANGLE) glArrayElement(2) index hellip

Vertex Buffer Objects ndash Create and Initialize

bull VBOrsquos instead of lsquopointerrsquo pointing to CPU memory itrsquos treated as a offset to a vertex buffer in GPU memory

bull glGenBuffers(GLsizei n GLuint buffers) create namebull glBindBuffer(GLenum target GLuint buffer) create buffer

target=GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER

bull glBufferData(GLenum target GLsizeiptr size const GLvoid data GLenum usage) copy data to buffer

size = elements size of elementdata = pointer to CPU memory or NULL (no initialize)usage = GL_(STREAM|STATIC|DYNAMIC)_(DRAW|READ|COPY)

usage is a performance hint

Vertex Buffer Objects - usage

bull _DRAW - data used as vertex data for renderingbull _READ ndash data read from an OGL buffer (such as

framebuffer) and used in application for computations not immediately related to rendering (OGL ge 21)

bull _COPY ndash data values are read from OGL buffer and then used as vertex data for rendering (OGL ge 21)

bull _STREAM_ - frequent updates to buffer but only used a few times in drawing or other operations (updatedraw asymp 11)

bull _STATIC_ - set data once and use many times (updatedraw = 1N)

bull _DYNAMIC_ - you may update buffer often and use it many times as well (updatedraw = NN)

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 10: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Object Coordinates to Eye Coordinates

far clipping plane

y

xz

near clippingplane

y

xz

World Coordinates

W

Eye Coordinates

y

xz

Body Coord

y

xz

Head Coord

Perspective Collineation

00 01 02 03

10 11 12 13

20 21 22 23

30 31 32 33

a a a ax x

a a a ay y

a a a az z

a a a aw w

M

bulltypically GL_PROJECTION stack contains a dimension preserving perspective collineation

bullexample of non-dimension preserving perspective collineation

+Z

-Z

(0 0 0)

(xyz)

(xprojyproj-d)

x

proj

proj

proj

xx

z dy

yz d

z d

Properties of Perspective Collineation

bull preserve lines

bull does not preserve parallelism

bull does not preserve distance ratios

eye

P

view window

bull 3D2D collapse loses depth informationndash zbuffer needs depth information but only works for

parallel projection

bull fastest frustum clipping algorithm would clip to unit cube ndash not arbitrary frustum

Non-dimension preserving persp collineation problem 1

eye b0

b1

a1a0a

b

y

z

b0b1

a1a0a

b

yz

eye at infin=(0010)

bull fastest frustum clipping algorithm would clip to unit cube ndash not against an arbitrary frustum

Non-dimension preserving persp collineation problem 2

(-1-1-1)

(111)

xdev

ydev

zdev

clipping planes have most trivial equation posible (z=1z=-1x=1x=-1 etc) Hence solving clipping intersection

equations is fast as possible

Perspective Collineation (Dimension Preserving)

near clippingplane

far clipping plane

eye

View Window

near clippingplane

far clipping plane

Mpers

Mpers2D Mparallel(3Drarr2D)

3Drarr3D

=

(3Drarr2D)

Rasterization ndash Pixel Window Coordinates

a

b

c

Rasterization - zBuffer(x1y1z1)

(x2y2z2)(x3y3z3)

(xryrzr)(xlylzl)

(xyz)

bull Generally to compute z

bull Incremental in x

bull Incremental in y

Ax By Dz

C

( 1)

A x By Dz z A C

C

1

So

or if =

x x m

A m Bz z z z B C m

C

Rasterization ndash Texture Coordinates

bull assign 3 (st)-coordinates to 3 vertices of geometric primitive

linearly interpolate (st) to map texture space to object-space

v1t1

v0t0

v2t2

t

s

t0 t1

t2 t=(st)

t=(st)

(11)

v1t1

v0t0

v2t2

t

s

t0 t1

t2t=(st)t=(st)

(11)

texture spaceobject space

window space

t=(st)t=(st) non-affine

affine

Mobjlarrtex

Mwinlarrobj

Rasterization Need Rational linear interpolation

Rational linear interpolation in Scan-Conversion

t

s

t0 t1

t2

t=(st)

(11)

texture spacewindow space

t=(st)t=(st)non-affine

MwinlarrobjMobjlarrtex

(sqtqq)bulllinearly interpolate 3 variables

sqtqqbullcompute st with a division per pixel

s=sqq t=tqq

Rasterization Who does what

bull Rasterize unit does ndash scan conversion (generate (xy))ndash rational linear interpolation of texture coordinatesndash linear interpolation of depth coordinatendash rational linear () interpolation of vertex color

bull Fragment Processorndash if using fragment shader you can further modify the

depth coordinate and texture coordinate from those generated by Rasterize unit

Rasterization GL state

bull GL_POINTS ndash glPointSize glPointParameter POINT SPRITE texture

bull GL_LINESGL_LINE_LOOP ndash glLineWidth glLineStipple

bull GL_TRIANGLES etc ndash glPolygonStipple glPolygonMode glPolygonOffset glFrontFace

bull crude anti-aliasing ndash glEnable GL_POINT_SMOOTH GL_LINE_SMOOTH GL_POLYGON_SMOOTH

bull Is color interpolated - glShadeModel

Per-Fragment Operations - I

bull pixel ownership test ndash is the destination pixel visible or obscured by other window

bull scissor test ndash clips fragment against rectangle given by glScissor

bull alpha test ndash decides whether to discard fragment based on comparison of fragrsquos alpha value with target given by glAlphaFunc

bull stencil test ndash compares stencil buffer value with reference value and decides whether to discard pixel (glStencilFunc glStencilOp)

bull depth test ndash use function set by glDepthFunc to compare depth of fragment to depth of destination pixel in framebuffer

Per-Fragment Operations - II

bull blending ndash color stored in pixel is blend of fragment color and original pixel color and blend state (glBlendFunc glBlendColor glBlendEquation)

bull logical operations ndashbitwise boolean operations (glLogicOp)

bull dithering - old

Frame Buffer Operations

bull which buffer(s) are written too GL_FRONT GL_FRONT_LEFTGL_AUX0 etc (glDrawBuffer glDrawBuffers)

bull write protection ndash which bitsbytes are affected (glColorMask glDepthMask glStencilMask)

bull clear framebuffer ndash glClear glClearColor glClearDepth glClearStencil glClearAccum

bull glFlush ndash make sure all primitives are progressing toward completion (noone waiting around in queue)

bull glFinish ndash block () until all pending GL calls have executed

Graphics Workstation

DisplayProcessor Display

ProcessorMemory

FramebufferVideo

Controller

PeripheralDevices

CPU SystemMemory

System Bus

Nvidia 8800 Ultra Peak 103GBs

PCIExpress Input 4GBs

Bandwidth Discrepancy Demands Data on Graphics Card

bull Since transfer from CPU to GPU is much slower than GPU to graphics memory we have

ndash texture objects (OGL ge 11)ndash vertex buffer objects (OGL ge 15)ndash pixel buffer objects (OGL ge 21)ndash display lists (OGL ge 10)

Texture Sampling

bull Fragment Processor gets interpolated texture coordinates from Rasterize unit and does a texel lookup from some of the texture units (GL_MAX_TEXTURE_UNITS)

bull Each texture unit is a piece of GPU hardware () and hasndash Enabledisabled statendash Texture matrix stackndash state for automatic generation of texture coordinatesndash Texture environment statendash Current 1D 2D 3D and cube map texture

GL_TEXTUREi

1D

2D

3D

CUBE

Texture Unit rarr glBindTexturelarrTexture Object

GL_TEXTURE0

hellip

GL_ACTIVE_TEXTURE

glActiveTexture

Texture UnitsTexture Objects

GLuint=1

GLuint=2

GLuint=3

GLuint=N

GL_

MA

X_T

EX

TU

RE

_UN

ITS

hellip

as many as m

emory allow

s

glBindTexture

bind texture object to one of the four texture targets of the active texture unit

1D

2D

3D

CUBE

GL_TEXTURE1

1D

2D

3D

CUBE

GL_TEXTUREN

1D

2D

3D

CUBE

hellip

Transfer pixel data to GPU texture memory

bull data is associated with texture object

bull glTexImage(3D|2D|1D) ndash load whole image from CPU

bull glTexSubImage(3D|2D|1D) ndash load sub image from CPU

bull glCopyTexImage(1D|2D) ndash load whole image from framebuffer

bull glCopyTexSubImage(1D|2D|3D) ndash load sub-image from framebuffer

bull MIPMAP and compression supported

Texture Object - glTexParameter

bull wrapping behavior ndash repeat clamp mirror

bull minification ndash GL_NEARESTGL_LINEAR

xxx_MIPMAP_xxx

bull magnification ndash GL_NEARESTGL_LINEAR

bull border color ndash when using clamped wrapping

bull priority

bull level-of-detail control for MIPMAP

bull hellip

Texture Unit - glTexEnv

bull many options for how texel is combined with framebuffer pixel colorndash blendingndash replacementndash decalndash addingndash enable point sprites

hellip

Other Texture issues

bull multi-texturingndash texture units work seriallyndash glMultiTexCoord vs glTexCoord

bull glTexGen ndash generate texcoordrsquos from vertex coordinatesndash define function that computes tex coord

Vertex Buffer Objects - Preliminaries

bull builds off of client side vertex arrays1 glEnableClientState(GLenum array)

array from GL_VERTEX_ARRAY GL_COLOR_ARRAY GL_NORMAL_ARRAY etc

2 glVertexPointer(int size enum type sizei stride void pointer)size = 234 type = GL_FLOATGL_INT etc

3 glDrawArrays(GLenum mode GLint first GLsizei count) helliporhellip glDrawElements(GLenum mode GLsizei count GLenum

type void indices) index helliporhellip

glBegin(GL_TRIANGLE) glArrayElement(2) index hellip

Vertex Buffer Objects ndash Create and Initialize

bull VBOrsquos instead of lsquopointerrsquo pointing to CPU memory itrsquos treated as a offset to a vertex buffer in GPU memory

bull glGenBuffers(GLsizei n GLuint buffers) create namebull glBindBuffer(GLenum target GLuint buffer) create buffer

target=GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER

bull glBufferData(GLenum target GLsizeiptr size const GLvoid data GLenum usage) copy data to buffer

size = elements size of elementdata = pointer to CPU memory or NULL (no initialize)usage = GL_(STREAM|STATIC|DYNAMIC)_(DRAW|READ|COPY)

usage is a performance hint

Vertex Buffer Objects - usage

bull _DRAW - data used as vertex data for renderingbull _READ ndash data read from an OGL buffer (such as

framebuffer) and used in application for computations not immediately related to rendering (OGL ge 21)

bull _COPY ndash data values are read from OGL buffer and then used as vertex data for rendering (OGL ge 21)

bull _STREAM_ - frequent updates to buffer but only used a few times in drawing or other operations (updatedraw asymp 11)

bull _STATIC_ - set data once and use many times (updatedraw = 1N)

bull _DYNAMIC_ - you may update buffer often and use it many times as well (updatedraw = NN)

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 11: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Perspective Collineation

00 01 02 03

10 11 12 13

20 21 22 23

30 31 32 33

a a a ax x

a a a ay y

a a a az z

a a a aw w

M

bulltypically GL_PROJECTION stack contains a dimension preserving perspective collineation

bullexample of non-dimension preserving perspective collineation

+Z

-Z

(0 0 0)

(xyz)

(xprojyproj-d)

x

proj

proj

proj

xx

z dy

yz d

z d

Properties of Perspective Collineation

bull preserve lines

bull does not preserve parallelism

bull does not preserve distance ratios

eye

P

view window

bull 3D2D collapse loses depth informationndash zbuffer needs depth information but only works for

parallel projection

bull fastest frustum clipping algorithm would clip to unit cube ndash not arbitrary frustum

Non-dimension preserving persp collineation problem 1

eye b0

b1

a1a0a

b

y

z

b0b1

a1a0a

b

yz

eye at infin=(0010)

bull fastest frustum clipping algorithm would clip to unit cube ndash not against an arbitrary frustum

Non-dimension preserving persp collineation problem 2

(-1-1-1)

(111)

xdev

ydev

zdev

clipping planes have most trivial equation posible (z=1z=-1x=1x=-1 etc) Hence solving clipping intersection

equations is fast as possible

Perspective Collineation (Dimension Preserving)

near clippingplane

far clipping plane

eye

View Window

near clippingplane

far clipping plane

Mpers

Mpers2D Mparallel(3Drarr2D)

3Drarr3D

=

(3Drarr2D)

Rasterization ndash Pixel Window Coordinates

a

b

c

Rasterization - zBuffer(x1y1z1)

(x2y2z2)(x3y3z3)

(xryrzr)(xlylzl)

(xyz)

bull Generally to compute z

bull Incremental in x

bull Incremental in y

Ax By Dz

C

( 1)

A x By Dz z A C

C

1

So

or if =

x x m

A m Bz z z z B C m

C

Rasterization ndash Texture Coordinates

bull assign 3 (st)-coordinates to 3 vertices of geometric primitive

linearly interpolate (st) to map texture space to object-space

v1t1

v0t0

v2t2

t

s

t0 t1

t2 t=(st)

t=(st)

(11)

v1t1

v0t0

v2t2

t

s

t0 t1

t2t=(st)t=(st)

(11)

texture spaceobject space

window space

t=(st)t=(st) non-affine

affine

Mobjlarrtex

Mwinlarrobj

Rasterization Need Rational linear interpolation

Rational linear interpolation in Scan-Conversion

t

s

t0 t1

t2

t=(st)

(11)

texture spacewindow space

t=(st)t=(st)non-affine

MwinlarrobjMobjlarrtex

(sqtqq)bulllinearly interpolate 3 variables

sqtqqbullcompute st with a division per pixel

s=sqq t=tqq

Rasterization Who does what

bull Rasterize unit does ndash scan conversion (generate (xy))ndash rational linear interpolation of texture coordinatesndash linear interpolation of depth coordinatendash rational linear () interpolation of vertex color

bull Fragment Processorndash if using fragment shader you can further modify the

depth coordinate and texture coordinate from those generated by Rasterize unit

Rasterization GL state

bull GL_POINTS ndash glPointSize glPointParameter POINT SPRITE texture

bull GL_LINESGL_LINE_LOOP ndash glLineWidth glLineStipple

bull GL_TRIANGLES etc ndash glPolygonStipple glPolygonMode glPolygonOffset glFrontFace

bull crude anti-aliasing ndash glEnable GL_POINT_SMOOTH GL_LINE_SMOOTH GL_POLYGON_SMOOTH

bull Is color interpolated - glShadeModel

Per-Fragment Operations - I

bull pixel ownership test ndash is the destination pixel visible or obscured by other window

bull scissor test ndash clips fragment against rectangle given by glScissor

bull alpha test ndash decides whether to discard fragment based on comparison of fragrsquos alpha value with target given by glAlphaFunc

bull stencil test ndash compares stencil buffer value with reference value and decides whether to discard pixel (glStencilFunc glStencilOp)

bull depth test ndash use function set by glDepthFunc to compare depth of fragment to depth of destination pixel in framebuffer

Per-Fragment Operations - II

bull blending ndash color stored in pixel is blend of fragment color and original pixel color and blend state (glBlendFunc glBlendColor glBlendEquation)

bull logical operations ndashbitwise boolean operations (glLogicOp)

bull dithering - old

Frame Buffer Operations

bull which buffer(s) are written too GL_FRONT GL_FRONT_LEFTGL_AUX0 etc (glDrawBuffer glDrawBuffers)

bull write protection ndash which bitsbytes are affected (glColorMask glDepthMask glStencilMask)

bull clear framebuffer ndash glClear glClearColor glClearDepth glClearStencil glClearAccum

bull glFlush ndash make sure all primitives are progressing toward completion (noone waiting around in queue)

bull glFinish ndash block () until all pending GL calls have executed

Graphics Workstation

DisplayProcessor Display

ProcessorMemory

FramebufferVideo

Controller

PeripheralDevices

CPU SystemMemory

System Bus

Nvidia 8800 Ultra Peak 103GBs

PCIExpress Input 4GBs

Bandwidth Discrepancy Demands Data on Graphics Card

bull Since transfer from CPU to GPU is much slower than GPU to graphics memory we have

ndash texture objects (OGL ge 11)ndash vertex buffer objects (OGL ge 15)ndash pixel buffer objects (OGL ge 21)ndash display lists (OGL ge 10)

Texture Sampling

bull Fragment Processor gets interpolated texture coordinates from Rasterize unit and does a texel lookup from some of the texture units (GL_MAX_TEXTURE_UNITS)

bull Each texture unit is a piece of GPU hardware () and hasndash Enabledisabled statendash Texture matrix stackndash state for automatic generation of texture coordinatesndash Texture environment statendash Current 1D 2D 3D and cube map texture

GL_TEXTUREi

1D

2D

3D

CUBE

Texture Unit rarr glBindTexturelarrTexture Object

GL_TEXTURE0

hellip

GL_ACTIVE_TEXTURE

glActiveTexture

Texture UnitsTexture Objects

GLuint=1

GLuint=2

GLuint=3

GLuint=N

GL_

MA

X_T

EX

TU

RE

_UN

ITS

hellip

as many as m

emory allow

s

glBindTexture

bind texture object to one of the four texture targets of the active texture unit

1D

2D

3D

CUBE

GL_TEXTURE1

1D

2D

3D

CUBE

GL_TEXTUREN

1D

2D

3D

CUBE

hellip

Transfer pixel data to GPU texture memory

bull data is associated with texture object

bull glTexImage(3D|2D|1D) ndash load whole image from CPU

bull glTexSubImage(3D|2D|1D) ndash load sub image from CPU

bull glCopyTexImage(1D|2D) ndash load whole image from framebuffer

bull glCopyTexSubImage(1D|2D|3D) ndash load sub-image from framebuffer

bull MIPMAP and compression supported

Texture Object - glTexParameter

bull wrapping behavior ndash repeat clamp mirror

bull minification ndash GL_NEARESTGL_LINEAR

xxx_MIPMAP_xxx

bull magnification ndash GL_NEARESTGL_LINEAR

bull border color ndash when using clamped wrapping

bull priority

bull level-of-detail control for MIPMAP

bull hellip

Texture Unit - glTexEnv

bull many options for how texel is combined with framebuffer pixel colorndash blendingndash replacementndash decalndash addingndash enable point sprites

hellip

Other Texture issues

bull multi-texturingndash texture units work seriallyndash glMultiTexCoord vs glTexCoord

bull glTexGen ndash generate texcoordrsquos from vertex coordinatesndash define function that computes tex coord

Vertex Buffer Objects - Preliminaries

bull builds off of client side vertex arrays1 glEnableClientState(GLenum array)

array from GL_VERTEX_ARRAY GL_COLOR_ARRAY GL_NORMAL_ARRAY etc

2 glVertexPointer(int size enum type sizei stride void pointer)size = 234 type = GL_FLOATGL_INT etc

3 glDrawArrays(GLenum mode GLint first GLsizei count) helliporhellip glDrawElements(GLenum mode GLsizei count GLenum

type void indices) index helliporhellip

glBegin(GL_TRIANGLE) glArrayElement(2) index hellip

Vertex Buffer Objects ndash Create and Initialize

bull VBOrsquos instead of lsquopointerrsquo pointing to CPU memory itrsquos treated as a offset to a vertex buffer in GPU memory

bull glGenBuffers(GLsizei n GLuint buffers) create namebull glBindBuffer(GLenum target GLuint buffer) create buffer

target=GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER

bull glBufferData(GLenum target GLsizeiptr size const GLvoid data GLenum usage) copy data to buffer

size = elements size of elementdata = pointer to CPU memory or NULL (no initialize)usage = GL_(STREAM|STATIC|DYNAMIC)_(DRAW|READ|COPY)

usage is a performance hint

Vertex Buffer Objects - usage

bull _DRAW - data used as vertex data for renderingbull _READ ndash data read from an OGL buffer (such as

framebuffer) and used in application for computations not immediately related to rendering (OGL ge 21)

bull _COPY ndash data values are read from OGL buffer and then used as vertex data for rendering (OGL ge 21)

bull _STREAM_ - frequent updates to buffer but only used a few times in drawing or other operations (updatedraw asymp 11)

bull _STATIC_ - set data once and use many times (updatedraw = 1N)

bull _DYNAMIC_ - you may update buffer often and use it many times as well (updatedraw = NN)

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 12: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Properties of Perspective Collineation

bull preserve lines

bull does not preserve parallelism

bull does not preserve distance ratios

eye

P

view window

bull 3D2D collapse loses depth informationndash zbuffer needs depth information but only works for

parallel projection

bull fastest frustum clipping algorithm would clip to unit cube ndash not arbitrary frustum

Non-dimension preserving persp collineation problem 1

eye b0

b1

a1a0a

b

y

z

b0b1

a1a0a

b

yz

eye at infin=(0010)

bull fastest frustum clipping algorithm would clip to unit cube ndash not against an arbitrary frustum

Non-dimension preserving persp collineation problem 2

(-1-1-1)

(111)

xdev

ydev

zdev

clipping planes have most trivial equation posible (z=1z=-1x=1x=-1 etc) Hence solving clipping intersection

equations is fast as possible

Perspective Collineation (Dimension Preserving)

near clippingplane

far clipping plane

eye

View Window

near clippingplane

far clipping plane

Mpers

Mpers2D Mparallel(3Drarr2D)

3Drarr3D

=

(3Drarr2D)

Rasterization ndash Pixel Window Coordinates

a

b

c

Rasterization - zBuffer(x1y1z1)

(x2y2z2)(x3y3z3)

(xryrzr)(xlylzl)

(xyz)

bull Generally to compute z

bull Incremental in x

bull Incremental in y

Ax By Dz

C

( 1)

A x By Dz z A C

C

1

So

or if =

x x m

A m Bz z z z B C m

C

Rasterization ndash Texture Coordinates

bull assign 3 (st)-coordinates to 3 vertices of geometric primitive

linearly interpolate (st) to map texture space to object-space

v1t1

v0t0

v2t2

t

s

t0 t1

t2 t=(st)

t=(st)

(11)

v1t1

v0t0

v2t2

t

s

t0 t1

t2t=(st)t=(st)

(11)

texture spaceobject space

window space

t=(st)t=(st) non-affine

affine

Mobjlarrtex

Mwinlarrobj

Rasterization Need Rational linear interpolation

Rational linear interpolation in Scan-Conversion

t

s

t0 t1

t2

t=(st)

(11)

texture spacewindow space

t=(st)t=(st)non-affine

MwinlarrobjMobjlarrtex

(sqtqq)bulllinearly interpolate 3 variables

sqtqqbullcompute st with a division per pixel

s=sqq t=tqq

Rasterization Who does what

bull Rasterize unit does ndash scan conversion (generate (xy))ndash rational linear interpolation of texture coordinatesndash linear interpolation of depth coordinatendash rational linear () interpolation of vertex color

bull Fragment Processorndash if using fragment shader you can further modify the

depth coordinate and texture coordinate from those generated by Rasterize unit

Rasterization GL state

bull GL_POINTS ndash glPointSize glPointParameter POINT SPRITE texture

bull GL_LINESGL_LINE_LOOP ndash glLineWidth glLineStipple

bull GL_TRIANGLES etc ndash glPolygonStipple glPolygonMode glPolygonOffset glFrontFace

bull crude anti-aliasing ndash glEnable GL_POINT_SMOOTH GL_LINE_SMOOTH GL_POLYGON_SMOOTH

bull Is color interpolated - glShadeModel

Per-Fragment Operations - I

bull pixel ownership test ndash is the destination pixel visible or obscured by other window

bull scissor test ndash clips fragment against rectangle given by glScissor

bull alpha test ndash decides whether to discard fragment based on comparison of fragrsquos alpha value with target given by glAlphaFunc

bull stencil test ndash compares stencil buffer value with reference value and decides whether to discard pixel (glStencilFunc glStencilOp)

bull depth test ndash use function set by glDepthFunc to compare depth of fragment to depth of destination pixel in framebuffer

Per-Fragment Operations - II

bull blending ndash color stored in pixel is blend of fragment color and original pixel color and blend state (glBlendFunc glBlendColor glBlendEquation)

bull logical operations ndashbitwise boolean operations (glLogicOp)

bull dithering - old

Frame Buffer Operations

bull which buffer(s) are written too GL_FRONT GL_FRONT_LEFTGL_AUX0 etc (glDrawBuffer glDrawBuffers)

bull write protection ndash which bitsbytes are affected (glColorMask glDepthMask glStencilMask)

bull clear framebuffer ndash glClear glClearColor glClearDepth glClearStencil glClearAccum

bull glFlush ndash make sure all primitives are progressing toward completion (noone waiting around in queue)

bull glFinish ndash block () until all pending GL calls have executed

Graphics Workstation

DisplayProcessor Display

ProcessorMemory

FramebufferVideo

Controller

PeripheralDevices

CPU SystemMemory

System Bus

Nvidia 8800 Ultra Peak 103GBs

PCIExpress Input 4GBs

Bandwidth Discrepancy Demands Data on Graphics Card

bull Since transfer from CPU to GPU is much slower than GPU to graphics memory we have

ndash texture objects (OGL ge 11)ndash vertex buffer objects (OGL ge 15)ndash pixel buffer objects (OGL ge 21)ndash display lists (OGL ge 10)

Texture Sampling

bull Fragment Processor gets interpolated texture coordinates from Rasterize unit and does a texel lookup from some of the texture units (GL_MAX_TEXTURE_UNITS)

bull Each texture unit is a piece of GPU hardware () and hasndash Enabledisabled statendash Texture matrix stackndash state for automatic generation of texture coordinatesndash Texture environment statendash Current 1D 2D 3D and cube map texture

GL_TEXTUREi

1D

2D

3D

CUBE

Texture Unit rarr glBindTexturelarrTexture Object

GL_TEXTURE0

hellip

GL_ACTIVE_TEXTURE

glActiveTexture

Texture UnitsTexture Objects

GLuint=1

GLuint=2

GLuint=3

GLuint=N

GL_

MA

X_T

EX

TU

RE

_UN

ITS

hellip

as many as m

emory allow

s

glBindTexture

bind texture object to one of the four texture targets of the active texture unit

1D

2D

3D

CUBE

GL_TEXTURE1

1D

2D

3D

CUBE

GL_TEXTUREN

1D

2D

3D

CUBE

hellip

Transfer pixel data to GPU texture memory

bull data is associated with texture object

bull glTexImage(3D|2D|1D) ndash load whole image from CPU

bull glTexSubImage(3D|2D|1D) ndash load sub image from CPU

bull glCopyTexImage(1D|2D) ndash load whole image from framebuffer

bull glCopyTexSubImage(1D|2D|3D) ndash load sub-image from framebuffer

bull MIPMAP and compression supported

Texture Object - glTexParameter

bull wrapping behavior ndash repeat clamp mirror

bull minification ndash GL_NEARESTGL_LINEAR

xxx_MIPMAP_xxx

bull magnification ndash GL_NEARESTGL_LINEAR

bull border color ndash when using clamped wrapping

bull priority

bull level-of-detail control for MIPMAP

bull hellip

Texture Unit - glTexEnv

bull many options for how texel is combined with framebuffer pixel colorndash blendingndash replacementndash decalndash addingndash enable point sprites

hellip

Other Texture issues

bull multi-texturingndash texture units work seriallyndash glMultiTexCoord vs glTexCoord

bull glTexGen ndash generate texcoordrsquos from vertex coordinatesndash define function that computes tex coord

Vertex Buffer Objects - Preliminaries

bull builds off of client side vertex arrays1 glEnableClientState(GLenum array)

array from GL_VERTEX_ARRAY GL_COLOR_ARRAY GL_NORMAL_ARRAY etc

2 glVertexPointer(int size enum type sizei stride void pointer)size = 234 type = GL_FLOATGL_INT etc

3 glDrawArrays(GLenum mode GLint first GLsizei count) helliporhellip glDrawElements(GLenum mode GLsizei count GLenum

type void indices) index helliporhellip

glBegin(GL_TRIANGLE) glArrayElement(2) index hellip

Vertex Buffer Objects ndash Create and Initialize

bull VBOrsquos instead of lsquopointerrsquo pointing to CPU memory itrsquos treated as a offset to a vertex buffer in GPU memory

bull glGenBuffers(GLsizei n GLuint buffers) create namebull glBindBuffer(GLenum target GLuint buffer) create buffer

target=GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER

bull glBufferData(GLenum target GLsizeiptr size const GLvoid data GLenum usage) copy data to buffer

size = elements size of elementdata = pointer to CPU memory or NULL (no initialize)usage = GL_(STREAM|STATIC|DYNAMIC)_(DRAW|READ|COPY)

usage is a performance hint

Vertex Buffer Objects - usage

bull _DRAW - data used as vertex data for renderingbull _READ ndash data read from an OGL buffer (such as

framebuffer) and used in application for computations not immediately related to rendering (OGL ge 21)

bull _COPY ndash data values are read from OGL buffer and then used as vertex data for rendering (OGL ge 21)

bull _STREAM_ - frequent updates to buffer but only used a few times in drawing or other operations (updatedraw asymp 11)

bull _STATIC_ - set data once and use many times (updatedraw = 1N)

bull _DYNAMIC_ - you may update buffer often and use it many times as well (updatedraw = NN)

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 13: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

bull 3D2D collapse loses depth informationndash zbuffer needs depth information but only works for

parallel projection

bull fastest frustum clipping algorithm would clip to unit cube ndash not arbitrary frustum

Non-dimension preserving persp collineation problem 1

eye b0

b1

a1a0a

b

y

z

b0b1

a1a0a

b

yz

eye at infin=(0010)

bull fastest frustum clipping algorithm would clip to unit cube ndash not against an arbitrary frustum

Non-dimension preserving persp collineation problem 2

(-1-1-1)

(111)

xdev

ydev

zdev

clipping planes have most trivial equation posible (z=1z=-1x=1x=-1 etc) Hence solving clipping intersection

equations is fast as possible

Perspective Collineation (Dimension Preserving)

near clippingplane

far clipping plane

eye

View Window

near clippingplane

far clipping plane

Mpers

Mpers2D Mparallel(3Drarr2D)

3Drarr3D

=

(3Drarr2D)

Rasterization ndash Pixel Window Coordinates

a

b

c

Rasterization - zBuffer(x1y1z1)

(x2y2z2)(x3y3z3)

(xryrzr)(xlylzl)

(xyz)

bull Generally to compute z

bull Incremental in x

bull Incremental in y

Ax By Dz

C

( 1)

A x By Dz z A C

C

1

So

or if =

x x m

A m Bz z z z B C m

C

Rasterization ndash Texture Coordinates

bull assign 3 (st)-coordinates to 3 vertices of geometric primitive

linearly interpolate (st) to map texture space to object-space

v1t1

v0t0

v2t2

t

s

t0 t1

t2 t=(st)

t=(st)

(11)

v1t1

v0t0

v2t2

t

s

t0 t1

t2t=(st)t=(st)

(11)

texture spaceobject space

window space

t=(st)t=(st) non-affine

affine

Mobjlarrtex

Mwinlarrobj

Rasterization Need Rational linear interpolation

Rational linear interpolation in Scan-Conversion

t

s

t0 t1

t2

t=(st)

(11)

texture spacewindow space

t=(st)t=(st)non-affine

MwinlarrobjMobjlarrtex

(sqtqq)bulllinearly interpolate 3 variables

sqtqqbullcompute st with a division per pixel

s=sqq t=tqq

Rasterization Who does what

bull Rasterize unit does ndash scan conversion (generate (xy))ndash rational linear interpolation of texture coordinatesndash linear interpolation of depth coordinatendash rational linear () interpolation of vertex color

bull Fragment Processorndash if using fragment shader you can further modify the

depth coordinate and texture coordinate from those generated by Rasterize unit

Rasterization GL state

bull GL_POINTS ndash glPointSize glPointParameter POINT SPRITE texture

bull GL_LINESGL_LINE_LOOP ndash glLineWidth glLineStipple

bull GL_TRIANGLES etc ndash glPolygonStipple glPolygonMode glPolygonOffset glFrontFace

bull crude anti-aliasing ndash glEnable GL_POINT_SMOOTH GL_LINE_SMOOTH GL_POLYGON_SMOOTH

bull Is color interpolated - glShadeModel

Per-Fragment Operations - I

bull pixel ownership test ndash is the destination pixel visible or obscured by other window

bull scissor test ndash clips fragment against rectangle given by glScissor

bull alpha test ndash decides whether to discard fragment based on comparison of fragrsquos alpha value with target given by glAlphaFunc

bull stencil test ndash compares stencil buffer value with reference value and decides whether to discard pixel (glStencilFunc glStencilOp)

bull depth test ndash use function set by glDepthFunc to compare depth of fragment to depth of destination pixel in framebuffer

Per-Fragment Operations - II

bull blending ndash color stored in pixel is blend of fragment color and original pixel color and blend state (glBlendFunc glBlendColor glBlendEquation)

bull logical operations ndashbitwise boolean operations (glLogicOp)

bull dithering - old

Frame Buffer Operations

bull which buffer(s) are written too GL_FRONT GL_FRONT_LEFTGL_AUX0 etc (glDrawBuffer glDrawBuffers)

bull write protection ndash which bitsbytes are affected (glColorMask glDepthMask glStencilMask)

bull clear framebuffer ndash glClear glClearColor glClearDepth glClearStencil glClearAccum

bull glFlush ndash make sure all primitives are progressing toward completion (noone waiting around in queue)

bull glFinish ndash block () until all pending GL calls have executed

Graphics Workstation

DisplayProcessor Display

ProcessorMemory

FramebufferVideo

Controller

PeripheralDevices

CPU SystemMemory

System Bus

Nvidia 8800 Ultra Peak 103GBs

PCIExpress Input 4GBs

Bandwidth Discrepancy Demands Data on Graphics Card

bull Since transfer from CPU to GPU is much slower than GPU to graphics memory we have

ndash texture objects (OGL ge 11)ndash vertex buffer objects (OGL ge 15)ndash pixel buffer objects (OGL ge 21)ndash display lists (OGL ge 10)

Texture Sampling

bull Fragment Processor gets interpolated texture coordinates from Rasterize unit and does a texel lookup from some of the texture units (GL_MAX_TEXTURE_UNITS)

bull Each texture unit is a piece of GPU hardware () and hasndash Enabledisabled statendash Texture matrix stackndash state for automatic generation of texture coordinatesndash Texture environment statendash Current 1D 2D 3D and cube map texture

GL_TEXTUREi

1D

2D

3D

CUBE

Texture Unit rarr glBindTexturelarrTexture Object

GL_TEXTURE0

hellip

GL_ACTIVE_TEXTURE

glActiveTexture

Texture UnitsTexture Objects

GLuint=1

GLuint=2

GLuint=3

GLuint=N

GL_

MA

X_T

EX

TU

RE

_UN

ITS

hellip

as many as m

emory allow

s

glBindTexture

bind texture object to one of the four texture targets of the active texture unit

1D

2D

3D

CUBE

GL_TEXTURE1

1D

2D

3D

CUBE

GL_TEXTUREN

1D

2D

3D

CUBE

hellip

Transfer pixel data to GPU texture memory

bull data is associated with texture object

bull glTexImage(3D|2D|1D) ndash load whole image from CPU

bull glTexSubImage(3D|2D|1D) ndash load sub image from CPU

bull glCopyTexImage(1D|2D) ndash load whole image from framebuffer

bull glCopyTexSubImage(1D|2D|3D) ndash load sub-image from framebuffer

bull MIPMAP and compression supported

Texture Object - glTexParameter

bull wrapping behavior ndash repeat clamp mirror

bull minification ndash GL_NEARESTGL_LINEAR

xxx_MIPMAP_xxx

bull magnification ndash GL_NEARESTGL_LINEAR

bull border color ndash when using clamped wrapping

bull priority

bull level-of-detail control for MIPMAP

bull hellip

Texture Unit - glTexEnv

bull many options for how texel is combined with framebuffer pixel colorndash blendingndash replacementndash decalndash addingndash enable point sprites

hellip

Other Texture issues

bull multi-texturingndash texture units work seriallyndash glMultiTexCoord vs glTexCoord

bull glTexGen ndash generate texcoordrsquos from vertex coordinatesndash define function that computes tex coord

Vertex Buffer Objects - Preliminaries

bull builds off of client side vertex arrays1 glEnableClientState(GLenum array)

array from GL_VERTEX_ARRAY GL_COLOR_ARRAY GL_NORMAL_ARRAY etc

2 glVertexPointer(int size enum type sizei stride void pointer)size = 234 type = GL_FLOATGL_INT etc

3 glDrawArrays(GLenum mode GLint first GLsizei count) helliporhellip glDrawElements(GLenum mode GLsizei count GLenum

type void indices) index helliporhellip

glBegin(GL_TRIANGLE) glArrayElement(2) index hellip

Vertex Buffer Objects ndash Create and Initialize

bull VBOrsquos instead of lsquopointerrsquo pointing to CPU memory itrsquos treated as a offset to a vertex buffer in GPU memory

bull glGenBuffers(GLsizei n GLuint buffers) create namebull glBindBuffer(GLenum target GLuint buffer) create buffer

target=GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER

bull glBufferData(GLenum target GLsizeiptr size const GLvoid data GLenum usage) copy data to buffer

size = elements size of elementdata = pointer to CPU memory or NULL (no initialize)usage = GL_(STREAM|STATIC|DYNAMIC)_(DRAW|READ|COPY)

usage is a performance hint

Vertex Buffer Objects - usage

bull _DRAW - data used as vertex data for renderingbull _READ ndash data read from an OGL buffer (such as

framebuffer) and used in application for computations not immediately related to rendering (OGL ge 21)

bull _COPY ndash data values are read from OGL buffer and then used as vertex data for rendering (OGL ge 21)

bull _STREAM_ - frequent updates to buffer but only used a few times in drawing or other operations (updatedraw asymp 11)

bull _STATIC_ - set data once and use many times (updatedraw = 1N)

bull _DYNAMIC_ - you may update buffer often and use it many times as well (updatedraw = NN)

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 14: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

bull fastest frustum clipping algorithm would clip to unit cube ndash not against an arbitrary frustum

Non-dimension preserving persp collineation problem 2

(-1-1-1)

(111)

xdev

ydev

zdev

clipping planes have most trivial equation posible (z=1z=-1x=1x=-1 etc) Hence solving clipping intersection

equations is fast as possible

Perspective Collineation (Dimension Preserving)

near clippingplane

far clipping plane

eye

View Window

near clippingplane

far clipping plane

Mpers

Mpers2D Mparallel(3Drarr2D)

3Drarr3D

=

(3Drarr2D)

Rasterization ndash Pixel Window Coordinates

a

b

c

Rasterization - zBuffer(x1y1z1)

(x2y2z2)(x3y3z3)

(xryrzr)(xlylzl)

(xyz)

bull Generally to compute z

bull Incremental in x

bull Incremental in y

Ax By Dz

C

( 1)

A x By Dz z A C

C

1

So

or if =

x x m

A m Bz z z z B C m

C

Rasterization ndash Texture Coordinates

bull assign 3 (st)-coordinates to 3 vertices of geometric primitive

linearly interpolate (st) to map texture space to object-space

v1t1

v0t0

v2t2

t

s

t0 t1

t2 t=(st)

t=(st)

(11)

v1t1

v0t0

v2t2

t

s

t0 t1

t2t=(st)t=(st)

(11)

texture spaceobject space

window space

t=(st)t=(st) non-affine

affine

Mobjlarrtex

Mwinlarrobj

Rasterization Need Rational linear interpolation

Rational linear interpolation in Scan-Conversion

t

s

t0 t1

t2

t=(st)

(11)

texture spacewindow space

t=(st)t=(st)non-affine

MwinlarrobjMobjlarrtex

(sqtqq)bulllinearly interpolate 3 variables

sqtqqbullcompute st with a division per pixel

s=sqq t=tqq

Rasterization Who does what

bull Rasterize unit does ndash scan conversion (generate (xy))ndash rational linear interpolation of texture coordinatesndash linear interpolation of depth coordinatendash rational linear () interpolation of vertex color

bull Fragment Processorndash if using fragment shader you can further modify the

depth coordinate and texture coordinate from those generated by Rasterize unit

Rasterization GL state

bull GL_POINTS ndash glPointSize glPointParameter POINT SPRITE texture

bull GL_LINESGL_LINE_LOOP ndash glLineWidth glLineStipple

bull GL_TRIANGLES etc ndash glPolygonStipple glPolygonMode glPolygonOffset glFrontFace

bull crude anti-aliasing ndash glEnable GL_POINT_SMOOTH GL_LINE_SMOOTH GL_POLYGON_SMOOTH

bull Is color interpolated - glShadeModel

Per-Fragment Operations - I

bull pixel ownership test ndash is the destination pixel visible or obscured by other window

bull scissor test ndash clips fragment against rectangle given by glScissor

bull alpha test ndash decides whether to discard fragment based on comparison of fragrsquos alpha value with target given by glAlphaFunc

bull stencil test ndash compares stencil buffer value with reference value and decides whether to discard pixel (glStencilFunc glStencilOp)

bull depth test ndash use function set by glDepthFunc to compare depth of fragment to depth of destination pixel in framebuffer

Per-Fragment Operations - II

bull blending ndash color stored in pixel is blend of fragment color and original pixel color and blend state (glBlendFunc glBlendColor glBlendEquation)

bull logical operations ndashbitwise boolean operations (glLogicOp)

bull dithering - old

Frame Buffer Operations

bull which buffer(s) are written too GL_FRONT GL_FRONT_LEFTGL_AUX0 etc (glDrawBuffer glDrawBuffers)

bull write protection ndash which bitsbytes are affected (glColorMask glDepthMask glStencilMask)

bull clear framebuffer ndash glClear glClearColor glClearDepth glClearStencil glClearAccum

bull glFlush ndash make sure all primitives are progressing toward completion (noone waiting around in queue)

bull glFinish ndash block () until all pending GL calls have executed

Graphics Workstation

DisplayProcessor Display

ProcessorMemory

FramebufferVideo

Controller

PeripheralDevices

CPU SystemMemory

System Bus

Nvidia 8800 Ultra Peak 103GBs

PCIExpress Input 4GBs

Bandwidth Discrepancy Demands Data on Graphics Card

bull Since transfer from CPU to GPU is much slower than GPU to graphics memory we have

ndash texture objects (OGL ge 11)ndash vertex buffer objects (OGL ge 15)ndash pixel buffer objects (OGL ge 21)ndash display lists (OGL ge 10)

Texture Sampling

bull Fragment Processor gets interpolated texture coordinates from Rasterize unit and does a texel lookup from some of the texture units (GL_MAX_TEXTURE_UNITS)

bull Each texture unit is a piece of GPU hardware () and hasndash Enabledisabled statendash Texture matrix stackndash state for automatic generation of texture coordinatesndash Texture environment statendash Current 1D 2D 3D and cube map texture

GL_TEXTUREi

1D

2D

3D

CUBE

Texture Unit rarr glBindTexturelarrTexture Object

GL_TEXTURE0

hellip

GL_ACTIVE_TEXTURE

glActiveTexture

Texture UnitsTexture Objects

GLuint=1

GLuint=2

GLuint=3

GLuint=N

GL_

MA

X_T

EX

TU

RE

_UN

ITS

hellip

as many as m

emory allow

s

glBindTexture

bind texture object to one of the four texture targets of the active texture unit

1D

2D

3D

CUBE

GL_TEXTURE1

1D

2D

3D

CUBE

GL_TEXTUREN

1D

2D

3D

CUBE

hellip

Transfer pixel data to GPU texture memory

bull data is associated with texture object

bull glTexImage(3D|2D|1D) ndash load whole image from CPU

bull glTexSubImage(3D|2D|1D) ndash load sub image from CPU

bull glCopyTexImage(1D|2D) ndash load whole image from framebuffer

bull glCopyTexSubImage(1D|2D|3D) ndash load sub-image from framebuffer

bull MIPMAP and compression supported

Texture Object - glTexParameter

bull wrapping behavior ndash repeat clamp mirror

bull minification ndash GL_NEARESTGL_LINEAR

xxx_MIPMAP_xxx

bull magnification ndash GL_NEARESTGL_LINEAR

bull border color ndash when using clamped wrapping

bull priority

bull level-of-detail control for MIPMAP

bull hellip

Texture Unit - glTexEnv

bull many options for how texel is combined with framebuffer pixel colorndash blendingndash replacementndash decalndash addingndash enable point sprites

hellip

Other Texture issues

bull multi-texturingndash texture units work seriallyndash glMultiTexCoord vs glTexCoord

bull glTexGen ndash generate texcoordrsquos from vertex coordinatesndash define function that computes tex coord

Vertex Buffer Objects - Preliminaries

bull builds off of client side vertex arrays1 glEnableClientState(GLenum array)

array from GL_VERTEX_ARRAY GL_COLOR_ARRAY GL_NORMAL_ARRAY etc

2 glVertexPointer(int size enum type sizei stride void pointer)size = 234 type = GL_FLOATGL_INT etc

3 glDrawArrays(GLenum mode GLint first GLsizei count) helliporhellip glDrawElements(GLenum mode GLsizei count GLenum

type void indices) index helliporhellip

glBegin(GL_TRIANGLE) glArrayElement(2) index hellip

Vertex Buffer Objects ndash Create and Initialize

bull VBOrsquos instead of lsquopointerrsquo pointing to CPU memory itrsquos treated as a offset to a vertex buffer in GPU memory

bull glGenBuffers(GLsizei n GLuint buffers) create namebull glBindBuffer(GLenum target GLuint buffer) create buffer

target=GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER

bull glBufferData(GLenum target GLsizeiptr size const GLvoid data GLenum usage) copy data to buffer

size = elements size of elementdata = pointer to CPU memory or NULL (no initialize)usage = GL_(STREAM|STATIC|DYNAMIC)_(DRAW|READ|COPY)

usage is a performance hint

Vertex Buffer Objects - usage

bull _DRAW - data used as vertex data for renderingbull _READ ndash data read from an OGL buffer (such as

framebuffer) and used in application for computations not immediately related to rendering (OGL ge 21)

bull _COPY ndash data values are read from OGL buffer and then used as vertex data for rendering (OGL ge 21)

bull _STREAM_ - frequent updates to buffer but only used a few times in drawing or other operations (updatedraw asymp 11)

bull _STATIC_ - set data once and use many times (updatedraw = 1N)

bull _DYNAMIC_ - you may update buffer often and use it many times as well (updatedraw = NN)

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 15: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Perspective Collineation (Dimension Preserving)

near clippingplane

far clipping plane

eye

View Window

near clippingplane

far clipping plane

Mpers

Mpers2D Mparallel(3Drarr2D)

3Drarr3D

=

(3Drarr2D)

Rasterization ndash Pixel Window Coordinates

a

b

c

Rasterization - zBuffer(x1y1z1)

(x2y2z2)(x3y3z3)

(xryrzr)(xlylzl)

(xyz)

bull Generally to compute z

bull Incremental in x

bull Incremental in y

Ax By Dz

C

( 1)

A x By Dz z A C

C

1

So

or if =

x x m

A m Bz z z z B C m

C

Rasterization ndash Texture Coordinates

bull assign 3 (st)-coordinates to 3 vertices of geometric primitive

linearly interpolate (st) to map texture space to object-space

v1t1

v0t0

v2t2

t

s

t0 t1

t2 t=(st)

t=(st)

(11)

v1t1

v0t0

v2t2

t

s

t0 t1

t2t=(st)t=(st)

(11)

texture spaceobject space

window space

t=(st)t=(st) non-affine

affine

Mobjlarrtex

Mwinlarrobj

Rasterization Need Rational linear interpolation

Rational linear interpolation in Scan-Conversion

t

s

t0 t1

t2

t=(st)

(11)

texture spacewindow space

t=(st)t=(st)non-affine

MwinlarrobjMobjlarrtex

(sqtqq)bulllinearly interpolate 3 variables

sqtqqbullcompute st with a division per pixel

s=sqq t=tqq

Rasterization Who does what

bull Rasterize unit does ndash scan conversion (generate (xy))ndash rational linear interpolation of texture coordinatesndash linear interpolation of depth coordinatendash rational linear () interpolation of vertex color

bull Fragment Processorndash if using fragment shader you can further modify the

depth coordinate and texture coordinate from those generated by Rasterize unit

Rasterization GL state

bull GL_POINTS ndash glPointSize glPointParameter POINT SPRITE texture

bull GL_LINESGL_LINE_LOOP ndash glLineWidth glLineStipple

bull GL_TRIANGLES etc ndash glPolygonStipple glPolygonMode glPolygonOffset glFrontFace

bull crude anti-aliasing ndash glEnable GL_POINT_SMOOTH GL_LINE_SMOOTH GL_POLYGON_SMOOTH

bull Is color interpolated - glShadeModel

Per-Fragment Operations - I

bull pixel ownership test ndash is the destination pixel visible or obscured by other window

bull scissor test ndash clips fragment against rectangle given by glScissor

bull alpha test ndash decides whether to discard fragment based on comparison of fragrsquos alpha value with target given by glAlphaFunc

bull stencil test ndash compares stencil buffer value with reference value and decides whether to discard pixel (glStencilFunc glStencilOp)

bull depth test ndash use function set by glDepthFunc to compare depth of fragment to depth of destination pixel in framebuffer

Per-Fragment Operations - II

bull blending ndash color stored in pixel is blend of fragment color and original pixel color and blend state (glBlendFunc glBlendColor glBlendEquation)

bull logical operations ndashbitwise boolean operations (glLogicOp)

bull dithering - old

Frame Buffer Operations

bull which buffer(s) are written too GL_FRONT GL_FRONT_LEFTGL_AUX0 etc (glDrawBuffer glDrawBuffers)

bull write protection ndash which bitsbytes are affected (glColorMask glDepthMask glStencilMask)

bull clear framebuffer ndash glClear glClearColor glClearDepth glClearStencil glClearAccum

bull glFlush ndash make sure all primitives are progressing toward completion (noone waiting around in queue)

bull glFinish ndash block () until all pending GL calls have executed

Graphics Workstation

DisplayProcessor Display

ProcessorMemory

FramebufferVideo

Controller

PeripheralDevices

CPU SystemMemory

System Bus

Nvidia 8800 Ultra Peak 103GBs

PCIExpress Input 4GBs

Bandwidth Discrepancy Demands Data on Graphics Card

bull Since transfer from CPU to GPU is much slower than GPU to graphics memory we have

ndash texture objects (OGL ge 11)ndash vertex buffer objects (OGL ge 15)ndash pixel buffer objects (OGL ge 21)ndash display lists (OGL ge 10)

Texture Sampling

bull Fragment Processor gets interpolated texture coordinates from Rasterize unit and does a texel lookup from some of the texture units (GL_MAX_TEXTURE_UNITS)

bull Each texture unit is a piece of GPU hardware () and hasndash Enabledisabled statendash Texture matrix stackndash state for automatic generation of texture coordinatesndash Texture environment statendash Current 1D 2D 3D and cube map texture

GL_TEXTUREi

1D

2D

3D

CUBE

Texture Unit rarr glBindTexturelarrTexture Object

GL_TEXTURE0

hellip

GL_ACTIVE_TEXTURE

glActiveTexture

Texture UnitsTexture Objects

GLuint=1

GLuint=2

GLuint=3

GLuint=N

GL_

MA

X_T

EX

TU

RE

_UN

ITS

hellip

as many as m

emory allow

s

glBindTexture

bind texture object to one of the four texture targets of the active texture unit

1D

2D

3D

CUBE

GL_TEXTURE1

1D

2D

3D

CUBE

GL_TEXTUREN

1D

2D

3D

CUBE

hellip

Transfer pixel data to GPU texture memory

bull data is associated with texture object

bull glTexImage(3D|2D|1D) ndash load whole image from CPU

bull glTexSubImage(3D|2D|1D) ndash load sub image from CPU

bull glCopyTexImage(1D|2D) ndash load whole image from framebuffer

bull glCopyTexSubImage(1D|2D|3D) ndash load sub-image from framebuffer

bull MIPMAP and compression supported

Texture Object - glTexParameter

bull wrapping behavior ndash repeat clamp mirror

bull minification ndash GL_NEARESTGL_LINEAR

xxx_MIPMAP_xxx

bull magnification ndash GL_NEARESTGL_LINEAR

bull border color ndash when using clamped wrapping

bull priority

bull level-of-detail control for MIPMAP

bull hellip

Texture Unit - glTexEnv

bull many options for how texel is combined with framebuffer pixel colorndash blendingndash replacementndash decalndash addingndash enable point sprites

hellip

Other Texture issues

bull multi-texturingndash texture units work seriallyndash glMultiTexCoord vs glTexCoord

bull glTexGen ndash generate texcoordrsquos from vertex coordinatesndash define function that computes tex coord

Vertex Buffer Objects - Preliminaries

bull builds off of client side vertex arrays1 glEnableClientState(GLenum array)

array from GL_VERTEX_ARRAY GL_COLOR_ARRAY GL_NORMAL_ARRAY etc

2 glVertexPointer(int size enum type sizei stride void pointer)size = 234 type = GL_FLOATGL_INT etc

3 glDrawArrays(GLenum mode GLint first GLsizei count) helliporhellip glDrawElements(GLenum mode GLsizei count GLenum

type void indices) index helliporhellip

glBegin(GL_TRIANGLE) glArrayElement(2) index hellip

Vertex Buffer Objects ndash Create and Initialize

bull VBOrsquos instead of lsquopointerrsquo pointing to CPU memory itrsquos treated as a offset to a vertex buffer in GPU memory

bull glGenBuffers(GLsizei n GLuint buffers) create namebull glBindBuffer(GLenum target GLuint buffer) create buffer

target=GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER

bull glBufferData(GLenum target GLsizeiptr size const GLvoid data GLenum usage) copy data to buffer

size = elements size of elementdata = pointer to CPU memory or NULL (no initialize)usage = GL_(STREAM|STATIC|DYNAMIC)_(DRAW|READ|COPY)

usage is a performance hint

Vertex Buffer Objects - usage

bull _DRAW - data used as vertex data for renderingbull _READ ndash data read from an OGL buffer (such as

framebuffer) and used in application for computations not immediately related to rendering (OGL ge 21)

bull _COPY ndash data values are read from OGL buffer and then used as vertex data for rendering (OGL ge 21)

bull _STREAM_ - frequent updates to buffer but only used a few times in drawing or other operations (updatedraw asymp 11)

bull _STATIC_ - set data once and use many times (updatedraw = 1N)

bull _DYNAMIC_ - you may update buffer often and use it many times as well (updatedraw = NN)

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 16: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Rasterization ndash Pixel Window Coordinates

a

b

c

Rasterization - zBuffer(x1y1z1)

(x2y2z2)(x3y3z3)

(xryrzr)(xlylzl)

(xyz)

bull Generally to compute z

bull Incremental in x

bull Incremental in y

Ax By Dz

C

( 1)

A x By Dz z A C

C

1

So

or if =

x x m

A m Bz z z z B C m

C

Rasterization ndash Texture Coordinates

bull assign 3 (st)-coordinates to 3 vertices of geometric primitive

linearly interpolate (st) to map texture space to object-space

v1t1

v0t0

v2t2

t

s

t0 t1

t2 t=(st)

t=(st)

(11)

v1t1

v0t0

v2t2

t

s

t0 t1

t2t=(st)t=(st)

(11)

texture spaceobject space

window space

t=(st)t=(st) non-affine

affine

Mobjlarrtex

Mwinlarrobj

Rasterization Need Rational linear interpolation

Rational linear interpolation in Scan-Conversion

t

s

t0 t1

t2

t=(st)

(11)

texture spacewindow space

t=(st)t=(st)non-affine

MwinlarrobjMobjlarrtex

(sqtqq)bulllinearly interpolate 3 variables

sqtqqbullcompute st with a division per pixel

s=sqq t=tqq

Rasterization Who does what

bull Rasterize unit does ndash scan conversion (generate (xy))ndash rational linear interpolation of texture coordinatesndash linear interpolation of depth coordinatendash rational linear () interpolation of vertex color

bull Fragment Processorndash if using fragment shader you can further modify the

depth coordinate and texture coordinate from those generated by Rasterize unit

Rasterization GL state

bull GL_POINTS ndash glPointSize glPointParameter POINT SPRITE texture

bull GL_LINESGL_LINE_LOOP ndash glLineWidth glLineStipple

bull GL_TRIANGLES etc ndash glPolygonStipple glPolygonMode glPolygonOffset glFrontFace

bull crude anti-aliasing ndash glEnable GL_POINT_SMOOTH GL_LINE_SMOOTH GL_POLYGON_SMOOTH

bull Is color interpolated - glShadeModel

Per-Fragment Operations - I

bull pixel ownership test ndash is the destination pixel visible or obscured by other window

bull scissor test ndash clips fragment against rectangle given by glScissor

bull alpha test ndash decides whether to discard fragment based on comparison of fragrsquos alpha value with target given by glAlphaFunc

bull stencil test ndash compares stencil buffer value with reference value and decides whether to discard pixel (glStencilFunc glStencilOp)

bull depth test ndash use function set by glDepthFunc to compare depth of fragment to depth of destination pixel in framebuffer

Per-Fragment Operations - II

bull blending ndash color stored in pixel is blend of fragment color and original pixel color and blend state (glBlendFunc glBlendColor glBlendEquation)

bull logical operations ndashbitwise boolean operations (glLogicOp)

bull dithering - old

Frame Buffer Operations

bull which buffer(s) are written too GL_FRONT GL_FRONT_LEFTGL_AUX0 etc (glDrawBuffer glDrawBuffers)

bull write protection ndash which bitsbytes are affected (glColorMask glDepthMask glStencilMask)

bull clear framebuffer ndash glClear glClearColor glClearDepth glClearStencil glClearAccum

bull glFlush ndash make sure all primitives are progressing toward completion (noone waiting around in queue)

bull glFinish ndash block () until all pending GL calls have executed

Graphics Workstation

DisplayProcessor Display

ProcessorMemory

FramebufferVideo

Controller

PeripheralDevices

CPU SystemMemory

System Bus

Nvidia 8800 Ultra Peak 103GBs

PCIExpress Input 4GBs

Bandwidth Discrepancy Demands Data on Graphics Card

bull Since transfer from CPU to GPU is much slower than GPU to graphics memory we have

ndash texture objects (OGL ge 11)ndash vertex buffer objects (OGL ge 15)ndash pixel buffer objects (OGL ge 21)ndash display lists (OGL ge 10)

Texture Sampling

bull Fragment Processor gets interpolated texture coordinates from Rasterize unit and does a texel lookup from some of the texture units (GL_MAX_TEXTURE_UNITS)

bull Each texture unit is a piece of GPU hardware () and hasndash Enabledisabled statendash Texture matrix stackndash state for automatic generation of texture coordinatesndash Texture environment statendash Current 1D 2D 3D and cube map texture

GL_TEXTUREi

1D

2D

3D

CUBE

Texture Unit rarr glBindTexturelarrTexture Object

GL_TEXTURE0

hellip

GL_ACTIVE_TEXTURE

glActiveTexture

Texture UnitsTexture Objects

GLuint=1

GLuint=2

GLuint=3

GLuint=N

GL_

MA

X_T

EX

TU

RE

_UN

ITS

hellip

as many as m

emory allow

s

glBindTexture

bind texture object to one of the four texture targets of the active texture unit

1D

2D

3D

CUBE

GL_TEXTURE1

1D

2D

3D

CUBE

GL_TEXTUREN

1D

2D

3D

CUBE

hellip

Transfer pixel data to GPU texture memory

bull data is associated with texture object

bull glTexImage(3D|2D|1D) ndash load whole image from CPU

bull glTexSubImage(3D|2D|1D) ndash load sub image from CPU

bull glCopyTexImage(1D|2D) ndash load whole image from framebuffer

bull glCopyTexSubImage(1D|2D|3D) ndash load sub-image from framebuffer

bull MIPMAP and compression supported

Texture Object - glTexParameter

bull wrapping behavior ndash repeat clamp mirror

bull minification ndash GL_NEARESTGL_LINEAR

xxx_MIPMAP_xxx

bull magnification ndash GL_NEARESTGL_LINEAR

bull border color ndash when using clamped wrapping

bull priority

bull level-of-detail control for MIPMAP

bull hellip

Texture Unit - glTexEnv

bull many options for how texel is combined with framebuffer pixel colorndash blendingndash replacementndash decalndash addingndash enable point sprites

hellip

Other Texture issues

bull multi-texturingndash texture units work seriallyndash glMultiTexCoord vs glTexCoord

bull glTexGen ndash generate texcoordrsquos from vertex coordinatesndash define function that computes tex coord

Vertex Buffer Objects - Preliminaries

bull builds off of client side vertex arrays1 glEnableClientState(GLenum array)

array from GL_VERTEX_ARRAY GL_COLOR_ARRAY GL_NORMAL_ARRAY etc

2 glVertexPointer(int size enum type sizei stride void pointer)size = 234 type = GL_FLOATGL_INT etc

3 glDrawArrays(GLenum mode GLint first GLsizei count) helliporhellip glDrawElements(GLenum mode GLsizei count GLenum

type void indices) index helliporhellip

glBegin(GL_TRIANGLE) glArrayElement(2) index hellip

Vertex Buffer Objects ndash Create and Initialize

bull VBOrsquos instead of lsquopointerrsquo pointing to CPU memory itrsquos treated as a offset to a vertex buffer in GPU memory

bull glGenBuffers(GLsizei n GLuint buffers) create namebull glBindBuffer(GLenum target GLuint buffer) create buffer

target=GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER

bull glBufferData(GLenum target GLsizeiptr size const GLvoid data GLenum usage) copy data to buffer

size = elements size of elementdata = pointer to CPU memory or NULL (no initialize)usage = GL_(STREAM|STATIC|DYNAMIC)_(DRAW|READ|COPY)

usage is a performance hint

Vertex Buffer Objects - usage

bull _DRAW - data used as vertex data for renderingbull _READ ndash data read from an OGL buffer (such as

framebuffer) and used in application for computations not immediately related to rendering (OGL ge 21)

bull _COPY ndash data values are read from OGL buffer and then used as vertex data for rendering (OGL ge 21)

bull _STREAM_ - frequent updates to buffer but only used a few times in drawing or other operations (updatedraw asymp 11)

bull _STATIC_ - set data once and use many times (updatedraw = 1N)

bull _DYNAMIC_ - you may update buffer often and use it many times as well (updatedraw = NN)

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 17: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Rasterization - zBuffer(x1y1z1)

(x2y2z2)(x3y3z3)

(xryrzr)(xlylzl)

(xyz)

bull Generally to compute z

bull Incremental in x

bull Incremental in y

Ax By Dz

C

( 1)

A x By Dz z A C

C

1

So

or if =

x x m

A m Bz z z z B C m

C

Rasterization ndash Texture Coordinates

bull assign 3 (st)-coordinates to 3 vertices of geometric primitive

linearly interpolate (st) to map texture space to object-space

v1t1

v0t0

v2t2

t

s

t0 t1

t2 t=(st)

t=(st)

(11)

v1t1

v0t0

v2t2

t

s

t0 t1

t2t=(st)t=(st)

(11)

texture spaceobject space

window space

t=(st)t=(st) non-affine

affine

Mobjlarrtex

Mwinlarrobj

Rasterization Need Rational linear interpolation

Rational linear interpolation in Scan-Conversion

t

s

t0 t1

t2

t=(st)

(11)

texture spacewindow space

t=(st)t=(st)non-affine

MwinlarrobjMobjlarrtex

(sqtqq)bulllinearly interpolate 3 variables

sqtqqbullcompute st with a division per pixel

s=sqq t=tqq

Rasterization Who does what

bull Rasterize unit does ndash scan conversion (generate (xy))ndash rational linear interpolation of texture coordinatesndash linear interpolation of depth coordinatendash rational linear () interpolation of vertex color

bull Fragment Processorndash if using fragment shader you can further modify the

depth coordinate and texture coordinate from those generated by Rasterize unit

Rasterization GL state

bull GL_POINTS ndash glPointSize glPointParameter POINT SPRITE texture

bull GL_LINESGL_LINE_LOOP ndash glLineWidth glLineStipple

bull GL_TRIANGLES etc ndash glPolygonStipple glPolygonMode glPolygonOffset glFrontFace

bull crude anti-aliasing ndash glEnable GL_POINT_SMOOTH GL_LINE_SMOOTH GL_POLYGON_SMOOTH

bull Is color interpolated - glShadeModel

Per-Fragment Operations - I

bull pixel ownership test ndash is the destination pixel visible or obscured by other window

bull scissor test ndash clips fragment against rectangle given by glScissor

bull alpha test ndash decides whether to discard fragment based on comparison of fragrsquos alpha value with target given by glAlphaFunc

bull stencil test ndash compares stencil buffer value with reference value and decides whether to discard pixel (glStencilFunc glStencilOp)

bull depth test ndash use function set by glDepthFunc to compare depth of fragment to depth of destination pixel in framebuffer

Per-Fragment Operations - II

bull blending ndash color stored in pixel is blend of fragment color and original pixel color and blend state (glBlendFunc glBlendColor glBlendEquation)

bull logical operations ndashbitwise boolean operations (glLogicOp)

bull dithering - old

Frame Buffer Operations

bull which buffer(s) are written too GL_FRONT GL_FRONT_LEFTGL_AUX0 etc (glDrawBuffer glDrawBuffers)

bull write protection ndash which bitsbytes are affected (glColorMask glDepthMask glStencilMask)

bull clear framebuffer ndash glClear glClearColor glClearDepth glClearStencil glClearAccum

bull glFlush ndash make sure all primitives are progressing toward completion (noone waiting around in queue)

bull glFinish ndash block () until all pending GL calls have executed

Graphics Workstation

DisplayProcessor Display

ProcessorMemory

FramebufferVideo

Controller

PeripheralDevices

CPU SystemMemory

System Bus

Nvidia 8800 Ultra Peak 103GBs

PCIExpress Input 4GBs

Bandwidth Discrepancy Demands Data on Graphics Card

bull Since transfer from CPU to GPU is much slower than GPU to graphics memory we have

ndash texture objects (OGL ge 11)ndash vertex buffer objects (OGL ge 15)ndash pixel buffer objects (OGL ge 21)ndash display lists (OGL ge 10)

Texture Sampling

bull Fragment Processor gets interpolated texture coordinates from Rasterize unit and does a texel lookup from some of the texture units (GL_MAX_TEXTURE_UNITS)

bull Each texture unit is a piece of GPU hardware () and hasndash Enabledisabled statendash Texture matrix stackndash state for automatic generation of texture coordinatesndash Texture environment statendash Current 1D 2D 3D and cube map texture

GL_TEXTUREi

1D

2D

3D

CUBE

Texture Unit rarr glBindTexturelarrTexture Object

GL_TEXTURE0

hellip

GL_ACTIVE_TEXTURE

glActiveTexture

Texture UnitsTexture Objects

GLuint=1

GLuint=2

GLuint=3

GLuint=N

GL_

MA

X_T

EX

TU

RE

_UN

ITS

hellip

as many as m

emory allow

s

glBindTexture

bind texture object to one of the four texture targets of the active texture unit

1D

2D

3D

CUBE

GL_TEXTURE1

1D

2D

3D

CUBE

GL_TEXTUREN

1D

2D

3D

CUBE

hellip

Transfer pixel data to GPU texture memory

bull data is associated with texture object

bull glTexImage(3D|2D|1D) ndash load whole image from CPU

bull glTexSubImage(3D|2D|1D) ndash load sub image from CPU

bull glCopyTexImage(1D|2D) ndash load whole image from framebuffer

bull glCopyTexSubImage(1D|2D|3D) ndash load sub-image from framebuffer

bull MIPMAP and compression supported

Texture Object - glTexParameter

bull wrapping behavior ndash repeat clamp mirror

bull minification ndash GL_NEARESTGL_LINEAR

xxx_MIPMAP_xxx

bull magnification ndash GL_NEARESTGL_LINEAR

bull border color ndash when using clamped wrapping

bull priority

bull level-of-detail control for MIPMAP

bull hellip

Texture Unit - glTexEnv

bull many options for how texel is combined with framebuffer pixel colorndash blendingndash replacementndash decalndash addingndash enable point sprites

hellip

Other Texture issues

bull multi-texturingndash texture units work seriallyndash glMultiTexCoord vs glTexCoord

bull glTexGen ndash generate texcoordrsquos from vertex coordinatesndash define function that computes tex coord

Vertex Buffer Objects - Preliminaries

bull builds off of client side vertex arrays1 glEnableClientState(GLenum array)

array from GL_VERTEX_ARRAY GL_COLOR_ARRAY GL_NORMAL_ARRAY etc

2 glVertexPointer(int size enum type sizei stride void pointer)size = 234 type = GL_FLOATGL_INT etc

3 glDrawArrays(GLenum mode GLint first GLsizei count) helliporhellip glDrawElements(GLenum mode GLsizei count GLenum

type void indices) index helliporhellip

glBegin(GL_TRIANGLE) glArrayElement(2) index hellip

Vertex Buffer Objects ndash Create and Initialize

bull VBOrsquos instead of lsquopointerrsquo pointing to CPU memory itrsquos treated as a offset to a vertex buffer in GPU memory

bull glGenBuffers(GLsizei n GLuint buffers) create namebull glBindBuffer(GLenum target GLuint buffer) create buffer

target=GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER

bull glBufferData(GLenum target GLsizeiptr size const GLvoid data GLenum usage) copy data to buffer

size = elements size of elementdata = pointer to CPU memory or NULL (no initialize)usage = GL_(STREAM|STATIC|DYNAMIC)_(DRAW|READ|COPY)

usage is a performance hint

Vertex Buffer Objects - usage

bull _DRAW - data used as vertex data for renderingbull _READ ndash data read from an OGL buffer (such as

framebuffer) and used in application for computations not immediately related to rendering (OGL ge 21)

bull _COPY ndash data values are read from OGL buffer and then used as vertex data for rendering (OGL ge 21)

bull _STREAM_ - frequent updates to buffer but only used a few times in drawing or other operations (updatedraw asymp 11)

bull _STATIC_ - set data once and use many times (updatedraw = 1N)

bull _DYNAMIC_ - you may update buffer often and use it many times as well (updatedraw = NN)

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 18: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Rasterization ndash Texture Coordinates

bull assign 3 (st)-coordinates to 3 vertices of geometric primitive

linearly interpolate (st) to map texture space to object-space

v1t1

v0t0

v2t2

t

s

t0 t1

t2 t=(st)

t=(st)

(11)

v1t1

v0t0

v2t2

t

s

t0 t1

t2t=(st)t=(st)

(11)

texture spaceobject space

window space

t=(st)t=(st) non-affine

affine

Mobjlarrtex

Mwinlarrobj

Rasterization Need Rational linear interpolation

Rational linear interpolation in Scan-Conversion

t

s

t0 t1

t2

t=(st)

(11)

texture spacewindow space

t=(st)t=(st)non-affine

MwinlarrobjMobjlarrtex

(sqtqq)bulllinearly interpolate 3 variables

sqtqqbullcompute st with a division per pixel

s=sqq t=tqq

Rasterization Who does what

bull Rasterize unit does ndash scan conversion (generate (xy))ndash rational linear interpolation of texture coordinatesndash linear interpolation of depth coordinatendash rational linear () interpolation of vertex color

bull Fragment Processorndash if using fragment shader you can further modify the

depth coordinate and texture coordinate from those generated by Rasterize unit

Rasterization GL state

bull GL_POINTS ndash glPointSize glPointParameter POINT SPRITE texture

bull GL_LINESGL_LINE_LOOP ndash glLineWidth glLineStipple

bull GL_TRIANGLES etc ndash glPolygonStipple glPolygonMode glPolygonOffset glFrontFace

bull crude anti-aliasing ndash glEnable GL_POINT_SMOOTH GL_LINE_SMOOTH GL_POLYGON_SMOOTH

bull Is color interpolated - glShadeModel

Per-Fragment Operations - I

bull pixel ownership test ndash is the destination pixel visible or obscured by other window

bull scissor test ndash clips fragment against rectangle given by glScissor

bull alpha test ndash decides whether to discard fragment based on comparison of fragrsquos alpha value with target given by glAlphaFunc

bull stencil test ndash compares stencil buffer value with reference value and decides whether to discard pixel (glStencilFunc glStencilOp)

bull depth test ndash use function set by glDepthFunc to compare depth of fragment to depth of destination pixel in framebuffer

Per-Fragment Operations - II

bull blending ndash color stored in pixel is blend of fragment color and original pixel color and blend state (glBlendFunc glBlendColor glBlendEquation)

bull logical operations ndashbitwise boolean operations (glLogicOp)

bull dithering - old

Frame Buffer Operations

bull which buffer(s) are written too GL_FRONT GL_FRONT_LEFTGL_AUX0 etc (glDrawBuffer glDrawBuffers)

bull write protection ndash which bitsbytes are affected (glColorMask glDepthMask glStencilMask)

bull clear framebuffer ndash glClear glClearColor glClearDepth glClearStencil glClearAccum

bull glFlush ndash make sure all primitives are progressing toward completion (noone waiting around in queue)

bull glFinish ndash block () until all pending GL calls have executed

Graphics Workstation

DisplayProcessor Display

ProcessorMemory

FramebufferVideo

Controller

PeripheralDevices

CPU SystemMemory

System Bus

Nvidia 8800 Ultra Peak 103GBs

PCIExpress Input 4GBs

Bandwidth Discrepancy Demands Data on Graphics Card

bull Since transfer from CPU to GPU is much slower than GPU to graphics memory we have

ndash texture objects (OGL ge 11)ndash vertex buffer objects (OGL ge 15)ndash pixel buffer objects (OGL ge 21)ndash display lists (OGL ge 10)

Texture Sampling

bull Fragment Processor gets interpolated texture coordinates from Rasterize unit and does a texel lookup from some of the texture units (GL_MAX_TEXTURE_UNITS)

bull Each texture unit is a piece of GPU hardware () and hasndash Enabledisabled statendash Texture matrix stackndash state for automatic generation of texture coordinatesndash Texture environment statendash Current 1D 2D 3D and cube map texture

GL_TEXTUREi

1D

2D

3D

CUBE

Texture Unit rarr glBindTexturelarrTexture Object

GL_TEXTURE0

hellip

GL_ACTIVE_TEXTURE

glActiveTexture

Texture UnitsTexture Objects

GLuint=1

GLuint=2

GLuint=3

GLuint=N

GL_

MA

X_T

EX

TU

RE

_UN

ITS

hellip

as many as m

emory allow

s

glBindTexture

bind texture object to one of the four texture targets of the active texture unit

1D

2D

3D

CUBE

GL_TEXTURE1

1D

2D

3D

CUBE

GL_TEXTUREN

1D

2D

3D

CUBE

hellip

Transfer pixel data to GPU texture memory

bull data is associated with texture object

bull glTexImage(3D|2D|1D) ndash load whole image from CPU

bull glTexSubImage(3D|2D|1D) ndash load sub image from CPU

bull glCopyTexImage(1D|2D) ndash load whole image from framebuffer

bull glCopyTexSubImage(1D|2D|3D) ndash load sub-image from framebuffer

bull MIPMAP and compression supported

Texture Object - glTexParameter

bull wrapping behavior ndash repeat clamp mirror

bull minification ndash GL_NEARESTGL_LINEAR

xxx_MIPMAP_xxx

bull magnification ndash GL_NEARESTGL_LINEAR

bull border color ndash when using clamped wrapping

bull priority

bull level-of-detail control for MIPMAP

bull hellip

Texture Unit - glTexEnv

bull many options for how texel is combined with framebuffer pixel colorndash blendingndash replacementndash decalndash addingndash enable point sprites

hellip

Other Texture issues

bull multi-texturingndash texture units work seriallyndash glMultiTexCoord vs glTexCoord

bull glTexGen ndash generate texcoordrsquos from vertex coordinatesndash define function that computes tex coord

Vertex Buffer Objects - Preliminaries

bull builds off of client side vertex arrays1 glEnableClientState(GLenum array)

array from GL_VERTEX_ARRAY GL_COLOR_ARRAY GL_NORMAL_ARRAY etc

2 glVertexPointer(int size enum type sizei stride void pointer)size = 234 type = GL_FLOATGL_INT etc

3 glDrawArrays(GLenum mode GLint first GLsizei count) helliporhellip glDrawElements(GLenum mode GLsizei count GLenum

type void indices) index helliporhellip

glBegin(GL_TRIANGLE) glArrayElement(2) index hellip

Vertex Buffer Objects ndash Create and Initialize

bull VBOrsquos instead of lsquopointerrsquo pointing to CPU memory itrsquos treated as a offset to a vertex buffer in GPU memory

bull glGenBuffers(GLsizei n GLuint buffers) create namebull glBindBuffer(GLenum target GLuint buffer) create buffer

target=GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER

bull glBufferData(GLenum target GLsizeiptr size const GLvoid data GLenum usage) copy data to buffer

size = elements size of elementdata = pointer to CPU memory or NULL (no initialize)usage = GL_(STREAM|STATIC|DYNAMIC)_(DRAW|READ|COPY)

usage is a performance hint

Vertex Buffer Objects - usage

bull _DRAW - data used as vertex data for renderingbull _READ ndash data read from an OGL buffer (such as

framebuffer) and used in application for computations not immediately related to rendering (OGL ge 21)

bull _COPY ndash data values are read from OGL buffer and then used as vertex data for rendering (OGL ge 21)

bull _STREAM_ - frequent updates to buffer but only used a few times in drawing or other operations (updatedraw asymp 11)

bull _STATIC_ - set data once and use many times (updatedraw = 1N)

bull _DYNAMIC_ - you may update buffer often and use it many times as well (updatedraw = NN)

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 19: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

v1t1

v0t0

v2t2

t

s

t0 t1

t2t=(st)t=(st)

(11)

texture spaceobject space

window space

t=(st)t=(st) non-affine

affine

Mobjlarrtex

Mwinlarrobj

Rasterization Need Rational linear interpolation

Rational linear interpolation in Scan-Conversion

t

s

t0 t1

t2

t=(st)

(11)

texture spacewindow space

t=(st)t=(st)non-affine

MwinlarrobjMobjlarrtex

(sqtqq)bulllinearly interpolate 3 variables

sqtqqbullcompute st with a division per pixel

s=sqq t=tqq

Rasterization Who does what

bull Rasterize unit does ndash scan conversion (generate (xy))ndash rational linear interpolation of texture coordinatesndash linear interpolation of depth coordinatendash rational linear () interpolation of vertex color

bull Fragment Processorndash if using fragment shader you can further modify the

depth coordinate and texture coordinate from those generated by Rasterize unit

Rasterization GL state

bull GL_POINTS ndash glPointSize glPointParameter POINT SPRITE texture

bull GL_LINESGL_LINE_LOOP ndash glLineWidth glLineStipple

bull GL_TRIANGLES etc ndash glPolygonStipple glPolygonMode glPolygonOffset glFrontFace

bull crude anti-aliasing ndash glEnable GL_POINT_SMOOTH GL_LINE_SMOOTH GL_POLYGON_SMOOTH

bull Is color interpolated - glShadeModel

Per-Fragment Operations - I

bull pixel ownership test ndash is the destination pixel visible or obscured by other window

bull scissor test ndash clips fragment against rectangle given by glScissor

bull alpha test ndash decides whether to discard fragment based on comparison of fragrsquos alpha value with target given by glAlphaFunc

bull stencil test ndash compares stencil buffer value with reference value and decides whether to discard pixel (glStencilFunc glStencilOp)

bull depth test ndash use function set by glDepthFunc to compare depth of fragment to depth of destination pixel in framebuffer

Per-Fragment Operations - II

bull blending ndash color stored in pixel is blend of fragment color and original pixel color and blend state (glBlendFunc glBlendColor glBlendEquation)

bull logical operations ndashbitwise boolean operations (glLogicOp)

bull dithering - old

Frame Buffer Operations

bull which buffer(s) are written too GL_FRONT GL_FRONT_LEFTGL_AUX0 etc (glDrawBuffer glDrawBuffers)

bull write protection ndash which bitsbytes are affected (glColorMask glDepthMask glStencilMask)

bull clear framebuffer ndash glClear glClearColor glClearDepth glClearStencil glClearAccum

bull glFlush ndash make sure all primitives are progressing toward completion (noone waiting around in queue)

bull glFinish ndash block () until all pending GL calls have executed

Graphics Workstation

DisplayProcessor Display

ProcessorMemory

FramebufferVideo

Controller

PeripheralDevices

CPU SystemMemory

System Bus

Nvidia 8800 Ultra Peak 103GBs

PCIExpress Input 4GBs

Bandwidth Discrepancy Demands Data on Graphics Card

bull Since transfer from CPU to GPU is much slower than GPU to graphics memory we have

ndash texture objects (OGL ge 11)ndash vertex buffer objects (OGL ge 15)ndash pixel buffer objects (OGL ge 21)ndash display lists (OGL ge 10)

Texture Sampling

bull Fragment Processor gets interpolated texture coordinates from Rasterize unit and does a texel lookup from some of the texture units (GL_MAX_TEXTURE_UNITS)

bull Each texture unit is a piece of GPU hardware () and hasndash Enabledisabled statendash Texture matrix stackndash state for automatic generation of texture coordinatesndash Texture environment statendash Current 1D 2D 3D and cube map texture

GL_TEXTUREi

1D

2D

3D

CUBE

Texture Unit rarr glBindTexturelarrTexture Object

GL_TEXTURE0

hellip

GL_ACTIVE_TEXTURE

glActiveTexture

Texture UnitsTexture Objects

GLuint=1

GLuint=2

GLuint=3

GLuint=N

GL_

MA

X_T

EX

TU

RE

_UN

ITS

hellip

as many as m

emory allow

s

glBindTexture

bind texture object to one of the four texture targets of the active texture unit

1D

2D

3D

CUBE

GL_TEXTURE1

1D

2D

3D

CUBE

GL_TEXTUREN

1D

2D

3D

CUBE

hellip

Transfer pixel data to GPU texture memory

bull data is associated with texture object

bull glTexImage(3D|2D|1D) ndash load whole image from CPU

bull glTexSubImage(3D|2D|1D) ndash load sub image from CPU

bull glCopyTexImage(1D|2D) ndash load whole image from framebuffer

bull glCopyTexSubImage(1D|2D|3D) ndash load sub-image from framebuffer

bull MIPMAP and compression supported

Texture Object - glTexParameter

bull wrapping behavior ndash repeat clamp mirror

bull minification ndash GL_NEARESTGL_LINEAR

xxx_MIPMAP_xxx

bull magnification ndash GL_NEARESTGL_LINEAR

bull border color ndash when using clamped wrapping

bull priority

bull level-of-detail control for MIPMAP

bull hellip

Texture Unit - glTexEnv

bull many options for how texel is combined with framebuffer pixel colorndash blendingndash replacementndash decalndash addingndash enable point sprites

hellip

Other Texture issues

bull multi-texturingndash texture units work seriallyndash glMultiTexCoord vs glTexCoord

bull glTexGen ndash generate texcoordrsquos from vertex coordinatesndash define function that computes tex coord

Vertex Buffer Objects - Preliminaries

bull builds off of client side vertex arrays1 glEnableClientState(GLenum array)

array from GL_VERTEX_ARRAY GL_COLOR_ARRAY GL_NORMAL_ARRAY etc

2 glVertexPointer(int size enum type sizei stride void pointer)size = 234 type = GL_FLOATGL_INT etc

3 glDrawArrays(GLenum mode GLint first GLsizei count) helliporhellip glDrawElements(GLenum mode GLsizei count GLenum

type void indices) index helliporhellip

glBegin(GL_TRIANGLE) glArrayElement(2) index hellip

Vertex Buffer Objects ndash Create and Initialize

bull VBOrsquos instead of lsquopointerrsquo pointing to CPU memory itrsquos treated as a offset to a vertex buffer in GPU memory

bull glGenBuffers(GLsizei n GLuint buffers) create namebull glBindBuffer(GLenum target GLuint buffer) create buffer

target=GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER

bull glBufferData(GLenum target GLsizeiptr size const GLvoid data GLenum usage) copy data to buffer

size = elements size of elementdata = pointer to CPU memory or NULL (no initialize)usage = GL_(STREAM|STATIC|DYNAMIC)_(DRAW|READ|COPY)

usage is a performance hint

Vertex Buffer Objects - usage

bull _DRAW - data used as vertex data for renderingbull _READ ndash data read from an OGL buffer (such as

framebuffer) and used in application for computations not immediately related to rendering (OGL ge 21)

bull _COPY ndash data values are read from OGL buffer and then used as vertex data for rendering (OGL ge 21)

bull _STREAM_ - frequent updates to buffer but only used a few times in drawing or other operations (updatedraw asymp 11)

bull _STATIC_ - set data once and use many times (updatedraw = 1N)

bull _DYNAMIC_ - you may update buffer often and use it many times as well (updatedraw = NN)

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 20: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Rational linear interpolation in Scan-Conversion

t

s

t0 t1

t2

t=(st)

(11)

texture spacewindow space

t=(st)t=(st)non-affine

MwinlarrobjMobjlarrtex

(sqtqq)bulllinearly interpolate 3 variables

sqtqqbullcompute st with a division per pixel

s=sqq t=tqq

Rasterization Who does what

bull Rasterize unit does ndash scan conversion (generate (xy))ndash rational linear interpolation of texture coordinatesndash linear interpolation of depth coordinatendash rational linear () interpolation of vertex color

bull Fragment Processorndash if using fragment shader you can further modify the

depth coordinate and texture coordinate from those generated by Rasterize unit

Rasterization GL state

bull GL_POINTS ndash glPointSize glPointParameter POINT SPRITE texture

bull GL_LINESGL_LINE_LOOP ndash glLineWidth glLineStipple

bull GL_TRIANGLES etc ndash glPolygonStipple glPolygonMode glPolygonOffset glFrontFace

bull crude anti-aliasing ndash glEnable GL_POINT_SMOOTH GL_LINE_SMOOTH GL_POLYGON_SMOOTH

bull Is color interpolated - glShadeModel

Per-Fragment Operations - I

bull pixel ownership test ndash is the destination pixel visible or obscured by other window

bull scissor test ndash clips fragment against rectangle given by glScissor

bull alpha test ndash decides whether to discard fragment based on comparison of fragrsquos alpha value with target given by glAlphaFunc

bull stencil test ndash compares stencil buffer value with reference value and decides whether to discard pixel (glStencilFunc glStencilOp)

bull depth test ndash use function set by glDepthFunc to compare depth of fragment to depth of destination pixel in framebuffer

Per-Fragment Operations - II

bull blending ndash color stored in pixel is blend of fragment color and original pixel color and blend state (glBlendFunc glBlendColor glBlendEquation)

bull logical operations ndashbitwise boolean operations (glLogicOp)

bull dithering - old

Frame Buffer Operations

bull which buffer(s) are written too GL_FRONT GL_FRONT_LEFTGL_AUX0 etc (glDrawBuffer glDrawBuffers)

bull write protection ndash which bitsbytes are affected (glColorMask glDepthMask glStencilMask)

bull clear framebuffer ndash glClear glClearColor glClearDepth glClearStencil glClearAccum

bull glFlush ndash make sure all primitives are progressing toward completion (noone waiting around in queue)

bull glFinish ndash block () until all pending GL calls have executed

Graphics Workstation

DisplayProcessor Display

ProcessorMemory

FramebufferVideo

Controller

PeripheralDevices

CPU SystemMemory

System Bus

Nvidia 8800 Ultra Peak 103GBs

PCIExpress Input 4GBs

Bandwidth Discrepancy Demands Data on Graphics Card

bull Since transfer from CPU to GPU is much slower than GPU to graphics memory we have

ndash texture objects (OGL ge 11)ndash vertex buffer objects (OGL ge 15)ndash pixel buffer objects (OGL ge 21)ndash display lists (OGL ge 10)

Texture Sampling

bull Fragment Processor gets interpolated texture coordinates from Rasterize unit and does a texel lookup from some of the texture units (GL_MAX_TEXTURE_UNITS)

bull Each texture unit is a piece of GPU hardware () and hasndash Enabledisabled statendash Texture matrix stackndash state for automatic generation of texture coordinatesndash Texture environment statendash Current 1D 2D 3D and cube map texture

GL_TEXTUREi

1D

2D

3D

CUBE

Texture Unit rarr glBindTexturelarrTexture Object

GL_TEXTURE0

hellip

GL_ACTIVE_TEXTURE

glActiveTexture

Texture UnitsTexture Objects

GLuint=1

GLuint=2

GLuint=3

GLuint=N

GL_

MA

X_T

EX

TU

RE

_UN

ITS

hellip

as many as m

emory allow

s

glBindTexture

bind texture object to one of the four texture targets of the active texture unit

1D

2D

3D

CUBE

GL_TEXTURE1

1D

2D

3D

CUBE

GL_TEXTUREN

1D

2D

3D

CUBE

hellip

Transfer pixel data to GPU texture memory

bull data is associated with texture object

bull glTexImage(3D|2D|1D) ndash load whole image from CPU

bull glTexSubImage(3D|2D|1D) ndash load sub image from CPU

bull glCopyTexImage(1D|2D) ndash load whole image from framebuffer

bull glCopyTexSubImage(1D|2D|3D) ndash load sub-image from framebuffer

bull MIPMAP and compression supported

Texture Object - glTexParameter

bull wrapping behavior ndash repeat clamp mirror

bull minification ndash GL_NEARESTGL_LINEAR

xxx_MIPMAP_xxx

bull magnification ndash GL_NEARESTGL_LINEAR

bull border color ndash when using clamped wrapping

bull priority

bull level-of-detail control for MIPMAP

bull hellip

Texture Unit - glTexEnv

bull many options for how texel is combined with framebuffer pixel colorndash blendingndash replacementndash decalndash addingndash enable point sprites

hellip

Other Texture issues

bull multi-texturingndash texture units work seriallyndash glMultiTexCoord vs glTexCoord

bull glTexGen ndash generate texcoordrsquos from vertex coordinatesndash define function that computes tex coord

Vertex Buffer Objects - Preliminaries

bull builds off of client side vertex arrays1 glEnableClientState(GLenum array)

array from GL_VERTEX_ARRAY GL_COLOR_ARRAY GL_NORMAL_ARRAY etc

2 glVertexPointer(int size enum type sizei stride void pointer)size = 234 type = GL_FLOATGL_INT etc

3 glDrawArrays(GLenum mode GLint first GLsizei count) helliporhellip glDrawElements(GLenum mode GLsizei count GLenum

type void indices) index helliporhellip

glBegin(GL_TRIANGLE) glArrayElement(2) index hellip

Vertex Buffer Objects ndash Create and Initialize

bull VBOrsquos instead of lsquopointerrsquo pointing to CPU memory itrsquos treated as a offset to a vertex buffer in GPU memory

bull glGenBuffers(GLsizei n GLuint buffers) create namebull glBindBuffer(GLenum target GLuint buffer) create buffer

target=GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER

bull glBufferData(GLenum target GLsizeiptr size const GLvoid data GLenum usage) copy data to buffer

size = elements size of elementdata = pointer to CPU memory or NULL (no initialize)usage = GL_(STREAM|STATIC|DYNAMIC)_(DRAW|READ|COPY)

usage is a performance hint

Vertex Buffer Objects - usage

bull _DRAW - data used as vertex data for renderingbull _READ ndash data read from an OGL buffer (such as

framebuffer) and used in application for computations not immediately related to rendering (OGL ge 21)

bull _COPY ndash data values are read from OGL buffer and then used as vertex data for rendering (OGL ge 21)

bull _STREAM_ - frequent updates to buffer but only used a few times in drawing or other operations (updatedraw asymp 11)

bull _STATIC_ - set data once and use many times (updatedraw = 1N)

bull _DYNAMIC_ - you may update buffer often and use it many times as well (updatedraw = NN)

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 21: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Rasterization Who does what

bull Rasterize unit does ndash scan conversion (generate (xy))ndash rational linear interpolation of texture coordinatesndash linear interpolation of depth coordinatendash rational linear () interpolation of vertex color

bull Fragment Processorndash if using fragment shader you can further modify the

depth coordinate and texture coordinate from those generated by Rasterize unit

Rasterization GL state

bull GL_POINTS ndash glPointSize glPointParameter POINT SPRITE texture

bull GL_LINESGL_LINE_LOOP ndash glLineWidth glLineStipple

bull GL_TRIANGLES etc ndash glPolygonStipple glPolygonMode glPolygonOffset glFrontFace

bull crude anti-aliasing ndash glEnable GL_POINT_SMOOTH GL_LINE_SMOOTH GL_POLYGON_SMOOTH

bull Is color interpolated - glShadeModel

Per-Fragment Operations - I

bull pixel ownership test ndash is the destination pixel visible or obscured by other window

bull scissor test ndash clips fragment against rectangle given by glScissor

bull alpha test ndash decides whether to discard fragment based on comparison of fragrsquos alpha value with target given by glAlphaFunc

bull stencil test ndash compares stencil buffer value with reference value and decides whether to discard pixel (glStencilFunc glStencilOp)

bull depth test ndash use function set by glDepthFunc to compare depth of fragment to depth of destination pixel in framebuffer

Per-Fragment Operations - II

bull blending ndash color stored in pixel is blend of fragment color and original pixel color and blend state (glBlendFunc glBlendColor glBlendEquation)

bull logical operations ndashbitwise boolean operations (glLogicOp)

bull dithering - old

Frame Buffer Operations

bull which buffer(s) are written too GL_FRONT GL_FRONT_LEFTGL_AUX0 etc (glDrawBuffer glDrawBuffers)

bull write protection ndash which bitsbytes are affected (glColorMask glDepthMask glStencilMask)

bull clear framebuffer ndash glClear glClearColor glClearDepth glClearStencil glClearAccum

bull glFlush ndash make sure all primitives are progressing toward completion (noone waiting around in queue)

bull glFinish ndash block () until all pending GL calls have executed

Graphics Workstation

DisplayProcessor Display

ProcessorMemory

FramebufferVideo

Controller

PeripheralDevices

CPU SystemMemory

System Bus

Nvidia 8800 Ultra Peak 103GBs

PCIExpress Input 4GBs

Bandwidth Discrepancy Demands Data on Graphics Card

bull Since transfer from CPU to GPU is much slower than GPU to graphics memory we have

ndash texture objects (OGL ge 11)ndash vertex buffer objects (OGL ge 15)ndash pixel buffer objects (OGL ge 21)ndash display lists (OGL ge 10)

Texture Sampling

bull Fragment Processor gets interpolated texture coordinates from Rasterize unit and does a texel lookup from some of the texture units (GL_MAX_TEXTURE_UNITS)

bull Each texture unit is a piece of GPU hardware () and hasndash Enabledisabled statendash Texture matrix stackndash state for automatic generation of texture coordinatesndash Texture environment statendash Current 1D 2D 3D and cube map texture

GL_TEXTUREi

1D

2D

3D

CUBE

Texture Unit rarr glBindTexturelarrTexture Object

GL_TEXTURE0

hellip

GL_ACTIVE_TEXTURE

glActiveTexture

Texture UnitsTexture Objects

GLuint=1

GLuint=2

GLuint=3

GLuint=N

GL_

MA

X_T

EX

TU

RE

_UN

ITS

hellip

as many as m

emory allow

s

glBindTexture

bind texture object to one of the four texture targets of the active texture unit

1D

2D

3D

CUBE

GL_TEXTURE1

1D

2D

3D

CUBE

GL_TEXTUREN

1D

2D

3D

CUBE

hellip

Transfer pixel data to GPU texture memory

bull data is associated with texture object

bull glTexImage(3D|2D|1D) ndash load whole image from CPU

bull glTexSubImage(3D|2D|1D) ndash load sub image from CPU

bull glCopyTexImage(1D|2D) ndash load whole image from framebuffer

bull glCopyTexSubImage(1D|2D|3D) ndash load sub-image from framebuffer

bull MIPMAP and compression supported

Texture Object - glTexParameter

bull wrapping behavior ndash repeat clamp mirror

bull minification ndash GL_NEARESTGL_LINEAR

xxx_MIPMAP_xxx

bull magnification ndash GL_NEARESTGL_LINEAR

bull border color ndash when using clamped wrapping

bull priority

bull level-of-detail control for MIPMAP

bull hellip

Texture Unit - glTexEnv

bull many options for how texel is combined with framebuffer pixel colorndash blendingndash replacementndash decalndash addingndash enable point sprites

hellip

Other Texture issues

bull multi-texturingndash texture units work seriallyndash glMultiTexCoord vs glTexCoord

bull glTexGen ndash generate texcoordrsquos from vertex coordinatesndash define function that computes tex coord

Vertex Buffer Objects - Preliminaries

bull builds off of client side vertex arrays1 glEnableClientState(GLenum array)

array from GL_VERTEX_ARRAY GL_COLOR_ARRAY GL_NORMAL_ARRAY etc

2 glVertexPointer(int size enum type sizei stride void pointer)size = 234 type = GL_FLOATGL_INT etc

3 glDrawArrays(GLenum mode GLint first GLsizei count) helliporhellip glDrawElements(GLenum mode GLsizei count GLenum

type void indices) index helliporhellip

glBegin(GL_TRIANGLE) glArrayElement(2) index hellip

Vertex Buffer Objects ndash Create and Initialize

bull VBOrsquos instead of lsquopointerrsquo pointing to CPU memory itrsquos treated as a offset to a vertex buffer in GPU memory

bull glGenBuffers(GLsizei n GLuint buffers) create namebull glBindBuffer(GLenum target GLuint buffer) create buffer

target=GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER

bull glBufferData(GLenum target GLsizeiptr size const GLvoid data GLenum usage) copy data to buffer

size = elements size of elementdata = pointer to CPU memory or NULL (no initialize)usage = GL_(STREAM|STATIC|DYNAMIC)_(DRAW|READ|COPY)

usage is a performance hint

Vertex Buffer Objects - usage

bull _DRAW - data used as vertex data for renderingbull _READ ndash data read from an OGL buffer (such as

framebuffer) and used in application for computations not immediately related to rendering (OGL ge 21)

bull _COPY ndash data values are read from OGL buffer and then used as vertex data for rendering (OGL ge 21)

bull _STREAM_ - frequent updates to buffer but only used a few times in drawing or other operations (updatedraw asymp 11)

bull _STATIC_ - set data once and use many times (updatedraw = 1N)

bull _DYNAMIC_ - you may update buffer often and use it many times as well (updatedraw = NN)

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 22: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Rasterization GL state

bull GL_POINTS ndash glPointSize glPointParameter POINT SPRITE texture

bull GL_LINESGL_LINE_LOOP ndash glLineWidth glLineStipple

bull GL_TRIANGLES etc ndash glPolygonStipple glPolygonMode glPolygonOffset glFrontFace

bull crude anti-aliasing ndash glEnable GL_POINT_SMOOTH GL_LINE_SMOOTH GL_POLYGON_SMOOTH

bull Is color interpolated - glShadeModel

Per-Fragment Operations - I

bull pixel ownership test ndash is the destination pixel visible or obscured by other window

bull scissor test ndash clips fragment against rectangle given by glScissor

bull alpha test ndash decides whether to discard fragment based on comparison of fragrsquos alpha value with target given by glAlphaFunc

bull stencil test ndash compares stencil buffer value with reference value and decides whether to discard pixel (glStencilFunc glStencilOp)

bull depth test ndash use function set by glDepthFunc to compare depth of fragment to depth of destination pixel in framebuffer

Per-Fragment Operations - II

bull blending ndash color stored in pixel is blend of fragment color and original pixel color and blend state (glBlendFunc glBlendColor glBlendEquation)

bull logical operations ndashbitwise boolean operations (glLogicOp)

bull dithering - old

Frame Buffer Operations

bull which buffer(s) are written too GL_FRONT GL_FRONT_LEFTGL_AUX0 etc (glDrawBuffer glDrawBuffers)

bull write protection ndash which bitsbytes are affected (glColorMask glDepthMask glStencilMask)

bull clear framebuffer ndash glClear glClearColor glClearDepth glClearStencil glClearAccum

bull glFlush ndash make sure all primitives are progressing toward completion (noone waiting around in queue)

bull glFinish ndash block () until all pending GL calls have executed

Graphics Workstation

DisplayProcessor Display

ProcessorMemory

FramebufferVideo

Controller

PeripheralDevices

CPU SystemMemory

System Bus

Nvidia 8800 Ultra Peak 103GBs

PCIExpress Input 4GBs

Bandwidth Discrepancy Demands Data on Graphics Card

bull Since transfer from CPU to GPU is much slower than GPU to graphics memory we have

ndash texture objects (OGL ge 11)ndash vertex buffer objects (OGL ge 15)ndash pixel buffer objects (OGL ge 21)ndash display lists (OGL ge 10)

Texture Sampling

bull Fragment Processor gets interpolated texture coordinates from Rasterize unit and does a texel lookup from some of the texture units (GL_MAX_TEXTURE_UNITS)

bull Each texture unit is a piece of GPU hardware () and hasndash Enabledisabled statendash Texture matrix stackndash state for automatic generation of texture coordinatesndash Texture environment statendash Current 1D 2D 3D and cube map texture

GL_TEXTUREi

1D

2D

3D

CUBE

Texture Unit rarr glBindTexturelarrTexture Object

GL_TEXTURE0

hellip

GL_ACTIVE_TEXTURE

glActiveTexture

Texture UnitsTexture Objects

GLuint=1

GLuint=2

GLuint=3

GLuint=N

GL_

MA

X_T

EX

TU

RE

_UN

ITS

hellip

as many as m

emory allow

s

glBindTexture

bind texture object to one of the four texture targets of the active texture unit

1D

2D

3D

CUBE

GL_TEXTURE1

1D

2D

3D

CUBE

GL_TEXTUREN

1D

2D

3D

CUBE

hellip

Transfer pixel data to GPU texture memory

bull data is associated with texture object

bull glTexImage(3D|2D|1D) ndash load whole image from CPU

bull glTexSubImage(3D|2D|1D) ndash load sub image from CPU

bull glCopyTexImage(1D|2D) ndash load whole image from framebuffer

bull glCopyTexSubImage(1D|2D|3D) ndash load sub-image from framebuffer

bull MIPMAP and compression supported

Texture Object - glTexParameter

bull wrapping behavior ndash repeat clamp mirror

bull minification ndash GL_NEARESTGL_LINEAR

xxx_MIPMAP_xxx

bull magnification ndash GL_NEARESTGL_LINEAR

bull border color ndash when using clamped wrapping

bull priority

bull level-of-detail control for MIPMAP

bull hellip

Texture Unit - glTexEnv

bull many options for how texel is combined with framebuffer pixel colorndash blendingndash replacementndash decalndash addingndash enable point sprites

hellip

Other Texture issues

bull multi-texturingndash texture units work seriallyndash glMultiTexCoord vs glTexCoord

bull glTexGen ndash generate texcoordrsquos from vertex coordinatesndash define function that computes tex coord

Vertex Buffer Objects - Preliminaries

bull builds off of client side vertex arrays1 glEnableClientState(GLenum array)

array from GL_VERTEX_ARRAY GL_COLOR_ARRAY GL_NORMAL_ARRAY etc

2 glVertexPointer(int size enum type sizei stride void pointer)size = 234 type = GL_FLOATGL_INT etc

3 glDrawArrays(GLenum mode GLint first GLsizei count) helliporhellip glDrawElements(GLenum mode GLsizei count GLenum

type void indices) index helliporhellip

glBegin(GL_TRIANGLE) glArrayElement(2) index hellip

Vertex Buffer Objects ndash Create and Initialize

bull VBOrsquos instead of lsquopointerrsquo pointing to CPU memory itrsquos treated as a offset to a vertex buffer in GPU memory

bull glGenBuffers(GLsizei n GLuint buffers) create namebull glBindBuffer(GLenum target GLuint buffer) create buffer

target=GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER

bull glBufferData(GLenum target GLsizeiptr size const GLvoid data GLenum usage) copy data to buffer

size = elements size of elementdata = pointer to CPU memory or NULL (no initialize)usage = GL_(STREAM|STATIC|DYNAMIC)_(DRAW|READ|COPY)

usage is a performance hint

Vertex Buffer Objects - usage

bull _DRAW - data used as vertex data for renderingbull _READ ndash data read from an OGL buffer (such as

framebuffer) and used in application for computations not immediately related to rendering (OGL ge 21)

bull _COPY ndash data values are read from OGL buffer and then used as vertex data for rendering (OGL ge 21)

bull _STREAM_ - frequent updates to buffer but only used a few times in drawing or other operations (updatedraw asymp 11)

bull _STATIC_ - set data once and use many times (updatedraw = 1N)

bull _DYNAMIC_ - you may update buffer often and use it many times as well (updatedraw = NN)

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 23: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Per-Fragment Operations - I

bull pixel ownership test ndash is the destination pixel visible or obscured by other window

bull scissor test ndash clips fragment against rectangle given by glScissor

bull alpha test ndash decides whether to discard fragment based on comparison of fragrsquos alpha value with target given by glAlphaFunc

bull stencil test ndash compares stencil buffer value with reference value and decides whether to discard pixel (glStencilFunc glStencilOp)

bull depth test ndash use function set by glDepthFunc to compare depth of fragment to depth of destination pixel in framebuffer

Per-Fragment Operations - II

bull blending ndash color stored in pixel is blend of fragment color and original pixel color and blend state (glBlendFunc glBlendColor glBlendEquation)

bull logical operations ndashbitwise boolean operations (glLogicOp)

bull dithering - old

Frame Buffer Operations

bull which buffer(s) are written too GL_FRONT GL_FRONT_LEFTGL_AUX0 etc (glDrawBuffer glDrawBuffers)

bull write protection ndash which bitsbytes are affected (glColorMask glDepthMask glStencilMask)

bull clear framebuffer ndash glClear glClearColor glClearDepth glClearStencil glClearAccum

bull glFlush ndash make sure all primitives are progressing toward completion (noone waiting around in queue)

bull glFinish ndash block () until all pending GL calls have executed

Graphics Workstation

DisplayProcessor Display

ProcessorMemory

FramebufferVideo

Controller

PeripheralDevices

CPU SystemMemory

System Bus

Nvidia 8800 Ultra Peak 103GBs

PCIExpress Input 4GBs

Bandwidth Discrepancy Demands Data on Graphics Card

bull Since transfer from CPU to GPU is much slower than GPU to graphics memory we have

ndash texture objects (OGL ge 11)ndash vertex buffer objects (OGL ge 15)ndash pixel buffer objects (OGL ge 21)ndash display lists (OGL ge 10)

Texture Sampling

bull Fragment Processor gets interpolated texture coordinates from Rasterize unit and does a texel lookup from some of the texture units (GL_MAX_TEXTURE_UNITS)

bull Each texture unit is a piece of GPU hardware () and hasndash Enabledisabled statendash Texture matrix stackndash state for automatic generation of texture coordinatesndash Texture environment statendash Current 1D 2D 3D and cube map texture

GL_TEXTUREi

1D

2D

3D

CUBE

Texture Unit rarr glBindTexturelarrTexture Object

GL_TEXTURE0

hellip

GL_ACTIVE_TEXTURE

glActiveTexture

Texture UnitsTexture Objects

GLuint=1

GLuint=2

GLuint=3

GLuint=N

GL_

MA

X_T

EX

TU

RE

_UN

ITS

hellip

as many as m

emory allow

s

glBindTexture

bind texture object to one of the four texture targets of the active texture unit

1D

2D

3D

CUBE

GL_TEXTURE1

1D

2D

3D

CUBE

GL_TEXTUREN

1D

2D

3D

CUBE

hellip

Transfer pixel data to GPU texture memory

bull data is associated with texture object

bull glTexImage(3D|2D|1D) ndash load whole image from CPU

bull glTexSubImage(3D|2D|1D) ndash load sub image from CPU

bull glCopyTexImage(1D|2D) ndash load whole image from framebuffer

bull glCopyTexSubImage(1D|2D|3D) ndash load sub-image from framebuffer

bull MIPMAP and compression supported

Texture Object - glTexParameter

bull wrapping behavior ndash repeat clamp mirror

bull minification ndash GL_NEARESTGL_LINEAR

xxx_MIPMAP_xxx

bull magnification ndash GL_NEARESTGL_LINEAR

bull border color ndash when using clamped wrapping

bull priority

bull level-of-detail control for MIPMAP

bull hellip

Texture Unit - glTexEnv

bull many options for how texel is combined with framebuffer pixel colorndash blendingndash replacementndash decalndash addingndash enable point sprites

hellip

Other Texture issues

bull multi-texturingndash texture units work seriallyndash glMultiTexCoord vs glTexCoord

bull glTexGen ndash generate texcoordrsquos from vertex coordinatesndash define function that computes tex coord

Vertex Buffer Objects - Preliminaries

bull builds off of client side vertex arrays1 glEnableClientState(GLenum array)

array from GL_VERTEX_ARRAY GL_COLOR_ARRAY GL_NORMAL_ARRAY etc

2 glVertexPointer(int size enum type sizei stride void pointer)size = 234 type = GL_FLOATGL_INT etc

3 glDrawArrays(GLenum mode GLint first GLsizei count) helliporhellip glDrawElements(GLenum mode GLsizei count GLenum

type void indices) index helliporhellip

glBegin(GL_TRIANGLE) glArrayElement(2) index hellip

Vertex Buffer Objects ndash Create and Initialize

bull VBOrsquos instead of lsquopointerrsquo pointing to CPU memory itrsquos treated as a offset to a vertex buffer in GPU memory

bull glGenBuffers(GLsizei n GLuint buffers) create namebull glBindBuffer(GLenum target GLuint buffer) create buffer

target=GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER

bull glBufferData(GLenum target GLsizeiptr size const GLvoid data GLenum usage) copy data to buffer

size = elements size of elementdata = pointer to CPU memory or NULL (no initialize)usage = GL_(STREAM|STATIC|DYNAMIC)_(DRAW|READ|COPY)

usage is a performance hint

Vertex Buffer Objects - usage

bull _DRAW - data used as vertex data for renderingbull _READ ndash data read from an OGL buffer (such as

framebuffer) and used in application for computations not immediately related to rendering (OGL ge 21)

bull _COPY ndash data values are read from OGL buffer and then used as vertex data for rendering (OGL ge 21)

bull _STREAM_ - frequent updates to buffer but only used a few times in drawing or other operations (updatedraw asymp 11)

bull _STATIC_ - set data once and use many times (updatedraw = 1N)

bull _DYNAMIC_ - you may update buffer often and use it many times as well (updatedraw = NN)

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 24: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Per-Fragment Operations - II

bull blending ndash color stored in pixel is blend of fragment color and original pixel color and blend state (glBlendFunc glBlendColor glBlendEquation)

bull logical operations ndashbitwise boolean operations (glLogicOp)

bull dithering - old

Frame Buffer Operations

bull which buffer(s) are written too GL_FRONT GL_FRONT_LEFTGL_AUX0 etc (glDrawBuffer glDrawBuffers)

bull write protection ndash which bitsbytes are affected (glColorMask glDepthMask glStencilMask)

bull clear framebuffer ndash glClear glClearColor glClearDepth glClearStencil glClearAccum

bull glFlush ndash make sure all primitives are progressing toward completion (noone waiting around in queue)

bull glFinish ndash block () until all pending GL calls have executed

Graphics Workstation

DisplayProcessor Display

ProcessorMemory

FramebufferVideo

Controller

PeripheralDevices

CPU SystemMemory

System Bus

Nvidia 8800 Ultra Peak 103GBs

PCIExpress Input 4GBs

Bandwidth Discrepancy Demands Data on Graphics Card

bull Since transfer from CPU to GPU is much slower than GPU to graphics memory we have

ndash texture objects (OGL ge 11)ndash vertex buffer objects (OGL ge 15)ndash pixel buffer objects (OGL ge 21)ndash display lists (OGL ge 10)

Texture Sampling

bull Fragment Processor gets interpolated texture coordinates from Rasterize unit and does a texel lookup from some of the texture units (GL_MAX_TEXTURE_UNITS)

bull Each texture unit is a piece of GPU hardware () and hasndash Enabledisabled statendash Texture matrix stackndash state for automatic generation of texture coordinatesndash Texture environment statendash Current 1D 2D 3D and cube map texture

GL_TEXTUREi

1D

2D

3D

CUBE

Texture Unit rarr glBindTexturelarrTexture Object

GL_TEXTURE0

hellip

GL_ACTIVE_TEXTURE

glActiveTexture

Texture UnitsTexture Objects

GLuint=1

GLuint=2

GLuint=3

GLuint=N

GL_

MA

X_T

EX

TU

RE

_UN

ITS

hellip

as many as m

emory allow

s

glBindTexture

bind texture object to one of the four texture targets of the active texture unit

1D

2D

3D

CUBE

GL_TEXTURE1

1D

2D

3D

CUBE

GL_TEXTUREN

1D

2D

3D

CUBE

hellip

Transfer pixel data to GPU texture memory

bull data is associated with texture object

bull glTexImage(3D|2D|1D) ndash load whole image from CPU

bull glTexSubImage(3D|2D|1D) ndash load sub image from CPU

bull glCopyTexImage(1D|2D) ndash load whole image from framebuffer

bull glCopyTexSubImage(1D|2D|3D) ndash load sub-image from framebuffer

bull MIPMAP and compression supported

Texture Object - glTexParameter

bull wrapping behavior ndash repeat clamp mirror

bull minification ndash GL_NEARESTGL_LINEAR

xxx_MIPMAP_xxx

bull magnification ndash GL_NEARESTGL_LINEAR

bull border color ndash when using clamped wrapping

bull priority

bull level-of-detail control for MIPMAP

bull hellip

Texture Unit - glTexEnv

bull many options for how texel is combined with framebuffer pixel colorndash blendingndash replacementndash decalndash addingndash enable point sprites

hellip

Other Texture issues

bull multi-texturingndash texture units work seriallyndash glMultiTexCoord vs glTexCoord

bull glTexGen ndash generate texcoordrsquos from vertex coordinatesndash define function that computes tex coord

Vertex Buffer Objects - Preliminaries

bull builds off of client side vertex arrays1 glEnableClientState(GLenum array)

array from GL_VERTEX_ARRAY GL_COLOR_ARRAY GL_NORMAL_ARRAY etc

2 glVertexPointer(int size enum type sizei stride void pointer)size = 234 type = GL_FLOATGL_INT etc

3 glDrawArrays(GLenum mode GLint first GLsizei count) helliporhellip glDrawElements(GLenum mode GLsizei count GLenum

type void indices) index helliporhellip

glBegin(GL_TRIANGLE) glArrayElement(2) index hellip

Vertex Buffer Objects ndash Create and Initialize

bull VBOrsquos instead of lsquopointerrsquo pointing to CPU memory itrsquos treated as a offset to a vertex buffer in GPU memory

bull glGenBuffers(GLsizei n GLuint buffers) create namebull glBindBuffer(GLenum target GLuint buffer) create buffer

target=GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER

bull glBufferData(GLenum target GLsizeiptr size const GLvoid data GLenum usage) copy data to buffer

size = elements size of elementdata = pointer to CPU memory or NULL (no initialize)usage = GL_(STREAM|STATIC|DYNAMIC)_(DRAW|READ|COPY)

usage is a performance hint

Vertex Buffer Objects - usage

bull _DRAW - data used as vertex data for renderingbull _READ ndash data read from an OGL buffer (such as

framebuffer) and used in application for computations not immediately related to rendering (OGL ge 21)

bull _COPY ndash data values are read from OGL buffer and then used as vertex data for rendering (OGL ge 21)

bull _STREAM_ - frequent updates to buffer but only used a few times in drawing or other operations (updatedraw asymp 11)

bull _STATIC_ - set data once and use many times (updatedraw = 1N)

bull _DYNAMIC_ - you may update buffer often and use it many times as well (updatedraw = NN)

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 25: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Frame Buffer Operations

bull which buffer(s) are written too GL_FRONT GL_FRONT_LEFTGL_AUX0 etc (glDrawBuffer glDrawBuffers)

bull write protection ndash which bitsbytes are affected (glColorMask glDepthMask glStencilMask)

bull clear framebuffer ndash glClear glClearColor glClearDepth glClearStencil glClearAccum

bull glFlush ndash make sure all primitives are progressing toward completion (noone waiting around in queue)

bull glFinish ndash block () until all pending GL calls have executed

Graphics Workstation

DisplayProcessor Display

ProcessorMemory

FramebufferVideo

Controller

PeripheralDevices

CPU SystemMemory

System Bus

Nvidia 8800 Ultra Peak 103GBs

PCIExpress Input 4GBs

Bandwidth Discrepancy Demands Data on Graphics Card

bull Since transfer from CPU to GPU is much slower than GPU to graphics memory we have

ndash texture objects (OGL ge 11)ndash vertex buffer objects (OGL ge 15)ndash pixel buffer objects (OGL ge 21)ndash display lists (OGL ge 10)

Texture Sampling

bull Fragment Processor gets interpolated texture coordinates from Rasterize unit and does a texel lookup from some of the texture units (GL_MAX_TEXTURE_UNITS)

bull Each texture unit is a piece of GPU hardware () and hasndash Enabledisabled statendash Texture matrix stackndash state for automatic generation of texture coordinatesndash Texture environment statendash Current 1D 2D 3D and cube map texture

GL_TEXTUREi

1D

2D

3D

CUBE

Texture Unit rarr glBindTexturelarrTexture Object

GL_TEXTURE0

hellip

GL_ACTIVE_TEXTURE

glActiveTexture

Texture UnitsTexture Objects

GLuint=1

GLuint=2

GLuint=3

GLuint=N

GL_

MA

X_T

EX

TU

RE

_UN

ITS

hellip

as many as m

emory allow

s

glBindTexture

bind texture object to one of the four texture targets of the active texture unit

1D

2D

3D

CUBE

GL_TEXTURE1

1D

2D

3D

CUBE

GL_TEXTUREN

1D

2D

3D

CUBE

hellip

Transfer pixel data to GPU texture memory

bull data is associated with texture object

bull glTexImage(3D|2D|1D) ndash load whole image from CPU

bull glTexSubImage(3D|2D|1D) ndash load sub image from CPU

bull glCopyTexImage(1D|2D) ndash load whole image from framebuffer

bull glCopyTexSubImage(1D|2D|3D) ndash load sub-image from framebuffer

bull MIPMAP and compression supported

Texture Object - glTexParameter

bull wrapping behavior ndash repeat clamp mirror

bull minification ndash GL_NEARESTGL_LINEAR

xxx_MIPMAP_xxx

bull magnification ndash GL_NEARESTGL_LINEAR

bull border color ndash when using clamped wrapping

bull priority

bull level-of-detail control for MIPMAP

bull hellip

Texture Unit - glTexEnv

bull many options for how texel is combined with framebuffer pixel colorndash blendingndash replacementndash decalndash addingndash enable point sprites

hellip

Other Texture issues

bull multi-texturingndash texture units work seriallyndash glMultiTexCoord vs glTexCoord

bull glTexGen ndash generate texcoordrsquos from vertex coordinatesndash define function that computes tex coord

Vertex Buffer Objects - Preliminaries

bull builds off of client side vertex arrays1 glEnableClientState(GLenum array)

array from GL_VERTEX_ARRAY GL_COLOR_ARRAY GL_NORMAL_ARRAY etc

2 glVertexPointer(int size enum type sizei stride void pointer)size = 234 type = GL_FLOATGL_INT etc

3 glDrawArrays(GLenum mode GLint first GLsizei count) helliporhellip glDrawElements(GLenum mode GLsizei count GLenum

type void indices) index helliporhellip

glBegin(GL_TRIANGLE) glArrayElement(2) index hellip

Vertex Buffer Objects ndash Create and Initialize

bull VBOrsquos instead of lsquopointerrsquo pointing to CPU memory itrsquos treated as a offset to a vertex buffer in GPU memory

bull glGenBuffers(GLsizei n GLuint buffers) create namebull glBindBuffer(GLenum target GLuint buffer) create buffer

target=GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER

bull glBufferData(GLenum target GLsizeiptr size const GLvoid data GLenum usage) copy data to buffer

size = elements size of elementdata = pointer to CPU memory or NULL (no initialize)usage = GL_(STREAM|STATIC|DYNAMIC)_(DRAW|READ|COPY)

usage is a performance hint

Vertex Buffer Objects - usage

bull _DRAW - data used as vertex data for renderingbull _READ ndash data read from an OGL buffer (such as

framebuffer) and used in application for computations not immediately related to rendering (OGL ge 21)

bull _COPY ndash data values are read from OGL buffer and then used as vertex data for rendering (OGL ge 21)

bull _STREAM_ - frequent updates to buffer but only used a few times in drawing or other operations (updatedraw asymp 11)

bull _STATIC_ - set data once and use many times (updatedraw = 1N)

bull _DYNAMIC_ - you may update buffer often and use it many times as well (updatedraw = NN)

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 26: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Graphics Workstation

DisplayProcessor Display

ProcessorMemory

FramebufferVideo

Controller

PeripheralDevices

CPU SystemMemory

System Bus

Nvidia 8800 Ultra Peak 103GBs

PCIExpress Input 4GBs

Bandwidth Discrepancy Demands Data on Graphics Card

bull Since transfer from CPU to GPU is much slower than GPU to graphics memory we have

ndash texture objects (OGL ge 11)ndash vertex buffer objects (OGL ge 15)ndash pixel buffer objects (OGL ge 21)ndash display lists (OGL ge 10)

Texture Sampling

bull Fragment Processor gets interpolated texture coordinates from Rasterize unit and does a texel lookup from some of the texture units (GL_MAX_TEXTURE_UNITS)

bull Each texture unit is a piece of GPU hardware () and hasndash Enabledisabled statendash Texture matrix stackndash state for automatic generation of texture coordinatesndash Texture environment statendash Current 1D 2D 3D and cube map texture

GL_TEXTUREi

1D

2D

3D

CUBE

Texture Unit rarr glBindTexturelarrTexture Object

GL_TEXTURE0

hellip

GL_ACTIVE_TEXTURE

glActiveTexture

Texture UnitsTexture Objects

GLuint=1

GLuint=2

GLuint=3

GLuint=N

GL_

MA

X_T

EX

TU

RE

_UN

ITS

hellip

as many as m

emory allow

s

glBindTexture

bind texture object to one of the four texture targets of the active texture unit

1D

2D

3D

CUBE

GL_TEXTURE1

1D

2D

3D

CUBE

GL_TEXTUREN

1D

2D

3D

CUBE

hellip

Transfer pixel data to GPU texture memory

bull data is associated with texture object

bull glTexImage(3D|2D|1D) ndash load whole image from CPU

bull glTexSubImage(3D|2D|1D) ndash load sub image from CPU

bull glCopyTexImage(1D|2D) ndash load whole image from framebuffer

bull glCopyTexSubImage(1D|2D|3D) ndash load sub-image from framebuffer

bull MIPMAP and compression supported

Texture Object - glTexParameter

bull wrapping behavior ndash repeat clamp mirror

bull minification ndash GL_NEARESTGL_LINEAR

xxx_MIPMAP_xxx

bull magnification ndash GL_NEARESTGL_LINEAR

bull border color ndash when using clamped wrapping

bull priority

bull level-of-detail control for MIPMAP

bull hellip

Texture Unit - glTexEnv

bull many options for how texel is combined with framebuffer pixel colorndash blendingndash replacementndash decalndash addingndash enable point sprites

hellip

Other Texture issues

bull multi-texturingndash texture units work seriallyndash glMultiTexCoord vs glTexCoord

bull glTexGen ndash generate texcoordrsquos from vertex coordinatesndash define function that computes tex coord

Vertex Buffer Objects - Preliminaries

bull builds off of client side vertex arrays1 glEnableClientState(GLenum array)

array from GL_VERTEX_ARRAY GL_COLOR_ARRAY GL_NORMAL_ARRAY etc

2 glVertexPointer(int size enum type sizei stride void pointer)size = 234 type = GL_FLOATGL_INT etc

3 glDrawArrays(GLenum mode GLint first GLsizei count) helliporhellip glDrawElements(GLenum mode GLsizei count GLenum

type void indices) index helliporhellip

glBegin(GL_TRIANGLE) glArrayElement(2) index hellip

Vertex Buffer Objects ndash Create and Initialize

bull VBOrsquos instead of lsquopointerrsquo pointing to CPU memory itrsquos treated as a offset to a vertex buffer in GPU memory

bull glGenBuffers(GLsizei n GLuint buffers) create namebull glBindBuffer(GLenum target GLuint buffer) create buffer

target=GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER

bull glBufferData(GLenum target GLsizeiptr size const GLvoid data GLenum usage) copy data to buffer

size = elements size of elementdata = pointer to CPU memory or NULL (no initialize)usage = GL_(STREAM|STATIC|DYNAMIC)_(DRAW|READ|COPY)

usage is a performance hint

Vertex Buffer Objects - usage

bull _DRAW - data used as vertex data for renderingbull _READ ndash data read from an OGL buffer (such as

framebuffer) and used in application for computations not immediately related to rendering (OGL ge 21)

bull _COPY ndash data values are read from OGL buffer and then used as vertex data for rendering (OGL ge 21)

bull _STREAM_ - frequent updates to buffer but only used a few times in drawing or other operations (updatedraw asymp 11)

bull _STATIC_ - set data once and use many times (updatedraw = 1N)

bull _DYNAMIC_ - you may update buffer often and use it many times as well (updatedraw = NN)

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 27: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Bandwidth Discrepancy Demands Data on Graphics Card

bull Since transfer from CPU to GPU is much slower than GPU to graphics memory we have

ndash texture objects (OGL ge 11)ndash vertex buffer objects (OGL ge 15)ndash pixel buffer objects (OGL ge 21)ndash display lists (OGL ge 10)

Texture Sampling

bull Fragment Processor gets interpolated texture coordinates from Rasterize unit and does a texel lookup from some of the texture units (GL_MAX_TEXTURE_UNITS)

bull Each texture unit is a piece of GPU hardware () and hasndash Enabledisabled statendash Texture matrix stackndash state for automatic generation of texture coordinatesndash Texture environment statendash Current 1D 2D 3D and cube map texture

GL_TEXTUREi

1D

2D

3D

CUBE

Texture Unit rarr glBindTexturelarrTexture Object

GL_TEXTURE0

hellip

GL_ACTIVE_TEXTURE

glActiveTexture

Texture UnitsTexture Objects

GLuint=1

GLuint=2

GLuint=3

GLuint=N

GL_

MA

X_T

EX

TU

RE

_UN

ITS

hellip

as many as m

emory allow

s

glBindTexture

bind texture object to one of the four texture targets of the active texture unit

1D

2D

3D

CUBE

GL_TEXTURE1

1D

2D

3D

CUBE

GL_TEXTUREN

1D

2D

3D

CUBE

hellip

Transfer pixel data to GPU texture memory

bull data is associated with texture object

bull glTexImage(3D|2D|1D) ndash load whole image from CPU

bull glTexSubImage(3D|2D|1D) ndash load sub image from CPU

bull glCopyTexImage(1D|2D) ndash load whole image from framebuffer

bull glCopyTexSubImage(1D|2D|3D) ndash load sub-image from framebuffer

bull MIPMAP and compression supported

Texture Object - glTexParameter

bull wrapping behavior ndash repeat clamp mirror

bull minification ndash GL_NEARESTGL_LINEAR

xxx_MIPMAP_xxx

bull magnification ndash GL_NEARESTGL_LINEAR

bull border color ndash when using clamped wrapping

bull priority

bull level-of-detail control for MIPMAP

bull hellip

Texture Unit - glTexEnv

bull many options for how texel is combined with framebuffer pixel colorndash blendingndash replacementndash decalndash addingndash enable point sprites

hellip

Other Texture issues

bull multi-texturingndash texture units work seriallyndash glMultiTexCoord vs glTexCoord

bull glTexGen ndash generate texcoordrsquos from vertex coordinatesndash define function that computes tex coord

Vertex Buffer Objects - Preliminaries

bull builds off of client side vertex arrays1 glEnableClientState(GLenum array)

array from GL_VERTEX_ARRAY GL_COLOR_ARRAY GL_NORMAL_ARRAY etc

2 glVertexPointer(int size enum type sizei stride void pointer)size = 234 type = GL_FLOATGL_INT etc

3 glDrawArrays(GLenum mode GLint first GLsizei count) helliporhellip glDrawElements(GLenum mode GLsizei count GLenum

type void indices) index helliporhellip

glBegin(GL_TRIANGLE) glArrayElement(2) index hellip

Vertex Buffer Objects ndash Create and Initialize

bull VBOrsquos instead of lsquopointerrsquo pointing to CPU memory itrsquos treated as a offset to a vertex buffer in GPU memory

bull glGenBuffers(GLsizei n GLuint buffers) create namebull glBindBuffer(GLenum target GLuint buffer) create buffer

target=GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER

bull glBufferData(GLenum target GLsizeiptr size const GLvoid data GLenum usage) copy data to buffer

size = elements size of elementdata = pointer to CPU memory or NULL (no initialize)usage = GL_(STREAM|STATIC|DYNAMIC)_(DRAW|READ|COPY)

usage is a performance hint

Vertex Buffer Objects - usage

bull _DRAW - data used as vertex data for renderingbull _READ ndash data read from an OGL buffer (such as

framebuffer) and used in application for computations not immediately related to rendering (OGL ge 21)

bull _COPY ndash data values are read from OGL buffer and then used as vertex data for rendering (OGL ge 21)

bull _STREAM_ - frequent updates to buffer but only used a few times in drawing or other operations (updatedraw asymp 11)

bull _STATIC_ - set data once and use many times (updatedraw = 1N)

bull _DYNAMIC_ - you may update buffer often and use it many times as well (updatedraw = NN)

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 28: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Texture Sampling

bull Fragment Processor gets interpolated texture coordinates from Rasterize unit and does a texel lookup from some of the texture units (GL_MAX_TEXTURE_UNITS)

bull Each texture unit is a piece of GPU hardware () and hasndash Enabledisabled statendash Texture matrix stackndash state for automatic generation of texture coordinatesndash Texture environment statendash Current 1D 2D 3D and cube map texture

GL_TEXTUREi

1D

2D

3D

CUBE

Texture Unit rarr glBindTexturelarrTexture Object

GL_TEXTURE0

hellip

GL_ACTIVE_TEXTURE

glActiveTexture

Texture UnitsTexture Objects

GLuint=1

GLuint=2

GLuint=3

GLuint=N

GL_

MA

X_T

EX

TU

RE

_UN

ITS

hellip

as many as m

emory allow

s

glBindTexture

bind texture object to one of the four texture targets of the active texture unit

1D

2D

3D

CUBE

GL_TEXTURE1

1D

2D

3D

CUBE

GL_TEXTUREN

1D

2D

3D

CUBE

hellip

Transfer pixel data to GPU texture memory

bull data is associated with texture object

bull glTexImage(3D|2D|1D) ndash load whole image from CPU

bull glTexSubImage(3D|2D|1D) ndash load sub image from CPU

bull glCopyTexImage(1D|2D) ndash load whole image from framebuffer

bull glCopyTexSubImage(1D|2D|3D) ndash load sub-image from framebuffer

bull MIPMAP and compression supported

Texture Object - glTexParameter

bull wrapping behavior ndash repeat clamp mirror

bull minification ndash GL_NEARESTGL_LINEAR

xxx_MIPMAP_xxx

bull magnification ndash GL_NEARESTGL_LINEAR

bull border color ndash when using clamped wrapping

bull priority

bull level-of-detail control for MIPMAP

bull hellip

Texture Unit - glTexEnv

bull many options for how texel is combined with framebuffer pixel colorndash blendingndash replacementndash decalndash addingndash enable point sprites

hellip

Other Texture issues

bull multi-texturingndash texture units work seriallyndash glMultiTexCoord vs glTexCoord

bull glTexGen ndash generate texcoordrsquos from vertex coordinatesndash define function that computes tex coord

Vertex Buffer Objects - Preliminaries

bull builds off of client side vertex arrays1 glEnableClientState(GLenum array)

array from GL_VERTEX_ARRAY GL_COLOR_ARRAY GL_NORMAL_ARRAY etc

2 glVertexPointer(int size enum type sizei stride void pointer)size = 234 type = GL_FLOATGL_INT etc

3 glDrawArrays(GLenum mode GLint first GLsizei count) helliporhellip glDrawElements(GLenum mode GLsizei count GLenum

type void indices) index helliporhellip

glBegin(GL_TRIANGLE) glArrayElement(2) index hellip

Vertex Buffer Objects ndash Create and Initialize

bull VBOrsquos instead of lsquopointerrsquo pointing to CPU memory itrsquos treated as a offset to a vertex buffer in GPU memory

bull glGenBuffers(GLsizei n GLuint buffers) create namebull glBindBuffer(GLenum target GLuint buffer) create buffer

target=GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER

bull glBufferData(GLenum target GLsizeiptr size const GLvoid data GLenum usage) copy data to buffer

size = elements size of elementdata = pointer to CPU memory or NULL (no initialize)usage = GL_(STREAM|STATIC|DYNAMIC)_(DRAW|READ|COPY)

usage is a performance hint

Vertex Buffer Objects - usage

bull _DRAW - data used as vertex data for renderingbull _READ ndash data read from an OGL buffer (such as

framebuffer) and used in application for computations not immediately related to rendering (OGL ge 21)

bull _COPY ndash data values are read from OGL buffer and then used as vertex data for rendering (OGL ge 21)

bull _STREAM_ - frequent updates to buffer but only used a few times in drawing or other operations (updatedraw asymp 11)

bull _STATIC_ - set data once and use many times (updatedraw = 1N)

bull _DYNAMIC_ - you may update buffer often and use it many times as well (updatedraw = NN)

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 29: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Texture Unit rarr glBindTexturelarrTexture Object

GL_TEXTURE0

hellip

GL_ACTIVE_TEXTURE

glActiveTexture

Texture UnitsTexture Objects

GLuint=1

GLuint=2

GLuint=3

GLuint=N

GL_

MA

X_T

EX

TU

RE

_UN

ITS

hellip

as many as m

emory allow

s

glBindTexture

bind texture object to one of the four texture targets of the active texture unit

1D

2D

3D

CUBE

GL_TEXTURE1

1D

2D

3D

CUBE

GL_TEXTUREN

1D

2D

3D

CUBE

hellip

Transfer pixel data to GPU texture memory

bull data is associated with texture object

bull glTexImage(3D|2D|1D) ndash load whole image from CPU

bull glTexSubImage(3D|2D|1D) ndash load sub image from CPU

bull glCopyTexImage(1D|2D) ndash load whole image from framebuffer

bull glCopyTexSubImage(1D|2D|3D) ndash load sub-image from framebuffer

bull MIPMAP and compression supported

Texture Object - glTexParameter

bull wrapping behavior ndash repeat clamp mirror

bull minification ndash GL_NEARESTGL_LINEAR

xxx_MIPMAP_xxx

bull magnification ndash GL_NEARESTGL_LINEAR

bull border color ndash when using clamped wrapping

bull priority

bull level-of-detail control for MIPMAP

bull hellip

Texture Unit - glTexEnv

bull many options for how texel is combined with framebuffer pixel colorndash blendingndash replacementndash decalndash addingndash enable point sprites

hellip

Other Texture issues

bull multi-texturingndash texture units work seriallyndash glMultiTexCoord vs glTexCoord

bull glTexGen ndash generate texcoordrsquos from vertex coordinatesndash define function that computes tex coord

Vertex Buffer Objects - Preliminaries

bull builds off of client side vertex arrays1 glEnableClientState(GLenum array)

array from GL_VERTEX_ARRAY GL_COLOR_ARRAY GL_NORMAL_ARRAY etc

2 glVertexPointer(int size enum type sizei stride void pointer)size = 234 type = GL_FLOATGL_INT etc

3 glDrawArrays(GLenum mode GLint first GLsizei count) helliporhellip glDrawElements(GLenum mode GLsizei count GLenum

type void indices) index helliporhellip

glBegin(GL_TRIANGLE) glArrayElement(2) index hellip

Vertex Buffer Objects ndash Create and Initialize

bull VBOrsquos instead of lsquopointerrsquo pointing to CPU memory itrsquos treated as a offset to a vertex buffer in GPU memory

bull glGenBuffers(GLsizei n GLuint buffers) create namebull glBindBuffer(GLenum target GLuint buffer) create buffer

target=GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER

bull glBufferData(GLenum target GLsizeiptr size const GLvoid data GLenum usage) copy data to buffer

size = elements size of elementdata = pointer to CPU memory or NULL (no initialize)usage = GL_(STREAM|STATIC|DYNAMIC)_(DRAW|READ|COPY)

usage is a performance hint

Vertex Buffer Objects - usage

bull _DRAW - data used as vertex data for renderingbull _READ ndash data read from an OGL buffer (such as

framebuffer) and used in application for computations not immediately related to rendering (OGL ge 21)

bull _COPY ndash data values are read from OGL buffer and then used as vertex data for rendering (OGL ge 21)

bull _STREAM_ - frequent updates to buffer but only used a few times in drawing or other operations (updatedraw asymp 11)

bull _STATIC_ - set data once and use many times (updatedraw = 1N)

bull _DYNAMIC_ - you may update buffer often and use it many times as well (updatedraw = NN)

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 30: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Transfer pixel data to GPU texture memory

bull data is associated with texture object

bull glTexImage(3D|2D|1D) ndash load whole image from CPU

bull glTexSubImage(3D|2D|1D) ndash load sub image from CPU

bull glCopyTexImage(1D|2D) ndash load whole image from framebuffer

bull glCopyTexSubImage(1D|2D|3D) ndash load sub-image from framebuffer

bull MIPMAP and compression supported

Texture Object - glTexParameter

bull wrapping behavior ndash repeat clamp mirror

bull minification ndash GL_NEARESTGL_LINEAR

xxx_MIPMAP_xxx

bull magnification ndash GL_NEARESTGL_LINEAR

bull border color ndash when using clamped wrapping

bull priority

bull level-of-detail control for MIPMAP

bull hellip

Texture Unit - glTexEnv

bull many options for how texel is combined with framebuffer pixel colorndash blendingndash replacementndash decalndash addingndash enable point sprites

hellip

Other Texture issues

bull multi-texturingndash texture units work seriallyndash glMultiTexCoord vs glTexCoord

bull glTexGen ndash generate texcoordrsquos from vertex coordinatesndash define function that computes tex coord

Vertex Buffer Objects - Preliminaries

bull builds off of client side vertex arrays1 glEnableClientState(GLenum array)

array from GL_VERTEX_ARRAY GL_COLOR_ARRAY GL_NORMAL_ARRAY etc

2 glVertexPointer(int size enum type sizei stride void pointer)size = 234 type = GL_FLOATGL_INT etc

3 glDrawArrays(GLenum mode GLint first GLsizei count) helliporhellip glDrawElements(GLenum mode GLsizei count GLenum

type void indices) index helliporhellip

glBegin(GL_TRIANGLE) glArrayElement(2) index hellip

Vertex Buffer Objects ndash Create and Initialize

bull VBOrsquos instead of lsquopointerrsquo pointing to CPU memory itrsquos treated as a offset to a vertex buffer in GPU memory

bull glGenBuffers(GLsizei n GLuint buffers) create namebull glBindBuffer(GLenum target GLuint buffer) create buffer

target=GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER

bull glBufferData(GLenum target GLsizeiptr size const GLvoid data GLenum usage) copy data to buffer

size = elements size of elementdata = pointer to CPU memory or NULL (no initialize)usage = GL_(STREAM|STATIC|DYNAMIC)_(DRAW|READ|COPY)

usage is a performance hint

Vertex Buffer Objects - usage

bull _DRAW - data used as vertex data for renderingbull _READ ndash data read from an OGL buffer (such as

framebuffer) and used in application for computations not immediately related to rendering (OGL ge 21)

bull _COPY ndash data values are read from OGL buffer and then used as vertex data for rendering (OGL ge 21)

bull _STREAM_ - frequent updates to buffer but only used a few times in drawing or other operations (updatedraw asymp 11)

bull _STATIC_ - set data once and use many times (updatedraw = 1N)

bull _DYNAMIC_ - you may update buffer often and use it many times as well (updatedraw = NN)

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 31: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Texture Object - glTexParameter

bull wrapping behavior ndash repeat clamp mirror

bull minification ndash GL_NEARESTGL_LINEAR

xxx_MIPMAP_xxx

bull magnification ndash GL_NEARESTGL_LINEAR

bull border color ndash when using clamped wrapping

bull priority

bull level-of-detail control for MIPMAP

bull hellip

Texture Unit - glTexEnv

bull many options for how texel is combined with framebuffer pixel colorndash blendingndash replacementndash decalndash addingndash enable point sprites

hellip

Other Texture issues

bull multi-texturingndash texture units work seriallyndash glMultiTexCoord vs glTexCoord

bull glTexGen ndash generate texcoordrsquos from vertex coordinatesndash define function that computes tex coord

Vertex Buffer Objects - Preliminaries

bull builds off of client side vertex arrays1 glEnableClientState(GLenum array)

array from GL_VERTEX_ARRAY GL_COLOR_ARRAY GL_NORMAL_ARRAY etc

2 glVertexPointer(int size enum type sizei stride void pointer)size = 234 type = GL_FLOATGL_INT etc

3 glDrawArrays(GLenum mode GLint first GLsizei count) helliporhellip glDrawElements(GLenum mode GLsizei count GLenum

type void indices) index helliporhellip

glBegin(GL_TRIANGLE) glArrayElement(2) index hellip

Vertex Buffer Objects ndash Create and Initialize

bull VBOrsquos instead of lsquopointerrsquo pointing to CPU memory itrsquos treated as a offset to a vertex buffer in GPU memory

bull glGenBuffers(GLsizei n GLuint buffers) create namebull glBindBuffer(GLenum target GLuint buffer) create buffer

target=GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER

bull glBufferData(GLenum target GLsizeiptr size const GLvoid data GLenum usage) copy data to buffer

size = elements size of elementdata = pointer to CPU memory or NULL (no initialize)usage = GL_(STREAM|STATIC|DYNAMIC)_(DRAW|READ|COPY)

usage is a performance hint

Vertex Buffer Objects - usage

bull _DRAW - data used as vertex data for renderingbull _READ ndash data read from an OGL buffer (such as

framebuffer) and used in application for computations not immediately related to rendering (OGL ge 21)

bull _COPY ndash data values are read from OGL buffer and then used as vertex data for rendering (OGL ge 21)

bull _STREAM_ - frequent updates to buffer but only used a few times in drawing or other operations (updatedraw asymp 11)

bull _STATIC_ - set data once and use many times (updatedraw = 1N)

bull _DYNAMIC_ - you may update buffer often and use it many times as well (updatedraw = NN)

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 32: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Texture Unit - glTexEnv

bull many options for how texel is combined with framebuffer pixel colorndash blendingndash replacementndash decalndash addingndash enable point sprites

hellip

Other Texture issues

bull multi-texturingndash texture units work seriallyndash glMultiTexCoord vs glTexCoord

bull glTexGen ndash generate texcoordrsquos from vertex coordinatesndash define function that computes tex coord

Vertex Buffer Objects - Preliminaries

bull builds off of client side vertex arrays1 glEnableClientState(GLenum array)

array from GL_VERTEX_ARRAY GL_COLOR_ARRAY GL_NORMAL_ARRAY etc

2 glVertexPointer(int size enum type sizei stride void pointer)size = 234 type = GL_FLOATGL_INT etc

3 glDrawArrays(GLenum mode GLint first GLsizei count) helliporhellip glDrawElements(GLenum mode GLsizei count GLenum

type void indices) index helliporhellip

glBegin(GL_TRIANGLE) glArrayElement(2) index hellip

Vertex Buffer Objects ndash Create and Initialize

bull VBOrsquos instead of lsquopointerrsquo pointing to CPU memory itrsquos treated as a offset to a vertex buffer in GPU memory

bull glGenBuffers(GLsizei n GLuint buffers) create namebull glBindBuffer(GLenum target GLuint buffer) create buffer

target=GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER

bull glBufferData(GLenum target GLsizeiptr size const GLvoid data GLenum usage) copy data to buffer

size = elements size of elementdata = pointer to CPU memory or NULL (no initialize)usage = GL_(STREAM|STATIC|DYNAMIC)_(DRAW|READ|COPY)

usage is a performance hint

Vertex Buffer Objects - usage

bull _DRAW - data used as vertex data for renderingbull _READ ndash data read from an OGL buffer (such as

framebuffer) and used in application for computations not immediately related to rendering (OGL ge 21)

bull _COPY ndash data values are read from OGL buffer and then used as vertex data for rendering (OGL ge 21)

bull _STREAM_ - frequent updates to buffer but only used a few times in drawing or other operations (updatedraw asymp 11)

bull _STATIC_ - set data once and use many times (updatedraw = 1N)

bull _DYNAMIC_ - you may update buffer often and use it many times as well (updatedraw = NN)

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 33: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Other Texture issues

bull multi-texturingndash texture units work seriallyndash glMultiTexCoord vs glTexCoord

bull glTexGen ndash generate texcoordrsquos from vertex coordinatesndash define function that computes tex coord

Vertex Buffer Objects - Preliminaries

bull builds off of client side vertex arrays1 glEnableClientState(GLenum array)

array from GL_VERTEX_ARRAY GL_COLOR_ARRAY GL_NORMAL_ARRAY etc

2 glVertexPointer(int size enum type sizei stride void pointer)size = 234 type = GL_FLOATGL_INT etc

3 glDrawArrays(GLenum mode GLint first GLsizei count) helliporhellip glDrawElements(GLenum mode GLsizei count GLenum

type void indices) index helliporhellip

glBegin(GL_TRIANGLE) glArrayElement(2) index hellip

Vertex Buffer Objects ndash Create and Initialize

bull VBOrsquos instead of lsquopointerrsquo pointing to CPU memory itrsquos treated as a offset to a vertex buffer in GPU memory

bull glGenBuffers(GLsizei n GLuint buffers) create namebull glBindBuffer(GLenum target GLuint buffer) create buffer

target=GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER

bull glBufferData(GLenum target GLsizeiptr size const GLvoid data GLenum usage) copy data to buffer

size = elements size of elementdata = pointer to CPU memory or NULL (no initialize)usage = GL_(STREAM|STATIC|DYNAMIC)_(DRAW|READ|COPY)

usage is a performance hint

Vertex Buffer Objects - usage

bull _DRAW - data used as vertex data for renderingbull _READ ndash data read from an OGL buffer (such as

framebuffer) and used in application for computations not immediately related to rendering (OGL ge 21)

bull _COPY ndash data values are read from OGL buffer and then used as vertex data for rendering (OGL ge 21)

bull _STREAM_ - frequent updates to buffer but only used a few times in drawing or other operations (updatedraw asymp 11)

bull _STATIC_ - set data once and use many times (updatedraw = 1N)

bull _DYNAMIC_ - you may update buffer often and use it many times as well (updatedraw = NN)

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 34: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Vertex Buffer Objects - Preliminaries

bull builds off of client side vertex arrays1 glEnableClientState(GLenum array)

array from GL_VERTEX_ARRAY GL_COLOR_ARRAY GL_NORMAL_ARRAY etc

2 glVertexPointer(int size enum type sizei stride void pointer)size = 234 type = GL_FLOATGL_INT etc

3 glDrawArrays(GLenum mode GLint first GLsizei count) helliporhellip glDrawElements(GLenum mode GLsizei count GLenum

type void indices) index helliporhellip

glBegin(GL_TRIANGLE) glArrayElement(2) index hellip

Vertex Buffer Objects ndash Create and Initialize

bull VBOrsquos instead of lsquopointerrsquo pointing to CPU memory itrsquos treated as a offset to a vertex buffer in GPU memory

bull glGenBuffers(GLsizei n GLuint buffers) create namebull glBindBuffer(GLenum target GLuint buffer) create buffer

target=GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER

bull glBufferData(GLenum target GLsizeiptr size const GLvoid data GLenum usage) copy data to buffer

size = elements size of elementdata = pointer to CPU memory or NULL (no initialize)usage = GL_(STREAM|STATIC|DYNAMIC)_(DRAW|READ|COPY)

usage is a performance hint

Vertex Buffer Objects - usage

bull _DRAW - data used as vertex data for renderingbull _READ ndash data read from an OGL buffer (such as

framebuffer) and used in application for computations not immediately related to rendering (OGL ge 21)

bull _COPY ndash data values are read from OGL buffer and then used as vertex data for rendering (OGL ge 21)

bull _STREAM_ - frequent updates to buffer but only used a few times in drawing or other operations (updatedraw asymp 11)

bull _STATIC_ - set data once and use many times (updatedraw = 1N)

bull _DYNAMIC_ - you may update buffer often and use it many times as well (updatedraw = NN)

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 35: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Vertex Buffer Objects ndash Create and Initialize

bull VBOrsquos instead of lsquopointerrsquo pointing to CPU memory itrsquos treated as a offset to a vertex buffer in GPU memory

bull glGenBuffers(GLsizei n GLuint buffers) create namebull glBindBuffer(GLenum target GLuint buffer) create buffer

target=GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER

bull glBufferData(GLenum target GLsizeiptr size const GLvoid data GLenum usage) copy data to buffer

size = elements size of elementdata = pointer to CPU memory or NULL (no initialize)usage = GL_(STREAM|STATIC|DYNAMIC)_(DRAW|READ|COPY)

usage is a performance hint

Vertex Buffer Objects - usage

bull _DRAW - data used as vertex data for renderingbull _READ ndash data read from an OGL buffer (such as

framebuffer) and used in application for computations not immediately related to rendering (OGL ge 21)

bull _COPY ndash data values are read from OGL buffer and then used as vertex data for rendering (OGL ge 21)

bull _STREAM_ - frequent updates to buffer but only used a few times in drawing or other operations (updatedraw asymp 11)

bull _STATIC_ - set data once and use many times (updatedraw = 1N)

bull _DYNAMIC_ - you may update buffer often and use it many times as well (updatedraw = NN)

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 36: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Vertex Buffer Objects - usage

bull _DRAW - data used as vertex data for renderingbull _READ ndash data read from an OGL buffer (such as

framebuffer) and used in application for computations not immediately related to rendering (OGL ge 21)

bull _COPY ndash data values are read from OGL buffer and then used as vertex data for rendering (OGL ge 21)

bull _STREAM_ - frequent updates to buffer but only used a few times in drawing or other operations (updatedraw asymp 11)

bull _STATIC_ - set data once and use many times (updatedraw = 1N)

bull _DYNAMIC_ - you may update buffer often and use it many times as well (updatedraw = NN)

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 37: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Vertex Buffer Object ndash Draw I

bull Example Draw ndash Vertex Only

assume we setup myBuffer alreadyglBindBuffer(GL_ARRAY_BUFFER myBuffer)glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3GL_FLOAT0BUFFER_OFFSET(0))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 38: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Vertex Buffer Object ndash Draw IIbull Example Draw ndash Vertex and Color [2pg87]

GLfloat vertexData[][6]= r0 g0 b0 x0 y0 z0 r1 g1 b1 x1 y1 z1 hellip

assume we setup lsquomyBufferrsquo already with colors and vertices initialized to lsquovertexDatarsquo

glBindBuffer(GL_ARRAY_BUFFER myBuffer)

glEnableClientState(GL_VERTEX_ARRAY)glEnableClientState(GL_COLOR_ARRAY)

glColorPointer(3GL_FLOAT6sizeof(float)BUFFER_OFFSET(0))glVertexPointer(3GL_FLOAT6sizeof(float) BUFFER_OFFSET(6sizeof(float)))

glDrawArrays(GL_TRIANGLES0myVertexCount)

glDisableClientState(GL_VERTEX_ARRAY)glBindBuffer(GL_ARRAY_BUFFER 0)

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 39: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

VBO Example 1

bull httpwwwsonghocaopenglgl_vbohtml

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 40: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

VBOrsquos can be updated (unlike display lists)

bull void glBufferSubData( GLenum target GLintptr offset GLsizeiptr size const GLvoid data )

target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER size = number of bytes to be updated offset = offset into VBO (in GPU mem) to make update data = data on CPU mem to copy to VBO

bull GLvoid glMapBuffer(GLenum target GLenum access) target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER access = GL_READ_ONLYGL_WRITEGL_READ_WRITE

bull GLboolean glUnmapBuffer(GLenum target)target = GL_ARRAY_BUFFERGL_ELEMENT_ARRAY_BUFFER

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 41: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Pixel Buffer Objects

bull vertex array calls normally work on CPU mem buffers but with VBOrsquos they execute on GPU mem buffers similarly normally glReadPixels glDrawPixels etc work on CPU mem buffers but PBO let them work on GPU buffers

bull void glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

bull void glTexImage2D(GLenum target hellip GLenum format GLenum type const GLvoid data)

Framebuffer

PBO

Texture Object

pack

pack

unpack

unpack

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 42: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

PBO ndash glReadPixels amp PIXEL_PACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_PACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glReadPixels(GLint x GLint y GLsizei width GLsizei height GLenum format GLenum type GLvoid data )

FramebufferPBOpack

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 43: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK

bull glGenBuffers(GLsizei n GLuint buffers) create nameglBindBuffer(GLenum target GLuint buffer) create buffer target=GL_PIXEL_UNPACK_BUFFERglBufferData(GLenum target GLsizeiptr size NULL GLenum usage) copy data to buffer

glDrawPixels(GLsizei width GLsizei height GLenum format GLenum type BUFFER_OFFSET(0))

hellip OR hellip

glTexImage1D(GLenum target GLint level GLint internalformat GLsizei width GLint border GLenum format GLenum type BUFFER_OFFSET(0))

FramebufferPBOunpack

Texture ObjectPBOunpack

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 44: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Non-PBO vs PBO

bull Without PBOs

bull With PBOs

Texture Source

RAM Texture Object

CPU Memory GPUOpenGL Memory

CPU CPU

glTex

Imag

e2D

Texture Source

PBO Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 45: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

PBO Streaming Texture

bull Streaming texture updates using glMapBufferglUnmapBuffer to write data for glTexSubImage into a buffer object at least one of the data copies usually required to download a texture can be eliminated significantly increasing download performance [1]

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 46: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

PBO Streaming Texture ndash Dual PBOs

Texture Source

PBO1

Texture Object

GPUOpenGL Memory

CPU DMA

glTex

Imag

e2D

PBO2

n+1

n

n

n+1

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 47: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

PBO Streaming Texture Example

bull httpwwwsonghocaopenglgl_pbohtmlunpack

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 48: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

PBO Asynchronous Reads

bull asynchronous reads ndash overlap reading of framebuffer data with CPU processingndash split framebuffer into pieces (1 per PBO)ndash call multiple glReadPixels but access with

glMapBufferbull glReadPixel piece 1bull glReadPixel piece 2bull glMapBuffer piece 1bull CPU process piece 1 piece 2 is being transferredbull glUnmapBuffer piece 1bull glMapBuffer piece 2

hellip

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 49: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

PBO Asynchronous Reads

PBO1

Texture Object

GPUOpenGL Memory

CPU processespixels DMA

glRea

dPixe

ls

PBO2

n+1

n

n

n+1

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 50: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

PBO Asynchronous Reads

bull httpwwwsonghocaopenglgl_pbohtmlpack

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 51: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

PBO Render to Vertex Array

bull render to vertex array The application can use a fragment program to render some image into one of its buffers then read this image out into a buffer object via glReadPixels Then it can use this buffer object as a source of vertex data [1]

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 52: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

PBO Render to Vertex Array

bull GLint bufferName glGenBuffers(1 ampbufferName)

glBindBuffer(GL_PACK_BUFFER_ARB bufferName) glBufferData(GL_PACK_BUFFER_ARB size NULL GL_DYNAMIC_COPY)RenderMyDisplacementMap()

glReadPixels( NULL) glBindBuffer(GL_ARRAY_BUFFER bufferName) glVertexAttribPointer( NULL)RenderMyDisplacedScene()

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 53: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Framebuffer Objects

bull FBO ndash extension for ldquodrawing to rendering destinations other than the buffers provided to the GL by the window-systemrdquo better than ARB_pbuffer and ARB_render_texture

ndash logical buffer ndash either the color depth or stencil buffers of the framebuffer

ndash framebuffer - collection of logical buffers where OGL rendering is directed

ndash renderbuffer - storage object containing a single 2D array of pixels that can be used as a destination for pixel data during rendering

ndash framebuffer attachable-image ndash 2D array of pixels that can be attached to FBO (either texture or renderbuffer object)

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 54: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

FBOs

FBO

Stencil

Depth

Color0Color1

ColorN

attachment points

render buffer objects

render buffer images

texture objects

texture images

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 55: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

FBO Example

initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT depth_rb)glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT GL_DEPTH_COMPONENT24 width height)

attach renderbufferto framebufferdepth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT GL_DEPTH_ATTACHMENT_EXT GL_RENDERBUFFER_EXT depth_rb)CHECK_FRAMEBUFFER_STATUS() render to the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT fb) (draw something here rendering to texture)

render to the window using the textureglBindFramebufferEXT(GL_FRAMEBUFFER_EXT 0)glBindTexture(GL_TEXTURE_2D tex)

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 56: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

END

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 57: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

References1 OGL 21 Specrsquos Chapter ARB_pixel_buffer_object [ httpwwwopenglorgregistryspecsARBpixel_buffer_objecttxt ]

2 OpenGL Programming Guide Fifth Edition

3 httphttpdownloadnvidiacomdeveloperPapers2005Fast_Texture_TransfersFast_Texture_Transferspdf

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions
Page 58: ©Zachary Wartell Review: 3D Graphics with OpenGL Revision 1.1 Copyright Zachary Wartell at University of North Carolina All Rights Reserved

Revisionsbull 11 ndash updated PBOrsquos and added FBOrsquos starting at slide 41

  • Slide 1
  • Overview
  • Notation
  • OpenGL Graphics Pipeline
  • OpenGL Transform Pipeline
  • Affine Transformations
  • Preserve Lines
  • Parallelism
  • Distance Ratios
  • Object Coordinates to Eye Coordinates
  • Perspective Collineation
  • Properties of Perspective Collineation
  • Non-dimension preserving persp collineation problem 1
  • Non-dimension preserving persp collineation problem 2
  • Perspective Collineation (Dimension Preserving)
  • Rasterization ndash Pixel Window Coordinates
  • Rasterization - zBuffer
  • Rasterization ndash Texture Coordinates
  • Rasterization Need Rational linear interpolation
  • Rational linear interpolation in Scan-Conversion
  • Rasterization Who does what
  • Rasterization GL state
  • Per-Fragment Operations - I
  • Per-Fragment Operations - II
  • Frame Buffer Operations
  • Graphics Workstation
  • Bandwidth Discrepancy Demands Data on Graphics Card
  • Texture Sampling
  • Texture Unit rarr glBindTexturelarrTexture Object
  • Transfer pixel data to GPU texture memory
  • Texture Object - glTexParameter
  • Texture Unit - glTexEnv
  • Other Texture issues
  • Vertex Buffer Objects - Preliminaries
  • Vertex Buffer Objects ndash Create and Initialize
  • Vertex Buffer Objects - usage
  • Vertex Buffer Object ndash Draw I
  • Vertex Buffer Object ndash Draw II
  • VBO Example 1
  • VBOrsquos can be updated (unlike display lists)
  • Pixel Buffer Objects
  • PBO ndash glReadPixels amp PIXEL_PACK
  • PBO ndash glDrawPixelsTexImage2D amp PIXEL_UNPACK
  • Non-PBO vs PBO
  • PBO Streaming Texture
  • PBO Streaming Texture ndash Dual PBOs
  • PBO Streaming Texture Example
  • PBO Asynchronous Reads
  • Slide 49
  • Slide 50
  • PBO Render to Vertex Array
  • Slide 52
  • Framebuffer Objects
  • FBOs
  • FBO Example
  • END
  • References
  • Revisions