Home | Namespaces | Hierarchy | Alphabetical List | Class list | Files | Namespace Members | Class members | File members | Tutorials

CIndexBuffer.h

Go to the documentation of this file.
00001 // Copyright (C) 2008-2010 Nikolaus Gebhardt
00002 // This file is part of the "Irrlicht Engine".
00003 // For conditions of distribution and use, see copyright notice in irrlicht.h
00004 
00005 #ifndef __C_INDEX_BUFFER_H_INCLUDED__
00006 #define __C_INDEX_BUFFER_H_INCLUDED__
00007 
00008 #include "IIndexBuffer.h"
00009 
00010 namespace irr
00011 {
00012 namespace scene
00013 {
00014 
00015         class CIndexBuffer : public IIndexBuffer
00016         {
00017 
00018                 class IIndexList
00019                 {
00020                 public:
00021                         virtual ~IIndexList(){};
00022 
00023                         virtual u32 stride() const =0;
00024                         virtual u32 size() const =0;
00025                         virtual void push_back(const u32 &element) =0;
00026                         virtual u32 operator [](u32 index) const =0;
00027                         virtual u32 getLast() =0;
00028                         virtual void setValue(u32 index, u32 value) =0;
00029                         virtual void set_used(u32 usedNow) =0;
00030                         virtual void reallocate(u32 new_size) =0;
00031                         virtual u32 allocated_size() const =0;
00032                         virtual void* pointer() =0;
00033                         virtual video::E_INDEX_TYPE getType() const =0;
00034                 };
00035 
00036                 template <class T>
00037                 class CSpecificIndexList : public IIndexList
00038                 {
00039                 public:
00040                         core::array<T> Indices;
00041 
00042                         virtual u32 stride() const {return sizeof(T);}
00043 
00044                         virtual u32 size() const {return Indices.size();}
00045 
00046                         virtual void push_back(const u32 &element)
00047                         {
00048                                 Indices.push_back((T&)element);
00049                         }
00050 
00051                         virtual u32 operator [](u32 index) const
00052                         {
00053                                 return (u32)(Indices[index]);
00054                         }
00055 
00056                         virtual u32 getLast() {return (u32)Indices.getLast();}
00057 
00058                         virtual void setValue(u32 index, u32 value)
00059                         {
00060                                 Indices[index]=(T)value;
00061                         }
00062 
00063                         virtual void set_used(u32 usedNow)
00064                         {
00065                                 Indices.set_used(usedNow);
00066                         }
00067 
00068                         virtual void reallocate(u32 new_size)
00069                         {
00070                                 Indices.reallocate(new_size);
00071                         }
00072 
00073                         virtual u32 allocated_size() const
00074                         {
00075                                 return Indices.allocated_size();
00076                         }
00077 
00078                         virtual void* pointer() {return Indices.pointer();}
00079 
00080                         virtual video::E_INDEX_TYPE getType() const
00081                         {
00082                                 if (sizeof(T)==sizeof(u16))
00083                                         return video::EIT_16BIT;
00084                                 else
00085                                         return video::EIT_32BIT;
00086                         }
00087                 };
00088 
00089         public:
00090                 IIndexList *Indices;
00091 
00092                 CIndexBuffer(video::E_INDEX_TYPE IndexType) :Indices(0), MappingHint(EHM_NEVER), ChangedID(1)
00093                 {
00094                         setType(IndexType);
00095                 }
00096 
00097                 CIndexBuffer(const IIndexBuffer &IndexBufferCopy) :Indices(0), MappingHint(EHM_NEVER), ChangedID(1)
00098                 {
00099                         setType(IndexBufferCopy.getType());
00100                         reallocate(IndexBufferCopy.size());
00101 
00102                         for (u32 n=0;n<IndexBufferCopy.size();++n)
00103                                 push_back(IndexBufferCopy[n]);
00104                 }
00105 
00106                 virtual ~CIndexBuffer()
00107                 {
00108                         delete Indices;
00109                 }
00110 
00111                 //virtual void setType(video::E_INDEX_TYPE IndexType);
00112                 virtual void setType(video::E_INDEX_TYPE IndexType)
00113                 {
00114                         IIndexList *NewIndices=0;
00115 
00116                         switch (IndexType)
00117                         {
00118                                 case video::EIT_16BIT:
00119                                 {
00120                                         NewIndices=new CSpecificIndexList<u16>;
00121                                         break;
00122                                 }
00123                                 case video::EIT_32BIT:
00124                                 {
00125                                         NewIndices=new CSpecificIndexList<u32>;
00126                                         break;
00127                                 }
00128                         }
00129 
00130                         if (Indices)
00131                         {
00132                                 NewIndices->reallocate( Indices->size() );
00133 
00134                                 for(u32 n=0;n<Indices->size();++n)
00135                                         NewIndices->push_back((*Indices)[n]);
00136 
00137                                 delete Indices;
00138                         }
00139 
00140                         Indices=NewIndices;
00141                 }
00142 
00143                 virtual void* getData() {return Indices->pointer();}
00144 
00145                 virtual video::E_INDEX_TYPE getType() const {return Indices->getType();}
00146 
00147                 virtual u32 stride() const {return Indices->stride();}
00148 
00149                 virtual u32 size() const
00150                 {
00151                         return Indices->size();
00152                 }
00153 
00154                 virtual void push_back(const u32 &element)
00155                 {
00156                         Indices->push_back(element);
00157                 }
00158 
00159                 virtual u32 operator [](u32 index) const
00160                 {
00161                         return (*Indices)[index];
00162                 }
00163 
00164                 virtual u32 getLast()
00165                 {
00166                         return Indices->getLast();
00167                 }
00168 
00169                 virtual void setValue(u32 index, u32 value)
00170                 {
00171                         Indices->setValue(index, value);
00172                 }
00173 
00174                 virtual void set_used(u32 usedNow)
00175                 {
00176                         Indices->set_used(usedNow);
00177                 }
00178 
00179                 virtual void reallocate(u32 new_size)
00180                 {
00181                         Indices->reallocate(new_size);
00182                 }
00183 
00184                 virtual u32 allocated_size() const
00185                 {
00186                         return Indices->allocated_size();
00187                 }
00188 
00189                 virtual void* pointer()
00190                 {
00191                         return Indices->pointer();
00192                 }
00193 
00195                 virtual E_HARDWARE_MAPPING getHardwareMappingHint() const
00196                 {
00197                         return MappingHint;
00198                 }
00199 
00201                 virtual void setHardwareMappingHint( E_HARDWARE_MAPPING NewMappingHint )
00202                 {
00203                         MappingHint=NewMappingHint;
00204                 }
00205 
00207                 virtual void setDirty()
00208                 {
00209                         ++ChangedID;
00210                 }
00211 
00213 
00214                 virtual u32 getChangedID() const {return ChangedID;}
00215 
00216                 E_HARDWARE_MAPPING MappingHint;
00217                 u32 ChangedID;
00218         };
00219 
00220 
00221 } // end namespace scene
00222 } // end namespace irr
00223 
00224 #endif
00225 

The Irrlicht Engine
The Irrlicht Engine Documentation © 2003-2010 by Nikolaus Gebhardt. Generated on Sun Oct 24 12:41:56 2010 by Doxygen (1.6.2)