4
4
(Object-oriented Graphics Rendering Engine)
5
5
For the latest info, see http://www.ogre3d.org
7
Copyright (c) 2000-2006 Torus Knot Software Ltd
8
Also see acknowledgements in Readme.html
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
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.
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.
24
You may alternatively use this source under the terms of a specific version of
25
the OGRE Unrestricted License provided you have obtained such a license from
26
Torus Knot Software Ltd.
7
Copyright (c) 2000-2009 Torus Knot Software Ltd
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:
16
The above copyright notice and this permission notice shall be included in
17
all copies or substantial portions of the Software.
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
27
26
-----------------------------------------------------------------------------
29
28
#include "OgreD3D9RenderSystem.h"
695
694
D3D9RenderWindow* renderWindow = new D3D9RenderWindow(mhInstance);
697
696
renderWindow->create(name, width, height, fullScreen, miscParams);
698
mResourceManager->lockDeviceAccess();
698
700
mDeviceManager->linkRenderWindow(renderWindow);
702
mResourceManager->unlockDeviceAccess();
700
704
mRenderWindows.push_back(renderWindow);
779
783
IDirect3DDevice9* d3d9Device = device->getD3D9Device();
781
785
IDirect3DSurface9* pSurf;
782
D3DSURFACE_DESC surfDesc;
784
788
// Check for hardware stencil support
785
789
d3d9Device->GetDepthStencilSurface(&pSurf);
786
pSurf->GetDesc(&surfDesc);
789
if (surfDesc.Format != D3DFMT_D24S8 && surfDesc.Format != D3DFMT_D24X8)
790
rsc->unsetCapability(RSC_HWSTENCIL);
793
D3DSURFACE_DESC surfDesc;
795
pSurf->GetDesc(&surfDesc);
798
if (surfDesc.Format != D3DFMT_D15S1 &&
799
surfDesc.Format != D3DFMT_D24S8 &&
800
surfDesc.Format != D3DFMT_D24X4S4 &&
801
surfDesc.Format != D3DFMT_D24FS8)
802
rsc->unsetCapability(RSC_HWSTENCIL);
793
805
// Check for hardware occlusion support
794
806
HRESULT hr = d3d9Device->CreateQuery(D3DQUERYTYPE_OCCLUSION, NULL);
2705
// If this is called without going through RenderWindow::update, then
2706
// the device will not have been set. Calling it twice is safe, the
2707
// implementation ensures nothing happens if the same device is set twice
2708
if (std::find(mRenderWindows.begin(), mRenderWindows.end(), target) != mRenderWindows.end())
2710
D3D9RenderWindow *window = static_cast<D3D9RenderWindow*>(target);
2711
mDeviceManager->setActiveRenderTargetDevice(window->getDevice());
2689
2714
// Retrieve render surfaces (up to OGRE_MAX_MULTIPLE_RENDER_TARGETS)
2690
2715
IDirect3DSurface9* pBack[OGRE_MAX_MULTIPLE_RENDER_TARGETS];
2691
2716
memset(pBack, 0, sizeof(pBack));
2712
2737
hr = getActiveD3D9Device()->SetRenderTarget(x, pBack[x]);
2713
2738
if (FAILED(hr))
2715
String msg = DXGetErrorDescription9(hr);
2740
String msg = DXGetErrorDescription(hr);
2716
2741
OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Failed to setRenderTarget : " + msg, "D3D9RenderSystem::_setViewport" );
2719
2744
hr = getActiveD3D9Device()->SetDepthStencilSurface(pDepth);
2720
2745
if (FAILED(hr))
2722
String msg = DXGetErrorDescription9(hr);
2747
String msg = DXGetErrorDescription(hr);
2723
2748
OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Failed to setDepthStencil : " + msg, "D3D9RenderSystem::_setViewport" );
2776
2801
if( FAILED( hr = getActiveD3D9Device()->BeginScene() ) )
2778
String msg = DXGetErrorDescription9(hr);
2803
String msg = DXGetErrorDescription(hr);
2779
2804
OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Error beginning frame :" + msg, "D3D9RenderSystem::_beginFrame" );
2782
2807
mLastVertexSourceCount = 0;
2809
// Clear left overs of previous viewport.
2810
// I.E: Viewport A can use 3 different textures and light states
2811
// When trying to render viewport B these settings should be cleared, otherwise
2812
// graphical artifacts might occur.
2813
mDeviceManager->getActiveDevice()->clearDeviceStreams();
2784
2815
//---------------------------------------------------------------------
2785
2816
void D3D9RenderSystem::_endFrame()
3520
3551
IDirect3DDevice9* D3D9RenderSystem::getResourceCreationDevice(UINT index)
3522
3553
D3D9ResourceCreationPolicy creationPolicy = msD3D9RenderSystem->mResourceManager->getCreationPolicy();
3554
IDirect3DDevice9* d3d9Device = NULL;
3524
3556
if (creationPolicy == RCP_CREATE_ON_ACTIVE_DEVICE)
3526
return msD3D9RenderSystem->getActiveD3D9Device();
3558
d3d9Device = msD3D9RenderSystem->getActiveD3D9Device();
3528
3560
else if (creationPolicy == RCP_CREATE_ON_ALL_DEVICES)
3530
return msD3D9RenderSystem->mDeviceManager->getDevice(index)->getD3D9Device();
3533
OGRE_EXCEPT( Exception::ERR_INVALIDPARAMS,
3534
"Invalid resource creation policy !!!",
3535
"D3D9RenderSystem::getResourceCreationDevice" );
3562
d3d9Device = msD3D9RenderSystem->mDeviceManager->getDevice(index)->getD3D9Device();
3566
OGRE_EXCEPT( Exception::ERR_INVALIDPARAMS,
3567
"Invalid resource creation policy !!!",
3568
"D3D9RenderSystem::getResourceCreationDevice" );
3540
3574
//---------------------------------------------------------------------
3602
3636
// Verify that the depth format is compatible
3603
3637
if(mpD3D->CheckDepthStencilMatch(
3604
3638
activeDevice->getAdapterNumber(),
3605
D3DDEVTYPE_HAL, srfDesc.Format,
3639
activeDevice->getDeviceType(),
3606
3641
fmt, ddDepthStencilFormats[x]) == D3D_OK)
3608
3643
dsfmt = ddDepthStencilFormats[x];
3767
3802
std::stringstream ss;
3804
// Reset the texture stages, they will need to be rebound
3805
for (size_t i = 0; i < OGRE_MAX_TEXTURE_LAYERS; ++i)
3806
_setTexture(i, false, TexturePtr());
3808
LogManager::getSingleton().logMessage("!!! Direct3D Device successfully restored.");
3769
3810
ss << "D3D9 device: 0x[" << device->getD3D9Device() << "] was reset";
3770
3811
LogManager::getSingleton().logMessage(ss.str());