コード例 #1
0
//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
bool Renderer::Present()
{
	HRESULT hr;

	// ガンマ
	if (m_isSRGBMode)
	{
		IDirect3DSwapChain9* swapChain = nullptr;
		m_d3d_device->GetSwapChain(0, &swapChain);
		
		hr = swapChain->Present(nullptr, nullptr, nullptr, nullptr, D3DPRESENT_LINEAR_CONTENT);
		
		ES_SAFE_RELEASE(swapChain);
	}
	else
	{
		hr = m_d3d_device->Present(NULL, NULL, NULL, NULL);
	}

	switch ( hr )
	{
		// ドライバ内部の意味不明なエラー
	case D3DERR_DRIVERINTERNALERROR:
		return false;

		// デバイスロスト
	case D3DERR_DEVICELOST:
		while ( FAILED( hr = m_d3d_device->TestCooperativeLevel() ) )
		{
			switch ( hr )
			{
				// デバイスロスト
			case D3DERR_DEVICELOST:
				::SleepEx( 1000, true );
				break;
				// デバイスロスト:リセット可
			case D3DERR_DEVICENOTRESET:
				ResetDevice();
				break;
			}
		}
		break;
	}

	return true;
}
コード例 #2
0
ファイル: D3DRenderer.cpp プロジェクト: Mismael/OtterUI
/* Called when a drawing pass has ended
 */
void D3DRenderer::OnDrawEnd()
{
	mDeviceLost = false;

	mD3DDevice->SetSamplerState(0, D3DSAMP_MIPMAPLODBIAS, 0);
	mD3DDevice->EndScene();

	HRESULT result = 0;

	result = mD3DDevice->TestCooperativeLevel();
	if(result == D3DERR_DEVICELOST)
		return;

	if(result == D3DERR_DEVICENOTRESET)
	{
		mDeviceLost = true;

		// Release the existing swap chains
		SwapChainMap::iterator swapChainIt = mSwapChains.begin();
		for(; swapChainIt != mSwapChains.end(); swapChainIt++)
		{
			IDirect3DSwapChain9* pSwapChain = swapChainIt->second.mD3DSwapChain;
			if(pSwapChain)
			{
				pSwapChain->Release();
			}
		}

		// Release the shaders
		ShaderMap::iterator shaderIt = mShaders.begin();
		for(; shaderIt != mShaders.end(); shaderIt++)
		{
			(*shaderIt).second.mEffect->Release();
		}

		// Release the vbuffer
		mVertexBuffer->Release();
		mVertexBuffer = NULL;

		// Release the vertex decl
		mVertexDeclaration->Release();
		mVertexDeclaration = NULL;

		// Reset the device
		D3DPRESENT_PARAMETERS d3dpp;
		GetPresentParams(d3dpp);   
		HRESULT hr = mD3DDevice->Reset(&d3dpp);
		if(FAILED(hr))
		{
			printf("FAILED\n");
		}

		// Recreate the swap chains
		swapChainIt = mSwapChains.begin();
		for(; swapChainIt != mSwapChains.end(); swapChainIt++)
		{
			SwapChain swapChain = swapChainIt->second;
			CreateContext(swapChain.mWindow, swapChain.mWidth, swapChain.mHeight, swapChainIt->first);
		}

		// Create the Vertex Buffer
		CreateBuffers();

		// Recreate the shaders
		ShaderMap tmp = mShaders;
		mShaders.clear();

		CreateShaders();

		shaderIt = tmp.begin();
		for(; shaderIt != tmp.end(); shaderIt++)
		{
			Shader& shader = shaderIt->second;
			if(shader.mSource != "")
				LoadShader(shader.mName.c_str(), shader.mSource.c_str());
		}

		// By setting mContext to zero, we force the back-buffer changes in the next frame
		long oldContext = mContext;
		mContext = 0;
		SetContext(oldContext);
	}

	SwapChainMap::iterator it = mSwapChains.find(mContext);
	if(it != mSwapChains.end())
	{
		IDirect3DSwapChain9* pSwapChain = it->second.mD3DSwapChain;
		if(pSwapChain)
			result = pSwapChain->Present(NULL, NULL, NULL, NULL, 0);
	}
}