CmGpuResourceData.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. namespace CamelotFramework
  4. {
  5. /**
  6. * @brief You can use this class to read and write to various GPU resources.
  7. *
  8. * @note If you allocate an internal buffer to store the resource data, the ownership of the buffer
  9. * will always remain with the initial instance of the class. If that initial instance
  10. * is deleted, any potential copies will point to garbage data.
  11. */
  12. class CM_EXPORT GpuResourceData : public IReflectable
  13. {
  14. public:
  15. GpuResourceData();
  16. GpuResourceData(const GpuResourceData& copy);
  17. virtual ~GpuResourceData();
  18. UINT8* getData() const;
  19. /**
  20. * @brief Allocates an internal buffer of a certain size. If there is another
  21. * buffer already allocated, it will be freed and new one will be allocated.
  22. * Buffer size is determine based on parameters used for initializing the class.
  23. */
  24. void allocateInternalBuffer();
  25. /**
  26. * @brief Allocates an internal buffer of a certain size. If there is another
  27. * buffer already allocated, it will be freed and new one will be allocated.
  28. *
  29. * @param size The size of the buffer in bytes.
  30. */
  31. void allocateInternalBuffer(UINT32 size);
  32. /**
  33. * @brief Frees the internal buffer that was allocated using "allocateInternal". Called automatically
  34. * when the instance of the class is destroyed.
  35. */
  36. void freeInternalBuffer();
  37. /**
  38. * @brief Makes the internal data pointer point to some external data. No copying is done,
  39. * so you must ensure that external data exists as long as this class uses it. You are also
  40. * responsible for deleting the data when you are done with it.
  41. *
  42. * @note If any internal data is allocated, it is freed.
  43. */
  44. void setExternalBuffer(UINT8* data);
  45. /**
  46. * @brief Locks the data and makes it available only to the core thread. Don't call manually.
  47. */
  48. void lock() const;
  49. /**
  50. * @brief Unlocks the data and makes it available to all threads. Don't call manually.
  51. */
  52. void unlock() const;
  53. protected:
  54. virtual UINT32 getInternalBufferSize() = 0;
  55. private:
  56. UINT8* mData;
  57. bool mOwnsData;
  58. mutable bool mLocked;
  59. /************************************************************************/
  60. /* SERIALIZATION */
  61. /************************************************************************/
  62. public:
  63. friend class GpuResourceDataRTTI;
  64. static RTTITypeBase* getRTTIStatic();
  65. virtual RTTITypeBase* getRTTI() const;
  66. };
  67. }