CmGpuParamBlock.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmCommonEnums.h"
  4. #include "CmCoreGpuObject.h"
  5. namespace CamelotEngine
  6. {
  7. /**
  8. * @brief Represents an actual GPU buffer.
  9. * Should only be accessed directly from render thread.
  10. */
  11. class CM_EXPORT GpuParamBlockBuffer
  12. {
  13. public:
  14. GpuParamBlockBuffer(UINT32 size, GpuParamBlockUsage usage);
  15. virtual ~GpuParamBlockBuffer();
  16. /**
  17. * @brief Writes all of the data to the buffer.
  18. * Data size must be the same size as the buffer;
  19. */
  20. virtual void writeAll(const void* data);
  21. const UINT8* getDataPtr(UINT32 offset) const;
  22. UINT32 getSize() const { return mSize; }
  23. protected:
  24. GpuParamBlockUsage mUsage;
  25. UINT8* mData;
  26. UINT32 mSize;
  27. };
  28. class CM_EXPORT GpuParamBlock : public CoreGpuObject
  29. {
  30. public:
  31. GpuParamBlock();
  32. virtual ~GpuParamBlock();
  33. void initialize(const GpuParamBlockDesc& desc, GpuParamBlockUsage usage);
  34. void write(UINT32 offset, const void* data, UINT32 size);
  35. void zeroOut(UINT32 offset, UINT32 size);
  36. /**
  37. * @brief Returns a buffer that may be bound as a material parameter.
  38. */
  39. const GpuParamBlockBuffer* getBindableBuffer() const { return mBuffer; }
  40. /**
  41. * @brief Updates the internal buffer. You must call this if you want the buffer to be
  42. * up to date after making changes to it. Buffer won't be touched if there were no changes
  43. * so feel free to call this often.
  44. *
  45. * @note This will only queue the buffer update on the render thread.
  46. */
  47. void updateBuffer();
  48. static GpuParamBlockPtr create(const GpuParamBlockDesc& desc);
  49. protected:
  50. friend class HardwareBufferManager;
  51. GpuParamBlockBuffer* mBuffer;
  52. GpuParamBlockUsage mUsage;
  53. UINT8* mData;
  54. UINT32 mSize;
  55. bool mDirty;
  56. /**
  57. * @copydoc CoreGpuObject::initialize_internal.
  58. */
  59. virtual void initialize_internal();
  60. /**
  61. * @copydoc CoreGpuObject::destroy_internal.
  62. */
  63. virtual void destroy_internal();
  64. /**
  65. * @brief Creates new GPU parameter buffer. Derived classes should
  66. * return their own specific buffer implementations.
  67. *
  68. * @note Should only be called from the render thread.
  69. */
  70. virtual GpuParamBlockBuffer* createBuffer() const;
  71. void updateBuffer_internal(UINT8* data);
  72. };
  73. }