BsD3D9RenderWindow.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. #pragma once
  2. #include "BsD3D9Prerequisites.h"
  3. #include "BsRenderWindow.h"
  4. #include "BsD3D9Device.h"
  5. namespace BansheeEngine
  6. {
  7. class D3D9RenderWindow;
  8. /**
  9. * @brief Contains various properties that describe a render window.
  10. */
  11. class BS_D3D9_EXPORT D3D9RenderWindowProperties : public RenderWindowProperties
  12. {
  13. public:
  14. virtual ~D3D9RenderWindowProperties() { }
  15. private:
  16. friend class D3D9RenderWindowCore;
  17. friend class D3D9RenderWindow;
  18. };
  19. /**
  20. * @brief Render window implementation for Windows.
  21. *
  22. * @note Core thread only.
  23. */
  24. class BS_D3D9_EXPORT D3D9RenderWindowCore : public RenderWindowCore
  25. {
  26. public:
  27. D3D9RenderWindowCore(D3D9RenderWindow* parent, RenderWindowProperties* properties, const RENDER_WINDOW_DESC& desc, HINSTANCE instance);
  28. ~D3D9RenderWindowCore();
  29. /**
  30. * @copydoc RenderWindowCore::setFullscreen(UINT32, UINT32, float, UINT32)
  31. */
  32. void setFullscreen(UINT32 width, UINT32 height, float refreshRate = 60.0f, UINT32 monitorIdx = 0);
  33. /**
  34. * @copydoc RenderWindowCore::setFullscreen(const VideoMode&)
  35. */
  36. void setFullscreen(const VideoMode& mode);
  37. /**
  38. * @copydoc RenderWindowCore::setWindowed
  39. */
  40. void setWindowed(UINT32 width, UINT32 height);
  41. /**
  42. * @copydoc RenderWindowCore::setHidden
  43. */
  44. void setHidden(bool hidden);
  45. /**
  46. * @copydoc RenderWindowCore::move
  47. */
  48. void move(INT32 left, INT32 top);
  49. /**
  50. * @copydoc RenderWindowCore::resize
  51. */
  52. void resize(UINT32 width, UINT32 height);
  53. /**
  54. * @copydoc RenderWindowCore::getCustomAttribute
  55. */
  56. void getCustomAttribute(const String& name, void* pData) const;
  57. /**
  58. * @copydoc RenderWindowCore::copyContentsToMemory
  59. */
  60. void copyToMemory(PixelData &dst, FrameBuffer buffer);
  61. /**
  62. * @copydoc RenderWindowCore::swapBuffers
  63. */
  64. void swapBuffers();
  65. /**
  66. * @copydoc RenderWindowCore::_windowMovedOrResized
  67. */
  68. void _windowMovedOrResized();
  69. /**
  70. * @brief Gets internal Win32 window handle.
  71. */
  72. HWND _getWindowHandle() const { return mHWnd; }
  73. /**
  74. * @brief Gets the DirectX 9 device object that manages this window.
  75. */
  76. IDirect3DDevice9* _getD3D9Device() const;
  77. /**
  78. * @brief Gets the device that manages this window.
  79. */
  80. D3D9Device* _getDevice() const;
  81. /**
  82. * @brief Sets the device that manages this window.
  83. */
  84. void _setDevice(D3D9Device* device);
  85. /**
  86. * @brief Build the presentation parameters used with this window.
  87. */
  88. void _buildPresentParameters(D3DPRESENT_PARAMETERS* presentParams) const;
  89. /**
  90. * @brief Accessor for render surface.
  91. */
  92. IDirect3DSurface9* _getRenderSurface() const;
  93. /**
  94. * @brief Returns true if this window use depth buffer.
  95. */
  96. bool _isDepthBuffered() const;
  97. /**
  98. * @brief Validate the device for this window.
  99. */
  100. bool _validateDevice();
  101. protected:
  102. friend class D3D9RenderWindow;
  103. /**
  104. * @brief Updates window coordinates and size from actual values provided by Windows.
  105. */
  106. void updateWindowRect();
  107. /**
  108. * @brief Calculates window size based on provided client area size and currently set window style.
  109. */
  110. void getAdjustedWindowSize(UINT32 clientWidth, UINT32 clientHeight,
  111. DWORD style, UINT32* winWidth, UINT32* winHeight);
  112. protected:
  113. HINSTANCE mInstance;
  114. D3D9Device* mDevice;
  115. bool mDeviceValid;
  116. HWND mHWnd;
  117. bool mIsExternal;
  118. D3DMULTISAMPLE_TYPE mMultisampleType;
  119. DWORD mMultisampleQuality;
  120. UINT mDisplayFrequency;
  121. unsigned int mVSyncInterval;
  122. DWORD mStyle;
  123. DWORD mWindowedStyle;
  124. DWORD mWindowedStyleEx;
  125. bool mIsDepthBuffered;
  126. bool mIsChild;
  127. };
  128. /**
  129. * @brief Render window implementation for Windows.
  130. *
  131. * @note Sim thread only.
  132. */
  133. class BS_D3D9_EXPORT D3D9RenderWindow : public RenderWindow
  134. {
  135. public:
  136. ~D3D9RenderWindow() { }
  137. /**
  138. * @copydoc RenderWindow::screenToWindowPos
  139. */
  140. Vector2I screenToWindowPos(const Vector2I& screenPos) const;
  141. /**
  142. * @copydoc RenderWindow::windowToScreenPos
  143. */
  144. Vector2I windowToScreenPos(const Vector2I& windowPos) const;
  145. /**
  146. * @copydoc RenderWindow::requiresTextureFlipping
  147. */
  148. bool requiresTextureFlipping() const { return false; }
  149. /**
  150. * @copydoc RenderWindow::getCustomAttribute
  151. */
  152. void getCustomAttribute(const String& name, void* pData) const;
  153. /**
  154. * @copydoc RenderWindow::getCore
  155. */
  156. D3D9RenderWindowCore* getCore() const;
  157. protected:
  158. friend class D3D9RenderWindowManager;
  159. D3D9RenderWindow(HINSTANCE instance);
  160. /**
  161. * @copydoc RenderWindow::initialize_internal
  162. */
  163. virtual void initialize_internal();
  164. /**
  165. * @copydoc RenderWindow::createProperties
  166. */
  167. virtual RenderTargetProperties* createProperties() const;
  168. /**
  169. * @copydoc RenderWindow::createCore
  170. */
  171. virtual RenderWindowCore* createCore(RenderWindowProperties* properties, const RENDER_WINDOW_DESC& desc);
  172. private:
  173. HINSTANCE mInstance;
  174. HWND mHWnd;
  175. };
  176. }