Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

OpenGLCache.C

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr
00003  *cr            (C) Copyright 1995-2011 The Board of Trustees of the
00004  *cr                        University of Illinois
00005  *cr                         All Rights Reserved
00006  *cr
00007  ***************************************************************************/
00008 /***************************************************************************
00009  * RCS INFORMATION:
00010  *
00011  *      $RCSfile: OpenGLCache.C,v $
00012  *      $Author: johns $        $Locker:  $             $State: Exp $
00013  *      $Revision: 1.8 $      $Date: 2010/12/16 04:08:25 $
00014  *
00015  ***************************************************************************
00016  * DESCRIPTION:
00017  *   Class to manage caching of OpenGL-related resources and handles
00018  ***************************************************************************/
00019 
00020 #include <stdio.h>
00021 #include "OpenGLCache.h"
00022 
00023 OpenGLCache::OpenGLCache() {
00024   cache = NULL; // initialize the cache to be empty
00025 }
00026 
00027 OpenGLCache::~OpenGLCache() {
00028   idlink *tmp;
00029   for (idlink *cur = cache; cur; cur=tmp) {
00030     tmp = cur->next;
00031     delete cur;
00032   }
00033 }
00034 
00035 void OpenGLCache::encache(unsigned long id, GLuint tag) {
00036   cache = new idlink(id, tag, cache);
00037 }
00038 
00039 void OpenGLCache::markUnused() {
00040   for (idlink *cur = cache; cur; cur= cur->next) {
00041     cur->used = 0;
00042   }
00043 }
00044 
00045 GLuint OpenGLCache::markUsed(unsigned long id) {
00046   for (idlink *lnk = cache; lnk; lnk = lnk->next) {
00047     if (lnk->id == id) {
00048       lnk->used = 1;
00049       return lnk->gltag;
00050     }
00051   }
00052   return GLCACHE_FAIL; // return 0 for default OpenGL tag.
00053 }
00054 
00055 GLuint OpenGLCache::deleteUnused() {
00056   idlink *prev=NULL, *cur = cache;
00057   while (cur) {
00058     if (!cur->used) {
00059       GLuint tag = cur->gltag;
00060       if (prev) { // link previous to next before deleting
00061         prev->next = cur->next;
00062         delete cur;
00063       } else {    // we're deleting the head of the list
00064         idlink *tmp = cur->next;
00065         delete cur;
00066         cache = tmp;
00067       }
00068       return tag;
00069     }
00070     prev = cur;
00071     cur = cur->next;
00072   }
00073   return GLCACHE_FAIL; // failed to find any unused items
00074 }
00075 

Generated on Sat May 26 01:48:14 2012 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002