Ejemplo n.º 1
0
	bool SPDevice::ResetDevice( SPConfig config )
	{
		//SPTextureManager::GetSingleton().Unload();

		// Try to reset.
		if (d3dDevice)
		{
			if (D3D_OK == d3dDevice->Reset(&config.ToD3DParameters()))
			{
				return true;
			}
		}		

		// Force reload.
		SPLogHelper::WriteLog("[DirectX] WARNING: Force reseting D3D device!");

		ReleaseDevice();

		if( !CreateD3DDevice(config) )
		{
			return false;
		}

		return true;
	}
Ejemplo n.º 2
0
D3DPresentEngine::D3DPresentEngine(HRESULT& hr) : 
    m_hwnd(NULL),
    m_DeviceResetToken(0),
    m_pD3D9(NULL),
    m_pDevice(NULL),
    m_pDeviceManager(NULL),
    m_pSurfaceRepaint(NULL),
	gl_handleD3D(NULL),
	d3d_shared_texture(NULL),
	d3d_shared_surface(NULL)
{
    SetRectEmpty(&m_rcDestRect);

    ZeroMemory(&m_DisplayMode, sizeof(m_DisplayMode));

    hr = InitializeD3D();

    if (SUCCEEDED(hr))
    {
       hr = CreateD3DDevice();
    }

	//bool nvdxInteropEnabled = false;
	//if(wglewIsSupported("WGL_NV_DX_interop"))
	//{
	//	nvdxInteropEnabled = true;
	//}
}
Ejemplo n.º 3
0
HRESULT D3DPresentEngine::CheckDeviceState(DeviceState *pState)
{
    HRESULT hr = S_OK;

    AutoLock lock(m_ObjectLock);

	if(IsVistaOrLater())
	{
		// Check the device state. Not every failure code is a critical failure.
		hr = ((IDirect3DDevice9Ex*)m_pDevice)->CheckDeviceState(m_hwnd);
	}
	else
	{
		/* Add support for XP!! Wait, f**k XP */
		hr = m_pDevice->TestCooperativeLevel();
	}

    *pState = DeviceOK;

    switch (hr)
    {
    case S_OK:
    case S_PRESENT_OCCLUDED:
      case S_PRESENT_MODE_CHANGED:
        // state is DeviceOK
        hr = S_OK;
        break;

    case D3DERR_DEVICELOST:
    case D3DERR_DEVICEHUNG:
        // Lost/hung device. Destroy the device and create a new one.
        CHECK_HR(hr = CreateD3DDevice());
        *pState = DeviceReset;
        hr = S_OK;
        break;

    case D3DERR_DEVICEREMOVED:
        // This is a fatal error.
        *pState = DeviceRemoved;
        break;

    case E_INVALIDARG:
        // CheckDeviceState can return E_INVALIDARG if the window is not valid
        // We'll assume that the window was destroyed; we'll recreate the device 
        // if the application sets a new window.
        hr = S_OK;
    }

done:
    return hr;
}
Ejemplo n.º 4
0
VMR9CustomPresenter::VMR9CustomPresenter(HRESULT& hr)
    : m_RefCount(1)
    , m_pPresentCb(NULL)
    , m_pD3D9(NULL)
    , m_pDevice(NULL)
    , m_pSurfAllocNotify(NULL)
    , m_D3D9Ex(false)
{
    hr = InitializeD3D();

    if (SUCCEEDED(hr))
    {
        hr = CreateD3DDevice();
    }
}
Ejemplo n.º 5
0
	bool SPDevice::InitializeD3D( SPConfig config )
	{
		SPLogHelper::WriteLog("[DirectX] Initializing D3D ...");

		if( !CreateD3DObject() )
		{
			return false;
		}

		if ( !CreateD3DDevice(config) )
		{
			return false;
		}

		return true;
	}
