Răsfoiți Sursa

Linux port:
- Getting Windows code back running after Linux related changes

BearishSun 8 ani în urmă
părinte
comite
f18318ad59

+ 14 - 0
Source/BansheeD3D11RenderAPI/BsD3D11RenderWindow.cpp

@@ -450,6 +450,20 @@ namespace bs
 		bs::RenderWindowManager::instance().notifyMovedOrResized(this);
 		bs::RenderWindowManager::instance().notifyMovedOrResized(this);
 	}
 	}
 
 
+	void D3D11RenderWindow::setVSync(bool enabled, UINT32 interval)
+	{
+		mProperties.vsync = enabled;
+		mProperties.vsyncInterval = interval;
+
+		{
+			ScopedSpinLock lock(mLock);
+			mSyncedProperties.vsync = enabled;
+			mSyncedProperties.vsyncInterval = interval;
+		}
+
+		bs::RenderWindowManager::instance().notifySyncDataDirty(this);
+	}
+
 	HWND D3D11RenderWindow::_getWindowHandle() const
 	HWND D3D11RenderWindow::_getWindowHandle() const
 	{
 	{
 		return mWindow->getHWnd();
 		return mWindow->getHWnd();

+ 3 - 0
Source/BansheeD3D11RenderAPI/BsD3D11RenderWindow.h

@@ -99,6 +99,9 @@ namespace bs {
 		/** @copydoc RenderWindow::setWindowed */
 		/** @copydoc RenderWindow::setWindowed */
 		void setWindowed(UINT32 width, UINT32 height) override;
 		void setWindowed(UINT32 width, UINT32 height) override;
 
 
+		/** @copydoc RenderWindow::setVSync */
+		void setVSync(bool enabled, UINT32 interval = 1) override;
+
 		/** 
 		/** 
 		 * Copies the contents of a frame buffer into the pre-allocated buffer. 
 		 * Copies the contents of a frame buffer into the pre-allocated buffer. 
 		 *
 		 *

+ 0 - 1
Source/BansheeEngine/Platform/BsSplashScreen.cpp

@@ -4,7 +4,6 @@
 #include "Resources/BsBuiltinResources.h"
 #include "Resources/BsBuiltinResources.h"
 #include "Utility/BsTimer.h"
 #include "Utility/BsTimer.h"
 #include "CoreThread/BsCoreThread.h"
 #include "CoreThread/BsCoreThread.h"
-#include <X11/Xutil.h>
 
 
 #if BS_PLATFORM == BS_PLATFORM_WIN32
 #if BS_PLATFORM == BS_PLATFORM_WIN32
 #include "Win32/BsWin32Platform.h"
 #include "Win32/BsWin32Platform.h"

+ 11 - 0
Source/BansheeGLRenderAPI/Linux/BsLinuxRenderWindow.cpp

@@ -481,6 +481,17 @@ namespace bs
 			glXSwapIntervalSGI(interval);
 			glXSwapIntervalSGI(interval);
 
 
 		LinuxPlatform::unlockX();
 		LinuxPlatform::unlockX();
+		
+		mProperties.vsync = enabled;
+		mProperties.vsyncInterval = interval;
+
+		{
+			ScopedSpinLock lock(mLock);
+			mSyncedProperties.vsync = enabled;
+			mSyncedProperties.vsyncInterval = interval;
+		}
+
+		bs::RenderWindowManager::instance().notifySyncDataDirty(this);		
 	}
 	}
 
 
 	void LinuxRenderWindow::swapBuffers(UINT32 syncMask)
 	void LinuxRenderWindow::swapBuffers(UINT32 syncMask)

+ 23 - 23
Source/BansheeGLRenderAPI/Win32/BsWin32GLSupport.cpp

@@ -22,11 +22,11 @@ namespace bs { namespace ct
 	}
 	}
 
 
 	Win32GLSupport::Win32GLSupport()
 	Win32GLSupport::Win32GLSupport()
-        : mInitialWindow(nullptr), mHasPixelFormatARB(false), mHasMultisample(false), 
+		: mInitialWindow(nullptr), mHasPixelFormatARB(false), mHasMultisample(false), 
 		mHasHardwareGamma(false), mHasAdvancedContext(false)
 		mHasHardwareGamma(false), mHasAdvancedContext(false)
-    {
+	{
 		initialiseWGL();
 		initialiseWGL();
-    } 
+	} 
 
 
 	SPtr<bs::RenderWindow> Win32GLSupport::newWindow(RENDER_WINDOW_DESC& desc, UINT32 windowId, SPtr<bs::RenderWindow> parentWindow)
 	SPtr<bs::RenderWindow> Win32GLSupport::newWindow(RENDER_WINDOW_DESC& desc, UINT32 windowId, SPtr<bs::RenderWindow> parentWindow)
 	{		
 	{		
@@ -77,12 +77,12 @@ namespace bs { namespace ct
 
 
 		// Parse them, and add them to the main list
 		// Parse them, and add them to the main list
 		StringStream ext;
 		StringStream ext;
-        String instr;
+		String instr;
 		ext << wgl_extensions;
 		ext << wgl_extensions;
-        while(ext >> instr)
-        {
-            extensionList.insert(instr);
-        }
+		while(ext >> instr)
+		{
+			extensionList.insert(instr);
+		}
 	}
 	}
 
 
 	SPtr<Win32Context> Win32GLSupport::createContext(HDC hdc, HGLRC externalGlrc)
 	SPtr<Win32Context> Win32GLSupport::createContext(HDC hdc, HGLRC externalGlrc)
@@ -136,7 +136,7 @@ namespace bs { namespace ct
 
 
 	void* Win32GLSupport::getProcAddress(const String& procname)
 	void* Win32GLSupport::getProcAddress(const String& procname)
 	{
 	{
-        return (void*)wglGetProcAddress(procname.c_str());
+		return (void*)wglGetProcAddress(procname.c_str());
 	}
 	}
 
 
 	void Win32GLSupport::initialiseWGL()
 	void Win32GLSupport::initialiseWGL()
@@ -232,22 +232,22 @@ namespace bs { namespace ct
 
 
 				int formats[256];
 				int formats[256];
 				unsigned int count;
 				unsigned int count;
-                WGLEW_GET_FUN(__wglewChoosePixelFormatARB) = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
+				WGLEW_GET_FUN(__wglewChoosePixelFormatARB) = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
 				PFNWGLGETPIXELFORMATATTRIBIVARBPROC _wglGetPixelFormatAttribivARB = 
 				PFNWGLGETPIXELFORMATATTRIBIVARBPROC _wglGetPixelFormatAttribivARB = 
 					(PFNWGLGETPIXELFORMATATTRIBIVARBPROC)wglGetProcAddress("wglGetPixelFormatAttribivARB");
 					(PFNWGLGETPIXELFORMATATTRIBIVARBPROC)wglGetProcAddress("wglGetPixelFormatAttribivARB");
-                if (WGLEW_GET_FUN(__wglewChoosePixelFormatARB)(hdc, iattr, 0, 256, formats, &count))
-                {
-                    // determine what multisampling levels are offered
-                    int query = WGL_SAMPLES_ARB, samples;
-                    for (unsigned int i = 0; i < count; ++i)
-                    {
-                        if (_wglGetPixelFormatAttribivARB(hdc, formats[i], 0, 1, &query, &samples))
-                        {
-                            mMultisampleLevels.push_back(samples);
-                        }
-                    }
-                    remove_duplicates(mMultisampleLevels);
-                }
+				if (WGLEW_GET_FUN(__wglewChoosePixelFormatARB)(hdc, iattr, 0, 256, formats, &count))
+				{
+					// determine what multisampling levels are offered
+					int query = WGL_SAMPLES_ARB, samples;
+					for (unsigned int i = 0; i < count; ++i)
+					{
+						if (_wglGetPixelFormatAttribivARB(hdc, formats[i], 0, 1, &query, &samples))
+						{
+							mMultisampleLevels.push_back(samples);
+						}
+					}
+					remove_duplicates(mMultisampleLevels);
+				}
 			}
 			}
 			
 			
 			wglMakeCurrent(oldhdc, oldrc);
 			wglMakeCurrent(oldhdc, oldrc);

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

@@ -16,7 +16,7 @@ namespace bs { namespace ct
 	class Win32GLSupport : public GLSupport
 	class Win32GLSupport : public GLSupport
 	{
 	{
 	public:
 	public:
-        Win32GLSupport();
+		Win32GLSupport();
 
 
 		/** @copydoc GLSupport::newWindow */
 		/** @copydoc GLSupport::newWindow */
 		SPtr<bs::RenderWindow> newWindow(RENDER_WINDOW_DESC& desc, UINT32 windowId, SPtr<bs::RenderWindow> parentWindow) override;
 		SPtr<bs::RenderWindow> newWindow(RENDER_WINDOW_DESC& desc, UINT32 windowId, SPtr<bs::RenderWindow> parentWindow) override;
@@ -72,7 +72,7 @@ namespace bs { namespace ct
 		Win32RenderWindow *mInitialWindow;
 		Win32RenderWindow *mInitialWindow;
 		Vector<int> mMultisampleLevels;
 		Vector<int> mMultisampleLevels;
 		bool mHasPixelFormatARB;
 		bool mHasPixelFormatARB;
-        bool mHasMultisample;
+		bool mHasMultisample;
 		bool mHasHardwareGamma;
 		bool mHasHardwareGamma;
 		bool mHasAdvancedContext;
 		bool mHasAdvancedContext;
 	};
 	};

+ 19 - 0
Source/BansheeGLRenderAPI/Win32/BsWin32RenderWindow.cpp

@@ -250,6 +250,9 @@ namespace bs
 
 
 		mContext = mGLSupport.createContext(mHDC, nullptr);
 		mContext = mGLSupport.createContext(mHDC, nullptr);
 
 
+		if (props.vsync && props.vsyncInterval > 0)
+			setVSync(true, props.vsyncInterval);
+
 		{
 		{
 			ScopedSpinLock lock(mLock);
 			ScopedSpinLock lock(mLock);
 			mSyncedProperties = props;
 			mSyncedProperties = props;
@@ -440,6 +443,22 @@ namespace bs
 		mWindow->restore();
 		mWindow->restore();
 	}
 	}
 
 
+	void Win32RenderWindow::setVSync(bool enabled, UINT32 interval)
+	{
+		wglSwapIntervalEXT(interval);
+
+		mProperties.vsync = enabled;
+		mProperties.vsyncInterval = interval;
+
+		{
+			ScopedSpinLock lock(mLock);
+			mSyncedProperties.vsync = enabled;
+			mSyncedProperties.vsyncInterval = interval;
+		}
+
+		bs::RenderWindowManager::instance().notifySyncDataDirty(this);
+	}
+
 	void Win32RenderWindow::swapBuffers(UINT32 syncMask)
 	void Win32RenderWindow::swapBuffers(UINT32 syncMask)
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;

+ 3 - 0
Source/BansheeGLRenderAPI/Win32/BsWin32RenderWindow.h

@@ -94,6 +94,9 @@ namespace bs
 		/** @copydoc RenderWindow::resize */
 		/** @copydoc RenderWindow::resize */
 		void resize(UINT32 width, UINT32 height) override;
 		void resize(UINT32 width, UINT32 height) override;
 
 
+		/** @copydoc RenderWindow::setVSync */
+		void setVSync(bool enabled, UINT32 interval = 1) override;
+
 		/** 
 		/** 
 		 * Copies the contents of a frame buffer into the pre-allocated buffer. 
 		 * Copies the contents of a frame buffer into the pre-allocated buffer. 
 		 *
 		 *

+ 27 - 5
Source/BansheeVulkanRenderAPI/Win32/BsWin32RenderWindow.cpp

@@ -22,11 +22,6 @@ namespace bs
 		: RenderWindow(desc, windowId), mProperties(desc)
 		: RenderWindow(desc, windowId), mProperties(desc)
 	{ }
 	{ }
 
 
-	Win32RenderWindow::~Win32RenderWindow()
-	{
-		Platform::resetNonClientAreas(*this);
-	}
-
 	void Win32RenderWindow::getCustomAttribute(const String& name, void* pData) const
 	void Win32RenderWindow::getCustomAttribute(const String& name, void* pData) const
 	{
 	{
 		if (name == "WINDOW")
 		if (name == "WINDOW")
@@ -94,6 +89,8 @@ namespace bs
 
 
 		mSwapChain = nullptr;
 		mSwapChain = nullptr;
 		vkDestroySurfaceKHR(mRenderAPI._getInstance(), mSurface, gVulkanAllocator);
 		vkDestroySurfaceKHR(mRenderAPI._getInstance(), mSurface, gVulkanAllocator);
+
+		Platform::resetNonClientAreas(*this);
 	}
 	}
 
 
 	void Win32RenderWindow::initialize()
 	void Win32RenderWindow::initialize()
@@ -577,6 +574,31 @@ namespace bs
 		bs::RenderWindowManager::instance().notifySyncDataDirty(this);
 		bs::RenderWindowManager::instance().notifySyncDataDirty(this);
 	}
 	}
 
 
+	void Win32RenderWindow::setVSync(bool enabled, UINT32 interval)
+	{
+		// Rebuild swap chain
+		
+		//// Need to make sure nothing is using the swap buffer before we re-create it
+		// Note: Optionally I can detect exactly on which queues (if any) are the swap chain images used on, and only wait
+		// on those
+		SPtr<VulkanDevice> presentDevice = mRenderAPI._getPresentDevice();
+		presentDevice->waitIdle();
+
+		mSwapChain->rebuild(presentDevice, mSurface, mProperties.width, mProperties.height, enabled, mColorFormat, mColorSpace, 
+			mDesc.depthBuffer, mDepthFormat);
+
+		mProperties.vsync = enabled;
+		mProperties.vsyncInterval = interval;
+
+		{
+			ScopedSpinLock lock(mLock);
+			mSyncedProperties.vsync = enabled;
+			mSyncedProperties.vsyncInterval = interval;
+		}
+
+		bs::RenderWindowManager::instance().notifySyncDataDirty(this);
+	}
+
 	HWND Win32RenderWindow::_getWindowHandle() const
 	HWND Win32RenderWindow::_getWindowHandle() const
 	{
 	{
 		return mWindow->getHWnd();
 		return mWindow->getHWnd();

+ 4 - 1
Source/BansheeVulkanRenderAPI/Win32/BsWin32RenderWindow.h

@@ -19,7 +19,7 @@ namespace bs
 	class Win32RenderWindow : public RenderWindow
 	class Win32RenderWindow : public RenderWindow
 	{
 	{
 	public:
 	public:
-		~Win32RenderWindow();
+		~Win32RenderWindow() { }
 
 
 		/** @copydoc RenderWindow::screenToWindowPos */
 		/** @copydoc RenderWindow::screenToWindowPos */
 		void getCustomAttribute(const String& name, void* pData) const override;
 		void getCustomAttribute(const String& name, void* pData) const override;
@@ -94,6 +94,9 @@ namespace bs
 
 
 		/** @copydoc RenderWindow::setWindowed */
 		/** @copydoc RenderWindow::setWindowed */
 		void setWindowed(UINT32 width, UINT32 height) override;
 		void setWindowed(UINT32 width, UINT32 height) override;
+	
+		/** @copydoc RenderWindow::setVSync */
+		void setVSync(bool enabled, UINT32 interval = 1) override;
 
 
 		/** 
 		/** 
 		 * Copies the contents of a frame buffer into the pre-allocated buffer. 
 		 * Copies the contents of a frame buffer into the pre-allocated buffer. 

+ 1 - 1
Source/CMake/Common.cmake

@@ -61,7 +61,7 @@ MACRO(gen_default_lib_search_dirs LIB_NAME)
 ENDMACRO()
 ENDMACRO()
 
 
 MACRO(add_imported_library LIB_NAME RELEASE_NAME DEBUG_NAME IS_SHARED)
 MACRO(add_imported_library LIB_NAME RELEASE_NAME DEBUG_NAME IS_SHARED)
-	if(${IS_SHARED})
+	if(${IS_SHARED} AND NOT WIN32)
 		add_library(${LIB_NAME} SHARED IMPORTED)
 		add_library(${LIB_NAME} SHARED IMPORTED)
 	else()
 	else()
 		add_library(${LIB_NAME} STATIC IMPORTED)
 		add_library(${LIB_NAME} STATIC IMPORTED)