Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre_src_v1-9-0/OgreMain/include/OgreHardwarePixelBuffer.h @ 148

Last change on this file since 148 was 148, checked in by patricwi, 6 years ago

Added new dependencies for ogre1.9 and cegui0.8

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-2013 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE SOFTWARE.
26-----------------------------------------------------------------------------
27*/
28#ifndef __HardwarePixelBuffer__
29#define __HardwarePixelBuffer__
30
31// Precompiler options
32#include "OgrePrerequisites.h"
33#include "OgreHardwareBuffer.h"
34#include "OgreSharedPtr.h"
35#include "OgrePixelFormat.h"
36#include "OgreImage.h"
37#include "OgreHeaderPrefix.h"
38
39namespace Ogre {
40
41        /** \addtogroup Core
42        *  @{
43        */
44        /** \addtogroup RenderSystem
45        *  @{
46        */
47        /** Specialisation of HardwareBuffer for a pixel buffer. The
48        HardwarePixelbuffer abstracts an 1D, 2D or 3D quantity of pixels
49        stored by the rendering API. The buffer can be located on the card
50        or in main memory depending on its usage. One mipmap level of a
51        texture is an example of a HardwarePixelBuffer.
52    */
53    class _OgreExport HardwarePixelBuffer : public HardwareBuffer
54    {
55    protected: 
56        /// Extents
57        uint32 mWidth, mHeight, mDepth;
58        /// Pitches (offsets between rows and slices)
59        size_t mRowPitch, mSlicePitch;
60        /// Internal format
61        PixelFormat mFormat;
62        /// Currently locked region (local coords)
63        PixelBox mCurrentLock;
64                /// The current locked box of this surface (entire surface coords)
65                Image::Box mLockedBox;
66
67       
68        /// Internal implementation of lock(), must be overridden in subclasses
69        virtual PixelBox lockImpl(const Image::Box lockBox,  LockOptions options) = 0;
70
71        /** Internal implementation of lock(), do not OVERRIDE or CALL this
72            for HardwarePixelBuffer implementations, but override the previous method */
73        virtual void* lockImpl(size_t offset, size_t length, LockOptions options);
74
75                /** Notify TextureBuffer of destruction of render target.
76                        Called by RenderTexture when destroyed.
77                */
78                virtual void _clearSliceRTT(size_t zoffset);
79                friend class RenderTexture;
80    public:
81        /// Should be called by HardwareBufferManager
82        HardwarePixelBuffer(uint32 mWidth, uint32 mHeight, uint32 mDepth,
83                PixelFormat mFormat,
84                HardwareBuffer::Usage usage, bool useSystemMemory, bool useShadowBuffer);
85        ~HardwarePixelBuffer();
86
87        /** Make every lock method from HardwareBuffer available.
88        See http://www.research.att.com/~bs/bs_faq2.html#overloadderived
89        */
90        using HardwareBuffer::lock;     
91
92        /** Lock the buffer for (potentially) reading / writing.
93                    @param lockBox Region of the buffer to lock
94                    @param options Locking options
95                    @return PixelBox containing the locked region, the pitches and
96                        the pixel format
97                */
98                virtual const PixelBox& lock(const Image::Box& lockBox, LockOptions options);
99                /// @copydoc HardwareBuffer::lock
100        virtual void* lock(size_t offset, size_t length, LockOptions options);
101
102                /** Get the current locked region. This is the same value as returned
103                    by lock(const Image::Box, LockOptions)
104                    @return PixelBox containing the locked region
105                */       
106        const PixelBox& getCurrentLock();
107               
108                /// @copydoc HardwareBuffer::readData
109                virtual void readData(size_t offset, size_t length, void* pDest);
110                /// @copydoc HardwareBuffer::writeData
111                virtual void writeData(size_t offset, size_t length, const void* pSource,
112                                bool discardWholeBuffer = false);
113       
114        /** Copies a box from another PixelBuffer to a region of the
115                this PixelBuffer.
116                        @param src              Source pixel buffer
117                @param srcBox   Image::Box describing the source region in src
118                @param dstBox   Image::Box describing the destination region in this buffer
119                        @remarks The source and destination regions dimensions don't have to match, in which
120                        case scaling is done. This scaling is generally done using a bilinear filter in hardware,
121            but it is faster to pass the source image in the right dimensions.
122                        @note Only call this function when both  buffers are unlocked.
123         */       
124        virtual void blit(const HardwarePixelBufferSharedPtr &src, const Image::Box &srcBox, const Image::Box &dstBox);
125
126                /** Convenience function that blits the entire source pixel buffer to this buffer.
127                        If source and destination dimensions don't match, scaling is done.
128                        @param src              PixelBox containing the source pixels and format in memory
129                        @note Only call this function when the buffer is unlocked.
130                */
131                void blit(const HardwarePixelBufferSharedPtr &src); 
132               
133                /** Copies a region from normal memory to a region of this pixelbuffer. The source
134                        image can be in any pixel format supported by OGRE, and in any size.
135                        @param src              PixelBox containing the source pixels and format in memory
136                        @param dstBox   Image::Box describing the destination region in this buffer
137            @remarks The source and destination regions dimensions don't have to match, in which
138            case scaling is done. This scaling is generally done using a bilinear filter in hardware,
139            but it is faster to pass the source image in the right dimensions.
140                        @note Only call this function when the buffer is unlocked.
141                */
142                virtual void blitFromMemory(const PixelBox &src, const Image::Box &dstBox) = 0;
143               
144                /** Convenience function that blits a pixelbox from memory to the entire
145                        buffer. The source image is scaled as needed.
146                        @param src              PixelBox containing the source pixels and format in memory
147                        @note Only call this function when the buffer is unlocked.
148                */
149                void blitFromMemory(const PixelBox &src)
150                {
151                        blitFromMemory(src, Box(0,0,0,mWidth,mHeight,mDepth));
152                }
153               
154                /** Copies a region of this pixelbuffer to normal memory.
155                        @param srcBox   Image::Box describing the source region of this buffer
156                        @param dst              PixelBox describing the destination pixels and format in memory
157                        @remarks The source and destination regions don't have to match, in which
158                        case scaling is done.
159                        @note Only call this function when the buffer is unlocked.
160                 */
161                virtual void blitToMemory(const Image::Box &srcBox, const PixelBox &dst) = 0;
162
163                /** Convenience function that blits this entire buffer to a pixelbox.
164                        The image is scaled as needed.
165                        @param dst              PixelBox describing the destination pixels and format in memory
166                        @note Only call this function when the buffer is unlocked.
167                */
168                void blitToMemory(const PixelBox &dst)
169                {
170                        blitToMemory(Box(0,0,0,mWidth,mHeight,mDepth), dst);
171                }
172       
173        /** Get a render target for this PixelBuffer, or a slice of it. The texture this
174            was acquired from must have TU_RENDERTARGET set, otherwise it is possible to
175            render to it and this method will throw an ERR_RENDERSYSTEM exception.
176            @param slice    Which slice
177            @return A pointer to the render target. This pointer has the lifespan of this
178            PixelBuffer.
179        */
180        virtual RenderTexture *getRenderTarget(size_t slice=0);
181       
182        /// Gets the width of this buffer
183        uint32 getWidth() const { return mWidth; }
184        /// Gets the height of this buffer
185        uint32 getHeight() const { return mHeight; }
186        /// Gets the depth of this buffer
187        uint32 getDepth() const { return mDepth; }
188        /// Gets the native pixel format of this buffer
189        PixelFormat getFormat() const { return mFormat; }
190    };
191
192    /** Shared pointer implementation used to share pixel buffers. */
193    class _OgreExport HardwarePixelBufferSharedPtr : public SharedPtr<HardwarePixelBuffer>
194    {
195    public:
196        HardwarePixelBufferSharedPtr() : SharedPtr<HardwarePixelBuffer>() {}
197        explicit HardwarePixelBufferSharedPtr(HardwarePixelBuffer* buf);
198
199
200    };
201
202        /** @} */
203        /** @} */
204}
205
206#include "OgreHeaderSuffix.h"
207
208#endif
209
Note: See TracBrowser for help on using the repository browser.