Exemplo n.º 1
0
	HRESULT CompileShaderFromFile( TCHAR* szFileName, LPCSTR szEntryPoint, LPCSTR szShaderModel, ID3DBlob** ppBlobOut, const D3D_SHADER_MACRO* pDefines )
	{
		HRESULT hr = S_OK;

		DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
		#if defined( DEBUG ) || defined( _DEBUG )
			// Set the D3DCOMPILE_DEBUG flag to embed debug information in the shaders.
			// Setting this flag improves the shader debugging experience, but still allows 
			// the shaders to be optimized and to run exactly the way they will run in 
			// the release configuration of this program.
			dwShaderFlags |= D3DCOMPILE_DEBUG;
		#endif

		// compile the shader
		ID3DBlob* pErrorBlob = NULL;
		hr = D3DX11CompileFromFile( szFileName, pDefines, NULL, szEntryPoint, szShaderModel, dwShaderFlags, NULL, NULL, ppBlobOut, &pErrorBlob, NULL );
		if( FAILED(hr) )
		{
			if( pErrorBlob != NULL )
				OutputDebugStringA( ( char* )pErrorBlob->GetBufferPointer() );
			SAFE_DX_RELEASE( pErrorBlob );
			return hr;
		}
		SAFE_DX_RELEASE( pErrorBlob );

		return S_OK;   
	}
Exemplo n.º 2
0
void CDX10Core::OnResize(int width, int height)
{		
	SAFE_DX_RELEASE( m_pRenderTargetView);
	SAFE_DX_RELEASE( m_pDepthStencilView);	
	
	// Resize the swap chain and recreate the render target view.

	HR(m_pSwapChain->ResizeBuffers(1, width, height, DXGI_FORMAT_R8G8B8A8_UNORM, 0));
		
	InitRenderAndDepthStencilTargets( width, height );

	// Set the viewport transform.
	D3D10_VIEWPORT vp;
	vp.TopLeftX = 0;
	vp.TopLeftY = 0;
	vp.Width    = width;
	vp.Height   = height;
	vp.MinDepth = 0.0f;
	vp.MaxDepth = 1.0f;

	m_pDevice->RSSetViewports( 1, &vp );

	InitMatrices(vp.Width, vp.Height);
	
	InitDepthStencilState();

	InitFont();

}
Exemplo n.º 3
0
void CDX10Core::InitBasicEffects()
{
	ID3D10Blob*	pBlobErrors = NULL;
	HRESULT hr = D3DX10CreateEffectFromFile( _T("effects/BasicShaders.fx"),
		NULL, NULL,
		"fx_4_0",
		D3D10_SHADER_ENABLE_STRICTNESS,
		0, m_pDevice,
		NULL, NULL,
		&m_pBasicEffect,
		&pBlobErrors, NULL);
	if ( FAILED ( hr ) )
	{
		UINT size = pBlobErrors->GetBufferSize() + 1;
		TCHAR *szError = new TCHAR[size];
#ifdef UNICODE
		char * pErrorString = (char *)pBlobErrors->GetBufferPointer();		
		mbstowcs(szError, pErrorString, size);
		szError[size - 1] = 0;
#else
		_tcscpy_s(szError, size, pBlobErrors->GetBufferPointer());
#endif
		MessageBox(m_hWnd, szError, _T("DirectX 10 shader Error"), MB_OK );
		SAFE_DX_RELEASE(pBlobErrors);
		delete[] szError;
		exit(1);
	}
	SAFE_DX_RELEASE(pBlobErrors);

	m_pBasicTechnique = m_pBasicEffect->GetTechniqueByName("BasicRender");
	
	m_pViewMatrixEffectVariable			= m_pBasicEffect->GetVariableByName( "View" )->AsMatrix();
	m_pProjectionMatrixEffectVariable	= m_pBasicEffect->GetVariableByName( "Projection" )->AsMatrix();
	m_pWorldMatrixEffectVariable		= m_pBasicEffect->GetVariableByName( "World" )->AsMatrix();
}
Exemplo n.º 4
0
void CDX10Core::SetWireframe(bool bWireframe)
{
	D3D10_RASTERIZER_DESC rasterizerStateDesc;
	m_pRasterizerState->GetDesc(&rasterizerStateDesc);
	rasterizerStateDesc.FillMode = bWireframe ? D3D10_FILL_WIREFRAME: D3D10_FILL_SOLID;
		
	SAFE_DX_RELEASE(m_pRasterizerState);
	m_pDevice->CreateRasterizerState( &rasterizerStateDesc, &m_pRasterizerState);	
}
/**
***************************************************************************************************
*   DX12ImageRenderer::~DX12ImageRenderer
*
*   @brief
*       Destructor.
***************************************************************************************************
*/
DX12ImageRenderer::~DX12ImageRenderer()
{
    SAFE_DX_RELEASE(m_pCmdAllocator);
    SAFE_DX_RELEASE(m_pCmdList);
    SAFE_DX_RELEASE(m_pRootSignatureGraphics);
    SAFE_DX_RELEASE(m_pPipelineStateGraphics);
    SAFE_DX_RELEASE(m_pSrvUavCbHeap);
    SAFE_DX_RELEASE(m_pFence);
    SAFE_DX_RELEASE(m_pConstantBuffer);
    SAFE_DX_RELEASE(m_pInternalRtvHeap);
}
Exemplo n.º 6
0
void CDX10Core::CleanupDevice()
{	

	SAFE_DX_RELEASE( m_pFont );

	SAFE_DX_RELEASE( m_pBasicEffect);

	SAFE_DX_RELEASE( m_pRenderTargetView );
	SAFE_DX_RELEASE( m_pDepthStencilView );
	
	for(int i = 0; i < VBT_COUNT; ++i)
	{
		SAFE_DX_RELEASE( m_pVertexBuffers[i] );
	}
	SAFE_DX_RELEASE( m_pIndexBuffer );

	SAFE_DX_RELEASE( m_pRasterizerState );
	SAFE_DX_RELEASE( m_pDepthStencilState );

	SAFE_DX_RELEASE( m_pSwapChain );		
	SAFE_DX_RELEASE( m_pDevice );
}
Exemplo n.º 7
0
void CDX10Core::InitFont()
{
	// Create font
	if( m_pFont )
		SAFE_DX_RELEASE( m_pFont );

	D3DX10_FONT_DESC fontDesc;
	fontDesc.Height          = 25;
	fontDesc.Width           = 12;
	fontDesc.Weight          = 0;
	fontDesc.MipLevels       = 1;
	fontDesc.Italic          = false;
	fontDesc.CharSet         = DEFAULT_CHARSET;
	fontDesc.OutputPrecision = OUT_DEFAULT_PRECIS;
	fontDesc.Quality         = DEFAULT_QUALITY;
	fontDesc.PitchAndFamily  = DEFAULT_PITCH | FF_DONTCARE;
	_tcscpy_s( fontDesc.FaceName, 32, _T( "Calibri" ) );

	HR( D3DX10CreateFontIndirect( m_pDevice, &fontDesc, &m_pFont ) );
}
/**
***************************************************************************************************
*   DX12ImageRenderer::FreeCaptureAssets
*
*   @brief
*       Destroy per-capture resources.
***************************************************************************************************
*/
void DX12ImageRenderer::FreeCaptureAssets()
{
    SAFE_DX_RELEASE(m_pInternalRT);
    SAFE_DX_RELEASE(m_pPSWriteBuf);
    SAFE_DX_RELEASE(m_pPSWriteBufReadBack);
}