mae152 computer graphics for scientists and engineers fall 03 display lists

Post on 14-Jan-2016

40 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

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

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.

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.

Immediate Mode versus Display Lists

Display Listed

Immediate Mode

DisplayList

PolynomialEvaluator

Per VertexOperations &

PrimitiveAssembly

RasterizationPer Fragment

Operations

TextureMemory

CPU

PixelOperations

FrameBuffer

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

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.

A Simple Example

void init(void) {

GLuint theTorus = glGenLists(1);

glNewList(theTorus, GL_COMPILE);

torus(8, 25)

glEndList();

}

void display(void) {

glCallList(theTorus);

glFlush();

}

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

}

}

• Demo• Display List for Triangles

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

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.

Creating a Display List

• Use glNewList() and glEndList()

glNewList(listIndex, GL_COMPILE);

...

glEndList();

• Options for glNewList()– GL_COMPILE_AND_EXECUTE– GL_COMPILE

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

Executing a Display List

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

void display(void {glCallList(theTorus);

glFlush();

}

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

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

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.

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.

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

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?

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

End of Display List

top related