Sign in to follow this  
Adriano

get vertex data from FVF desc

Recommended Posts

Adriano    122
Hello! Is there a way to get vertex data from a vertex buffer knowing only the vertex format description? I mean: if I have some vertices and I know their description is like D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_DIFFUSE|D3DFVF_TEXCOORD1 how do I retrieve the normal and position vectors, the diffuse D3DCOLOR and the two floats representing the texture U and V? Any ideas would be appreciated.

Share this post


Link to post
Share on other sites
Evil Steve    2017
The FVF tells D3D (and you) not only want items are in a vertex, but also what oder they're in. The position has to come first, then the normals, then the diffuse, then the texture coordinates (It's defined in the SDK docs, it just so happens that's the order the bits are put in (which is good)).

Assuming you lock the vertex buffer and get a void* pData back:

void* pData; // From Lock()
BYTEt* pBytes = (BYTE*)pData;

for(size_t i=0; i<num_vertices; ++i)
{
D3DXVECTOR3 vPos = *(D3DXVECTOR3*)(pBytes+0);
D3DXVECTOR3 vNormal = *(D3DXVECTOR3*)(pBytes+12);
DWORD dwColour = *(DWORD*)(pBytes+12+12);
float tu = *(float*)(pBytes+12+12+4);
float tv = *(float*)(pBytes+12+12+4+4);

// Skip to next vertex
pBytes += 12+12+4+4+4;
}


Share this post


Link to post
Share on other sites
jollyjeffers    1570
Easiest way is to have a declared struct that you can cast the data to, but thats obviously a bit limited.

Instead, probably best to cast it bytes and walk through it manually using various memcpy_s() tricks.

The important thing to note is that they are in a specific order:



The above diagram is from some old DX8 documentation, but it should still be correct.

hth
Jack

Share this post


Link to post
Share on other sites
Wixner    163
well.. lock you vertexbuffer and copy the data

[source lang = "cpp"]

void* pVertexData = 0;
m_pVertexBuffer->Lock( 0, 0, reinterpret_cast < void** >( &pVertexData ), 0 );
// your data is now stored, according to the D3DFVF inside pVertexData

m_pVertexBuffer->Unlock();




Omg - two answers within.. like... 30secs? :)

Share this post


Link to post
Share on other sites
Adriano    122
Well thank you all for the rapid and exaustive replies.
Evil steve, that is exactly the code I was trying to write!
And jollyjeffers, that was what I needed to write it!
:)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this