btSoftBodySolverVertexBuffer.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. Bullet Continuous Collision Detection and Physics Library
  3. Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
  4. This software is provided 'as-is', without any express or implied warranty.
  5. In no event will the authors be held liable for any damages arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose,
  7. including commercial applications, and to alter it and redistribute it freely,
  8. subject to the following restrictions:
  9. 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  10. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  11. 3. This notice may not be removed or altered from any source distribution.
  12. */
  13. #ifndef BT_SOFT_BODY_SOLVER_VERTEX_BUFFER_H
  14. #define BT_SOFT_BODY_SOLVER_VERTEX_BUFFER_H
  15. class btVertexBufferDescriptor
  16. {
  17. public:
  18. enum BufferTypes
  19. {
  20. CPU_BUFFER,
  21. DX11_BUFFER,
  22. OPENGL_BUFFER
  23. };
  24. protected:
  25. bool m_hasVertexPositions;
  26. bool m_hasNormals;
  27. int m_vertexOffset;
  28. int m_vertexStride;
  29. int m_normalOffset;
  30. int m_normalStride;
  31. public:
  32. btVertexBufferDescriptor()
  33. {
  34. m_hasVertexPositions = false;
  35. m_hasNormals = false;
  36. m_vertexOffset = 0;
  37. m_vertexStride = 0;
  38. m_normalOffset = 0;
  39. m_normalStride = 0;
  40. }
  41. virtual ~btVertexBufferDescriptor()
  42. {
  43. }
  44. virtual bool hasVertexPositions() const
  45. {
  46. return m_hasVertexPositions;
  47. }
  48. virtual bool hasNormals() const
  49. {
  50. return m_hasNormals;
  51. }
  52. /**
  53. * Return the type of the vertex buffer descriptor.
  54. */
  55. virtual BufferTypes getBufferType() const = 0;
  56. /**
  57. * Return the vertex offset in floats from the base pointer.
  58. */
  59. virtual int getVertexOffset() const
  60. {
  61. return m_vertexOffset;
  62. }
  63. /**
  64. * Return the vertex stride in number of floats between vertices.
  65. */
  66. virtual int getVertexStride() const
  67. {
  68. return m_vertexStride;
  69. }
  70. /**
  71. * Return the vertex offset in floats from the base pointer.
  72. */
  73. virtual int getNormalOffset() const
  74. {
  75. return m_normalOffset;
  76. }
  77. /**
  78. * Return the vertex stride in number of floats between vertices.
  79. */
  80. virtual int getNormalStride() const
  81. {
  82. return m_normalStride;
  83. }
  84. };
  85. class btCPUVertexBufferDescriptor : public btVertexBufferDescriptor
  86. {
  87. protected:
  88. float *m_basePointer;
  89. public:
  90. /**
  91. * vertexBasePointer is pointer to beginning of the buffer.
  92. * vertexOffset is the offset in floats to the first vertex.
  93. * vertexStride is the stride in floats between vertices.
  94. */
  95. btCPUVertexBufferDescriptor(float *basePointer, int vertexOffset, int vertexStride)
  96. {
  97. m_basePointer = basePointer;
  98. m_vertexOffset = vertexOffset;
  99. m_vertexStride = vertexStride;
  100. m_hasVertexPositions = true;
  101. }
  102. /**
  103. * vertexBasePointer is pointer to beginning of the buffer.
  104. * vertexOffset is the offset in floats to the first vertex.
  105. * vertexStride is the stride in floats between vertices.
  106. */
  107. btCPUVertexBufferDescriptor(float *basePointer, int vertexOffset, int vertexStride, int normalOffset, int normalStride)
  108. {
  109. m_basePointer = basePointer;
  110. m_vertexOffset = vertexOffset;
  111. m_vertexStride = vertexStride;
  112. m_hasVertexPositions = true;
  113. m_normalOffset = normalOffset;
  114. m_normalStride = normalStride;
  115. m_hasNormals = true;
  116. }
  117. virtual ~btCPUVertexBufferDescriptor()
  118. {
  119. }
  120. /**
  121. * Return the type of the vertex buffer descriptor.
  122. */
  123. virtual BufferTypes getBufferType() const
  124. {
  125. return CPU_BUFFER;
  126. }
  127. /**
  128. * Return the base pointer in memory to the first vertex.
  129. */
  130. virtual float *getBasePointer() const
  131. {
  132. return m_basePointer;
  133. }
  134. };
  135. #endif // #ifndef BT_SOFT_BODY_SOLVER_VERTEX_BUFFER_H