BsGpuBufferView.h 2.6 KB

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