D3D10 Constant buffer not working

半腔热情 提交于 2019-12-12 01:45:36

问题


I am using a constant buffer to transfer data to my pixel shader

The problem is that the buffer contains 0s in the shader during runtime for x, y, z, and w of the float4 member, regardless of what data is updated to the buffer

Structure definitions are as follows:

// (C++)
struct Buffer
{
    XMMATRIX mvp_;
    XMFLOAT4 rgba_;
    int usemvp_;
};


// HLSL
cbuffer Buffer : register( b0 )
{
    matrix mvp_;
    float4 rgba_;
    int usemvp_;
};

Any help is much appreciated


回答1:


You need to pad your struct to make it 16 byte aligned.

// (C++)
struct Buffer
{
    XMMATRIX mvp_;
    XMFLOAT4 rgba_;
    int usemvp_;
    float padding[3];
};

Also you have to make sure that you are setting the constant buffer into the correct shader stage, ie VSSetConstantBuffers vs PSSetConstantBuffers.



来源:https://stackoverflow.com/questions/14782061/d3d10-constant-buffer-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!