/src/ogre/OgreMain/src/OgreDepthBuffer.cpp
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 | | #include "OgreStableHeaders.h" |
29 | | |
30 | | namespace Ogre |
31 | | { |
32 | | DepthBuffer::DepthBuffer( uint16 poolId, uint32 width, uint32 height, |
33 | | uint32 fsaa, bool manual ) : |
34 | 0 | mPoolId(poolId), |
35 | 0 | mWidth(width), |
36 | 0 | mHeight(height), |
37 | 0 | mFsaa(fsaa), |
38 | 0 | mManual(manual) |
39 | 0 | { |
40 | 0 | } |
41 | | |
42 | | DepthBuffer::~DepthBuffer() |
43 | 0 | { |
44 | 0 | detachFromAllRenderTargets(); |
45 | 0 | } |
46 | | |
47 | | void DepthBuffer::_setPoolId( uint16 poolId ) |
48 | 0 | { |
49 | | //Change the pool Id |
50 | 0 | mPoolId = poolId; |
51 | | |
52 | | //Render Targets were attached to us, but they have a different pool Id, |
53 | | //so detach ourselves from them |
54 | 0 | detachFromAllRenderTargets(); |
55 | 0 | } |
56 | | //----------------------------------------------------------------------- |
57 | | uint16 DepthBuffer::getPoolId() const |
58 | 0 | { |
59 | 0 | return mPoolId; |
60 | 0 | } |
61 | | //----------------------------------------------------------------------- |
62 | | uint32 DepthBuffer::getWidth() const |
63 | 0 | { |
64 | 0 | return mWidth; |
65 | 0 | } |
66 | | //---------------------------------------------------------------------- |
67 | | uint32 DepthBuffer::getHeight() const |
68 | 0 | { |
69 | 0 | return mHeight; |
70 | 0 | } |
71 | | //----------------------------------------------------------------------- |
72 | | bool DepthBuffer::isManual() const |
73 | 0 | { |
74 | 0 | return mManual; |
75 | 0 | } |
76 | | //----------------------------------------------------------------------- |
77 | | bool DepthBuffer::isCompatible( RenderTarget *renderTarget ) const |
78 | 0 | { |
79 | 0 | if( this->getWidth() >= renderTarget->getWidth() && |
80 | 0 | this->getHeight() >= renderTarget->getHeight() && |
81 | 0 | this->getFSAA() == renderTarget->getFSAA() ) |
82 | 0 | { |
83 | 0 | return true; |
84 | 0 | } |
85 | | |
86 | 0 | return false; |
87 | 0 | } |
88 | | //----------------------------------------------------------------------- |
89 | | void DepthBuffer::_notifyRenderTargetAttached( RenderTarget *renderTarget ) |
90 | 0 | { |
91 | 0 | assert( mAttachedRenderTargets.find( renderTarget ) == mAttachedRenderTargets.end() ); |
92 | |
|
93 | 0 | mAttachedRenderTargets.insert( renderTarget ); |
94 | 0 | } |
95 | | //----------------------------------------------------------------------- |
96 | | void DepthBuffer::_notifyRenderTargetDetached( RenderTarget *renderTarget ) |
97 | 0 | { |
98 | 0 | RenderTargetSet::iterator itor = mAttachedRenderTargets.find( renderTarget ); |
99 | 0 | assert( itor != mAttachedRenderTargets.end() ); |
100 | |
|
101 | 0 | mAttachedRenderTargets.erase( itor ); |
102 | 0 | } |
103 | | //----------------------------------------------------------------------- |
104 | | void DepthBuffer::detachFromAllRenderTargets() |
105 | 0 | { |
106 | 0 | for (auto *r : mAttachedRenderTargets) |
107 | 0 | r->_detachDepthBuffer(); |
108 | |
|
109 | 0 | mAttachedRenderTargets.clear(); |
110 | 0 | } |
111 | | } |