🔒 Locked
About SetStreamSource function
Advertisement
Original Post
Still old question but i want to have exact answer: When I have multiple vertex buffer, how to invoke DrawPrimitive()? For example, I create 2 vertex-buffers(named as pVB1, pVB2). I want to draw 2 Triangles: //now in the render() function if( SUCCEEDED( g_pd3dDevice->BeginScene() ) ) { SetupMatrices(); g_pd3dDevice->SetStreamSource( 0, pVB1, 0, sizeof(CUSTOMVERTEX) ); g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX ); g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 1 ); g_pd3dDevice->SetStreamSource( 1, pVB2, 0, sizeof(CUSTOMVERTEX) ); g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX ); g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 1 ); g_pd3dDevice->EndScene(); } g_pd3dDevice->Present( NULL, NULL, NULL, NULL ); But only first vertex buffer(pVB1) is drawn. Why???
In case of drawing two triangles from different vertex buffers, you don't set buffers as different stream numbers. I don't understand what kind of performance boost you are expecting in this case.
You'll use multiple streams in the case if you need the data from both of the buffers in the _same_ drawing call. For example, having multiple vertex coordinates (which you don't always need) or doing geometry instacing are cases where multiple streams are needed. Otherwise, you'll just use stream 0.
Drawing two triangles is quite bad example for optimizing performance. Of course, you can do it faster by putting both of the triangles in the same vertex buffer and draw them in a single call. This is called batching in which you are trying to minimize the amount of DrawPrimitive calls.
Cheers !
[edit] funny typos ..
You'll use multiple streams in the case if you need the data from both of the buffers in the _same_ drawing call. For example, having multiple vertex coordinates (which you don't always need) or doing geometry instacing are cases where multiple streams are needed. Otherwise, you'll just use stream 0.
Drawing two triangles is quite bad example for optimizing performance. Of course, you can do it faster by putting both of the triangles in the same vertex buffer and draw them in a single call. This is called batching in which you are trying to minimize the amount of DrawPrimitive calls.
Cheers !
[edit] funny typos ..
Well, by default, your FVF vertex format code defines the data to come from stream 0. So, logically, if you set your VB as stream 1 and you use the FVF code, the vertex pipeline doesn't have any data available.
Possibly you could write a vertex declaration for the custom vertex where you define all your data to come from stream 1, but it doesn't really make sense.
Check for the details here:
http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/directx9_c_Dec_2005/Programming_One_or_More_Streams.asp
Cheers!
D3DXMATRIXA16 matWorld;
if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
{
SetupMatrices();
g_pd3dDevice->SetStreamSource( 0, pVB1, 0, sizeof(CUSTOMVERTEX) );
g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 1 );
D3DXMatrixTranslation( &matWorld, 1.0f,1.0f,0.0f);
g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
g_pd3dDevice->SetStreamSource( 1, pVB2, 0, sizeof(CUSTOMVERTEX) );
g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 1 );
g_pd3dDevice->EndScene();
}
g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
D3DXMATRIXA16 matWorld;
if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
{
SetupMatrices();
g_pd3dDevice->SetStreamSource( 0, pVB1, 0, sizeof(CUSTOMVERTEX) );
g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 1 );
D3DXMatrixTranslation( &matWorld, 1.0f,1.0f,0.0f);
g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
g_pd3dDevice->SetStreamSource( 1, pVB2, 0, sizeof(CUSTOMVERTEX) );
g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 1 );
g_pd3dDevice->EndScene();
}
g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
{
SetupMatrices();
g_pd3dDevice->SetStreamSource( 0, pVB1, 0, sizeof(CUSTOMVERTEX) );
g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 1 );
D3DXMatrixTranslation( &matWorld, 1.0f,1.0f,0.0f);
g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
g_pd3dDevice->SetStreamSource( 1, pVB2, 0, sizeof(CUSTOMVERTEX) );
g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 1 );
g_pd3dDevice->EndScene();
}
g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
Hi,
- As I explained in the earlier post, you'll need to use SetVertexDeclaration(...) instead of SetFVF(...) to be able to use other streams.
- Even if you are able to make your code work, it won't be as efficient as using only 1 buffer since vertex buffer switch is a costly operation.
- Can you please explain why this is so important to you ? You have already an exact answer to your original question.
Cheers !
Streams in DX are used to distribute your vertex data (more precisely vertex components) into multiple vertex streams. Fof example, you can put vertex position and normal into one buffer and texture coordinates into another buffer. By setting these two buffers as stream 0 and stream 1 you can combine the position and normal from first buffer and texcoord from second buffer to get complete vertices which are used in the following DrawPrimitive call. This is particularly useful when you want to e.g. combine one set of texcoords with multiple sets of geometry (i can't come up with any other examples right now). Basically said it lets you decompose elements of your vertices into multiple buffers and then combine them to feed the pipeline.
When you just want to draw multiple primitives of the same vertex type, putting them in the same vertex buffer should be the fastest way. Multiple streams are just not designed for that.
When you just want to draw multiple primitives of the same vertex type, putting them in the same vertex buffer should be the fastest way. Multiple streams are just not designed for that.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement