Jump to content
  • Advertisement
Sign in to follow this  
poigwym

Multi Vertex Buffer And Inputlayout

This topic is 786 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hellow!

I'm going to do skin mesh, I don't know whether I 'm in the right way.

Here's the code:

struct Vertex1 
{

  float3 pos;

  float3 normal;

  float2 texcoord;

};

 

struct Vertex2 
{

  float4 weights;

  float4 ids;
};

 

And I have 2 vertex stream,  std::vector<Vertex1> v1,  std::vector<Vertex2> v2, then I use these 2 stream to create two vertex buffer  vb1 and vb2;

The question is : 

How to set vertex buffer?   VSSetVertexBuffer( 0, 1, &vb1);   VSSetVertexBuffer( 1, 1, &vb2);

How big the stride ?  sizeof(Vertex1) + sizeof(Vertex2) ?

 

Another question is :

If I want to combine the two kind of vertex, how can I do ? 

 

The new Vertex look like this: 

struct Vertex
{

  float3 pos;

  float3 normal;

  float2 texcoord;

  float4 weights;

  float4 ids;
};

If the mesh is not skined, I just use pos,normal,texcoord,   can I set the stride to sizeof(pos) + sizeof(normal) + sizeof(texcoord)?  and use a input layout with 3 elements?

When the mesh is skined, the whole Vertex will be used, and the input layout will be 5 elements.

 

 

 

 

Share this post


Link to post
Share on other sites
Advertisement

Yep, that will set them to slots 0 and 1.

 

The stride is the number of bytes to advance in the data stream to reach the data for the next vertex.

Your first set of attributes would use sizeof(Vertex1) and the second set would use sizeof(Vertex2). You'd also make sure to specify each attrib as coming from stream 0 or 1 (via the InputSlot field in D3D11_INPUT_ELEMENT_DESC).

 

As for the second question, yes, you can specify just 3 attributes, but, no, if you lie about the stride then the GPU can't iterate through the buffer correctly.

Edited by Hodgman

Share this post


Link to post
Share on other sites

In D3D10+, which I assume you're using based on the API calls used, you would combine these into a single call, like so:

 

ID3D11Buffer *buffers[] = {vb1, vb2};

UINT strides[] = {sizeof (vertex1), sizeof (vertex2)};

UINT offsets[] = {0, 0}; // assume - may be different

context->IASetVertexBuffers (0, 2, buffers, strides, offsets);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!