00001 #include "dlcache.h"
00002
00003 #include <glt/error.h>
00004
00017 using namespace std;
00018
00020
00021 GltDisplayListCache::GltDisplayListCache(const uint32 capacity)
00022 : _capacity(capacity)
00023 {
00024 _lists.reserve(capacity);
00025 assert(capacity>0);
00026 }
00027
00028 GltDisplayListCache::~GltDisplayListCache()
00029 {
00030 clear();
00031 }
00032
00033 void
00034 GltDisplayListCache::draw(const uint32 seed)
00035 {
00036 GLuint *id = _lru.find(seed);
00037
00038 GLERROR;
00039
00040 if (id)
00041 glCallList(*id);
00042 else
00043 {
00044 GLuint list;
00045
00046 if (_lru.size()>=_capacity)
00047 list = _lru.insert(seed);
00048 else
00049 {
00050 list = glGenLists(1);
00051 _lists.push_back(list);
00052 _lru.insert(seed,list);
00053 }
00054
00055
00056
00057 glNewList(list,GL_COMPILE_AND_EXECUTE);
00058 OnDraw(seed);
00059 glEndList();
00060 }
00061
00062 GLERROR;
00063 }
00064
00065 void
00066 GltDisplayListCache::clear()
00067 {
00068 if (!_lists.size() && !_lru.size())
00069 return;
00070
00071 GLERROR;
00072
00073
00074 for (int i=0; i<_lists.size(); i++)
00075 glDeleteLists(_lists[i],1);
00076
00077 GLERROR;
00078
00079
00080 _lists.clear();
00081
00082
00083 _lru.clear();
00084 }