Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

indexbuffer.cpp

Go to the documentation of this file.
00001 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*-
00002 
00003    this file is part of rcssserver3D
00004    Fri May 9 2003
00005    Copyright (C) 2002,2003 Koblenz University
00006    Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group
00007    $Id: indexbuffer.cpp,v 1.1 2004/04/22 17:55:33 rollmark Exp $
00008 
00009    This program is free software; you can redistribute it and/or modify
00010    it under the terms of the GNU General Public License as published by
00011    the Free Software Foundation; version 2 of the License.
00012 
00013    This program is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with this program; if not, write to the Free Software
00020    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00021 */
00022 
00023 #include "indexbuffer.h"
00024 #include <string.h>
00025 
00026 using namespace oxygen;
00027 using namespace boost;
00028 
00029 IndexBuffer::IndexBuffer()
00030     : mMaxIndex(0), mNumIndex(0), mIndex(0)   {}
00031 
00032 IndexBuffer::~IndexBuffer()
00033 {
00034 }
00035 
00036 void IndexBuffer::Cache(unsigned int numIndex, unsigned int *index)
00037 {
00038     EnsureFit(numIndex);
00039 
00040     // append new index data to our cache
00041     memcpy(&mIndex[mNumIndex], index, numIndex*sizeof(unsigned int));
00042     mNumIndex += numIndex;
00043 }
00044 
00045 void IndexBuffer::Cache(unsigned int newIndex)
00046 {
00047     Cache(1, &newIndex);
00048 }
00049 
00050 void IndexBuffer::EnsureFit(unsigned int count)
00051 {
00052     if(mIndex.get() == 0)
00053         {
00054             mIndex    = shared_array<unsigned int>(new unsigned int[count]);
00055             mMaxIndex = count;
00056             mNumIndex = 0;
00057         } else
00058             {
00059                 // check if there's enough room in our index cache
00060                 const unsigned int reqSize = mNumIndex+count;
00061 
00062                 if(mMaxIndex < reqSize)
00063                 {
00064                     // we don't have enough room ... so make room
00065                     unsigned int newSize = mMaxIndex*2;
00066 
00067                     while(newSize<reqSize)
00068                         {
00069                             newSize *= 2;
00070                         }
00071 
00072                     // allocate new memory
00073                     shared_array<unsigned int> newIndex(new unsigned int[newSize]);
00074 
00075                     // copy old data
00076                     memcpy(newIndex.get(), mIndex.get(),
00077                            mNumIndex*sizeof(unsigned int));
00078 
00079                     mIndex          = newIndex;
00080                     mMaxIndex       = newSize;
00081                 }
00082         }
00083 }
00084 
00085 void IndexBuffer::Flush()
00086 {
00087     mNumIndex = 0;
00088 }
00089 
00090 int IndexBuffer::GetNumIndex() const
00091 {
00092     return mNumIndex;
00093 }
00094 
00095 shared_array<unsigned int> IndexBuffer::GetIndex() const
00096 {
00097     return mIndex;
00098 }
00099 

Generated on Thu Apr 6 15:25:38 2006 for rcssserver3d by  doxygen 1.4.4