BsGpuParamBlock.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. GpuParamBlock(UINT32 size);
  15. GpuParamBlock(GpuParamBlock* otherBlock);
  16. virtual ~GpuParamBlock();
  17. /**
  18. * @brief Write some data to the specified offset in the buffer.
  19. * Marks the block as dirty.
  20. * All values are in bytes.
  21. */
  22. void write(UINT32 offset, const void* data, UINT32 size);
  23. /**
  24. * @brief Read some data from the specified offset in the buffer.
  25. * All values are in bytes.
  26. */
  27. void read(UINT32 offset, void* data, UINT32 size);
  28. /**
  29. * @brief Clear specified section of the buffer to zero.
  30. * All values are in bytes.
  31. */
  32. void zeroOut(UINT32 offset, UINT32 size);
  33. /**
  34. * @brief Returns size of the internal buffer in bytes.
  35. */
  36. UINT32 getSize() const { return mSize; }
  37. /**
  38. * @brief Returns a raw pointer to the internal buffer.
  39. */
  40. UINT8* getData() const { return mData; }
  41. /**
  42. * @brief Uploads the current data to the specified buffer, and marks the block a non-dirty.
  43. *
  44. * @note Core thread only.
  45. */
  46. void uploadToBuffer(const GpuParamBlockBufferPtr& buffer);
  47. /**
  48. * @brief Checks if something has been written to the buffer
  49. * since the last time object was clean.
  50. */
  51. bool isDirty() const { return mDirty; }
  52. /**
  53. * @brief Marks the object as dirty or clean. Signifies
  54. * whether or not some new data has been written in the buffer.
  55. */
  56. void setDirty(bool dirty) { mDirty = dirty; }
  57. protected:
  58. UINT8* mData;
  59. UINT32 mSize;
  60. bool mDirty;
  61. };
  62. }