CmGpuParamBlock.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include "CmGpuParamBlock.h"
  2. #include "CmGpuParamDesc.h"
  3. #include "CmGpuParamBlockBuffer.h"
  4. #include "CmHardwareBufferManager.h"
  5. #include "CmException.h"
  6. namespace BansheeEngine
  7. {
  8. GpuParamBlock::GpuParamBlock(UINT32 size)
  9. :mDirty(true), mData(nullptr), mSize(size)
  10. {
  11. mData = (UINT8*)cm_alloc<ScratchAlloc>(mSize);
  12. memset(mData, 0, mSize);
  13. }
  14. GpuParamBlock::GpuParamBlock(GpuParamBlock* otherBlock)
  15. {
  16. mSize = otherBlock->mSize;
  17. mData = (UINT8*)cm_alloc<ScratchAlloc>(mSize);
  18. write(0, otherBlock->getData(), otherBlock->getSize());
  19. mDirty = otherBlock->mDirty;
  20. }
  21. GpuParamBlock::~GpuParamBlock()
  22. {
  23. if(mData != nullptr)
  24. cm_free<ScratchAlloc>(mData);
  25. }
  26. void GpuParamBlock::write(UINT32 offset, const void* data, UINT32 size)
  27. {
  28. #if CM_DEBUG_MODE
  29. if(offset < 0 || (offset + size) > mSize)
  30. {
  31. CM_EXCEPT(InvalidParametersException, "Wanted range is out of buffer bounds. " \
  32. "Available range: 0 .. " + toString(mSize) + ". " \
  33. "Wanted range: " + toString(offset) + " .. " + toString(offset + size) + ".");
  34. }
  35. #endif
  36. memcpy(mData + offset, data, size);
  37. mDirty = true;
  38. }
  39. void GpuParamBlock::read(UINT32 offset, void* data, UINT32 size)
  40. {
  41. #if CM_DEBUG_MODE
  42. if(offset < 0 || (offset + size) > mSize)
  43. {
  44. CM_EXCEPT(InvalidParametersException, "Wanted range is out of buffer bounds. " \
  45. "Available range: 0 .. " + toString(mSize) + ". " \
  46. "Wanted range: " + toString(offset) + " .. " + toString(offset + size) + ".");
  47. }
  48. #endif
  49. memcpy(data, mData + offset, size);
  50. }
  51. void GpuParamBlock::zeroOut(UINT32 offset, UINT32 size)
  52. {
  53. #if CM_DEBUG_MODE
  54. if(offset < 0 || (offset + size) > mSize)
  55. {
  56. CM_EXCEPT(InvalidParametersException, "Wanted range is out of buffer bounds. " \
  57. "Available range: 0 .. " + toString(mSize) + ". " \
  58. "Wanted range: " + toString(offset) + " .. " + toString(offset + size) + ".");
  59. }
  60. #endif
  61. memset(mData + offset, 0, size);
  62. mDirty = true;
  63. }
  64. }