Speeding Up Rendering After Deciding What to Draw.

Slides:



Advertisements
Similar presentations
Chapter 11. Faster Geometry Throughput Presented by Garrett Yeh.
Advertisements

1Computer Graphics Building Models John Shearer Culture Lab – space 2
Vertex Buffer Objects, Vertex Array Objects, Pixel Buffer Objects.
©Zachary Wartell, UNCC9/28/ :30 AM 1 Overview of OpenGL Revision: 1.2 Copyright Professor Zachary Wartell, University of North Carolina All Rights.
Chapter 2: Graphics Programming
CMPE 466 COMPUTER GRAPHICS
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Building Models modified by Ray Wisman Ed Angel Professor of Computer Science,
1 Building Models. 2 Objectives Introduce simple data structures for building polygonal models ­Vertex lists ­Edge lists OpenGL vertex arrays.
Graphics Pipeline.
Computer Graphics(Fall 2003) COMS 4160, Lecture 7: OpenGL 3 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
OPENGL Return of the Survival Guide. Buffers (0,0) OpenGL holds the buffers in a coordinate system such that the origin is the lower left corner.
Informationsteknologi Wednesday, November 7, 2007Computer Graphics - Class 51 Today’s class Geometric objects and transformations.
 The success of GL lead to OpenGL (1992), a platform-independent API that was  Easy to use  Close enough to the hardware to get excellent performance.
As well as colors, normals, and other vertex data PUSHIN’ GEO TO THE GPU JEFF CHASTINE 1.
Meshes Dr. Scott Schaefer. 3D Surfaces Vertex Table.
OpenGL (Graphics Library) Software Interface to graphics software Allows to create interactive programs that produce color images of moving 3D objects.
Computer Graphics Ben-Gurion University of the Negev Fall 2012.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Better Interactive Programs Ed Angel Professor of Computer Science, Electrical and Computer.
COMP Advanced Graphics Advanced Graphics: Part 2 Quick review of OpenGL Some more information about OpenGL Performance optimisation techniques generally.
OpenGL Display Lists A way to improve performance.
COMP Advanced Graphics Advanced Graphics: Performance.
OpenGL Pixel Operations, Bitmaps, Fonts and Images The Current Raster Position Current raster position: A position in window coordinates where the next.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Picking. What is picking? Selecting an object on the screen What does this require? –Get Mouse Location –Compute what objects are rendered at the position.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Basic OpenGL Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, September 10, 2003.
Using OpenGL. 2 What is OpenGL? A software interface to graphics hardware It is a Graphics Rendering API (Application Programmer’s Interface) that is.
Modeling. Geometric Models  2D and 3D objects  Triangles, quadrilaterals, polygons  Spheres, cones, boxes  Surface characteristics  Color  Texture.
 Bitmap: A bitmap is a rectangular array of 0s and 1s that serves as a drawing mask for a corresponding rectangular portion of the window.  Applications:
