OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreD3D9Device.h
Go to the documentation of this file.
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-2014 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.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef __D3D9Device_H__
29 #define __D3D9Device_H__
30 
31 #include "OgreD3D9Prerequisites.h"
32 #include "OgreRenderTarget.h"
33 
34 namespace Ogre {
35 
36  class D3D9RenderWindow;
37  class D3D9DeviceManager;
38 
43  {
44 
45  // Interface.
46  public:
47  void attachRenderWindow (D3D9RenderWindow* renderWindow);
48  void detachRenderWindow (D3D9RenderWindow* renderWindow);
49 
50  bool acquire ();
51 
52  void release ();
53  void destroy ();
54 
55  bool isDeviceLost ();
56  IDirect3DDevice9* getD3D9Device ();
57 
58  UINT getAdapterNumber () const;
59  D3DDEVTYPE getDeviceType () const;
60  bool isMultihead () const;
61  bool isAutoDepthStencil () const;
62  bool isFullScreen () const;
63 
64  const D3DCAPS9& getD3D9DeviceCaps () const;
65  D3DFORMAT getBackBufferFormat () const;
66 
67  bool validate (D3D9RenderWindow* renderWindow);
68  void invalidate (D3D9RenderWindow* renderWindow);
69 
70  void present (D3D9RenderWindow* renderWindow);
71 
72  IDirect3DSurface9* getDepthBuffer (D3D9RenderWindow* renderWindow);
73  IDirect3DSurface9* getBackBuffer (D3D9RenderWindow* renderWindow);
74 
75  uint getRenderWindowCount () const;
76  D3D9RenderWindow* getRenderWindow (uint index);
77  uint getLastPresentFrame () const { return mLastPresentFrame; }
78 
79  void setAdapterOrdinalIndex (D3D9RenderWindow* renderWindow, uint adapterOrdinalInGroupIndex);
80  void copyContentsToMemory(D3D9RenderWindow* window, const PixelBox &dst, RenderTarget::FrameBuffer buffer);
81  void clearDeviceStreams ();
82  int getVBlankMissCount (D3D9RenderWindow* renderWindow);
83 
84  public:
85  D3D9Device (D3D9DeviceManager* deviceManager,
86  UINT adapterNumber,
87  HMONITOR hMonitor,
88  D3DDEVTYPE devType,
89  DWORD behaviorFlags);
90  ~D3D9Device ();
91 
92  protected:
93  D3D9DeviceManager* mDeviceManager; // The manager of this device instance.
94  IDirect3DDevice9* mDevice; // Will hold the device interface.
95  UINT mAdapterNumber; // The adapter that this device belongs to.
96  HMONITOR mMonitor; // The monitor that this device belongs to.
97  D3DDEVTYPE mDeviceType; // Device type.
98  static HWND msSharedFocusWindow; // The shared focus window in case of multiple full screen render windows.
99  HWND mFocusWindow; // The focus window this device attached to.
100  DWORD mBehaviorFlags; // The behavior of this device.
101  D3DPRESENT_PARAMETERS* mPresentationParams; // Presentation parameters which the device was created with. May be
102  // an array of presentation parameters in case of multi-head device.
103  UINT mPresentationParamsCount; // Number of presentation parameters elements.
104  D3DCAPS9 mD3D9DeviceCaps; // Device caps.
105  bool mD3D9DeviceCapsValid; // True if device caps initialized.
106  D3DDEVICE_CREATION_PARAMETERS mCreationParams; // Creation parameters.
107  uint mLastPresentFrame; // Last frame that this device present method called.
108  bool mDeviceLost; // True if device entered lost state.
109  D3DPRESENTSTATS mPreviousPresentStats; // We save the previous present stats - so we can detect a "vblank miss"
110  bool mPreviousPresentStatsIsValid; // Does mLastPresentStats data is valid (it isn't if when you start or resize the window)
111  uint mVBlankMissCount; // Number of times we missed the v sync blank
112 
114  {
115  IDirect3DSwapChain9* swapChain; // Swap chain interface.
116  IDirect3DSwapChain9Ex * swapChain9Ex; // The 9Ex version of the chain is needed for the v synk blank stats
117  uint adapterOrdinalInGroupIndex; // Relative index of the render window in the group.
118  uint presentParametersIndex; // Index of present parameter in the shared array of the device.
119  IDirect3DSurface9* backBuffer; // The back buffer of the render window.
120  IDirect3DSurface9* depthBuffer; // The depth buffer of the render window.
121  D3DPRESENT_PARAMETERS presentParameters; // Present parameters of the render window.
122  bool acquired; // True if resources acquired.
123  };
125  typedef RenderWindowToResourcesMap::iterator RenderWindowToResourcesIterator;
126 
127  RenderWindowToResourcesMap mMapRenderWindowToResources; // Map between render window to resources.
128 
129 
130  protected:
131  RenderWindowToResourcesIterator getRenderWindowIterator (D3D9RenderWindow* renderWindow);
132 
133  bool acquire (D3D9RenderWindow* renderWindow);
134  bool reset ();
135  void updatePresentationParameters ();
136  void updateRenderWindowsIndices ();
137 
138  void createD3D9Device ();
139  void releaseD3D9Device ();
140  void releaseRenderWindowResources (RenderWindowResources* renderWindowResources);
141  void acquireRenderWindowResources (RenderWindowToResourcesIterator it);
142  void setupDeviceStates ();
143  void notifyDeviceLost ();
144 
145  void validateFocusWindow ();
146  void validateBackBufferSize (D3D9RenderWindow* renderWindow);
147  bool validateDisplayMonitor (D3D9RenderWindow* renderWindow);
148  bool validateDeviceState (D3D9RenderWindow* renderWindow);
149  bool isSwapChainWindow (D3D9RenderWindow* renderWindow);
150  D3D9RenderWindow* getPrimaryWindow ();
151  void setSharedWindowHandle (HWND hSharedHWND);
152 
153  private:
154  friend class D3D9DeviceManager;
155  friend class D3D9RenderSystem;
156  };
157 }
158 #endif
static HWND msSharedFocusWindow
IDirect3DDevice9 * mDevice
D3DPRESENTSTATS mPreviousPresentStats
Device manager interface.
D3D9DeviceManager * mDeviceManager
bool mPreviousPresentStatsIsValid
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
#define _OgreD3D9Export
map< D3D9RenderWindow *, RenderWindowResources * >::type RenderWindowToResourcesMap
RenderWindowToResourcesMap::iterator RenderWindowToResourcesIterator
D3DDEVICE_CREATION_PARAMETERS mCreationParams
Implementation of DirectX9 as a rendering system.
High level interface of Direct3D9 Device.
uint getLastPresentFrame() const
D3DDEVTYPE mDeviceType
D3DCAPS9 mD3D9DeviceCaps
RenderWindowToResourcesMap mMapRenderWindowToResources
D3DPRESENT_PARAMETERS * mPresentationParams
unsigned int uint