Esempio n. 1
0
bool CD3DEffect::SetConstantBuffer(LPCSTR handle, ID3D11Buffer *buffer)
{
  if (m_effect)
  {
    ID3DX11EffectConstantBuffer* effectbuffer = m_effect->GetConstantBufferByName(handle);
    if (effectbuffer->IsValid())
      return (S_OK == effectbuffer->SetConstantBuffer(buffer));
  }
  return false;
}
Esempio n. 2
0
//
// GameCode4_Hlsl_VertexShader::SetupRender                                     - Chapter 15, page 513
//
HRESULT LineDraw_Hlsl_Shader::SetupRender(Scene *pScene)
{
	HRESULT hr = S_OK;

	m_EffectPass->Apply(0, g_pDX11W->GetD3D11DeviceContext());

	g_pDX11W->GetD3D11DeviceContext()->IASetInputLayout(m_pVertexLayout11);
        
	D3D11_MAPPED_SUBRESOURCE MappedResource;

	// ----- Render Target Size ------
	V(g_pDX11W->GetD3D11DeviceContext()->Map(m_pcbRenderTargetSize, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedResource));

	Vec4 * pRenderTargetSize = (Vec4 *)MappedResource.pData;
	pRenderTargetSize->x = (FLOAT)g_pDX11W->GetWindowWidth();
	pRenderTargetSize->y = (FLOAT)g_pDX11W->GetWindowHeight();
	pRenderTargetSize->z = 0.0f;
	pRenderTargetSize->w = 0.0f;

	g_pDX11W->GetD3D11DeviceContext()->Unmap(m_pcbRenderTargetSize, 0);

	// ----- Transform Matricies ------
	V(g_pDX11W->GetD3D11DeviceContext()->Map(m_pcbChangePerFrame, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedResource));

	LineDrawerChangePerFrameBuffer * pChangePerFrame = (LineDrawerChangePerFrameBuffer*)MappedResource.pData;
	Mat4x4 mWorldViewProjection = pScene->GetCamera()->GetWorldViewProjection(pScene);
	D3DXMatrixTranspose(&pChangePerFrame->m_WorldViewProjection, &mWorldViewProjection);

	g_pDX11W->GetD3D11DeviceContext()->Unmap(m_pcbChangePerFrame, 0);

	// ----- Constant Buffers -----
	ID3DX11EffectConstantBuffer* fxRenderTargetCB = m_pEffect->GetConstantBufferByName("cbRenderTarget")->AsConstantBuffer();
	ID3DX11EffectConstantBuffer* fxChangePerFrameCB = m_pEffect->GetConstantBufferByName("cbChangePerFrame")->AsConstantBuffer();
	ID3DX11EffectConstantBuffer* fxDiffuseCB = m_pEffect->GetConstantBufferByName("cbDiffuseColor")->AsConstantBuffer();

	fxRenderTargetCB->SetConstantBuffer(m_pcbRenderTargetSize);
	fxChangePerFrameCB->SetConstantBuffer(m_pcbChangePerFrame);
	fxDiffuseCB->SetConstantBuffer(m_pcbDiffuseColor);

	return S_OK;
}