~ogre-team/testogre/soc09-samples

« back to all changes in this revision

Viewing changes to RenderSystems/Direct3D9/src/OgreD3D9RenderSystem.cpp

  • Committer: sinbad
  • Date: 2009-09-27 16:23:50 UTC
  • Revision ID: svn-v4:8631bf8a-c64b-0410-883c-f3eb003322f7:branches/soc09-samples:9126
Merged trunk changes to r9109 into soc09-samples so that we can perform platform tests & refine
Once again a staged commit because of crappy server performance

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
(Object-oriented Graphics Rendering Engine)
5
5
For the latest info, see http://www.ogre3d.org
6
6
 
7
 
Copyright (c) 2000-2006 Torus Knot Software Ltd
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
 
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
 
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.
27
26
-----------------------------------------------------------------------------
28
27
*/
29
28
#include "OgreD3D9RenderSystem.h"
695
694
                D3D9RenderWindow* renderWindow = new D3D9RenderWindow(mhInstance);
696
695
                
697
696
                renderWindow->create(name, width, height, fullScreen, miscParams);
 
697
 
 
698
                mResourceManager->lockDeviceAccess();
 
699
 
698
700
                mDeviceManager->linkRenderWindow(renderWindow);
 
701
 
 
702
                mResourceManager->unlockDeviceAccess();
699
703
        
700
704
                mRenderWindows.push_back(renderWindow);         
701
705
                
779
783
                        IDirect3DDevice9* d3d9Device = device->getD3D9Device();
780
784
 
781
785
                        IDirect3DSurface9* pSurf;
782
 
                        D3DSURFACE_DESC surfDesc;
 
786
                        
783
787
 
784
788
                        // Check for hardware stencil support
785
789
                        d3d9Device->GetDepthStencilSurface(&pSurf);
786
 
                        pSurf->GetDesc(&surfDesc);
787
 
                        pSurf->Release();
788
 
 
789
 
                        if (surfDesc.Format != D3DFMT_D24S8 && surfDesc.Format != D3DFMT_D24X8)                 
790
 
                                rsc->unsetCapability(RSC_HWSTENCIL);                                                                                            
791
 
 
 
790
 
 
791
                        if (pSurf != NULL)
 
792
                        {
 
793
                                D3DSURFACE_DESC surfDesc;
 
794
 
 
795
                                pSurf->GetDesc(&surfDesc);
 
796
                                pSurf->Release();
 
797
 
 
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);    
 
803
                        }                                                                                                                                       
792
804
 
793
805
                        // Check for hardware occlusion support
794
806
                        HRESULT hr = d3d9Device->CreateQuery(D3DQUERYTYPE_OCCLUSION,  NULL);
937
949
                case 0x102B:
938
950
                        rsc->setVendor(GPU_MATROX);
939
951
                        break;
 
952
                case 0x1039:
 
953
                        rsc->setVendor(GPU_SIS);
 
954
                        break;
940
955
                default:
941
956
                        rsc->setVendor(GPU_UNKNOWN);
942
957
                        break;
1357
1372
 
1358
1373
                        HRESULT hr = mpD3D->CheckDeviceFormat(
1359
1374
                                currDevice->getAdapterNumber(),
1360
 
                                D3DDEVTYPE_HAL,
 
1375
                                currDevice->getDeviceType(),
1361
1376
                                srfDesc.Format,
1362
1377
                                d3dusage,
1363
1378
                                rtype,
1404
1419
        //---------------------------------------------------------------------
1405
1420
        String D3D9RenderSystem::getErrorDescription( long errorNumber ) const
1406
1421
        {
1407
 
                const String errMsg = DXGetErrorDescription9( errorNumber );
 
1422
                const String errMsg = DXGetErrorDescription( errorNumber );
1408
1423
                return errMsg;
1409
1424
        }
1410
1425
        //---------------------------------------------------------------------
2686
2701
 
2687
2702
                HRESULT hr;
2688
2703
 
 
2704
 
 
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())
 
2709
                {
 
2710
                        D3D9RenderWindow *window = static_cast<D3D9RenderWindow*>(target);
 
2711
                        mDeviceManager->setActiveRenderTargetDevice(window->getDevice());
 
2712
                }
 
2713
 
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))
2714
2739
                        {
2715
 
                                String msg = DXGetErrorDescription9(hr);
 
2740
                                String msg = DXGetErrorDescription(hr);
2716
2741
                                OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Failed to setRenderTarget : " + msg, "D3D9RenderSystem::_setViewport" );
2717
2742
                        }
2718
2743
                }
2719
2744
                hr = getActiveD3D9Device()->SetDepthStencilSurface(pDepth);
2720
2745
                if (FAILED(hr))
2721
2746
                {
2722
 
                        String msg = DXGetErrorDescription9(hr);
 
2747
                        String msg = DXGetErrorDescription(hr);
2723
2748
                        OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Failed to setDepthStencil : " + msg, "D3D9RenderSystem::_setViewport" );
2724
2749
                }
2725
2750
        }
2775
2800
 
2776
2801
                if( FAILED( hr = getActiveD3D9Device()->BeginScene() ) )
