[692] | 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-2005 The OGRE Team
|
---|
| 8 | Also see acknowledgements in Readme.html
|
---|
| 9 |
|
---|
| 10 | This program is free software; you can redistribute it and/or modify it under
|
---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
| 13 | version.
|
---|
| 14 |
|
---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
| 18 |
|
---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
| 22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
| 23 | -----------------------------------------------------------------------------
|
---|
| 24 | */
|
---|
| 25 | #include "OgreD3D9MultiRenderTarget.h"
|
---|
| 26 | #include "OgreD3D9HardwarePixelBuffer.h"
|
---|
| 27 | #include "OgreException.h"
|
---|
| 28 | #include "OgreLogManager.h"
|
---|
| 29 | #include "OgreStringConverter.h"
|
---|
| 30 | #include "OgreBitwise.h"
|
---|
| 31 |
|
---|
| 32 | namespace Ogre
|
---|
| 33 | {
|
---|
| 34 | D3D9MultiRenderTarget::D3D9MultiRenderTarget(const String &name):
|
---|
| 35 | MultiRenderTarget(name)
|
---|
| 36 | {
|
---|
| 37 | /// Clear targets
|
---|
| 38 | for(size_t x=0; x<OGRE_MAX_MULTIPLE_RENDER_TARGETS; ++x)
|
---|
| 39 | {
|
---|
| 40 | targets[x] = 0;
|
---|
| 41 | }
|
---|
| 42 | }
|
---|
| 43 | D3D9MultiRenderTarget::~D3D9MultiRenderTarget()
|
---|
| 44 | {
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | void D3D9MultiRenderTarget::bindSurface(size_t attachment, RenderTexture *target)
|
---|
| 48 | {
|
---|
| 49 | assert(attachment<OGRE_MAX_MULTIPLE_RENDER_TARGETS);
|
---|
| 50 | /// Get buffer and surface to bind to
|
---|
| 51 | D3D9HardwarePixelBuffer *buffer = 0;
|
---|
| 52 | target->getCustomAttribute("BUFFER", &buffer);
|
---|
| 53 | assert(buffer);
|
---|
| 54 |
|
---|
| 55 | /// Find first non-null target
|
---|
| 56 | int y;
|
---|
| 57 | for(y=0; y<OGRE_MAX_MULTIPLE_RENDER_TARGETS && !targets[y]; ++y) ;
|
---|
| 58 |
|
---|
| 59 | if(y!=OGRE_MAX_MULTIPLE_RENDER_TARGETS)
|
---|
| 60 | {
|
---|
| 61 | /// If there is another target bound, compare sizes
|
---|
| 62 | if(targets[y]->getWidth() != buffer->getWidth() ||
|
---|
| 63 | targets[y]->getHeight() != buffer->getHeight() ||
|
---|
| 64 | targets[y]->getFormat() != buffer->getFormat())
|
---|
| 65 | {
|
---|
| 66 | OGRE_EXCEPT(
|
---|
| 67 | Exception::ERR_INVALIDPARAMS,
|
---|
| 68 | "MultiRenderTarget surfaces are not of same size or pixel format",
|
---|
| 69 | "D3D9MultiRenderTarget::checkAndUpdate"
|
---|
| 70 | );
|
---|
| 71 | }
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | targets[attachment] = buffer;
|
---|
| 75 | checkAndUpdate();
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | void D3D9MultiRenderTarget::unbindSurface(size_t attachment)
|
---|
| 79 | {
|
---|
| 80 | assert(attachment<OGRE_MAX_MULTIPLE_RENDER_TARGETS);
|
---|
| 81 | targets[attachment] = 0;
|
---|
| 82 | checkAndUpdate();
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | void D3D9MultiRenderTarget::getCustomAttribute(const String& name, void *pData)
|
---|
| 86 | {
|
---|
| 87 | if(name == "DDBACKBUFFER")
|
---|
| 88 | {
|
---|
| 89 | IDirect3DSurface9 ** pSurf = (IDirect3DSurface9 **)pData;
|
---|
| 90 | /// Transfer surfaces
|
---|
| 91 | for(size_t x=0; x<OGRE_MAX_MULTIPLE_RENDER_TARGETS; ++x)
|
---|
| 92 | {
|
---|
| 93 | if(targets[x])
|
---|
| 94 | pSurf[x] = targets[x]->getSurface();
|
---|
| 95 | }
|
---|
| 96 | return;
|
---|
| 97 | }
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | void D3D9MultiRenderTarget::checkAndUpdate()
|
---|
| 101 | {
|
---|
| 102 | if(targets[0])
|
---|
| 103 | {
|
---|
| 104 | mWidth = targets[0]->getWidth();
|
---|
| 105 | mHeight = targets[0]->getHeight();
|
---|
| 106 | }
|
---|
| 107 | else
|
---|
| 108 | {
|
---|
| 109 | mWidth = 0;
|
---|
| 110 | mHeight = 0;
|
---|
| 111 | }
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 |
|
---|
| 115 | }
|
---|
| 116 |
|
---|