BsPixelBuffer.h 3.1 KB

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