OgreHardwareVertexBuffer.h
Go to the documentation of this file.
/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2013 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#ifndef __HardwareVertexBuffer__
#define __HardwareVertexBuffer__
// Precompiler options
#include "OgrePrerequisites.h"
#include "OgreHardwareBuffer.h"
#include "OgreSharedPtr.h"
#include "OgreColourValue.h"
#include "OgreHeaderPrefix.h"
namespace Ogre {
class HardwareBufferManagerBase;
class _OgreExport HardwareVertexBuffer : public HardwareBuffer
{
protected:
HardwareBufferManagerBase* mMgr;
size_t mNumVertices;
size_t mVertexSize;
bool mIsInstanceData;
size_t mInstanceDataStepRate;
virtual bool checkIfVertexInstanceDataIsSupported();
public:
HardwareVertexBuffer(HardwareBufferManagerBase* mgr, size_t vertexSize, size_t numVertices,
HardwareBuffer::Usage usage, bool useSystemMemory, bool useShadowBuffer);
~HardwareVertexBuffer();
HardwareBufferManagerBase* getManager() const { return mMgr; }
size_t getVertexSize(void) const { return mVertexSize; }
size_t getNumVertices(void) const { return mNumVertices; }
bool isInstanceData() const { return mIsInstanceData; }
void setIsInstanceData(const bool val);
size_t getInstanceDataStepRate() const;
void setInstanceDataStepRate(const size_t val);
// NB subclasses should override lock, unlock, readData, writeData
};
class _OgreExport HardwareVertexBufferSharedPtr : public SharedPtr<HardwareVertexBuffer>
{
public:
HardwareVertexBufferSharedPtr() : SharedPtr<HardwareVertexBuffer>() {}
explicit HardwareVertexBufferSharedPtr(HardwareVertexBuffer* buf);
};
typedef HardwareBufferLockGuard<HardwareVertexBufferSharedPtr> HardwareVertexBufferLockGuard;
enum VertexElementSemantic {
VES_POSITION = 1,
VES_BLEND_WEIGHTS = 2,
VES_BLEND_INDICES = 3,
VES_NORMAL = 4,
VES_DIFFUSE = 5,
VES_SPECULAR = 6,
VES_TEXTURE_COORDINATES = 7,
VES_BINORMAL = 8,
VES_TANGENT = 9,
VES_COUNT = 9
};
enum VertexElementType
{
VET_FLOAT1 = 0,
VET_FLOAT2 = 1,
VET_FLOAT3 = 2,
VET_FLOAT4 = 3,
VET_COLOUR = 4,
VET_SHORT1 = 5,
VET_SHORT2 = 6,
VET_SHORT3 = 7,
VET_SHORT4 = 8,
VET_UBYTE4 = 9,
VET_COLOUR_ARGB = 10,
VET_COLOUR_ABGR = 11,
VET_DOUBLE1 = 12,
VET_DOUBLE2 = 13,
VET_DOUBLE3 = 14,
VET_DOUBLE4 = 15,
VET_USHORT1 = 16,
VET_USHORT2 = 17,
VET_USHORT3 = 18,
VET_USHORT4 = 19,
VET_INT1 = 20,
VET_INT2 = 21,
VET_INT3 = 22,
VET_INT4 = 23,
VET_UINT1 = 24,
VET_UINT2 = 25,
VET_UINT3 = 26,
VET_UINT4 = 27
};
class _OgreExport VertexElement : public VertexDataAlloc
{
protected:
unsigned short mSource;
size_t mOffset;
VertexElementType mType;
VertexElementSemantic mSemantic;
unsigned short mIndex;
public:
VertexElement() {}
VertexElement(unsigned short source, size_t offset, VertexElementType theType,
VertexElementSemantic semantic, unsigned short index = 0);
unsigned short getSource(void) const { return mSource; }
size_t getOffset(void) const { return mOffset; }
VertexElementType getType(void) const { return mType; }
VertexElementSemantic getSemantic(void) const { return mSemantic; }
unsigned short getIndex(void) const { return mIndex; }
size_t getSize(void) const;
static size_t getTypeSize(VertexElementType etype);
static unsigned short getTypeCount(VertexElementType etype);
static VertexElementType multiplyTypeCount(VertexElementType baseType, unsigned short count);
static VertexElementType getBaseType(VertexElementType multiType);
static void convertColourValue(VertexElementType srcType,
VertexElementType dstType, uint32* ptr);
static uint32 convertColourValue(const ColourValue& src,
VertexElementType dst);
static VertexElementType getBestColourVertexElementType(void);
inline bool operator== (const VertexElement& rhs) const
{
if (mType != rhs.mType ||
mIndex != rhs.mIndex ||
mOffset != rhs.mOffset ||
mSemantic != rhs.mSemantic ||
mSource != rhs.mSource)
return false;
else
return true;
}
inline void baseVertexPointerToElement(void* pBase, void** pElem) const
{
// The only way we can do this is to cast to char* in order to use byte offset
// then cast back to void*.
*pElem = static_cast<void*>(
static_cast<unsigned char*>(pBase) + mOffset);
}
inline void baseVertexPointerToElement(void* pBase, float** pElem) const
{
// The only way we can do this is to cast to char* in order to use byte offset
// then cast back to float*. However we have to go via void* because casting
// directly is not allowed
*pElem = static_cast<float*>(
static_cast<void*>(
static_cast<unsigned char*>(pBase) + mOffset));
}
inline void baseVertexPointerToElement(void* pBase, RGBA** pElem) const
{
*pElem = static_cast<RGBA*>(
static_cast<void*>(
static_cast<unsigned char*>(pBase) + mOffset));
}
inline void baseVertexPointerToElement(void* pBase, unsigned char** pElem) const
{
*pElem = static_cast<unsigned char*>(pBase) + mOffset;
}
inline void baseVertexPointerToElement(void* pBase, unsigned short** pElem) const
{
*pElem = static_cast<unsigned short*>(
static_cast<void*>(
static_cast<unsigned char*>(pBase) + mOffset));
}
};
class _OgreExport VertexDeclaration : public VertexDataAlloc
{
public:
typedef list<VertexElement>::type VertexElementList;
static bool vertexElementLess(const VertexElement& e1, const VertexElement& e2);
protected:
VertexElementList mElementList;
public:
VertexDeclaration();
virtual ~VertexDeclaration();
size_t getElementCount(void) const { return mElementList.size(); }
const VertexElementList& getElements(void) const;
const VertexElement* getElement(unsigned short index) const;
void sort(void);
void closeGapsInSource(void);
VertexDeclaration* getAutoOrganisedDeclaration(bool skeletalAnimation,
bool vertexAnimation, bool vertexAnimationNormals) const;
unsigned short getMaxSource(void) const;
virtual const VertexElement& addElement(unsigned short source, size_t offset, VertexElementType theType,
VertexElementSemantic semantic, unsigned short index = 0);
virtual const VertexElement& insertElement(unsigned short atPosition,
unsigned short source, size_t offset, VertexElementType theType,
VertexElementSemantic semantic, unsigned short index = 0);
virtual void removeElement(unsigned short elem_index);
virtual void removeElement(VertexElementSemantic semantic, unsigned short index = 0);
virtual void removeAllElements(void);
virtual void modifyElement(unsigned short elem_index, unsigned short source, size_t offset, VertexElementType theType,
VertexElementSemantic semantic, unsigned short index = 0);
virtual const VertexElement* findElementBySemantic(VertexElementSemantic sem, unsigned short index = 0) const;
virtual VertexElementList findElementsBySource(unsigned short source) const;
virtual size_t getVertexSize(unsigned short source) const;
virtual unsigned short getNextFreeTextureCoordinate() const;
virtual VertexDeclaration* clone(HardwareBufferManagerBase* mgr = 0) const;
inline bool operator== (const VertexDeclaration& rhs) const
{
if (mElementList.size() != rhs.mElementList.size())
return false;
VertexElementList::const_iterator i, iend, rhsi, rhsiend;
iend = mElementList.end();
rhsiend = rhs.mElementList.end();
rhsi = rhs.mElementList.begin();
for (i = mElementList.begin(); i != iend && rhsi != rhsiend; ++i, ++rhsi)
{
if ( !(*i == *rhsi) )
return false;
}
return true;
}
inline bool operator!= (const VertexDeclaration& rhs) const
{
return !(*this == rhs);
}
};
class _OgreExport VertexBufferBinding : public VertexDataAlloc
{
public:
typedef map<unsigned short, HardwareVertexBufferSharedPtr>::type VertexBufferBindingMap;
protected:
VertexBufferBindingMap mBindingMap;
mutable unsigned short mHighIndex;
public:
VertexBufferBinding();
virtual ~VertexBufferBinding();
virtual void setBinding(unsigned short index, const HardwareVertexBufferSharedPtr& buffer);
virtual void unsetBinding(unsigned short index);
virtual void unsetAllBindings(void);
virtual const VertexBufferBindingMap& getBindings(void) const;
virtual const HardwareVertexBufferSharedPtr& getBuffer(unsigned short index) const;
virtual bool isBufferBound(unsigned short index) const;
virtual size_t getBufferCount(void) const { return mBindingMap.size(); }
virtual unsigned short getNextIndex(void) const { return mHighIndex++; }
virtual unsigned short getLastBoundIndex(void) const;
typedef map<ushort, ushort>::type BindingIndexMap;
virtual bool hasGaps(void) const;
virtual void closeGaps(BindingIndexMap& bindingIndexMap);
virtual bool hasInstanceData() const;
};
}
#include "OgreHeaderSuffix.h"
#endif
Ogre::VET_UINT4
Definition: OgreHardwareVertexBuffer.h:155
Ogre::VertexElement::getType
VertexElementType getType(void) const
Gets the data format of this element.
Definition: OgreHardwareVertexBuffer.h:191
Ogre::VET_USHORT2
Definition: OgreHardwareVertexBuffer.h:145
Ogre::VertexDeclaration::VertexElementList
list< VertexElement >::type VertexElementList
Defines the list of vertex elements that makes up this declaration.
Definition: OgreHardwareVertexBuffer.h:341
_OgreExport
#define _OgreExport
Definition: OgrePlatform.h:257
Ogre::VertexElement::mSource
unsigned short mSource
The source vertex buffer, as bound to an index using VertexBufferBinding.
Definition: OgreHardwareVertexBuffer.h:171
Ogre::list
Definition: OgrePrerequisites.h:505
Ogre::VertexElementType
VertexElementType
Vertex element type, used to identify the base types of the vertex contents.
Definition: OgreHardwareVertexBuffer.h:123
Ogre::VertexElement::baseVertexPointerToElement
void baseVertexPointerToElement(void *pBase, unsigned short **pElem) const
Adjusts a pointer to the base of a vertex to point at this element.
Definition: OgreHardwareVertexBuffer.h:306
Ogre::VET_COLOUR_ABGR
GL style compact colour.
Definition: OgreHardwareVertexBuffer.h:139
OgreSharedPtr.h
Ogre::VET_USHORT3
Definition: OgreHardwareVertexBuffer.h:146
Ogre::VertexElement::getSource
unsigned short getSource(void) const
Gets the vertex buffer index from where this element draws it&#39;s values.
Definition: OgreHardwareVertexBuffer.h:187
Ogre::VertexElement::VertexElement
VertexElement()
Constructor, should not be called directly, only needed because of list.
Definition: OgreHardwareVertexBuffer.h:182
Ogre::VertexElement::baseVertexPointerToElement
void baseVertexPointerToElement(void *pBase, float **pElem) const
Adjusts a pointer to the base of a vertex to point at this element.
Definition: OgreHardwareVertexBuffer.h:264
Ogre::VET_COLOUR
alias to more specific colour type - use the current rendersystem&#39;s colour packing ...
Definition: OgreHardwareVertexBuffer.h:130
Ogre::ColourValue
Class representing colour.
Definition: OgreColourValue.h:57
Ogre::VET_SHORT3
Definition: OgreHardwareVertexBuffer.h:133
Ogre::HardwareVertexBuffer
Specialisation of HardwareBuffer for a vertex buffer.
Definition: OgreHardwareVertexBuffer.h:48
Ogre::VertexBufferBinding::getBufferCount
virtual size_t getBufferCount(void) const
Definition: OgreHardwareVertexBuffer.h:556
Ogre::VET_SHORT4
Definition: OgreHardwareVertexBuffer.h:134
Ogre::HardwareVertexBuffer::isInstanceData
bool isInstanceData() const
Get if this vertex buffer is an "instance data" buffer (per instance)
Definition: OgreHardwareVertexBuffer.h:72
Ogre::VES_SPECULAR
Specular colours.
Definition: OgreHardwareVertexBuffer.h:111
Ogre::VertexDeclaration::getElementCount
size_t getElementCount(void) const
Get the number of elements in the declaration.
Definition: OgreHardwareVertexBuffer.h:352
Ogre::VertexBufferBinding::mBindingMap
VertexBufferBindingMap mBindingMap
Definition: OgreHardwareVertexBuffer.h:527
Ogre::VertexDeclaration::mElementList
VertexElementList mElementList
Definition: OgreHardwareVertexBuffer.h:345
Ogre::VES_TEXTURE_COORDINATES
Texture coordinates.
Definition: OgreHardwareVertexBuffer.h:113
Ogre::VES_POSITION
Position, 3 reals per vertex.
Definition: OgreHardwareVertexBuffer.h:101
Ogre::VES_DIFFUSE
Diffuse colours.
Definition: OgreHardwareVertexBuffer.h:109
Ogre::VET_FLOAT3
Definition: OgreHardwareVertexBuffer.h:127
Ogre::VET_USHORT1
Definition: OgreHardwareVertexBuffer.h:144
Ogre::VES_BLEND_INDICES
Blending indices.
Definition: OgreHardwareVertexBuffer.h:105
Ogre::VET_INT4
Definition: OgreHardwareVertexBuffer.h:151
Ogre::VertexBufferBinding::mHighIndex
unsigned short mHighIndex
Definition: OgreHardwareVertexBuffer.h:528
Ogre::VertexDeclaration
This class declares the format of a set of vertex inputs, which can be issued to the rendering API th...
Definition: OgreHardwareVertexBuffer.h:337
Ogre::VET_DOUBLE3
Definition: OgreHardwareVertexBuffer.h:142
Ogre::HardwareVertexBufferSharedPtr
Shared pointer implementation used to share vertex buffers.
Definition: OgreHardwareVertexBuffer.h:86
Ogre::VertexElement::getOffset
size_t getOffset(void) const
Gets the offset into the buffer where this element starts.
Definition: OgreHardwareVertexBuffer.h:189
OgrePrerequisites.h
Ogre::VertexElement::getSemantic
VertexElementSemantic getSemantic(void) const
Gets the meaning of this element.
Definition: OgreHardwareVertexBuffer.h:193
Ogre::map::type
std::map< K, V, P, A > type
Definition: OgrePrerequisites.h:536
Ogre::VertexElement::baseVertexPointerToElement
void baseVertexPointerToElement(void *pBase, unsigned char **pElem) const
Adjusts a pointer to the base of a vertex to point at this element.
Definition: OgreHardwareVertexBuffer.h:294
Ogre::HardwareBufferManagerBase
Base definition of a hardware buffer manager.
Definition: OgreHardwareBufferManager.h:113
Ogre::VET_DOUBLE1
Definition: OgreHardwareVertexBuffer.h:140
Ogre::HardwareVertexBufferLockGuard
HardwareBufferLockGuard< HardwareVertexBufferSharedPtr > HardwareVertexBufferLockGuard
Locking helper.
Definition: OgreHardwareVertexBuffer.h:96
Ogre::VET_UBYTE4
Definition: OgreHardwareVertexBuffer.h:135
Ogre::HardwareVertexBuffer::mInstanceDataStepRate
size_t mInstanceDataStepRate
Definition: OgreHardwareVertexBuffer.h:56
Ogre::VET_INT2
Definition: OgreHardwareVertexBuffer.h:149
Ogre::VertexBufferBinding::VertexBufferBindingMap
map< unsigned short, HardwareVertexBufferSharedPtr >::type VertexBufferBindingMap
Defines the vertex buffer bindings used as source for vertex declarations.
Definition: OgreHardwareVertexBuffer.h:525
Ogre::VET_UINT1
Definition: OgreHardwareVertexBuffer.h:152
Ogre::VET_INT3
Definition: OgreHardwareVertexBuffer.h:150
Ogre::VertexElement::mType
VertexElementType mType
The type of element.
Definition: OgreHardwareVertexBuffer.h:175
Ogre::VET_FLOAT4
Definition: OgreHardwareVertexBuffer.h:128
Ogre::operator!=
bool operator!=(STLAllocator< T, P > const &, STLAllocator< T2, P > const &)
determine equality, can memory from another allocator be released by this allocator, (ISO C++)
Definition: OgreMemorySTLAllocator.h:202
Ogre::VertexBufferBinding::BindingIndexMap
map< ushort, ushort >::type BindingIndexMap
Definition: OgreHardwareVertexBuffer.h:569
Ogre::HardwareBuffer::Usage
Usage
Enums describing buffer usage; not mutually exclusive.
Definition: OgreHardwareBuffer.h:79
Ogre::HardwareVertexBuffer::getNumVertices
size_t getNumVertices(void) const
Get the number of vertices in this buffer.
Definition: OgreHardwareVertexBuffer.h:70
Ogre::VertexBufferBinding::getNextIndex
virtual unsigned short getNextIndex(void) const
Gets the highest index which has already been set, plus 1.
Definition: OgreHardwareVertexBuffer.h:563
Ogre::HardwareVertexBuffer::getManager
HardwareBufferManagerBase * getManager() const
Return the manager of this buffer, if any.
Definition: OgreHardwareVertexBuffer.h:66
Ogre::HardwareVertexBuffer::getVertexSize
size_t getVertexSize(void) const
Gets the size in bytes of a single vertex in this buffer.
Definition: OgreHardwareVertexBuffer.h:68
Ogre::VertexElementSemantic
VertexElementSemantic
Vertex element semantics, used to identify the meaning of vertex buffer contents. ...
Definition: OgreHardwareVertexBuffer.h:99
Ogre::HardwareVertexBuffer::mNumVertices
size_t mNumVertices
Definition: OgreHardwareVertexBuffer.h:53
Ogre::HardwareBuffer
Abstract class defining common features of hardware buffers.
Definition: OgreHardwareBuffer.h:74
Ogre::VES_BLEND_WEIGHTS
Blending weights.
Definition: OgreHardwareVertexBuffer.h:103
Ogre::VET_DOUBLE4
Definition: OgreHardwareVertexBuffer.h:143
Ogre::VES_TANGENT
Tangent (X axis if normal is Z)
Definition: OgreHardwareVertexBuffer.h:117
Ogre::VET_INT1
Definition: OgreHardwareVertexBuffer.h:148
OgreHeaderSuffix.h
Ogre::VertexElement::mSemantic
VertexElementSemantic mSemantic
The meaning of the element.
Definition: OgreHardwareVertexBuffer.h:177
Ogre::VertexBufferBinding
Records the state of all the vertex buffer bindings required to provide a vertex declaration with the...
Definition: OgreHardwareVertexBuffer.h:521
Ogre::HardwareBufferLockGuard
Locking helper.
Definition: OgreHardwareBuffer.h:357
Ogre::HardwareVertexBuffer::mIsInstanceData
bool mIsInstanceData
Definition: OgreHardwareVertexBuffer.h:55
Ogre::VET_USHORT4
Definition: OgreHardwareVertexBuffer.h:147
Ogre::VertexElement
This class declares the usage of a single vertex buffer as a component of a complete VertexDeclaratio...
Definition: OgreHardwareVertexBuffer.h:167
Ogre::uint32
unsigned int uint32
Definition: OgrePlatform.h:359
Ogre::VertexElement::getIndex
unsigned short getIndex(void) const
Gets the index of this element, only applicable for repeating elements.
Definition: OgreHardwareVertexBuffer.h:195
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::VET_FLOAT2
Definition: OgreHardwareVertexBuffer.h:126
Ogre::VertexElement::baseVertexPointerToElement
void baseVertexPointerToElement(void *pBase, void **pElem) const
Adjusts a pointer to the base of a vertex to point at this element.
Definition: OgreHardwareVertexBuffer.h:250
Ogre::VES_NORMAL
Normal, 3 reals per vertex.
Definition: OgreHardwareVertexBuffer.h:107
OgreHardwareBuffer.h
Ogre::SharedPtr
Reference-counted shared pointer, used for objects where implicit destruction is required.
Definition: OgrePrerequisites.h:310
Ogre::VET_UINT3
Definition: OgreHardwareVertexBuffer.h:154
OgreColourValue.h
OgreHeaderPrefix.h
Ogre::HardwareVertexBuffer::mVertexSize
size_t mVertexSize
Definition: OgreHardwareVertexBuffer.h:54
Ogre::operator==
bool operator==(STLAllocator< T, P > const &, STLAllocator< T2, P > const &)
determine equality, can memory from another allocator be released by this allocator, (ISO C++)
Definition: OgreMemorySTLAllocator.h:184
Ogre::HardwareVertexBuffer::mMgr
HardwareBufferManagerBase * mMgr
Definition: OgreHardwareVertexBuffer.h:52
Ogre::HardwareVertexBufferSharedPtr::HardwareVertexBufferSharedPtr
HardwareVertexBufferSharedPtr()
Definition: OgreHardwareVertexBuffer.h:89
Ogre::map
Definition: OgrePrerequisites.h:533
Ogre::VET_SHORT2
Definition: OgreHardwareVertexBuffer.h:132
Ogre::VET_FLOAT1
Definition: OgreHardwareVertexBuffer.h:125
Ogre::VES_BINORMAL
Binormal (Y axis if normal is Z)
Definition: OgreHardwareVertexBuffer.h:115
Ogre::VET_SHORT1
Definition: OgreHardwareVertexBuffer.h:131
Ogre::VET_COLOUR_ARGB
D3D style compact colour.
Definition: OgreHardwareVertexBuffer.h:137
Ogre::VertexElement::mOffset
size_t mOffset
The offset in the buffer that this element starts at.
Definition: OgreHardwareVertexBuffer.h:173
Ogre::VET_DOUBLE2
Definition: OgreHardwareVertexBuffer.h:141
Ogre::AllocatedObject
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Definition: OgreMemoryAllocatedObject.h:58
Ogre::RGBA
uint32 RGBA
Definition: OgreColourValue.h:41
Ogre::VES_COUNT
The number of VertexElementSemantic elements (note - the first value VES_POSITION is 1) ...
Definition: OgreHardwareVertexBuffer.h:119
Ogre::VertexElement::baseVertexPointerToElement
void baseVertexPointerToElement(void *pBase, RGBA **pElem) const
Adjusts a pointer to the base of a vertex to point at this element.
Definition: OgreHardwareVertexBuffer.h:281
Ogre::VET_UINT2
Definition: OgreHardwareVertexBuffer.h:153
Ogre::VertexElement::mIndex
unsigned short mIndex
Index of the item, only applicable for some elements like texture coords.
Definition: OgreHardwareVertexBuffer.h:179

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.