BsPixelBuffer.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsPixelBuffer.h"
  4. #include "BsException.h"
  5. namespace BansheeEngine
  6. {
  7. PixelBuffer::PixelBuffer(UINT32 width, UINT32 height, UINT32 depth,
  8. PixelFormat format,
  9. GpuBufferUsage usage, bool useSystemMemory):
  10. HardwareBuffer(usage, useSystemMemory),
  11. mWidth(width), mHeight(height), mDepth(depth),
  12. mFormat(format)
  13. {
  14. mRowPitch = mWidth;
  15. mSlicePitch = mHeight*mWidth;
  16. mSizeInBytes = mHeight*mWidth*PixelUtil::getNumElemBytes(mFormat);
  17. }
  18. PixelBuffer::~PixelBuffer()
  19. {
  20. }
  21. void* PixelBuffer::lock(UINT32 offset, UINT32 length, GpuLockOptions options)
  22. {
  23. assert(!isLocked() && "Cannot lock this buffer, it is already locked!");
  24. assert(offset == 0 && length == mSizeInBytes && "Cannot lock memory region, most lock box or entire buffer");
  25. PixelVolume myBox(0, 0, 0, mWidth, mHeight, mDepth);
  26. const PixelData &rv = lock(myBox, options);
  27. return rv.getData();
  28. }
  29. const PixelData& PixelBuffer::lock(const PixelVolume& lockBox, GpuLockOptions options)
  30. {
  31. // Lock the real buffer if there is no shadow buffer
  32. mCurrentLock = lockImpl(lockBox, options);
  33. mIsLocked = true;
  34. return mCurrentLock;
  35. }
  36. void* PixelBuffer::lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options)
  37. {
  38. BS_EXCEPT(InternalErrorException, "lockImpl(offset,length) is not valid for PixelBuffers and should never be called");
  39. }
  40. void PixelBuffer::readData(UINT32 offset, UINT32 length, void* pDest)
  41. {
  42. // TODO
  43. BS_EXCEPT(NotImplementedException, "Reading a byte range is not implemented. Use blitToMemory.");
  44. }
  45. void PixelBuffer::writeData(UINT32 offset, UINT32 length, const void* pSource, BufferWriteType writeFlags)
  46. {
  47. // TODO
  48. BS_EXCEPT(NotImplementedException, "Writing a byte range is not implemented. Use blitFromMemory.");
  49. }
  50. }