CSC461 Lecture 11: Interactive Programs Contents and Objectives Picking Writing modes – XOR/Copy Rubberbanding Display list.
Triangulation Introduction to Computer Graphics and Animation (Principle of Computer Graphics) Rattapoom Waranusast.
Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, Chapter 13.
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
Interactive Computer Graphics CS 418 – Spring 2015 Mesh Rendering, Transformation, Camera Viewing and Projection in OpenGL TA: Zhicheng Yan Sushma S Kini.
State Management and Drawing Geometry Objects
Computing & Information Sciences Kansas State University Lecture 20 of 42CIS 636/736: (Introduction to) Computer Graphics Lecture 21 of 42 William H. Hsu.
CS 4363/6353 OPENGL BACKGROUND. WHY IS THIS CLASS SO HARD TO TEACH? (I’LL STOP WHINING SOON) Hardware (GPUs) double in processing power ever 6 months!
1 Better Interactive Programs. 2 Objectives Learn to build more sophisticated interactive programs using ­Picking Select objects from the display Three.
Representation. Objectives Introduce concepts such as dimension and basis Introduce coordinate systems for representing vectors spaces and frames for.
Review of OpenGL Basics
Computer Graphics Bing-Yu Chen National Taiwan University.
OpenGL Shader Language Vertex and Fragment Shading Programs.
MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists.
1 3D API OPENGL ES v1.0 Owned by Silicon Graphics (SGL) Control was then transferred to Khronos Group Introduction.
Intro to OpenGL: Vertices and Drawing
UniS CS297 Graphics with Java and OpenGL State Management and Drawing Primative Geometric Objects.
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
Details of Texture Mapping Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, December 1, 2003.
OpenGL Vertex Arrays OpenGL vertex arrays store vertex properties such as coordinates, normal vectors, color values and texture coordinates. These properties.
Computer Graphics I, Fall 2010 Building Models.
OpenGL: Introduction #include main() { OpenWindow() ; glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0,
OpenGL Objects Finalised. Debugging Tip For Debugging your applications remember: glGetError(); gluErrorString(); Don’t use these in release code (the.
4. Geometric Objects and Transformations
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Texture Mapping CEng 477 Introduction to Computer Graphics.
Unit-4 Geometric Objects and Transformations- I
Pushin’ Geo to the GPU As well as colors, normals, and other vertex data Made by Jeff Chastine, Modified by Chao Mei Jeff Chastine.
Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
The Human Visual System vs The Pinhole camera
Better Interactive Programs
Building Models Ed Angel
Display Lists & Text Glenn G. Chappell
Better Interactive Programs
Isaac Gang University of Mary Hardin-Baylor
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Computer Graphics Practical Lesson 8
Geometric Objects and Transformations (I)
Mickaël Sereno Shaders Mickaël Sereno 25/04/2019 Mickaël Sereno -
OpenGL Background CS 4722.
Computer Graphics Vertex Array Object
Presentation transcript:

Speeding Up Rendering After Deciding What to Draw

We want to render our complex models at interactive frame rates. Here when we say render we mean the decision process of deciding what to render and the actual rendering. 30 fps  33 msec per frame. Need More Time

Thing that Have to be Done Visibility calculations Character animation Collision detection LOD determination Shadows Reflections … The decision process includes: All this and the actual rendering have to be done on time.

Display Lists Method One

Display Lists A display list is a convenient and efficient way to name and organize a set of OpenGL commands. glCallList( wheel_id ); modelview transformation glCallList( wheel_id ); modelview transformation glCallList( wheel_id );

Display Lists To optimize performance, an OpenGL display list is a cache of commands rather than a dynamic database. In other words, once a display list is created, it can't be modified.

What does Cache Mean? glRotate(35.0, 1.0, 0.0, 0.0): Matrix Computed by the Function Computation Result We Store This Matrix in Memory

Getting Display Lists ids GLuint glGenLists(GLsizei range); Allocates range number of contiguous, previously unallocated display-list indices. The integer returned is the index that marks the beginning of a contiguous block of empty display-list indices. void glDeleteLists(GLuint list, GLsizei range); Deletes range display lists, starting at the index specified by list.

Creating a List void glNewList (GLuint list, GLenum mode); Specifies the start of a display list. OpenGL routines that are called subsequently are stored in a display list, except for a few restricted OpenGL routines that can't be stored. Mode can be GL_COMPILE or GL_COMPILE_AND_EXECUTE. void glEndList (void); Marks the end of a display list.

Rendering Context Display Lists are rendering context sensitive. If you are working in a rendering context that is not the one that the display list was created in, it will probably not work!!!

Not Allowed Vertex Array Stuff glVertexPointer() glColorPointer() glNormalPointer() glTexCoordPointer() glEdgeFlagPointer() glIndexPointer() glInterleavedArrays() glEnableClientState() glDisableClientState() Display List Stuff glDeleteLists() glGenLists() glIsList() Selection Stuff glRenderMode() glSelectBuffer() glFeedbackBuffer() And a Few Others…

Using a Display List void glCallList (GLuint list); This routine executes the display list specified by list. The commands in the display list are executed in the order they were saved, just as if they were issued without using a display list.

Vertex Arrays Method Two

What is Vertex Array? -1 You may have noticed that OpenGL requires many function calls to render geometric primitives. glBegin( GL_XXXX ); glVertex …; … glEnd();

What is Vertex Array? -2 An additional problem is the redundant processing of vertices that are shared between adjacent polygons 6 Sides ; 8 Shared Vertices

What is Vertex Array? -3 OpenGL has vertex array routines that allow you to specify a lot of vertex- related data with just a few arrays and to access that data with equally few function calls Arranging data in vertex arrays may increase the performance of your application.

What is Vertex Array? -4 Vertex arrays are standard in version 1.1 of OpenGL but were not part of the OpenGL 1.0 specification

The Basic Idea A B C D E F G H ABCDEFGHABBCFEFGADHECHGD Vertices Stored in an Array Indices of Quads into the vertex array Vertex G

HOW-TO Three steps to use vertex array –Activate (enable) up to six arrays –Put data into the array –Draw geometry with the data Accessing individual array elements Creating a list of individual array elements Processing sequential array elements

Step 1: Enabling Arrays -1 The first step is to call glEnableClientState() with an enumerated parameter, which activates the chosen array –void glEnableClientState (GLenum array); Specifies the array to enable. Symbolic constants GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_INDEX_ARRAY, GL_NORMAL_ARRAY, GL_TEXTURE_COORD_ARRAY, and GL_EDGE_FLAG_ARRAY are acceptable parameters. –void glDisableClientState (GLenum array); Specifies the array to disable. Accepts the same symbolic constants as glEnableClientState().

Step 1: Enabling Arrays -2 For example: –If you use lighting, you may want to define a surface normal for every vertex. To use vertex arrays for that case, you activate both the surface normal and vertex coordinate arrays: glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); –Suppose that you want to turn off lighting at some point and just draw the geometry using a single color. You want to call glDisable() to turn off lighting states. Now that lighting has been deactivated, you also want to stop changing the values of the surface normal state, which is wasted effort. To do that, you call glDisableClientState(GL_NORMAL_ARRAY);

