source: OGRE/trunk/ogrenew/OgreMain/include/OgreHardwarePixelBuffer.h @ 692

Revision 692, 8.5 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

RevLine 
[692]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-2005 The OGRE Team
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-----------------------------------------------------------------------------
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
35namespace Ogre {
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 _OgreExport HardwarePixelBuffer : public HardwareBuffer
44    {
45    protected:
46        // Extents
47        size_t mWidth, mHeight, mDepth;
48        // Pitches (offsets between rows and slices)
49        size_t mRowPitch, mSlicePitch;
50        // Internal format
51        PixelFormat mFormat;
52        // Currently locked region
53        PixelBox mCurrentLock;
54       
55        /// Internal implementation of lock(), must be overridden in subclasses
56        virtual PixelBox lockImpl(const Image::Box lockBox,  LockOptions options) = 0;
57
58        /// Internal implementation of lock(), do not OVERRIDE or CALL this
59        /// for HardwarePixelBuffer implementations, but override the previous method
60        virtual void* lockImpl(size_t offset, size_t length, LockOptions options);
61
62        /// Internal implementation of unlock(), must be overridden in subclasses
63        // virtual void unlockImpl(void) = 0;
64
65                /** Notify TextureBuffer of destruction of render target.
66                        Called by RenderTexture when destroyed.
67                */
68                virtual void _clearSliceRTT(size_t zoffset);
69                friend class RenderTexture;
70    public:
71        /// Should be called by HardwareBufferManager
72        HardwarePixelBuffer(size_t mWidth, size_t mHeight, size_t mDepth,
73                PixelFormat mFormat,
74                HardwareBuffer::Usage usage, bool useSystemMemory, bool useShadowBuffer);
75        ~HardwarePixelBuffer();
76
77        /** make every lock method from HardwareBuffer available.
78        See http://www.research.att.com/~bs/bs_faq2.html#overloadderived
79        */
80        using HardwareBuffer::lock;     
81
82        /** Lock the buffer for (potentially) reading / writing.
83                    @param lockBox Region of the buffer to lock
84                    @param options Locking options
85                    @returns PixelBox containing the locked region, the pitches and
86                        the pixel format
87                */
88                virtual const PixelBox& lock(const Image::Box& lockBox, LockOptions options);
89                /// @copydoc HardwareBuffer::lock
90        virtual void* lock(size_t offset, size_t length, LockOptions options);
91
92                /** Get the current locked region. This is the same value as returned
93                    by lock(const Image::Box, LockOptions)
94                    @returns PixelBox containing the locked region
95                */       
96        const PixelBox& getCurrentLock();
97               
98                /// @copydoc HardwareBuffer::readData
99                virtual void readData(size_t offset, size_t length, void* pDest);
100                /// @copydoc HardwareBuffer::writeData
101                virtual void writeData(size_t offset, size_t length, const void* pSource,
102                                bool discardWholeBuffer = false);
103       
104        /** Copies a box from another PixelBuffer to a region of the
105                this PixelBuffer.
106                        @param dst              Source pixel buffer
107                @param srcBox   Image::Box describing the source region in src
108                @param dstBox   Image::Box describing the destination region in this buffer
109                        @remarks The source and destination regions dimensions don't have to match, in which
110                        case scaling is done. This scaling is generally done using a bilinear filter in hardware,
111            but it is faster to pass the source image in the right dimensions.
112                        @note Only call this function when both  buffers are unlocked.
113         */       
114        virtual void blit(const HardwarePixelBufferSharedPtr &src, const Image::Box &srcBox, const Image::Box &dstBox);
115
116                /** Convience function that blits the entire source pixel buffer to this buffer.
117                        If source and destination dimensions don't match, scaling is done.
118                        @param src              PixelBox containing the source pixels and format in memory
119                        @note Only call this function when the buffer is unlocked.
120                */
121                void blit(const HardwarePixelBufferSharedPtr &src);
122               
123                /** Copies a region from normal memory to a region of this pixelbuffer. The source
124                        image can be in any pixel format supported by OGRE, and in any size.
125                        @param src              PixelBox containing the source pixels and format in memory
126                        @param dstBox   Image::Box describing the destination region in this buffer
127            @remarks The source and destination regions dimensions don't have to match, in which
128            case scaling is done. This scaling is generally done using a bilinear filter in hardware,
129            but it is faster to pass the source image in the right dimensions.
130                        @note Only call this function when the buffer is unlocked.
131                */
132                virtual void blitFromMemory(const PixelBox &src, const Image::Box &dstBox) = 0;
133               
134                /** Convience function that blits a pixelbox from memory to the entire
135                        buffer. The source image is scaled as needed.
136                        @param src              PixelBox containing the source pixels and format in memory
137                        @note Only call this function when the buffer is unlocked.
138                */
139                void blitFromMemory(const PixelBox &src)
140                {
141                        blitFromMemory(src, Box(0,0,0,mWidth,mHeight,mDepth));
142                }
143               
144                /** Copies a region of this pixelbuffer to normal memory.
145                        @param srcBox   Image::Box describing the source region of this buffer
146                        @param dst              PixelBox describing the destination pixels and format in memory
147                        @remarks The source and destination regions don't have to match, in which
148                        case scaling is done.
149                        @note Only call this function when the buffer is unlocked.
150                 */
151                virtual void blitToMemory(const Image::Box &srcBox, const PixelBox &dst) = 0;
152
153                /** Convience function that blits this entire buffer to a pixelbox.
154                        The image is scaled as needed.
155                        @param src              PixelBox containing the source pixels and format in memory
156                        @note Only call this function when the buffer is unlocked.
157                */
158                void blitToMemory(const PixelBox &dst)
159                {
160                        blitToMemory(Box(0,0,0,mWidth,mHeight,mDepth), dst);
161                }
162       
163        /** Get a render target for this PixelBuffer, or a slice of it. The texture this
164            was acquired from must have TU_RENDERTARGET set, otherwise it is possible to
165            render to it and this method will throw an ERR_RENDERSYSTEM exception.
166            @param slice    Which slice
167            @returns A pointer to the render target. This pointer has the lifespan of this
168            PixelBuffer.
169        */
170        virtual RenderTexture *getRenderTarget(size_t slice=0);
171       
172        /// Gets the width of this buffer
173        size_t getWidth() const { return mWidth; }
174        /// Gets the height of this buffer
175        size_t getHeight() const { return mHeight; }
176        /// Gets the depth of this buffer
177        size_t getDepth() const { return mDepth; }
178        /// Gets the native pixel format of this buffer
179        PixelFormat getFormat() const { return mFormat; }
180    };
181
182    /** Shared pointer implementation used to share pixel buffers. */
183    class _OgreExport HardwarePixelBufferSharedPtr : public SharedPtr<HardwarePixelBuffer>
184    {
185    public:
186        HardwarePixelBufferSharedPtr() : SharedPtr<HardwarePixelBuffer>() {}
187        explicit HardwarePixelBufferSharedPtr(HardwarePixelBuffer* buf);
188
189
190    };
191
192}
193#endif
194
Note: See TracBrowser for help on using the repository browser.