struct CBPerMesh
{
D3DXVECTOR3 ObjectPosition;
D3DXVECTOR3 CameraPosition;
D3DXVECTOR2 CameraZoom;
};
This is the vertex shader (I don't think the pixel shader has anything to do with my problem):
struct VS_INPUT
{
float3 position : POSITION;
float2 texcoord : TEXCOORD;
};
struct VS_OUTPUT
{
float4 position : SV_POSITION;
float2 texcoord : TEXCOORD;
};
cbuffer PerMesh
{
float3 ObjectPosition;
float3 CameraPosition;
float2 CameraZoom;
};
VS_OUTPUT vsMain( VS_INPUT v )
{
VS_OUTPUT o = (VS_OUTPUT)0;
o.position.x = ( v.position.x + CameraPosition.x ) / CameraZoom.x;
o.position.y = ( v.position.y + CameraPosition.y ) / CameraZoom.y;
o.position.z = 0.0f;
o.position.w = 1.0f;
o.texcoord = v.texcoord;
return o;
}
This is how I create the constant buffer:
// setup creation information
D3D11_BUFFER_DESC cbDesc;
cbDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
cbDesc.ByteWidth = sizeof( ConstantBuffer );
cbDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
cbDesc.MiscFlags = 0;
cbDesc.StructureByteStride = 0;
cbDesc.Usage = D3D11_USAGE_DYNAMIC;
// create the buffer
ID3D11Buffer* CBuffer = NULL;
D3DDevice->CreateBuffer( &cbDesc, NULL, &CBuffer );
And this is to update the constant buffer:
// ConstantBuffer is a CBPerMesh
// CBuffer is the ID3D11Buffer*
D3D11_MAPPED_SUBRESOURCE MSData;
if( SUCCEEDED( D3DContext->Map( CBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &MSData ) ) )
{
// copy data over to constant buffer
memcpy_s( MSData.pData, MSData.RowPitch, ConstantBuffer, sizeof( ConstantBuffer ) );
D3DContext->Unmap( CBuffer, 0 );
}
else
return false;
D3DContext->VSSetConstantBuffers( 0, 1, &CBuffer );
return true;
Everything compiles and runs fine, but it seems that only part of the constant buffer is being updated. When I debug it it PIX, it appears that everything has been updated, but the only changes that I visually see is with CameraPosition.y (from CBPerMesh)
Sorry about all the code, but I'm having trouble narrowing down the problem.
Much appreciated.