Browse Source

Fixed OpenGL monitor enumeration

Marko Pintera 11 years ago
parent
commit
23cd5f1fa7

+ 22 - 0
BansheeEditor/Source/DbgEditorWidget2.cpp

@@ -20,8 +20,29 @@
 #include "BsGUISpace.h"
 #include "CmHString.h"
 
+#include "CmCoreThread.h"
+#include "CmApplication.h"
+
 namespace BansheeEngine
 {
+	bool cm_dbg_fullscreen = false;
+
+	void toggleFullscreen()
+	{
+		if (cm_dbg_fullscreen)
+		{
+			gCoreAccessor().setWindowed(gApplication().getPrimaryWindow());
+		}
+		else
+		{
+			//gCoreAccessor().setFullscreen(window, *videoMode);
+			gCoreAccessor().setFullscreen(gApplication().getPrimaryWindow(), 1680, 1050, 60, 0);
+		}
+
+		cm_dbg_fullscreen = !cm_dbg_fullscreen;
+	}
+
+
 	DbgEditorWidget2* DbgEditorWidget2::Instance = nullptr;
 
 	DbgEditorWidget2::DbgEditorWidget2(const ConstructPrivately& dummy, EditorWidgetContainer& parentContainer)
@@ -42,6 +63,7 @@ namespace BansheeEngine
 		colorField->setValue(Color::Red);
 
 		GUIButton* button = GUIButton::create(HString(L"Testing"), GUIOptions(GUIOption::fixedWidth(100)));
+		button->onClick.connect(&toggleFullscreen);
 
 		layout.addElement(intField);
 		layout.addElement(floatField);

+ 1 - 1
BansheeEditorExec/BsEditorExec.cpp

@@ -11,7 +11,7 @@ int CALLBACK WinMain(
 	_In_  int nCmdShow
 	)
 {
-	EditorApplication::startUp(RenderSystemPlugin::DX11);
+	EditorApplication::startUp(RenderSystemPlugin::OpenGL);
 	EditorApplication::instance().runMainLoop();
 	EditorApplication::shutDown();
 

+ 17 - 19
CamelotD3D9Renderer/Source/CmD3D9RenderWindow.cpp

@@ -586,8 +586,7 @@ namespace BansheeEngine
 		ZeroMemory( presentParams, sizeof(D3DPRESENT_PARAMETERS) );
 		presentParams->Windowed					= !mIsFullScreen;
 		presentParams->SwapEffect				= D3DSWAPEFFECT_DISCARD;
-		// triple buffer if VSync is on
-		presentParams->BackBufferCount			= mVSync ? 2 : 1;
+		presentParams->BackBufferCount			= 1;
 		presentParams->EnableAutoDepthStencil	= mIsDepthBuffered;
 		presentParams->hDeviceWindow			= mHWnd;
 		presentParams->BackBufferWidth			= mWidth;
@@ -640,43 +639,42 @@ namespace BansheeEngine
 			presentParams->PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
 		}
 
-		presentParams->BackBufferFormat		= D3DFMT_R5G6B5;
-		if( mColorDepth > 16 )
+		presentParams->BackBufferFormat	= D3DFMT_R5G6B5;
+		if(mColorDepth > 16)
 			presentParams->BackBufferFormat = D3DFMT_X8R8G8B8;
 
-		if (mColorDepth > 16 )
+		if (mColorDepth > 16)
 		{
-			// Try to create a 32-bit depth, 8-bit stencil
-			if( FAILED( pD3D->CheckDeviceFormat(mDevice->getAdapterNumber(),
+			if(FAILED( pD3D->CheckDeviceFormat(mDevice->getAdapterNumber(),
 				devType,  presentParams->BackBufferFormat,  D3DUSAGE_DEPTHSTENCIL, 
-				D3DRTYPE_SURFACE, D3DFMT_D24S8 )))
+				D3DRTYPE_SURFACE, D3DFMT_D24S8)))
 			{
-				// Bugger, no 8-bit hardware stencil, just try 32-bit zbuffer 
-				if( FAILED( pD3D->CheckDeviceFormat(mDevice->getAdapterNumber(),
+				if(FAILED( pD3D->CheckDeviceFormat(mDevice->getAdapterNumber(),
 					devType,  presentParams->BackBufferFormat,  D3DUSAGE_DEPTHSTENCIL, 
-					D3DRTYPE_SURFACE, D3DFMT_D32 )))
+					D3DRTYPE_SURFACE, D3DFMT_D32)))
 				{
-					// Jeez, what a naff card. Fall back on 16-bit depth buffering
 					presentParams->AutoDepthStencilFormat = D3DFMT_D16;
 				}
 				else
+				{
 					presentParams->AutoDepthStencilFormat = D3DFMT_D32;
+				}
 			}
 			else
 			{
-				// Woohoo!
-				if( SUCCEEDED( pD3D->CheckDepthStencilMatch( mDevice->getAdapterNumber(), devType,
-					presentParams->BackBufferFormat, presentParams->BackBufferFormat, D3DFMT_D24S8 ) ) )
+				if(SUCCEEDED( pD3D->CheckDepthStencilMatch( mDevice->getAdapterNumber(), devType,
+				presentParams->BackBufferFormat, presentParams->BackBufferFormat, D3DFMT_D24S8)))
 				{
 					presentParams->AutoDepthStencilFormat = D3DFMT_D24S8; 
 				} 
-				else 
-					presentParams->AutoDepthStencilFormat = D3DFMT_D24X8; 
+				else
+				{
+					presentParams->AutoDepthStencilFormat = D3DFMT_D24X8;
+				}
 			}
 		}
 		else
-			// 16-bit depth, software stencil
-			presentParams->AutoDepthStencilFormat	= D3DFMT_D16;
+			presentParams->AutoDepthStencilFormat = D3DFMT_D16;
 
 		D3D9RenderSystem* rsys = static_cast<D3D9RenderSystem*>(BansheeEngine::RenderSystem::instancePtr());
 

+ 1 - 1
CamelotGLRenderer/Include/CmWin32VideoModeInfo.h

@@ -23,7 +23,7 @@ namespace BansheeEngine
 	class CM_RSGL_EXPORT Win32VideoOutputInfo : public VideoOutputInfo
 	{
 	public:
-		Win32VideoOutputInfo(char* deviceName);
+		Win32VideoOutputInfo(HMONITOR monitorHandle);
 		~Win32VideoOutputInfo();
 
 		/**

+ 18 - 27
CamelotGLRenderer/Source/CmWin32VideoModeInfo.cpp

@@ -4,45 +4,36 @@
 
 namespace BansheeEngine
 {
-	Win32VideoModeInfo::Win32VideoModeInfo()
+	BOOL CALLBACK monitorEnumCallback(HMONITOR hMonitor, HDC hdc, LPRECT rect, LPARAM lParam)
 	{
-		DISPLAY_DEVICE displayDevice;
-		memset(&displayDevice, 0, sizeof(DISPLAY_DEVICE));
-		displayDevice.cb = sizeof(DISPLAY_DEVICE);
+		Vector<VideoOutputInfo*>* outputInfos = (Vector<VideoOutputInfo*>*)lParam;
+		outputInfos->push_back(cm_new<Win32VideoOutputInfo>(hMonitor));
 
-		UINT32 i = 0;
-		while (EnumDisplayDevices(nullptr, i++, &displayDevice, 0))
-		{
-			if ((displayDevice.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) == 0)
-				continue;
+		return TRUE;
+	};
 
-			mOutputs.push_back(cm_new<Win32VideoOutputInfo>(displayDevice.DeviceName));
-		}
+	Win32VideoModeInfo::Win32VideoModeInfo()
+	{
+		EnumDisplayMonitors(0, nullptr, &monitorEnumCallback, (LPARAM)&mOutputs);
 	}
 
-	Win32VideoOutputInfo::Win32VideoOutputInfo(char* deviceName)
-		:mMonitorHandle(0)
+	Win32VideoOutputInfo::Win32VideoOutputInfo(HMONITOR monitorHandle)
+		:mMonitorHandle(monitorHandle)
 	{
-		mName = deviceName;
+		MONITORINFOEX monitorInfo;
 
-		DISPLAY_DEVICE displayDevice;
-		displayDevice.cb = sizeof(DISPLAY_DEVICE);
+		memset(&monitorInfo, 0, sizeof(MONITORINFOEX));
+		monitorInfo.cbSize = sizeof(MONITORINFOEX);
+		GetMonitorInfo(mMonitorHandle, &monitorInfo);
 
-		UINT32 i = 0;
-		while (EnumDisplayDevices(deviceName, i++, &displayDevice, EDD_GET_DEVICE_INTERFACE_NAME))
-		{
-			if (displayDevice.StateFlags & DISPLAY_DEVICE_ACTIVE)
-			{
-				mMonitorHandle = (HMONITOR)CreateFile(displayDevice.DeviceID, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
-			}
-		}
+		mName = monitorInfo.szDevice;
 
 		DEVMODE devMode;
 		devMode.dmSize = sizeof(DEVMODE);
 		devMode.dmDriverExtra = 0;
 
-		i = 0;
-		while (EnumDisplaySettings(deviceName, i++, &devMode))
+		UINT32 i = 0;
+		while (EnumDisplaySettings(monitorInfo.szDevice, i++, &devMode))
 		{
 			bool foundVideoMode = false;
 			for (auto videoMode : mVideoModes)
@@ -83,7 +74,7 @@ namespace BansheeEngine
 		}
 
 		// Get desktop display mode
-		EnumDisplaySettings(deviceName, ENUM_CURRENT_SETTINGS, &devMode);
+		EnumDisplaySettings(monitorInfo.szDevice, ENUM_CURRENT_SETTINGS, &devMode);
 
 		Win32VideoMode* desktopVideoMode = cm_new<Win32VideoMode>(devMode.dmPelsWidth, devMode.dmPelsHeight, this);
 		desktopVideoMode->mRefreshRates.push_back((float)devMode.dmDisplayFrequency);

+ 10 - 9
CamelotGLRenderer/Source/CmWin32Window.cpp

@@ -51,7 +51,8 @@ namespace BansheeEngine
 		mHWnd = 0;
 		mName = mDesc.title;
 		mIsFullScreen = mDesc.fullscreen;
-		mClosed = false;		
+		mClosed = false;
+		mIsChild = false;
 		mDisplayFrequency = mDesc.displayFrequency;
 		mColorDepth = mDesc.colorDepth;
 		HWND parent = 0;
@@ -385,21 +386,21 @@ namespace BansheeEngine
 		displayDeviceMode.dmDisplayFrequency = mDisplayFrequency;
 		displayDeviceMode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY;
 
+		HMONITOR hMonitor = outputInfo.getMonitorHandle();
+		MONITORINFOEX monitorInfo;
+
+		memset(&monitorInfo, 0, sizeof(MONITORINFOEX));
+		monitorInfo.cbSize = sizeof(MONITORINFOEX);
+		GetMonitorInfo(hMonitor, &monitorInfo);
+
 		// Move window to 0,0 before display switch
 		SetWindowPos(mHWnd, HWND_TOPMOST, 0, 0, mWidth, mHeight, SWP_NOACTIVATE);
 
-		if (ChangeDisplaySettingsEx(mDeviceName, &displayDeviceMode, NULL, CDS_FULLSCREEN, NULL) != DISP_CHANGE_SUCCESSFUL)
+		if (ChangeDisplaySettingsEx(monitorInfo.szDevice, &displayDeviceMode, NULL, CDS_FULLSCREEN, NULL) != DISP_CHANGE_SUCCESSFUL)
 		{
 			CM_EXCEPT(RenderingAPIException, "ChangeDisplaySettings failed");
 		}
 
-		HMONITOR hMonitor = outputInfo.getMonitorHandle();
-		MONITORINFO monitorInfo;
-
-		memset(&monitorInfo, 0, sizeof(MONITORINFO));
-		monitorInfo.cbSize = sizeof(MONITORINFO);
-		GetMonitorInfo(hMonitor, &monitorInfo);
-
 		mTop = monitorInfo.rcMonitor.top;
 		mLeft = monitorInfo.rcMonitor.left;
 		mWidth = width;

+ 9 - 0
Polish.txt

@@ -24,7 +24,16 @@ When initializing a render window I don't have an option to use exact refresh ra
 ChangeDisplaySettingEx - For actually changing resolution and refresh rate
  - http://msdn.microsoft.com/en-us/library/windows/desktop/dd183413(v=vs.85).aspx
 
+ Add ability to change FSAA on RenderWindow.
+  - Maybe later. OpenGL requires window to be re-created for it to change I think. As SetPixelFormat is allowed to be called just once per window
 
+Add a better way of specifying FSAA (and don't call it FSAA because it's multisampling)
+ - fsaaHint is useless in most cases. Add an Enum instead.
+
+I should be able to specify resolution when going to windowed mode
+ - Maybe just store the windowed and fullscreen resolutions separately and restore automatically?
+
+OpenGL going back from windowed mode doesn't restore window style properly.
 
  -----------------------------