Coverage Report

Created: 2025-11-11 06:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ogre/OgreMain/include/OgreDepthBuffer.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 __DepthBuffer_H__
29
#define __DepthBuffer_H__
30
31
#include "OgreCommon.h"
32
#include "OgrePrerequisites.h"
33
#include "OgreHeaderPrefix.h"
34
35
namespace Ogre
36
{
37
    /** \addtogroup Core
38
    *  @{
39
    */
40
    /** \addtogroup RenderSystem
41
    *  @{
42
    */
43
44
    /** An abstract class that contains a depth/stencil buffer.
45
        Depth Buffers can be attached to render targets. Note we handle Depth & Stencil together.
46
        DepthBuffer sharing is handled automatically for you. However, there are times where you want
47
        to specifically control depth buffers to achieve certain effects or increase performance.
48
        You can control this by hinting Ogre with POOL IDs. Created depth buffers can live in different
49
        pools, or all together in the same one.
50
        Usually, a depth buffer can only be attached to a RenderTarget if it's dimensions are bigger
51
        and have the same bit depth and same multisample settings. Depth Buffers are created automatically
52
        for new RTs when needed, and stored in the pool where the RenderTarget should have drawn from.
53
        By default, all RTs have the Id POOL_DEFAULT, which means all depth buffers are stored by default
54
        in that pool. By choosing a different Pool Id for a specific RenderTarget, that RT will only
55
        retrieve depth buffers from _that_ pool, therefore not conflicting with sharing depth buffers
56
        with other RTs (such as shadows maps).
57
        Setting an RT to POOL_MANUAL_USAGE means Ogre won't manage the DepthBuffer for you (not recommended)
58
        RTs with POOL_NO_DEPTH are very useful when you don't want to create a DepthBuffer for it. You can
59
        still manually attach a depth buffer though as internally POOL_NO_DEPTH & POOL_MANUAL_USAGE are
60
        handled in the same way.
61
62
        Behavior is consistent across all render systems, if, and only if, the same RSC flags are set
63
        RSC flags that affect this class are:
64
        - #RSC_RTT_MAIN_DEPTHBUFFER_ATTACHABLE:
65
        some APIs (ie. OpenGL w/ FBO) don't allow using
66
        the main depth buffer for offscreen RTTs. When this flag is set, the depth buffer can be
67
        shared between the main window and an RTT.
68
        - #RSC_RTT_INDEPENDENT_BUFFER_SIZE:
69
        When this flag isn't set, the depth buffer can only be shared across RTTs who have the EXACT
70
        same resolution. When it's set, it can be shared with RTTs as long as they have a
71
        resolution less or equal than the depth buffer's.
72
73
74
        Design discussion http://www.ogre3d.org/forums/viewtopic.php?f=4&t=53534&p=365582
75
     */
76
    class _OgreExport DepthBuffer : public RenderSysAlloc
77
    {
78
    public:
79
        /// @deprecated use #RenderBufferPool instead
80
        enum PoolId
81
        {
82
            POOL_NO_DEPTH       = RBP_NONE,
83
            POOL_MANUAL_USAGE   = RBP_NONE,
84
            POOL_DEFAULT        = RBP_DEFAULT
85
        };
86
87
        DepthBuffer(uint16 poolId, uint32 width, uint32 height, uint32 fsaa, bool manual);
88
        virtual ~DepthBuffer();
89
90
        /// @deprecated do not use
91
        OGRE_DEPRECATED void _setPoolId( uint16 poolId );
92
93
        /// Gets the pool id in which this DepthBuffer lives
94
        virtual uint16 getPoolId() const;
95
        virtual uint32 getWidth() const;
96
        virtual uint32 getHeight() const;
97
0
        uint32 getFSAA() const { return mFsaa; }
98
99
        /** Manual DepthBuffers are cleared in RenderSystem's destructor. Non-manual ones are released
100
            with it's render target (aka, a backbuffer or similar) */
101
        bool isManual() const;
102
103
        /** Returns whether the specified RenderTarget is compatible with this DepthBuffer
104
            That is, this DepthBuffer can be attached to that RenderTarget
105
106
            Most APIs impose the following restrictions:
107
            - Width & height must be equal or higher than the render target's
108
            - They must be of the same bit depth.
109
            - They need to have the same FSAA setting
110
            @param renderTarget The render target to test against
111
        */
112
        virtual bool isCompatible( RenderTarget *renderTarget ) const;
113
114
        /** Called when a RenderTarget is attaches this DepthBuffer
115
116
            This function doesn't actually attach. It merely informs the DepthBuffer
117
            which RenderTarget did attach. The real attachment happens in
118
            RenderTarget::attachDepthBuffer()
119
            @param renderTarget The RenderTarget that has just been attached
120
        */
121
        virtual void _notifyRenderTargetAttached( RenderTarget *renderTarget );
122
123
        /** Called when a RenderTarget is detaches from this DepthBuffer
124
125
            Same as DepthBuffer::_notifyRenderTargetAttached()
126
            @param renderTarget The RenderTarget that has just been detached
127
        */
128
        virtual void _notifyRenderTargetDetached( RenderTarget *renderTarget );
129
130
    protected:
131
        typedef std::set<RenderTarget*> RenderTargetSet;
132
133
        uint16                      mPoolId;
134
        uint32                      mWidth;
135
        uint32                      mHeight;
136
        uint32                      mFsaa;
137
138
        bool                        mManual; //We don't Release manual surfaces on destruction
139
        RenderTargetSet             mAttachedRenderTargets;
140
141
        void detachFromAllRenderTargets();
142
    };
143
}
144
145
#include "OgreHeaderSuffix.h"
146
147
#endif