1 / 22

MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists

MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists. Objective. Understand how display lists can be used along with commands in immediate mode to organize your data and improve performance. Maximize performance by knowing how and when to use display lists.

tori
Download Presentation

MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists

  2. Objective • Understand how display lists can be used along with commands in immediate mode to organize your data and improve performance. • Maximize performance by knowing how and when to use display lists.

  3. What is Display List • Display list is a group of OpenGL commands that have been stored for later execution. • When a display list is invoked, the commands in it are executed in the order in which they were issued. • Immediate mode • commands are executed immediately • You can freely mix immediate mode programming and display lists.

  4. Immediate Mode Per Vertex Operations & Primitive Assembly Polynomial Evaluator DisplayList Per Fragment Operations Frame Buffer CPU Rasterization Display Listed Texture Memory Pixel Operations Immediate Mode versus Display Lists

  5. Immediate Mode vs Display Listed Rendering • Immediate Mode Graphics • Primitives are sent to pipeline and displayed right away • No memory of graphical entities • Display Listed Graphics • Primitives placed in display lists • Display lists kept on graphics server • Can be redisplayed with different state • Can be shared among OpenGL graphics contexts

  6. Why Use Display Lists? • It can reduce OpenGL command transmission • When running OpenGL programs remotely to another machine on the network. Display lists are stored in server computer. You can reduce the cost of repeatedly transmitting commands over the network. • Performance Gain in Local Running • Some graphics hardware may store display lists in dedicated memory or may store the data in an optimized form that is more compatible with the graphics hardware or software.

  7. A Simple Example void init(void) { GLuint theTorus = glGenLists(1); glNewList(theTorus, GL_COMPILE); torus(8, 25) glEndList(); } void display(void) { glCallList(theTorus); glFlush(); }

  8. A Simple Example (cont) void torus(int numc, int numt) { for(i=0; i<numc; i++) { glBegin(GL_QUAD_STRIP); for(j=0; j<=numt; j++) { for(k=1; k>=0; k--) { x = (1+.1*cos(s(twopi/umc))*cos(t*twopi/numt); y = (1+.1*cos(s(twopi/umc))*sin(t*twopi/numt); z = .1 * sin(s*twopi/numc); } } glEnd(); } }

  9. Demo • Display List for Triangles

  10. Display-List Design Philosophy • Display list can not be changed. • this is to MAXIMIZE the performance gain. • Display list stores only the final values. • does NOT store the intermediate results • Ex) glRotate*() directly stores the matrix • Ex) when the material properties are changed for each item • Ex) when dealing with textures

  11. Naming a Display List • Each display list is identified by an integer index. • To allocate one or more unused index, use glGenLists() command. • listIndex = glGenLists(n); allocates n consecutive previously unallocated display-list indices, and returns the first index.

  12. Creating a Display List • Use glNewList() and glEndList() glNewList(listIndex, GL_COMPILE); ... glEndList(); • Options for glNewList() • GL_COMPILE_AND_EXECUTE • GL_COMPILE

  13. What’s Stored in a Display List • Almost all OpenGL commands can be stored in a display list. • Only the values for expressions are stored in the list. GLfloat v[3] = {0, 0, 0}; glNewList(1, GL_COMPILE); glColor3fv(v); glEndList(); v[0] = 1.0; // no effect

  14. Executing a Display List • Use glCallList() command to execute commands in a display list. void display(void { glCallList(theTorus); glFlush(); }

  15. Display Lists and Hierarchy • Consider model of a car • Create display list for chassis • Create display list for wheel glNewList( CAR, GL_COMPILE ); glCallList( CHASSIS ); glTranslatef( … ); glCallList( WHEEL ); glTranslatef( … ); glCallList( WHEEL ); … glEndList();

  16. Hierarchical Display List • Hierarchical display list is a display list that includes other display lists in it. • Limit on the nesting = 64 glNewList(listIndex, GL_COMPILE); glCallList(frame); glTranslatef(1.0, 1.0, 0.0); glCallList(wheel); glEndList();

  17. Managing Display List Indices • Use glIsList() command to determine whether a specific index is in use. GLboolean glIsList(GLuint list) • Use glDeleteLists() command to delete a contiguous range of display lists. glDeleteLists(list, n) deletes n display lists, starting at the index specified by list.

  18. Executing Multiple Display Lists • Use glListBase() command to set base index of glCallLists() glListBase(base) • Use glCallLists() command to execute multiple display lists. glCallLists(n, type, lists) executes n display lists. See the next example.

  19. An Example void display() { glListBase(10); GL_INT lists[] = { 1, 1, 3, 5 }; glCallLists(4, GL_INT, lists); } // Executed display lists are of // index 11, 12, 15, 20

  20. Managing State Variables How to include state changes in display lists? • You can not use glGet*() in a display list. • glGetFloatv(GL_CURRENT_COLOR, &v[0]) • Instead, use glPushAttrib() command to save a group of state variables. • Use glPopAttrib() to restore the values when you’re ready for them.

  21. Managing State Variables glNewList(listIndex, GL_COMPILE); // Example code. glPushMatrix(); // Save current matrix glPushAttrib(); // Save current attribute glColor3f(1.0, 0.0, 0.0); // Attribute change glBegin(GL_POLYGON); glVertex2f(0.0, 0.0); glVertex2f(1.0, 0.0); glVertex2f(0.0, 1.0); glEnd(); glTranslatef(1.5, 0.0, 0.0); // Matrix change glPopAttrib(); // Restore attribute glPopMatrix(); // Restore matrix glEndList();

  22. End of Display List

More Related