I am using SharpDX to render 3D graphics and i cannot get to work constant buffer in my shader since it contains an array. Currently it looks like this:
cbuffer cb0 : register(b0)
{
matrix mWorld;
matrix mView;
matrix mProj;
float4 vLightDir[2];
float4 vLightColor[2];
float4 vOutputColor;
}
But how to define a struct in C#, which will be correctly marshalled to such constant buffer in shader? In C# we don't have "excplicit" array initialization, e.g. this line of code i used in C++ will not work in C#:
struct cb0
{
// ...
Vector4 twos[2];// C#: Vector4[] twos;
// ...
}
I always set StructLayout option Pack=16 for my structs for alignment, but HOW to define such struct with C#? i have tried to define struct like this:
struct cb0_t//pack=16
{
public Matrix mWorld;
public Matrix mView;
public Matrix mProj;
public Vector4 vLightDir0;
public Vector4 vLightDir1;
public Vector4 vLightColor0;
public Vector4 vLightColor1;
public Vector4 vOutputColor;
}
Yes, it works with this, but this IS NOT COOL. Thank you, sorry for my english...