imaging and raster primitives vicki shreiner. 2 jobs andrew giles andrew giles chuck fultz chuck...

34
Imaging and Raster Primitives Vicki Shreiner Vicki Shreiner

Upload: nelson-paul

Post on 31-Dec-2015

222 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph -  SIGGraph

Imaging and Raster PrimitivesImaging and Raster Primitives

Vicki ShreinerVicki Shreiner

Page 2: Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph -  SIGGraph

2

JobsJobs

• Andrew GilesAndrew Giles

• Chuck FultzChuck Fultz

• SIGGraph - SIGGraph - http://http://www.siggraph.orgwww.siggraph.org/jobs//jobs/

Page 3: Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph -  SIGGraph

3

Imaging and Raster PrimitivesImaging and Raster Primitives

• Describe OpenGL’s raster primitives: Describe OpenGL’s raster primitives: bitmaps and image rectanglesbitmaps and image rectangles

• Demonstrate how to get OpenGL to read Demonstrate how to get OpenGL to read and render pixel rectanglesand render pixel rectangles

Page 4: Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph -  SIGGraph

4

Pixel-based primitivesPixel-based primitives

• BitmapsBitmaps• 2D array of bit masks for pixels

• update pixel color based on current color

• ImagesImages• 2D array of pixel color information

• complete color information for each pixel

• OpenGL doesn’t understand image OpenGL doesn’t understand image formatsformats

Page 5: Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph -  SIGGraph

FrameBuffer

Rasterization(including

Pixel Zoom)

Per FragmentOperations

TextureMemory

Pixel-TransferOperations

(and Pixel Map)CPU

PixelStorageModes

glReadPixels(), glCopyPixels()

glBitmap(), glDrawPixels()

glCopyTex*Image();

Pixel PipelinePixel Pipeline

• Programmable pixel storageProgrammable pixel storage and transfer operations and transfer operations

CPUCPU

DLDL

Poly.Poly. Per

Vertex

PerVertex

RasterRaster

FragFrag

FBFB

PixelPixel

TextureTexture

Page 6: Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph -  SIGGraph

6

Positioning Image PrimitivesPositioning Image Primitives

glRasterPos3f( glRasterPos3f( x, y, zx, y, z ) )• raster position transformed like geometry

• discarded if raster position isoutside of viewport

• may need to fine tuneviewport for desired results

Raster Position

Page 7: Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph -  SIGGraph

7

Rendering BitmapsRendering Bitmaps

glBitmap( glBitmap( width, height, xorig, yorig, xmove, width, height, xorig, yorig, xmove, ymove, bitmapymove, bitmap ) )

• render bitmap in current colorat

• advance raster position by after rendering

yorigyxorigx

ymovexmove

width

he

igh

t

xorig

yorig

xmove

Page 8: Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph -  SIGGraph

8

Rendering Fonts using BitmapsRendering Fonts using Bitmaps

• OpenGL uses bitmaps for font renderingOpenGL uses bitmaps for font rendering• each character is stored in a display list containing

a bitmap

• window system specific routines to access system fonts

•glXUseXFont()•wglUseFontBitmaps()

Page 9: Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph -  SIGGraph

9

Rendering ImagesRendering Images

glDrawPixels( glDrawPixels( width, height, format, type, width, height, format, type, pixelspixels ) )

• render pixels with lower left ofimage at current raster position

• numerous formats and data typesfor specifying storage in memory

• best performance by using format and type that matches hardware

Page 10: Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph -  SIGGraph

10

Reading PixelsReading Pixels

glReadPixels( glReadPixels( x, y, width, height, format, x, y, width, height, format, type, pixelstype, pixels ) )

• read pixels form specified (x,y) position in framebuffer

• pixels automatically converted from framebuffer format into requested format and type

• Framebuffer pixel copyFramebuffer pixel copyglCopyPixels( glCopyPixels( x, y, width, height, typex, y, width, height, type ) )

Page 11: Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph -  SIGGraph

11

RasterPosition

glPixelZoom(1.0, -1.0);

Pixel ZoomPixel Zoom

glPixelZoom( glPixelZoom( x, yx, y ) )• expand, shrink or reflect pixels

around current raster position

• fractional zoom supported

glPixelZoom( glPixelZoom( x, yx, y ) )• expand, shrink or reflect pixels

around current raster position

• fractional zoom supported

Page 12: Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph -  SIGGraph

12

Storage and Transfer ModesStorage and Transfer Modes

• Storage modes control accessing memoryStorage modes control accessing memory• byte alignment in host memory

• extracting a subimage

