Jump to content
  • Advertisement
Sign in to follow this  
derek7

How to know vertex format

This topic is 4862 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
I mean automaticly create other than manually.

struct vertex {stuff};

Vertex FVFToStruct ( DWORD fvf) {how to do??}

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!