BsGpuBufferView.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 GPU buffer view. Must be called right after
  45. * construction.
  46. */
  47. virtual void initialize(GpuBufferPtr buffer, GPU_BUFFER_DESC& desc);
  48. /**
  49. * @brief Returns a descriptor structure used for creating the view.
  50. */
  51. const GPU_BUFFER_DESC& getDesc() const { return mDesc; }
  52. /**
  53. * @brief Returns the buffer this view was created for.
  54. */
  55. GpuBufferPtr getBuffer() const { return mBuffer; }
  56. /**
  57. * @brief Returns index of first element in the buffer that this view
  58. * provides access to.
  59. */
  60. UINT32 getFirstElement() const { return mDesc.firstElement; }
  61. /**
  62. * @brief Returns width of an element in the buffer, in bytes.
  63. */
  64. UINT32 getElementWidth() const { return mDesc.elementWidth; }
  65. /**
  66. * @brief Returns the total number of elements this buffer provides
  67. * access to.
  68. */
  69. UINT32 getNumElements() const { return mDesc.numElements; }
  70. /**
  71. * @brief Returns true if this view allows a GPU program to use counters on
  72. * the bound buffer.
  73. */
  74. bool getUseCounter() const { return mDesc.useCounter; }
  75. /**
  76. * @brief Returns view usage which determines where in the pipeline
  77. * can the view be bound.
  78. */
  79. GpuViewUsage getUsage() const { return mDesc.usage; }
  80. protected:
  81. GPU_BUFFER_DESC mDesc;
  82. GpuBufferPtr mBuffer;
  83. };
  84. }