mae152 computer graphics for scientists and engineers fall 03 display lists

22
MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists

Upload: tori

Post on 14-Jan-2016

37 views

Category:

Documents


0 download

DESCRIPTION

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. - PowerPoint PPT Presentation

TRANSCRIPT

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

MAE152

Computer Graphics for Scientists and Engineers

Fall 03

Display Lists

Page 2: 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.

Page 3: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists

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.

Page 4: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists

Immediate Mode versus Display Lists

Display Listed

Immediate Mode

DisplayList

PolynomialEvaluator

Per VertexOperations &

PrimitiveAssembly

RasterizationPer Fragment

Operations

TextureMemory

CPU

PixelOperations

FrameBuffer

Page 5: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists

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

Page 6: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists

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.

Page 7: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists

A Simple Example

void init(void) {

GLuint theTorus = glGenLists(1);

glNewList(theTorus, GL_COMPILE);

torus(8, 25)

glEndList();

}

void display(void) {

glCallList(theTorus);

glFlush();

}

Page 8: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists

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

}

}

Page 9: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists

• Demo• Display List for Triangles

Page 10: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists

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 f

or each item– Ex) when dealing with textures

Page 11: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists

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); allo

cates n consecutive previously unallocated display-list indices, and returns the first index.

Page 12: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists

Creating a Display List

• Use glNewList() and glEndList()

glNewList(listIndex, GL_COMPILE);

...

glEndList();

• Options for glNewList()– GL_COMPILE_AND_EXECUTE– GL_COMPILE

Page 13: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists

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

Page 14: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists

Executing a Display List

• Use glCallList() command to execute commands in a display list.

void display(void {glCallList(theTorus);

glFlush();

}

Page 15: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists

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

Page 16: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists

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

Page 17: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists

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.

Page 18: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists

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.

Page 19: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists

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

Page 20: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists

Managing State Variables

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

How to include state changes in display lists?

Page 21: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists

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

Page 22: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists

End of Display List