BsPixelBuffer.h 3.3 KB

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