BsGpuParamBlock.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //__________________________ Banshee Project - A modern game development toolkit _________________________________//
  2. //_____________________________________ www.banshee-project.com __________________________________________________//
  3. //________________________ Copyright (c) 2014 Marko Pintera. All rights reserved. ________________________________//
  4. #pragma once
  5. #include "BsCorePrerequisites.h"
  6. #include "BsCoreObject.h"
  7. namespace BansheeEngine
  8. {
  9. /**
  10. * @brief Stores data (e.g. int, float, Vector2) GPU parameters in a raw buffer.
  11. * Used primarily for caching GPU parameters on the CPU before they're submitted
  12. * to the actual GPU parameter buffer.
  13. */
  14. class BS_CORE_EXPORT GpuParamBlock
  15. {
  16. public:
  17. GpuParamBlock(UINT32 size);
  18. GpuParamBlock(GpuParamBlock* otherBlock);
  19. virtual ~GpuParamBlock();
  20. /**
  21. * @brief Write some data to the specified offset in the buffer.
  22. * Marks the block as dirty.
  23. * All values are in bytes.
  24. */
  25. void write(UINT32 offset, const void* data, UINT32 size);
  26. /**
  27. * @brief Read some data from the specified offset in the buffer.
  28. * All values are in bytes.
  29. */
  30. void read(UINT32 offset, void* data, UINT32 size);
  31. /**
  32. * @brief Clear specified section of the buffer to zero.
  33. * All values are in bytes.
  34. */
  35. void zeroOut(UINT32 offset, UINT32 size);
  36. /**
  37. * @brief Returns size of the internal buffer in bytes.
  38. */
  39. UINT32 getSize() const { return mSize; }
  40. /**
  41. * @brief Returns a raw pointer to the internal buffer.
  42. */
  43. UINT8* getData() const { return mData; }
  44. /**
  45. * @brief Uploads the current data to the specified buffer, and marks the block a non-dirty.
  46. *
  47. * @note Core thread only.
  48. */
  49. void uploadToBuffer(const GpuParamBlockBufferPtr& buffer);
  50. /**
  51. * @brief Checks if something has been written to the buffer
  52. * since the last time object was clean.
  53. */
  54. bool isDirty() const { return mDirty; }
  55. /**
  56. * @brief Marks the object as dirty or clean. Signifies
  57. * whether or not some new data has been written in the buffer.
  58. */
  59. void setDirty(bool dirty) { mDirty = dirty; }
  60. protected:
  61. UINT8* mData;
  62. UINT32 mSize;
  63. bool mDirty;
  64. };
  65. }