View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Using a struct + <vector> and input layouts

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1noatom  Members

Posted 02 October 2012 - 02:31 PM

So Let's suppose I have this:

[source lang="cpp"]struct Ball{ XMFLOAT2 position; XMFLOAT2 velocity; std::vector<XMFLOAT2> vertices; AABB box; XMFLOAT4 color;};[/source]

As you can see the Ball struct has a vector<XMFLOAT2> in it called vertices.In "vertices" I'm gonna store the vertexes that compose the whole ball.

Also,notice that AABB is just another struct,there's no point in putting the implementation here.

The problem is (pseudocode):

Ball x;
I fill the "vertices" array with 10 vertexes.

But how do I create a vertex buffer? I mean:

[source lang="cpp"]D3D11_BUFFER_DESC ballBuffer; ballBuffer.Usage = D3D11_USAGE_IMMUTABLE; ballBuffer.ByteWidth = sizeof(SIZEOF WHAT?); ballBuffer.BindFlags = D3D11_BIND_VERTEX_BUFFER; ballBuffer.CPUAccessFlags = 0; ballBuffer.MiscFlags = 0; ballBuffer.StructureByteStride = 0; D3D11_SUBRESOURCE_DATA vinitDataBall; vinitDataBall.pSysMem = ADRESS OF WHAT?; HR(md3dDevice->CreateBuffer(&ballBuffer, &vinitDataBall, &mBallVB));[/source]

Should vinitDataBall.pSysMem = POINT TO WHAT?

And also,what should the ByteWidth be?

And another big problem,how should I implement the input layout?

Edited by noatom, 02 October 2012 - 02:32 PM.

### #2Seabolt  Members

Posted 03 October 2012 - 01:17 PM

Basically:
ballBuffer.ByteWidth = sizeof( YOUR_VERTEX ) * vertices.size();
vinitDataBall.pSysMem = &vertices[0];
Perception is when one imagination clashes with another

### #3MJP  Moderators

Posted 04 October 2012 - 11:34 PM

vinitDataBall.pSysMem = &vertices[0];

You can also do vertices.data() to get a raw pointer to the array (f you're using a recent version of Visual Studio).

Edited by MJP, 04 October 2012 - 11:34 PM.

### #4MaxDZ8  Members

Posted 05 October 2012 - 01:52 AM

Just to point out this example is a bit far from real world usage. In the real world there wouldn't be a Ball structure to start with, there would be a ModelInstance structure using resource ball.mdl or something, and we would pull out the vertices from there.
It's worth noticing that there's no such thing as std::vector vertices. What you really want to have is a std::vector<ConfigurableVertex> vertices. Personally I strongly suggest to use std::vector<unsigned byte>.

In the latter case ballBuffer.ByteWidth = FunctionOf(VertexMaterial, AnimationContext) * 10.

edit: set fonts

Edited by Krohm, 05 October 2012 - 01:52 AM.

Previously "Krohm"

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.