   How to know vertex format
  Given FVF how to know what do vertex consist of??Is there available function to do it?   
  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 DWORDhthJack   ;Quote:Original post by IllcoThe 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?IllcoUsually , 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 structstruct 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 exampleD3DFVF_XYZ | D3DFVF_TEX1You will refer to the documentation to see what it consists of.e.g.#defineD3DFVF_XYZDescriptionVertex format includes the position of an untransformed vertex. This flag cannot be used with the D3DFVF_XYZRHW flag.Data order and typefloat, 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 conclusionstruct 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.;  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.hthJack   