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 #include "OgreStableHeaders.h" 29 #include "OgreDepthBuffer.h" 30 #include "OgreRenderTarget.h" 31 32 namespace Ogre 33 { DepthBuffer(uint16 poolId,uint16 bitDepth,uint32 width,uint32 height,uint32 fsaa,const String & fsaaHint,bool manual)34 DepthBuffer::DepthBuffer( uint16 poolId, uint16 bitDepth, uint32 width, uint32 height, 35 uint32 fsaa, const String &fsaaHint, bool manual ) : 36 mPoolId(poolId), 37 mBitDepth(bitDepth), 38 mWidth(width), 39 mHeight(height), 40 mFsaa(fsaa), 41 mFsaaHint(fsaaHint), 42 mManual(manual) 43 { 44 } 45 ~DepthBuffer()46 DepthBuffer::~DepthBuffer() 47 { 48 detachFromAllRenderTargets(); 49 } 50 _setPoolId(uint16 poolId)51 void DepthBuffer::_setPoolId( uint16 poolId ) 52 { 53 //Change the pool Id 54 mPoolId = poolId; 55 56 //Render Targets were attached to us, but they have a different pool Id, 57 //so detach ourselves from them 58 detachFromAllRenderTargets(); 59 } 60 //----------------------------------------------------------------------- getPoolId() const61 uint16 DepthBuffer::getPoolId() const 62 { 63 return mPoolId; 64 } 65 //----------------------------------------------------------------------- getBitDepth() const66 uint16 DepthBuffer::getBitDepth() const 67 { 68 return mBitDepth; 69 } 70 //----------------------------------------------------------------------- getWidth() const71 uint32 DepthBuffer::getWidth() const 72 { 73 return mWidth; 74 } 75 //---------------------------------------------------------------------- getHeight() const76 uint32 DepthBuffer::getHeight() const 77 { 78 return mHeight; 79 } 80 //----------------------------------------------------------------------- getFsaa() const81 uint32 DepthBuffer::getFsaa() const 82 { 83 return mFsaa; 84 } 85 //----------------------------------------------------------------------- getFsaaHint() const86 const String& DepthBuffer::getFsaaHint() const 87 { 88 return mFsaaHint; 89 } 90 //----------------------------------------------------------------------- isManual() const91 bool DepthBuffer::isManual() const 92 { 93 return mManual; 94 } 95 //----------------------------------------------------------------------- isCompatible(RenderTarget * renderTarget) const96 bool DepthBuffer::isCompatible( RenderTarget *renderTarget ) const 97 { 98 if( this->getWidth() >= renderTarget->getWidth() && 99 this->getHeight() >= renderTarget->getHeight() && 100 this->getFsaa() == renderTarget->getFSAA() ) 101 { 102 return true; 103 } 104 105 return false; 106 } 107 //----------------------------------------------------------------------- _notifyRenderTargetAttached(RenderTarget * renderTarget)108 void DepthBuffer::_notifyRenderTargetAttached( RenderTarget *renderTarget ) 109 { 110 assert( mAttachedRenderTargets.find( renderTarget ) == mAttachedRenderTargets.end() ); 111 112 mAttachedRenderTargets.insert( renderTarget ); 113 } 114 //----------------------------------------------------------------------- _notifyRenderTargetDetached(RenderTarget * renderTarget)115 void DepthBuffer::_notifyRenderTargetDetached( RenderTarget *renderTarget ) 116 { 117 RenderTargetSet::iterator itor = mAttachedRenderTargets.find( renderTarget ); 118 assert( itor != mAttachedRenderTargets.end() ); 119 120 mAttachedRenderTargets.erase( itor ); 121 } 122 //----------------------------------------------------------------------- detachFromAllRenderTargets()123 void DepthBuffer::detachFromAllRenderTargets() 124 { 125 RenderTargetSet::const_iterator itor = mAttachedRenderTargets.begin(); 126 RenderTargetSet::const_iterator end = mAttachedRenderTargets.end(); 127 while( itor != end ) 128 { 129 //If we call, detachDepthBuffer, we'll invalidate the iterators 130 (*itor)->_detachDepthBuffer(); 131 ++itor; 132 } 133 134 mAttachedRenderTargets.clear(); 135 } 136 } 137