This is the function where I set the buffer:
[spoiler]
bool CShader::CreateConstantBuffers(ID3D11Device *pDev)
{
D3D11_BUFFER_DESC matrixDesc;
matrixDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
matrixDesc.ByteWidth = sizeof(MatrixType);
matrixDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
matrixDesc.MiscFlags = 0;
matrixDesc.Usage = D3D11_USAGE_DYNAMIC;
matrixDesc.StructureByteStride = 0;
if ( FAILED(pDev->CreateBuffer(&matrixDesc, 0, &pMatrixBuffer)) ) return
::Error(L"Unable to create constant buffer");
return true;
}
[/spoiler]This two functions do the rendering (the last one is the problem):
[spoiler]
bool CShader::RenderObject(ID3D11DeviceContext *pDevCon, ID3D11Device *pDev,
CModel *model, CCamera *camera, unsigned int stride, unsigned int offset)
{
// Send information to the video card
pDevCon->IASetVertexBuffers(0, 1, model->ppGetVertexBuffer(), &stride, &offset);
pDevCon->IASetIndexBuffer(model->pGetIndexBuffer(), DXGI_FORMAT_R32_UINT, 0);
pDevCon->IASetInputLayout(pInputLayout);
if (! SetShaderVariables(pDevCon, model, 0, camera, RENDER_MODE_MODEL) ) return false;
pDevCon->DrawIndexed(model->GetNumIndices(), 0, 0);
return true;
}
bool CShader::SetShaderVariables(ID3D11DeviceContext *pDevCon, CModel *model, CSprite *sprite, CCamera *camera, unsigned int renderMode)
{
D3D11_MAPPED_SUBRESOURCE mappedSubResource;
if ( FAILED(pDevCon->Map(pMatrixBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedSubResource)) )
return ::Error(L"Could not lock the buffer");
MatrixType *pData = (MatrixType*)mappedSubResource.pData;
pData->World = model->worldMatrix;
pData->View = camera->viewMatrix;
pData->Projection = camera->projectionMatrix;
pDevCon->Unmap(pMatrixBuffer, 0);
pDevCon->VSSetConstantBuffers(0, 1, &pMatrixBuffer);
pDevCon->VSSetShader(pVertexShader, 0, 0);
pDevCon->PSSetShader(pPixelShader, 0, 0);
return true;
}
[/spoiler]This is my matrix struct:
[spoiler]
struct MatrixType
{
D3DXMATRIX World;
D3DXMATRIX View;
D3DXMATRIX Projection;
};
[/spoiler]And this is my shader:
[spoiler]
cbuffer cbPerObj : register ( b0 )
{
matrix World : packoffset ( c0 );
matrix View : packoffset ( c4 );
matrix Projection : packoffset ( c8 );
}
struct VS_INPUT
{
float4 Pos : POSITION;
float3 Normal : NORMAL;
float2 TexCoord : TEXCOORD;
};
struct PS_INPUT
{
float4 Pos : SV_POSITION;
float2 TexCoord : TEXCOORD0;
float3 Normal : NORMAL;
float4 Color : COLOR0;
};
PS_INPUT VS( VS_INPUT input )
{
input.Pos.w = 1.0f;
PS_INPUT output = (PS_INPUT)0;
output.Pos = mul( input.Pos, World );
output.Pos = mul( output.Pos, View );
output.Pos = mul( output.Pos, Projection );
output.TexCoord = input.TexCoord;
return output;
}
float4 PS( PS_INPUT input ) : SV_TARGET
{
return float4(1.0f, 0.0f, 0.0f, 1.0f);
}
[/spoiler]Here's some PIX info
[spoiler]
[/spoiler]
Thanks in advance.