// Initialization for the application window, devices and
// DComp resources before entering the message loop
HRESULT Application::BeforeEnteringMessageLoop()
{
    HRESULT hr = S_OK;

    if (SUCCEEDED(hr))
    {
        hr = CreateMainWindow();
    }

    if (SUCCEEDED(hr))
    {
        hr = CreateD3DDevice();
    }

    if (SUCCEEDED(hr))
    {
        hr = CreateD2DDevice();
    }

    if (SUCCEEDED(hr))
    {
        hr = CreateDWriteFactory();
    }

    if (SUCCEEDED(hr))
    {
        hr = CreateDCompDevice();
    }

    if (SUCCEEDED(hr))
    {
        hr = CreateDCompVisualTree();
    }

    if (SUCCEEDED(hr))
    {
        hr = ShowMainWindow();
    }

    if (SUCCEEDED(hr))
    {
        hr = EnableMouseAsPointerDevice();
    }

    return hr;
}
Ejemplo n.º 7
0
HRESULT D3DPresentEngine::SetVideoWindow(HWND hwnd)
{
    // Assertions: EVRCustomPresenter checks these cases.
    assert(IsWindow(hwnd));
    assert(hwnd != m_hwnd);     

    HRESULT hr = S_OK;

    AutoLock lock(m_ObjectLock);

    m_hwnd = hwnd;

    // Recreate the device.
    hr = CreateD3DDevice();

    return hr;
}
Ejemplo n.º 8
0
D3DPresentEngine::D3DPresentEngine(HRESULT& hr) : 
    m_hwnd(NULL),
    m_DeviceResetToken(0),
    m_pD3D9(NULL),
    m_pDevice(NULL),
    m_pDeviceManager(NULL),
    m_pSurfaceRepaint(NULL)
{
    SetRectEmpty(&m_rcDestRect);

    ZeroMemory(&m_DisplayMode, sizeof(m_DisplayMode));

    hr = InitializeD3D();

    if (SUCCEEDED(hr))
    {
       hr = CreateD3DDevice();
    }
}
Ejemplo n.º 9
0
//
// Program starts here
//
int main(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
	//
	// Create a window and attach directx to it
	//
	g_pD3D = Direct3DCreate9( D3D_SDK_VERSION );
	g_pHWND = CreateGameWindow();
	CreateD3DDevice();	

	//
	// Create a GWEN DirectX renderer
	//
	Gwen::Renderer::DirectX9* pRenderer = new Gwen::Renderer::DirectX9( g_pD3DDevice );

	//
	// Create a GWEN skin
	//
	Gwen::Skin::TexturedBase skin;
	skin.SetRender( pRenderer );
	skin.Init( "DefaultSkin.png" );

	//
	// Create a Canvas (it's root, on which all other GWEN panels are created)
	//
	Gwen::Controls::Canvas* pCanvas = new Gwen::Controls::Canvas( &skin );
	pCanvas->SetSize( 1000, 622 );
	pCanvas->SetDrawBackground( true );
	pCanvas->SetBackgroundColor( Gwen::Color( 150, 170, 170, 255 ) );

	//
	// Create our unittest control (which is a Window with controls in it)
	//
	UnitTest* pUnit = new UnitTest( pCanvas );
	pUnit->SetPos( 10, 10 );

	//
	// Create a Windows Control helper 
	// (Processes Windows MSG's and fires input at GWEN)
	//
	Gwen::Input::Windows GwenInput;
	GwenInput.Initialize( pCanvas );

	//
	// Begin the main game loop
	//
	MSG msg;
	while( true )
	{
		// Skip out if the window is closed
		if ( !IsWindowVisible( g_pHWND ) )
			break;

		// If we have a message from windows..
		if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
		{
			// .. give it to the input handler to process
			GwenInput.ProcessMessage( msg );

			// if it's QUIT then quit..
			if ( msg.message == WM_QUIT )
				break;

			// Handle the regular window stuff..
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else
		{
			// Normal DirectX rendering loop
			g_pD3DDevice->BeginScene();

				g_pD3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB( 0, 0, 0 ), 1, 0 );

				// This is how easy it is to render GWEN!
				pCanvas->RenderCanvas();

			g_pD3DDevice->EndScene();
			g_pD3DDevice->Present( NULL, NULL, NULL, NULL );

		}
	}

	if ( g_pD3DDevice )
	{
		g_pD3DDevice->Release();
		g_pD3DDevice = NULL;
	}

	if ( g_pD3D )
	{
		g_pD3D->Release();
		g_pD3D = NULL;
	}
}
Ejemplo n.º 10
0
    void Initialize( HWND hParentWindow )
    {
		// Store the window handle.
		m_hParentWindow = hParentWindow;

		// Get the D3D pointer
		m_pd3d = Direct3DCreate9( D3D_SDK_VERSION );

        // Enumerate the display modes
        EnumerateDisplayModes( );

		// TBD: Enumerate the zbuffer formats properly!
		EnumerateZBufferModes( );

		// Create the D3D device now.
		m_pD3DDevice = CreateD3DDevice( hParentWindow );		// Calls CreateD3DDevice in this (dddevice) class().
		
/*		if (pdd == NULL) 
		{
            TRef<IDirectDraw> pddPrimary;

            HRESULT hr = DirectDrawCreate(NULL, &pddPrimary, NULL);

            if (SUCCEEDED(hr)) 
			{
                DDCall(pddPrimary->QueryInterface(IID_IDirectDrawX, (void**)&m_pdd));
            }
        } 
		else 
		{
            m_pdd = pdd;
        }

        if (m_pdd) 
		{
            // Get Device Info
            DDDeviceIdentifier dddi;
            m_pdd->GetDeviceIdentifier(&dddi, DDGDI_GETHOSTIDENTIFIER);

            m_strName = dddi.szDescription;

            // Get device capabilities.
            DDCall(m_pdd->GetCaps(&m_ddcapsHW, &m_ddcapsSW));

            // Get the amount of video memory
            DWORD dwFree;
            DDSCaps ddsc;
            ddsc.dwCaps = DDSCAPS_VIDEOMEMORY;

            HRESULT hr = m_pdd->GetAvailableVidMem(&ddsc, &m_dwTotalVideoMemory, &dwFree);
            if (DDERR_NODIRECTDRAWHW != hr)
                DDCall(hr);

            // Does the driver support 3D with texture mapping and zbuffer?
            DWORD ddsCaps = DDSCAPS_TEXTURE | DDSCAPS_ZBUFFER;

            m_b3DAcceleration =
                   ((m_ddcapsHW.dwCaps         & DDCAPS_3D) !=       0)
                && ((m_ddcapsHW.ddsCaps.dwCaps & ddsCaps  ) == ddsCaps);

            // Set the cooperative level to Normal
			DDCall(m_pdd->SetCooperativeLevel(NULL, DDSCL_NORMAL));

            // Get the D3D pointer
//            DDCall(m_pdd->QueryInterface(IID_IDirect3DX, (void**)&m_pd3d));
			m_pd3d = Direct3DCreate9( D3D_SDK_VERSION );

            // Enumerate the display modes
            m_pdd->EnumDisplayModes(0, NULL, this, StaticEnumModes);

			// Enumerate the zbuffer formats
//            m_pd3d->EnumZBufferFormats(GetIID(true), StaticEnumZBufferFormats, this);
        }*/
    }
