| In|Framez® Papers |
Returns the offset (in bytes) of a vertex component within the structure that resembles its Flexible-Vertex-Format (FVF) code.
DWORD GetFVFComponentOffset( DWORD dwFVF, DWORD dwFVFComponent, BYTE iTexCoordIndex );
The offset (in bytes) of the requested component inside the vertex
structure.
If one of the parameters were invalid, or dwFVFComponent is
not part of dwFVF, then the function fails and the return value
is 0xFFFFFFFF.
The following code snippets show how the function can be used :
Example 1 :
// Define the FVF DWORD anFVF = D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_DIFFUSE; DWORD Offset = 0; Offset = GetFVFComponentOffset(anFVF,D3DFVF_XYZ); // Returns 0 Offset = GetFVFComponentOffset(anFVF,D3DFVF_NORMAL); // Returns 12 Offset = GetFVFComponentOffset(anFVF,D3DFVF_DIFFUSE); // Returns 24 BYTE *pVertexData; // Lock the Vertex Buffer and save pointer to the data in pVertexData // With Offset containing the offset ot the Diffuse component, we'll // manipulate the first vertex's Diffuse pVertexData += Offset; // Move to Diffuse *(DWORD*)pVertexData = D3DCOLOR_ARGB(255,255,0,0); // Opaque Red Vertex
struct CUSTOMVERTEX
{
float x,y,z,rhw; // Transformed Position (16 Bytes)
floay nx,ny,nz; // Normal (12 Bytes)
float u,v; // 2D Texture Coordinates (8 Bytes)
};
// Define FVF for CUSTOMVERTEX
DWORD anFVF = D3DFVF_XYZRHW|D3DFVF_NORMAL|D3DFVF_TEX1|D3DFVF_TEXCOORDSIZE2(0);
DWORD Offset = 0;
Offset = GetFVFComponentOffset(anFVF,D3DFVF_XYZRHW); // Returns 0
Offset = GetFVFComponentOffset(anFVF,D3DFVF_NORMAL); // Returns 16
Offset = GetFVFComponentOffset(anFVF,D3DFVF_DIFFUSE); // Returns 0xFFFFFFFF (Failed)
Offset = GetFVFComponentOffset(anFVF,D3DFVF_TEXCOORDSIZE2(0),0); // Returns 28
struct CUSTOMVERTEX
{
float x,y,z; // Untransformed Position (12 Bytes)
float b1; // One Blending Weight (4 Bytes)
float u3,v3,z3; // 3D Texture Coordinates (12 Bytes)
float u1; // 1D Texture Coordinates (4 Bytes)
float u2,v2; // 2D Texture Coordinates (8 Bytes)
float u4,v4,w4,t4; // 4D Texture Coordinates (16 Bytes)
};
// Define FVF for CUSTOMVERTEX
DWORD anFVF = D3DFVF_XYZB1|D3DFVF_TEX4| /* 4 Texture Coordinates Sets */
D3DFVF_TEXCOORDSIZE3(0)| /* 3D Set */
D3DFVF_TEXCOORDSIZE1(1)| /* 1D Set */
D3DFVF_TEXCOORDSIZE2(2)| /* 2D Set */
D3DFVF_TEXCOORDSIZE4(3); /* 4D Set */
DWORD Offset = 0;
Offset = GetFVFComponentOffset(anFVF,D3DFVF_XYZ); // Returns 0xFFFFFFFF (Failed)
Offset = GetFVFComponentOffset(anFVF,D3DFVF_XYZB1); // Returns 0
Offset = GetFVFComponentOffset(anFVF,D3DFVF_TEXCOORDSIZE3(0),0); // Returns 16
Offset = GetFVFComponentOffset(anFVF,D3DFVF_TEXCOORDSIZE1(1),1); // Returns 28
Offset = GetFVFComponentOffset(anFVF,D3DFVF_TEXCOORDSIZE2(2),2); // Returns 32
Offset = GetFVFComponentOffset(anFVF,D3DFVF_TEXCOORDSIZE4(3),3); // Returns 40
// This will return an error, because there is no 3D Set defined at index 1
Offset = GetFVFComponentOffset(anFVF,D3DFVF_TEXCOORDSIZE3(1),1); // Returns 0xFFFFFFFF (Failed)
struct CUSTOMVERTEX
{
float x,y,z; // Untransformed Position (12 Bytes)
float b1,b2; // Two Blending Weights (8 Bytes)
float u1,v1; // 2D Texture Coordinates (8 Bytes)
float u2,v2; // 2D Texture Coordinates (8 Bytes)
float u3,v3; // 2D Texture Coordinates (8 Bytes)
};
// Define FVF for CUSTOMVERTEX
DWORD anFVF = D3DFVF_XYZB2|D3DFVF_TEX3| /* 3 Texture Coordinates Sets */
D3DFVF_TEXCOORDSIZE2(0)| /* 2D Set */
D3DFVF_TEXCOORDSIZE2(1)| /* 2D Set */
D3DFVF_TEXCOORDSIZE2(2); /* 2D Set */
DWORD Offset = 0;
Offset = GetFVFComponentOffset(anFVF,D3DFVF_XYZB1); // Returns 0xFFFFFFFF (Failed)
Offset = GetFVFComponentOffset(anFVF,D3DFVF_XYZB2); // Returns 0
Offset = GetFVFComponentOffset(anFVF,D3DFVF_TEXCOORDSIZE2(0),0); // Returns 20
Offset = GetFVFComponentOffset(anFVF,D3DFVF_TEXCOORDSIZE2(1),1); // Returns 28
Offset = GetFVFComponentOffset(anFVF,D3DFVF_TEXCOORDSIZE2(2),2); // Returns 36
// This will return an error, because there is no 1D Set defined at index 0
Offset = GetFVFComponentOffset(anFVF,D3DFVF_TEXCOORDSIZE1(0),0); // Returns 0xFFFFFFFF (Failed)