Enable / Disable void glEnableClientState (GLenum array) void glDisableClientState(GLenum array); Specifies the array to enable / disable. GL_VERTEX_ARRAY Vertices GL_COLOR_ARRAY Colors GL_INDEX_ARRAY Indexed Colors GL_NORMAL_ARRAY Normals GL_TEXTURE_COORD_ARRAY Texture Coordinates GL_EDGE_FLAG_ARRAY Edge Type

Step 2: Specifying Data -1 There are six different routines to specify arrays –one routine for each kind of array void glVertexPointer (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); Specifies where spatial coordinate data can be accessed. pointer is the memory address of the first coordinate of the first vertex in the array. type specifies the data type (GL_SHORT, GL_INT, GL_FLOAT, or GL_DOUBLE) of each coordinate in the array. size is the number of coordinates per vertex, which must be 2, 3, or 4. stride is the byte offset between consecutive vertexes. If stride is 0, the vertices are understood to be tightly packed in the array

Step 2: Specifying Data -2 –To access the other five arrays, there are five similar routines: void glColorPointer (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); void glIndexPointer (GLenum type, GLsizei stride, const GLvoid *pointer); void glNormalPointer (GLenum type, GLsizei stride, const GLvoid *pointer); void glTexCoordPointer (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); void glEdgeFlagPointer (GLsizei stride, const GLvoid *pointer);

Step 2: Specifying Data -3 Ex: Enabling and loading vertex array static GLint vertices[] = {25, 25, 100, 325, 175, 25, 175, 325, 250, 25, 325, 325}; static GLfloat colors[] = {1.0, 0.2, 0.2, 0.2, 0.2, 1.0, 0.8, 1.0, 0.2, 0.75, 0.75, 0.75, 0.35, 0.35, 0.35, 0.5, 0.5, 0.5}; glEnableClientState (GL_COLOR_ARRAY); glEnableClientState (GL_VERTEX_ARRAY); glColorPointer (3, GL_FLOAT, 0, colors); glVertexPointer (2, GL_INT, 0, vertices);

Step 2: Specifying Data -4 Stride: –With a stride of zero, each type of vertex array (RGB color, color index, vertex coordinate, and so on) must be tightly packed –The data in the array must be homogeneous; that is, the data must be all RGB color values, all vertex coordinates, or all some other data similar in some fashion –Another way is to use glInterleavedArrays()

Step 2: Specifying Data -5 –Using a stride of other than zero can be useful, especially when dealing with interleaved arrays. –Ex: 6 vertices, RGB followed by XYZ static GLfloat intertwined[] = { 1.0, 0.2, 1.0, 100.0, 100.0, 0.0, 1.0, 0.2, 0.2, 0.0, 200.0, 0.0, 1.0, 1.0, 0.2, 100.0, 300.0, 0.0, 0.2, 1.0, 0.2, 200.0, 300.0, 0.0, 0.2, 1.0, 1.0, 300.0, 200.0, 0.0, 0.2, 0.2, 1.0, 200.0, 100.0, 0.0 }; glColorPointer ( 3, GL_FLOAT, 6 * sizeof(GLfloat), intertwined ); glVertexPointer( 3, GL_FLOAT, 6 * sizeof(GLfloat), &intertwined[3] );

Step 2: Specifying Data -6 Another way by using glInterleavedArrays(); –void glInterleavedArrays (GLenum format, GLsizei stride, void *pointer); The parameter of glInterleavedArrays() is not listed here. (See Red-Book for detailed) EX: –glInterleavedArrays( GL_C3F_V3F, 0, intertwined );

