Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound 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 © 2000-2002 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         HardwareVertexBufferSharedPtr(HardwareVertexBuffer* buf);
00065 
00066 
00067     };
00068 
00070     enum VertexElementSemantic {
00072         VES_POSITION,
00074         VES_NORMAL,
00076         VES_BLEND_WEIGHTS,
00078         VES_BLEND_INDICES,
00080         VES_DIFFUSE,
00082         VES_SPECULAR,
00084         VES_TEXTURE_COORDINATES,
00086         VES_BINORMAL,
00088         VES_TANGENT
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     };
00105 
00115     class _OgreExport VertexElement
00116     {
00117     protected:
00119         unsigned short mSource;
00121         size_t mOffset;
00123         VertexElementType mType;
00125         VertexElementSemantic mSemantic;
00127         unsigned short mIndex;
00128     public:
00130         VertexElement(unsigned short source, size_t offset, VertexElementType theType,
00131             VertexElementSemantic semantic, unsigned short index = 0);
00133         unsigned short getSource(void) const { return mSource; }
00135         size_t getOffset(void) const { return mOffset; }
00137         VertexElementType getType(void) const { return mType; }
00139         VertexElementSemantic getSemantic(void) const { return mSemantic; }
00141         unsigned short getIndex(void) const { return mIndex; }
00143         size_t getSize(void) const;
00145         static size_t getTypeSize(VertexElementType etype);
00147         static unsigned short getTypeCount(VertexElementType etype);
00151         static VertexElementType multiplyTypeCount(VertexElementType baseType, unsigned short count);
00152 
00153         inline bool operator== (const VertexElement& rhs) const
00154         {
00155             if (mType != rhs.mType || 
00156                 mIndex != rhs.mIndex ||
00157                 mOffset != rhs.mOffset ||
00158                 mSemantic != rhs.mSemantic ||
00159                 mSource != rhs.mSource)
00160                 return false;
00161             else
00162                 return true;
00163 
00164         }
00172         inline void baseVertexPointerToElement(void* pBase, Real** pElem) const
00173         {
00174             // The only way we can do this is to cast to char* in order to use byte offset
00175             // then cast back to Real*. However we have to go via void* because casting  
00176             // directly is not allowed
00177             *pElem = static_cast<Real*>(
00178                 static_cast<void*>(
00179                     static_cast<unsigned char*>(pBase) + mOffset));
00180         }
00181 
00189         inline void baseVertexPointerToElement(void* pBase, RGBA** pElem) const
00190         {
00191             *pElem = static_cast<RGBA*>(
00192                 static_cast<void*>(
00193                     static_cast<unsigned char*>(pBase) + mOffset));
00194         }
00202         inline void baseVertexPointerToElement(void* pBase, unsigned char** pElem) const
00203         {
00204             *pElem = static_cast<unsigned char*>(pBase) + mOffset;
00205         }
00206 
00207 
00208 
00209     };
00232     class _OgreExport VertexDeclaration
00233     {
00234     public:
00236         typedef std::vector<VertexElement> VertexElementList;
00237     protected:
00238         VertexElementList mElementList;
00239     public:
00241         VertexDeclaration();
00242         virtual ~VertexDeclaration();
00243         
00245         const VertexElementList& getElements(void) const;
00246 
00260         virtual const VertexElement& addElement(unsigned short source, size_t offset, VertexElementType theType,
00261             VertexElementSemantic semantic, unsigned short index = 0);
00262 
00264         virtual void removeElement(unsigned short elem_index);
00265 
00272         virtual void removeElement(VertexElementSemantic semantic, unsigned short index = 0);
00273 
00279         virtual void modifyElement(unsigned short elem_index, unsigned short source, size_t offset, VertexElementType theType,
00280             VertexElementSemantic semantic, unsigned short index = 0);
00281 
00287         virtual const VertexElement* findElementBySemantic(VertexElementSemantic sem, unsigned short index = 0);
00297         virtual VertexElementList findElementsBySource(unsigned short source);
00298         
00300         virtual size_t getVertexSize(unsigned short source);
00301 
00303         virtual VertexDeclaration* clone(void);
00304 
00305         inline bool operator== (const VertexDeclaration& rhs) const
00306         {
00307             if (mElementList.size() != rhs.mElementList.size())
00308                 return false;
00309 
00310             VertexElementList::const_iterator i, iend, rhsi, rhsiend;
00311             iend = mElementList.end();
00312             rhsiend = rhs.mElementList.end();
00313             rhsi = rhs.mElementList.begin();
00314             for (i = mElementList.begin(); i != iend && rhsi != rhsiend; ++i, ++rhsi)
00315             {
00316                 if ( !(i == rhsi) )
00317                     return false;
00318             }
00319 
00320             return true;
00321         }
00322 
00323     };
00324 
00338     class _OgreExport VertexBufferBinding
00339     {
00340     public:
00342         typedef std::map<unsigned short, HardwareVertexBufferSharedPtr> VertexBufferBindingMap;
00343     protected:
00344         VertexBufferBindingMap mBindingMap;
00345         unsigned short mHighIndex;
00346     public:
00348         VertexBufferBinding();
00349         virtual ~VertexBufferBinding();
00358         virtual void setBinding(unsigned short index, HardwareVertexBufferSharedPtr buffer);
00360         virtual void unsetBinding(unsigned short index);
00361 
00363         virtual void unsetAllBindings(void);
00364 
00366         virtual const VertexBufferBindingMap& getBindings(void) const;
00367 
00369         virtual HardwareVertexBufferSharedPtr getBuffer(unsigned short index);
00370 
00376         virtual unsigned short getNextIndex(void) const { return mHighIndex; }
00377 
00378 
00379 
00380 
00381     };
00382 
00383 
00384 
00385 }
00386 #endif
00387 

Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:13 2004