Jump to content
  • Advertisement
Sign in to follow this  
spirit bomb

Using Multiple Vertex Buffers... Is Killing Me

This topic is 2911 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

Hello!

I cannot, for the life of me, make more than one vertex buffer function. I believe I know the problem, but due to a mixture of google failing me and poor DirectX documentation, I cannot solve this via teh interweb. The problem, i believe, is in the streamsource id.

This is how i set up my vertex buffer...



LPDIRECT3DVERTEXBUFFER9 m_pTerrainVB = NULL; //vertex buffer
LPDIRECT3DINDEXBUFFER9 m_pTerrainIB = NULL; //index buffer

d3ddev->CreateVertexBuffer(sizeof(CUSTOMVERTEX)*m_dwTerrainVertices,
D3DUSAGE_WRITEONLY,
CUSTOMFVF,
D3DPOOL_MANAGED,
&m_pTerrainVB,
NULL);

m_pTerrainVB->Lock(0,0,(void**)&pVertexData,0);
memcpy(pVoid, vertices, sizeof(vertices));
m_pTerrainVB->Unlock();

So when i make the call to display the vertex buffer...

d3ddev->SetStreamSource(0, m_pTerrainVB, 0, sizeof(CUSTOMVERTEX));
d3ddev->SetIndices(m_pTerrainIB);
d3ddev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, TOTAL_VERTICES, 0, TOTAL_POLY);

... only the first vertex buffer will be displayed. How would I go about making this to operate with more than one vertex buffer?

The First parameter of SETStreamSource() confuses me. I never told my direct3d device what the stream source id my vertex buffers should corrospond with. How would i set the number of their id?

Share this post


Link to post
Share on other sites
Advertisement
hi, the assignment is done via SetStreamSource. For e.g. in your code when you call:

d3ddev->SetStreamSource(0, m_pTerrainVB, 0, sizeof(CUSTOMVERTEX));

you are setting m_pTerrainVB to be in stream 0. How the stream are used depends on your FVF or VertexDeclaration. The FVF and VertexDeclaration tells directx that for a particular set of vertices obtain the data from the following sources. Hence if you set your VertexDeclaration to:


D3DVERTEXELEMENT9 vertexElement = {
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
{1, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0}};


this tell d3d that when taking the data for a vertex, obtain the position from stream 0, and obtain the normal from stream 1. You set the stream data using the SetStreamSource method

Hope this help you

Share this post


Link to post
Share on other sites
THANK YOU MUCH! (I so rated you up)

That does help very much. Yet I am a bit of a slow learner haha...
How would one go about using this with your selected FVF? For example:

If I wanted to set up 2 vertex buffers with the same FVF, specifically...

//
struct CUSTOMVERTEX {FLOAT X, Y, Z; D3DVECTOR NORMAL;};
#define CUSTOMFVF (D3DFVF_XYZ | D3DFVF_NORMAL)
//

... would I do something like what follows:

d3ddev->SetStreamSource(0, vertex_Buf_ONE, 0, sizeof(CUSTOMVERTEX));
d3ddev->SetStreamSource(1, vertex_Buf_TWO, 0, sizeof(CUSTOMVERTEX));

D3DVERTEXELEMENT9 vertexElement_ONE = {
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0}};

D3DVERTEXELEMENT9 vertexElement_TWO = {
{1, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0}};

And then i would somehow attach the vertexElement and the streamsource...
I feel a bit lost. Would I want to declare a vertex element in the init stage, or once per frame. I use the SetStreamSource() once per frame already, so that is why I ask.

Sorry if I am asking dumb questions, all my game programming experience is in 2d.

Thank you.



Share this post


Link to post
Share on other sites
You need to use SetStreamSource every time you want to change the Vertex buffer that is used to render an object. If you have one buffer per object you need to call it for every object.

Multiple stream sources are used when you split your vertex data for one object in multiple parts. Like one for the position, another one for the colors and so on.

The vertex elements are used to describe how your vertex buffers are structured. Look for CreateVertexDeclaration and SetVertexDeclaration how to use them.

Share this post


Link to post
Share on other sites
WOW, I feel stupid. It would seem that I actually know less than I thought I did. My notions of what streams were was completely incorrect. Thank you for pointing me in the right direction.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!