/indra/newview/VertexCache.h

https://bitbucket.org/lindenlab/viewer-beta/ · C++ Header · 105 lines · 56 code · 23 blank · 26 comment · 6 complexity · 5d769cd6852fe7ed8e3b946104dd6e43 MD5 · raw file

  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. #ifndef VERTEX_CACHE_H
  27. #define VERTEX_CACHE_H
  28. class VertexCache
  29. {
  30. public:
  31. VertexCache(int size)
  32. {
  33. numEntries = size;
  34. entries = new int[numEntries];
  35. for(int i = 0; i < numEntries; i++)
  36. entries[i] = -1;
  37. }
  38. VertexCache() { VertexCache(16); }
  39. ~VertexCache() { delete[] entries; entries = 0; }
  40. bool InCache(int entry)
  41. {
  42. bool returnVal = false;
  43. for(int i = 0; i < numEntries; i++)
  44. {
  45. if(entries[i] == entry)
  46. {
  47. returnVal = true;
  48. break;
  49. }
  50. }
  51. return returnVal;
  52. }
  53. int AddEntry(int entry)
  54. {
  55. int removed;
  56. removed = entries[numEntries - 1];
  57. //push everything right one
  58. for(int i = numEntries - 2; i >= 0; i--)
  59. {
  60. entries[i + 1] = entries[i];
  61. }
  62. entries[0] = entry;
  63. return removed;
  64. }
  65. void Clear()
  66. {
  67. memset(entries, -1, sizeof(int) * numEntries);
  68. }
  69. void Copy(VertexCache* inVcache)
  70. {
  71. for(int i = 0; i < numEntries; i++)
  72. {
  73. inVcache->Set(i, entries[i]);
  74. }
  75. }
  76. int At(int index) { return entries[index]; }
  77. void Set(int index, int value) { entries[index] = value; }
  78. private:
  79. int *entries;
  80. int numEntries;
  81. };
  82. #endif