c# - How do Flexible vertex formats definitions define the order of the items in the struct? -


so little confused defined when type:

 vertexformat fvf_format = vertexformat.position | vertexformat.diffuse; 

from reading documentation here: http://msdn.microsoft.com/en-us/library/ms889239.aspx

it seems fvf format defines information stored in struct, not order of items in struct. how directx engine know find position , color components?

or vertexformat meant way signal other classes required vertex?

  struct my_vertex   {     vertexformat fvf_format = vertexformat.position | vertexformat.diffuse;       public float x, y, z;     public int color;      public my_vertex(float x, float y, float z, int color)     {       this.x = -x;       this.y = -y;       this.z = z;       this.color = color;     } 

good question, after few minutes testing, found directx don't care fvf_format definition order, care order of vertex struct, following 2 lines same result.

vertexformat fvf_format = vertexformat.position | vertexformat.diffuse; vertexformat fvf_format = vertexformat.diffuse | vertexformat.position; 

internally, d3dfvf_xyz defined before d3dfvf_diffuse below(d3d9types.h), both above 2 lines value of 0x42. when directx process vertex, may use bit-wise operation such &. example, 0x42(hex) = 01000010(bin), first test d3d_fvf_xyz

(0x42 & 0x002) != 0, bit set, d3dfvf_xyz present! fetch data vertex buffer vertex position. same logic apply other macros.

#define d3dfvf_xyz              0x002 #define d3dfvf_xyzrhw           0x004 #define d3dfvf_xyzb1            0x006 #define d3dfvf_xyzb2            0x008 #define d3dfvf_xyzb3            0x00a #define d3dfvf_xyzb4            0x00c #define d3dfvf_xyzb5            0x00e #define d3dfvf_xyzw             0x4002  #define d3dfvf_normal           0x010 #define d3dfvf_psize            0x020 #define d3dfvf_diffuse          0x040 

this means must define vertex in following order, first position, , diffuse(the order depends on macro definitions above).this true when fill in data of vertex buffer.

note: above conclusion based on test, , didn't find documents this, can test own code see whether true.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -