CmD3D9Device.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. Copyright (c) 2000-2011 Torus Knot Software Ltd
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. -----------------------------------------------------------------------------
  23. */
  24. #ifndef __D3D9Device_H__
  25. #define __D3D9Device_H__
  26. #include "CmD3D9Prerequisites.h"
  27. #include "CmRenderTarget.h"
  28. namespace CamelotEngine {
  29. class D3D9RenderWindow;
  30. class D3D9DeviceManager;
  31. /** High level interface of Direct3D9 Device.
  32. Provide useful methods for device handling.
  33. */
  34. class _OgreD3D9Export D3D9Device
  35. {
  36. // Interface.
  37. public:
  38. void attachRenderWindow (D3D9RenderWindow* renderWindow);
  39. void detachRenderWindow (D3D9RenderWindow* renderWindow);
  40. bool acquire ();
  41. void release ();
  42. void destroy ();
  43. bool isDeviceLost ();
  44. IDirect3DDevice9* getD3D9Device ();
  45. UINT getAdapterNumber () const;
  46. D3DDEVTYPE getDeviceType () const;
  47. bool isMultihead () const;
  48. bool isAutoDepthStencil () const;
  49. const D3DCAPS9& getD3D9DeviceCaps () const;
  50. D3DFORMAT getBackBufferFormat () const;
  51. bool validate (D3D9RenderWindow* renderWindow);
  52. void invalidate (D3D9RenderWindow* renderWindow);
  53. void present (D3D9RenderWindow* renderWindow);
  54. IDirect3DSurface9* getDepthBuffer (D3D9RenderWindow* renderWindow);
  55. IDirect3DSurface9* getBackBuffer (D3D9RenderWindow* renderWindow);
  56. UINT32 getRenderWindowCount () const;
  57. D3D9RenderWindow* getRenderWindow (UINT32 index);
  58. UINT32 getLastPresentFrame () const { return mLastPresentFrame; }
  59. void setAdapterOrdinalIndex (D3D9RenderWindow* renderWindow, UINT32 adapterOrdinalInGroupIndex);
  60. void copyContentsToMemory(D3D9RenderWindow* window, const PixelData &dst, RenderTarget::FrameBuffer buffer);
  61. void clearDeviceStreams ();
  62. public:
  63. D3D9Device (D3D9DeviceManager* deviceManager,
  64. UINT adapterNumber,
  65. HMONITOR hMonitor,
  66. D3DDEVTYPE devType,
  67. DWORD behaviorFlags);
  68. ~D3D9Device ();
  69. protected:
  70. D3D9DeviceManager* mpDeviceManager; // The manager of this device instance.
  71. IDirect3DDevice9* mpDevice; // Will hold the device interface.
  72. UINT mAdapterNumber; // The adapter that this device belongs to.
  73. HMONITOR mMonitor; // The monitor that this device belongs to.
  74. D3DDEVTYPE mDeviceType; // Device type.
  75. static HWND msSharedFocusWindow; // The shared focus window in case of multiple full screen render windows.
  76. HWND mFocusWindow; // The focus window this device attached to.
  77. DWORD mBehaviorFlags; // The behavior of this device.
  78. D3DPRESENT_PARAMETERS* mPresentationParams; // Presentation parameters which the device was created with. May be
  79. // an array of presentation parameters in case of multi-head device.
  80. UINT mPresentationParamsCount; // Number of presentation parameters elements.
  81. D3DCAPS9 mD3D9DeviceCaps; // Device caps.
  82. bool mD3D9DeviceCapsValid; // True if device caps initialized.
  83. D3DDEVICE_CREATION_PARAMETERS mCreationParams; // Creation parameters.
  84. UINT32 mLastPresentFrame; // Last frame that this device present method called.
  85. bool mDeviceLost; // True if device entered lost state.
  86. struct RenderWindowResources
  87. {
  88. IDirect3DSwapChain9* swapChain; // Swap chain interface.
  89. UINT32 adapterOrdinalInGroupIndex; // Relative index of the render window in the group.
  90. UINT32 presentParametersIndex; // Index of present parameter in the shared array of the device.
  91. IDirect3DSurface9* backBuffer; // The back buffer of the render window.
  92. IDirect3DSurface9* depthBuffer; // The depth buffer of the render window.
  93. D3DPRESENT_PARAMETERS presentParameters; // Present parameters of the render window.
  94. bool acquired; // True if resources acquired.
  95. };
  96. typedef map<D3D9RenderWindow*, RenderWindowResources*>::type RenderWindowToResorucesMap;
  97. typedef RenderWindowToResorucesMap::iterator RenderWindowToResorucesIterator;
  98. RenderWindowToResorucesMap mMapRenderWindowToResoruces; // Map between render window to resources.
  99. protected:
  100. RenderWindowToResorucesIterator getRenderWindowIterator (D3D9RenderWindow* renderWindow);
  101. bool acquire (D3D9RenderWindow* renderWindow);
  102. bool reset ();
  103. void updatePresentationParameters ();
  104. void updateRenderWindowsIndices ();
  105. void createD3D9Device ();
  106. void releaseD3D9Device ();
  107. void releaseRenderWindowResources (RenderWindowResources* renderWindowResources);
  108. void acquireRenderWindowResources (RenderWindowToResorucesIterator it);
  109. void setupDeviceStates ();
  110. void notifyDeviceLost ();
  111. void validateFocusWindow ();
  112. void validateBackBufferSize (D3D9RenderWindow* renderWindow);
  113. bool validateDisplayMonitor (D3D9RenderWindow* renderWindow);
  114. bool validateDeviceState (D3D9RenderWindow* renderWindow);
  115. bool isSwapChainWindow (D3D9RenderWindow* renderWindow);
  116. D3D9RenderWindow* getPrimaryWindow ();
  117. void setSharedWindowHandle (HWND hSharedHWND);
  118. private:
  119. friend class D3D9DeviceManager;
  120. friend class D3D9RenderSystem;
  121. };
  122. }
  123. #endif