BsGpuBufferView.h 2.6 KB

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