BsD3D11RenderWindow.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsD3D11Prerequisites.h"
  5. #include "BsRenderWindow.h"
  6. namespace BansheeEngine
  7. {
  8. /** @addtogroup D3D11
  9. * @{
  10. */
  11. class D3D11RenderWindow;
  12. /** Contains various properties that describe a render window. */
  13. class BS_D3D11_EXPORT D3D11RenderWindowProperties : public RenderWindowProperties
  14. {
  15. public:
  16. D3D11RenderWindowProperties(const RENDER_WINDOW_DESC& desc);
  17. virtual ~D3D11RenderWindowProperties() { }
  18. private:
  19. friend class D3D11RenderWindowCore;
  20. friend class D3D11RenderWindow;
  21. };
  22. /**
  23. * Render window implementation for Windows and DirectX 11.
  24. *
  25. * @note Core thread only.
  26. */
  27. class BS_D3D11_EXPORT D3D11RenderWindowCore : public RenderWindowCore
  28. {
  29. public:
  30. D3D11RenderWindowCore(const RENDER_WINDOW_DESC& desc, UINT32 windowId,
  31. D3D11Device& device, IDXGIFactory* DXGIFactory);
  32. ~D3D11RenderWindowCore();
  33. /** @copydoc RenderWindowCore::move */
  34. void move(INT32 left, INT32 top) override;
  35. /** @copydoc RenderWindowCore::resize */
  36. void resize(UINT32 width, UINT32 height) override;
  37. /** @copydoc RenderWindowCore::setHidden */
  38. void setHidden(bool hidden) override;
  39. /** @copydoc RenderWindowCore::setActive */
  40. void setActive(bool state) override;
  41. /** @copydoc RenderWindowCore::minimize */
  42. void minimize() override;
  43. /** @copydoc RenderWindowCore::maximize */
  44. void maximize() override;
  45. /** @copydoc RenderWindowCore::restore */
  46. void restore() override;
  47. /** @copydoc RenderWindowCore::setFullscreen(UINT32, UINT32, float, UINT32) */
  48. void setFullscreen(UINT32 width, UINT32 height, float refreshRate = 60.0f, UINT32 monitorIdx = 0) override;
  49. /** @copydoc RenderWindowCore::setFullscreen(const VideoMode&) */
  50. void setFullscreen(const VideoMode& videoMode) override;
  51. /** @copydoc RenderWindowCore::setWindowed */
  52. void setWindowed(UINT32 width, UINT32 height) override;
  53. /**
  54. * Copies the contents of a frame buffer into the pre-allocated buffer.
  55. *
  56. * @param[out] dst Previously allocated buffer to read the contents into. Must be of valid size.
  57. * @param[in] buffer Frame buffer to read the contents from.
  58. */
  59. void copyToMemory(PixelData &dst, FrameBuffer buffer);
  60. /** @copydoc RenderWindowCore::swapBuffers */
  61. void swapBuffers() override;
  62. /** @copydoc RenderWindowCore::getCustomAttribute */
  63. void getCustomAttribute(const String& name, void* pData) const override;
  64. /** @copydoc RenderWindowCore::_windowMovedOrResized */
  65. void _windowMovedOrResized() override;
  66. /** Returns presentation parameters used for creating the window swap chain. */
  67. DXGI_SWAP_CHAIN_DESC* _getPresentationParameters() { return &mSwapChainDesc; }
  68. /** Returns internal window handle. */
  69. HWND _getWindowHandle() const;
  70. protected:
  71. friend class D3D11RenderWindow;
  72. /** @copydoc CoreObjectCore::initialize */
  73. virtual void initialize() override;
  74. /** Creates internal resources dependent on window size. */
  75. void createSizeDependedD3DResources();
  76. /** Destroys internal resources dependent on window size. */
  77. void destroySizeDependedD3DResources();
  78. /** Queries the current DXGI device. Make sure to release the returned object when done with it. */
  79. IDXGIDevice* queryDxgiDevice();
  80. /** Creates a swap chain for the window. */
  81. void createSwapChain();
  82. /** Resizes all buffers attached to the swap chain to the specified size. */
  83. void resizeSwapChainBuffers(UINT32 width, UINT32 height);
  84. /** @copydoc RenderWindowCore::getProperties */
  85. const RenderTargetProperties& getPropertiesInternal() const override { return mProperties; }
  86. /** @copydoc RenderWindowCore::getSyncedProperties */
  87. RenderWindowProperties& getSyncedProperties() override { return mSyncedProperties; }
  88. /** @copydoc RenderWindowCore::syncProperties */
  89. void syncProperties() override;
  90. protected:
  91. D3D11Device& mDevice;
  92. IDXGIFactory* mDXGIFactory;
  93. bool mSizing;
  94. bool mIsChild;
  95. bool mShowOnSwap;
  96. DXGI_SAMPLE_DESC mMultisampleType;
  97. UINT32 mRefreshRateNumerator;
  98. UINT32 mRefreshRateDenominator;
  99. ID3D11Texture2D* mBackBuffer;
  100. ID3D11RenderTargetView* mRenderTargetView;
  101. SPtr<TextureView> mDepthStencilView;
  102. SPtr<TextureCore> mDepthStencilBuffer;
  103. IDXGISwapChain* mSwapChain;
  104. DXGI_SWAP_CHAIN_DESC mSwapChainDesc;
  105. Win32Window* mWindow;
  106. D3D11RenderWindowProperties mProperties;
  107. D3D11RenderWindowProperties mSyncedProperties;
  108. };
  109. /**
  110. * Render window implementation for Windows and DirectX 11.
  111. *
  112. * @note Sim thread only.
  113. */
  114. class BS_D3D11_EXPORT D3D11RenderWindow : public RenderWindow
  115. {
  116. public:
  117. ~D3D11RenderWindow() { }
  118. /** @copydoc RenderWindow::screenToWindowPos */
  119. void getCustomAttribute(const String& name, void* pData) const override;
  120. /** @copydoc RenderWindow::screenToWindowPos */
  121. Vector2I screenToWindowPos(const Vector2I& screenPos) const override;
  122. /** @copydoc RenderWindow::windowToScreenPos */
  123. Vector2I windowToScreenPos(const Vector2I& windowPos) const override;
  124. /** @copydoc RenderWindow::getCore */
  125. SPtr<D3D11RenderWindowCore> getCore() const;
  126. protected:
  127. friend class D3D11RenderWindowManager;
  128. friend class D3D11RenderWindowCore;
  129. D3D11RenderWindow(const RENDER_WINDOW_DESC& desc, UINT32 windowId,
  130. D3D11Device& device, IDXGIFactory* DXGIFactory);
  131. /** @copydoc RenderWindowCore::getProperties */
  132. const RenderTargetProperties& getPropertiesInternal() const override { return mProperties; }
  133. /** @copydoc RenderWindow::syncProperties */
  134. void syncProperties() override;
  135. /** Retrieves internal window handle. */
  136. HWND getHWnd() const;
  137. private:
  138. D3D11Device& mDevice;
  139. IDXGIFactory* mDXGIFactory;
  140. D3D11RenderWindowProperties mProperties;
  141. };
  142. /** @} */
  143. }