OGRE: OgreHardwareVertexBuffer.h Source File - OGRE Documentation

# 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-2009 Torus Knot Software Ltd
    00008
    00009 Permission is hereby granted, free of charge, to any person obtaining a copy
    00010 of this software and associated documentation files (the "Software"), to deal
    00011 in the Software without restriction, including without limitation the rights
    00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00013 copies of the Software, and to permit persons to whom the Software is
    00014 furnished to do so, subject to the following conditions:
    00015
    00016 The above copyright notice and this permission notice shall be included in
    00017 all copies or substantial portions of the Software.
    00018
    00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    00025 THE SOFTWARE.
    00026 -----------------------------------------------------------------------------
    00027 */
    00028 #ifndef __HardwareVertexBuffer__
    00029 #define __HardwareVertexBuffer__
    00030
    00031 // Precompiler options
    00032 #include "OgrePrerequisites.h"
    00033 #include "OgreHardwareBuffer.h"
    00034 #include "OgreSharedPtr.h"
    00035 #include "OgreColourValue.h"
    00036
    00037 namespace Ogre {
    00038     class HardwareBufferManagerBase;
    00039
    00047     class _OgreExport HardwareVertexBuffer : public HardwareBuffer
    00048     {
    00049         protected:
    00050
    00051             HardwareBufferManagerBase* mMgr;
    00052             size_t mNumVertices;
    00053             size_t mVertexSize;
    00054
    00055         public:
    00057             HardwareVertexBuffer(HardwareBufferManagerBase* mgr, size_t vertexSize, size_t numVertices,
    00058                 HardwareBuffer::Usage usage, bool useSystemMemory, bool useShadowBuffer);
    00059             ~HardwareVertexBuffer();
    00061             HardwareBufferManagerBase* getManager() const { return mMgr; }
    00063             size_t getVertexSize(void) const { return mVertexSize; }
    00065             size_t getNumVertices(void) const { return mNumVertices; }
    00066
    00067
    00068
    00069             // NB subclasses should override lock, unlock, readData, writeData
    00070
    00071     };
    00072
    00074     class _OgreExport HardwareVertexBufferSharedPtr : public SharedPtr<HardwareVertexBuffer>
    00075     {
    00076     public:
    00077         HardwareVertexBufferSharedPtr() : SharedPtr<HardwareVertexBuffer>() {}
    00078         explicit HardwareVertexBufferSharedPtr(HardwareVertexBuffer* buf);
    00079
    00080
    00081     };
    00082
    00084     enum VertexElementSemantic {
    00086         VES_POSITION = 1,
    00088         VES_BLEND_WEIGHTS = 2,
    00090         VES_BLEND_INDICES = 3,
    00092         VES_NORMAL = 4,
    00094         VES_DIFFUSE = 5,
    00096         VES_SPECULAR = 6,
    00098         VES_TEXTURE_COORDINATES = 7,
    00100         VES_BINORMAL = 8,
    00102         VES_TANGENT = 9
    00103
    00104     };
    00105
    00107     enum VertexElementType
    00108     {
    00109         VET_FLOAT1 = 0,
    00110         VET_FLOAT2 = 1,
    00111         VET_FLOAT3 = 2,
    00112         VET_FLOAT4 = 3,
    00114         VET_COLOUR = 4,
    00115         VET_SHORT1 = 5,
    00116         VET_SHORT2 = 6,
    00117         VET_SHORT3 = 7,
    00118         VET_SHORT4 = 8,
    00119         VET_UBYTE4 = 9,
    00121         VET_COLOUR_ARGB = 10,
    00123         VET_COLOUR_ABGR = 11
    00124     };
    00125
    00135     class _OgreExport VertexElement : public VertexDataAlloc
    00136     {
    00137     protected:
    00139         unsigned short mSource;
    00141         size_t mOffset;
    00143         VertexElementType mType;
    00145         VertexElementSemantic mSemantic;
    00147         unsigned short mIndex;
    00148     public:
    00150         VertexElement() {}
    00152         VertexElement(unsigned short source, size_t offset, VertexElementType theType,
    00153             VertexElementSemantic semantic, unsigned short index = 0);
    00155         unsigned short getSource(void) const { return mSource; }
    00157         size_t getOffset(void) const { return mOffset; }
    00159         VertexElementType getType(void) const { return mType; }
    00161         VertexElementSemantic getSemantic(void) const { return mSemantic; }
    00163         unsigned short getIndex(void) const { return mIndex; }
    00165         size_t getSize(void) const;
    00167         static size_t getTypeSize(VertexElementType etype);
    00169         static unsigned short getTypeCount(VertexElementType etype);
    00173         static VertexElementType multiplyTypeCount(VertexElementType baseType, unsigned short count);
    00177         static VertexElementType getBaseType(VertexElementType multiType);
    00178
    00185         static void convertColourValue(VertexElementType srcType,
    00186             VertexElementType dstType, uint32* ptr);
    00187
    00193         static uint32 convertColourValue(const ColourValue& src,
    00194             VertexElementType dst);
    00195
    00197         static VertexElementType getBestColourVertexElementType(void);
    00198
    00199         inline bool operator== (const VertexElement& rhs) const
    00200         {
    00201             if (mType != rhs.mType ||
    00202                 mIndex != rhs.mIndex ||
    00203                 mOffset != rhs.mOffset ||
    00204                 mSemantic != rhs.mSemantic ||
    00205                 mSource != rhs.mSource)
    00206                 return false;
    00207             else
    00208                 return true;
    00209
    00210         }
    00218         inline void baseVertexPointerToElement(void* pBase, void** pElem) const
    00219         {
    00220             // The only way we can do this is to cast to char* in order to use byte offset
    00221             // then cast back to void*.
    00222             *pElem = static_cast<void*>(
    00223                 static_cast<unsigned char*>(pBase) + mOffset);
    00224         }
    00232         inline void baseVertexPointerToElement(void* pBase, float** pElem) const
    00233         {
    00234             // The only way we can do this is to cast to char* in order to use byte offset
    00235             // then cast back to float*. However we have to go via void* because casting
    00236             // directly is not allowed
    00237             *pElem = static_cast<float*>(
    00238                 static_cast<void*>(
    00239                     static_cast<unsigned char*>(pBase) + mOffset));
    00240         }
    00241
    00249         inline void baseVertexPointerToElement(void* pBase, RGBA** pElem) const
    00250         {
    00251             *pElem = static_cast<RGBA*>(
    00252                 static_cast<void*>(
    00253                     static_cast<unsigned char*>(pBase) + mOffset));
    00254         }
    00262         inline void baseVertexPointerToElement(void* pBase, unsigned char** pElem) const
    00263         {
    00264             *pElem = static_cast<unsigned char*>(pBase) + mOffset;
    00265         }
    00266
    00274         inline void baseVertexPointerToElement(void* pBase, unsigned short** pElem) const
    00275         {
    00276             *pElem = static_cast<unsigned short*>(
    00277                 static_cast<void*>(
    00278                     static_cast<unsigned char*>(pBase) + mOffset));
    00279         }
    00280
    00281
    00282     };
    00305     class _OgreExport VertexDeclaration : public VertexDataAlloc
    00306     {
    00307     public:
    00309         typedef list<VertexElement>::type VertexElementList;
    00311         static bool vertexElementLess(const VertexElement& e1, const VertexElement& e2);
    00312     protected:
    00313         VertexElementList mElementList;
    00314     public:
    00316         VertexDeclaration();
    00317         virtual ~VertexDeclaration();
    00318
    00320         size_t getElementCount(void) { return mElementList.size(); }
    00322         const VertexElementList& getElements(void) const;
    00324         const VertexElement* getElement(unsigned short index);
    00325
    00334         void sort(void);
    00335
    00346         void closeGapsInSource(void);
    00347
    00358         VertexDeclaration* getAutoOrganisedDeclaration(bool skeletalAnimation,
    00359             bool vertexAnimation);
    00360
    00362         unsigned short getMaxSource(void) const;
    00363
    00364
    00365
    00379         virtual const VertexElement& addElement(unsigned short source, size_t offset, VertexElementType theType,
    00380             VertexElementSemantic semantic, unsigned short index = 0);
    00394         virtual const VertexElement& insertElement(unsigned short atPosition,
    00395             unsigned short source, size_t offset, VertexElementType theType,
    00396             VertexElementSemantic semantic, unsigned short index = 0);
    00397
    00399         virtual void removeElement(unsigned short elem_index);
    00400
    00407         virtual void removeElement(VertexElementSemantic semantic, unsigned short index = 0);
    00408
    00410         virtual void removeAllElements(void);
    00411
    00417         virtual void modifyElement(unsigned short elem_index, unsigned short source, size_t offset, VertexElementType theType,
    00418             VertexElementSemantic semantic, unsigned short index = 0);
    00419
    00425         virtual const VertexElement* findElementBySemantic(VertexElementSemantic sem, unsigned short index = 0);
    00435         virtual VertexElementList findElementsBySource(unsigned short source);
    00436
    00438         virtual size_t getVertexSize(unsigned short source);
    00439
    00444         virtual VertexDeclaration* clone(HardwareBufferManagerBase* mgr = 0);
    00445
    00446         inline bool operator== (const VertexDeclaration& rhs) const
    00447         {
    00448             if (mElementList.size() != rhs.mElementList.size())
    00449                 return false;
    00450
    00451             VertexElementList::const_iterator i, iend, rhsi, rhsiend;
    00452             iend = mElementList.end();
    00453             rhsiend = rhs.mElementList.end();
    00454             rhsi = rhs.mElementList.begin();
    00455             for (i = mElementList.begin(); i != iend && rhsi != rhsiend; ++i, ++rhsi)
    00456             {
    00457                 if ( !(*i == *rhsi) )
    00458                     return false;
    00459             }
    00460
    00461             return true;
    00462         }
    00463         inline bool operator!= (const VertexDeclaration& rhs) const
    00464         {
    00465             return !(*this == rhs);
    00466         }
    00467
    00468     };
    00469
    00483     class _OgreExport VertexBufferBinding : public VertexDataAlloc
    00484     {
    00485     public:
    00487         typedef map<unsigned short, HardwareVertexBufferSharedPtr>::type VertexBufferBindingMap;
    00488     protected:
    00489         VertexBufferBindingMap mBindingMap;
    00490         mutable unsigned short mHighIndex;
    00491     public:
    00493         VertexBufferBinding();
    00494         virtual ~VertexBufferBinding();
    00503         virtual void setBinding(unsigned short index, const HardwareVertexBufferSharedPtr& buffer);
    00505         virtual void unsetBinding(unsigned short index);
    00506
    00508         virtual void unsetAllBindings(void);
    00509
    00511         virtual const VertexBufferBindingMap& getBindings(void) const;
    00512
    00514         virtual const HardwareVertexBufferSharedPtr& getBuffer(unsigned short index) const;
    00516         virtual bool isBufferBound(unsigned short index) const;
    00517
    00518         virtual size_t getBufferCount(void) const { return mBindingMap.size(); }
    00519
    00525         virtual unsigned short getNextIndex(void) const { return mHighIndex++; }
    00526
    00529         virtual unsigned short getLastBoundIndex(void) const;
    00530
    00531         typedef map<ushort, ushort>::type BindingIndexMap;
    00532
    00535         virtual bool hasGaps(void) const;
    00536
    00549         virtual void closeGaps(BindingIndexMap& bindingIndexMap);
    00550
    00551
    00552     };
    00558 }
    00559 #endif
    00560

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Wed Nov 3 2010 19:24:51