# OgreHardwareVertexBuffer.h

Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004     (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright (c) 2000-2005 The OGRE Team
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This program is free software; you can redistribute it and/or modify it under
    00011 the terms of the GNU Lesser General Public License as published by the Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023 -----------------------------------------------------------------------------
    00024 */
    00025 #ifndef __HardwareVertexBuffer__
    00026 #define __HardwareVertexBuffer__
    00027
    00028 // Precompiler options
    00029 #include "OgrePrerequisites.h"
    00030 #include "OgreHardwareBuffer.h"
    00031 #include "OgreSharedPtr.h"
    00032 #include "OgreColourValue.h"
    00033
    00034 namespace Ogre {
    00036     class _OgreExport HardwareVertexBuffer : public HardwareBuffer
    00037     {
    00038         protected:
    00039
    00040             size_t mNumVertices;
    00041             size_t mVertexSize;
    00042
    00043         public:
    00045             HardwareVertexBuffer(size_t vertexSize, size_t numVertices,
    00046                 HardwareBuffer::Usage usage, bool useSystemMemory, bool useShadowBuffer);
    00047             ~HardwareVertexBuffer();
    00049             size_t getVertexSize(void) const { return mVertexSize; }
    00051             size_t getNumVertices(void) const { return mNumVertices; }
    00052
    00053
    00054
    00055             // NB subclasses should override lock, unlock, readData, writeData
    00056
    00057     };
    00058
    00060     class _OgreExport HardwareVertexBufferSharedPtr : public SharedPtr<HardwareVertexBuffer>
    00061     {
    00062     public:
    00063         HardwareVertexBufferSharedPtr() : SharedPtr<HardwareVertexBuffer>() {}
    00064         explicit HardwareVertexBufferSharedPtr(HardwareVertexBuffer* buf);
    00065
    00066
    00067     };
    00068
    00070     enum VertexElementSemantic {
    00072         VES_POSITION = 1,
    00074         VES_BLEND_WEIGHTS = 2,
    00076         VES_BLEND_INDICES = 3,
    00078         VES_NORMAL = 4,
    00080         VES_DIFFUSE = 5,
    00082         VES_SPECULAR = 6,
    00084         VES_TEXTURE_COORDINATES = 7,
    00086         VES_BINORMAL = 8,
    00088         VES_TANGENT = 9
    00089
    00090     };
    00091
    00093     enum VertexElementType
    00094     {
    00095         VET_FLOAT1,
    00096         VET_FLOAT2,
    00097         VET_FLOAT3,
    00098         VET_FLOAT4,
    00099         VET_COLOUR,
    00100         VET_SHORT1,
    00101         VET_SHORT2,
    00102         VET_SHORT3,
    00103         VET_SHORT4,
    00104         VET_UBYTE4
    00105     };
    00106
    00116     class _OgreExport VertexElement
    00117     {
    00118     protected:
    00120         unsigned short mSource;
    00122         size_t mOffset;
    00124         VertexElementType mType;
    00126         VertexElementSemantic mSemantic;
    00128         unsigned short mIndex;
    00129     public:
    00131         VertexElement(unsigned short source, size_t offset, VertexElementType theType,
    00132             VertexElementSemantic semantic, unsigned short index = 0);
    00134         unsigned short getSource(void) const { return mSource; }
    00136         size_t getOffset(void) const { return mOffset; }
    00138         VertexElementType getType(void) const { return mType; }
    00140         VertexElementSemantic getSemantic(void) const { return mSemantic; }
    00142         unsigned short getIndex(void) const { return mIndex; }
    00144         size_t getSize(void) const;
    00146         static size_t getTypeSize(VertexElementType etype);
    00148         static unsigned short getTypeCount(VertexElementType etype);
    00152         static VertexElementType multiplyTypeCount(VertexElementType baseType, unsigned short count);
    00156         static VertexElementType getBaseType(VertexElementType multiType);
    00157
    00158         inline bool operator== (const VertexElement& rhs) const
    00159         {
    00160             if (mType != rhs.mType ||
    00161                 mIndex != rhs.mIndex ||
    00162                 mOffset != rhs.mOffset ||
    00163                 mSemantic != rhs.mSemantic ||
    00164                 mSource != rhs.mSource)
    00165                 return false;
    00166             else
    00167                 return true;
    00168
    00169         }
    00177         inline void baseVertexPointerToElement(void* pBase, void** pElem) const
    00178         {
    00179             // The only way we can do this is to cast to char* in order to use byte offset
    00180             // then cast back to void*.
    00181             *pElem = static_cast<void*>(
    00182                 static_cast<unsigned char*>(pBase) + mOffset);
    00183         }
    00191         inline void baseVertexPointerToElement(void* pBase, float** pElem) const
    00192         {
    00193             // The only way we can do this is to cast to char* in order to use byte offset
    00194             // then cast back to float*. However we have to go via void* because casting
    00195             // directly is not allowed
    00196             *pElem = static_cast<float*>(
    00197                 static_cast<void*>(
    00198                     static_cast<unsigned char*>(pBase) + mOffset));
    00199         }
    00200
    00208         inline void baseVertexPointerToElement(void* pBase, RGBA** pElem) const
    00209         {
    00210             *pElem = static_cast<RGBA*>(
    00211                 static_cast<void*>(
    00212                     static_cast<unsigned char*>(pBase) + mOffset));
    00213         }
    00221         inline void baseVertexPointerToElement(void* pBase, unsigned char** pElem) const
    00222         {
    00223             *pElem = static_cast<unsigned char*>(pBase) + mOffset;
    00224         }
    00225
    00233         inline void baseVertexPointerToElement(void* pBase, unsigned short** pElem) const
    00234         {
    00235             *pElem = static_cast<unsigned short*>(pBase) + mOffset;
    00236         }
    00237
    00238
    00239     };
    00262     class _OgreExport VertexDeclaration
    00263     {
    00264     public:
    00266         typedef std::list<VertexElement> VertexElementList;
    00268         static bool vertexElementLess(const VertexElement& e1, const VertexElement& e2);
    00269     protected:
    00270         VertexElementList mElementList;
    00271     public:
    00273         VertexDeclaration();
    00274         virtual ~VertexDeclaration();
    00275
    00277         size_t getElementCount(void) { return mElementList.size(); }
    00279         const VertexElementList& getElements(void) const;
    00281         const VertexElement* getElement(unsigned short index);
    00282
    00291         void sort(void);
    00292
    00303         void closeGapsInSource(void);
    00304
    00311         VertexDeclaration* getAutoOrganisedDeclaration(bool animated);
    00312
    00314         unsigned short getMaxSource(void) const;
    00315
    00316
    00317
    00331         virtual const VertexElement& addElement(unsigned short source, size_t offset, VertexElementType theType,
    00332             VertexElementSemantic semantic, unsigned short index = 0);
    00346         virtual const VertexElement& insertElement(unsigned short atPosition,
    00347             unsigned short source, size_t offset, VertexElementType theType,
    00348             VertexElementSemantic semantic, unsigned short index = 0);
    00349
    00351         virtual void removeElement(unsigned short elem_index);
    00352
    00359         virtual void removeElement(VertexElementSemantic semantic, unsigned short index = 0);
    00360
    00366         virtual void modifyElement(unsigned short elem_index, unsigned short source, size_t offset, VertexElementType theType,
    00367             VertexElementSemantic semantic, unsigned short index = 0);
    00368
    00374         virtual const VertexElement* findElementBySemantic(VertexElementSemantic sem, unsigned short index = 0);
    00384         virtual VertexElementList findElementsBySource(unsigned short source);
    00385
    00387         virtual size_t getVertexSize(unsigned short source);
    00388
    00390         virtual VertexDeclaration* clone(void);
    00391
    00392         inline bool operator== (const VertexDeclaration& rhs) const
    00393         {
    00394             if (mElementList.size() != rhs.mElementList.size())
    00395                 return false;
    00396
    00397             VertexElementList::const_iterator i, iend, rhsi, rhsiend;
    00398             iend = mElementList.end();
    00399             rhsiend = rhs.mElementList.end();
    00400             rhsi = rhs.mElementList.begin();
    00401             for (i = mElementList.begin(); i != iend && rhsi != rhsiend; ++i, ++rhsi)
    00402             {
    00403                 if ( !(*i == *rhsi) )
    00404                     return false;
    00405             }
    00406
    00407             return true;
    00408         }
    00409         inline bool operator!= (const VertexDeclaration& rhs) const
    00410         {
    00411             return !(*this == rhs);
    00412         }
    00413
    00414     };
    00415
    00429     class _OgreExport VertexBufferBinding
    00430     {
    00431     public:
    00433         typedef std::map<unsigned short, HardwareVertexBufferSharedPtr> VertexBufferBindingMap;
    00434     protected:
    00435         VertexBufferBindingMap mBindingMap;
    00436         mutable unsigned short mHighIndex;
    00437     public:
    00439         VertexBufferBinding();
    00440         virtual ~VertexBufferBinding();
    00449         virtual void setBinding(unsigned short index, HardwareVertexBufferSharedPtr buffer);
    00451         virtual void unsetBinding(unsigned short index);
    00452
    00454         virtual void unsetAllBindings(void);
    00455
    00457         virtual const VertexBufferBindingMap& getBindings(void) const;
    00458
    00460         virtual HardwareVertexBufferSharedPtr getBuffer(unsigned short index);
    00461
    00462         virtual size_t getBufferCount(void) const { return mBindingMap.size(); }
    00463
    00469         virtual unsigned short getNextIndex(void) const { return mHighIndex++; }
    00470
    00471
    00472
    00473
    00474     };
    00475
    00476
    00477
    00478 }
    00479 #endif
    00480

Copyright © 2000-2005 by The OGRE Team
Last modified Sun Nov 20 12:36:01 2005