How to know vertex format

Started by
9 comments, last by Illco 18 years, 4 months ago
Given FVF how to know what do vertex consist of?? Is there available function to do it?
Advertisement
The FVF gives exactly what is present in the vertex; just check the bits that are set in the DWORD value to see what is there. The order is predetermined so one FVF value fixes the vertex format.

There is no function but think about it: what would you want such a function to return?

Illco
You might be interested in a recent thread: How to know which fvf codes are in a DWORD

hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

Quote:Original post by Illco
The FVF gives exactly what is present in the vertex; just check the bits that are set in the DWORD value to see what is there. The order is predetermined so one FVF value fixes the vertex format.

There is no function but think about it: what would you want such a function to return?

Illco




Usually , FVF and vertex format is created first. and then according to it vertexbuffer created!

But now:
I have 1. vertexbuffer 2.I know FVF.

I will define a vertex struct

struct vertex
{
D3DXVECTOR3 pos;
.......
}
then I can access vertexbuffer by the struct.
vertex.pos = .......

So how to design the struct only according to FVF? I must will a swith to list all possible vertex struct?
Or there are something better?

Quote:
So how to design the struct only according to FVF?

This is a simple and easy task.
When you decide on a FVF,
for example
D3DFVF_XYZ | D3DFVF_TEX1
You will refer to the documentation to see what it consists of.
e.g.
#define
D3DFVF_XYZ
Description
Vertex format includes the position of an untransformed vertex. This flag cannot be used with the D3DFVF_XYZRHW flag.
Data order and type
float, float, float.

This will give you a clear indication of what order to follow and what data type to use. Matching the given Flexible vertex format you will be able to come to this conclusion

struct VERTEX{  float x, y, z;  float u, v;};


I hope this helps.
Take care.
I mean automaticly create other than manually.

struct vertex {stuff};

Vertex FVFToStruct ( DWORD fvf) {how to do??}
well you could have a struct full of every field for each FVF code. When they give u the FVF u go through each bit and if its there, u assignt hat field whatever u want. otherwise, just zero the memory. Only way I can think of at 3 in the morning...
You can't provide a real dynamic struct. You can however have a vertex's data as a memory block and let a wrapper class calculate the offsets into the data for the content values:

When you've got D3DFVF_XYZ | D3DFVF_TEX1 you know:

A vertex is 3 floats plus 2 floats (20 bytes). The order is defined by DirectX, so the offset for the xyz values is 0, for the texture coordinates it's 12.

Once the offsets for all included members are calculated you can provide accessor methods for reading and setting the values.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

You could also:

1. fill a boost::any with a representitive struct, and provide a safe interface to this (much like what Endurion said).

2. provide an interface I_Vertex and use a factory to build a concrete representation that stores the FVF. In this case, the factory is a "FVF -> I_Vertex* converter".

e.g.:
I_Vertex* vertex = fvf_to_vertex( theFVF );Position pos = vertex->getPosition();TextureCoords coords = vertex->getTextureCoords();


In any case, you will have to think about how to handle errors when the client (e.g.) asks for texture coordinates that aren't provided by the FVF.
derek7 - could you give us some more details on what you are trying to do?

What you've asked/described is a fairly uncommon thing to be doing - it might well be that we can suggest a different/easier way [smile]

As another idea... if you're using ID3DXMesh then you can use ID3DXMesh::CloneMesh() to get just a particular component and read it out as a regular array.

hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

This topic is closed to new replies.

Advertisement