OGRE  1.9
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 
83  public:
84  D3D9Device (D3D9DeviceManager* deviceManager,
85  UINT adapterNumber,
86  HMONITOR hMonitor,
87  D3DDEVTYPE devType,
88  DWORD behaviorFlags);
89  ~D3D9Device ();
90 
91  protected:
92  D3D9DeviceManager* mDeviceManager; // The manager of this device instance.
93  IDirect3DDevice9* mDevice; // Will hold the device interface.
94  UINT mAdapterNumber; // The adapter that this device belongs to.
95  HMONITOR mMonitor; // The monitor that this device belongs to.
96  D3DDEVTYPE mDeviceType; // Device type.
97  static HWND msSharedFocusWindow; // The shared focus window in case of multiple full screen render windows.
98  HWND mFocusWindow; // The focus window this device attached to.
99  DWORD mBehaviorFlags; // The behavior of this device.
100  D3DPRESENT_PARAMETERS* mPresentationParams; // Presentation parameters which the device was created with. May be
101  // an array of presentation parameters in case of multi-head device.
102  UINT mPresentationParamsCount; // Number of presentation parameters elements.
103  D3DCAPS9 mD3D9DeviceCaps; // Device caps.
104  bool mD3D9DeviceCapsValid; // True if device caps initialized.
105  D3DDEVICE_CREATION_PARAMETERS mCreationParams; // Creation parameters.
106  uint mLastPresentFrame; // Last frame that this device present method called.
107  bool mDeviceLost; // True if device entered lost state.
108 
110  {
111  IDirect3DSwapChain9* swapChain; // Swap chain interface.
112  uint adapterOrdinalInGroupIndex; // Relative index of the render window in the group.
113  uint presentParametersIndex; // Index of present parameter in the shared array of the device.
114  IDirect3DSurface9* backBuffer; // The back buffer of the render window.
115  IDirect3DSurface9* depthBuffer; // The depth buffer of the render window.
116  D3DPRESENT_PARAMETERS presentParameters; // Present parameters of the render window.
117  bool acquired; // True if resources acquired.
118  };
120  typedef RenderWindowToResourcesMap::iterator RenderWindowToResourcesIterator;
121 
122  RenderWindowToResourcesMap mMapRenderWindowToResources; // Map between render window to resources.
123 
124 
125  protected:
126  RenderWindowToResourcesIterator getRenderWindowIterator (D3D9RenderWindow* renderWindow);
127 
128  bool acquire (D3D9RenderWindow* renderWindow);
129  bool reset ();
130  void updatePresentationParameters ();
131  void updateRenderWindowsIndices ();
132 
133  void createD3D9Device ();
134  void releaseD3D9Device ();
135  void releaseRenderWindowResources (RenderWindowResources* renderWindowResources);
136  void acquireRenderWindowResources (RenderWindowToResourcesIterator it);
137  void setupDeviceStates ();
138  void notifyDeviceLost ();
139 
140  void validateFocusWindow ();
141  void validateBackBufferSize (D3D9RenderWindow* renderWindow);
142  bool validateDisplayMonitor (D3D9RenderWindow* renderWindow);
143  bool validateDeviceState (D3D9RenderWindow* renderWindow);
144  bool isSwapChainWindow (D3D9RenderWindow* renderWindow);
145  D3D9RenderWindow* getPrimaryWindow ();
146  void setSharedWindowHandle (HWND hSharedHWND);
147 
148  private:
149  friend class D3D9DeviceManager;
150  friend class D3D9RenderSystem;
151  };
152 }
153 #endif
static HWND msSharedFocusWindow
IDirect3DDevice9 * mDevice
Device manager interface.
D3D9DeviceManager * mDeviceManager
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
A primitive describing a volume (3D), image (2D) or line (1D) of pixels in memory.
D3DPRESENT_PARAMETERS * mPresentationParams
unsigned int uint