BsWin32RenderWindow.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. namespace BansheeEngine
  7. {
  8. /** @addtogroup Vulkan
  9. * @{
  10. */
  11. class Win32RenderWindow;
  12. /** Contains various properties that describe a render window. */
  13. class Win32RenderWindowProperties : public RenderWindowProperties
  14. {
  15. public:
  16. Win32RenderWindowProperties(const RENDER_WINDOW_DESC& desc);
  17. virtual ~Win32RenderWindowProperties() { }
  18. private:
  19. friend class Win32RenderWindowCore;
  20. friend class Win32RenderWindow;
  21. };
  22. /**
  23. * Render window implementation for Windows and Vulkan.
  24. *
  25. * @note Core thread only.
  26. */
  27. class Win32RenderWindowCore : public RenderWindowCore
  28. {
  29. public:
  30. Win32RenderWindowCore(const RENDER_WINDOW_DESC& desc, UINT32 windowId, VulkanRenderAPI& renderAPI);
  31. ~Win32RenderWindowCore();
  32. /** @copydoc RenderWindowCore::move */
  33. void move(INT32 left, INT32 top) override;
  34. /** @copydoc RenderWindowCore::resize */
  35. void resize(UINT32 width, UINT32 height) override;
  36. /** @copydoc RenderWindowCore::setHidden */
  37. void setHidden(bool hidden) override;
  38. /** @copydoc RenderWindowCore::setActive */
  39. void setActive(bool state) override;
  40. /** @copydoc RenderWindowCore::minimize */
  41. void minimize() override;
  42. /** @copydoc RenderWindowCore::maximize */
  43. void maximize() override;
  44. /** @copydoc RenderWindowCore::restore */
  45. void restore() override;
  46. /** @copydoc RenderWindowCore::setFullscreen(UINT32, UINT32, float, UINT32) */
  47. void setFullscreen(UINT32 width, UINT32 height, float refreshRate = 60.0f, UINT32 monitorIdx = 0) override;
  48. /** @copydoc RenderWindowCore::setFullscreen(const VideoMode&) */
  49. void setFullscreen(const VideoMode& videoMode) override;
  50. /** @copydoc RenderWindowCore::setWindowed */
  51. void setWindowed(UINT32 width, UINT32 height) override;
  52. /**
  53. * Copies the contents of a frame buffer into the pre-allocated buffer.
  54. *
  55. * @param[out] dst Previously allocated buffer to read the contents into. Must be of valid size.
  56. * @param[in] buffer Frame buffer to read the contents from.
  57. */
  58. void copyToMemory(PixelData &dst, FrameBuffer buffer);
  59. /** Prepares the back buffer for rendering. Should be called before it is bound to the GPU. */
  60. void acquireBackBuffer();
  61. /** @copydoc RenderWindowCore::swapBuffers */
  62. void swapBuffers(UINT32 syncMask = 0xFFFFFFFF) override;
  63. /** @copydoc RenderWindowCore::getCustomAttribute */
  64. void getCustomAttribute(const String& name, void* data) const override;
  65. /** @copydoc RenderWindowCore::_windowMovedOrResized */
  66. void _windowMovedOrResized() override;
  67. /** Returns internal window handle. */
  68. HWND _getWindowHandle() const;
  69. protected:
  70. friend class Win32RenderWindow;
  71. /** @copydoc CoreObjectCore::initialize */
  72. void initialize() override;
  73. /** @copydoc RenderWindowCore::getProperties */
  74. const RenderTargetProperties& getPropertiesInternal() const override { return mProperties; }
  75. /** @copydoc RenderWindowCore::getSyncedProperties */
  76. RenderWindowProperties& getSyncedProperties() override { return mSyncedProperties; }
  77. /** @copydoc RenderWindowCore::syncProperties */
  78. void syncProperties() override;
  79. protected:
  80. Win32Window* mWindow;
  81. bool mIsChild;
  82. bool mShowOnSwap;
  83. INT32 mDisplayFrequency;
  84. VulkanRenderAPI& mRenderAPI;
  85. VkSurfaceKHR mSurface;
  86. VkColorSpaceKHR mColorSpace;
  87. VkFormat mColorFormat;
  88. VkFormat mDepthFormat;
  89. UINT32 mPresentQueueFamily;
  90. SPtr<VulkanSwapChain> mSwapChain;
  91. VkSemaphore mSemaphoresTemp[BS_MAX_UNIQUE_QUEUES];
  92. bool mRequiresNewBackBuffer;
  93. Win32RenderWindowProperties mProperties;
  94. Win32RenderWindowProperties mSyncedProperties;
  95. };
  96. /**
  97. * Render window implementation for Windows and Vulkan.
  98. *
  99. * @note Sim thread only.
  100. */
  101. class Win32RenderWindow : public RenderWindow
  102. {
  103. public:
  104. ~Win32RenderWindow() { }
  105. /** @copydoc RenderWindow::screenToWindowPos */
  106. void getCustomAttribute(const String& name, void* pData) const override;
  107. /** @copydoc RenderWindow::screenToWindowPos */
  108. Vector2I screenToWindowPos(const Vector2I& screenPos) const override;
  109. /** @copydoc RenderWindow::windowToScreenPos */
  110. Vector2I windowToScreenPos(const Vector2I& windowPos) const override;
  111. /** @copydoc RenderWindow::getCore */
  112. SPtr<Win32RenderWindowCore> getCore() const;
  113. /** Retrieves internal window handle. */
  114. HWND getHWnd() const;
  115. protected:
  116. friend class VulkanRenderWindowManager;
  117. friend class Win32RenderWindowCore;
  118. Win32RenderWindow(const RENDER_WINDOW_DESC& desc, UINT32 windowId);
  119. /** @copydoc RenderWindowCore::getProperties */
  120. const RenderTargetProperties& getPropertiesInternal() const override { return mProperties; }
  121. /** @copydoc RenderWindow::syncProperties */
  122. void syncProperties() override;
  123. private:
  124. Win32RenderWindowProperties mProperties;
  125. };
  126. /** @} */
  127. }