ddraw: Add a test for IDirect3DVertexBuffer7::ProcessVertices.

This commit is contained in:
Stefan Dösinger 2006-04-09 17:10:38 +02:00 committed by Alexandre Julliard
parent 6053d265bc
commit dbdc8c2f65
1 changed files with 359 additions and 5 deletions

View File

@ -2,6 +2,7 @@
* Some unit tests for d3d functions
*
* Copyright (C) 2005 Antoine Chavasse
* Copyright (C) 2006 Stefan Dösinger for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -23,13 +24,32 @@
#include "ddraw.h"
#include "d3d.h"
static LPDIRECTDRAW7 lpDD = NULL;
static LPDIRECT3D7 lpD3D = NULL;
static LPDIRECTDRAWSURFACE7 lpDDS = NULL;
static LPDIRECT3DDEVICE7 lpD3DDevice = NULL;
static LPDIRECTDRAW7 lpDD = NULL;
static LPDIRECT3D7 lpD3D = NULL;
static LPDIRECTDRAWSURFACE7 lpDDS = NULL;
static LPDIRECT3DDEVICE7 lpD3DDevice = NULL;
static LPDIRECT3DVERTEXBUFFER7 lpVBufSrc = NULL;
static LPDIRECT3DVERTEXBUFFER7 lpVBufDest1 = NULL;
static LPDIRECT3DVERTEXBUFFER7 lpVBufDest2 = NULL;
/* To compare bad floating point numbers. Not the ideal way to do it,
* but it should be enought for here */
#define comparefloat(a, b) ( ((a - b) < 0.0001) && ((a-b) > -0.0001) )
static HRESULT (WINAPI *pDirectDrawCreateEx)(LPGUID,LPVOID*,REFIID,LPUNKNOWN);
typedef struct _VERTEX
{
float x, y, z; /* position */
} VERTEX, *LPVERTEX;
typedef struct _TVERTEX
{
float x, y, z; /* position */
float rhw;
} TVERTEX, *LPTVERTEX;
static void init_function_pointers(void)
{
HMODULE hmod = GetModuleHandleA("ddraw.dll");
@ -200,6 +220,339 @@ static void LightTest(void)
ok(rc==DDERR_INVALIDPARAMS, "GetLightEnable returned: %lx\n", rc);
}
static void ProcessVerticesTest()
{
D3DVERTEXBUFFERDESC desc;
HRESULT rc;
VERTEX *in;
TVERTEX *out;
VERTEX *out2;
D3DVIEWPORT7 vp;
D3DMATRIX view = { 2.0, 0.0, 0.0, 0.0,
0.0, -1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 3.0 };
D3DMATRIX world = { 0.0, 1.0, 0.0, 0.0,
1.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 1.0,
0.0, 1.0, 1.0, 1.0 };
D3DMATRIX proj = { 1.0, 0.0, 0.0, 1.0,
0.0, 1.0, 1.0, 0.0,
0.0, 1.0, 1.0, 0.0,
1.0, 0.0, 0.0, 1.0 };
/* Create some vertex buffers */
memset(&desc, 0, sizeof(desc));
desc.dwSize = sizeof(desc);
desc.dwCaps = 0;
desc.dwFVF = D3DFVF_XYZ;
desc.dwNumVertices = 16;
rc = IDirect3D7_CreateVertexBuffer(lpD3D, &desc, &lpVBufSrc, 0);
ok(rc==D3D_OK || rc==E_OUTOFMEMORY, "CreateVertexBuffer returned: %lx\n", rc);
if (!lpVBufSrc)
{
trace("IDirect3D7::CreateVertexBuffer() failed with an error %lx\n", rc);
goto out;
}
memset(&desc, 0, sizeof(desc));
desc.dwSize = sizeof(desc);
desc.dwCaps = 0;
desc.dwFVF = D3DFVF_XYZRHW;
desc.dwNumVertices = 16;
/* Msdn says that the last parameter must be 0 - check that */
rc = IDirect3D7_CreateVertexBuffer(lpD3D, &desc, &lpVBufDest1, 4);
ok(rc==D3D_OK || rc==E_OUTOFMEMORY, "CreateVertexBuffer returned: %lx\n", rc);
if (!lpVBufDest1)
{
trace("IDirect3D7::CreateVertexBuffer() failed with an error %lx\n", rc);
goto out;
}
memset(&desc, 0, sizeof(desc));
desc.dwSize = sizeof(desc);
desc.dwCaps = 0;
desc.dwFVF = D3DFVF_XYZ;
desc.dwNumVertices = 16;
/* Msdn says that the last parameter must be 0 - check that */
rc = IDirect3D7_CreateVertexBuffer(lpD3D, &desc, &lpVBufDest2, 12345678);
ok(rc==D3D_OK || rc==E_OUTOFMEMORY, "CreateVertexBuffer returned: %lx\n", rc);
if (!lpVBufDest2)
{
trace("IDirect3D7::CreateVertexBuffer() failed with an error %lx\n", rc);
goto out;
}
rc = IDirect3DVertexBuffer7_Lock(lpVBufSrc, 0, (void **) &in, NULL);
ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %lx\n", rc);
if(!in) goto out;
/* Check basic transformation */
in[0].x = 0.0;
in[0].y = 0.0;
in[0].z = 0.0;
in[1].x = 1.0;
in[1].y = 1.0;
in[1].z = 1.0;
in[2].x = -1.0;
in[2].y = -1.0;
in[2].z = 0.5;
in[3].x = 0.5;
in[3].y = -0.5;
in[3].z = 0.25;
rc = IDirect3DVertexBuffer7_Unlock(lpVBufSrc);
ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %lx\n", rc);
rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest1, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %lx\n", rc);
rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest2, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %lx\n", rc);
rc = IDirect3DVertexBuffer7_Lock(lpVBufDest1, 0, (void **) &out, NULL);
ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %lx\n", rc);
if(!out) goto out;
/* Check the results */
if( !comparefloat(out[0].x, 128.0 ) ||
!comparefloat(out[0].y, 128.0 ) ||
!comparefloat(out[0].z, 0.0 ) ||
!comparefloat(out[0].rhw, 1.0 ))
{
todo_wine ok(FALSE, "Output 0 vertex is (%f , %f , %f , %f)\n", out[0].x, out[0].y, out[0].z, out[0].rhw);
}
else
{
todo_wine ok(TRUE, "Output 0 vertex is (%f , %f , %f , %f)\n", out[0].x, out[0].y, out[0].z, out[0].rhw);
}
if( !comparefloat(out[1].x, 256.0 ) ||
!comparefloat(out[1].y, 0.0 ) ||
!comparefloat(out[1].z, 1.0 ) ||
!comparefloat(out[1].rhw, 1.0 ))
{
todo_wine ok(FALSE, "Output 1 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
}
else
{
todo_wine ok(TRUE, "Output 1 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
}
if( !comparefloat(out[2].x, 0.0 ) ||
!comparefloat(out[2].y, 256.0 ) ||
!comparefloat(out[2].z, 0.5 ) ||
!comparefloat(out[2].rhw, 1.0 ))
{
todo_wine ok(FALSE, "Output 2 vertex is (%f , %f , %f , %f)\n", out[2].x, out[2].y, out[2].z, out[2].rhw);
}
else
{
todo_wine ok(TRUE, "Output 2 vertex is (%f , %f , %f , %f)\n", out[2].x, out[2].y, out[2].z, out[2].rhw);
}
if( !comparefloat(out[3].x, 192.0 ) ||
!comparefloat(out[3].y, 192.0 ) ||
!comparefloat(out[3].z, 0.25 ) ||
!comparefloat(out[3].rhw, 1.0 ))
{
todo_wine ok(FALSE, "Output 3 vertex is (%f , %f , %f , %f)\n", out[3].x, out[3].y, out[3].z, out[3].rhw);
}
else
{
todo_wine ok(TRUE, "Output 3 vertex is (%f , %f , %f , %f)\n", out[3].x, out[3].y, out[3].z, out[3].rhw);
}
rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest1);
ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %lx\n", rc);
out = NULL;
rc = IDirect3DVertexBuffer7_Lock(lpVBufDest2, 0, (void **) &out2, NULL);
ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %lx\n", rc);
if(!out2) goto out;
/* Small thing without much practial meaning, but I stumbled upon it,
* so let's check for it: If the output vertex buffer has to RHW value,
* The RHW value of the last vertex is written into the next vertex
*/
if( !comparefloat(out2[4].x, 1.0 ) ||
!comparefloat(out2[4].y, 0.0 ) ||
!comparefloat(out2[4].z, 0.0 ) )
{
todo_wine ok(FALSE, "Output 4 vertex is (%f , %f , %f)\n", out2[4].x, out2[4].y, out2[4].z);
}
else
{
todo_wine ok(TRUE, "Output 4 vertex is (%f , %f , %f)\n", out2[4].x, out2[4].y, out2[4].z);
}
rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest2);
ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %lx\n", rc);
out = NULL;
/* Try a more complicated viewport, same vertices */
memset(&vp, 0, sizeof(vp));
vp.dwX = 10;
vp.dwY = 5;
vp.dwWidth = 246;
vp.dwHeight = 130;
vp.dvMinZ = -2.0;
vp.dvMaxZ = 4.0;
rc = IDirect3DDevice7_SetViewport(lpD3DDevice, &vp);
ok(rc==D3D_OK, "IDirect3DDevice7_SetViewport failed with rc=%lx\n", rc);
/* Process again */
rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest1, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %lx\n", rc);
rc = IDirect3DVertexBuffer7_Lock(lpVBufDest1, 0, (void **) &out, NULL);
ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %lx\n", rc);
if(!out) goto out;
/* Check the results */
if( !comparefloat(out[0].x, 133.0 ) ||
!comparefloat(out[0].y, 70.0 ) ||
!comparefloat(out[0].z, -2.0 ) ||
!comparefloat(out[0].rhw, 1.0 ))
{
todo_wine ok(FALSE, "Output 0 vertex is (%f , %f , %f , %f)\n", out[0].x, out[0].y, out[0].z, out[0].rhw);
}
else
{
todo_wine ok(TRUE, "Output 0 vertex is (%f , %f , %f , %f)\n", out[0].x, out[0].y, out[0].z, out[0].rhw);
}
if( !comparefloat(out[1].x, 256.0 ) ||
!comparefloat(out[1].y, 5.0 ) ||
!comparefloat(out[1].z, 4.0 ) ||
!comparefloat(out[1].rhw, 1.0 ))
{
todo_wine ok(FALSE, "Output 1 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
}
else
{
todo_wine ok(TRUE, "Output 1 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
}
if( !comparefloat(out[2].x, 10.0 ) ||
!comparefloat(out[2].y, 135.0 ) ||
!comparefloat(out[2].z, 1.0 ) ||
!comparefloat(out[2].rhw, 1.0 ))
{
todo_wine ok(FALSE, "Output 2 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
}
else
{
todo_wine ok(TRUE, "Output 2 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
}
if( !comparefloat(out[3].x, 194.5 ) ||
!comparefloat(out[3].y, 102.5 ) ||
!comparefloat(out[3].z, -0.5 ) ||
!comparefloat(out[3].rhw, 1.0 ))
{
todo_wine ok(FALSE, "Output 3 vertex is (%f , %f , %f , %f)\n", out[3].x, out[3].y, out[3].z, out[3].rhw);
}
else
{
todo_wine ok(TRUE, "Output 3 vertex is (%f , %f , %f , %f)\n", out[3].x, out[3].y, out[3].z, out[3].rhw);
}
rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest1);
ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %lx\n", rc);
out = NULL;
/* Play with some matrices. */
rc = IDirect3DDevice7_SetTransform(lpD3DDevice, D3DTRANSFORMSTATE_VIEW, &view);
ok(rc==D3D_OK, "IDirect3DDevice7_SetTransform failed");
rc = IDirect3DDevice7_SetTransform(lpD3DDevice, D3DTRANSFORMSTATE_PROJECTION, &proj);
ok(rc==D3D_OK, "IDirect3DDevice7_SetTransform failed");
rc = IDirect3DDevice7_SetTransform(lpD3DDevice, D3DTRANSFORMSTATE_WORLD, &world);
ok(rc==D3D_OK, "IDirect3DDevice7_SetTransform failed");
rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest1, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %lx\n", rc);
rc = IDirect3DVertexBuffer7_Lock(lpVBufDest1, 0, (void **) &out, NULL);
ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %lx\n", rc);
if(!out) goto out;
/* Keep the viewport simpler, otherwise we get bad numbers to compare */
vp.dwX = 0;
vp.dwY = 0;
vp.dwWidth = 100;
vp.dwHeight = 100;
vp.dvMinZ = 1.0;
vp.dvMaxZ = 0.0;
rc = IDirect3DDevice7_SetViewport(lpD3DDevice, &vp);
ok(rc==D3D_OK, "IDirect3DDevice7_SetViewport failed");
/* Check the results */
if( !comparefloat(out[0].x, 256.0 ) || /* X coordinate is cut at the surface edges */
!comparefloat(out[0].y, 70.0 ) ||
!comparefloat(out[0].z, -2.0 ) ||
!comparefloat(out[0].rhw, (1.0 / 3.0)))
{
todo_wine ok(FALSE, "Output 0 vertex is (%f , %f , %f , %f)\n", out[0].x, out[0].y, out[0].z, out[0].rhw);
}
else
{
todo_wine ok(TRUE, "Output 0 vertex is (%f , %f , %f , %f)\n", out[0].x, out[0].y, out[0].z, out[0].rhw);
}
if( !comparefloat(out[1].x, 256.0 ) ||
!comparefloat(out[1].y, 78.125000 ) ||
!comparefloat(out[1].z, -2.750000 ) ||
!comparefloat(out[1].rhw, 0.125000 ))
{
todo_wine ok(FALSE, "Output 1 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
}
else
{
todo_wine ok(TRUE, "Output 1 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
}
if( !comparefloat(out[2].x, 256.0 ) ||
!comparefloat(out[2].y, 44.000000 ) ||
!comparefloat(out[2].z, 0.400000 ) ||
!comparefloat(out[2].rhw, 0.400000 ))
{
todo_wine ok(FALSE, "Output 2 vertex is (%f , %f , %f , %f)\n", out[2].x, out[2].y, out[2].z, out[2].rhw);
}
else
{
todo_wine ok(TRUE, "Output 2 vertex is (%f , %f , %f , %f)\n", out[2].x, out[2].y, out[2].z, out[2].rhw);
}
if( !comparefloat(out[3].x, 256.0 ) ||
!comparefloat(out[3].y, 81.818184 ) ||
!comparefloat(out[3].z, -3.090909 ) ||
!comparefloat(out[3].rhw, 0.363636 ))
{
todo_wine ok(FALSE, "Output 3 vertex is (%f , %f , %f , %f)\n", out[3].x, out[3].y, out[3].z, out[3].rhw);
}
else
{
todo_wine ok(TRUE, "Output 3 vertex is (%f , %f , %f , %f)\n", out[3].x, out[3].y, out[3].z, out[3].rhw);
}
rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest1);
ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %lx\n", rc);
out = NULL;
out:
IDirect3DVertexBuffer7_Release(lpVBufSrc);
IDirect3DVertexBuffer7_Release(lpVBufDest1);
IDirect3DVertexBuffer7_Release(lpVBufDest2);
}
START_TEST(d3d)
{
init_function_pointers();
@ -211,7 +564,8 @@ START_TEST(d3d)
if(!CreateDirect3D()) {
trace("Skipping tests\n");
return;
}
}
LightTest();
ProcessVerticesTest();
ReleaseDirect3D();
}