OgreHardwareVertexBuffer.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4  (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2013 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef __HardwareVertexBuffer__
29 #define __HardwareVertexBuffer__
30 
31 // Precompiler options
32 #include "OgrePrerequisites.h"
33 #include "OgreHardwareBuffer.h"
34 #include "OgreSharedPtr.h"
35 #include "OgreColourValue.h"
36 #include "OgreHeaderPrefix.h"
37 
38 namespace Ogre {
39  class HardwareBufferManagerBase;
40 
49  {
50  protected:
51 
53  size_t mNumVertices;
54  size_t mVertexSize;
59 
60  public:
62  HardwareVertexBuffer(HardwareBufferManagerBase* mgr, size_t vertexSize, size_t numVertices,
63  HardwareBuffer::Usage usage, bool useSystemMemory, bool useShadowBuffer);
66  HardwareBufferManagerBase* getManager() const { return mMgr; }
68  size_t getVertexSize(void) const { return mVertexSize; }
70  size_t getNumVertices(void) const { return mNumVertices; }
72  bool isInstanceData() const { return mIsInstanceData; }
74  void setIsInstanceData(const bool val);
76  size_t getInstanceDataStepRate() const;
78  void setInstanceDataStepRate(const size_t val);
79 
80 
81  // NB subclasses should override lock, unlock, readData, writeData
82 
83  };
84 
86  class _OgreExport HardwareVertexBufferSharedPtr : public SharedPtr<HardwareVertexBuffer>
87  {
88  public:
91 
92 
93  };
94 
97 
119  VES_COUNT = 9
120  };
121 
124  {
147  VET_USHORT4 = 19,
148  VET_INT1 = 20,
149  VET_INT2 = 21,
150  VET_INT3 = 22,
151  VET_INT4 = 23,
152  VET_UINT1 = 24,
153  VET_UINT2 = 25,
154  VET_UINT3 = 26,
155  VET_UINT4 = 27
156  };
157 
168  {
169  protected:
171  unsigned short mSource;
173  size_t mOffset;
179  unsigned short mIndex;
180  public:
184  VertexElement(unsigned short source, size_t offset, VertexElementType theType,
185  VertexElementSemantic semantic, unsigned short index = 0);
187  unsigned short getSource(void) const { return mSource; }
189  size_t getOffset(void) const { return mOffset; }
191  VertexElementType getType(void) const { return mType; }
193  VertexElementSemantic getSemantic(void) const { return mSemantic; }
195  unsigned short getIndex(void) const { return mIndex; }
197  size_t getSize(void) const;
199  static size_t getTypeSize(VertexElementType etype);
201  static unsigned short getTypeCount(VertexElementType etype);
205  static VertexElementType multiplyTypeCount(VertexElementType baseType, unsigned short count);
210 
218  VertexElementType dstType, uint32* ptr);
219 
226  VertexElementType dst);
227 
230 
231  inline bool operator== (const VertexElement& rhs) const
232  {
233  if (mType != rhs.mType ||
234  mIndex != rhs.mIndex ||
235  mOffset != rhs.mOffset ||
236  mSemantic != rhs.mSemantic ||
237  mSource != rhs.mSource)
238  return false;
239  else
240  return true;
241 
242  }
250  inline void baseVertexPointerToElement(void* pBase, void** pElem) const
251  {
252  // The only way we can do this is to cast to char* in order to use byte offset
253  // then cast back to void*.
254  *pElem = static_cast<void*>(
255  static_cast<unsigned char*>(pBase) + mOffset);
256  }
264  inline void baseVertexPointerToElement(void* pBase, float** pElem) const
265  {
266  // The only way we can do this is to cast to char* in order to use byte offset
267  // then cast back to float*. However we have to go via void* because casting
268  // directly is not allowed
269  *pElem = static_cast<float*>(
270  static_cast<void*>(
271  static_cast<unsigned char*>(pBase) + mOffset));
272  }
273 
281  inline void baseVertexPointerToElement(void* pBase, RGBA** pElem) const
282  {
283  *pElem = static_cast<RGBA*>(
284  static_cast<void*>(
285  static_cast<unsigned char*>(pBase) + mOffset));
286  }
294  inline void baseVertexPointerToElement(void* pBase, unsigned char** pElem) const
295  {
296  *pElem = static_cast<unsigned char*>(pBase) + mOffset;
297  }
298 
306  inline void baseVertexPointerToElement(void* pBase, unsigned short** pElem) const
307  {
308  *pElem = static_cast<unsigned short*>(
309  static_cast<void*>(
310  static_cast<unsigned char*>(pBase) + mOffset));
311  }
312 
313 
314  };
338  {
339  public:
343  static bool vertexElementLess(const VertexElement& e1, const VertexElement& e2);
344  protected:
346  public:
350 
352  size_t getElementCount(void) const { return mElementList.size(); }
354  const VertexElementList& getElements(void) const;
356  const VertexElement* getElement(unsigned short index) const;
357 
366  void sort(void);
367 
378  void closeGapsInSource(void);
379 
392  bool vertexAnimation, bool vertexAnimationNormals) const;
393 
395  unsigned short getMaxSource(void) const;
396 
397 
398 
412  virtual const VertexElement& addElement(unsigned short source, size_t offset, VertexElementType theType,
413  VertexElementSemantic semantic, unsigned short index = 0);
427  virtual const VertexElement& insertElement(unsigned short atPosition,
428  unsigned short source, size_t offset, VertexElementType theType,
429  VertexElementSemantic semantic, unsigned short index = 0);
430 
432  virtual void removeElement(unsigned short elem_index);
433 
440  virtual void removeElement(VertexElementSemantic semantic, unsigned short index = 0);
441 
443  virtual void removeAllElements(void);
444 
450  virtual void modifyElement(unsigned short elem_index, unsigned short source, size_t offset, VertexElementType theType,
451  VertexElementSemantic semantic, unsigned short index = 0);
452 
458  virtual const VertexElement* findElementBySemantic(VertexElementSemantic sem, unsigned short index = 0) const;
468  virtual VertexElementList findElementsBySource(unsigned short source) const;
469 
471  virtual size_t getVertexSize(unsigned short source) const;
472 
476  virtual unsigned short getNextFreeTextureCoordinate() const;
477 
483 
484  inline bool operator== (const VertexDeclaration& rhs) const
485  {
486  if (mElementList.size() != rhs.mElementList.size())
487  return false;
488 
489  VertexElementList::const_iterator i, iend, rhsi, rhsiend;
490  iend = mElementList.end();
491  rhsiend = rhs.mElementList.end();
492  rhsi = rhs.mElementList.begin();
493  for (i = mElementList.begin(); i != iend && rhsi != rhsiend; ++i, ++rhsi)
494  {
495  if ( !(*i == *rhsi) )
496  return false;
497  }
498 
499  return true;
500  }
501  inline bool operator!= (const VertexDeclaration& rhs) const
502  {
503  return !(*this == rhs);
504  }
505 
506  };
507 
522  {
523  public:
526  protected:
528  mutable unsigned short mHighIndex;
529  public:
541  virtual void setBinding(unsigned short index, const HardwareVertexBufferSharedPtr& buffer);
543  virtual void unsetBinding(unsigned short index);
544 
546  virtual void unsetAllBindings(void);
547 
549  virtual const VertexBufferBindingMap& getBindings(void) const;
550 
552  virtual const HardwareVertexBufferSharedPtr& getBuffer(unsigned short index) const;
554  virtual bool isBufferBound(unsigned short index) const;
555 
556  virtual size_t getBufferCount(void) const { return mBindingMap.size(); }
557 
563  virtual unsigned short getNextIndex(void) const { return mHighIndex++; }
564 
567  virtual unsigned short getLastBoundIndex(void) const;
568 
570 
573  virtual bool hasGaps(void) const;
574 
587  virtual void closeGaps(BindingIndexMap& bindingIndexMap);
588 
590  virtual bool hasInstanceData() const;
591 
592 
593  };
599 }
600 
601 #include "OgreHeaderSuffix.h"
602 
603 #endif
604 
#define _OgreExport
Definition: OgrePlatform.h:257
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Class representing colour.
Base definition of a hardware buffer manager.
Abstract class defining common features of hardware buffers.
Usage
Enums describing buffer usage; not mutually exclusive.
Shared pointer implementation used to share vertex buffers.
HardwareVertexBufferSharedPtr(HardwareVertexBuffer *buf)
Specialisation of HardwareBuffer for a vertex buffer.
HardwareBufferManagerBase * mMgr
void setInstanceDataStepRate(const size_t val)
Set the number of instances to draw using the same per-instance data before advancing in the buffer b...
virtual bool checkIfVertexInstanceDataIsSupported()
Checks if vertex instance data is supported by the render system.
HardwareVertexBuffer(HardwareBufferManagerBase *mgr, size_t vertexSize, size_t numVertices, HardwareBuffer::Usage usage, bool useSystemMemory, bool useShadowBuffer)
Should be called by HardwareBufferManager.
bool isInstanceData() const
Get if this vertex buffer is an "instance data" buffer (per instance)
void setIsInstanceData(const bool val)
Set if this vertex buffer is an "instance data" buffer (per instance)
size_t getVertexSize(void) const
Gets the size in bytes of a single vertex in this buffer.
size_t getInstanceDataStepRate() const
Get the number of instances to draw using the same per-instance data before advancing in the buffer b...
size_t getNumVertices(void) const
Get the number of vertices in this buffer.
HardwareBufferManagerBase * getManager() const
Return the manager of this buffer, if any.
Reference-counted shared pointer, used for objects where implicit destruction is required.
Records the state of all the vertex buffer bindings required to provide a vertex declaration with the...
virtual unsigned short getNextIndex(void) const
Gets the highest index which has already been set, plus 1.
virtual bool isBufferBound(unsigned short index) const
Gets whether a buffer is bound to the given source index.
virtual const HardwareVertexBufferSharedPtr & getBuffer(unsigned short index) const
Gets the buffer bound to the given source index.
map< unsigned short, HardwareVertexBufferSharedPtr >::type VertexBufferBindingMap
Defines the vertex buffer bindings used as source for vertex declarations.
virtual size_t getBufferCount(void) const
virtual void unsetAllBindings(void)
Removes all the bindings.
virtual void unsetBinding(unsigned short index)
Removes an existing binding.
VertexBufferBindingMap mBindingMap
virtual unsigned short getLastBoundIndex(void) const
Gets the last bound index.
VertexBufferBinding()
Constructor, should not be called direct, use HardwareBufferManager::createVertexBufferBinding.
map< ushort, ushort >::type BindingIndexMap
virtual void setBinding(unsigned short index, const HardwareVertexBufferSharedPtr &buffer)
Set a binding, associating a vertex buffer with a given index.
virtual const VertexBufferBindingMap & getBindings(void) const
Gets a read-only version of the buffer bindings.
virtual void closeGaps(BindingIndexMap &bindingIndexMap)
Remove any gaps in the bindings.
virtual bool hasInstanceData() const
Returns true if this binding has an element that contains instance data.
virtual bool hasGaps(void) const
Check whether any gaps in the bindings.
This class declares the format of a set of vertex inputs, which can be issued to the rendering API th...
VertexDeclaration * getAutoOrganisedDeclaration(bool skeletalAnimation, bool vertexAnimation, bool vertexAnimationNormals) const
Generates a new VertexDeclaration for optimal usage based on the current vertex declaration,...
virtual VertexDeclaration * clone(HardwareBufferManagerBase *mgr=0) const
Clones this declaration.
virtual unsigned short getNextFreeTextureCoordinate() const
Return the index of the next free texture coordinate set which may be added to this declaration.
size_t getElementCount(void) const
Get the number of elements in the declaration.
void closeGapsInSource(void)
Remove any gaps in the source buffer list used by this declaration.
virtual void removeElement(unsigned short elem_index)
Remove the element at the given index from this declaration.
list< VertexElement >::type VertexElementList
Defines the list of vertex elements that makes up this declaration.
virtual VertexElementList findElementsBySource(unsigned short source) const
Based on the current elements, gets the size of the vertex for a given buffer source.
VertexDeclaration()
Standard constructor, not you should use HardwareBufferManager::createVertexDeclaration.
static bool vertexElementLess(const VertexElement &e1, const VertexElement &e2)
Sort routine for vertex elements.
virtual const VertexElement * findElementBySemantic(VertexElementSemantic sem, unsigned short index=0) const
Finds a VertexElement with the given semantic, and index if there is more than one element with the s...
virtual size_t getVertexSize(unsigned short source) const
Gets the vertex size defined by this declaration for a given source.
const VertexElementList & getElements(void) const
Gets read-only access to the list of vertex elements.
void sort(void)
Sorts the elements in this list to be compatible with the maximum number of rendering APIs / graphics...
virtual void removeAllElements(void)
Remove all elements.
virtual const VertexElement & insertElement(unsigned short atPosition, unsigned short source, size_t offset, VertexElementType theType, VertexElementSemantic semantic, unsigned short index=0)
Inserts a new VertexElement at a given position in this declaration.
virtual void modifyElement(unsigned short elem_index, unsigned short source, size_t offset, VertexElementType theType, VertexElementSemantic semantic, unsigned short index=0)
Modify an element in-place, params as addElement.
virtual void removeElement(VertexElementSemantic semantic, unsigned short index=0)
Remove the element with the given semantic and usage index.
virtual const VertexElement & addElement(unsigned short source, size_t offset, VertexElementType theType, VertexElementSemantic semantic, unsigned short index=0)
Adds a new VertexElement to this declaration.
unsigned short getMaxSource(void) const
Gets the index of the highest source value referenced by this declaration.
const VertexElement * getElement(unsigned short index) const
Get a single element.
This class declares the usage of a single vertex buffer as a component of a complete VertexDeclaratio...
static size_t getTypeSize(VertexElementType etype)
Utility method for helping to calculate offsets.
VertexElementSemantic getSemantic(void) const
Gets the meaning of this element.
unsigned short getIndex(void) const
Gets the index of this element, only applicable for repeating elements.
VertexElementSemantic mSemantic
The meaning of the element.
size_t getSize(void) const
Gets the size of this element in bytes.
unsigned short mIndex
Index of the item, only applicable for some elements like texture coords.
VertexElementType mType
The type of element.
void baseVertexPointerToElement(void *pBase, unsigned short **pElem) const
Adjusts a pointer to the base of a vertex to point at this element.
static void convertColourValue(VertexElementType srcType, VertexElementType dstType, uint32 *ptr)
Utility method for converting colour from one packed 32-bit colour type to another.
VertexElementType getType(void) const
Gets the data format of this element.
size_t mOffset
The offset in the buffer that this element starts at.
VertexElement()
Constructor, should not be called directly, only needed because of list.
void baseVertexPointerToElement(void *pBase, RGBA **pElem) const
Adjusts a pointer to the base of a vertex to point at this element.
void baseVertexPointerToElement(void *pBase, float **pElem) const
Adjusts a pointer to the base of a vertex to point at this element.
static uint32 convertColourValue(const ColourValue &src, VertexElementType dst)
Utility method for converting colour to a packed 32-bit colour type.
VertexElement(unsigned short source, size_t offset, VertexElementType theType, VertexElementSemantic semantic, unsigned short index=0)
Constructor, should not be called directly, call VertexDeclaration::addElement.
static VertexElementType getBaseType(VertexElementType multiType)
Simple converter function which will a type into it's single-value equivalent - makes switches on typ...
unsigned short mSource
The source vertex buffer, as bound to an index using VertexBufferBinding.
unsigned short getSource(void) const
Gets the vertex buffer index from where this element draws it's values.
void baseVertexPointerToElement(void *pBase, void **pElem) const
Adjusts a pointer to the base of a vertex to point at this element.
void baseVertexPointerToElement(void *pBase, unsigned char **pElem) const
Adjusts a pointer to the base of a vertex to point at this element.
static VertexElementType multiplyTypeCount(VertexElementType baseType, unsigned short count)
Simple converter function which will turn a single-value type into a multi-value type based on a para...
static unsigned short getTypeCount(VertexElementType etype)
Utility method which returns the count of values in a given type.
size_t getOffset(void) const
Gets the offset into the buffer where this element starts.
static VertexElementType getBestColourVertexElementType(void)
Utility method to get the most appropriate packed colour vertex element format.
uint32 RGBA
bool operator!=(STLAllocator< T, P > const &, STLAllocator< T2, P > const &)
determine equality, can memory from another allocator be released by this allocator,...
bool operator==(STLAllocator< T, P > const &, STLAllocator< T2, P > const &)
determine equality, can memory from another allocator be released by this allocator,...
VertexElementType
Vertex element type, used to identify the base types of the vertex contents.
VertexElementSemantic
Vertex element semantics, used to identify the meaning of vertex buffer contents.
HardwareBufferLockGuard< HardwareVertexBufferSharedPtr > HardwareVertexBufferLockGuard
Locking helper.
@ VET_COLOUR
alias to more specific colour type - use the current rendersystem's colour packing
@ VET_COLOUR_ARGB
D3D style compact colour.
@ VET_COLOUR_ABGR
GL style compact colour.
@ VES_TEXTURE_COORDINATES
Texture coordinates.
@ VES_NORMAL
Normal, 3 reals per vertex.
@ VES_BINORMAL
Binormal (Y axis if normal is Z)
@ VES_TANGENT
Tangent (X axis if normal is Z)
@ VES_BLEND_WEIGHTS
Blending weights.
@ VES_COUNT
The number of VertexElementSemantic elements (note - the first value VES_POSITION is 1)
@ VES_DIFFUSE
Diffuse colours.
@ VES_SPECULAR
Specular colours.
@ VES_POSITION
Position, 3 reals per vertex.
@ VES_BLEND_INDICES
Blending indices.
unsigned int uint32
Definition: OgrePlatform.h:359
std::map< K, V, P, A > type

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