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

OpenGLCache.C

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr
00003  *cr            (C) Copyright 1995-2019 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.11 $      $Date: 2020/02/26 06:00:57 $
00014  *
00015  ***************************************************************************/
00021 #include <stdio.h>
00022 #include "OpenGLCache.h"
00023 
00024 OpenGLCache::OpenGLCache() {
00025   cache = NULL; // initialize the cache to be empty
00026 }
00027 
00028 OpenGLCache::~OpenGLCache() {
00029   idlink *tmp;
00030   for (idlink *cur = cache; cur; cur=tmp) {
00031     tmp = cur->next;
00032     delete cur;
00033   }
00034 }
00035 
00036 void OpenGLCache::encache(unsigned long id, GLuint tag) {
00037   cache = new idlink(id, tag, cache);
00038 }
00039 
00040 void OpenGLCache::markUnused() {
00041   for (idlink *cur = cache; cur; cur= cur->next) {
00042     cur->used = 0;
00043   }
00044 }
00045 
00046 GLuint OpenGLCache::markUsed(unsigned long id) {
00047   for (idlink *lnk = cache; lnk; lnk = lnk->next) {
00048     if (lnk->id == id) {
00049       lnk->used = 1;
00050       return lnk->gltag;
00051     }
00052   }
00053   return GLCACHE_FAIL; // return 0 for default OpenGL tag.
00054 }
00055 
00056 GLuint OpenGLCache::deleteUnused() {
00057   idlink *prev=NULL, *cur = cache;
00058   while (cur) {
00059     if (!cur->used) {
00060       GLuint tag = cur->gltag;
00061       if (prev) { // link previous to next before deleting
00062         prev->next = cur->next;
00063         delete cur;
00064       } else {    // we're deleting the head of the list
00065         idlink *tmp = cur->next;
00066         delete cur;
00067         cache = tmp;
00068       }
00069       return tag;
00070     }
00071     prev = cur;
00072     cur = cur->next;
00073   }
00074   return GLCACHE_FAIL; // failed to find any unused items
00075 }
00076 

Generated on Sat Apr 20 02:43:05 2024 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002