Browse Source

Fixed DX9 and DX11 resize
Fixed an issue with layouts

Marko Pintera 12 years ago
parent
commit
529e59b4de

+ 7 - 2
BansheeEngine/Source/BsGUILayoutX.cpp

@@ -289,15 +289,20 @@ namespace BansheeEngine
 					{
 						const GUILayoutOptions& layoutOptions = child.element->_getLayoutOptions();
 
-						if(layoutOptions.maxWidth > 0 && elementWidth > layoutOptions.maxWidth)
+						if(elementWidth == 0)
+						{
+							processedElements[childIdx] = true;
+							numNonClampedElements--;
+						}
+						else if(layoutOptions.maxWidth > 0 && elementWidth > layoutOptions.maxWidth)
 						{
-							extraWidth = elementSizes[childIdx] - layoutOptions.maxWidth;
 							elementWidth = layoutOptions.maxWidth;
 
 							processedElements[childIdx] = true;
 							numNonClampedElements--;
 						}
 
+						extraWidth = elementWidth - elementSizes[childIdx];
 						elementSizes[childIdx] = elementWidth;
 						remainingSize = (UINT32)std::max(0, (INT32)remainingSize - (INT32)extraWidth);
 					}

+ 1 - 1
BansheeEngine/Source/BsGUILayoutY.cpp

@@ -302,7 +302,7 @@ namespace BansheeEngine
 							numNonClampedElements--;
 						}
 
-						extraHeight = elementSizes[childIdx] - elementHeight;
+						extraHeight = elementHeight - elementSizes[childIdx];
 						elementSizes[childIdx] = elementHeight;
 						remainingSize = (UINT32)std::max(0, (INT32)remainingSize - (INT32)extraHeight);
 					}

+ 7 - 1
BansheeEngine/Source/BsGUIWindowFrame.cpp

@@ -5,6 +5,7 @@
 #include "BsSpriteTexture.h"
 #include "BsGUILayoutOptions.h"
 #include "BsGUIMouseEvent.h"
+#include "CmApplication.h"
 #include "CmCursor.h"
 #include "CmTexture.h"
 #include "CmRenderWindow.h"
@@ -264,7 +265,12 @@ namespace BansheeEngine
 			if(dragAmount.x != 0 || dragAmount.y != 0)
 			{
 				RenderWindow* window = _getParentWidget().getOwnerWindow();
-				window->resize(window->getWidth() + dragAmount.x, window->getHeight() + dragAmount.y);
+
+				UINT32 newWidth = window->getWidth() + dragAmount.x;
+				UINT32 newHeight = window->getHeight() + dragAmount.y;
+
+				RenderWindowPtr windowPtr = std::static_pointer_cast<RenderWindow>(window->getThisPtr());
+				gMainCA().resizeWindow(windowPtr, newWidth, newHeight);
 			}
 		}
 

+ 2 - 2
CamelotClient/CamelotClient.cpp

@@ -30,9 +30,9 @@
 #include "CmRTTIType.h"
 #include "CmCursor.h"
 
-#define DX11
+//#define DX11
 //#define DX9
-//#define GL
+#define GL
 
 using namespace CamelotFramework;
 using namespace BansheeEditor;

+ 2 - 0
CamelotClient/CmEditorWindow.cpp

@@ -94,6 +94,8 @@ namespace BansheeEditor
 		//titleBarBackgroundArea->getLayout().addElement(GUITexture::create(*mGUI, GUIImageScaleMode::RepeatToFit, GUILayoutOptions::expandableXY(), mGUI->getGUISkin()->getStyle("TitleBarBg")));
 		//titleBarBackgroundArea->getLayout().addSpace(1);
 		
+		gMainCA().resizeWindow(mRenderWindow, 400, 300);
+
 		//mRenderWindow->resize(300, 250);
 		//mRenderWindow->setVisible(false);
 	}

+ 5 - 5
CamelotCore/Include/CmCoreObject.h

@@ -93,6 +93,11 @@ o		 *
 			}
 		}
 
+		/**
+		 * @brief	Returns a shared_ptr version of "this" pointer.
+		 */
+		std::shared_ptr<CoreObject> getThisPtr() const { return mThis.lock(); }
+
 	protected:
 		/**
 		 * @brief	Frees all of the objects dynamically allocated memory. All derived classes that have something to free
@@ -110,11 +115,6 @@ o		 *
 		 */
 		virtual void initialize_internal();
 
