Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/RenderSystems/Direct3D9/src/OgreD3D9MultiRenderTarget.cpp @ 1

Last change on this file since 1 was 1, checked in by landauf, 17 years ago
File size: 3.9 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2006 Torus Knot Software Ltd
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23
24You may alternatively use this source under the terms of a specific version of
25the OGRE Unrestricted License provided you have obtained such a license from
26Torus Knot Software Ltd.
27-----------------------------------------------------------------------------
28*/
29#include "OgreD3D9MultiRenderTarget.h"
30#include "OgreD3D9HardwarePixelBuffer.h"
31#include "OgreException.h"
32#include "OgreLogManager.h"
33#include "OgreStringConverter.h"
34#include "OgreBitwise.h"
35#include "OgreD3D9RenderSystem.h"
36#include "OgreRoot.h"
37
38namespace Ogre
39{
40        D3D9MultiRenderTarget::D3D9MultiRenderTarget(const String &name):
41                MultiRenderTarget(name)
42        {
43                /// Clear targets
44                for(size_t x=0; x<OGRE_MAX_MULTIPLE_RENDER_TARGETS; ++x)
45                {
46                        targets[x] = 0;
47                }
48        }
49        D3D9MultiRenderTarget::~D3D9MultiRenderTarget()
50        {
51        }
52
53        void D3D9MultiRenderTarget::bindSurface(size_t attachment, RenderTexture *target)
54        {
55                assert(attachment<OGRE_MAX_MULTIPLE_RENDER_TARGETS);
56                /// Get buffer and surface to bind to
57                D3D9HardwarePixelBuffer *buffer = 0;
58                target->getCustomAttribute("BUFFER", &buffer);
59                assert(buffer);
60
61                /// Find first non-null target
62                int y;
63                for(y=0; y<OGRE_MAX_MULTIPLE_RENDER_TARGETS && !targets[y]; ++y) ;
64               
65                if(y!=OGRE_MAX_MULTIPLE_RENDER_TARGETS)
66                {
67                        /// If there is another target bound, compare sizes
68                        if(targets[y]->getWidth() != buffer->getWidth() ||
69                                targets[y]->getHeight() != buffer->getHeight() ||
70                                PixelUtil::getNumElemBits(targets[y]->getFormat()) != 
71                                        PixelUtil::getNumElemBits(buffer->getFormat()))
72                        {
73                                OGRE_EXCEPT(
74                                        Exception::ERR_INVALIDPARAMS, 
75                                        "MultiRenderTarget surfaces are not of same size or bit depth", 
76                                        "D3D9MultiRenderTarget::bindSurface"
77                                );
78                        }
79                }
80
81                targets[attachment] = buffer;
82                checkAndUpdate();
83        }
84
85        void D3D9MultiRenderTarget::unbindSurface(size_t attachment)
86        {
87                assert(attachment<OGRE_MAX_MULTIPLE_RENDER_TARGETS);
88                targets[attachment] = 0;
89                checkAndUpdate();
90        }
91
92    void D3D9MultiRenderTarget::update(void)
93    {
94        D3D9RenderSystem* rs = static_cast<D3D9RenderSystem*>(
95            Root::getSingleton().getRenderSystem());
96        if (rs->isDeviceLost())
97            return;
98
99        MultiRenderTarget::update();
100    }
101
102        void D3D9MultiRenderTarget::getCustomAttribute(const String& name, void *pData)
103    {
104                if(name == "DDBACKBUFFER")
105        {
106            IDirect3DSurface9 ** pSurf = (IDirect3DSurface9 **)pData;
107                        /// Transfer surfaces
108                        for(size_t x=0; x<OGRE_MAX_MULTIPLE_RENDER_TARGETS; ++x)
109                        {
110                                if(targets[x])
111                                        pSurf[x] = targets[x]->getSurface();
112                        }
113                        return;
114        }
115        }
116
117        void D3D9MultiRenderTarget::checkAndUpdate()
118        {
119                if(targets[0])
120                {
121                        mWidth = targets[0]->getWidth();
122                        mHeight = targets[0]->getHeight();
123                }
124                else
125                {
126                        mWidth = 0;
127                        mHeight = 0;
128                }
129        }
130
131
132}
133
Note: See TracBrowser for help on using the repository browser.