2 * Some unit tests for d3d functions
4 * Copyright (C) 2005 Antoine Chavasse
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/test.h"
26 static LPDIRECTDRAW7 lpDD
= NULL
;
27 static LPDIRECT3D7 lpD3D
= NULL
;
28 static LPDIRECTDRAWSURFACE7 lpDDS
= NULL
;
29 static LPDIRECT3DDEVICE7 lpD3DDevice
= NULL
;
31 static HRESULT (WINAPI
*pDirectDrawCreateEx
)(LPGUID
,LPVOID
*,REFIID
,LPUNKNOWN
);
33 static void init_function_pointers(void)
35 HMODULE hmod
= GetModuleHandleA("ddraw.dll");
39 pDirectDrawCreateEx
= (void*)GetProcAddress(hmod
, "DirectDrawCreateEx");
44 static BOOL
CreateDirect3D(void)
49 rc
= pDirectDrawCreateEx(NULL
, (void**)&lpDD
,
50 &IID_IDirectDraw7
, NULL
);
51 ok(rc
==DD_OK
, "DirectDrawCreateEx returned: %lx\n", rc
);
53 rc
= IDirectDraw_SetCooperativeLevel(lpDD
, NULL
, DDSCL_NORMAL
);
54 ok(rc
==DD_OK
, "SetCooperativeLevel returned: %lx\n", rc
);
56 rc
= IDirectDraw7_QueryInterface(lpDD
, &IID_IDirect3D7
, (void**) &lpD3D
);
57 ok(rc
==DD_OK
, "QueryInterface returned: %lx\n", rc
);
59 memset(&ddsd
, 0, sizeof(ddsd
));
60 ddsd
.dwSize
= sizeof(ddsd
);
61 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
62 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
65 rc
= IDirectDraw7_CreateSurface(lpDD
, &ddsd
, &lpDDS
, NULL
);
66 ok(rc
==DD_OK
, "CreateSurface returned: %lx\n", rc
);
68 rc
= IDirect3D7_CreateDevice(lpD3D
, &IID_IDirect3DTnLHalDevice
, lpDDS
,
70 ok(rc
==D3D_OK
|| rc
==DDERR_NOPALETTEATTACHED
, "CreateDevice returned: %lx\n", rc
);
72 trace("IDirect3D7::CreateDevice() failed\n");
79 static void ReleaseDirect3D(void)
81 if (lpD3DDevice
!= NULL
)
83 IDirect3DDevice7_Release(lpD3DDevice
);
89 IDirectDrawSurface_Release(lpDDS
);
95 IDirect3D7_Release(lpD3D
);
101 IDirectDraw_Release(lpDD
);
106 static void LightTest(void)
110 D3DLIGHT7 defaultlight
;
111 BOOL bEnabled
= FALSE
;
113 /* Set a few lights with funky indices. */
114 memset(&light
, 0, sizeof(light
));
115 light
.dltType
= D3DLIGHT_DIRECTIONAL
;
116 U1(light
.dcvDiffuse
).r
= 0.5f
;
117 U2(light
.dcvDiffuse
).g
= 0.6f
;
118 U3(light
.dcvDiffuse
).b
= 0.7f
;
119 U2(light
.dvDirection
).y
= 1.f
;
121 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 5, &light
);
122 ok(rc
==D3D_OK
, "SetLight returned: %lx\n", rc
);
123 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 10, &light
);
124 ok(rc
==D3D_OK
, "SetLight returned: %lx\n", rc
);
125 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 45, &light
);
126 ok(rc
==D3D_OK
, "SetLight returned: %lx\n", rc
);
129 /* Try to retrieve a light beyond the indices of the lights that have
131 rc
= IDirect3DDevice7_GetLight(lpD3DDevice
, 50, &light
);
132 ok(rc
==DDERR_INVALIDPARAMS
, "GetLight returned: %lx\n", rc
);
133 rc
= IDirect3DDevice7_GetLight(lpD3DDevice
, 2, &light
);
134 ok(rc
==DDERR_INVALIDPARAMS
, "GetLight returned: %lx\n", rc
);
137 /* Try to retrieve one of the lights that have been set */
138 rc
= IDirect3DDevice7_GetLight(lpD3DDevice
, 10, &light
);
139 ok(rc
==D3D_OK
, "GetLight returned: %lx\n", rc
);
142 /* Enable a light that have been previously set. */
143 rc
= IDirect3DDevice7_LightEnable(lpD3DDevice
, 10, TRUE
);
144 ok(rc
==D3D_OK
, "LightEnable returned: %lx\n", rc
);
147 /* Enable some lights that have not been previously set, and verify that
148 they have been initialized with proper default values. */
149 memset(&defaultlight
, 0, sizeof(D3DLIGHT7
));
150 defaultlight
.dltType
= D3DLIGHT_DIRECTIONAL
;
151 U1(defaultlight
.dcvDiffuse
).r
= 1.f
;
152 U2(defaultlight
.dcvDiffuse
).g
= 1.f
;
153 U3(defaultlight
.dcvDiffuse
).b
= 1.f
;
154 U3(defaultlight
.dvDirection
).z
= 1.f
;
156 rc
= IDirect3DDevice7_LightEnable(lpD3DDevice
, 20, TRUE
);
157 ok(rc
==D3D_OK
, "LightEnable returned: %lx\n", rc
);
158 memset(&light
, 0, sizeof(D3DLIGHT7
));
159 rc
= IDirect3DDevice7_GetLight(lpD3DDevice
, 20, &light
);
160 ok(rc
==D3D_OK
, "GetLight returned: %lx\n", rc
);
161 ok(!memcmp(&light
, &defaultlight
, sizeof(D3DLIGHT7
)),
162 "light data doesn't match expected default values\n" );
164 rc
= IDirect3DDevice7_LightEnable(lpD3DDevice
, 50, TRUE
);
165 ok(rc
==D3D_OK
, "LightEnable returned: %lx\n", rc
);
166 memset(&light
, 0, sizeof(D3DLIGHT7
));
167 rc
= IDirect3DDevice7_GetLight(lpD3DDevice
, 50, &light
);
168 ok(rc
==D3D_OK
, "GetLight returned: %lx\n", rc
);
169 ok(!memcmp(&light
, &defaultlight
, sizeof(D3DLIGHT7
)),
170 "light data doesn't match expected default values\n" );
173 /* Disable one of the light that have been previously enabled. */
174 rc
= IDirect3DDevice7_LightEnable(lpD3DDevice
, 20, FALSE
);
175 ok(rc
==D3D_OK
, "LightEnable returned: %lx\n", rc
);
177 /* Try to retrieve the enable status of some lights */
178 /* Light 20 is supposed to be disabled */
179 rc
= IDirect3DDevice7_GetLightEnable(lpD3DDevice
, 20, &bEnabled
);
180 ok(rc
==D3D_OK
, "GetLightEnable returned: %lx\n", rc
);
181 ok(!bEnabled
, "GetLightEnable says the light is enabled\n");
183 /* Light 10 is supposed to be enabled */
185 rc
= IDirect3DDevice7_GetLightEnable(lpD3DDevice
, 10, &bEnabled
);
186 ok(rc
==D3D_OK
, "GetLightEnable returned: %lx\n", rc
);
187 ok(bEnabled
, "GetLightEnable says the light is disabled\n");
189 /* Light 80 has not been set */
190 rc
= IDirect3DDevice7_GetLightEnable(lpD3DDevice
, 80, &bEnabled
);
191 ok(rc
==DDERR_INVALIDPARAMS
, "GetLightEnable returned: %lx\n", rc
);
193 /* Light 23 has not been set */
194 rc
= IDirect3DDevice7_GetLightEnable(lpD3DDevice
, 23, &bEnabled
);
195 ok(rc
==DDERR_INVALIDPARAMS
, "GetLightEnable returned: %lx\n", rc
);
200 init_function_pointers();
201 if(!pDirectDrawCreateEx
) {
202 trace("function DirectDrawCreateEx not available, skipping tests\n");
206 if(!CreateDirect3D()) {
207 trace("Skipping tests\n");