Coverage Report

Created: 2025-08-28 06:22

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