Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

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 = 0,
00096         VET_FLOAT2 = 1,
00097         VET_FLOAT3 = 2,
00098         VET_FLOAT4 = 3,
00100         VET_COLOUR = 4,
00101         VET_SHORT1 = 5,
00102         VET_SHORT2 = 6,
00103         VET_SHORT3 = 7,
00104         VET_SHORT4 = 8,
00105         VET_UBYTE4 = 9,
00107         VET_COLOUR_ARGB = 10,
00109         VET_COLOUR_ABGR = 11
00110     };
00111 
00121     class _OgreExport VertexElement
00122     {
00123     protected:
00125         unsigned short mSource;
00127         size_t mOffset;
00129         VertexElementType mType;
00131         VertexElementSemantic mSemantic;
00133         unsigned short mIndex;
00134     public:
00136         VertexElement(unsigned short source, size_t offset, VertexElementType theType,
00137             VertexElementSemantic semantic, unsigned short index = 0);
00139         unsigned short getSource(void) const { return mSource; }
00141         size_t getOffset(void) const { return mOffset; }
00143         VertexElementType getType(void) const { return mType; }
00145         VertexElementSemantic getSemantic(void) const { return mSemantic; }
00147         unsigned short getIndex(void) const { return mIndex; }
00149         size_t getSize(void) const;
00151         static size_t getTypeSize(VertexElementType etype);
00153         static unsigned short getTypeCount(VertexElementType etype);
00157         static VertexElementType multiplyTypeCount(VertexElementType baseType, unsigned short count);
00161         static VertexElementType getBaseType(VertexElementType multiType);
00162 
00169         static void convertColourValue(VertexElementType srcType,
00170             VertexElementType dstType, uint32* ptr);
00171 
00177         static uint32 convertColourValue(const ColourValue& src,
00178             VertexElementType dst);
00179 
00181         static VertexElementType getBestColourVertexElementType(void);
00182 
00183         inline bool operator== (const VertexElement& rhs) const
00184         {
00185             if (mType != rhs.mType ||
00186                 mIndex != rhs.mIndex ||
00187                 mOffset != rhs.mOffset ||
00188                 mSemantic != rhs.mSemantic ||
00189                 mSource != rhs.mSource)
00190                 return false;
00191             else
00192                 return true;
00193 
00194         }
00202         inline void baseVertexPointerToElement(void* pBase, void** pElem) const
00203         {
00204             // The only way we can do this is to cast to char* in order to use byte offset
00205             // then cast back to void*.
00206             *pElem = static_cast<void*>(
00207                 static_cast<unsigned char*>(pBase) + mOffset);
00208         }
00216         inline void baseVertexPointerToElement(void* pBase, float** pElem) const
00217         {
00218             // The only way we can do this is to cast to char* in order to use byte offset
00219             // then cast back to float*. However we have to go via void* because casting
00220             // directly is not allowed
00221             *pElem = static_cast<float*>(
00222                 static_cast<void*>(
00223                     static_cast<unsigned char*>(pBase) + mOffset));
00224         }
00225 
00233         inline void baseVertexPointerToElement(void* pBase, RGBA** pElem) const
00234         {
00235             *pElem = static_cast<RGBA*>(
00236                 static_cast<void*>(
00237                     static_cast<unsigned char*>(pBase) + mOffset));
00238         }
00246         inline void baseVertexPointerToElement(void* pBase, unsigned char** pElem) const
00247         {
00248             *pElem = static_cast<unsigned char*>(pBase) + mOffset;
00249         }
00250 
00258         inline void baseVertexPointerToElement(void* pBase, unsigned short** pElem) const
00259         {
00260             *pElem = static_cast<unsigned short*>(pBase) + mOffset;
00261         }
00262 
00263 
00264     };
00287     class _OgreExport VertexDeclaration
00288     {
00289     public:
00291         typedef std::list<VertexElement> VertexElementList;
00293         static bool vertexElementLess(const VertexElement& e1, const VertexElement& e2);
00294     protected:
00295         VertexElementList mElementList;
00296     public:
00298         VertexDeclaration();
00299         virtual ~VertexDeclaration();
00300 
00302         size_t getElementCount(void) { return mElementList.size(); }
00304         const VertexElementList& getElements(void) const;
00306         const VertexElement* getElement(unsigned short index);
00307 
00316         void sort(void);
00317 
00328         void closeGapsInSource(void);
00329 
00340         VertexDeclaration* getAutoOrganisedDeclaration(bool skeletalAnimation,
00341             bool vertexAnimation);
00342 
00344         unsigned short getMaxSource(void) const;
00345 
00346 
00347 
00361         virtual const VertexElement& addElement(unsigned short source, size_t offset, VertexElementType theType,
00362             VertexElementSemantic semantic, unsigned short index = 0);
00376         virtual const VertexElement& insertElement(unsigned short atPosition,
00377             unsigned short source, size_t offset, VertexElementType theType,
00378             VertexElementSemantic semantic, unsigned short index = 0);
00379 
00381         virtual void removeElement(unsigned short elem_index);
00382 
00389         virtual void removeElement(VertexElementSemantic semantic, unsigned short index = 0);
00390 
00392         virtual void removeAllElements(void);
00393 
00399         virtual void modifyElement(unsigned short elem_index, unsigned short source, size_t offset, VertexElementType theType,
00400             VertexElementSemantic semantic, unsigned short index = 0);
00401 
00407         virtual const VertexElement* findElementBySemantic(VertexElementSemantic sem, unsigned short index = 0);
00417         virtual VertexElementList findElementsBySource(unsigned short source);
00418 
00420         virtual size_t getVertexSize(unsigned short source);
00421 
00423         virtual VertexDeclaration* clone(void);
00424 
00425         inline bool operator== (const VertexDeclaration& rhs) const
00426         {
00427             if (mElementList.size() != rhs.mElementList.size())
00428                 return false;
00429 
00430             VertexElementList::const_iterator i, iend, rhsi, rhsiend;
00431             iend = mElementList.end();
00432             rhsiend = rhs.mElementList.end();
00433             rhsi = rhs.mElementList.begin();
00434             for (i = mElementList.begin(); i != iend && rhsi != rhsiend; ++i, ++rhsi)
00435             {
00436                 if ( !(*i == *rhsi) )
00437                     return false;
00438             }
00439 
00440             return true;
00441         }
00442         inline bool operator!= (const VertexDeclaration& rhs) const
00443         {
00444             return !(*this == rhs);
00445         }
00446 
00447     };
00448 
00462     class _OgreExport VertexBufferBinding
00463     {
00464     public:
00466         typedef std::map<unsigned short, HardwareVertexBufferSharedPtr> VertexBufferBindingMap;
00467     protected:
00468         VertexBufferBindingMap mBindingMap;
00469         mutable unsigned short mHighIndex;
00470     public:
00472         VertexBufferBinding();
00473         virtual ~VertexBufferBinding();
00482         virtual void setBinding(unsigned short index, HardwareVertexBufferSharedPtr buffer);
00484         virtual void unsetBinding(unsigned short index);
00485 
00487         virtual void unsetAllBindings(void);
00488 
00490         virtual const VertexBufferBindingMap& getBindings(void) const;
00491 
00493         virtual HardwareVertexBufferSharedPtr getBuffer(unsigned short index);
00495         virtual bool isBufferBound(unsigned short index);
00496 
00497         virtual size_t getBufferCount(void) const { return mBindingMap.size(); }
00498 
00504         virtual unsigned short getNextIndex(void) const { return mHighIndex++; }
00505 
00506 
00507 
00508 
00509     };
00510 
00511 
00512 
00513 }
00514 #endif
00515 

Copyright © 2000-2005 by The OGRE Team
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Mar 12 14:37:42 2006