-		/**
-		 * @brief	Returns a shared_ptr version of "this" pointer.
-		 */
-		std::shared_ptr<CoreObject> getThisPtr() const { return mThis.lock(); }
-
 		static void _deleteDelayedInternal(CoreObject* obj);
 
 		/**

+ 10 - 1
CamelotCore/Include/CmCoreThreadAccessor.h

@@ -204,7 +204,6 @@ namespace CamelotFramework
 			mCommandQueue->queue(boost::bind(&RenderSystem::drawIndexed, RenderSystem::instancePtr(), startIndex, indexCount, vertexCount));
 		}
 
-
 		/**
 		 * @copydoc RenderSystem::writeSubresource()
 		 *
@@ -233,6 +232,16 @@ namespace CamelotFramework
 			return mCommandQueue->queueReturn(boost::bind(&RenderSystem::readSubresource, RenderSystem::instancePtr(), resource, subresourceIdx, boost::ref(data), _1));
 		}
 
+		void resizeWindow(RenderWindowPtr& renderWindow, UINT32 width, UINT32 height)
+		{
+			mCommandQueue->queue(boost::bind(&RenderWindow::resize, renderWindow.get(), width, height));
+		}
+
+		void moveWindow(RenderWindowPtr& renderWindow, INT32 left, INT32 top)
+		{
+			mCommandQueue->queue(boost::bind(&RenderWindow::reposition, renderWindow.get(), left, top));
+		}
+
 		/**
 		 * @brief	Makes all the currently queued commands available to the core thread. They will be executed
 		 * 			as soon as the core thread is ready.

+ 1 - 1
CamelotCore/Source/CmRenderWindowManager.cpp

@@ -49,7 +49,7 @@ namespace CamelotFramework
 
 		auto iterFind = std::find(begin(mMovedOrResizedWindows), end(mMovedOrResizedWindows), window);
 
-		if(iterFind != end(mMovedOrResizedWindows))
+		if(iterFind == end(mMovedOrResizedWindows))
 			mMovedOrResizedWindows.push_back(window);
 	}
 

+ 15 - 37
CamelotD3D11RenderSystem/Source/CmD3D11RenderWindow.cpp

@@ -299,23 +299,29 @@ namespace CamelotFramework
 		}
 	}
 
-	void D3D11RenderWindow::reposition(int top, int left)
+	void D3D11RenderWindow::reposition(INT32 top, INT32 left)
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
 		if (mHWnd && !mIsFullScreen)
 		{
+			mTop = top;
+			mLeft = left;
+
 			SetWindowPos(mHWnd, 0, top, left, 0, 0,
 				SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
 		}
 	}
 
-	void D3D11RenderWindow::resize(unsigned int width, unsigned int height)
+	void D3D11RenderWindow::resize(UINT32 width, UINT32 height)
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
 		if (mHWnd && !mIsFullScreen)
 		{
+			mWidth = width;
+			mHeight = height;
+
 			RECT rc = { 0, 0, width, height };
 			AdjustWindowRect(&rc, GetWindowLong(mHWnd, GWL_STYLE), false);
 			width = rc.right - rc.left;
@@ -557,9 +563,6 @@ namespace CamelotFramework
 		if (height == 0)
 			height = 1;
 
-		if (mWidth == width && mHeight == height)
-			return;
-
 		resizeSwapChainBuffers(width, height);
 
 		RenderWindow::_windowMovedOrResized();
@@ -673,44 +676,19 @@ namespace CamelotFramework
 
 		// width and height can be zero to autodetect size, therefore do not rely on them
 		UINT Flags = mIsFullScreen ? DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH : 0;
-		mSwapChain->ResizeBuffers(mSwapChainDesc.BufferCount, width, height, mSwapChainDesc.BufferDesc.Format, Flags);
+		HRESULT hr = mSwapChain->ResizeBuffers(mSwapChainDesc.BufferCount, width, height, mSwapChainDesc.BufferDesc.Format, Flags);
+
+		if(hr != S_OK)
+			CM_EXCEPT(InternalErrorException, "Call to ResizeBuffers failed.");
+
 		mSwapChain->GetDesc(&mSwapChainDesc);
-		mWidth = mSwapChainDesc.BufferDesc.Width;
-		mHeight = mSwapChainDesc.BufferDesc.Height;
+		//mWidth = mSwapChainDesc.BufferDesc.Width;
+		//mHeight = mSwapChainDesc.BufferDesc.Height;
 		mIsFullScreen = (0 == mSwapChainDesc.Windowed); // Alt-Enter together with SetWindowAssociation() can change this state
 
 		createSizeDependedD3DResources();
 
 		mDevice.getImmediateContext()->OMSetRenderTargets(0, 0, 0);
-		// Additional swap chains need their own depth buffer
-		// to support resizing them
-
-		HRESULT hr = mSwapChain->GetBuffer( 0,  __uuidof( ID3D11Texture2D ), (LPVOID*)&mBackBuffer  );
-		if( FAILED(hr) )
-		{
-			CM_EXCEPT(RenderingAPIException, 
-				"Unable to Get Back Buffer for swap chain");
-		}
-
-		// get the backbuffer desc
-		D3D11_TEXTURE2D_DESC BBDesc;
-		mBackBuffer->GetDesc(&BBDesc);
-
-		// create the render target view
-		D3D11_RENDER_TARGET_VIEW_DESC RTVDesc;
-		ZeroMemory( &RTVDesc, sizeof(RTVDesc) );
-
-		RTVDesc.Format = BBDesc.Format;
-		RTVDesc.ViewDimension = mFSAA ? D3D11_RTV_DIMENSION_TEXTURE2DMS : D3D11_RTV_DIMENSION_TEXTURE2D;
-		RTVDesc.Texture2D.MipSlice = 0;
-		hr = mDevice.getD3D11Device()->CreateRenderTargetView(mBackBuffer, &RTVDesc, &mRenderTargetView);
-
-		if(FAILED(hr))
-		{
-			String errorDescription = mDevice.getErrorDescription();
-			CM_EXCEPT(RenderingAPIException, 
-				"Unable to create rendertagert view\nError Description:" + errorDescription);
-		}
 	}
 
 	IDXGIDevice* D3D11RenderWindow::queryDxgiDevice()

+ 9 - 8
CamelotD3D9Renderer/Source/CmD3D9RenderWindow.cpp

@@ -370,6 +370,9 @@ namespace CamelotFramework
 
 		if (mHWnd && !mIsFullScreen)
 		{
+			mLeft = left;
+			mTop = top;
+
 			SetWindowPos(mHWnd, 0, top, left, 0, 0,
 				SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
 		}
@@ -381,8 +384,12 @@ namespace CamelotFramework
 
 		if (mHWnd && !mIsFullScreen)
 		{
+			mWidth = width;
+			mHeight = height;
+
 			unsigned int winWidth, winHeight;
 			_adjustWindow(width, height, mStyle, &winWidth, &winHeight);
+
 			SetWindowPos(mHWnd, 0, 0, 0, winWidth, winHeight,
 				SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
 		}
@@ -756,15 +763,9 @@ namespace CamelotFramework
 			mHeight = 0;
 			return;
 		}
-		unsigned int width = rc.right - rc.left;
-		unsigned int height = rc.bottom - rc.top;
 
-		// Case window resized.
-		if (width != mWidth || height != mHeight)
-		{
-			mWidth  = rc.right - rc.left;
-			mHeight = rc.bottom - rc.top;	
-		}	
+		mWidth  = rc.right - rc.left;
+		mHeight = rc.bottom - rc.top;	
 	}
 
 	bool D3D9RenderWindow::_validateDevice()

+ 6 - 3
CamelotGLRenderer/Source/CmWin32Window.cpp

@@ -552,6 +552,9 @@ namespace CamelotFramework {
 
 		if (mHWnd && !mIsFullScreen)
 		{
+			mLeft = left;
+			mTop = top;
+
 			SetWindowPos(mHWnd, 0, left, top, 0, 0,
 				SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
 		}
@@ -563,6 +566,9 @@ namespace CamelotFramework {
 
 		if (mHWnd && !mIsFullScreen)
 		{
+			mWidth = width;
+			mHeight = height;
+
 			RECT rc = { 0, 0, width, height };
 			AdjustWindowRect(&rc, GetWindowLong(mHWnd, GWL_STYLE), false);
 			width = rc.right - rc.left;
@@ -723,9 +729,6 @@ namespace CamelotFramework {
 		// width and height represent drawable area only
 		GetClientRect(mHWnd, &rc);
 
-		if (mWidth == rc.right && mHeight == rc.bottom)
-			return;
-
 		mWidth = rc.right - rc.left;
 		mHeight = rc.bottom - rc.top;
 

+ 5 - 12
TODO.txt

@@ -21,21 +21,14 @@ MAJOR ISSUE: writeSubresource/readSubresoure doesn't require a shared ptr to Gpu
 I call waitUntilLoaded too many times. Sometimes 5-6 times in a single function. Each of those calls will wait a single frame.
 GUIWidget::updateMeshes leaks. If I leave the game running I can see memory continously going up
 
-/************** INPUT REFACTOR *********************/
-
-DO LATER:
- - Rename DeferredRenderContext and everything that references it
- - onMovedOrResized is still used by Viewport
- - Replace list of windows in WIndowEventUtilities with WindowManagers list. No need to keep two lists I think
-
-/*******************************************************/
-
 IMMEDIATE:
+ - It's possible to resize smaller than 0 and cause an exception
+ - Cursor doesn't stay inside the window we're resizing, window seems to resize slower than the cursor moves
+ - OpenGL resize doesn't work - I believe its because its render thread works too slow and we call "cancelAll" on the command queue. Check out why is the render thread slow, and get rid of cancelAll(), it's not a valid approach
  - Update debug camera so it uses callbacks
  - Add support for diacritical marks
- - Add window-management command to DeferredRenderContext - I already have resource management commands
-   there, few window related ones won't hurt. I can always split the class if needed.
-     - Possibly add guards to render target classes so they aren't accidentaly accessed from the render thread (similar to how Texture is handled)
+ - onMovedOrResized is still used by Viewport
+ - Replace list of windows in WIndowEventUtilities with WindowManagers list. No need to keep two lists I think
 
  - I have disabled linear filtering because it doesn't look good on scale9grid textures. (Add another material so it works with stretched textures?)
  - Enable alpha test so I don't render completely transparent pixels.