BsPixelBuffer.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. /** @addtogroup RenderAPI-Internal
  10. * @{
  11. */
  12. /**
  13. * Represents a hardware buffer that stores a single pixel surface. This may be a 1D, 2D or 3D surface, but unlike a
  14. * texture it consists only of a single surface (no mip maps, cube map faces or similar).
  15. *
  16. * @note Core thread only
  17. */
  18. class BS_CORE_EXPORT PixelBuffer : public HardwareBuffer
  19. {
  20. public:
  21. /**
  22. * Constructs a new pixel buffer with the provided settings.
  23. *
  24. * @param[in] width Width of the pixel buffer in pixels.
  25. * @param[in] height Height of the pixel buffer in pixels.
  26. * @param[in] depth Depth of the pixel buffer in pixels (number of 2D slices).
  27. * @param[in] format Format of each pixel in the buffer.
  28. * @param[in] usage Usage signaling the render system how we plan on using the buffer.
  29. * @param[in] useSystemMemory True if buffer should be allocated in system memory.
  30. */
  31. PixelBuffer(UINT32 width, UINT32 height, UINT32 depth, PixelFormat format,
  32. GpuBufferUsage usage, bool useSystemMemory);
  33. ~PixelBuffer();
  34. // Make the other lock overloads visible.
  35. using HardwareBuffer::lock;
  36. /**
  37. * Locks a certain region of the pixel buffer for reading and returns a pointer to the locked region.
  38. *
  39. * @param[in] lockBox Region of the surface to lock.
  40. * @param[in] options Lock options that hint the hardware on what you intend to do with the locked data.
  41. *
  42. * @note Returned object is only valid while the lock is active.
  43. */
  44. virtual const PixelData& lock(const PixelVolume& lockBox, GpuLockOptions options);
  45. /** @copydoc HardwareBuffer::lock */
  46. virtual void* lock(UINT32 offset, UINT32 length, GpuLockOptions options);
  47. /** @copydoc HardwareBuffer::readData */
  48. virtual void readData(UINT32 offset, UINT32 length, void* dest);
  49. /** @copydoc HardwareBuffer::writeData */
  50. virtual void writeData(UINT32 offset, UINT32 length, const void* source,
  51. 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. /**
  63. * Internal implementation of the lock() method.
  64. *
  65. * @copydoc lock(const PixelVolume&, GpuLockOptions)
  66. */
  67. virtual PixelData lockImpl(PixelVolume lockBox, GpuLockOptions options) = 0;
  68. /** @copydoc HardwareBuffer::lock(UINT32, UINT32, GpuLockOptions) */
  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. /** @} */
  78. }