PDA

View Full Version : DirectX Question


goruka
07-24-2007, 04:46 PM
I want to use separate buffers for the vertex arrays, like in OpenGL. One for vertices, another for normals, another for UV, and finally one for colors.

From what i've been reading, it is possible,but really confusing to me (since every single tutorial and even microsoft docs don't seem to believe people will do that)

Basically, from what I see is that I have to create a VertexBuffer for vertices, another for normals, another for UVs, etc, and when using "setStreamSource" I have to use stream 0, stream 1, stream 2, etc. for each,

yet, i can't seem to figure out how to do this fully. If i render multiple objects, many may lack some arrays (color, UV, etc), that the previous object rendered... then carry the one from the previous object, since i suppose it will be still active... (as in, can it be disabled after rendering? or specify how many am i using?)

So my question is:

-Is it really possible to have streams not containing vertices? (only uv/etc)
-How do I switch streamsources on/off ?
-Where do I specify how many streams am I using?
-What happens if i want to have many UV layers? how do i specify which vertexbuffer with uvs goes to which layer?
-What happens if i have more than one vertex array, normal array (as in, purposedly setting some info twice) just to know what happens...

well, that's basically it, Thanks in advance!

AndyDX
07-25-2007, 04:10 AM
hi, i dont know how vertex array works in OpenGL since iam only using DX.
but i can tell you how to settup different streams and inputs.

first you need a vertex declaration.


D3DVERTEXELEMENT9 declDesc[] =
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
{1, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
{2, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
{0xFF,0,D3DDECLTYPE_UNUSED, 0,0,0}
};
pd3dDevice->CreateVertexDeclaration( declDesc, &pDecl );


the first number of each entry for the declarations says from which stream the input for the declared type comes from.
so for this declarations the position data comes from stream 0 the normals from stream 1 and the texturecoords from 2.

so you can store position, normals and texturecoords in different vertex buffers.
important is just to set the vertexbuffer with the correct streamnumber when you want to display data from it.

pd3dDevice->SetStreamSource( 0, pVBPosition, 0, sizeof(D3DXVECTOR3) );
pd3dDevice->SetStreamSource( 1, pVBNormals, 0, sizeof(D3DXVECTOR3) );
pd3dDevice->SetStreamSource( 2, pVBTexCrd, 0, sizeof(D3DXVECTOR2) );

pd3dDevice->CreateVertexDeclaration( declDesc, &pDecl );


with the SetStreamSource you tell DX from which stream the data comes.
important is here to set the created declaration instead of using the FVF format.

there is some basic informations about how streams and declarations works in the c++ SDK doc.

Andy

goruka
07-27-2007, 12:10 PM
Thanks a lot! I think i have it figured out, i'll give it a try!!