2
0
Эх сурвалжийг харах

Populating VideoModeInfo for Vulkan

BearishSun 9 жил өмнө
parent
commit
8f6a5f169e

+ 2 - 2
Source/BansheeGLRenderAPI/Include/Win32/BsWin32GLSupport.h

@@ -19,10 +19,10 @@ namespace BansheeEngine
         Win32GLSupport();
         Win32GLSupport();
 
 
 		/** @copydoc GLSupport::newWindow */
 		/** @copydoc GLSupport::newWindow */
-		virtual SPtr<RenderWindow> newWindow(RENDER_WINDOW_DESC& desc, UINT32 windowId, SPtr<RenderWindow> parentWindow) override;
+		SPtr<RenderWindow> newWindow(RENDER_WINDOW_DESC& desc, UINT32 windowId, SPtr<RenderWindow> parentWindow) override;
 
 
 		/** @copydoc GLSupport::newWindowCore */
 		/** @copydoc GLSupport::newWindowCore */
-		virtual SPtr<RenderWindowCore> newWindowCore(RENDER_WINDOW_DESC& desc, UINT32 windowId) override;
+		SPtr<RenderWindowCore> newWindowCore(RENDER_WINDOW_DESC& desc, UINT32 windowId) override;
 
 
 		/** @copydoc GLSupport::start */
 		/** @copydoc GLSupport::start */
 		void start() override;
 		void start() override;

+ 0 - 1
Source/BansheeGLRenderAPI/Source/Win32/BsWin32VideoModeInfo.cpp

@@ -2,7 +2,6 @@
 //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
 //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
 #include "Win32/BsWin32VideoModeInfo.h"
 #include "Win32/BsWin32VideoModeInfo.h"
 #include "BsMath.h"
 #include "BsMath.h"
-#include "BsException.h"
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {

+ 8 - 3
Source/BansheeVulkanRenderAPI/Include/Win32/BsWin32VideoModeInfo.h

@@ -18,15 +18,20 @@ namespace BansheeEngine
 		Win32VideoMode(UINT32 width, UINT32 height, float refreshRate, UINT32 outputIdx);
 		Win32VideoMode(UINT32 width, UINT32 height, float refreshRate, UINT32 outputIdx);
 
 
 	private:
 	private:
-		friend class VulkanVideoOutputInfo;
+		friend class Win32VideoOutputInfo;
 	};
 	};
 
 
 	/** @copydoc VideoOutputInfo */
 	/** @copydoc VideoOutputInfo */
 	class Win32VideoOutputInfo : public VideoOutputInfo
 	class Win32VideoOutputInfo : public VideoOutputInfo
 	{
 	{
 	public:
 	public:
-		Win32VideoOutputInfo(UINT32 outputIdx);
-		~Win32VideoOutputInfo();
+		Win32VideoOutputInfo(HMONITOR monitorHandle, UINT32 outputIdx);
+
+		/**	Gets a Win32 handle to the monitor referenced by this object. */
+		HMONITOR getMonitorHandle() const { return mMonitorHandle; }
+
+	private:
+		HMONITOR mMonitorHandle;
 	};
 	};
 
 
 	/** @copydoc VideoModeInfo */
 	/** @copydoc VideoModeInfo */

+ 7 - 1
Source/BansheeVulkanRenderAPI/Source/BsVulkanRenderAPI.cpp

@@ -12,6 +12,7 @@
 #include "BsGpuProgramManager.h"
 #include "BsGpuProgramManager.h"
 #include "BsVulkanQueryManager.h"
 #include "BsVulkanQueryManager.h"
 #include "BsVulkanGLSLProgramFactory.h"
 #include "BsVulkanGLSLProgramFactory.h"
+#include "Win32/BsWin32VideoModeInfo.h"
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
@@ -205,7 +206,12 @@ namespace BansheeEngine
 		RenderStateCoreManager::startUp<VulkanRenderStateCoreManager>();
 		RenderStateCoreManager::startUp<VulkanRenderStateCoreManager>();
 		GpuProgramCoreManager::instance().addFactory(mGLSLFactory);
 		GpuProgramCoreManager::instance().addFactory(mGLSLFactory);
 
 
-		// TODO - Create and populate VideoModeInfo
+#if BS_PLATFORM == BS_PLATFORM_WIN32
+		mVideoModeInfo = bs_shared_ptr_new<Win32VideoModeInfo>();
+#else
+		static_assert(false, "mVideoModeInfo needs to be created.")
+#endif
+
 		// TODO - Create and populate capabilities, per device
 		// TODO - Create and populate capabilities, per device
 		mCurrentCapabilities->addShaderProfile("glsl");
 		mCurrentCapabilities->addShaderProfile("glsl");
 
 

