Display Lists
  • Topics: 
    • Using display lists  + immediate mode to increase performance
  •  What is a display list?
    • A group of OpenGL commands which are stored for later execution 
  •  What is immediate mode?
    • OpenGL commands which are executed immediately
  • All examples up to this point have been immediate mode

  •  

     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Why use Display Lists?
  • Ideal for geometry which is rendered multiple times
    • Also good for OpenGL state changes
     (picture of a wheeled vehicle)
  •  Display lists can be a critical performance enhancement for remote OpenGL rendering 
  • Local rendering can benefit from display lists:
    • Local dedicated memory may be used on some HW implementations
    • DL data may be stored native data formats for optimized performance

     

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

 
  Example

     
  • Relevant Code:
    •  
      /* Create display list with Torus and initialize state*/ 
      static void init(void) 

        theTorus = glGenLists (1); 
        glNewList(theTorus, GL_COMPILE); 
        torus(8, 25); 
        glEndList(); 
        glShadeModel(GL_FLAT); 
        glClearColor(0.0, 0.0, 0.0, 0.0); 

      void display(void) 

        glClear(GL_COLOR_BUFFER_BIT); 
        glColor3f (1.0, 1.0, 1.0); 
        glCallList(theTorus); 
        glFlush(); 
      }


     
     

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Design Philosophy
  • Display lists are static (non-modifyable)
  • DL optimizations are not guaranteed for any particular platform
    • They will never be slower than immediate mode
  • Jumping to (executing) a display list incurs a small overhead
    • May be slower if the DL is small
  • Good candidates for display lists:
    • Matrix operations
    • Raster bitmaps and images
    • Lights, material properties and lighting models
    • Textures
    • Polygon stipple patterns
    • NOTE!  some OpenGL commands are context sensitive (glMaterial()) and should not be display listed

     
     

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Creating and Executing

     
  • glNewList() / glEndList() surround the list definition
  • The list is invoked by glCallList()
  • Note that glTranslate() is called between DL calls

  •  

     
     
     
     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Naming and Creating a Display List
  • Each display list has a unique integer index 
    • glGenLists() can generate unique index values (to avoid accidental over-writing)


    listIndex = glGenLists(1); 
    if (listIndex != 0) { 
      glNewList(listIndex,GL_COMPILE); 
      ... 
      glEndList(); 
    }
     

  •  When a display list is created it is stored with the current graphics context
    • DL's are destroyed when the context is destroyed (NOTE: check the implementation!  This may be a big deal ...)

     

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 


  What's stored in a Display List
  • Only values for expressions are stored not variable references

  •  

     
     
     

    GLfloat color_vector[3] = {0.0, 0.0, 0.0}; 
    glNewList(1, GL_COMPILE); 
    glColor3fv(color_vector); 
    glEndList();
    color_vector[0] = 1.0;

    The color of the object will always be black ...
     

  •  Not all OGL commands can be stored within a DL
    • Those which set and retrieve client state
    • If they are used in a definition, they are executed immediately

    •  

       


      Hint:  Those OGL calls which return values 
       

       

     

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Executing a Display List
  • glCallList() will execute the pre-defined DL
  • You can mix immediate-mode commands with DLs

  •  

     
     
     

  •  Display lists can be hierarchical (at least 64 levels)
    • Query with glGetIntegerv(GL_MAX_LIST_NESTING)

    • glNewList(listIndex,GL_COMPILE); glCallList(handlebars); 
      glCallList(frame); 
      glTranslatef(1.0,0.0,0.0); 
      glCallList(wheel); 
      glTranslatef(3.0,0.0,0.0); 
      glCallList(wheel); 
      glEndList();


     

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Managing DL Indices
  • glIsList(GLuint list) will return GL_TRUE if this list index exists (if you don't want to use glGenLists())
  • Delete lists with glDeleteLists(GLuint list, GLsizei range)

  •  

     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Executing Multiple Display Lists
  • Several DLs can be executed in succession
    • Place the indices in an array 
    • call glCallLists()
    • good for symbology or fonts


    void initStrokedFont(void) 

      GLuint base; 
      base = glGenLists(128); 
      glListBase(base); 
      glNewList(base+ A , GL_COMPILE); drawLetter(Adata); 
      glEndList();   glNewList(base+ E , GL_COMPILE);  
      drawLetter(Edata); glEndList(); glNewList(base+ P , GL_COMPILE);
      drawLetter(Pdata); glEndList(); glNewList(base+ R , GL_COMPILE);
      drawLetter(Rdata); glEndList(); glNewList(base+ S , GL_COMPILE);
      drawLetter(Sdata); glEndList(); glNewList(base+   , GL_COMPILE);
      /* space character */
      glTranslatef(8.0, 0.0, 0.0);
      glEndList();
    }
     
     

    void printStrokedString(GLbyte *s) 

      GLint len = strlen(s); 
      glCallLists(len, GL_BYTE, s); 
    }