BsGpuParamBlock.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 Checks if something has been written to the buffer
  43. * since the last time object was clean.
  44. */
  45. bool isDirty() const { return mDirty; }
  46. /**
  47. * @brief Marks the object as dirty or clean. Signifies
  48. * whether or not some new data has been written in the buffer.
  49. */
  50. void setDirty() { mDirty = true; }
  51. protected:
  52. UINT8* mData;
  53. UINT32 mSize;
  54. bool mDirty;
  55. };
  56. }