2012-03-03 79 views
2

我目前正在尝试进行自定义顶点声明。XNA 4.0自定义顶点声明

其中一个位置,颜色和整数传递给效果。我有问题确定什么枚举的VertexElementUsage将用于传递一个整数,以及如何确定声明VertexElements时的偏移量?

public readonly static VertexDeclaration VertexDeclaration = new VertexDeclaration 
{ 
    new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0), 
    new VertexElement(12, VertexElementFormat.Color, VertexElementUsage.Color, 0), 
    new VertexElement(?, VertexElementFormat.Byte4, ?, 0) 
}; 

(注意?在过去VertexElement)

回答

2

这将是Vector2的尺寸+颜色的大小。 基本上这样想,
在一个正常的数组中,只有一种类型的对象,所以知道要跳转到下一个项目有多少。
这里有所不同,因为它们都有不同的尺寸。
使用的sizeof()是蛮好的,所以它会是这样:

public readonly static VertexDeclaration VertexDeclaration = new VertexDeclaration 
{ 
    new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0), 
    new VertexElement(sizeof(Vector3), VertexElementFormat.Color, VertexElementUsage.Color, 0), 
    new VertexElement(sizeof(Vector3)+sizeof(Color), VertexElementFormat.Byte4, ?, 0) 
}; 

或相似。

否则,你可以找到一个颜色对象的大小,并将其添加到Vector3对象的大小(这将是偏移量)。

+0

那VertexElementUsage怎么样? – William 2012-03-03 03:51:20

+0

任何你想要的。在您的HLSL效果中,可以通过您所说的任何用途来访问数据。 – 2012-03-03 03:52:00

+0

例如VertexElementUsage.Position意味着你可以通过“POSITION0”(或类似的,我不使用HLSL很多,但这是使用部分的全部点)在你的效果里面包含的数据 – 2012-03-03 03:52:45