BsPixelBuffer.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsHardwareBuffer.h"
  4. #include "BsPixelUtil.h"
  5. namespace BansheeEngine
  6. {
  7. /**
  8. * @brief Represents a hardware buffer that stores a single pixel surface.
  9. * This may be a 1D, 2D or 3D surface, but unlike a texture it consists
  10. * only of a single surface (no mip maps, cube map faces or similar).
  11. *
  12. * @note Core thread only
  13. */
  14. class BS_CORE_EXPORT PixelBuffer : public HardwareBuffer
  15. {
  16. public:
  17. PixelBuffer(UINT32 mWidth, UINT32 mHeight, UINT32 mDepth, PixelFormat mFormat,
  18. GpuBufferUsage usage, bool useSystemMemory);
  19. ~PixelBuffer();
  20. // Make the other lock overloads visible.
  21. using HardwareBuffer::lock;
  22. /**
  23. * @brief Locks a certain region of the pixel buffer for reading and returns a pointer
  24. * to the locked region.
  25. *
  26. * @param lockBox Region of the surface to lock.
  27. * @param options Lock options that hint the hardware on what you intend to do with the locked data.
  28. *
  29. * @note Returned object is only valid while the lock is active.
  30. */
  31. virtual const PixelData& lock(const PixelVolume& lockBox, GpuLockOptions options);
  32. /**
  33. * @copydoc HardwareBuffer::lock
  34. */
  35. virtual void* lock(UINT32 offset, UINT32 length, GpuLockOptions options);
  36. /**
  37. * @copydoc HardwareBuffer::readData
  38. */
  39. virtual void readData(UINT32 offset, UINT32 length, void* pDest);
  40. /**
  41. * @copydoc HardwareBuffer::writeData
  42. */
  43. virtual void writeData(UINT32 offset, UINT32 length, const void* pSource, BufferWriteType writeFlags = BufferWriteType::Normal);
  44. /**
  45. * @brief Returns width of the surface in pixels.
  46. */
  47. UINT32 getWidth() const { return mWidth; }
  48. /**
  49. * @brief Returns height of the surface in pixels.
  50. */
  51. UINT32 getHeight() const { return mHeight; }
  52. /**
  53. * @brief Returns depth of the surface in pixels.
  54. */
  55. UINT32 getDepth() const { return mDepth; }
  56. /**
  57. * @brief Returns format of the pixels in the surface.
  58. */
  59. PixelFormat getFormat() const { return mFormat; }
  60. protected:
  61. friend class RenderTexture;
  62. /**
  63. * @brief Internal implementation of the "lock" method.
  64. */
  65. virtual PixelData lockImpl(PixelVolume lockBox, GpuLockOptions options) = 0;
  66. /**
  67. * @copydoc HardwareBuffer::lockImpl
  68. */
  69. virtual void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options);
  70. protected:
  71. UINT32 mWidth, mHeight, mDepth;
  72. UINT32 mRowPitch, mSlicePitch;
  73. PixelFormat mFormat;
  74. PixelData mCurrentLock;
  75. PixelVolume mLockedBox;
  76. };
  77. }