Ejemplo n.º 11
0
//
// Program starts here
//
int main(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
	//
	// Create a window and attach directx to it
	//

	g_pHWND = CreateGameWindow();
	CreateD3DDevice();
	RECT FrameBounds;
	GetClientRect(g_pHWND, &FrameBounds);
	//
	// Create a GWEN DirectX renderer
	//
	Gwen::Renderer::DirectX10* pRenderer = new Gwen::Renderer::DirectX10(g_pd3dDevice);
	//
	// Create a GWEN skin
	//
	Gwen::Skin::TexturedBase* pSkin = new Gwen::Skin::TexturedBase(pRenderer);
	pSkin->Init("DefaultSkin.png");
	//
	// Create a Canvas (it's root, on which all other GWEN panels are created)
	//
	Gwen::Controls::Canvas* pCanvas = new Gwen::Controls::Canvas(pSkin);
	pCanvas->SetSize(FrameBounds.right, FrameBounds.bottom);
	pCanvas->SetDrawBackground(true);
	pCanvas->SetBackgroundColor(Gwen::Color(150, 170, 170, 255));
	//
	// Create our unittest control (which is a Window with controls in it)
	//
	UnitTest* pUnit = new UnitTest(pCanvas);
	pUnit->SetPos(10, 10);
	//
	// Create a Windows Control helper
	// (Processes Windows MSG's and fires input at GWEN)
	//
	Gwen::Input::Windows GwenInput;
	GwenInput.Initialize(pCanvas);
	//
	// Begin the main game loop
	//
	MSG msg;

	while (true)
	{
		// Skip out if the window is closed
		if (!IsWindowVisible(g_pHWND))
		{
			break;
		}

		// If we have a message from windows..
		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			// .. give it to the input handler to process
			GwenInput.ProcessMessage(msg);

			// if it's QUIT then quit..
			if (msg.message == WM_QUIT)
			{
				break;
			}

			// Handle the regular window stuff..
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else
		{
			float ClearColor[4] = { 0.128f, 0.128f, 0.3f, 1.0f };
			// Normal DirectX rendering loop
			g_pd3dDevice->ClearRenderTargetView(g_pRenderTargetView, ClearColor);

			// This is how easy it is to render GWEN!
			pCanvas->RenderCanvas();

			g_pSwapChain->Present(0, 0);
		}
	}

	delete pCanvas;
	delete pSkin;
	delete pRenderer;

	if (g_pRenderTargetView)
	{
		g_pRenderTargetView->Release();
		g_pRenderTargetView = NULL;
	}

	if (g_pSwapChain)
	{
		g_pSwapChain->Release();
		g_pSwapChain = NULL;
	}

	if (g_pd3dDevice)
	{
		g_pd3dDevice->Release();
		g_pd3dDevice = NULL;
	}
}
Ejemplo n.º 12
0
DrawScence::DrawScence(HWND hWnd)
{
	m_hWnd = hWnd;

	CreateD3DDevice();
}
Ejemplo n.º 13
0
//
// Program starts here
//
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, PSTR cmdLine, int showCmd) {	

	g_pHWND = CreateGameWindow();
	CreateD3DDevice();	
	

	MY_UI::DirectX11* renderer = new MY_UI::DirectX11( g_Device, g_DeviceContext );
	MY_UI::cRootWidget* root = new MY_UI::cRootWidget();
	MY_UI::cWidgetSkin* skin = new MY_UI::cWidgetSkin();
	//the MY_UI::Utilities::cInput input    class declared above will clean up MY UI on its destruction so you dont need to free any memory. You can explicitly call MY_UI::DeInit() if you want when the program is shutting down though
	MY_UI::Init(renderer, skin, root);
	MY_UI::Utilities::SetCursor(MY_UI::Utilities::Standard);
	RECT temp;
	GetClientRect( g_pHWND, &temp );
	root->SetSize(temp.right, temp.bottom);

	InitDemo();
	InitScene();

	//
	// Begin the main game loop
	//
	MY_UI::Controls::Text* fpscounter = new MY_UI::Controls::Text(root);
	fpscounter->SetFontSize(20);
	unsigned int framecount = 0;
	unsigned int lasttick = MY_UI::Utilities::GetTime();
	std::string fpsStr, FrameStats;

	MSG msg;
	while( true )
	{
		// Skip out if the window is closed
		if ( !IsWindowVisible( g_pHWND ) )
			break;

		// If we have a message from windows..
		if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
		{
			// if it's QUIT then quit..
			if ( msg.message == WM_QUIT )
				break;

			// Handle the regular window stuff..
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else
		{
			// Normal DirectX rendering loop
				

				framecount++;
				if(MY_UI::Utilities::GetTime() -lasttick  >= 1000){// update
					float fps(static_cast<float>(framecount));
					float msec(1000.0f/fps);
					std::ostringstream outs1;   
					outs1.precision(4);
					outs1<<" FPS: "<<fps<<" MPF: "<<msec;
					fpsStr=outs1.str();
					lasttick=MY_UI::Utilities::GetTime();
					framecount=0;// reset
					std::ostringstream o;
					o<<"Draw Calls: "<<renderer->GetDrawCalls();
					fpscounter->SetText(fpsStr +o.str());
				}
				
	
				float ClearColor[4] = { .2f, .1f, 1.0f, 0.0f };
				
				g_DeviceContext->ClearRenderTargetView( BackBufferRTV, ClearColor );
	
				// This is how easy it is to render

				Render3D();
				root->Draw();
				
				SwapChain->Present(0, 0);

		}
	}
	MY_UI::Safe_Delete(Dummy);// destroy the dummy. This is not absolutely needed because the MY_UI library will clean up all widgets, but I delete it here because the 3d example needs to be shut down before everything else
	SAFE_DELETE(input);// make sure to delete this here. It will call the cleanup code in its destructor
	Cleanup();// clean up the 3d stuff
	HR(SwapChain->SetFullscreenState(false, 0));// this is needed in case full screen is on
	
	RELEASECOM(BackBufferRTV);
	RELEASECOM(SwapChain);
	RELEASECOM(g_DeviceContext);
	RELEASECOM(g_Device);


}
Ejemplo n.º 14
0
int CGraphicsEngine::Initialize( void )
{
	int nResult  = FALSE;
	int nRetCode = FALSE;

	// 初始化输入
	m_pDXInput = DX_Input::GetInstance();
	LOG_FAILD_JUMP(m_pDXInput);

	nRetCode = m_pDXInput->CreateInput(g_hInstance, g_hWnd);
	if (!nRetCode)
	{
		MessageBox(NULL,_T("初始化输入设备失败"),NULL,NULL);
		goto Exit0;
	}

	// 初始化声音
	/*
	m_pDXSoundMgr = DX_SoundManager::GetSoundManager();
	LOG_FAILD_JUMP(m_pDXSoundMgr);

	nRetCode = m_pDXSoundMgr->Init(g_hWnd);
	LOG_FAILD_JUMP(nRetCode);

	nRetCode = m_pDXSoundMgr->SetPrimaryBufferFormat();
	LOG_FAILD_JUMP(nRetCode);
	*/

	// 初始化计时器
	m_pTimer = CTimer::GetInstance();
	LOG_FAILD_JUMP(m_pTimer);

	nRetCode = m_pTimer->InitTime();
	LOG_FAILD_JUMP(nRetCode);

	// 创建3D设备
	nRetCode = CreateD3DDevice(g_hWnd, false);
	LOG_FAILD_JUMP(nRetCode);
	
	// 设置投影矩阵
	SetProjection();

	// 设置视口
	{
		D3DVIEWPORT9 vp = {0, 0, SCREEMWIDTH, SCREEMHEIGH, 0, 1};
		m_pIDirect3DDevice->SetViewport(&vp);

		if (FAILED(D3DXCreateSprite(m_pIDirect3DDevice, &m_pSprite)))
		{
			MessageBox(NULL, "创建精灵接口失败", "警告", MB_OK | MB_ICONINFORMATION);
			goto Exit0;
		}
	}
	
	m_pTextureMgr = TextureMgr::GetInstance();
	LOG_FAILD_JUMP(m_pTextureMgr);

	nRetCode = m_pTextureMgr->Init(m_pIDirect3DDevice);
	LOG_FAILD_JUMP(nRetCode);

	m_pParticleMgr = new CParticleMgr();
	LOG_FAILD_JUMP(m_pParticleMgr);


	nResult = TRUE;
Exit0:
	if (!nResult)
	{
		if (m_pDXInput)
		{
			m_pDXInput->InputRelease();
			m_pDXInput = NULL;
		}
		if (m_pDXSoundMgr)
		{
			m_pDXSoundMgr->Release();
			m_pDXSoundMgr = NULL;
		}
	}
	return nResult;
}