BsIndexBuffer.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 "BsHardwareBuffer.h"
  6. #include "BsCoreObject.h"
  7. namespace BansheeEngine
  8. {
  9. /** @addtogroup RenderAPI
  10. * @{
  11. */
  12. /** Type of the indices used, used for determining size. */
  13. enum IndexType
  14. {
  15. IT_16BIT, /**< 16-bit indices. */
  16. IT_32BIT /**< 32-bit indices. */
  17. };
  18. /** Contains information about an index buffer. */
  19. class BS_CORE_EXPORT IndexBufferProperties
  20. {
  21. public:
  22. IndexBufferProperties(IndexType idxType, UINT32 numIndexes);
  23. /** Returns the type of indices stored. */
  24. IndexType getType() const { return mIndexType; }
  25. /** Returns the number of indices this buffer can hold. */
  26. UINT32 getNumIndices() const { return mNumIndices; }
  27. /** Returns the size of a single index in bytes. */
  28. UINT32 getIndexSize() const { return mIndexSize; }
  29. protected:
  30. friend class IndexBuffer;
  31. friend class IndexBufferCore;
  32. IndexType mIndexType;
  33. UINT32 mNumIndices;
  34. UINT32 mIndexSize;
  35. };
  36. /** Hardware buffer that hold indices that reference vertices in a vertex buffer. */
  37. class BS_CORE_EXPORT IndexBuffer : public CoreObject
  38. {
  39. public:
  40. virtual ~IndexBuffer() { }
  41. /** Returns information about the index buffer. */
  42. const IndexBufferProperties& getProperties() const { return mProperties; }
  43. /**
  44. * Retrieves a core implementation of an index buffer usable only from the core thread.
  45. *
  46. * @note Core thread only.
  47. */
  48. SPtr<IndexBufferCore> getCore() const;
  49. /** @copydoc HardwareBufferManager::createIndexBuffer */
  50. static SPtr<IndexBuffer> create(IndexType itype, UINT32 numIndices, GpuBufferUsage usage = GBU_STATIC);
  51. protected:
  52. friend class HardwareBufferManager;
  53. IndexBuffer(IndexType idxType, UINT32 numIndexes, GpuBufferUsage usage);
  54. /** @copydoc CoreObject::createCore */
  55. virtual SPtr<CoreObjectCore> createCore() const;
  56. IndexBufferProperties mProperties;
  57. GpuBufferUsage mUsage;
  58. };
  59. /** @} */
  60. /** @addtogroup RenderAPI-Internal
  61. * @{
  62. */
  63. /** Core thread specific implementation of an IndexBuffer. */
  64. class BS_CORE_EXPORT IndexBufferCore : public CoreObjectCore, public HardwareBuffer
  65. {
  66. public:
  67. IndexBufferCore(IndexType idxType, UINT32 numIndices, GpuBufferUsage usage);
  68. virtual ~IndexBufferCore() { }
  69. /** Returns information about the index buffer. */
  70. const IndexBufferProperties& getProperties() const { return mProperties; }
  71. /** @copydoc HardwareBufferManager::createIndexBuffer */
  72. static SPtr<IndexBufferCore> create(IndexType itype, UINT32 numIndices, GpuBufferUsage usage = GBU_STATIC);
  73. protected:
  74. IndexBufferProperties mProperties;
  75. };
  76. /** @} */
  77. }