Coverage Report

Created: 2025-11-04 07:18

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