• Advertisement
Sign in to follow this  

Vertexsize from FVF

This topic is 4439 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

First the topic is a bit misleading but it's the best topic i came up with.. I'm not only trying to get the vertexsize from the FVF but also bit-offsets to get pointers to the other elements of the vertex..(if you haven't understood this right know maybe looking at my code could help). I don't know what is wrong with my code but if i pass D3DFVF_XYZ|D3DFVF_TEX1|D3DFVF_NORMAL to the function it doesn't execute the normal part but some texture stuff(which isn't included here) and the vertex size i get is 44 which isn't right.. it should be 32 anyway, my code:
	//Those -inc s are the offset for the vertexptr to get to the data you want..
	//i.e. :if you want the normal data you can do vertexptr+nromalinc and you have a pointer to it
	int normalinc=0;
	int texcoordinc=0;
	int szfloat=sizeof(float);
	int size=0;
	//test which fvf-code are included in fvf:
	

	if((fvf & D3DFVF_XYZ)==D3DFVF_XYZ)size+=3*sizeof(float);
	else if((fvf & D3DFVF_XYZRHW)==D3DFVF_XYZRHW)size+=4*sizeof(float);
	if((fvf & D3DFVF_NORMAL)==D3DFVF_NORMAL)
	{
		normalinc=size;	
		size+=3*sizeof(float);
	}
	if((fvf & D3DFVF_DIFFUSE)==D3DFVF_DIFFUSE)size+=sizeof(D3DCOLOR);
	if((fvf & D3DFVF_SPECULAR)==D3DFVF_SPECULAR)size+=sizeof(D3DCOLOR);

	if(fvf & D3DFVF_TEX1)
	{
		texcoordinc=size;
		size+=2*sizeof(float);
		
	}

        //Here is the uncompleted code for the other fvfs...



I'm aware of D3DXGetFVFVertexSize but it doesn't help me in this case.. i hope anyone understood what i want and can help me regards, m4gnus [Edited by - m4gnus on December 31, 2005 6:41:12 AM]

Share this post


Link to post
Share on other sites
Advertisement
I understand what you want; it is clear. Have you looked into vertex declarations? These are the replacements for (old) FVFs and do precisely what you are trying to do manually.

Now for the size of D3DFVF_XYZ|D3DFVF_TEX1|D3DFVF_NORMAL. It seems to me this vertex consists of 3 + 2 + 3 floats = 8 floating points. The vertex size would be a multiple of 8 and can therefore never be 36 (rahter 32).

I'm currently looking into your code...

Illco

Share this post


Link to post
Share on other sites
oops ok you're right about the 32bytes...

btw the fvf for D3DFVF_XYZ|D3DFVF_TEX1|D3DFVF_NORMAL was 0x000000112 if i remember right

Share this post


Link to post
Share on other sites
Just a quick guess, but shouldn't this line:

if(fvf & D3DFVF_TEX1)

be

if( (fvf & D3DFVF_TEX1) == D3DFVF_TEX1)


That also seems consistent with the 2 * 4 bytes you get too much (assuming a float is 4 bytes in unmanaged code too)... It may not apply to your problem directly, but it seems to be off anyway...

Share this post


Link to post
Share on other sites
Your code works fine. My test:

#include <stdio.h>
#include <d3dx9.h>

int ComputeFVFSize( DWORD fvf )
{
//Those -inc s are the offset for the vertexptr to get to the data you want..
//i.e. :if you want the normal data you can do vertexptr+nromalinc and you have a pointer to it
int normalinc=0;
int texcoordinc=0;
int szfloat=sizeof(float);
int size=0;
//test which fvf-code are included in fvf:


if((fvf & D3DFVF_XYZ)==D3DFVF_XYZ)size+=3*sizeof(float);
else if((fvf & D3DFVF_XYZRHW)==D3DFVF_XYZRHW)size+=4*sizeof(float);
if((fvf & D3DFVF_NORMAL)==D3DFVF_NORMAL)
{
normalinc=size;
size+=3*sizeof(float);
}
if((fvf & D3DFVF_DIFFUSE)==D3DFVF_DIFFUSE)size+=sizeof(D3DCOLOR);
if((fvf & D3DFVF_SPECULAR)==D3DFVF_SPECULAR)size+=sizeof(D3DCOLOR);

if(fvf & D3DFVF_TEX1)
{
texcoordinc=size;
size+=2*sizeof(float);

}

//Here is the uncompleted code for the other fvfs...

return size;
}

void main( void )
{
DWORD dwFVF = D3DFVF_XYZ|D3DFVF_TEX1|D3DFVF_NORMAL;
printf( "Size of FVF is %d.\n", ComputeFVFSize( dwFVF ) );
}



The program prints:

Size of FVF is 32.


Illco

Share this post


Link to post
Share on other sites
yeah sorry i also discovered that right now :/ the function was called from somewhere else with another fvf ...


regards,
m4gnus

Share this post


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

  • Advertisement