CmGpuParamBlockBuffer.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmCommonEnums.h"
  4. #include "CmCoreObject.h"
  5. namespace BansheeEngine
  6. {
  7. /**
  8. * @brief Represents a GPU parameter block buffer. Parameter block buffers
  9. * are bound to GPU programs which then fetch parameters from those buffers.
  10. *
  11. * Writing or reading from this buffer will translate directly to API calls
  12. * that update the GPU.
  13. *
  14. * @note Core thread only.
  15. */
  16. class CM_EXPORT GpuParamBlockBuffer : public CoreObject
  17. {
  18. public:
  19. GpuParamBlockBuffer();
  20. virtual ~GpuParamBlockBuffer();
  21. /**
  22. * @brief Initializes a buffer with the specified size in bytes and usage.
  23. * Specify dynamic usage if you plan on modifying the buffer often,
  24. * otherwise specify static usage.
  25. *
  26. * @see CoreObject::initialize
  27. *
  28. * @note Must be called right after construction.
  29. */
  30. void initialize(UINT32 size, GpuParamBlockUsage usage);
  31. /**
  32. * @brief Writes all of the specified data to the buffer.
  33. * Data size must be the same size as the buffer;
  34. */
  35. virtual void writeData(const UINT8* data) = 0;
  36. /**
  37. * @brief Copies data from the internal buffer to a pre-allocated array.
  38. * Be aware this generally isn't a very fast operation as reading
  39. * from the GPU will most definitely involve a CPU-GPU sync point.
  40. *
  41. * @param [in,out] data Array where the data will be written to. Must be of
  42. * "getSize()" bytes.
  43. */
  44. virtual void readData(UINT8* data) const = 0;
  45. /**
  46. * @brief Returns the size of the buffer in bytes.
  47. */
  48. UINT32 getSize() const { return mSize; }
  49. /**
  50. * @brief Returns a parameter block buffer which is used for caching
  51. * the parameter information on the CPU. Essentially a CPU
  52. * copy of the GPU buffer.
  53. *
  54. * @note Sim thread only.
  55. */
  56. GpuParamBlock* getParamBlock() const { return mParamBlock; }
  57. protected:
  58. GpuParamBlockUsage mUsage;
  59. UINT32 mSize;
  60. GpuParamBlock* mParamBlock;
  61. };
  62. /**
  63. * @brief Implementation of a GpuParamBlock buffer that doesn't use a GPU buffer
  64. * for storage. Used with APIs that do not support GPU parameter buffers.
  65. */
  66. class CM_EXPORT GenericGpuParamBlockBuffer : public GpuParamBlockBuffer
  67. {
  68. public:
  69. /**
  70. * @copydoc GpuParamBlockBuffer::writeData
  71. */
  72. void writeData(const UINT8* data);
  73. /**
  74. * @copydoc GpuParamBlockBuffer::readData.
  75. */
  76. void readData(UINT8* data) const;
  77. protected:
  78. UINT8* mData;
  79. /**
  80. * @copydoc CoreObject::initialize_internal.
  81. */
  82. virtual void initialize_internal();
  83. /**
  84. * @copydoc CoreObject::destroy_internal.
  85. */
  86. virtual void destroy_internal();
  87. };
  88. }