BsGpuBufferView.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. namespace BansheeEngine
  4. {
  5. /**
  6. * @brief Descriptor structure used for initializing a GPU buffer view.
  7. *
  8. * @see GpuBufferView
  9. * @see GpuBuffer
  10. */
  11. struct BS_CORE_EXPORT GPU_BUFFER_DESC
  12. {
  13. UINT32 firstElement;
  14. UINT32 elementWidth;
  15. UINT32 numElements;
  16. bool useCounter;
  17. GpuViewUsage usage;
  18. };
  19. /**
  20. * @brief Holds information about a GPU buffer view. Views allow you to specify
  21. * how is data in a buffer organized to make it easier for the pipeline to interpret.
  22. *
  23. * @note Buffers don't get bound to the pipeline directly, views do.
  24. * Core thread only.
  25. *
  26. * @see GpuBuffer
  27. */
  28. class BS_CORE_EXPORT GpuBufferView
  29. {
  30. public:
  31. class HashFunction
  32. {
  33. public:
  34. size_t operator()(const GPU_BUFFER_DESC& key) const;
  35. };
  36. class EqualFunction
  37. {
  38. public:
  39. bool operator()(const GPU_BUFFER_DESC& a, const GPU_BUFFER_DESC& b) const;
  40. };
  41. GpuBufferView();
  42. virtual ~GpuBufferView();
  43. /**
  44. * @brief Initializes the view with the specified buffer and
  45. * a set of parameters describing the view to create.
  46. * Must be called right after construction.
  47. */
  48. virtual void initialize(const SPtr<GpuBufferCore>& buffer, GPU_BUFFER_DESC& desc);
  49. /**
  50. * @brief Returns a descriptor structure used for creating the view.
  51. */
  52. const GPU_BUFFER_DESC& getDesc() const { return mDesc; }
  53. /**
  54. * @brief Returns the buffer this view was created for.
  55. */
  56. SPtr<GpuBufferCore> getBuffer() const { return mBuffer; }
  57. /**
  58. * @brief Returns index of first element in the buffer that this view
  59. * provides access to.
  60. */
  61. UINT32 getFirstElement() const { return mDesc.firstElement; }
  62. /**
  63. * @brief Returns width of an element in the buffer, in bytes.
  64. */
  65. UINT32 getElementWidth() const { return mDesc.elementWidth; }
  66. /**
  67. * @brief Returns the total number of elements this buffer provides
  68. * access to.
  69. */
  70. UINT32 getNumElements() const { return mDesc.numElements; }
  71. /**
  72. * @brief Returns true if this view allows a GPU program to use counters on
  73. * the bound buffer.
  74. */
  75. bool getUseCounter() const { return mDesc.useCounter; }
  76. /**
  77. * @brief Returns view usage which determines where in the pipeline
  78. * can the view be bound.
  79. */
  80. GpuViewUsage getUsage() const { return mDesc.usage; }
  81. protected:
  82. GPU_BUFFER_DESC mDesc;
  83. SPtr<GpuBufferCore> mBuffer;
  84. };
  85. }