少し問題が発生しました。
TextureVertex
さまざまなタイプの頂点 ( 、ColorVertex
など)を表すクラスまたは構造体が必要です。また、任意の頂点タイプVertex
を作成できるようにする必要があるため、スーパー クラス ( ) も必要です。VertexBuffer
頂点は値型でなければならないので、構造体が必要なようです。
この種の競合は通常、C# でどのように解決されますか?
編集:値型データが必要な理由は、メソッド( http://sharpdx.org/documentation/api/m-sharpdx-direct3d11-buffer-create--1-1 )がこのようにそれを必要とするように見えるからです。これはアンマネージ コードを呼び出し、頂点データは data パラメーターに入ります。
編集 2: いくつかのコードを捨てる
public interface Vertex
{ }
[StructLayout(LayoutKind.Sequential)]
public struct TextureVertex : Vertex
{
private Vector3 _position;
public Vector3 Position { get { return _position; } set { _position = value; } }
private Vector2 _texture;
public Vector2 Texture { get { return _texture; } set { _texture = value; } }
private Vector3 _normal;
public Vector3 Normal { get { return _normal; } set { _normal = value; } }
public TextureVertex(float x, float y, float z, float u, float v)
{
_position = new Vector3(x, y, z);
_texture = new Vector2(u, v);
_normal = new Vector3();
}
}
...
TextureVertex[] vertices = new []
{
new TextureVertex(-1.0f, -1.0f, 0.0f, 0.0f, 1.0f),
new TextureVertex(-1.0f, +1.0f, 0.0f, 0.0f, 0.0f),
new TextureVertex(+1.0f, +1.0f, 0.0f, 1.0f, 0.0f),
new TextureVertex(+1.0f, -1.0f, 0.0f, 1.0f, 1.0f)
};
...
VertexBuffer = Buffer.Create<Vertex>(Graphics.Device, BindFlags.VertexBuffer, vertices);