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 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); 00153 00154 inline bool operator== (const VertexElement& rhs) const 00155 { 00156 if (mType != rhs.mType || 00157 mIndex != rhs.mIndex || 00158 mOffset != rhs.mOffset || 00159 mSemantic != rhs.mSemantic || 00160 mSource != rhs.mSource) 00161 return false; 00162 else 00163 return true; 00164 00165 } 00173 inline void baseVertexPointerToElement(void* pBase, Real** pElem) const 00174 { 00175 // The only way we can do this is to cast to char* in order to use byte offset 00176 // then cast back to Real*. However we have to go via void* because casting 00177 // directly is not allowed 00178 *pElem = static_cast<Real*>( 00179 static_cast<void*>( 00180 static_cast<unsigned char*>(pBase) + mOffset)); 00181 } 00182 00190 inline void baseVertexPointerToElement(void* pBase, RGBA** pElem) const 00191 { 00192 *pElem = static_cast<RGBA*>( 00193 static_cast<void*>( 00194 static_cast<unsigned char*>(pBase) + mOffset)); 00195 } 00203 inline void baseVertexPointerToElement(void* pBase, unsigned char** pElem) const 00204 { 00205 *pElem = static_cast<unsigned char*>(pBase) + mOffset; 00206 } 00207 00215 inline void baseVertexPointerToElement(void* pBase, unsigned short** pElem) const 00216 { 00217 *pElem = static_cast<unsigned short*>(pBase) + mOffset; 00218 } 00219 00220 00221 }; 00244 class _OgreExport VertexDeclaration 00245 { 00246 public: 00248 typedef std::list<VertexElement> VertexElementList; 00249 protected: 00250 VertexElementList mElementList; 00251 public: 00253 VertexDeclaration(); 00254 virtual ~VertexDeclaration(); 00255 00257 const VertexElementList& getElements(void) const; 00259 const VertexElement* getElement(unsigned short index); 00260 00274 virtual const VertexElement& addElement(unsigned short source, size_t offset, VertexElementType theType, 00275 VertexElementSemantic semantic, unsigned short index = 0); 00289 virtual const VertexElement& insertElement(unsigned short atPosition, 00290 unsigned short source, size_t offset, VertexElementType theType, 00291 VertexElementSemantic semantic, unsigned short index = 0); 00292 00294 virtual void removeElement(unsigned short elem_index); 00295 00302 virtual void removeElement(VertexElementSemantic semantic, unsigned short index = 0); 00303 00309 virtual void modifyElement(unsigned short elem_index, unsigned short source, size_t offset, VertexElementType theType, 00310 VertexElementSemantic semantic, unsigned short index = 0); 00311 00317 virtual const VertexElement* findElementBySemantic(VertexElementSemantic sem, unsigned short index = 0); 00327 virtual VertexElementList findElementsBySource(unsigned short source); 00328 00330 virtual size_t getVertexSize(unsigned short source); 00331 00333 virtual VertexDeclaration* clone(void); 00334 00335 inline bool operator== (const VertexDeclaration& rhs) const 00336 { 00337 if (mElementList.size() != rhs.mElementList.size()) 00338 return false; 00339 00340 VertexElementList::const_iterator i, iend, rhsi, rhsiend; 00341 iend = mElementList.end(); 00342 rhsiend = rhs.mElementList.end(); 00343 rhsi = rhs.mElementList.begin(); 00344 for (i = mElementList.begin(); i != iend && rhsi != rhsiend; ++i, ++rhsi) 00345 { 00346 if ( !(i == rhsi) ) 00347 return false; 00348 } 00349 00350 return true; 00351 } 00352 00353 }; 00354 00368 class _OgreExport VertexBufferBinding 00369 { 00370 public: 00372 typedef std::map<unsigned short, HardwareVertexBufferSharedPtr> VertexBufferBindingMap; 00373 protected: 00374 VertexBufferBindingMap mBindingMap; 00375 mutable unsigned short mHighIndex; 00376 public: 00378 VertexBufferBinding(); 00379 virtual ~VertexBufferBinding(); 00388 virtual void setBinding(unsigned short index, HardwareVertexBufferSharedPtr buffer); 00390 virtual void unsetBinding(unsigned short index); 00391 00393 virtual void unsetAllBindings(void); 00394 00396 virtual const VertexBufferBindingMap& getBindings(void) const; 00397 00399 virtual HardwareVertexBufferSharedPtr getBuffer(unsigned short index); 00400 00406 virtual unsigned short getNextIndex(void) const { return mHighIndex++; } 00407 00408 00409 00410 00411 }; 00412 00413 00414 00415 } 00416 #endif 00417
Copyright © 2002-2003 by The OGRE Team
Last modified Fri May 14 23:22:17 2004