1
我有一個Vertexbuffer與648 VertexPositionNormalTexture元素。這是27個立方體,每個立方體擁有24個頂點。Vertexbuffer Getdata VertexPositionNormalTexture
如果我要訪問的頂點爲我的第一個立方體,我可以寫:
int startIndex = 0;
VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[24];
vertexBuffer.GetData<VertexPositionNormalTexture>(vertices, startIndex, 24);
的問題是,如果我要訪問我的第九立方體(24 * 9 = 216)。我必須寫:
int startIndex = 216;
VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[startIndex + 24];
vertexBuffer.GetData<VertexPositionNormalTexture>(vertices, startIndex, 24);
我必須創建192個額外的插槽只是爲了訪問我的24個元素。因爲vertex.GetData將複製到它從中獲取數據的相同索引。我該怎麼做呢?它將24個元素寫入正確大小的數組中?
所有類,結構和功能,從XNA Framework 4.0中
我沒有保存我的數組,因爲我發現它變廢爲保存相同的數據的兩倍。所以,如果我需要數據,我可以從頂點緩衝中取出數據。那不好嗎? – Blc
從gpu內存中檢索頂點並不常見,如果需要修改頂點,請將它們保存在主內存中...比使用getdata好得多,因爲這樣不會產生垃圾,並且它具有更好的性能...... – Blau