| 
									
										
										
										
											2018-04-21 21:24:46 +08:00
										 |  |  |  | #include "..\e2dbase.h"
 | 
					
						
							|  |  |  |  | #include "..\e2dmanager.h"
 | 
					
						
							|  |  |  |  | #include "..\e2dnode.h"
 | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-24 17:19:54 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | e2d::Renderer*		e2d::Renderer::_instance = nullptr; | 
					
						
							|  |  |  |  | ID2D1Factory*		e2d::Renderer::_d2dFactory = nullptr; | 
					
						
							|  |  |  |  | IWICImagingFactory*	e2d::Renderer::_imagingFactory = nullptr; | 
					
						
							|  |  |  |  | IDWriteFactory*		e2d::Renderer::_writeFactory = nullptr; | 
					
						
							|  |  |  |  | IDWriteTextFormat*	e2d::Renderer::_textFormat = nullptr; | 
					
						
							|  |  |  |  | ID2D1StrokeStyle*	e2d::Renderer::_miterStrokeStyle = nullptr; | 
					
						
							|  |  |  |  | ID2D1StrokeStyle*	e2d::Renderer::_bevelStrokeStyle = nullptr; | 
					
						
							|  |  |  |  | ID2D1StrokeStyle*	e2d::Renderer::_roundStrokeStyle = nullptr; | 
					
						
							| 
									
										
										
										
											2018-05-24 17:19:54 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | e2d::Renderer * e2d::Renderer::getInstance() | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	if (!_instance) | 
					
						
							| 
									
										
										
										
											2018-05-24 12:24:39 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 		_instance = new (std::nothrow) Renderer; | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	return _instance; | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | void e2d::Renderer::destroyInstance() | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	if (_instance) | 
					
						
							| 
									
										
										
										
											2018-05-24 12:24:39 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 		delete _instance; | 
					
						
							|  |  |  |  | 		_instance = nullptr; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		SafeRelease(_textFormat); | 
					
						
							|  |  |  |  | 		SafeRelease(_d2dFactory); | 
					
						
							|  |  |  |  | 		SafeRelease(_miterStrokeStyle); | 
					
						
							|  |  |  |  | 		SafeRelease(_bevelStrokeStyle); | 
					
						
							|  |  |  |  | 		SafeRelease(_roundStrokeStyle); | 
					
						
							|  |  |  |  | 		SafeRelease(_imagingFactory); | 
					
						
							|  |  |  |  | 		SafeRelease(_writeFactory); | 
					
						
							| 
									
										
										
										
											2018-05-24 12:24:39 +08:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-04-21 18:22:01 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | e2d::Renderer::Renderer() | 
					
						
							|  |  |  |  | 	: _showFps(false) | 
					
						
							|  |  |  |  | 	, _renderTarget(nullptr) | 
					
						
							|  |  |  |  | 	, _solidBrush(nullptr) | 
					
						
							|  |  |  |  | 	, _textRenderer(nullptr) | 
					
						
							|  |  |  |  | 	, _clearColor(D2D1::ColorF(D2D1::ColorF::Black)) | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-04 15:33:09 +08:00
										 |  |  |  | 	CoInitialize(nullptr); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	this->__createDeviceResources(); | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-04-17 11:41:33 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | e2d::Renderer::~Renderer() | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	SafeRelease(_renderTarget); | 
					
						
							|  |  |  |  | 	SafeRelease(_solidBrush); | 
					
						
							|  |  |  |  | 	SafeRelease(_textRenderer); | 
					
						
							| 
									
										
										
										
											2018-07-04 15:33:09 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	CoUninitialize(); | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | bool e2d::Renderer::__createDeviceResources() | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	HRESULT hr = S_OK; | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	if (!_renderTarget) | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 		HWND hWnd = Window::getInstance()->getHWnd(); | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>Щ<EFBFBD><D0A9>ԴӦ<D4B4><D3A6> Direct3D <20>豸<EFBFBD><E8B1B8>ʧʱ<CAA7>ؽ<EFBFBD><D8BD><EFBFBD>
 | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD>統 isVisiable <20><><EFBFBD>ģ<DEB8><C4A3>ȵ<EFBFBD>
 | 
					
						
							|  |  |  |  | 		RECT rc; | 
					
						
							|  |  |  |  | 		GetClientRect(hWnd, &rc); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		D2D1_SIZE_U size = D2D1::SizeU( | 
					
						
							|  |  |  |  | 			rc.right - rc.left, | 
					
						
							|  |  |  |  | 			rc.bottom - rc.top | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB> Direct2D <20><>ȾĿ<C8BE><C4BF>
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 		hr = Renderer::getFactory()->CreateHwndRenderTarget( | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 			D2D1::RenderTargetProperties(), | 
					
						
							|  |  |  |  | 			D2D1::HwndRenderTargetProperties( | 
					
						
							|  |  |  |  | 				hWnd, | 
					
						
							|  |  |  |  | 				size), | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 			&_renderTarget | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-24 12:24:39 +08:00
										 |  |  |  | 		if (FAILED(hr)) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			throw SystemException(L"Create ID2D1HwndRenderTarget failed"); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 		else | 
					
						
							| 
									
										
										
										
											2018-02-01 09:38:25 +08:00
										 |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˢ
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 			hr = _renderTarget->CreateSolidColorBrush( | 
					
						
							| 
									
										
										
										
											2018-02-01 09:38:25 +08:00
										 |  |  |  | 				D2D1::ColorF(D2D1::ColorF::White), | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 				&_solidBrush | 
					
						
							| 
									
										
										
										
											2018-02-01 09:38:25 +08:00
										 |  |  |  | 			); | 
					
						
							|  |  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-24 12:24:39 +08:00
										 |  |  |  | 		if (FAILED(hr)) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			throw SystemException(L"Create ID2D1SolidColorBrush failed"); | 
					
						
							|  |  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 	return SUCCEEDED(hr); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | void e2d::Renderer::__discardDeviceResources() | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	SafeRelease(_renderTarget); | 
					
						
							|  |  |  |  | 	SafeRelease(_solidBrush); | 
					
						
							|  |  |  |  | 	SafeRelease(_textRenderer); | 
					
						
							|  |  |  |  | 	SafeRelease(_miterStrokeStyle); | 
					
						
							|  |  |  |  | 	SafeRelease(_bevelStrokeStyle); | 
					
						
							|  |  |  |  | 	SafeRelease(_roundStrokeStyle); | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | void e2d::Renderer::__render() | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	HRESULT hr = S_OK; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	// <20><><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ
 | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | 	Renderer::__createDeviceResources(); | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	// <20><>ʼ<EFBFBD><CABC>Ⱦ
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	_renderTarget->BeginDraw(); | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 	// ʹ<>ñ<EFBFBD><C3B1><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	_renderTarget->Clear(_clearColor); | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	// <20><>Ⱦ<EFBFBD><C8BE><EFBFBD><EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2018-07-05 16:34:53 +08:00
										 |  |  |  | 	SceneManager::getInstance()->__render(); | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-17 11:41:33 +08:00
										 |  |  |  | 	// <20><>Ⱦ FPS
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	if (_showFps) | 
					
						
							| 
									
										
										
										
											2018-04-17 11:41:33 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-04-21 18:22:01 +08:00
										 |  |  |  | 		static int s_nRenderTimes = 0; | 
					
						
							|  |  |  |  | 		static double s_fLastRenderTime = 0; | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  |  | 		static String s_sFpsText; | 
					
						
							| 
									
										
										
										
											2018-04-21 18:22:01 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-14 22:51:40 +08:00
										 |  |  |  | 		++s_nRenderTimes; | 
					
						
							| 
									
										
										
										
											2018-04-17 11:41:33 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 		double fDelay = Time::getTotalTime() - s_fLastRenderTime; | 
					
						
							|  |  |  |  | 		if (fDelay >= 0.3) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			s_sFpsText = String::format(L"FPS: %.1lf", (1 / fDelay) * s_nRenderTimes); | 
					
						
							|  |  |  |  | 			s_fLastRenderTime = Time::getTotalTime(); | 
					
						
							|  |  |  |  | 			s_nRenderTimes = 0; | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  |  | 		IDWriteTextLayout * pTextLayout = nullptr; | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 		IDWriteTextFormat * pTextFormat = Renderer::getFpsTextFormat(); | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 		hr = _writeFactory->CreateTextLayout( | 
					
						
							| 
									
										
										
										
											2018-05-24 14:33:16 +08:00
										 |  |  |  | 			(const WCHAR *)s_sFpsText, | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  |  | 			(UINT32)s_sFpsText.getLength(), | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 			pTextFormat, | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  |  | 			0, | 
					
						
							|  |  |  |  | 			0, | 
					
						
							|  |  |  |  | 			&pTextLayout | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		if (SUCCEEDED(hr)) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 			_renderTarget->SetTransform(D2D1::Matrix3x2F::Identity()); | 
					
						
							|  |  |  |  | 			_solidBrush->SetOpacity(1.0f); | 
					
						
							|  |  |  |  | 			_textRenderer->SetTextStyle( | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  |  | 				D2D1::ColorF(D2D1::ColorF::White), | 
					
						
							| 
									
										
										
										
											2018-04-22 00:33:20 +08:00
										 |  |  |  | 				TRUE, | 
					
						
							| 
									
										
										
										
											2018-04-22 16:14:04 +08:00
										 |  |  |  | 				D2D1::ColorF(D2D1::ColorF::Black, 0.4f), | 
					
						
							|  |  |  |  | 				1.5f, | 
					
						
							| 
									
										
										
										
											2018-04-23 17:59:46 +08:00
										 |  |  |  | 				D2D1_LINE_JOIN_ROUND | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  |  | 			); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 			pTextLayout->Draw(nullptr, _textRenderer, 10, 0); | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-22 12:24:43 +08:00
										 |  |  |  | 			SafeRelease(pTextLayout); | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-04-17 11:41:33 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 	// <20><>ֹ<EFBFBD><D6B9>Ⱦ
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	hr = _renderTarget->EndDraw(); | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (hr == D2DERR_RECREATE_TARGET) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD> Direct3D <20>豸<EFBFBD><E8B1B8>ִ<EFBFBD>й<EFBFBD><D0B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ
 | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ε<EFBFBD><CEB5><EFBFBD>ʱ<EFBFBD>ؽ<EFBFBD><D8BD><EFBFBD>Դ
 | 
					
						
							|  |  |  |  | 		hr = S_OK; | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 		this->__discardDeviceResources(); | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (FAILED(hr)) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-05-24 12:24:39 +08:00
										 |  |  |  | 		throw SystemException(L"Device loss recovery failed"); | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-22 13:15:57 +08:00
										 |  |  |  | e2d::Color e2d::Renderer::getBackgroundColor() | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	return Color(_clearColor.r, _clearColor.g, _clearColor.b, _clearColor.a); | 
					
						
							| 
									
										
										
										
											2018-04-22 13:15:57 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void e2d::Renderer::setBackgroundColor(Color color) | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	_clearColor = color.toD2DColorF(); | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-17 11:41:33 +08:00
										 |  |  |  | void e2d::Renderer::showFps(bool show) | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	_showFps = show; | 
					
						
							| 
									
										
										
										
											2018-04-17 11:41:33 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | ID2D1HwndRenderTarget * e2d::Renderer::getRenderTarget() | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	return _renderTarget; | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | ID2D1SolidColorBrush * e2d::Renderer::getSolidColorBrush() | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	return _solidBrush; | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | e2d::TextRenderer * e2d::Renderer::getTextRenderer() | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	if (!_textRenderer) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ⱦ<EFBFBD><C8BE>
 | 
					
						
							|  |  |  |  | 		_textRenderer = TextRenderer::Create( | 
					
						
							|  |  |  |  | 			Renderer::getFactory(), | 
					
						
							|  |  |  |  | 			this->getRenderTarget(), | 
					
						
							|  |  |  |  | 			this->getSolidColorBrush() | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	return _textRenderer; | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | ID2D1Factory * e2d::Renderer::getFactory() | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	if (!_d2dFactory) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		HRESULT hr = D2D1CreateFactory( | 
					
						
							|  |  |  |  | 			D2D1_FACTORY_TYPE_SINGLE_THREADED, | 
					
						
							|  |  |  |  | 			&_d2dFactory | 
					
						
							|  |  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 		if (FAILED(hr)) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			throw SystemException(L"Create ID2D1Factory failed"); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	return _d2dFactory; | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | IWICImagingFactory * e2d::Renderer::getImagingFactory() | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	if (!_imagingFactory) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD> WIC <20><>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͳһ<CDB3><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD>ʽ<EFBFBD><CABD>ͼƬ
 | 
					
						
							|  |  |  |  | 		HRESULT hr = CoCreateInstance( | 
					
						
							|  |  |  |  | 			CLSID_WICImagingFactory, | 
					
						
							|  |  |  |  | 			nullptr, | 
					
						
							|  |  |  |  | 			CLSCTX_INPROC_SERVER, | 
					
						
							|  |  |  |  | 			IID_IWICImagingFactory, | 
					
						
							|  |  |  |  | 			reinterpret_cast<void**>(&_imagingFactory) | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		if (FAILED(hr)) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			throw SystemException(L"Create IWICImagingFactory failed"); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	return _imagingFactory; | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | IDWriteFactory * e2d::Renderer::getWriteFactory() | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	if (!_writeFactory) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD> DirectWrite <20><><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 		HRESULT hr = DWriteCreateFactory( | 
					
						
							|  |  |  |  | 			DWRITE_FACTORY_TYPE_SHARED, | 
					
						
							|  |  |  |  | 			__uuidof(IDWriteFactory), | 
					
						
							|  |  |  |  | 			reinterpret_cast<IUnknown**>(&_writeFactory) | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		if (FAILED(hr)) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			throw SystemException(L"Create IDWriteFactory failed"); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	return _writeFactory; | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | IDWriteTextFormat * e2d::Renderer::getFpsTextFormat() | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	if (!_textFormat) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD> FPS <20>ı<EFBFBD><C4B1><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 		HRESULT hr = Renderer::getWriteFactory()->CreateTextFormat( | 
					
						
							|  |  |  |  | 			L"", | 
					
						
							|  |  |  |  | 			nullptr, | 
					
						
							|  |  |  |  | 			DWRITE_FONT_WEIGHT_NORMAL, | 
					
						
							|  |  |  |  | 			DWRITE_FONT_STYLE_NORMAL, | 
					
						
							|  |  |  |  | 			DWRITE_FONT_STRETCH_NORMAL, | 
					
						
							|  |  |  |  | 			20, | 
					
						
							|  |  |  |  | 			L"", | 
					
						
							|  |  |  |  | 			&_textFormat | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		if (SUCCEEDED(hr)) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			_textFormat->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	return _textFormat; | 
					
						
							| 
									
										
										
										
											2018-04-21 23:09:59 +08:00
										 |  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-05-24 17:19:54 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | ID2D1StrokeStyle * e2d::Renderer::getMiterStrokeStyle() | 
					
						
							| 
									
										
										
										
											2018-05-24 17:19:54 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	if (!_miterStrokeStyle) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		HRESULT hr = Renderer::getFactory()->CreateStrokeStyle( | 
					
						
							|  |  |  |  | 			D2D1::StrokeStyleProperties( | 
					
						
							|  |  |  |  | 				D2D1_CAP_STYLE_FLAT, | 
					
						
							|  |  |  |  | 				D2D1_CAP_STYLE_FLAT, | 
					
						
							|  |  |  |  | 				D2D1_CAP_STYLE_FLAT, | 
					
						
							|  |  |  |  | 				D2D1_LINE_JOIN_MITER, | 
					
						
							|  |  |  |  | 				2.0f, | 
					
						
							|  |  |  |  | 				D2D1_DASH_STYLE_SOLID, | 
					
						
							|  |  |  |  | 				0.0f), | 
					
						
							|  |  |  |  | 			nullptr, | 
					
						
							|  |  |  |  | 			0, | 
					
						
							|  |  |  |  | 			&_miterStrokeStyle | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		if (FAILED(hr)) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			throw SystemException(L"Create ID2D1StrokeStyle failed"); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	return _miterStrokeStyle; | 
					
						
							| 
									
										
										
										
											2018-05-24 17:19:54 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | ID2D1StrokeStyle * e2d::Renderer::getBevelStrokeStyle() | 
					
						
							| 
									
										
										
										
											2018-05-24 17:19:54 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	if (!_bevelStrokeStyle) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		HRESULT hr = Renderer::getFactory()->CreateStrokeStyle( | 
					
						
							|  |  |  |  | 			D2D1::StrokeStyleProperties( | 
					
						
							|  |  |  |  | 				D2D1_CAP_STYLE_FLAT, | 
					
						
							|  |  |  |  | 				D2D1_CAP_STYLE_FLAT, | 
					
						
							|  |  |  |  | 				D2D1_CAP_STYLE_FLAT, | 
					
						
							|  |  |  |  | 				D2D1_LINE_JOIN_BEVEL, | 
					
						
							|  |  |  |  | 				2.0f, | 
					
						
							|  |  |  |  | 				D2D1_DASH_STYLE_SOLID, | 
					
						
							|  |  |  |  | 				0.0f), | 
					
						
							|  |  |  |  | 			nullptr, | 
					
						
							|  |  |  |  | 			0, | 
					
						
							|  |  |  |  | 			&_bevelStrokeStyle | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		if (FAILED(hr)) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			throw SystemException(L"Create ID2D1StrokeStyle failed"); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	return _bevelStrokeStyle; | 
					
						
							| 
									
										
										
										
											2018-05-24 17:19:54 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | ID2D1StrokeStyle * e2d::Renderer::getRoundStrokeStyle() | 
					
						
							| 
									
										
										
										
											2018-05-24 17:19:54 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	if (!_roundStrokeStyle) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		HRESULT hr = Renderer::getFactory()->CreateStrokeStyle( | 
					
						
							|  |  |  |  | 			D2D1::StrokeStyleProperties( | 
					
						
							|  |  |  |  | 				D2D1_CAP_STYLE_FLAT, | 
					
						
							|  |  |  |  | 				D2D1_CAP_STYLE_FLAT, | 
					
						
							|  |  |  |  | 				D2D1_CAP_STYLE_FLAT, | 
					
						
							|  |  |  |  | 				D2D1_LINE_JOIN_ROUND, | 
					
						
							|  |  |  |  | 				2.0f, | 
					
						
							|  |  |  |  | 				D2D1_DASH_STYLE_SOLID, | 
					
						
							|  |  |  |  | 				0.0f), | 
					
						
							|  |  |  |  | 			nullptr, | 
					
						
							|  |  |  |  | 			0, | 
					
						
							|  |  |  |  | 			&_roundStrokeStyle | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		if (FAILED(hr)) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			throw SystemException(L"Create ID2D1StrokeStyle failed"); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	return _roundStrokeStyle; | 
					
						
							| 
									
										
										
										
											2018-05-24 17:19:54 +08:00
										 |  |  |  | } |