Setting up the constant buffer using SlimDX

后端 未结 1 1175
南旧
南旧 2021-01-25 09:50

I\'ve been following the Microsoft Direct3D11 tutorials but using C# and SlimDX. I\'m trying to set the constant buffer but am not sure how to either create or set it.

I

1条回答
  •  走了就别回头了
    2021-01-25 10:25

    Something similar to this should work:

    var buffer = new Buffer(device, new BufferDescription {
        Usage = ResourceUsage.Default,
        SizeInBytes = sizeof(ConstantBuffer),
        BindFlags = BindFlags.ConstantBuffer
    });
    
    var cb = new ConstantBuffer();
    cb.World = Matrix.Transpose(world);
    cb.View = Matrix.Transpose(view);
    cb.Projection = Matrix.Transpose(projection);
    
    var data = new DataStream(sizeof(ConstantBuffer), true, true);
    data.Write(cb);
    data.Position = 0;
    
    context.UpdateSubresource(new DataBox(0, 0, data), buffer, 0);
    

    0 讨论(0)
提交回复
热议问题