Blc
Blc

Reputation: 58

Vertexbuffer Getdata VertexPositionNormalTexture

I have a Vertexbuffer with 648 VertexPositionNormalTexture elements. That is 27 cubes and each cube hold 24 vertices.

If I want to access the vertices for my first cube I can write:

int startIndex = 0;

VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[24];

vertexBuffer.GetData<VertexPositionNormalTexture>(vertices, startIndex, 24);

The problem is if I want to access my 9th cube (24*9 = 216). I have to write:

int startIndex = 216;

VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[startIndex + 24];

vertexBuffer.GetData<VertexPositionNormalTexture>(vertices, startIndex, 24);

I have to create 192 extra slots just to access my 24 elements. Because the vertex.GetData will copy to same index it get data from. How do I do so It write my 24 elements to a correct sized array?

All classes, structs and functions are from XNA Framework 4.0

Upvotes: 1

Views: 768

Answers (1)

Blau
Blau

Reputation: 5762

Why you need to use GetData?

Save the reference to your array and work with the array... not with the vertexBuffer...

Upvotes: 1

Related Questions