• Transfer modes allow modify pixel valuesTransfer modes allow modify pixel values• scale and bias pixel component values

• replace colors using pixel maps

Page 13: Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph -  SIGGraph

Texture MappingTexture Mapping

Ed AngelEd Angel

Page 14: Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph -  SIGGraph

14

• Apply a 1D, 2D, or 3D image to geometricApply a 1D, 2D, or 3D image to geometric primitives primitives

• Uses of TexturingUses of Texturing• simulating materials

• reducing geometric complexity

• image warping

• reflections

• Apply a 1D, 2D, or 3D image to geometricApply a 1D, 2D, or 3D image to geometric primitives primitives

• Uses of TexturingUses of Texturing• simulating materials

• reducing geometric complexity

• image warping

• reflections

TextureMappingTextureMapping

CPUCPU

DLDL

Poly.Poly. Per

Vertex

PerVertex

RasterRaster

FragFrag

FBFB

PixelPixel

TextureTexture

Page 15: Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph -  SIGGraph

15

Texture MappingTexture Mapping

s

t

x

y

z

image

geometry screen

Page 16: Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph -  SIGGraph

16

Texture Mapping and the OpenGL PipelineTexture Mapping and the OpenGL Pipeline

geometry pipelinevertices

pixel pipelineimage

rasterizer

• Images and geometry flow through Images and geometry flow through separate pipelines that join at the separate pipelines that join at the rasterizerrasterizer• “complex” textures do not affect geometric

complexity

Page 17: Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph -  SIGGraph

17

Texture ExampleTexture Example

• The texture (below) is a The texture (below) is a 256 x 256 image that has been256 x 256 image that has beenmapped to a rectangularmapped to a rectangularpolygon which is viewed inpolygon which is viewed inperspectiveperspective

Page 18: Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph -  SIGGraph

18

Applying Textures IApplying Textures I

• Three stepsThree stepsspecify texture

• read or generate image

• assign to texture

assign texture coordinates to vertices

specify texture parameters

• wrapping, filtering

Page 19: Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph -  SIGGraph

19

Applying Textures II

• specify textures in texture objects

• set texture filter

• set texture function

• set texture wrap mode

• set optional perspective correction hint

• bind texture object

• enable texturing

• supply texture coordinates for vertex

• coordinates can also be generated

• specify textures in texture objects

• set texture filter

• set texture function

• set texture wrap mode

• set optional perspective correction hint

• bind texture object

• enable texturing

• supply texture coordinates for vertex

• coordinates can also be generated

Page 20: Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph -  SIGGraph

20

Texture Objects

• Like display lists for texture imagesLike display lists for texture images• one image per texture object

• may be shared by several graphics contexts

• Generate texture namesGenerate texture namesglGenTextures( n, *texIds );

Page 21: Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph -  SIGGraph

21

Texture Objects (cont.)Texture Objects (cont.)

• Create texture objects with texture data and Create texture objects with texture data and statestateglBindTexture( target, id );

• Bind textures before usingBind textures before usingglBindTexture( target, id );

Page 22: Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph -  SIGGraph

22

• Define a texture image from an array of Define a texture image from an array of texels in CPU memory texels in CPU memory

glTexImage2D( glTexImage2D( target, level, components,target, level, components, w, h, border, format, type, *texels w, h, border, format, type, *texels ); );

• dimensions of image must be powers of 2

• Texel colors are processed by pixel Texel colors are processed by pixel pipelinepipeline• pixel scales, biases and lookups can be

done

Specify TextureImageSpecify TextureImage

CPUCPU

DLDL

Poly.Poly. Per

Vertex

PerVertex

RasterRaster

FragFrag

FBFB

PixelPixel

TextureTexture

Page 23: Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph -  SIGGraph

23

Converting A Texture Image

• If dimensions of image are not power of 2If dimensions of image are not power of 2

gluScaleImage( gluScaleImage( format, w_in, h_in,format, w_in, h_in, type_in, *data_in, w_out, h_out, type_in, *data_in, w_out, h_out,

type_out, *data_out type_out, *data_out ); );

• *_in is for source image

• *_out is for destination image

• Image interpolated and filtered during Image interpolated and filtered during scalingscaling

Page 24: Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph -  SIGGraph

24

Specifying a Texture:Other Methods

• Use frame buffer as source of texture imageUse frame buffer as source of texture image• uses current buffer as source image

glCopyTexImage2D(...)glCopyTexImage2D(...)

glCopyTexImage1D(...)glCopyTexImage1D(...)

• Modify part of a defined textureModify part of a defined texture

glTexSubImage2D(...)glTexSubImage2D(...)

