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-2012 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 bool mIsInstanceData; 00055 size_t mInstanceDataStepRate; 00057 virtual bool checkIfVertexInstanceDataIsSupported(); 00058 00059 public: 00061 HardwareVertexBuffer(HardwareBufferManagerBase* mgr, size_t vertexSize, size_t numVertices, 00062 HardwareBuffer::Usage usage, bool useSystemMemory, bool useShadowBuffer); 00063 ~HardwareVertexBuffer(); 00065 HardwareBufferManagerBase* getManager() const { return mMgr; } 00067 size_t getVertexSize(void) const { return mVertexSize; } 00069 size_t getNumVertices(void) const { return mNumVertices; } 00071 bool getIsInstanceData() const { return mIsInstanceData; } 00073 void setIsInstanceData(const bool val); 00075 size_t getInstanceDataStepRate() const; 00077 void setInstanceDataStepRate(const size_t val); 00078 00079 00080 // NB subclasses should override lock, unlock, readData, writeData 00081 00082 }; 00083 00085 class _OgreExport HardwareVertexBufferSharedPtr : public SharedPtr<HardwareVertexBuffer> 00086 { 00087 public: 00088 HardwareVertexBufferSharedPtr() : SharedPtr<HardwareVertexBuffer>() {} 00089 explicit HardwareVertexBufferSharedPtr(HardwareVertexBuffer* buf); 00090 00091 00092 }; 00093 00095 enum VertexElementSemantic { 00097 VES_POSITION = 1, 00099 VES_BLEND_WEIGHTS = 2, 00101 VES_BLEND_INDICES = 3, 00103 VES_NORMAL = 4, 00105 VES_DIFFUSE = 5, 00107 VES_SPECULAR = 6, 00109 VES_TEXTURE_COORDINATES = 7, 00111 VES_BINORMAL = 8, 00113 VES_TANGENT = 9, 00115 VES_COUNT = 9 00116 }; 00117 00119 enum VertexElementType 00120 { 00121 VET_FLOAT1 = 0, 00122 VET_FLOAT2 = 1, 00123 VET_FLOAT3 = 2, 00124 VET_FLOAT4 = 3, 00126 VET_COLOUR = 4, 00127 VET_SHORT1 = 5, 00128 VET_SHORT2 = 6, 00129 VET_SHORT3 = 7, 00130 VET_SHORT4 = 8, 00131 VET_UBYTE4 = 9, 00133 VET_COLOUR_ARGB = 10, 00135 VET_COLOUR_ABGR = 11 00136 }; 00137 00147 class _OgreExport VertexElement : public VertexDataAlloc 00148 { 00149 protected: 00151 unsigned short mSource; 00153 size_t mOffset; 00155 VertexElementType mType; 00157 VertexElementSemantic mSemantic; 00159 unsigned short mIndex; 00160 public: 00162 VertexElement() {} 00164 VertexElement(unsigned short source, size_t offset, VertexElementType theType, 00165 VertexElementSemantic semantic, unsigned short index = 0); 00167 unsigned short getSource(void) const { return mSource; } 00169 size_t getOffset(void) const { return mOffset; } 00171 VertexElementType getType(void) const { return mType; } 00173 VertexElementSemantic getSemantic(void) const { return mSemantic; } 00175 unsigned short getIndex(void) const { return mIndex; } 00177 size_t getSize(void) const; 00179 static size_t getTypeSize(VertexElementType etype); 00181 static unsigned short getTypeCount(VertexElementType etype); 00185 static VertexElementType multiplyTypeCount(VertexElementType baseType, unsigned short count); 00189 static VertexElementType getBaseType(VertexElementType multiType); 00190 00197 static void convertColourValue(VertexElementType srcType, 00198 VertexElementType dstType, uint32* ptr); 00199 00205 static uint32 convertColourValue(const ColourValue& src, 00206 VertexElementType dst); 00207 00209 static VertexElementType getBestColourVertexElementType(void); 00210 00211 inline bool operator== (const VertexElement& rhs) const 00212 { 00213 if (mType != rhs.mType || 00214 mIndex != rhs.mIndex || 00215 mOffset != rhs.mOffset || 00216 mSemantic != rhs.mSemantic || 00217 mSource != rhs.mSource) 00218 return false; 00219 else 00220 return true; 00221 00222 } 00230 inline void baseVertexPointerToElement(void* pBase, void** pElem) const 00231 { 00232 // The only way we can do this is to cast to char* in order to use byte offset 00233 // then cast back to void*. 00234 *pElem = static_cast<void*>( 00235 static_cast<unsigned char*>(pBase) + mOffset); 00236 } 00244 inline void baseVertexPointerToElement(void* pBase, float** pElem) const 00245 { 00246 // The only way we can do this is to cast to char* in order to use byte offset 00247 // then cast back to float*. However we have to go via void* because casting 00248 // directly is not allowed 00249 *pElem = static_cast<float*>( 00250 static_cast<void*>( 00251 static_cast<unsigned char*>(pBase) + mOffset)); 00252 } 00253 00261 inline void baseVertexPointerToElement(void* pBase, RGBA** pElem) const 00262 { 00263 *pElem = static_cast<RGBA*>( 00264 static_cast<void*>( 00265 static_cast<unsigned char*>(pBase) + mOffset)); 00266 } 00274 inline void baseVertexPointerToElement(void* pBase, unsigned char** pElem) const 00275 { 00276 *pElem = static_cast<unsigned char*>(pBase) + mOffset; 00277 } 00278 00286 inline void baseVertexPointerToElement(void* pBase, unsigned short** pElem) const 00287 { 00288 *pElem = static_cast<unsigned short*>( 00289 static_cast<void*>( 00290 static_cast<unsigned char*>(pBase) + mOffset)); 00291 } 00292 00293 00294 }; 00317 class _OgreExport VertexDeclaration : public VertexDataAlloc 00318 { 00319 public: 00321 typedef list<VertexElement>::type VertexElementList; 00323 static bool vertexElementLess(const VertexElement& e1, const VertexElement& e2); 00324 protected: 00325 VertexElementList mElementList; 00326 public: 00328 VertexDeclaration(); 00329 virtual ~VertexDeclaration(); 00330 00332 size_t getElementCount(void) const { return mElementList.size(); } 00334 const VertexElementList& getElements(void) const; 00336 const VertexElement* getElement(unsigned short index) const; 00337 00346 void sort(void); 00347 00358 void closeGapsInSource(void); 00359 00371 VertexDeclaration* getAutoOrganisedDeclaration(bool skeletalAnimation, 00372 bool vertexAnimation, bool vertexAnimationNormals) const; 00373 00375 unsigned short getMaxSource(void) const; 00376 00377 00378 00392 virtual const VertexElement& addElement(unsigned short source, size_t offset, VertexElementType theType, 00393 VertexElementSemantic semantic, unsigned short index = 0); 00407 virtual const VertexElement& insertElement(unsigned short atPosition, 00408 unsigned short source, size_t offset, VertexElementType theType, 00409 VertexElementSemantic semantic, unsigned short index = 0); 00410 00412 virtual void removeElement(unsigned short elem_index); 00413 00420 virtual void removeElement(VertexElementSemantic semantic, unsigned short index = 0); 00421 00423 virtual void removeAllElements(void); 00424 00430 virtual void modifyElement(unsigned short elem_index, unsigned short source, size_t offset, VertexElementType theType, 00431 VertexElementSemantic semantic, unsigned short index = 0); 00432 00438 virtual const VertexElement* findElementBySemantic(VertexElementSemantic sem, unsigned short index = 0) const; 00448 virtual VertexElementList findElementsBySource(unsigned short source) const; 00449 00451 virtual size_t getVertexSize(unsigned short source) const; 00452 00456 virtual unsigned short getNextFreeTextureCoordinate() const; 00457 00462 virtual VertexDeclaration* clone(HardwareBufferManagerBase* mgr = 0) const; 00463 00464 inline bool operator== (const VertexDeclaration& rhs) const 00465 { 00466 if (mElementList.size() != rhs.mElementList.size()) 00467 return false; 00468 00469 VertexElementList::const_iterator i, iend, rhsi, rhsiend; 00470 iend = mElementList.end(); 00471 rhsiend = rhs.mElementList.end(); 00472 rhsi = rhs.mElementList.begin(); 00473 for (i = mElementList.begin(); i != iend && rhsi != rhsiend; ++i, ++rhsi) 00474 { 00475 if ( !(*i == *rhsi) ) 00476 return false; 00477 } 00478 00479 return true; 00480 } 00481 inline bool operator!= (const VertexDeclaration& rhs) const 00482 { 00483 return !(*this == rhs); 00484 } 00485 00486 }; 00487 00501 class _OgreExport VertexBufferBinding : public VertexDataAlloc 00502 { 00503 public: 00505 typedef map<unsigned short, HardwareVertexBufferSharedPtr>::type VertexBufferBindingMap; 00506 protected: 00507 VertexBufferBindingMap mBindingMap; 00508 mutable unsigned short mHighIndex; 00509 public: 00511 VertexBufferBinding(); 00512 virtual ~VertexBufferBinding(); 00521 virtual void setBinding(unsigned short index, const HardwareVertexBufferSharedPtr& buffer); 00523 virtual void unsetBinding(unsigned short index); 00524 00526 virtual void unsetAllBindings(void); 00527 00529 virtual const VertexBufferBindingMap& getBindings(void) const; 00530 00532 virtual const HardwareVertexBufferSharedPtr& getBuffer(unsigned short index) const; 00534 virtual bool isBufferBound(unsigned short index) const; 00535 00536 virtual size_t getBufferCount(void) const { return mBindingMap.size(); } 00537 00543 virtual unsigned short getNextIndex(void) const { return mHighIndex++; } 00544 00547 virtual unsigned short getLastBoundIndex(void) const; 00548 00549 typedef map<ushort, ushort>::type BindingIndexMap; 00550 00553 virtual bool hasGaps(void) const; 00554 00567 virtual void closeGaps(BindingIndexMap& bindingIndexMap); 00568 00570 virtual bool getHasInstanceData() const; 00571 00572 00573 }; 00579 } 00580 #endif 00581
Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Fri May 25 23:36:24 2012