BsGpuParamBlock.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsCoreObject.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief Stores data (e.g. int, float, Vector2) GPU parameters in a raw buffer.
  8. * Used primarily for caching GPU parameters on the CPU before they're submitted
  9. * to the actual GPU parameter buffer.
  10. */
  11. class BS_CORE_EXPORT GpuParamBlock
  12. {
  13. public:
  14. /**
  15. * @brief Construct a new parameter block with internal data allocated using the
  16. * standard allocator.
  17. */
  18. GpuParamBlock(UINT32 size);
  19. /**
  20. * @brief Construct a new parameter block with internal data allocated using the
  21. * provided frame allocator. Such blocks must be released the same frame
  22. * they were allocated on.
  23. */
  24. GpuParamBlock(FrameAlloc* alloc, UINT32 size);
  25. virtual ~GpuParamBlock();
  26. /**
  27. * @brief Write some data to the specified offset in the buffer.
  28. * Marks the block as dirty.
  29. * All values are in bytes.
  30. */
  31. void write(UINT32 offset, const void* data, UINT32 size);
  32. /**
  33. * @brief Read some data from the specified offset in the buffer.
  34. * All values are in bytes.
  35. */
  36. void read(UINT32 offset, void* data, UINT32 size);
  37. /**
  38. * @brief Clear specified section of the buffer to zero.
  39. * All values are in bytes.
  40. */
  41. void zeroOut(UINT32 offset, UINT32 size);
  42. /**
  43. * @brief Returns size of the internal buffer in bytes.
  44. */
  45. UINT32 getSize() const { return mSize; }
  46. /**
  47. * @brief Returns a raw pointer to the internal buffer.
  48. */
  49. UINT8* getData() const { return mData; }
  50. /**
  51. * @brief Uploads the current data to the specified buffer, and marks the block a non-dirty.
  52. *
  53. * @note Core thread only.
  54. */
  55. void uploadToBuffer(const GpuParamBlockBufferPtr& buffer);
  56. /**
  57. * @brief Checks if something has been written to the buffer
  58. * since the last time object was clean.
  59. */
  60. bool isDirty() const { return mDirty; }
  61. /**
  62. * @brief Marks the object as dirty or clean. Signifies
  63. * whether or not some new data has been written in the buffer.
  64. */
  65. void setDirty(bool dirty) { mDirty = dirty; }
  66. protected:
  67. UINT8* mData;
  68. UINT32 mSize;
  69. bool mDirty;
  70. FrameAlloc* mAlloc;
  71. };
  72. }