glTexSubImage1D(...)glTexSubImage1D(...)

• Do both with Do both with glCopyTexSubImage2D(...)glCopyTexSubImage2D(...), etc., etc.

Page 25: Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph -  SIGGraph

25

• Based on parametric texture coordinatesBased on parametric texture coordinates• glTexCoord*()glTexCoord*() specified at each vertex specified at each vertex

s

t1, 1

0, 1

0, 0 1, 0

(s, t) = (0.2, 0.8)

(0.4, 0.2)

(0.8, 0.4)

A

B C

a

bc

Texture Space Object Space

Mapping aTextureMapping aTexture

CPUCPU

DLDL

Poly.Poly. Per

Vertex

PerVertex

RasterRaster

FragFrag

FBFB

PixelPixel

TextureTexture

Page 26: Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph -  SIGGraph

26

Tutorial: TextureTutorial: Texture

Page 27: Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph -  SIGGraph

27

• Filter ModesFilter Modes• minification or magnification

• special mipmap minification filters

• Wrap ModesWrap Modes• clamping or repeating

• Texture FunctionsTexture Functions• how to mix primitive’s color with texture’s color

• blend, modulate or replace texels

Texture Application Methods

Page 28: Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph -  SIGGraph

28

Filter Modes

Texture Polygon

Magnification Minification

PolygonTexture

Example:

glTexParameteri( glTexParameteri( target, type, modetarget, type, mode ); );

Page 29: Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph -  SIGGraph

29

Mipmapped Textures

• Mipmap allows for prefiltered texture maps of Mipmap allows for prefiltered texture maps of decreasing resolutionsdecreasing resolutions

• Lessens interpolation errors for smaller textured Lessens interpolation errors for smaller textured objectsobjects

• Declare mipmap level during texture definitionDeclare mipmap level during texture definitionglTexImage*D( glTexImage*D( GL_TEXTURE_*D, level, …GL_TEXTURE_*D, level, … ) )

• GLU mipmap builder routinesGLU mipmap builder routinesgluBuild*DMipmaps( … )gluBuild*DMipmaps( … )

• OpenGL 1.2 introduces advanced LOD controlsOpenGL 1.2 introduces advanced LOD controls

Page 30: Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph -  SIGGraph

30

Wrapping Mode

• Example:Example:glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP )

glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT )

textureGL_REPEAT

wrappingGL_CLAMP

wrapping

s

t

Page 31: Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph -  SIGGraph

31

Texture Functions

• Controls how texture is appliedControls how texture is applied

glTexEnv{fi}[v]( glTexEnv{fi}[v]( GL_TEXTURE_ENV, prop, paramGL_TEXTURE_ENV, prop, param ) ) • GL_TEXTURE_ENV_MODEGL_TEXTURE_ENV_MODE modes modes

• GL_DECAL

• GL_ADD

• GL_COMBINE

• GL_MODULATE

• GL_BLEND

• GL_REPLACE

• Set blend color with Set blend color with GL_TEXTURE_ENV_COLORGL_TEXTURE_ENV_COLOR

Page 32: Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph -  SIGGraph

32

Perspective Correction Hint

• Texture coordinate and color interpolationTexture coordinate and color interpolation• either linearly in screen space

• or using depth/perspective values (slower)

• Noticeable for polygons “on edge”Noticeable for polygons “on edge”glHint(glHint( GL_PERSPECTIVE_CORRECTION_HINT, hintGL_PERSPECTIVE_CORRECTION_HINT, hint ))where hint is one of

•GL_DONT_CARE•GL_NICEST•GL_FASTEST

Page 33: Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph -  SIGGraph

33

Is There Room for a Texture?

• Query largest dimension of texture imageQuery largest dimension of texture image• typically largest square texture

• doesn’t consider internal format size

glGetIntegerv(glGetIntegerv( GL_MAX_TEXTURE_SIZE, &size GL_MAX_TEXTURE_SIZE, &size ))

• Texture proxyTexture proxy• will memory accommodate requested texture size?

• no image specified; placeholder

• if texture won’t fit, texture state variables set to 0• doesn’t know about other textures• only considers whether this one texture will fit all of memory

Page 34: Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph -  SIGGraph

34

Texture Residency

• Working set of texturesWorking set of textures• high-performance, usually hardware accelerated

• textures must be in texture objects

• a texture in the working set is resident

• for residency of current texture, check GL_TEXTURE_RESIDENT state

• If too many textures, not all are residentIf too many textures, not all are resident• can set priority to have some kicked out first

• establish 0.0 to 1.0 priorities for texture objects