+ 85 - 6
Source/BansheeVulkanRenderAPI/Source/Win32/BsWin32VideoModeInfo.cpp

@@ -1,23 +1,102 @@
 //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
 //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
 //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
 //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
 #include "Win32/BsWin32VideoModeInfo.h"
 #include "Win32/BsWin32VideoModeInfo.h"
-#include "BsException.h"
+#include "BsMath.h"
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
-	Win32VideoModeInfo::Win32VideoModeInfo()
+	BOOL CALLBACK monitorEnumCallback(HMONITOR hMonitor, HDC hdc, LPRECT rect, LPARAM lParam)
 	{
 	{
+		Vector<HMONITOR>* outputInfos = (Vector<HMONITOR>*)lParam;
+		outputInfos->push_back(hMonitor);
 
 
-	}
+		return TRUE;
+	};
 
 
-	Win32VideoOutputInfo::Win32VideoOutputInfo( UINT32 outputIdx)
+	Win32VideoModeInfo::Win32VideoModeInfo()
 	{
 	{
-		
+		Vector<HMONITOR> handles;
+		EnumDisplayMonitors(0, nullptr, &monitorEnumCallback, (LPARAM)&handles);
+
+		// Sort so that primary is the first output
+		for (auto iter = handles.begin(); iter != handles.end(); ++iter)
+		{
+			MONITORINFOEX monitorInfo;
+
+			memset(&monitorInfo, 0, sizeof(MONITORINFOEX));
+			monitorInfo.cbSize = sizeof(MONITORINFOEX);
+			GetMonitorInfo(*iter, &monitorInfo);
+
+			if ((monitorInfo.dwFlags & MONITORINFOF_PRIMARY) != 0)
+			{
+				if (iter != handles.begin())
+				{
+					HMONITOR temp = handles[0];
+					handles[0] = *iter;
+					*iter = temp;
+				}
+
+				break;
+			}
+		}
+
+		UINT32 idx = 0;
+		for (auto& handle : handles)
+		{
+			mOutputs.push_back(bs_new<Win32VideoOutputInfo>(handle, idx++));
+		}
 	}
 	}
 
 
-	Win32VideoOutputInfo::~Win32VideoOutputInfo()
+	Win32VideoOutputInfo::Win32VideoOutputInfo(HMONITOR monitorHandle, UINT32 outputIdx)
+		:mMonitorHandle(monitorHandle)
 	{
 	{
+		MONITORINFOEX monitorInfo;
+
+		memset(&monitorInfo, 0, sizeof(MONITORINFOEX));
+		monitorInfo.cbSize = sizeof(MONITORINFOEX);
+		GetMonitorInfo(mMonitorHandle, &monitorInfo);
+
+		mName = monitorInfo.szDevice;
+
+		DEVMODE devMode;
+		devMode.dmSize = sizeof(DEVMODE);
+		devMode.dmDriverExtra = 0;
+
+		UINT32 i = 0;
+		while (EnumDisplaySettings(monitorInfo.szDevice, i++, &devMode))
+		{
+			bool foundVideoMode = false;
+			for (auto videoMode : mVideoModes)
+			{
+				Win32VideoMode* win32VideoMode = static_cast<Win32VideoMode*>(videoMode);
+
+				UINT32 intRefresh = Math::roundToInt(win32VideoMode->mRefreshRate);
+				if (win32VideoMode->mWidth == devMode.dmPelsWidth && win32VideoMode->mHeight == devMode.dmPelsHeight
+					&& intRefresh == devMode.dmDisplayFrequency)
+				{
+					foundVideoMode = true;
+					break;
+				}
+			}
+
+			if (!foundVideoMode)
+			{
+				Win32VideoMode* videoMode = bs_new<Win32VideoMode>(devMode.dmPelsWidth, devMode.dmPelsHeight,
+					(float)devMode.dmDisplayFrequency, outputIdx);
+				videoMode->mIsCustom = false;
+
+				mVideoModes.push_back(videoMode);
+			}
+		}
+
+		// Get desktop display mode
+		EnumDisplaySettings(monitorInfo.szDevice, ENUM_CURRENT_SETTINGS, &devMode);
+
+		Win32VideoMode* desktopVideoMode = bs_new<Win32VideoMode>(devMode.dmPelsWidth, devMode.dmPelsHeight,
+			(float)devMode.dmDisplayFrequency, outputIdx);
+		desktopVideoMode->mIsCustom = false;
 
 
+		mDesktopVideoMode = desktopVideoMode;
 	}
 	}
 
 
 	Win32VideoMode::Win32VideoMode(UINT32 width, UINT32 height, float refreshRate, UINT32 outputIdx)
 	Win32VideoMode::Win32VideoMode(UINT32 width, UINT32 height, float refreshRate, UINT32 outputIdx)