BsD3D9RenderWindow.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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& videoMode) 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. /**
  56. * Copies the contents of a frame buffer into the pre-allocated buffer.
  57. *
  58. * @param[out] dst Previously allocated buffer to read the contents into. Must be of valid size.
  59. * @param[in] buffer Frame buffer to read the contents from.
  60. */
  61. void copyToMemory(PixelData& dst, FrameBuffer buffer);
  62. /** @copydoc RenderWindowCore::swapBuffers */
  63. void swapBuffers() override;
  64. /** @copydoc RenderWindowCore::_windowMovedOrResized */
  65. void _windowMovedOrResized() override;
  66. /** Gets internal Win32 window handle. */
  67. HWND _getWindowHandle() const;
  68. /** Gets the DirectX 9 device object that manages this window. */
  69. IDirect3DDevice9* _getD3D9Device() const;
  70. /** Gets the device that manages this window. */
  71. D3D9Device* _getDevice() const;
  72. /** Sets the device that manages this window. */
  73. void _setDevice(D3D9Device* device);
  74. /** Build the presentation parameters used with this window. */
  75. void _buildPresentParameters(D3DPRESENT_PARAMETERS* presentParams) const;
  76. /** Accessor for render surface. */
  77. IDirect3DSurface9* _getRenderSurface() const;
  78. /** Returns true if this window use depth buffer. */
  79. bool _isDepthBuffered() const;
  80. /** Validate the device for this window. */
  81. bool _validateDevice();
  82. protected:
  83. friend class D3D9RenderWindow;
  84. /** @copydoc CoreObjectCore::initialize */
  85. virtual void initialize() override;
  86. /** @copydoc RenderWindowCore::getProperties */
  87. const RenderTargetProperties& getPropertiesInternal() const override { return mProperties; }
  88. /** @copydoc RenderWindowCore::getSyncedProperties */
  89. RenderWindowProperties& getSyncedProperties() override { return mSyncedProperties; }
  90. /** @copydoc RenderWindowCore::syncProperties */
  91. void syncProperties() override;
  92. protected:
  93. Win32Window* mWindow;
  94. HINSTANCE mInstance;
  95. D3D9Device* mDevice;
  96. bool mDeviceValid;
  97. D3DMULTISAMPLE_TYPE mMultisampleType;
  98. DWORD mMultisampleQuality;
  99. UINT mDisplayFrequency;
  100. unsigned int mVSyncInterval;
  101. bool mIsDepthBuffered;
  102. bool mIsChild;
  103. bool mShowOnSwap;
  104. D3D9RenderWindowProperties mProperties;
  105. D3D9RenderWindowProperties mSyncedProperties;
  106. };
  107. /**
  108. * Render window implementation for Windows.
  109. *
  110. * @note Sim thread only.
  111. */
  112. class BS_D3D9_EXPORT D3D9RenderWindow : public RenderWindow
  113. {
  114. public:
  115. ~D3D9RenderWindow() { }
  116. /** @copydoc RenderWindow::screenToWindowPos */
  117. void getCustomAttribute(const String& name, void* pData) const override;
  118. /** @copydoc RenderWindow::screenToWindowPos */
  119. Vector2I screenToWindowPos(const Vector2I& screenPos) const override;
  120. /** @copydoc RenderWindow::windowToScreenPos */
  121. Vector2I windowToScreenPos(const Vector2I& windowPos) const override;
  122. /** @copydoc RenderWindow::getCore */
  123. SPtr<D3D9RenderWindowCore> getCore() const;
  124. protected:
  125. friend class D3D9RenderWindowManager;
  126. friend class D3D9RenderWindowCore;
  127. D3D9RenderWindow(const RENDER_WINDOW_DESC& desc, UINT32 windowId, HINSTANCE instance);
  128. /** @copydoc RenderWindowCore::getProperties */
  129. const RenderTargetProperties& getPropertiesInternal() const override { return mProperties; }
  130. /** @copydoc RenderWindow::syncProperties */
  131. void syncProperties() override;
  132. /** Retrieves internal window handle. */
  133. HWND getHWnd() const;
  134. private:
  135. HINSTANCE mInstance;
  136. D3D9RenderWindowProperties mProperties;
  137. };
  138. /** @} */
  139. }