CmPixelBuffer.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. -----------------------------------------------------------------------------
  3. This source file is part of OGRE
  4. (Object-oriented Graphics Rendering Engine)
  5. For the latest info, see http://www.ogre3d.org/
  6. Copyright (c) 2000-2011 Torus Knot Software Ltd
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. -----------------------------------------------------------------------------
  23. */
  24. #ifndef __HardwarePixelBuffer__
  25. #define __HardwarePixelBuffer__
  26. // Precompiler options
  27. #include "CmPrerequisites.h"
  28. #include "CmHardwareBuffer.h"
  29. #include "CmPixelUtil.h"
  30. namespace CamelotFramework {
  31. /** \addtogroup Core
  32. * @{
  33. */
  34. /** \addtogroup RenderSystem
  35. * @{
  36. */
  37. /** Specialisation of HardwareBuffer for a pixel buffer. The
  38. HardwarePixelbuffer abstracts an 1D, 2D or 3D quantity of pixels
  39. stored by the rendering API. The buffer can be located on the card
  40. or in main memory depending on its usage. One mipmap level of a
  41. texture is an example of a HardwarePixelBuffer.
  42. */
  43. class CM_EXPORT PixelBuffer : public HardwareBuffer
  44. {
  45. protected:
  46. // Extents
  47. UINT32 mWidth, mHeight, mDepth;
  48. // Pitches (offsets between rows and slices)
  49. UINT32 mRowPitch, mSlicePitch;
  50. // Internal format
  51. PixelFormat mFormat;
  52. // Currently locked region (local coords)
  53. PixelData mCurrentLock;
  54. // The current locked box of this surface (entire surface coords)
  55. PixelVolume mLockedBox;
  56. /// Internal implementation of lock(), must be overridden in subclasses
  57. virtual PixelData lockImpl(const PixelVolume lockBox, GpuLockOptions options) = 0;
  58. /// Internal implementation of lock(), do not OVERRIDE or CALL this
  59. /// for HardwarePixelBuffer implementations, but override the previous method
  60. virtual void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options);
  61. friend class RenderTexture;
  62. public:
  63. /// Should be called by HardwareBufferManager
  64. PixelBuffer(UINT32 mWidth, UINT32 mHeight, UINT32 mDepth,
  65. PixelFormat mFormat, GpuBufferUsage usage, bool useSystemMemory);
  66. ~PixelBuffer();
  67. /** make every lock method from HardwareBuffer available.
  68. See http://www.research.att.com/~bs/bs_faq2.html#overloadderived
  69. */
  70. using HardwareBuffer::lock;
  71. /** Lock the buffer for (potentially) reading / writing.
  72. @param lockBox Region of the buffer to lock
  73. @param options Locking options
  74. @returns PixelBox containing the locked region, the pitches and
  75. the pixel format
  76. */
  77. virtual const PixelData& lock(const PixelVolume& lockBox, GpuLockOptions options);
  78. /// @copydoc HardwareBuffer::lock
  79. virtual void* lock(UINT32 offset, UINT32 length, GpuLockOptions options);
  80. /** Get the current locked region. This is the same value as returned
  81. by lock(const Image::Box, LockOptions)
  82. @returns PixelBox containing the locked region
  83. */
  84. const PixelData& getCurrentLock();
  85. /// @copydoc HardwareBuffer::readData
  86. virtual void readData(UINT32 offset, UINT32 length, void* pDest);
  87. /// @copydoc HardwareBuffer::writeData
  88. virtual void writeData(UINT32 offset, UINT32 length, const void* pSource, BufferWriteType writeFlags = BufferWriteType::Normal);
  89. /// Gets the width of this buffer
  90. UINT32 getWidth() const { return mWidth; }
  91. /// Gets the height of this buffer
  92. UINT32 getHeight() const { return mHeight; }
  93. /// Gets the depth of this buffer
  94. UINT32 getDepth() const { return mDepth; }
  95. /// Gets the native pixel format of this buffer
  96. PixelFormat getFormat() const { return mFormat; }
  97. };
  98. /** @} */
  99. }
  100. #endif