[148] | 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-2013 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_SEPARATE_DEPTHBUFFER: |
---|
| 64 | The RTT can create a custom depth buffer different from the main depth buffer. This means, |
---|
| 65 | an RTT is able to not share it's depth buffer with the main window if it wants to. |
---|
| 66 | * RSC_RTT_MAIN_DEPTHBUFFER_ATTACHABLE: |
---|
| 67 | When RSC_RTT_SEPARATE_DEPTHBUFFER is set, some APIs (ie. OpenGL w/ FBO) don't allow using |
---|
| 68 | the main depth buffer for offscreen RTTs. When this flag is set, the depth buffer can be |
---|
| 69 | shared between the main window and an RTT. |
---|
| 70 | * RSC_RTT_DEPTHBUFFER_RESOLUTION_LESSEQUAL: |
---|
| 71 | When this flag isn't set, the depth buffer can only be shared across RTTs who have the EXACT |
---|
| 72 | same resolution. When it's set, it can be shared with RTTs as long as they have a |
---|
| 73 | resolution less or equal than the depth buffer's. |
---|
| 74 | |
---|
| 75 | @remarks |
---|
| 76 | Design discussion http://www.ogre3d.org/forums/viewtopic.php?f=4&t=53534&p=365582 |
---|
| 77 | @author |
---|
| 78 | Matias N. Goldberg |
---|
| 79 | @version |
---|
| 80 | 1.0 |
---|
| 81 | */ |
---|
| 82 | class _OgreExport DepthBuffer : public RenderSysAlloc |
---|
| 83 | { |
---|
| 84 | public: |
---|
| 85 | enum PoolId |
---|
| 86 | { |
---|
| 87 | POOL_NO_DEPTH = 0, |
---|
| 88 | POOL_MANUAL_USAGE = 0, |
---|
| 89 | POOL_DEFAULT = 1 |
---|
| 90 | }; |
---|
| 91 | |
---|
| 92 | DepthBuffer( uint16 poolId, uint16 bitDepth, uint32 width, uint32 height, |
---|
| 93 | uint32 fsaa, const String &fsaaHint, bool manual ); |
---|
| 94 | virtual ~DepthBuffer(); |
---|
| 95 | |
---|
| 96 | /** Sets the pool id in which this DepthBuffer lives. |
---|
| 97 | Note this will detach any render target from this depth buffer */ |
---|
| 98 | void _setPoolId( uint16 poolId ); |
---|
| 99 | |
---|
| 100 | /// Gets the pool id in which this DepthBuffer lives |
---|
| 101 | virtual uint16 getPoolId() const; |
---|
| 102 | virtual uint16 getBitDepth() const; |
---|
| 103 | virtual uint32 getWidth() const; |
---|
| 104 | virtual uint32 getHeight() const; |
---|
| 105 | virtual uint32 getFsaa() const; |
---|
| 106 | virtual const String& getFsaaHint() const; |
---|
| 107 | |
---|
| 108 | /** Manual DepthBuffers are cleared in RenderSystem's destructor. Non-manual ones are released |
---|
| 109 | with it's render target (aka, a backbuffer or similar) */ |
---|
| 110 | bool isManual() const; |
---|
| 111 | |
---|
| 112 | /** Returns whether the specified RenderTarget is compatible with this DepthBuffer |
---|
| 113 | That is, this DepthBuffer can be attached to that RenderTarget |
---|
| 114 | @remarks |
---|
| 115 | Most APIs impose the following restrictions: |
---|
| 116 | Width & height must be equal or higher than the render target's |
---|
| 117 | They must be of the same bit depth. |
---|
| 118 | They need to have the same FSAA setting |
---|
| 119 | @param renderTarget The render target to test against |
---|
| 120 | */ |
---|
| 121 | virtual bool isCompatible( RenderTarget *renderTarget ) const; |
---|
| 122 | |
---|
| 123 | /** Called when a RenderTarget is attaches this DepthBuffer |
---|
| 124 | @remarks |
---|
| 125 | This function doesn't actually attach. It merely informs the DepthBuffer |
---|
| 126 | which RenderTarget did attach. The real attachment happens in |
---|
| 127 | RenderTarget::attachDepthBuffer() |
---|
| 128 | @param renderTarget The RenderTarget that has just been attached |
---|
| 129 | */ |
---|
| 130 | virtual void _notifyRenderTargetAttached( RenderTarget *renderTarget ); |
---|
| 131 | |
---|
| 132 | /** Called when a RenderTarget is detaches from this DepthBuffer |
---|
| 133 | @remarks |
---|
| 134 | Same as DepthBuffer::_notifyRenderTargetAttached() |
---|
| 135 | @param renderTarget The RenderTarget that has just been detached |
---|
| 136 | */ |
---|
| 137 | virtual void _notifyRenderTargetDetached( RenderTarget *renderTarget ); |
---|
| 138 | |
---|
| 139 | protected: |
---|
| 140 | typedef set<RenderTarget*>::type RenderTargetSet; |
---|
| 141 | |
---|
| 142 | uint16 mPoolId; |
---|
| 143 | uint16 mBitDepth; |
---|
| 144 | uint32 mWidth; |
---|
| 145 | uint32 mHeight; |
---|
| 146 | uint32 mFsaa; |
---|
| 147 | String mFsaaHint; |
---|
| 148 | |
---|
| 149 | bool mManual; //We don't Release manual surfaces on destruction |
---|
| 150 | RenderTargetSet mAttachedRenderTargets; |
---|
| 151 | |
---|
| 152 | void detachFromAllRenderTargets(); |
---|
| 153 | }; |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | #include "OgreHeaderSuffix.h" |
---|
| 157 | |
---|
| 158 | #endif |
---|