BsWin32RenderWindow.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsVulkanPrerequisites.h"
  5. #include "BsRenderWindow.h"
  6. #include "BsVulkanFramebuffer.h"
  7. namespace BansheeEngine
  8. {
  9. /** @addtogroup Vulkan
  10. * @{
  11. */
  12. class Win32RenderWindow;
  13. /** Contains various properties that describe a render window. */
  14. class Win32RenderWindowProperties : public RenderWindowProperties
  15. {
  16. public:
  17. Win32RenderWindowProperties(const RENDER_WINDOW_DESC& desc);
  18. virtual ~Win32RenderWindowProperties() { }
  19. private:
  20. friend class Win32RenderWindowCore;
  21. friend class Win32RenderWindow;
  22. };
  23. /**
  24. * Render window implementation for Windows and Vulkan.
  25. *
  26. * @note Core thread only.
  27. */
  28. class Win32RenderWindowCore : public RenderWindowCore
  29. {
  30. public:
  31. Win32RenderWindowCore(const RENDER_WINDOW_DESC& desc, UINT32 windowId, VulkanRenderAPI& renderAPI);
  32. ~Win32RenderWindowCore();
  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 internal window handle. */
  67. HWND _getWindowHandle() const;
  68. protected:
  69. friend class Win32RenderWindow;
  70. /** @copydoc CoreObjectCore::initialize */
  71. void initialize() override;
  72. /** @copydoc RenderWindowCore::getProperties */
  73. const RenderTargetProperties& getPropertiesInternal() const override { return mProperties; }
  74. /** @copydoc RenderWindowCore::getSyncedProperties */
  75. RenderWindowProperties& getSyncedProperties() override { return mSyncedProperties; }
  76. /** @copydoc RenderWindowCore::syncProperties */
  77. void syncProperties() override;
  78. protected:
  79. /** Contains an information regarding a framebuffer representing a single swap chain surface. */
  80. struct FrameBufferInfo
  81. {
  82. UPtr<VulkanFramebuffer> framebuffer;
  83. VULKAN_FRAMEBUFFER_DESC desc;
  84. };
  85. Win32Window* mWindow;
  86. bool mIsChild;
  87. bool mShowOnSwap;
  88. INT32 mDisplayFrequency;
  89. VulkanRenderAPI& mRenderAPI;
  90. VkSurfaceKHR mSurface;
  91. VkColorSpaceKHR mColorSpace;
  92. VkFormat mColorFormat;
  93. VkFormat mDepthFormat;
  94. SPtr<VulkanSwapChain> mSwapChain;
  95. FrameBufferInfo mFramebufferInfos[BS_NUM_BACK_BUFFERS + 1];
  96. Win32RenderWindowProperties mProperties;
  97. Win32RenderWindowProperties mSyncedProperties;
  98. };
  99. /**
  100. * Render window implementation for Windows and Vulkan.
  101. *
  102. * @note Sim thread only.
  103. */
  104. class Win32RenderWindow : public RenderWindow
  105. {
  106. public:
  107. ~Win32RenderWindow() { }
  108. /** @copydoc RenderWindow::screenToWindowPos */
  109. void getCustomAttribute(const String& name, void* pData) const override;
  110. /** @copydoc RenderWindow::screenToWindowPos */
  111. Vector2I screenToWindowPos(const Vector2I& screenPos) const override;
  112. /** @copydoc RenderWindow::windowToScreenPos */
  113. Vector2I windowToScreenPos(const Vector2I& windowPos) const override;
  114. /** @copydoc RenderWindow::getCore */
  115. SPtr<Win32RenderWindowCore> getCore() const;
  116. /** Retrieves internal window handle. */
  117. HWND getHWnd() const;
  118. protected:
  119. friend class VulkanRenderWindowManager;
  120. friend class Win32RenderWindowCore;
  121. Win32RenderWindow(const RENDER_WINDOW_DESC& desc, UINT32 windowId);
  122. /** @copydoc RenderWindowCore::getProperties */
  123. const RenderTargetProperties& getPropertiesInternal() const override { return mProperties; }
  124. /** @copydoc RenderWindow::syncProperties */
  125. void syncProperties() override;
  126. private:
  127. Win32RenderWindowProperties mProperties;
  128. };
  129. /** @} */
  130. }