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 
29 #include "OgreGL3PlusFBOMultiRenderTarget.h"
30 
31 namespace Ogre {
32 
GL3PlusFBOMultiRenderTarget(GL3PlusFBOManager * manager,const String & name)33 	GL3PlusFBOMultiRenderTarget::GL3PlusFBOMultiRenderTarget(GL3PlusFBOManager *manager, const String &name):
34 		MultiRenderTarget(name),
35 		fbo(manager, 0 /* TODO: multisampling on MRTs? */)
36 	{
37 	}
~GL3PlusFBOMultiRenderTarget()38 	GL3PlusFBOMultiRenderTarget::~GL3PlusFBOMultiRenderTarget()
39 	{
40 	}
41 
bindSurfaceImpl(size_t attachment,RenderTexture * target)42 	void GL3PlusFBOMultiRenderTarget::bindSurfaceImpl(size_t attachment, RenderTexture *target)
43 	{
44 		// Check if the render target is in the rendertarget->FBO map
45         GL3PlusFrameBufferObject *fbobj = 0;
46         target->getCustomAttribute(GL3PlusRenderTexture::CustomAttributeString_FBO, &fbobj);
47 		assert(fbobj);
48 		fbo.bindSurface(attachment, fbobj->getSurface(0));
49 
50 		// Set width and height
51 		mWidth = fbo.getWidth();
52 		mHeight = fbo.getHeight();
53 	}
54 
unbindSurfaceImpl(size_t attachment)55 	void GL3PlusFBOMultiRenderTarget::unbindSurfaceImpl(size_t attachment)
56 	{
57 		fbo.unbindSurface(attachment);
58 
59 		// Set width and height
60 		mWidth = fbo.getWidth();
61 		mHeight = fbo.getHeight();
62 	}
63 
getCustomAttribute(const String & name,void * pData)64 	void GL3PlusFBOMultiRenderTarget::getCustomAttribute( const String& name, void *pData )
65 	{
66 		if(name == GL3PlusRenderTexture::CustomAttributeString_FBO)
67         {
68             *static_cast<GL3PlusFrameBufferObject **>(pData) = &fbo;
69         }
70 	}
71 	//-----------------------------------------------------------------------------
attachDepthBuffer(DepthBuffer * depthBuffer)72 	bool GL3PlusFBOMultiRenderTarget::attachDepthBuffer( DepthBuffer *depthBuffer )
73 	{
74 		bool result;
75 		if( (result = MultiRenderTarget::attachDepthBuffer( depthBuffer )) )
76 			fbo.attachDepthBuffer( depthBuffer );
77 
78 		return result;
79 	}
80 	//-----------------------------------------------------------------------------
detachDepthBuffer()81 	void GL3PlusFBOMultiRenderTarget::detachDepthBuffer()
82 	{
83 		fbo.detachDepthBuffer();
84 		MultiRenderTarget::detachDepthBuffer();
85 	}
86 	//-----------------------------------------------------------------------------
_detachDepthBuffer()87 	void GL3PlusFBOMultiRenderTarget::_detachDepthBuffer()
88 	{
89 		fbo.detachDepthBuffer();
90 		MultiRenderTarget::_detachDepthBuffer();
91 	}
92 }
93