Step 3: Dereferencing & Rendering -1 Until the contents of the vertex arrays are dereferenced, the arrays remain on the client side, and their contents are easily changed. In Step 3, contents of the arrays are obtained, sent down to the server, and then sent down the graphics processing pipeline for rendering.

Step 3: Dereferencing & Rendering -2 There are three ways to obtain data: –1. Dereference a Single Array Element –2. Dereference a List of Array Element –3. Dereference a Sequence of Array Element

Step 3: Dereferencing & Rendering -3 (1). Dereference a Single Array Element –void glArrayElement (GLint ith) Obtains the data of one (the ith) vertex for all currently enabled arrays. For the vertex coordinate array, the corresponding command would be glVertex [size][type] v(), where size is one of [2,3,4], and type is one of [s,i,f,d] for GLshort, GLint, GLfloat, and GLdouble respectively. Both size and type were defined by glVertexPointer(). For other enabled arrays, glArrayElement() calls glEdgeFlagv(), glTexCoord [size][type] v(), glColor [size][type] v(), glIndex [type] v(), and glNormal [type] v(). If the vertex coordinate array is enabled, the glVertex*v() routine is executed last, after the execution (if enabled) of up to five corresponding array values.

Step 3: Dereferencing & Rendering -4 – glArrayElement() is usually called between glBegin() and glEnd(). glEnableClientState (GL_COLOR_ARRAY); glEnableClientState (GL_VERTEX_ARRAY); glColorPointer (3, GL_FLOAT, 0, colors); glVertexPointer (2, GL_INT, 0, vertices); glBegin(GL_TRIANGLES); glArrayElement (2); // == glColor3fv(colors+(2*3*sizeof(GLfloat)); // glVertex3fv(vertices+(2*2*sizeof(GLint)); glArrayElement (3); // == glColor3fv(colors+(3*3*sizeof(GLfloat)); // glVertex3fv(vertices+(3*2*sizeof(GLint)); glArrayElement (5); // == glColor3fv(colors+(5*3*sizeof(GLfloat)); // glVertex3fv(vertices+(5*2*sizeof(GLint)); glEnd();

Step 3: Dereferencing & Rendering -5 (2). Dereference a List of Array Elements –void glDrawElements (GLenum mode, GLsizei count, GLenum type, void *indices); Defines a sequence of geometric primitives using count number of elements, whose indices are stored in the array indices. type must be one of GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, or GL_UNSIGNED_INT, indicating the data type of the indices array. mode specifies what kind of primitives are constructed and is one of the same values that is accepted by glBegin() ; –for example, GL_POLYGON, GL_LINE_LOOP, GL_LINES, GL_POINTS, and so on.

Step 3: Dereferencing & Rendering -6 The effect of glDrawElements() is almost the same as the command: glBegin (mode); for ( int i = 0; i < count; i++) glArrayElement( indices[ i ] ); glEnd(); EX: static GLubyte allIndices = {4, 5, 6, 7, 1, 2, 6, 5, 0, 1, 5, 4, 0, 3, 2, 1, 0, 4, 7, 3, 2, 3, 7, 6}; glDrawElements( GL_QUADS, 24, GL_UNSIGNED_BYTE, allIndices );

Step 3: Dereferencing & Rendering -7 (3). Dereference a Sequence of Array Element –void glDrawArrays (GLenum mode, GLint first, GLsizei count); Constructs a sequence of geometric primitives using array elements starting at first and ending at first+count- 1 of each enabled array. mode specifies what kinds of primitives are constructed and is one of the same values accepted by glBegin() ; –for example, GL_POLYGON, GL_LINE_LOOP, GL_LINES, GL_POINTS, and so on.

Step 3: Dereferencing & Rendering -8 The effect of glDrawArrays() is almost the same as the command sequence: glBegin (mode); for( int i = 0; i < count; i++) glArrayElement( first + I ); glEnd();

Using the Vertex Arrays void glArrayElement( ith ) void glDrawElements(mode, count, type, *indices); Defines a sequence of geometric primitives using count number of elements, whose indices are stored in the array indices. Type indicates the data type of the indices array. Mode specifies what kind of primitives are constructed void glDrawArrays(mode, first, count); Constructs a sequence of geometric primitives using array elements starting at first and ending at first+count- 1 of each enabled array.

Which One is Better? Depends on the Implementation

A Few Words About Cards Not Really OpenGL

Graphics Hardware New hardware has further capabilities for rendering … OpenGL extensions, for example VBO.

OpenGL Extensions Vertex Buffer Object is basically the same idea as the Vertex Array only it is implemented on the graphics hardware. The use is pretty much the same, the difference is that the data is stored directly on the graphics hardware.