OgreD3D9Device.h
Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004 (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright (c) 2000-2012 Torus Knot Software Ltd
    00008
    00009 Permission is hereby granted, free of charge, to any person obtaining a copy
    00010 of this software and associated documentation files (the "Software"), to deal
    00011 in the Software without restriction, including without limitation the rights
    00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00013 copies of the Software, and to permit persons to whom the Software is
    00014 furnished to do so, subject to the following conditions:
    00015
    00016 The above copyright notice and this permission notice shall be included in
    00017 all copies or substantial portions of the Software.
    00018
    00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    00025 THE SOFTWARE.
    00026 -----------------------------------------------------------------------------
    00027 */
    00028 #ifndef __D3D9Device_H__
    00029 #define __D3D9Device_H__
    00030
    00031 #include "OgreD3D9Prerequisites.h"
    00032 #include "OgreRenderTarget.h"
    00033
    00034 namespace Ogre {
    00035
    00036     class D3D9RenderWindow;
    00037     class D3D9DeviceManager;
    00038
    00042     class _OgreD3D9Export D3D9Device : public ResourceAlloc
    00043     {
    00044
    00045     // Interface.
    00046     public:
    00047         void                    attachRenderWindow      (D3D9RenderWindow* renderWindow);
    00048         void                    detachRenderWindow      (D3D9RenderWindow* renderWindow);
    00049
    00050         bool                    acquire                 ();
    00051
    00052         void                    release                 ();
    00053         void                    destroy                 ();
    00054
    00055         bool                    isDeviceLost            ();
    00056         IDirect3DDevice9*       getD3D9Device           ();
    00057
    00058         UINT                    getAdapterNumber        () const;
    00059         D3DDEVTYPE              getDeviceType           () const;
    00060         bool                    isMultihead             () const;
    00061         bool                    isAutoDepthStencil      () const;
    00062         bool                    isFullScreen            () const;
    00063
    00064         const D3DCAPS9&         getD3D9DeviceCaps       () const;
    00065         D3DFORMAT               getBackBufferFormat     () const;
    00066
    00067         bool                    validate                (D3D9RenderWindow* renderWindow);
    00068         void                    invalidate              (D3D9RenderWindow* renderWindow);
    00069
    00070         void                    present                 (D3D9RenderWindow* renderWindow);
    00071
    00072         IDirect3DSurface9*      getDepthBuffer          (D3D9RenderWindow* renderWindow);
    00073         IDirect3DSurface9*      getBackBuffer           (D3D9RenderWindow* renderWindow);
    00074
    00075         uint                    getRenderWindowCount    () const;
    00076         D3D9RenderWindow*       getRenderWindow         (uint index);
    00077         uint                    getLastPresentFrame     () const { return mLastPresentFrame; }
    00078
    00079         void                    setAdapterOrdinalIndex  (D3D9RenderWindow* renderWindow, uint adapterOrdinalInGroupIndex);
    00080         void                    copyContentsToMemory(D3D9RenderWindow* window, const PixelBox &dst, RenderTarget::FrameBuffer buffer);
    00081         void                    clearDeviceStreams      ();
    00082
    00083     public:
    00084         D3D9Device  (D3D9DeviceManager* deviceManager,
    00085                      UINT adapterNumber,
    00086                      HMONITOR hMonitor,
    00087                      D3DDEVTYPE devType,
    00088                      DWORD behaviorFlags);
    00089         ~D3D9Device ();
    00090
    00091     protected:
    00092         D3D9DeviceManager*              mDeviceManager;         // The manager of this device instance.
    00093         IDirect3DDevice9*               mDevice;                    // Will hold the device interface.
    00094         UINT                            mAdapterNumber;             // The adapter that this device belongs to.
    00095         HMONITOR                        mMonitor;                   // The monitor that this device belongs to.
    00096         D3DDEVTYPE                      mDeviceType;                // Device type.
    00097         static HWND                     msSharedFocusWindow;        // The shared focus window in case of multiple full screen render windows.
    00098         HWND                            mFocusWindow;               // The focus window this device attached to.
    00099         DWORD                           mBehaviorFlags;             // The behavior of this device.
    00100         D3DPRESENT_PARAMETERS*          mPresentationParams;        // Presentation parameters which the device was created with. May be
    00101                                                                     // an array of presentation parameters in case of multi-head device.
    00102         UINT                            mPresentationParamsCount;   // Number of presentation parameters elements.
    00103         D3DCAPS9                        mD3D9DeviceCaps;            // Device caps.
    00104         bool                            mD3D9DeviceCapsValid;       // True if device caps initialized.
    00105         D3DDEVICE_CREATION_PARAMETERS   mCreationParams;            // Creation parameters.
    00106         uint                            mLastPresentFrame;          // Last frame that this device present method called.
    00107         bool                            mDeviceLost;                // True if device entered lost state.
    00108
    00109         struct RenderWindowResources
    00110         {
    00111             IDirect3DSwapChain9*    swapChain;                      // Swap chain interface.
    00112             uint                    adapterOrdinalInGroupIndex;     // Relative index of the render window in the group.
    00113             uint                    presentParametersIndex;         // Index of present parameter in the shared array of the device.
    00114             IDirect3DSurface9*      backBuffer;                     // The back buffer of the render window.
    00115             IDirect3DSurface9*      depthBuffer;                    // The depth buffer of the render window.
    00116             D3DPRESENT_PARAMETERS   presentParameters;              // Present parameters of the render window.
    00117             bool                    acquired;                       // True if resources acquired.
    00118         };
    00119         typedef map<D3D9RenderWindow*, RenderWindowResources*>::type RenderWindowToResourcesMap;
    00120         typedef RenderWindowToResourcesMap::iterator                 RenderWindowToResourcesIterator;
    00121
    00122         RenderWindowToResourcesMap mMapRenderWindowToResources;     // Map between render window to resources.
    00123
    00124
    00125     protected:
    00126         RenderWindowToResourcesIterator getRenderWindowIterator (D3D9RenderWindow* renderWindow);
    00127
    00128         bool                    acquire                         (D3D9RenderWindow* renderWindow);
    00129         bool                    reset                           ();
    00130         void                    updatePresentationParameters    ();
    00131         void                    updateRenderWindowsIndices      ();
    00132
    00133         void                    createD3D9Device                ();
    00134         void                    releaseD3D9Device               ();
    00135         void                    releaseRenderWindowResources    (RenderWindowResources* renderWindowResources);
    00136         void                    acquireRenderWindowResources    (RenderWindowToResourcesIterator it);
    00137         void                    setupDeviceStates               ();
    00138         void                    notifyDeviceLost                ();
    00139
    00140         void                    validateFocusWindow             ();
    00141         void                    validateBackBufferSize          (D3D9RenderWindow* renderWindow);
    00142         bool                    validateDisplayMonitor          (D3D9RenderWindow* renderWindow);
    00143         bool                    validateDeviceState             (D3D9RenderWindow* renderWindow);
    00144         bool                    isSwapChainWindow               (D3D9RenderWindow* renderWindow);
    00145         D3D9RenderWindow*       getPrimaryWindow                ();
    00146         void                    setSharedWindowHandle           (HWND hSharedHWND);
    00147
    00148     private:
    00149         friend class D3D9DeviceManager;
    00150         friend class D3D9RenderSystem;
    00151     };
    00152 }
    00153 #endif

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun Sep 2 2012 07:27:21