CmGpuParamBlock.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include "CmGpuParamBlock.h"
  2. #include "CmGpuParamDesc.h"
  3. #include "CmHardwareBufferManager.h"
  4. #include "CmException.h"
  5. namespace CamelotEngine
  6. {
  7. GpuParamBlock::GpuParamBlock(const GpuParamBlockDesc& desc)
  8. :mSize(desc.blockSize * sizeof(UINT32)), mDirty(true)
  9. {
  10. mData = new UINT8[desc.blockSize];
  11. memset(mData, 0, desc.blockSize);
  12. }
  13. GpuParamBlock::~GpuParamBlock()
  14. {
  15. delete [] mData;
  16. }
  17. void GpuParamBlock::write(UINT32 offset, const void* data, UINT32 size)
  18. {
  19. #if CM_DEBUG_MODE
  20. if(offset < 0 || (offset + size) > mSize)
  21. {
  22. CM_EXCEPT(InvalidParametersException, "Wanted range is out of buffer bounds. " \
  23. "Available range: 0 .. " + toString(mSize) + ". " \
  24. "Wanted range: " + toString(offset) + " .. " + toString(offset + size) + ".");
  25. }
  26. #endif
  27. memcpy(mData + offset, data, size);
  28. mDirty = true;
  29. }
  30. void GpuParamBlock::zeroOut(UINT32 offset, UINT32 size)
  31. {
  32. #if CM_DEBUG_MODE
  33. if(offset < 0 || (offset + size) > mSize)
  34. {
  35. CM_EXCEPT(InvalidParametersException, "Wanted range is out of buffer bounds. " \
  36. "Available range: 0 .. " + toString(mSize) + ". " \
  37. "Wanted range: " + toString(offset) + " .. " + toString(offset + size) + ".");
  38. }
  39. #endif
  40. memset(mData + offset, 0, size);
  41. mDirty = true;
  42. }
  43. const UINT8* GpuParamBlock::getDataPtr(UINT32 offset) const
  44. {
  45. #if CM_DEBUG_MODE
  46. if(offset < 0 || offset >= mSize)
  47. {
  48. CM_EXCEPT(InvalidParametersException, "Wanted range is out of buffer bounds. " \
  49. "Available range: 0 .. " + toString(mSize) + ". " \
  50. "Wanted range: " + toString(offset) + " .. " + toString(offset) + ".");
  51. }
  52. #endif
  53. return &mData[offset];
  54. }
  55. void GpuParamBlock::updateIfDirty()
  56. {
  57. mDirty = false;
  58. // Do nothing
  59. }
  60. GpuParamBlockPtr GpuParamBlock::clone() const
  61. {
  62. GpuParamBlockPtr clonedParamBlock(new GpuParamBlock(*this));
  63. clonedParamBlock->mData = new UINT8[mSize];
  64. memcpy(clonedParamBlock->mData, mData, mSize);
  65. return clonedParamBlock;
  66. }
  67. GpuParamBlockPtr GpuParamBlock::create(const GpuParamBlockDesc& desc)
  68. {
  69. return HardwareBufferManager::instance().createGpuParamBlock(desc);
  70. }
  71. }