2 * Copyright (C) 2005 Henri Verbeet
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "wine/test.h"
23 static HMODULE d3d9_handle = 0;
25 static HWND create_window(void)
28 wc.lpfnWndProc = &DefWindowProc;
29 wc.lpszClassName = "d3d9_test_wc";
32 return CreateWindow("d3d9_test_wc", "d3d9_test",
33 0, 0, 0, 0, 0, 0, 0, 0, 0);
36 static IDirect3DDevice9 *init_d3d9(void)
38 IDirect3D9 * (__stdcall * d3d9_create)(UINT SDKVersion) = 0;
39 IDirect3D9 *d3d9_ptr = 0;
40 IDirect3DDevice9 *device_ptr = 0;
41 D3DPRESENT_PARAMETERS present_parameters;
44 d3d9_create = (void *)GetProcAddress(d3d9_handle, "Direct3DCreate9");
45 ok(d3d9_create != NULL, "Failed to get address of Direct3DCreate9\n");
46 if (!d3d9_create) return NULL;
48 d3d9_ptr = d3d9_create(D3D_SDK_VERSION);
49 ok(d3d9_ptr != NULL, "Failed to create IDirect3D9 object\n");
50 if (!d3d9_ptr) return NULL;
52 ZeroMemory(&present_parameters, sizeof(present_parameters));
53 present_parameters.Windowed = TRUE;
54 present_parameters.hDeviceWindow = create_window();
55 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
57 hres = IDirect3D9_CreateDevice(d3d9_ptr, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, NULL, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device_ptr);
58 ok(hres == D3D_OK, "IDirect3D_CreateDevice returned: 0x%lx\n", hres);
63 static int get_refcount(IUnknown *object)
65 IUnknown_AddRef(object);
66 return IUnknown_Release(object);
69 static void test_get_set_vertex_shader(IDirect3DDevice9 *device_ptr)
72 static DWORD simple_vs[] = {0xFFFE0101, /* vs_1_1 */
73 0x0000001F, 0x80000000, 0x900F0000, /* dcl_position0 v0 */
74 0x00000009, 0xC0010000, 0x90E40000, 0xA0E40000, /* dp4 oPos.x, v0, c0 */
75 0x00000009, 0xC0020000, 0x90E40000, 0xA0E40001, /* dp4 oPos.y, v0, c1 */
76 0x00000009, 0xC0040000, 0x90E40000, 0xA0E40002, /* dp4 oPos.z, v0, c2 */
77 0x00000009, 0xC0080000, 0x90E40000, 0xA0E40003, /* dp4 oPos.w, v0, c3 */
78 0x0000FFFF}; /* END */
80 IDirect3DVertexShader9 *shader_ptr = 0;
81 IDirect3DVertexShader9 *current_shader_ptr = 0;
83 int shader_refcount = 0;
86 hret = IDirect3DDevice9_CreateVertexShader(device_ptr, simple_vs, &shader_ptr);
87 ok(hret == D3D_OK && shader_ptr != NULL, "CreateVertexShader returned: hret 0x%lx, shader_ptr %p. "
88 "Expected hret 0x%lx, shader_ptr != %p. Aborting.\n", hret, shader_ptr, D3D_OK, NULL);
89 if (hret != D3D_OK || shader_ptr == NULL) return;
91 /* SetVertexShader should not touch the shader's refcount. */
92 i = get_refcount((IUnknown *)shader_ptr);
93 hret = IDirect3DDevice9_SetVertexShader(device_ptr, shader_ptr);
94 shader_refcount = get_refcount((IUnknown *)shader_ptr);
95 ok(hret == D3D_OK && shader_refcount == i, "SetVertexShader returned: hret 0x%lx, refcount %d. "
96 "Expected hret 0x%lx, refcount %d.\n", hret, shader_refcount, D3D_OK, i);
98 /* GetVertexShader should increase the shader's refcount by one. */
99 i = shader_refcount+1;
100 hret = IDirect3DDevice9_GetVertexShader(device_ptr, ¤t_shader_ptr);
101 shader_refcount = get_refcount((IUnknown *)shader_ptr);
102 ok(hret == D3D_OK && shader_refcount == i && current_shader_ptr == shader_ptr,
103 "GetVertexShader returned: hret 0x%lx, current_shader_ptr %p refcount %d. "
104 "Expected hret 0x%lx, current_shader_ptr %p, refcount %d.\n", hret, current_shader_ptr, shader_refcount, D3D_OK, shader_ptr, i);
107 static void test_get_set_pixel_shader(IDirect3DDevice9 *device_ptr)
109 static DWORD simple_ps[] = {0xFFFF0101, /* ps_1_1 */
110 0x00000051, 0xA00F0001, 0x3F800000, 0x00000000, 0x00000000, 0x00000000, /* def c1 = 1.0, 0.0, 0.0, 0.0 */
111 0x00000042, 0xB00F0000, /* tex t0 */
112 0x00000008, 0x800F0000, 0xA0E40001, 0xA0E40000, /* dp3 r0, c1, c0 */
113 0x00000005, 0x800F0000, 0x90E40000, 0x80E40000, /* mul r0, v0, r0 */
114 0x00000005, 0x800F0000, 0xB0E40000, 0x80E40000, /* mul r0, t0, r0 */
115 0x0000FFFF}; /* END */
117 IDirect3DPixelShader9 *shader_ptr = 0;
118 IDirect3DPixelShader9 *current_shader_ptr = 0;
120 int shader_refcount = 0;
123 hret = IDirect3DDevice9_CreatePixelShader(device_ptr, simple_ps, &shader_ptr);
124 ok(hret == D3D_OK && shader_ptr != NULL, "CreatePixelShader returned: hret 0x%lx, shader_ptr %p. "
125 "Expected hret 0x%lx, shader_ptr != %p. Aborting.\n", hret, shader_ptr, D3D_OK, NULL);
126 if (hret != D3D_OK || shader_ptr == NULL) return;
128 /* SetPixelsShader should not touch the shader's refcount. */
129 i = get_refcount((IUnknown *)shader_ptr);
130 hret = IDirect3DDevice9_SetPixelShader(device_ptr, shader_ptr);
131 shader_refcount = get_refcount((IUnknown *)shader_ptr);
132 ok(hret == D3D_OK && shader_refcount == i, "SetPixelShader returned: hret 0x%lx, refcount %d. "
133 "Expected hret 0x%lx, refcount %d.\n", hret, shader_refcount, D3D_OK, i);
135 /* GetPixelShader should increase the shader's refcount by one. */
136 i = shader_refcount+1;
137 hret = IDirect3DDevice9_GetPixelShader(device_ptr, ¤t_shader_ptr);
138 shader_refcount = get_refcount((IUnknown *)shader_ptr);
139 ok(hret == D3D_OK && shader_refcount == i && current_shader_ptr == shader_ptr,
140 "GetPixelShader returned: hret 0x%lx, current_shader_ptr %p refcount %d. "
141 "Expected hret 0x%lx, current_shader_ptr %p, refcount %d.\n", hret, current_shader_ptr, shader_refcount, D3D_OK, shader_ptr, i);
147 IDirect3DDevice9 *device_ptr;
149 d3d9_handle = LoadLibraryA("d3d9.dll");
152 trace("Could not load d3d9.dll, skipping tests\n");
156 device_ptr = init_d3d9();
157 if (!device_ptr) return;
159 IDirect3DDevice9_GetDeviceCaps(device_ptr, &caps);
161 if (caps.VertexShaderVersion & 0xffff)
163 test_get_set_vertex_shader(device_ptr);
165 else trace("No vertex shader support, skipping test\n");
167 if (caps.PixelShaderVersion & 0xffff)
169 test_get_set_pixel_shader(device_ptr);
171 else trace("No pixel shader support, skipping test\n");