Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/OgreMain/include/OgreHardwarePixelBuffer.h @ 1

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