BsPixelBuffer.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //__________________________ Banshee Project - A modern game development toolkit _________________________________//
  2. //_____________________________________ www.banshee-project.com __________________________________________________//
  3. //________________________ Copyright (c) 2014 Marko Pintera. All rights reserved. ________________________________//
  4. #pragma once
  5. #include "BsCorePrerequisites.h"
  6. #include "BsHardwareBuffer.h"
  7. #include "BsPixelUtil.h"
  8. namespace BansheeEngine
  9. {
  10. /**
  11. * @brief Represents a hardware buffer that stores a single pixel surface.
  12. * This may be a 1D, 2D or 3D surface, but unlike a texture it consists
  13. * 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. * @brief Constructs a new pixel buffer with the provided settings.
  22. *
  23. * @param width Width of the pixel buffer in pixels.
  24. * @param height Height of the pixel buffer in pixels.
  25. * @param depth Depth of the pixel buffer in pixels (number of 2D slices).
  26. * @param format Format of each pixel in the buffer.
  27. * @param usage Usage signaling the render system how we plan on using the buffer.
  28. * @param 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. * @brief Locks a certain region of the pixel buffer for reading and returns a pointer
  37. * to the locked region.
  38. *
  39. * @param lockBox Region of the surface to lock.
  40. * @param 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. /**
  46. * @copydoc HardwareBuffer::lock
  47. */
  48. virtual void* lock(UINT32 offset, UINT32 length, GpuLockOptions options);
  49. /**
  50. * @copydoc HardwareBuffer::readData
  51. */
  52. virtual void readData(UINT32 offset, UINT32 length, void* pDest);
  53. /**
  54. * @copydoc HardwareBuffer::writeData
  55. */
  56. virtual void writeData(UINT32 offset, UINT32 length, const void* pSource, BufferWriteType writeFlags = BufferWriteType::Normal);
  57. /**
  58. * @brief Returns width of the surface in pixels.
  59. */
  60. UINT32 getWidth() const { return mWidth; }
  61. /**
  62. * @brief Returns height of the surface in pixels.
  63. */
  64. UINT32 getHeight() const { return mHeight; }
  65. /**
  66. * @brief Returns depth of the surface in pixels.
  67. */
  68. UINT32 getDepth() const { return mDepth; }
  69. /**
  70. * @brief Returns format of the pixels in the surface.
  71. */
  72. PixelFormat getFormat() const { return mFormat; }
  73. protected:
  74. friend class RenderTexture;
  75. /**
  76. * @brief Internal implementation of the "lock" method.
  77. */
  78. virtual PixelData lockImpl(PixelVolume lockBox, GpuLockOptions options) = 0;
  79. /**
  80. * @copydoc HardwareBuffer::lockImpl
  81. */
  82. virtual void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options);
  83. protected:
  84. UINT32 mWidth, mHeight, mDepth;
  85. UINT32 mRowPitch, mSlicePitch;
  86. PixelFormat mFormat;
  87. PixelData mCurrentLock;
  88. PixelVolume mLockedBox;
  89. };
  90. }