2012-03-03 84 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