/indra/newview/VertexCache.h
C++ Header | 105 lines | 56 code | 23 blank | 26 comment | 6 complexity | 5d769cd6852fe7ed8e3b946104dd6e43 MD5 | raw file
Possible License(s): LGPL-2.1
1/** 2 * @file VertexCache.h 3 * @brief VertexCache class definition 4 * 5 * $LicenseInfo:firstyear=2002&license=viewerlgpl$ 6 * Second Life Viewer Source Code 7 * Copyright (C) 2010, Linden Research, Inc. 8 * 9 * This library is free software; you can redistribute it and/or 10 * modify it under the terms of the GNU Lesser General Public 11 * License as published by the Free Software Foundation; 12 * version 2.1 of the License only. 13 * 14 * This library is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 * Lesser General Public License for more details. 18 * 19 * You should have received a copy of the GNU Lesser General Public 20 * License along with this library; if not, write to the Free Software 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 22 * 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA 24 * $/LicenseInfo$ 25 */ 26 27 28#ifndef VERTEX_CACHE_H 29 30#define VERTEX_CACHE_H 31 32class VertexCache 33{ 34 35public: 36 37 VertexCache(int size) 38 { 39 numEntries = size; 40 41 entries = new int[numEntries]; 42 43 for(int i = 0; i < numEntries; i++) 44 entries[i] = -1; 45 } 46 47 VertexCache() { VertexCache(16); } 48 ~VertexCache() { delete[] entries; entries = 0; } 49 50 bool InCache(int entry) 51 { 52 bool returnVal = false; 53 for(int i = 0; i < numEntries; i++) 54 { 55 if(entries[i] == entry) 56 { 57 returnVal = true; 58 break; 59 } 60 } 61 62 return returnVal; 63 } 64 65 int AddEntry(int entry) 66 { 67 int removed; 68 69 removed = entries[numEntries - 1]; 70 71 //push everything right one 72 for(int i = numEntries - 2; i >= 0; i--) 73 { 74 entries[i + 1] = entries[i]; 75 } 76 77 entries[0] = entry; 78 79 return removed; 80 } 81 82 void Clear() 83 { 84 memset(entries, -1, sizeof(int) * numEntries); 85 } 86 87 void Copy(VertexCache* inVcache) 88 { 89 for(int i = 0; i < numEntries; i++) 90 { 91 inVcache->Set(i, entries[i]); 92 } 93 } 94 95 int At(int index) { return entries[index]; } 96 void Set(int index, int value) { entries[index] = value; } 97 98private: 99 100 int *entries; 101 int numEntries; 102 103}; 104 105#endif