BsD3D9RenderWindow.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. class D3D9RenderWindow;
  10. /** Contains various properties that describe a render window. */
  11. class BS_D3D9_EXPORT D3D9RenderWindowProperties : public RenderWindowProperties
  12. {
  13. public:
  14. D3D9RenderWindowProperties(const RENDER_WINDOW_DESC& desc);
  15. virtual ~D3D9RenderWindowProperties() { }
  16. private:
  17. friend class D3D9RenderWindowCore;
  18. friend class D3D9RenderWindow;
  19. };
  20. /**
  21. * Render window implementation for Windows.
  22. *
  23. * @note Core thread only.
  24. */
  25. class BS_D3D9_EXPORT D3D9RenderWindowCore : public RenderWindowCore
  26. {
  27. public:
  28. D3D9RenderWindowCore(const RENDER_WINDOW_DESC& desc, UINT32 windowId, HINSTANCE instance);
  29. ~D3D9RenderWindowCore();
  30. /** @copydoc RenderWindowCore::setFullscreen(UINT32, UINT32, float, UINT32) */
  31. void setFullscreen(UINT32 width, UINT32 height, float refreshRate = 60.0f, UINT32 monitorIdx = 0) override;
  32. /** @copydoc RenderWindowCore::setFullscreen(const VideoMode&) */
  33. void setFullscreen(const VideoMode& mode) override;
  34. /** @copydoc RenderWindowCore::setWindowed */
  35. void setWindowed(UINT32 width, UINT32 height) override;
  36. /** @copydoc RenderWindowCore::setActive */
  37. virtual void setActive(bool state) override;
  38. /** @copydoc RenderWindowCore::setHidden */
  39. void setHidden(bool hidden) 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::move */
  47. void move(INT32 left, INT32 top) override;
  48. /** @copydoc RenderWindowCore::resize */
  49. void resize(UINT32 width, UINT32 height) override;
  50. /** @copydoc RenderWindowCore::getCustomAttribute */
  51. void getCustomAttribute(const String& name, void* pData) const override;
  52. /** @copydoc RenderWindowCore::copyContentsToMemory */
  53. void copyToMemory(PixelData &dst, FrameBuffer buffer);
  54. /** @copydoc RenderWindowCore::swapBuffers */
  55. void swapBuffers() override;
  56. /** @copydoc RenderWindowCore::_windowMovedOrResized */
  57. void _windowMovedOrResized() override;
  58. /** Gets internal Win32 window handle. */
  59. HWND _getWindowHandle() const;
  60. /** Gets the DirectX 9 device object that manages this window. */
  61. IDirect3DDevice9* _getD3D9Device() const;
  62. /** Gets the device that manages this window. */
  63. D3D9Device* _getDevice() const;
  64. /** Sets the device that manages this window. */
  65. void _setDevice(D3D9Device* device);
  66. /** Build the presentation parameters used with this window. */
  67. void _buildPresentParameters(D3DPRESENT_PARAMETERS* presentParams) const;
  68. /** Accessor for render surface. */
  69. IDirect3DSurface9* _getRenderSurface() const;
  70. /** Returns true if this window use depth buffer. */
  71. bool _isDepthBuffered() const;
  72. /** Validate the device for this window. */
  73. bool _validateDevice();
  74. protected:
  75. friend class D3D9RenderWindow;
  76. /** @copydoc CoreObjectCore::initialize */
  77. virtual void initialize() override;
  78. /** @copydoc RenderWindowCore::getProperties */
  79. const RenderTargetProperties& getPropertiesInternal() const override { return mProperties; }
  80. /** @copydoc RenderWindowCore::getSyncedProperties */
  81. RenderWindowProperties& getSyncedProperties() override { return mSyncedProperties; }
  82. /** @copydoc RenderWindowCore::syncProperties */
  83. void syncProperties() override;
  84. protected:
  85. Win32Window* mWindow;
  86. HINSTANCE mInstance;
  87. D3D9Device* mDevice;
  88. bool mDeviceValid;
  89. D3DMULTISAMPLE_TYPE mMultisampleType;
  90. DWORD mMultisampleQuality;
  91. UINT mDisplayFrequency;
  92. unsigned int mVSyncInterval;
  93. bool mIsDepthBuffered;
  94. bool mIsChild;
  95. bool mShowOnSwap;
  96. D3D9RenderWindowProperties mProperties;
  97. D3D9RenderWindowProperties mSyncedProperties;
  98. };
  99. /**
  100. * Render window implementation for Windows.
  101. *
  102. * @note Sim thread only.
  103. */
  104. class BS_D3D9_EXPORT D3D9RenderWindow : public RenderWindow
  105. {
  106. public:
  107. ~D3D9RenderWindow() { }
  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<D3D9RenderWindowCore> getCore() const;
  116. protected:
  117. friend class D3D9RenderWindowManager;
  118. friend class D3D9RenderWindowCore;
  119. D3D9RenderWindow(const RENDER_WINDOW_DESC& desc, UINT32 windowId, HINSTANCE instance);
  120. /** @copydoc RenderWindowCore::getProperties */
  121. const RenderTargetProperties& getPropertiesInternal() const override { return mProperties; }
  122. /** @copydoc RenderWindow::syncProperties */
  123. void syncProperties() override;
  124. /** Retrieves internal window handle. */
  125. HWND getHWnd() const;
  126. private:
  127. HINSTANCE mInstance;
  128. D3D9RenderWindowProperties mProperties;
  129. };
  130. }