BsVertexBuffer.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "RenderAPI/BsHardwareBuffer.h"
  6. #include "CoreThread/BsCoreObject.h"
  7. namespace bs
  8. {
  9. /** @addtogroup RenderAPI
  10. * @{
  11. */
  12. /** Descriptor structure used for initialization of a VertexBuffer. */
  13. struct VERTEX_BUFFER_DESC
  14. {
  15. UINT32 vertexSize; /**< Size of a single vertex in the buffer, in bytes. */
  16. UINT32 numVerts; /**< Number of vertices the buffer can hold. */
  17. GpuBufferUsage usage = GBU_STATIC; /**< Usage that tells the hardware how will be buffer be used. */
  18. bool streamOut = false; /**< If true the buffer will be usable for streaming out data from the GPU. */
  19. };
  20. /** Contains information about a vertex buffer buffer. */
  21. class BS_CORE_EXPORT VertexBufferProperties
  22. {
  23. public:
  24. VertexBufferProperties(UINT32 numVertices, UINT32 vertexSize);
  25. /** Gets the size in bytes of a single vertex in this buffer. */
  26. UINT32 getVertexSize() const { return mVertexSize; }
  27. /** Get the number of vertices in this buffer. */
  28. UINT32 getNumVertices() const { return mNumVertices; }
  29. protected:
  30. friend class VertexBuffer;
  31. friend class ct::VertexBuffer;
  32. UINT32 mNumVertices;
  33. UINT32 mVertexSize;
  34. };
  35. /** Specialization of a hardware buffer used for holding vertex data. */
  36. class BS_CORE_EXPORT VertexBuffer : public CoreObject
  37. {
  38. public:
  39. virtual ~VertexBuffer() { }
  40. /**
  41. * Retrieves a core implementation of a vertex buffer usable only from the core thread.
  42. *
  43. * @note Core thread only.
  44. */
  45. SPtr<ct::VertexBuffer> getCore() const;
  46. /** @copydoc HardwareBufferManager::createVertexBuffer */
  47. static SPtr<VertexBuffer> create(const VERTEX_BUFFER_DESC& desc);
  48. static const int MAX_SEMANTIC_IDX = 8;
  49. protected:
  50. friend class HardwareBufferManager;
  51. VertexBuffer(const VERTEX_BUFFER_DESC& desc);
  52. /** @copydoc CoreObject::createCore */
  53. virtual SPtr<ct::CoreObject> createCore() const;
  54. protected:
  55. VertexBufferProperties mProperties;
  56. GpuBufferUsage mUsage;
  57. bool mStreamOut;
  58. };
  59. /** @} */
  60. namespace ct
  61. {
  62. /** @addtogroup RenderAPI-Internal
  63. * @{
  64. */
  65. /** Core thread specific implementation of a bs::VertexBuffer. */
  66. class BS_CORE_EXPORT VertexBuffer : public CoreObject, public HardwareBuffer
  67. {
  68. public:
  69. VertexBuffer(const VERTEX_BUFFER_DESC& desc, GpuDeviceFlags deviceMask = GDF_DEFAULT);
  70. virtual ~VertexBuffer() { }
  71. /** Returns information about the vertex buffer. */
  72. const VertexBufferProperties& getProperties() const { return mProperties; }
  73. /** @copydoc HardwareBufferManager::createVertexBuffer */
  74. static SPtr<VertexBuffer> create(const VERTEX_BUFFER_DESC& desc, GpuDeviceFlags deviceMask = GDF_DEFAULT);
  75. protected:
  76. VertexBufferProperties mProperties;
  77. };
  78. /** @} */
  79. }
  80. }