CmGpuBuffer.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmCommonEnums.h"
  4. #include "CmGpuBufferView.h"
  5. #include "CmCoreObject.h"
  6. namespace CamelotFramework
  7. {
  8. class CM_EXPORT GpuBuffer : public CoreObject
  9. {
  10. public:
  11. virtual ~GpuBuffer();
  12. virtual void* lock(UINT32 offset, UINT32 length, GpuLockOptions options) = 0;
  13. virtual void unlock() = 0;
  14. virtual void readData(UINT32 offset, UINT32 length, void* pDest) = 0;
  15. virtual void writeData(UINT32 offset, UINT32 length, const void* pSource, BufferWriteType writeFlags = BufferWriteType::Normal) = 0;
  16. virtual void copyData(GpuBuffer& srcBuffer, UINT32 srcOffset,
  17. UINT32 dstOffset, UINT32 length, bool discardWholeBuffer = false) = 0;
  18. static GpuBufferView* requestView(GpuBufferPtr buffer, UINT32 firstElement, UINT32 elementWidth, UINT32 numElements, bool useCounter, GpuViewUsage usage);
  19. static void releaseView(GpuBufferView* view);
  20. GpuBufferType getType() const { return mType; }
  21. GpuBufferUsage getUsage() const { return mUsage; }
  22. bool getRandomGpuWrite() const { return mRandomGpuWrite; }
  23. bool getUseCounter() const { return mUseCounter; }
  24. UINT32 getElementCount() const { return mElementCount; }
  25. UINT32 getElementSize() const { return mElementSize; }
  26. protected:
  27. GpuBuffer(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
  28. virtual GpuBufferView* createView() = 0;
  29. virtual void destroyView(GpuBufferView* view) = 0;
  30. void clearBufferViews();
  31. /**
  32. * @copydoc CoreGpuObject::destroy_internal()
  33. */
  34. virtual void destroy_internal();
  35. struct GpuBufferReference
  36. {
  37. GpuBufferReference(GpuBufferView* _view)
  38. :view(_view), refCount(0)
  39. { }
  40. GpuBufferView* view;
  41. UINT32 refCount;
  42. };
  43. UnorderedMap<GPU_BUFFER_DESC, GpuBufferReference*, GpuBufferView::HashFunction, GpuBufferView::EqualFunction>::type mBufferViews;
  44. protected:
  45. GpuBufferType mType;
  46. GpuBufferUsage mUsage;
  47. bool mRandomGpuWrite;
  48. bool mUseCounter;
  49. UINT32 mElementCount;
  50. UINT32 mElementSize;
  51. };
  52. }