OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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-2014 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;
58  virtual bool checkIfVertexInstanceDataIsSupported();
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 getIsInstanceData() 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 
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,
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);
209  static VertexElementType getBaseType(VertexElementType multiType);
210 
217  static void convertColourValue(VertexElementType srcType,
218  VertexElementType dstType, uint32* ptr);
219 
225  static uint32 convertColourValue(const ColourValue& src,
226  VertexElementType dst);
227 
229  static VertexElementType getBestColourVertexElementType(void);
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:
349  virtual ~VertexDeclaration();
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 
391  VertexDeclaration* getAutoOrganisedDeclaration(bool skeletalAnimation,
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 
482  virtual VertexDeclaration* clone(HardwareBufferManagerBase* mgr = 0) const;
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:
532  virtual ~VertexBufferBinding();
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 getHasInstanceData() const;
591 
592 
593  };
599 }
600 
601 #include "OgreHeaderSuffix.h"
602 
603 #endif
604 
void baseVertexPointerToElement(void *pBase, float **pElem) const
Adjusts a pointer to the base of a vertex to point at this element.
VertexElementSemantic getSemantic(void) const
Gets the meaning of this element.
map< unsigned short, HardwareVertexBufferSharedPtr >::type VertexBufferBindingMap
Defines the vertex buffer bindings used as source for vertex declarations.
unsigned int uint32
Definition: OgrePlatform.h:420
Binormal (Y axis if normal is Z)
#define _OgreExport
Definition: OgrePlatform.h:255
VertexElementType getType(void) const
Gets the data format of this element.
Records the state of all the vertex buffer bindings required to provide a vertex declaration with the...
Tangent (X axis if normal is Z)
Class representing colour.
VertexElementType mType
The type of element.
virtual size_t getBufferCount(void) const
Shared pointer implementation used to share vertex buffers.
VertexElementSemantic
Vertex element semantics, used to identify the meaning of vertex buffer contents. ...
unsigned short mSource
The source vertex buffer, as bound to an index using VertexBufferBinding.
alias to more specific colour type - use the current rendersystem's colour packing ...
unsigned short getSource(void) const
Gets the vertex buffer index from where this element draws it's values.
HardwareBufferManagerBase * getManager() const
Return the manager of this buffer, if any.
HardwareBufferLockGuard< HardwareVertexBufferSharedPtr > HardwareVertexBufferLockGuard
Locking helper.
virtual unsigned short getNextIndex(void) const
Gets the highest index which has already been set, plus 1.
unsigned short getIndex(void) const
Gets the index of this element, only applicable for repeating elements.
This class declares the usage of a single vertex buffer as a component of a complete VertexDeclaratio...
void baseVertexPointerToElement(void *pBase, void **pElem) const
Adjusts a pointer to the base of a vertex to point at this element.
size_t getElementCount(void) const
Get the number of elements in the declaration.
uint32 RGBA
void baseVertexPointerToElement(void *pBase, unsigned char **pElem) const
Adjusts a pointer to the base of a vertex to point at this element.
HardwareBufferManagerBase * mMgr
GL style compact colour.
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
size_t getVertexSize(void) const
Gets the size in bytes of a single vertex in this buffer.
bool getIsInstanceData() const
Get if this vertex buffer is an "instance data" buffer (per instance)
VertexElementSemantic mSemantic
The meaning of the element.
D3D style compact colour.
Base definition of a hardware buffer manager.
map< ushort, ushort >::type BindingIndexMap
Usage
Enums describing buffer usage; not mutually exclusive.
VertexElementType
Vertex element type, used to identify the base types of the vertex contents.
unsigned short mIndex
Index of the item, only applicable for some elements like texture coords.
std::map< K, V, P, A > type
Position, 3 reals per vertex.
This class declares the format of a set of vertex inputs, which can be issued to the rendering API th...
VertexBufferBindingMap mBindingMap
list< VertexElement >::type VertexElementList
Defines the list of vertex elements that makes up this declaration.
Abstract class defining common features of hardware buffers.
size_t mOffset
The offset in the buffer that this element starts at.
Normal, 3 reals per vertex.
Specialisation of HardwareBuffer for a vertex buffer.
Reference-counted shared pointer, used for objects where implicit destruction is required.
void baseVertexPointerToElement(void *pBase, unsigned short **pElem) const
Adjusts a pointer to the base of a vertex to point at this element.
The number of VertexElementSemantic elements (note - the first value VES_POSITION is 1) ...
void baseVertexPointerToElement(void *pBase, RGBA **pElem) const
Adjusts a pointer to the base of a vertex to point at this element.
VertexElement()
Constructor, should not be called directly, only needed because of list.
size_t getOffset(void) const
Gets the offset into the buffer where this element starts.
size_t getNumVertices(void) const
Get the number of vertices in this buffer.
bool operator==(STLAllocator< T, P > const &, STLAllocator< T2, P > const &)
determine equality, can memory from another allocator be released by this allocator, (ISO C++)
bool operator!=(STLAllocator< T, P > const &, STLAllocator< T2, P > const &)
determine equality, can memory from another allocator be released by this allocator, (ISO C++)