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*>(pBase) + mOffset; 00277 } 00278 00279 00280 }; 00303 class _OgreExport VertexDeclaration : public VertexDataAlloc 00304 { 00305 public: 00307 typedef list<VertexElement>::type VertexElementList; 00309 static bool vertexElementLess(const VertexElement& e1, const VertexElement& e2); 00310 protected: 00311 VertexElementList mElementList; 00312 public: 00314 VertexDeclaration(); 00315 virtual ~VertexDeclaration(); 00316 00318 size_t getElementCount(void) { return mElementList.size(); } 00320 const VertexElementList& getElements(void) const; 00322 const VertexElement* getElement(unsigned short index); 00323 00332 void sort(void); 00333 00344 void closeGapsInSource(void); 00345 00356 VertexDeclaration* getAutoOrganisedDeclaration(bool skeletalAnimation, 00357 bool vertexAnimation); 00358 00360 unsigned short getMaxSource(void) const; 00361 00362 00363 00377 virtual const VertexElement& addElement(unsigned short source, size_t offset, VertexElementType theType, 00378 VertexElementSemantic semantic, unsigned short index = 0); 00392 virtual const VertexElement& insertElement(unsigned short atPosition, 00393 unsigned short source, size_t offset, VertexElementType theType, 00394 VertexElementSemantic semantic, unsigned short index = 0); 00395 00397 virtual void removeElement(unsigned short elem_index); 00398 00405 virtual void removeElement(VertexElementSemantic semantic, unsigned short index = 0); 00406 00408 virtual void removeAllElements(void); 00409 00415 virtual void modifyElement(unsigned short elem_index, unsigned short source, size_t offset, VertexElementType theType, 00416 VertexElementSemantic semantic, unsigned short index = 0); 00417 00423 virtual const VertexElement* findElementBySemantic(VertexElementSemantic sem, unsigned short index = 0); 00433 virtual VertexElementList findElementsBySource(unsigned short source); 00434 00436 virtual size_t getVertexSize(unsigned short source); 00437 00442 virtual VertexDeclaration* clone(HardwareBufferManagerBase* mgr = 0); 00443 00444 inline bool operator== (const VertexDeclaration& rhs) const 00445 { 00446 if (mElementList.size() != rhs.mElementList.size()) 00447 return false; 00448 00449 VertexElementList::const_iterator i, iend, rhsi, rhsiend; 00450 iend = mElementList.end(); 00451 rhsiend = rhs.mElementList.end(); 00452 rhsi = rhs.mElementList.begin(); 00453 for (i = mElementList.begin(); i != iend && rhsi != rhsiend; ++i, ++rhsi) 00454 { 00455 if ( !(*i == *rhsi) ) 00456 return false; 00457 } 00458 00459 return true; 00460 } 00461 inline bool operator!= (const VertexDeclaration& rhs) const 00462 { 00463 return !(*this == rhs); 00464 } 00465 00466 }; 00467 00481 class _OgreExport VertexBufferBinding : public VertexDataAlloc 00482 { 00483 public: 00485 typedef map<unsigned short, HardwareVertexBufferSharedPtr>::type VertexBufferBindingMap; 00486 protected: 00487 VertexBufferBindingMap mBindingMap; 00488 mutable unsigned short mHighIndex; 00489 public: 00491 VertexBufferBinding(); 00492 virtual ~VertexBufferBinding(); 00501 virtual void setBinding(unsigned short index, const HardwareVertexBufferSharedPtr& buffer); 00503 virtual void unsetBinding(unsigned short index); 00504 00506 virtual void unsetAllBindings(void); 00507 00509 virtual const VertexBufferBindingMap& getBindings(void) const; 00510 00512 virtual const HardwareVertexBufferSharedPtr& getBuffer(unsigned short index) const; 00514 virtual bool isBufferBound(unsigned short index) const; 00515 00516 virtual size_t getBufferCount(void) const { return mBindingMap.size(); } 00517 00523 virtual unsigned short getNextIndex(void) const { return mHighIndex++; } 00524 00527 virtual unsigned short getLastBoundIndex(void) const; 00528 00529 typedef map<ushort, ushort>::type BindingIndexMap; 00530 00533 virtual bool hasGaps(void) const; 00534 00547 virtual void closeGaps(BindingIndexMap& bindingIndexMap); 00548 00549 00550 }; 00556 } 00557 #endif 00558
Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Thu Dec 31 16:27:09 2009