BsPixelBuffer.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. /**
  18. * @brief Constructs a new pixel buffer with the provided settings.
  19. *
  20. * @param width Width of the pixel buffer in pixels.
  21. * @param height Height of the pixel buffer in pixels.
  22. * @param depth Depth of the pixel buffer in pixels (number of 2D slices).
  23. * @param format Format of each pixel in the buffer.
  24. * @param usage Usage signaling the render system how we plan on using the buffer.
  25. * @param useSystemMemory True if buffer should be allocated in system memory.
  26. */
  27. PixelBuffer(UINT32 width, UINT32 height, UINT32 depth, PixelFormat format,
  28. GpuBufferUsage usage, bool useSystemMemory);
  29. ~PixelBuffer();
  30. // Make the other lock overloads visible.
  31. using HardwareBuffer::lock;
  32. /**
  33. * @brief Locks a certain region of the pixel buffer for reading and returns a pointer
  34. * to the locked region.
  35. *
  36. * @param lockBox Region of the surface to lock.
  37. * @param options Lock options that hint the hardware on what you intend to do with the locked data.
  38. *
  39. * @note Returned object is only valid while the lock is active.
  40. */
  41. virtual const PixelData& lock(const PixelVolume& lockBox, GpuLockOptions options);
  42. /**
  43. * @copydoc HardwareBuffer::lock
  44. */
  45. virtual void* lock(UINT32 offset, UINT32 length, GpuLockOptions options);
  46. /**
  47. * @copydoc HardwareBuffer::readData
  48. */
  49. virtual void readData(UINT32 offset, UINT32 length, void* pDest);
  50. /**
  51. * @copydoc HardwareBuffer::writeData
  52. */
  53. virtual void writeData(UINT32 offset, UINT32 length, const void* pSource, BufferWriteType writeFlags = BufferWriteType::Normal);
  54. /**
  55. * @brief Returns width of the surface in pixels.
  56. */
  57. UINT32 getWidth() const { return mWidth; }
  58. /**
  59. * @brief Returns height of the surface in pixels.
  60. */
  61. UINT32 getHeight() const { return mHeight; }
  62. /**
  63. * @brief Returns depth of the surface in pixels.
  64. */
  65. UINT32 getDepth() const { return mDepth; }
  66. /**
  67. * @brief Returns format of the pixels in the surface.
  68. */
  69. PixelFormat getFormat() const { return mFormat; }
  70. protected:
  71. friend class RenderTexture;
  72. /**
  73. * @brief Internal implementation of the "lock" method.
  74. */
  75. virtual PixelData lockImpl(PixelVolume lockBox, GpuLockOptions options) = 0;
  76. /**
  77. * @copydoc HardwareBuffer::lockImpl
  78. */
  79. virtual void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options);
  80. protected:
  81. UINT32 mWidth, mHeight, mDepth;
  82. UINT32 mRowPitch, mSlicePitch;
  83. PixelFormat mFormat;
  84. PixelData mCurrentLock;
  85. PixelVolume mLockedBox;
  86. };
  87. }