[1092] | 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 |
|
---|
| 7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
| 8 | Also see acknowledgements in Readme.html
|
---|
| 9 |
|
---|
| 10 | This program is free software; you can redistribute it and/or modify it under
|
---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
| 13 | version.
|
---|
| 14 |
|
---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
| 18 |
|
---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
| 22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
| 23 | -----------------------------------------------------------------------------
|
---|
| 24 | */
|
---|
| 25 | #ifndef __HardwarePixelBuffer__
|
---|
| 26 | #define __HardwarePixelBuffer__
|
---|
| 27 |
|
---|
| 28 | // Precompiler options
|
---|
| 29 | #include "OgrePrerequisites.h"
|
---|
| 30 | #include "OgreHardwareBuffer.h"
|
---|
| 31 | #include "OgreSharedPtr.h"
|
---|
| 32 | #include "OgrePixelFormat.h"
|
---|
| 33 | #include "OgreImage.h"
|
---|
| 34 |
|
---|
| 35 | namespace Ogre {
|
---|
| 36 | /** Specialisation of HardwareBuffer for a pixel buffer. The
|
---|
| 37 | HardwarePixelbuffer abstracts an 1D, 2D or 3D quantity of pixels
|
---|
| 38 | stored by the rendering API. The buffer can be located on the card
|
---|
| 39 | or in main memory depending on its usage. One mipmap level of a
|
---|
| 40 | texture is an example of a HardwarePixelBuffer.
|
---|
| 41 | */
|
---|
| 42 | class _OgreExport HardwarePixelBuffer : public HardwareBuffer
|
---|
| 43 | {
|
---|
| 44 | protected:
|
---|
| 45 | // Extents
|
---|
| 46 | size_t mWidth, mHeight, mDepth;
|
---|
| 47 | // Pitches (offsets between rows and slices)
|
---|
| 48 | size_t mRowPitch, mSlicePitch;
|
---|
| 49 | // Internal format
|
---|
| 50 | PixelFormat mFormat;
|
---|
| 51 | // Currently locked region
|
---|
| 52 | PixelBox mCurrentLock;
|
---|
| 53 |
|
---|
| 54 | /// Internal implementation of lock(), must be overridden in subclasses
|
---|
| 55 | virtual PixelBox lockImpl(const Image::Box lockBox, LockOptions options) = 0;
|
---|
| 56 |
|
---|
| 57 | /// Internal implementation of lock(), do not OVERRIDE or CALL this
|
---|
| 58 | /// for HardwarePixelBuffer implementations, but override the previous method
|
---|
| 59 | virtual void* lockImpl(size_t offset, size_t length, LockOptions options);
|
---|
| 60 |
|
---|
| 61 | /// Internal implementation of unlock(), must be overridden in subclasses
|
---|
| 62 | // virtual void unlockImpl(void) = 0;
|
---|
| 63 | public:
|
---|
| 64 | /// Should be called by HardwareBufferManager
|
---|
| 65 | HardwarePixelBuffer(size_t mWidth, size_t mHeight, size_t mDepth,
|
---|
| 66 | PixelFormat mFormat,
|
---|
| 67 | HardwareBuffer::Usage usage, bool useSystemMemory, bool useShadowBuffer);
|
---|
| 68 | ~HardwarePixelBuffer();
|
---|
| 69 |
|
---|
| 70 | /** make every lock method from HardwareBuffer available.
|
---|
| 71 | See http://www.research.att.com/~bs/bs_faq2.html#overloadderived
|
---|
| 72 | */
|
---|
| 73 | using HardwareBuffer::lock;
|
---|
| 74 |
|
---|
| 75 | /** Lock the buffer for (potentially) reading / writing.
|
---|
| 76 | @param lockBox Region of the buffer to lock
|
---|
| 77 | @param options Locking options
|
---|
| 78 | @returns PixelBox containing the locked region, the pitches and
|
---|
| 79 | the pixel format
|
---|
| 80 | */
|
---|
| 81 | virtual const PixelBox& lock(const Image::Box& lockBox, LockOptions options);
|
---|
| 82 | /// @copydoc HardwareBuffer::lock
|
---|
| 83 | virtual void* lock(size_t offset, size_t length, LockOptions options);
|
---|
| 84 |
|
---|
| 85 | /** Get the current locked region. This is the same value as returned
|
---|
| 86 | by lock(const Image::Box, LockOptions)
|
---|
| 87 | @returns PixelBox containing the locked region
|
---|
| 88 | */
|
---|
| 89 | const PixelBox& getCurrentLock();
|
---|
| 90 |
|
---|
| 91 | /// @copydoc HardwareBuffer::readData
|
---|
| 92 | virtual void readData(size_t offset, size_t length, void* pDest);
|
---|
| 93 | /// @copydoc HardwareBuffer::writeData
|
---|
| 94 | virtual void writeData(size_t offset, size_t length, const void* pSource,
|
---|
| 95 | bool discardWholeBuffer = false);
|
---|
| 96 |
|
---|
| 97 | /** Copies a box from another PixelBuffer to a region of the
|
---|
| 98 | this PixelBuffer.
|
---|
| 99 | @param dst Source pixel buffer
|
---|
| 100 | @param srcBox Image::Box describing the source region in src
|
---|
| 101 | @param dstBox Image::Box describing the destination region in this buffer
|
---|
| 102 | @remarks The source and destination regions dimensions don't have to match, in which
|
---|
| 103 | case scaling is done. This scaling is done in software for some render systems,
|
---|
| 104 | thus for realtime usage it is recommended to pass the source image in the right dimensions.
|
---|
| 105 | @note Only call this function when both buffers are unlocked.
|
---|
| 106 | */
|
---|
| 107 | virtual void blit(HardwarePixelBuffer *src, const Image::Box &srcBox, const Image::Box &dstBox);
|
---|
| 108 |
|
---|
| 109 | /** Convience function that blits the entire source pixel buffer to this buffer.
|
---|
| 110 | If source and destination dimensions don't match, scaling is done.
|
---|
| 111 | @param src PixelBox containing the source pixels and format in memory
|
---|
| 112 | @note Only call this function when the buffer is unlocked.
|
---|
| 113 | */
|
---|
| 114 | void blit(HardwarePixelBuffer *src)
|
---|
| 115 | {
|
---|
| 116 | blit(src,
|
---|
| 117 | Box(0,0,0,src->getWidth(),src->getHeight(),src->getDepth()),
|
---|
| 118 | Box(0,0,0,mWidth,mHeight,mDepth)
|
---|
| 119 | );
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | /** Copies a region from normal memory to a region of this pixelbuffer. The source
|
---|
| 123 | image can be in any pixel format supported by OGRE, and in any size.
|
---|
| 124 | @param src PixelBox containing the source pixels and format in memory
|
---|
| 125 | @param dstBox Image::Box describing the destination region in this buffer
|
---|
| 126 | @remarks The source and destination regions dimensions don't have to match, in which
|
---|
| 127 | case scaling is done. This scaling is done in software for some render systems,
|
---|
| 128 | so for realtime usage it is recommended to pass the source image in the right dimensions.
|
---|
| 129 | @note Only call this function when the buffer is unlocked.
|
---|
| 130 | */
|
---|
| 131 | virtual void blitFromMemory(const PixelBox &src, const Image::Box &dstBox) = 0;
|
---|
| 132 |
|
---|
| 133 | /** Convience function that blits a pixelbox from memory to the entire
|
---|
| 134 | buffer. The source image is scaled as needed.
|
---|
| 135 | @param src PixelBox containing the source pixels and format in memory
|
---|
| 136 | @note Only call this function when the buffer is unlocked.
|
---|
| 137 | */
|
---|
| 138 | void blitFromMemory(const PixelBox &src)
|
---|
| 139 | {
|
---|
| 140 | blitFromMemory(src, Box(0,0,0,mWidth,mHeight,mDepth));
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | /** Copies a region of this pixelbuffer to normal memory.
|
---|
| 144 | @param srcBox Image::Box describing the source region of this buffer
|
---|
| 145 | @param dst PixelBox describing the destination pixels and format in memory
|
---|
| 146 | @remarks The source and destination regions don't have to match, in which
|
---|
| 147 | case scaling is done.
|
---|
| 148 | @note Only call this function when the buffer is unlocked.
|
---|
| 149 | */
|
---|
| 150 | virtual void blitToMemory(const Image::Box &srcBox, const PixelBox &dst) = 0;
|
---|
| 151 |
|
---|
| 152 | /** Convience function that blits this entire buffer to a pixelbox.
|
---|
| 153 | The image is scaled as needed.
|
---|
| 154 | @param src PixelBox containing the source pixels and format in memory
|
---|
| 155 | @note Only call this function when the buffer is unlocked.
|
---|
| 156 | */
|
---|
| 157 | void blitToMemory(const PixelBox &dst)
|
---|
| 158 | {
|
---|
| 159 | blitToMemory(Box(0,0,0,mWidth,mHeight,mDepth), dst);
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | /// Gets the width of this buffer
|
---|
| 163 | size_t getWidth() const { return mWidth; }
|
---|
| 164 | /// Gets the height of this buffer
|
---|
| 165 | size_t getHeight() const { return mHeight; }
|
---|
| 166 | /// Gets the depth of this buffer
|
---|
| 167 | size_t getDepth() const { return mDepth; }
|
---|
| 168 | /// Gets the native pixel format of this buffer
|
---|
| 169 | PixelFormat getFormat() const { return mFormat; }
|
---|
| 170 | };
|
---|
| 171 |
|
---|
| 172 | /** Shared pointer implementation used to share pixel buffers. */
|
---|
| 173 | class _OgreExport HardwarePixelBufferSharedPtr : public SharedPtr<HardwarePixelBuffer>
|
---|
| 174 | {
|
---|
| 175 | public:
|
---|
| 176 | HardwarePixelBufferSharedPtr() : SharedPtr<HardwarePixelBuffer>() {}
|
---|
| 177 | explicit HardwarePixelBufferSharedPtr(HardwarePixelBuffer* buf);
|
---|
| 178 |
|
---|
| 179 |
|
---|
| 180 | };
|
---|
| 181 |
|
---|
| 182 | }
|
---|
| 183 | #endif
|
---|
| 184 |
|
---|