BsPixelBuffer.cpp 2.2 KB

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