CmVertexData.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. Copyright (c) 2000-2011 Torus Knot Software Ltd
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. -----------------------------------------------------------------------------
  23. */
  24. #ifndef __VertexIndexData_H__
  25. #define __VertexIndexData_H__
  26. #include "CmPrerequisites.h"
  27. #include "CmVertexDeclaration.h"
  28. #include "CmVertexBuffer.h"
  29. namespace CamelotFramework {
  30. /** \addtogroup Core
  31. * @{
  32. */
  33. /** \addtogroup RenderSystem
  34. * @{
  35. */
  36. /** Summary class collecting together vertex source information. */
  37. class CM_EXPORT VertexData
  38. {
  39. public:
  40. /** Constructor.
  41. @note
  42. This constructor creates the VertexDeclaration and VertexBufferBinding
  43. automatically, and arranges for their deletion afterwards.
  44. @param mgr Optional HardwareBufferManager from which to create resources
  45. */
  46. VertexData(HardwareBufferManager* mgr = 0);
  47. /** Constructor.
  48. @note
  49. This constructor receives the VertexDeclaration from the caller.
  50. @param dcl The VertexDeclaration to use
  51. */
  52. VertexData(VertexDeclarationPtr dcl);
  53. ~VertexData();
  54. /** Declaration of the vertex to be used in this operation.
  55. @remarks Note that this is created for you on construction.
  56. */
  57. VertexDeclarationPtr vertexDeclaration;
  58. /// The number of vertices used in this operation
  59. UINT32 vertexCount;
  60. void setBuffer(UINT32 index, VertexBufferPtr buffer);
  61. /// Gets the buffer bound to the given source index
  62. VertexBufferPtr getBuffer(UINT32 index) const;
  63. const UnorderedMap<UINT32, VertexBufferPtr>::type& getBuffers() const { return mVertexBuffers; }
  64. /// Gets whether a buffer is bound to the given source index
  65. bool isBufferBound(UINT32 index) const;
  66. UINT32 getBufferCount(void) const { return (UINT32)mVertexBuffers.size(); }
  67. UINT32 getMaxBufferIndex(void) const { return (UINT32)mVertexBuffers.size(); }
  68. /** Convert all packed colour values (VET_COLOUR_*) in buffers used to
  69. another type.
  70. @param srcType The source colour type to assume if the ambiguous VET_COLOUR
  71. is encountered.
  72. @param destType The destination colour type, must be VET_COLOUR_ABGR or
  73. VET_COLOUR_ARGB.
  74. */
  75. void convertPackedColour(VertexElementType srcType, VertexElementType destType);
  76. private:
  77. /// Protected copy constructor, to prevent misuse
  78. VertexData(const VertexData& rhs); /* do nothing, should not use */
  79. /// Protected operator=, to prevent misuse
  80. VertexData& operator=(const VertexData& rhs); /* do not use */
  81. HardwareBufferManager* mMgr;
  82. bool mOwnsDeclaration;
  83. /** The vertex buffer bindings to be used.
  84. @remarks Note that this is created for you on construction.
  85. */
  86. UnorderedMap<UINT32, VertexBufferPtr>::type mVertexBuffers;
  87. };
  88. /** Vertex cache profiler.
  89. @remarks
  90. Utility class for evaluating the effectiveness of the use of the vertex
  91. cache by a given index buffer.
  92. */
  93. class CM_EXPORT VertexCacheProfiler
  94. {
  95. public:
  96. enum CacheType {
  97. FIFO, LRU
  98. };
  99. VertexCacheProfiler(unsigned int cachesize = 16, CacheType cachetype = FIFO )
  100. : size ( cachesize ), type ( cachetype ), tail (0), buffersize (0), hit (0), miss (0)
  101. {
  102. cache = (UINT32*)malloc(sizeof(UINT32) * size);
  103. }
  104. ~VertexCacheProfiler()
  105. {
  106. free(cache);
  107. }
  108. void profile(const IndexBufferPtr& indexBuffer);
  109. void reset() { hit = 0; miss = 0; tail = 0; buffersize = 0; }
  110. void flush() { tail = 0; buffersize = 0; }
  111. unsigned int getHits() { return hit; }
  112. unsigned int getMisses() { return miss; }
  113. unsigned int getSize() { return size; }
  114. private:
  115. unsigned int size;
  116. UINT32 *cache;
  117. CacheType type;
  118. unsigned int tail, buffersize;
  119. unsigned int hit, miss;
  120. bool inCache(unsigned int index);
  121. };
  122. /** @} */
  123. /** @} */
  124. }
  125. #endif