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-2006 Torus Knot Software Ltd
    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 You may alternatively use this source under the terms of a specific version of
    00025 the OGRE Unrestricted License provided you have obtained such a license from
    00026 Torus Knot Software Ltd.
    00027 -----------------------------------------------------------------------------
    00028 */
    00029 #ifndef __HardwareVertexBuffer__
    00030 #define __HardwareVertexBuffer__
    00031
    00032 // Precompiler options
    00033 #include "OgrePrerequisites.h"
    00034 #include "OgreHardwareBuffer.h"
    00035 #include "OgreSharedPtr.h"
    00036 #include "OgreColourValue.h"
    00037
    00038 namespace Ogre {
    00040     class _OgreExport HardwareVertexBuffer : public HardwareBuffer
    00041     {
    00042         protected:
    00043
    00044             size_t mNumVertices;
    00045             size_t mVertexSize;
    00046
    00047         public:
    00049             HardwareVertexBuffer(size_t vertexSize, size_t numVertices,
    00050                 HardwareBuffer::Usage usage, bool useSystemMemory, bool useShadowBuffer);
    00051             ~HardwareVertexBuffer();
    00053             size_t getVertexSize(void) const { return mVertexSize; }
    00055             size_t getNumVertices(void) const { return mNumVertices; }
    00056
    00057
    00058
    00059             // NB subclasses should override lock, unlock, readData, writeData
    00060
    00061     };
    00062
    00064     class _OgreExport HardwareVertexBufferSharedPtr : public SharedPtr<HardwareVertexBuffer>
    00065     {
    00066     public:
    00067         HardwareVertexBufferSharedPtr() : SharedPtr<HardwareVertexBuffer>() {}
    00068         explicit HardwareVertexBufferSharedPtr(HardwareVertexBuffer* buf);
    00069
    00070
    00071     };
    00072
    00074     enum VertexElementSemantic {
    00076         VES_POSITION = 1,
    00078         VES_BLEND_WEIGHTS = 2,
    00080         VES_BLEND_INDICES = 3,
    00082         VES_NORMAL = 4,
    00084         VES_DIFFUSE = 5,
    00086         VES_SPECULAR = 6,
    00088         VES_TEXTURE_COORDINATES = 7,
    00090         VES_BINORMAL = 8,
    00092         VES_TANGENT = 9
    00093
    00094     };
    00095
    00097     enum VertexElementType
    00098     {
    00099         VET_FLOAT1 = 0,
    00100         VET_FLOAT2 = 1,
    00101         VET_FLOAT3 = 2,
    00102         VET_FLOAT4 = 3,
    00104         VET_COLOUR = 4,
    00105         VET_SHORT1 = 5,
    00106         VET_SHORT2 = 6,
    00107         VET_SHORT3 = 7,
    00108         VET_SHORT4 = 8,
    00109         VET_UBYTE4 = 9,
    00111         VET_COLOUR_ARGB = 10,
    00113         VET_COLOUR_ABGR = 11
    00114     };
    00115
    00125     class _OgreExport VertexElement : public VertexDataAlloc
    00126     {
    00127     protected:
    00129         unsigned short mSource;
    00131         size_t mOffset;
    00133         VertexElementType mType;
    00135         VertexElementSemantic mSemantic;
    00137         unsigned short mIndex;
    00138     public:
    00140         VertexElement(unsigned short source, size_t offset, VertexElementType theType,
    00141             VertexElementSemantic semantic, unsigned short index = 0);
    00143         unsigned short getSource(void) const { return mSource; }
    00145         size_t getOffset(void) const { return mOffset; }
    00147         VertexElementType getType(void) const { return mType; }
    00149         VertexElementSemantic getSemantic(void) const { return mSemantic; }
    00151         unsigned short getIndex(void) const { return mIndex; }
    00153         size_t getSize(void) const;
    00155         static size_t getTypeSize(VertexElementType etype);
    00157         static unsigned short getTypeCount(VertexElementType etype);
    00161         static VertexElementType multiplyTypeCount(VertexElementType baseType, unsigned short count);
    00165         static VertexElementType getBaseType(VertexElementType multiType);
    00166
    00173         static void convertColourValue(VertexElementType srcType,
    00174             VertexElementType dstType, uint32* ptr);
    00175
    00181         static uint32 convertColourValue(const ColourValue& src,
    00182             VertexElementType dst);
    00183
    00185         static VertexElementType getBestColourVertexElementType(void);
    00186
    00187         inline bool operator== (const VertexElement& rhs) const
    00188         {
    00189             if (mType != rhs.mType ||
    00190                 mIndex != rhs.mIndex ||
    00191                 mOffset != rhs.mOffset ||
    00192                 mSemantic != rhs.mSemantic ||
    00193                 mSource != rhs.mSource)
    00194                 return false;
    00195             else
    00196                 return true;
    00197
    00198         }
    00206         inline void baseVertexPointerToElement(void* pBase, void** pElem) const
    00207         {
    00208             // The only way we can do this is to cast to char* in order to use byte offset
    00209             // then cast back to void*.
    00210             *pElem = static_cast<void*>(
    00211                 static_cast<unsigned char*>(pBase) + mOffset);
    00212         }
    00220         inline void baseVertexPointerToElement(void* pBase, float** pElem) const
    00221         {
    00222             // The only way we can do this is to cast to char* in order to use byte offset
    00223             // then cast back to float*. However we have to go via void* because casting
    00224             // directly is not allowed
    00225             *pElem = static_cast<float*>(
    00226                 static_cast<void*>(
    00227                     static_cast<unsigned char*>(pBase) + mOffset));
    00228         }
    00229
    00237         inline void baseVertexPointerToElement(void* pBase, RGBA** pElem) const
    00238         {
    00239             *pElem = static_cast<RGBA*>(
    00240                 static_cast<void*>(
    00241                     static_cast<unsigned char*>(pBase) + mOffset));
    00242         }
    00250         inline void baseVertexPointerToElement(void* pBase, unsigned char** pElem) const
    00251         {
    00252             *pElem = static_cast<unsigned char*>(pBase) + mOffset;
    00253         }
    00254
    00262         inline void baseVertexPointerToElement(void* pBase, unsigned short** pElem) const
    00263         {
    00264             *pElem = static_cast<unsigned short*>(pBase) + mOffset;
    00265         }
    00266
    00267
    00268     };
    00291     class _OgreExport VertexDeclaration : public VertexDataAlloc
    00292     {
    00293     public:
    00295         typedef std::list<VertexElement> VertexElementList;
    00297         static bool vertexElementLess(const VertexElement& e1, const VertexElement& e2);
    00298     protected:
    00299         VertexElementList mElementList;
    00300     public:
    00302         VertexDeclaration();
    00303         virtual ~VertexDeclaration();
    00304
    00306         size_t getElementCount(void) { return mElementList.size(); }
    00308         const VertexElementList& getElements(void) const;
    00310         const VertexElement* getElement(unsigned short index);
    00311
    00320         void sort(void);
    00321
    00332         void closeGapsInSource(void);
    00333
    00344         VertexDeclaration* getAutoOrganisedDeclaration(bool skeletalAnimation,
    00345             bool vertexAnimation);
    00346
    00348         unsigned short getMaxSource(void) const;
    00349
    00350
    00351
    00365         virtual const VertexElement& addElement(unsigned short source, size_t offset, VertexElementType theType,
    00366             VertexElementSemantic semantic, unsigned short index = 0);
    00380         virtual const VertexElement& insertElement(unsigned short atPosition,
    00381             unsigned short source, size_t offset, VertexElementType theType,
    00382             VertexElementSemantic semantic, unsigned short index = 0);
    00383
    00385         virtual void removeElement(unsigned short elem_index);
    00386
    00393         virtual void removeElement(VertexElementSemantic semantic, unsigned short index = 0);
    00394
    00396         virtual void removeAllElements(void);
    00397
    00403         virtual void modifyElement(unsigned short elem_index, unsigned short source, size_t offset, VertexElementType theType,
    00404             VertexElementSemantic semantic, unsigned short index = 0);
    00405
    00411         virtual const VertexElement* findElementBySemantic(VertexElementSemantic sem, unsigned short index = 0);
    00421         virtual VertexElementList findElementsBySource(unsigned short source);
    00422
    00424         virtual size_t getVertexSize(unsigned short source);
    00425
    00427         virtual VertexDeclaration* clone(void);
    00428
    00429         inline bool operator== (const VertexDeclaration& rhs) const
    00430         {
    00431             if (mElementList.size() != rhs.mElementList.size())
    00432                 return false;
    00433
    00434             VertexElementList::const_iterator i, iend, rhsi, rhsiend;
    00435             iend = mElementList.end();
    00436             rhsiend = rhs.mElementList.end();
    00437             rhsi = rhs.mElementList.begin();
    00438             for (i = mElementList.begin(); i != iend && rhsi != rhsiend; ++i, ++rhsi)
    00439             {
    00440                 if ( !(*i == *rhsi) )
    00441                     return false;
    00442             }
    00443
    00444             return true;
    00445         }
    00446         inline bool operator!= (const VertexDeclaration& rhs) const
    00447         {
    00448             return !(*this == rhs);
    00449         }
    00450
    00451     };
    00452
    00466     class _OgreExport VertexBufferBinding : public VertexDataAlloc
    00467     {
    00468     public:
    00470         typedef std::map<unsigned short, HardwareVertexBufferSharedPtr> VertexBufferBindingMap;
    00471     protected:
    00472         VertexBufferBindingMap mBindingMap;
    00473         mutable unsigned short mHighIndex;
    00474     public:
    00476         VertexBufferBinding();
    00477         virtual ~VertexBufferBinding();
    00486         virtual void setBinding(unsigned short index, const HardwareVertexBufferSharedPtr& buffer);
    00488         virtual void unsetBinding(unsigned short index);
    00489
    00491         virtual void unsetAllBindings(void);
    00492
    00494         virtual const VertexBufferBindingMap& getBindings(void) const;
    00495
    00497         virtual const HardwareVertexBufferSharedPtr& getBuffer(unsigned short index) const;
    00499         virtual bool isBufferBound(unsigned short index) const;
    00500
    00501         virtual size_t getBufferCount(void) const { return mBindingMap.size(); }
    00502
    00508         virtual unsigned short getNextIndex(void) const { return mHighIndex++; }
    00509
    00512         virtual unsigned short getLastBoundIndex(void) const;
    00513
    00514         typedef std::map<ushort, ushort> BindingIndexMap;
    00515
    00518         virtual bool hasGaps(void) const;
    00519
    00532         virtual void closeGaps(BindingIndexMap& bindingIndexMap);
    00533
    00534
    00535     };
    00536
    00537
    00538
    00539 }
    00540 #endif
    00541

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Jul 26 11:32:17 2009