CmGpuBufferView.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmCommonEnums.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief Descriptor structure used for initializing a GPU buffer view.
  8. *
  9. * @see GpuBufferView
  10. * @see GpuBuffer
  11. */
  12. struct CM_EXPORT GPU_BUFFER_DESC
  13. {
  14. UINT32 firstElement;
  15. UINT32 elementWidth;
  16. UINT32 numElements;
  17. bool useCounter;
  18. GpuViewUsage usage;
  19. };
  20. /**
  21. * @brief Holds information about a GPU buffer view. Views allow you to specify
  22. * how is data in a buffer organized to make it easier for the pipeline to interpret.
  23. *
  24. * @note Buffers don't get bound to the pipeline directly, views do.
  25. * Core thread only.
  26. *
  27. * @see GpuBuffer
  28. */
  29. class CM_EXPORT GpuBufferView
  30. {
  31. public:
  32. class HashFunction
  33. {
  34. public:
  35. size_t operator()(const GPU_BUFFER_DESC& key) const;
  36. };
  37. class EqualFunction
  38. {
  39. public:
  40. bool operator()(const GPU_BUFFER_DESC& a, const GPU_BUFFER_DESC& b) const;
  41. };
  42. GpuBufferView();
  43. virtual ~GpuBufferView();
  44. /**
  45. * @brief Initializes the GPU buffer view. Must be called right after
  46. * construction.
  47. */
  48. virtual void initialize(GpuBufferPtr 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. GpuBufferPtr 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. GpuBufferPtr mBuffer;
  84. };
  85. }