BsPixelBuffer.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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* pDest);
  49. /** @copydoc HardwareBuffer::writeData */
  50. virtual void writeData(UINT32 offset, UINT32 length, const void* pSource, BufferWriteType writeFlags = BufferWriteType::Normal);
  51. /** Returns width of the surface in pixels. */
  52. UINT32 getWidth() const { return mWidth; }
  53. /** Returns height of the surface in pixels. */
  54. UINT32 getHeight() const { return mHeight; }
  55. /** Returns depth of the surface in pixels. */
  56. UINT32 getDepth() const { return mDepth; }
  57. /** Returns format of the pixels in the surface. */
  58. PixelFormat getFormat() const { return mFormat; }
  59. protected:
  60. friend class RenderTexture;
  61. /** Internal implementation of the lock() method. */
  62. virtual PixelData lockImpl(PixelVolume lockBox, GpuLockOptions options) = 0;
  63. /** @copydoc HardwareBuffer::lockImpl */
  64. virtual void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options);
  65. protected:
  66. UINT32 mWidth, mHeight, mDepth;
  67. UINT32 mRowPitch, mSlicePitch;
  68. PixelFormat mFormat;
  69. PixelData mCurrentLock;
  70. PixelVolume mLockedBox;
  71. };
  72. /** @} */
  73. }