2777
2802
                {
2778
 
                        String msg = DXGetErrorDescription9(hr);
 
2803
                        String msg = DXGetErrorDescription(hr);
2779
2804
                        OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Error beginning frame :" + msg, "D3D9RenderSystem::_beginFrame" );
2780
2805
                }
2781
2806
 
2782
2807
                mLastVertexSourceCount = 0;
 
2808
 
 
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();
2783
2814
        }
2784
2815
        //---------------------------------------------------------------------
2785
2816
        void D3D9RenderSystem::_endFrame()
2973
3004
 
2974
3005
                if( FAILED( hr ) )
2975
3006
                {
2976
 
                        String msg = DXGetErrorDescription9(hr);
 
3007
                        String msg = DXGetErrorDescription(hr);
2977
3008
                        OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Failed to DrawPrimitive : " + msg, "D3D9RenderSystem::_render" );
2978
3009
                }
2979
3010
 
3063
3094
                }
3064
3095
 
3065
3096
                HRESULT hr;
3066
 
                const GpuLogicalBufferStruct* floatLogical = params->getFloatLogicalBufferStruct();
3067
 
                const GpuLogicalBufferStruct* intLogical = params->getIntLogicalBufferStruct();
 
3097
                GpuLogicalBufferStructPtr floatLogical = params->getFloatLogicalBufferStruct();
 
3098
                GpuLogicalBufferStructPtr intLogical = params->getIntLogicalBufferStruct();
3068
3099
 
3069
3100
                switch(gptype)
3070
3101
                {
3333
3364
                        depth, 
3334
3365
                        stencil ) ) )
3335
3366
                {
3336
 
                        String msg = DXGetErrorDescription9(hr);
 
3367
                        String msg = DXGetErrorDescription(hr);
3337
3368
                        OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Error clearing frame buffer : " 
3338
3369
                                + msg, "D3D9RenderSystem::clearFrameBuffer" );
3339
3370
                }
3520
3551
        IDirect3DDevice9* D3D9RenderSystem::getResourceCreationDevice(UINT index)
3521
3552
        {
3522
3553
                D3D9ResourceCreationPolicy creationPolicy = msD3D9RenderSystem->mResourceManager->getCreationPolicy();
 
3554
                IDirect3DDevice9* d3d9Device = NULL;
3523
3555
 
3524
3556
                if (creationPolicy == RCP_CREATE_ON_ACTIVE_DEVICE)
3525
3557
                {
3526
 
                        return msD3D9RenderSystem->getActiveD3D9Device();
 
3558
                        d3d9Device = msD3D9RenderSystem->getActiveD3D9Device();
3527
3559
                }
3528
3560
                else if (creationPolicy == RCP_CREATE_ON_ALL_DEVICES) 
3529
3561
                {
3530
 
                        return msD3D9RenderSystem->mDeviceManager->getDevice(index)->getD3D9Device();
3531
 
                }
3532
 
 
3533
 
                OGRE_EXCEPT( Exception::ERR_INVALIDPARAMS, 
3534
 
                        "Invalid resource creation policy !!!", 
3535
 
                        "D3D9RenderSystem::getResourceCreationDevice" );
3536
 
 
3537
 
                return NULL;
 
3562
                        d3d9Device = msD3D9RenderSystem->mDeviceManager->getDevice(index)->getD3D9Device();
 
3563
                }
 
3564
                else
 
3565
                {
 
3566
                        OGRE_EXCEPT( Exception::ERR_INVALIDPARAMS, 
 
3567
                                "Invalid resource creation policy !!!", 
 
3568
                                "D3D9RenderSystem::getResourceCreationDevice" );
 
3569
                }
 
3570
 
 
3571
                return d3d9Device;
3538
3572
        }
3539
3573
 
3540
3574
        //---------------------------------------------------------------------
3591
3625
                                // Verify that the depth format exists
3592
3626
                                if (mpD3D->CheckDeviceFormat(
3593
3627
                                        activeDevice->getAdapterNumber(),
3594
 
                                        D3DDEVTYPE_HAL,
 
3628
                                        activeDevice->getDeviceType(),
3595
3629
                                        srfDesc.Format,
3596
3630
                                        D3DUSAGE_DEPTHSTENCIL,
3597
3631
                                        D3DRTYPE_SURFACE,
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(), 
 
3640
                                        srfDesc.Format,
3606
3641
                                        fmt, ddDepthStencilFormats[x]) == D3D_OK)
3607
3642
                                {
3608
3643
                                        dsfmt = ddDepthStencilFormats[x];
3659
3694
                                NULL);
3660
3695
                        if(FAILED(hr))
3661
3696
                        {
3662
 
                                String msg = DXGetErrorDescription9(hr);
 
3697
                                String msg = DXGetErrorDescription(hr);
3663
3698
                                OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Error CreateDepthStencilSurface : " + msg, "D3D9RenderSystem::_getDepthStencilFor" );
3664
3699
                        }
3665
3700
                        /// And cache it
3766
3801
 
3767
3802
                std::stringstream ss;
3768
3803
 
 
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());
 
3807
 
 
3808
                LogManager::getSingleton().logMessage("!!! Direct3D Device successfully restored.");
 
3809
 
3769
3810
                ss << "D3D9 device: 0x[" << device->getD3D9Device() << "] was reset";
3770
3811
                LogManager::getSingleton().logMessage(ss.str());
3771
3812