BsD3D9RenderWindow.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsD3D9Prerequisites.h"
  5. #include "BsRenderWindow.h"
  6. #include "BsD3D9Device.h"
  7. namespace BansheeEngine
  8. {
  9. /** @addtogroup D3D9
  10. * @{
  11. */
  12. class D3D9RenderWindow;
  13. /** Contains various properties that describe a render window. */
  14. class BS_D3D9_EXPORT D3D9RenderWindowProperties : public RenderWindowProperties
  15. {
  16. public:
  17. D3D9RenderWindowProperties(const RENDER_WINDOW_DESC& desc);
  18. virtual ~D3D9RenderWindowProperties() { }
  19. private:
  20. friend class D3D9RenderWindowCore;
  21. friend class D3D9RenderWindow;
  22. };
  23. /**
  24. * Render window implementation for Windows.
  25. *
  26. * @note Core thread only.
  27. */
  28. class BS_D3D9_EXPORT D3D9RenderWindowCore : public RenderWindowCore
  29. {
  30. public:
  31. D3D9RenderWindowCore(const RENDER_WINDOW_DESC& desc, UINT32 windowId, HINSTANCE instance);
  32. ~D3D9RenderWindowCore();
  33. /** @copydoc RenderWindowCore::setFullscreen(UINT32, UINT32, float, UINT32) */
  34. void setFullscreen(UINT32 width, UINT32 height, float refreshRate = 60.0f, UINT32 monitorIdx = 0) override;
  35. /** @copydoc RenderWindowCore::setFullscreen(const VideoMode&) */
  36. void setFullscreen(const VideoMode& mode) override;
  37. /** @copydoc RenderWindowCore::setWindowed */
  38. void setWindowed(UINT32 width, UINT32 height) override;
  39. /** @copydoc RenderWindowCore::setActive */
  40. virtual void setActive(bool state) override;
  41. /** @copydoc RenderWindowCore::setHidden */
  42. void setHidden(bool hidden) override;
  43. /** @copydoc RenderWindowCore::minimize */
  44. void minimize() override;
  45. /** @copydoc RenderWindowCore::maximize */
  46. void maximize() override;
  47. /** @copydoc RenderWindowCore::restore */
  48. void restore() override;
  49. /** @copydoc RenderWindowCore::move */
  50. void move(INT32 left, INT32 top) override;
  51. /** @copydoc RenderWindowCore::resize */
  52. void resize(UINT32 width, UINT32 height) override;
  53. /** @copydoc RenderWindowCore::getCustomAttribute */
  54. void getCustomAttribute(const String& name, void* pData) const override;
  55. /** @copydoc RenderWindowCore::copyContentsToMemory */
  56. void copyToMemory(PixelData &dst, FrameBuffer buffer);
  57. /** @copydoc RenderWindowCore::swapBuffers */
  58. void swapBuffers() override;
  59. /** @copydoc RenderWindowCore::_windowMovedOrResized */
  60. void _windowMovedOrResized() override;
  61. /** Gets internal Win32 window handle. */
  62. HWND _getWindowHandle() const;
  63. /** Gets the DirectX 9 device object that manages this window. */
  64. IDirect3DDevice9* _getD3D9Device() const;
  65. /** Gets the device that manages this window. */
  66. D3D9Device* _getDevice() const;
  67. /** Sets the device that manages this window. */
  68. void _setDevice(D3D9Device* device);
  69. /** Build the presentation parameters used with this window. */
  70. void _buildPresentParameters(D3DPRESENT_PARAMETERS* presentParams) const;
  71. /** Accessor for render surface. */
  72. IDirect3DSurface9* _getRenderSurface() const;
  73. /** Returns true if this window use depth buffer. */
  74. bool _isDepthBuffered() const;
  75. /** Validate the device for this window. */
  76. bool _validateDevice();
  77. protected:
  78. friend class D3D9RenderWindow;
  79. /** @copydoc CoreObjectCore::initialize */
  80. virtual void initialize() override;
  81. /** @copydoc RenderWindowCore::getProperties */
  82. const RenderTargetProperties& getPropertiesInternal() const override { return mProperties; }
  83. /** @copydoc RenderWindowCore::getSyncedProperties */
  84. RenderWindowProperties& getSyncedProperties() override { return mSyncedProperties; }
  85. /** @copydoc RenderWindowCore::syncProperties */
  86. void syncProperties() override;
  87. protected:
  88. Win32Window* mWindow;
  89. HINSTANCE mInstance;
  90. D3D9Device* mDevice;
  91. bool mDeviceValid;
  92. D3DMULTISAMPLE_TYPE mMultisampleType;
  93. DWORD mMultisampleQuality;
  94. UINT mDisplayFrequency;
  95. unsigned int mVSyncInterval;
  96. bool mIsDepthBuffered;
  97. bool mIsChild;
  98. bool mShowOnSwap;
  99. D3D9RenderWindowProperties mProperties;
  100. D3D9RenderWindowProperties mSyncedProperties;
  101. };
  102. /**
  103. * Render window implementation for Windows.
  104. *
  105. * @note Sim thread only.
  106. */
  107. class BS_D3D9_EXPORT D3D9RenderWindow : public RenderWindow
  108. {
  109. public:
  110. ~D3D9RenderWindow() { }
  111. /** @copydoc RenderWindow::screenToWindowPos */
  112. void getCustomAttribute(const String& name, void* pData) const override;
  113. /** @copydoc RenderWindow::screenToWindowPos */
  114. Vector2I screenToWindowPos(const Vector2I& screenPos) const override;
  115. /** @copydoc RenderWindow::windowToScreenPos */
  116. Vector2I windowToScreenPos(const Vector2I& windowPos) const override;
  117. /** @copydoc RenderWindow::getCore */
  118. SPtr<D3D9RenderWindowCore> getCore() const;
  119. protected:
  120. friend class D3D9RenderWindowManager;
  121. friend class D3D9RenderWindowCore;
  122. D3D9RenderWindow(const RENDER_WINDOW_DESC& desc, UINT32 windowId, HINSTANCE instance);
  123. /** @copydoc RenderWindowCore::getProperties */
  124. const RenderTargetProperties& getPropertiesInternal() const override { return mProperties; }
  125. /** @copydoc RenderWindow::syncProperties */
  126. void syncProperties() override;
  127. /** Retrieves internal window handle. */
  128. HWND getHWnd() const;
  129. private:
  130. HINSTANCE mInstance;
  131. D3D9RenderWindowProperties mProperties;
  132. };
  133. /** @} */
  134. }