[PATCH] D3DXGetFVFVertexSize implementation

Victor Eremin ErV2005 at rambler.ru
Fri Jan 25 12:16:52 CST 2008


This is a DX8 implementation of D3DXGetFVFVertexSize (i.e. D3DFVF_XYZW is commented out).
I must note that I've encountered a bug in original/natvie D3DXGetFVFVertexSize - it returned
wrong vertex size(one float less than needed(?)) when it was used with D3DFVF_XYZB4.
It was more than a year ago, and I'm not sure if this bug still exists in native D3DX. 
Anyway this bug isn't reproduced here.

Changelog:
    added D3DXGetFVFVertexSize implementation
---
 dlls/d3dx8/d3dx8_main.c |   67 +++++++++++++++++++++++++++++++++++++++++++++-
 dlls/d3dx8/tests/math.c |   19 +++++++++++++
 2 files changed, 84 insertions(+), 2 deletions(-)

diff --git a/dlls/d3dx8/d3dx8_main.c b/dlls/d3dx8/d3dx8_main.c
index c24aedc..a2aa651 100644
--- a/dlls/d3dx8/d3dx8_main.c
+++ b/dlls/d3dx8/d3dx8_main.c
@@ -61,8 +61,71 @@ HRESULT WINAPI D3DXCreateFont(LPDIRECT3DDEVICE8 pDevice, HFONT hFont, LPD3DXFONT
 }
 
 UINT WINAPI D3DXGetFVFVertexSize(DWORD FVF) {
-  FIXME("(void): stub\n");
-  return 0;
+	UINT result = 0;
+	UINT texCount, i;
+	
+	switch (FVF & D3DFVF_POSITION_MASK){
+		case(D3DFVF_XYZ):
+			result += 4*3;
+			break;
+		#if 0
+		//fixme: this is DX8 version of function, and DX8 doesn't have D3DFVF_XYZW
+		case()://D3DFVF_XYZW):
+			result += 4*4;
+			break;
+		#endif
+		case(D3DFVF_XYZRHW):
+			result += 4*4;
+			break;
+		case(D3DFVF_XYZB1):
+			result += 4*4;
+			break;
+		case(D3DFVF_XYZB2):
+			result += 4*5;
+			break;
+		case(D3DFVF_XYZB3):
+			result += 4*6;
+			break;
+		case(D3DFVF_XYZB4): 
+			/*fixme: As I know, original D3DX had an undocumented bug - 
+			D3DXGetFVFVertexSize did not return correct vertex size when used with
+			D3DFVF_XYZB4 (The size returned was one float less, if I remember correctly).
+			This implementation doesn't take that bug into account.*/
+			result += 4*7;
+			break;
+		case(D3DFVF_XYZB5):
+			result += 4*8;
+			break;			
+	};
+	
+	if (FVF & D3DFVF_DIFFUSE)
+		result += 4; 
+	if (FVF & D3DFVF_NORMAL)
+		result += 4*3; 
+	if (FVF & D3DFVF_PSIZE)
+		result += 4; 
+	if (FVF & D3DFVF_SPECULAR)
+		result += 4;
+		
+	texCount = (FVF & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT;
+	for (i = 0; i < texCount; i++){
+		switch((FVF >> (i * 2 + 16))&3){
+			case(D3DFVF_TEXTUREFORMAT1):
+				result += 4;
+				break;
+			case(D3DFVF_TEXTUREFORMAT2):
+				result += 4*2;
+				break;
+			case(D3DFVF_TEXTUREFORMAT3):
+				result += 4*3;
+				break;
+			case(D3DFVF_TEXTUREFORMAT4):
+				result += 4*4;
+				break;				
+		}
+	}
+	
+	return result;
 }
 
 HRESULT WINAPI D3DXAssembleShader(LPCVOID pSrcData, UINT SrcDataLen, DWORD Flags, 
diff --git a/dlls/d3dx8/tests/math.c b/dlls/d3dx8/tests/math.c
index a8471b3..f36cf40 100644
--- a/dlls/d3dx8/tests/math.c
+++ b/dlls/d3dx8/tests/math.c
@@ -1295,6 +1295,24 @@ static void D3X8Vector4Test(void)
     expect_vec4(expectedtrans,gottrans);
 }
 
+void D3DXFVFTest(){
+    DWORD size, requiredSize, i;
+    DWORD testData[][2] = {
+	{4*3, D3DFVF_XYZ}, 
+	{4*(3+3), D3DFVF_XYZ|D3DFVF_NORMAL},
+	{4*(3+3+1), D3DFVF_XYZ|D3DFVF_TEX2|D3DFVF_TEXCOORDSIZE3(0)|D3DFVF_TEXCOORDSIZE1(1)},
+	{4*(4+2), D3DFVF_XYZRHW|D3DFVF_TEX1},
+	{4*(6+3+2), D3DFVF_XYZB3|D3DFVF_NORMAL|D3DFVF_TEX1},
+	{0, 0}
+    };
+    
+    for (i = 0; testData[i][0] != 0; i++){
+	requiredSize = testData[i][0];
+	size = D3DXGetFVFVertexSize(testData[i][1]);
+	ok(size == requiredSize, "Expected: %d, got: %d", requiredSize, size);
+    }
+}
+
 START_TEST(math)
 {
     D3DXColorTest();
@@ -1304,4 +1322,5 @@ START_TEST(math)
     D3X8Vector2Test();
     D3X8Vector3Test();
     D3X8Vector4Test();
+    D3DXFVFTest();
 }
-- 
1.5.2.2


--Boundary-00=_x1imHZtF1gV6Chc--



More information about the wine-patches mailing list