Configurando o buffer constante usando o SlimDX
Eu tenho seguido os tutoriais do Microsoft Direct3D11, mas usando C # e SlimDX. Estou tentando definir o buffer constante, mas não sei como criá-lo ou defini-lo.
Estou simplesmente tentando definir três matrizes (mundo, visão e projeção) usando um buffer constante, mas estou lutando em todas as etapas, criação, entrada de dados e passando para o shader.
O HLSL no MSDN (que eu essencialmente copiei) é:
cbuffer ConstantBuffer : register( b0 )
{
matrix World;
matrix View;
matrix Projection;
}
O código C ++ no MSDN é:
ID3D11Buffer* g_pConstantBuffer = NULL;
XMMATRIX g_World;
XMMATRIX g_View;
XMMATRIX g_Projection;
//set up the constant buffer
D3D11_BUFFER_DESC bd;
ZeroMemory( &bd, sizeof(bd) );
bd.Usage = D3D11_USAGE_DEFAULT;
bd.ByteWidth = sizeof(ConstantBuffer);
bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
bd.CPUAccessFlags = 0;
if( FAILED(g_pd3dDevice->CreateBuffer( &bd, NULL, &g_pConstantBuffer ) ) )
return hr;
//
// Update variables
//
ConstantBuffer cb;
cb.mWorld = XMMatrixTranspose( g_World );
cb.mView = XMMatrixTranspose( g_View );
cb.mProjection = XMMatrixTranspose( g_Projection );
g_pImmediateContext->UpdateSubresource( g_pConstantBuffer, 0, NULL, &cb, 0, 0 );
Alguém sabe como traduzir isso para SlimDX? Ou se alguém conhece algum tutorial ou recurso do SlimDX que também seria útil.
Obrigado.