BsGpuBufferView.h 2.4 KB

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