static void test_create_line(IDirect3DDevice9* device) { HRESULT hr; LPD3DXLINE line = NULL; LPDIRECT3DDEVICE9 return_device; D3DXMATRIX world, identity, result; FLOAT r11, r12, r13, r14; ULONG ref; /* Arbitrary values for matrix tests. */ r11 = 0.1421; r12 = 0.2114; r13 = 0.8027; r14 = 0.4587; hr = D3DXCreateLine(NULL, &line); ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3D_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL); hr = D3DXCreateLine(device, NULL); ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3D_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL); hr = D3DXCreateLine(device, &line); ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr); if (FAILED(hr)) { return; } hr = ID3DXLine_GetDevice(line, NULL); ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3D_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL); hr = ID3DXLine_GetDevice(line, &return_device); ok(hr == D3D_OK, "Got result %x, expected %x (D3D_OK)\n", hr, D3D_OK); ok(return_device == device, "Expected line device %p, got %p\n", device, return_device); D3DXMatrixIdentity(&world); D3DXMatrixIdentity(&identity); S(U(world))._11 = r11; S(U(world))._12 = r12; S(U(world))._13 = r13; S(U(world))._14 = r14; hr = IDirect3DDevice9_SetTransform(device, D3DTS_WORLD, &world); ok(hr == D3D_OK, "Got result %x, expected %x (D3D_OK)\n", hr, D3D_OK); hr = ID3DXLine_Begin(line); ok(hr == D3D_OK, "Got result %x, expected %x (D3D_OK)\n", hr, D3D_OK); hr = IDirect3DDevice9_GetTransform(device, D3DTS_WORLD, &result); ok(hr == D3D_OK, "Got result %x, expected %x (D3D_OK)\n", hr, D3D_OK); expect_mat(&identity, &result); hr = ID3DXLine_End(line); ok(hr == D3D_OK, "Got result %x, expected %x (D3D_OK)\n", hr, D3D_OK); hr = IDirect3DDevice9_GetTransform(device, D3DTS_WORLD, &result); ok(hr == D3D_OK, "Got result %x, expected %x (D3D_OK)\n", hr, D3D_OK); expect_mat(&world, &result); ref = IDirect3DDevice9_Release(return_device); ok(ref == 2, "Got %x references to device %p, expected 2\n", ref, return_device); ref = ID3DXLine_Release(line); ok(ref == 0, "Got %x references to line %p, expected 0\n", ref, line); }
static void test_ID3DXSprite(IDirect3DDevice9 *device) { ID3DXSprite *sprite; IDirect3D9 *d3d; IDirect3DDevice9 *cmpdev; IDirect3DTexture9 *tex1, *tex2; D3DXMATRIX mat, cmpmat; D3DVIEWPORT9 vp; RECT rect; D3DXVECTOR3 pos, center; HRESULT hr; IDirect3DDevice9_GetDirect3D(device, &d3d); hr = IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_DYNAMIC, D3DRTYPE_TEXTURE, D3DFMT_A8R8G8B8); IDirect3D9_Release(d3d); ok (hr == D3D_OK, "D3DFMT_A8R8G8B8 not supported\n"); if (FAILED(hr)) return; hr = IDirect3DDevice9_CreateTexture(device, 64, 64, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex1, NULL); ok (hr == D3D_OK, "Failed to create first texture (error code: %#x)\n", hr); if (FAILED(hr)) return; hr = IDirect3DDevice9_CreateTexture(device, 32, 32, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex2, NULL); ok (hr == D3D_OK, "Failed to create second texture (error code: %#x)\n", hr); if (FAILED(hr)) { IDirect3DTexture9_Release(tex1); return; } /* Test D3DXCreateSprite */ hr = D3DXCreateSprite(device, NULL); ok (hr == D3DERR_INVALIDCALL, "D3DXCreateSprite returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); hr = D3DXCreateSprite(NULL, &sprite); ok (hr == D3DERR_INVALIDCALL, "D3DXCreateSprite returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); hr = D3DXCreateSprite(device, &sprite); ok (hr == D3D_OK, "D3DXCreateSprite returned %#x, expected %#x\n", hr, D3D_OK); /* Test ID3DXSprite_GetDevice */ hr = ID3DXSprite_GetDevice(sprite, NULL); ok (hr == D3DERR_INVALIDCALL, "GetDevice returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); hr = ID3DXSprite_GetDevice(sprite, &cmpdev); /* cmpdev == NULL */ ok (hr == D3D_OK, "GetDevice returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_GetDevice(sprite, &cmpdev); /* cmpdev != NULL */ ok (hr == D3D_OK, "GetDevice returned %#x, expected %#x\n", hr, D3D_OK); IDirect3DDevice9_Release(device); IDirect3DDevice9_Release(device); /* Test ID3DXSprite_GetTransform */ hr = ID3DXSprite_GetTransform(sprite, NULL); ok (hr == D3DERR_INVALIDCALL, "GetTransform returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); hr = ID3DXSprite_GetTransform(sprite, &mat); ok (hr == D3D_OK, "GetTransform returned %#x, expected %#x\n", hr, D3D_OK); if(SUCCEEDED(hr)) { D3DXMATRIX identity; D3DXMatrixIdentity(&identity); check_mat(mat, identity); } /* Test ID3DXSprite_SetTransform */ /* Set a transform and test if it gets returned correctly */ U(mat).m[0][0]=2.1f; U(mat).m[0][1]=6.5f; U(mat).m[0][2]=-9.6f; U(mat).m[0][3]=1.7f; U(mat).m[1][0]=4.2f; U(mat).m[1][1]=-2.5f; U(mat).m[1][2]=2.1f; U(mat).m[1][3]=5.5f; U(mat).m[2][0]=-2.6f; U(mat).m[2][1]=0.3f; U(mat).m[2][2]=8.6f; U(mat).m[2][3]=8.4f; U(mat).m[3][0]=6.7f; U(mat).m[3][1]=-5.1f; U(mat).m[3][2]=6.1f; U(mat).m[3][3]=2.2f; hr = ID3DXSprite_SetTransform(sprite, NULL); ok (hr == D3DERR_INVALIDCALL, "SetTransform returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); hr = ID3DXSprite_SetTransform(sprite, &mat); ok (hr == D3D_OK, "SetTransform returned %#x, expected %#x\n", hr, D3D_OK); if(SUCCEEDED(hr)) { hr=ID3DXSprite_GetTransform(sprite, &cmpmat); if(SUCCEEDED(hr)) check_mat(cmpmat, mat); else skip("GetTransform returned %#x\n", hr); } /* Test ID3DXSprite_SetWorldViewLH/RH */ todo_wine { hr = ID3DXSprite_SetWorldViewLH(sprite, &mat, &mat); ok (hr == D3D_OK, "SetWorldViewLH returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_SetWorldViewLH(sprite, NULL, &mat); ok (hr == D3D_OK, "SetWorldViewLH returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_SetWorldViewLH(sprite, &mat, NULL); ok (hr == D3D_OK, "SetWorldViewLH returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_SetWorldViewLH(sprite, NULL, NULL); ok (hr == D3D_OK, "SetWorldViewLH returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_SetWorldViewRH(sprite, &mat, &mat); ok (hr == D3D_OK, "SetWorldViewRH returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_SetWorldViewRH(sprite, NULL, &mat); ok (hr == D3D_OK, "SetWorldViewRH returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_SetWorldViewRH(sprite, &mat, NULL); ok (hr == D3D_OK, "SetWorldViewRH returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_SetWorldViewRH(sprite, NULL, NULL); ok (hr == D3D_OK, "SetWorldViewRH returned %#x, expected %#x\n", hr, D3D_OK); } IDirect3DDevice9_BeginScene(device); /* Test ID3DXSprite_Begin*/ hr = ID3DXSprite_Begin(sprite, 0); ok (hr == D3D_OK, "Begin returned %#x, expected %#x\n", hr, D3D_OK); IDirect3DDevice9_GetTransform(device, D3DTS_WORLD, &mat); D3DXMatrixIdentity(&cmpmat); check_mat(mat, cmpmat); IDirect3DDevice9_GetTransform(device, D3DTS_VIEW, &mat); check_mat(mat, cmpmat); IDirect3DDevice9_GetTransform(device, D3DTS_PROJECTION, &mat); IDirect3DDevice9_GetViewport(device, &vp); D3DXMatrixOrthoOffCenterLH(&cmpmat, vp.X+0.5f, (float)vp.Width+vp.X+0.5f, (float)vp.Height+vp.Y+0.5f, vp.Y+0.5f, vp.MinZ, vp.MaxZ); check_mat(mat, cmpmat); /* Test ID3DXSprite_Flush and ID3DXSprite_End */ hr = ID3DXSprite_Flush(sprite); ok (hr == D3D_OK, "Flush returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_End(sprite); ok (hr == D3D_OK, "End returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_Flush(sprite); /* May not be called before next Begin */ ok (hr == D3DERR_INVALIDCALL, "Flush returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); hr = ID3DXSprite_End(sprite); ok (hr == D3DERR_INVALIDCALL, "End returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); /* Test ID3DXSprite_Draw */ hr = ID3DXSprite_Begin(sprite, 0); ok (hr == D3D_OK, "Begin returned %#x, expected %#x\n", hr, D3D_OK); if(FAILED(hr)) skip("Couldn't ID3DXSprite_Begin, can't test ID3DXSprite_Draw\n"); else { /* Feed the sprite batch */ int texref1, texref2; SetRect(&rect, 53, 12, 142, 165); pos.x = 2.2f; pos.y = 4.5f; pos.z = 5.1f; center.x = 11.3f; center.y = 3.4f; center.z = 1.2f; texref1 = get_ref((IUnknown*)tex1); texref2 = get_ref((IUnknown*)tex2); hr = ID3DXSprite_Draw(sprite, NULL, &rect, ¢er, &pos, D3DCOLOR_XRGB(255, 255, 255)); ok (hr == D3DERR_INVALIDCALL, "Draw returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); hr = ID3DXSprite_Draw(sprite, tex1, &rect, ¢er, &pos, D3DCOLOR_XRGB(255, 255, 255)); ok (hr == D3D_OK, "Draw returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_Draw(sprite, tex2, &rect, ¢er, &pos, D3DCOLOR_XRGB( 3, 45, 66)); ok (hr == D3D_OK, "Draw returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_Draw(sprite, tex1, NULL, ¢er, &pos, D3DCOLOR_XRGB(255, 255, 255)); ok (hr == D3D_OK, "Draw returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_Draw(sprite, tex1, &rect, NULL, &pos, D3DCOLOR_XRGB(255, 255, 255)); ok (hr == D3D_OK, "Draw returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_Draw(sprite, tex1, &rect, ¢er, NULL, D3DCOLOR_XRGB(255, 255, 255)); ok (hr == D3D_OK, "Draw returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_Draw(sprite, tex1, NULL, NULL, NULL, 0); ok (hr == D3D_OK, "Draw returned %#x, expected %#x\n", hr, D3D_OK); check_ref((IUnknown*)tex1, texref1+5); check_ref((IUnknown*)tex2, texref2+1); hr = ID3DXSprite_Flush(sprite); ok (hr == D3D_OK, "Flush returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_Flush(sprite); /* Flushing twice should work */ ok (hr == D3D_OK, "Flush returned %#x, expected %#x\n", hr, D3D_OK); check_ref((IUnknown*)tex1, texref1); check_ref((IUnknown*)tex2, texref2); hr = ID3DXSprite_End(sprite); ok (hr == D3D_OK, "End returned %#x, expected %#x\n", hr, D3D_OK); } /* Test ID3DXSprite_OnLostDevice and ID3DXSprite_OnResetDevice */ /* Both can be called twice */ hr = ID3DXSprite_OnLostDevice(sprite); ok (hr == D3D_OK, "OnLostDevice returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_OnLostDevice(sprite); ok (hr == D3D_OK, "OnLostDevice returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_OnResetDevice(sprite); ok (hr == D3D_OK, "OnResetDevice returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_OnResetDevice(sprite); ok (hr == D3D_OK, "OnResetDevice returned %#x, expected %#x\n", hr, D3D_OK); /* Make sure everything works like before */ hr = ID3DXSprite_Begin(sprite, 0); ok (hr == D3D_OK, "Begin returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_Draw(sprite, tex2, &rect, ¢er, &pos, D3DCOLOR_XRGB(255, 255, 255)); ok (hr == D3D_OK, "Draw returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_Flush(sprite); ok (hr == D3D_OK, "Flush returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_End(sprite); ok (hr == D3D_OK, "End returned %#x, expected %#x\n", hr, D3D_OK); /* OnResetDevice makes the interface "forget" the Begin call */ hr = ID3DXSprite_Begin(sprite, 0); ok (hr == D3D_OK, "Begin returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_OnResetDevice(sprite); ok (hr == D3D_OK, "OnResetDevice returned %#x, expected %#x\n", hr, D3D_OK); hr = ID3DXSprite_End(sprite); ok (hr == D3DERR_INVALIDCALL, "End returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); IDirect3DDevice9_EndScene(device); check_release((IUnknown*)sprite, 0); check_release((IUnknown*)tex2, 0); check_release((IUnknown*)tex1, 0); }