1 #ifdef __REACTOS__
2 #include "precomp.h"
3 #else
4 /*
5 * Copyright 2010 Christian Costa
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 *
21 */
22
23
24 #include "d3dx9_private.h"
25 #endif /* __REACTOS__ */
26
27 WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
28
29 struct d3dx9_line
30 {
31 ID3DXLine ID3DXLine_iface;
32 LONG ref;
33
34 IDirect3DDevice9 *device;
35 IDirect3DStateBlock9 *state;
36 };
37
impl_from_ID3DXLine(ID3DXLine * iface)38 static inline struct d3dx9_line *impl_from_ID3DXLine(ID3DXLine *iface)
39 {
40 return CONTAINING_RECORD(iface, struct d3dx9_line, ID3DXLine_iface);
41 }
42
d3dx9_line_QueryInterface(ID3DXLine * iface,REFIID riid,void ** out)43 static HRESULT WINAPI d3dx9_line_QueryInterface(ID3DXLine *iface, REFIID riid, void **out)
44 {
45 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
46
47 if (IsEqualGUID(riid, &IID_ID3DXLine)
48 || IsEqualGUID(riid, &IID_IUnknown))
49 {
50 ID3DXLine_AddRef(iface);
51 *out = iface;
52 return S_OK;
53 }
54
55 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
56
57 *out = NULL;
58 return E_NOINTERFACE;
59 }
60
d3dx9_line_AddRef(ID3DXLine * iface)61 static ULONG WINAPI d3dx9_line_AddRef(ID3DXLine *iface)
62 {
63 struct d3dx9_line *line = impl_from_ID3DXLine(iface);
64 ULONG refcount = InterlockedIncrement(&line->ref);
65
66 TRACE("%p increasing refcount to %u.\n", line, refcount);
67
68 return refcount;
69 }
70
d3dx9_line_Release(ID3DXLine * iface)71 static ULONG WINAPI d3dx9_line_Release(ID3DXLine *iface)
72 {
73 struct d3dx9_line *line = impl_from_ID3DXLine(iface);
74 ULONG refcount = InterlockedDecrement(&line->ref);
75
76 TRACE("%p decreasing refcount to %u.\n", line, refcount);
77
78 if (!refcount)
79 {
80 IDirect3DDevice9_Release(line->device);
81 HeapFree(GetProcessHeap(), 0, line);
82 }
83
84 return refcount;
85 }
86
d3dx9_line_GetDevice(struct ID3DXLine * iface,struct IDirect3DDevice9 ** device)87 static HRESULT WINAPI d3dx9_line_GetDevice(struct ID3DXLine *iface, struct IDirect3DDevice9 **device)
88 {
89 struct d3dx9_line *line = impl_from_ID3DXLine(iface);
90
91 TRACE("iface %p, device %p.\n", iface, line);
92
93 if (!device)
94 return D3DERR_INVALIDCALL;
95
96 *device = line->device;
97 IDirect3DDevice9_AddRef(line->device);
98
99 return D3D_OK;
100 }
101
d3dx9_line_Begin(ID3DXLine * iface)102 static HRESULT WINAPI d3dx9_line_Begin(ID3DXLine *iface)
103 {
104 struct d3dx9_line *line = impl_from_ID3DXLine(iface);
105 D3DXMATRIX identity, projection;
106 D3DVIEWPORT9 vp;
107
108 TRACE("iface %p.\n", iface);
109
110 if (line->state)
111 return D3DERR_INVALIDCALL;
112
113 if (FAILED(IDirect3DDevice9_CreateStateBlock(line->device, D3DSBT_ALL, &line->state)))
114 return D3DXERR_INVALIDDATA;
115
116 if (FAILED(IDirect3DDevice9_GetViewport(line->device, &vp)))
117 goto failed;
118
119 D3DXMatrixIdentity(&identity);
120 D3DXMatrixOrthoOffCenterLH(&projection, 0.0, (FLOAT)vp.Width, (FLOAT)vp.Height, 0.0, 0.0, 1.0);
121
122 if (FAILED(IDirect3DDevice9_SetTransform(line->device, D3DTS_WORLD, &identity)))
123 goto failed;
124 if (FAILED(IDirect3DDevice9_SetTransform(line->device, D3DTS_VIEW, &identity)))
125 goto failed;
126 if (FAILED(IDirect3DDevice9_SetTransform(line->device, D3DTS_PROJECTION, &projection)))
127 goto failed;
128
129 if (FAILED(IDirect3DDevice9_SetRenderState(line->device, D3DRS_LIGHTING, FALSE)))
130 goto failed;
131 if (FAILED(IDirect3DDevice9_SetRenderState(line->device, D3DRS_FOGENABLE, FALSE)))
132 goto failed;
133 if (FAILED(IDirect3DDevice9_SetRenderState(line->device, D3DRS_SHADEMODE, D3DSHADE_FLAT)))
134 goto failed;
135 if (FAILED(IDirect3DDevice9_SetRenderState(line->device, D3DRS_ALPHABLENDENABLE, TRUE)))
136 goto failed;
137 if (FAILED(IDirect3DDevice9_SetRenderState(line->device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA)))
138 goto failed;
139 if (FAILED(IDirect3DDevice9_SetRenderState(line->device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA)))
140 goto failed;
141
142 return D3D_OK;
143
144 failed:
145 IDirect3DStateBlock9_Apply(line->state);
146 IDirect3DStateBlock9_Release(line->state);
147 line->state = NULL;
148 return D3DXERR_INVALIDDATA;
149 }
150
d3dx9_line_Draw(ID3DXLine * iface,const D3DXVECTOR2 * vertex_list,DWORD vertex_list_count,D3DCOLOR color)151 static HRESULT WINAPI d3dx9_line_Draw(ID3DXLine *iface, const D3DXVECTOR2 *vertex_list,
152 DWORD vertex_list_count, D3DCOLOR color)
153 {
154 FIXME("iface %p, vertex_list %p, vertex_list_count %u, color 0x%08x stub!\n",
155 iface, vertex_list, vertex_list_count, color);
156
157 return E_NOTIMPL;
158 }
159
d3dx9_line_DrawTransform(ID3DXLine * iface,const D3DXVECTOR3 * vertex_list,DWORD vertex_list_count,const D3DXMATRIX * transform,D3DCOLOR color)160 static HRESULT WINAPI d3dx9_line_DrawTransform(ID3DXLine *iface, const D3DXVECTOR3 *vertex_list,
161 DWORD vertex_list_count, const D3DXMATRIX *transform, D3DCOLOR color)
162 {
163 FIXME("iface %p, vertex_list %p, vertex_list_count %u, transform %p, color 0x%08x stub!\n",
164 iface, vertex_list, vertex_list_count, transform, color);
165
166 return E_NOTIMPL;
167 }
168
d3dx9_line_SetPattern(ID3DXLine * iface,DWORD pattern)169 static HRESULT WINAPI d3dx9_line_SetPattern(ID3DXLine *iface, DWORD pattern)
170 {
171 FIXME("iface %p, pattern 0x%08x stub!\n", iface, pattern);
172
173 return E_NOTIMPL;
174 }
175
d3dx9_line_GetPattern(ID3DXLine * iface)176 static DWORD WINAPI d3dx9_line_GetPattern(ID3DXLine *iface)
177 {
178 FIXME("iface %p stub!\n", iface);
179
180 return 0xffffffff;
181 }
182
d3dx9_line_SetPatternScale(ID3DXLine * iface,float scale)183 static HRESULT WINAPI d3dx9_line_SetPatternScale(ID3DXLine *iface, float scale)
184 {
185 FIXME("iface %p, scale %.8e stub!\n", iface, scale);
186
187 return E_NOTIMPL;
188 }
189
d3dx9_line_GetPatternScale(ID3DXLine * iface)190 static float WINAPI d3dx9_line_GetPatternScale(ID3DXLine *iface)
191 {
192 FIXME("iface %p stub!\n", iface);
193
194 return 1.0f;
195 }
196
d3dx9_line_SetWidth(ID3DXLine * iface,float width)197 static HRESULT WINAPI d3dx9_line_SetWidth(ID3DXLine *iface, float width)
198 {
199 FIXME("iface %p, width %.8e stub!\n", iface, width);
200
201 return E_NOTIMPL;
202 }
203
d3dx9_line_GetWidth(ID3DXLine * iface)204 static float WINAPI d3dx9_line_GetWidth(ID3DXLine *iface)
205 {
206 FIXME("iface %p stub!\n", iface);
207
208 return 1.0f;
209 }
210
d3dx9_line_SetAntialias(ID3DXLine * iface,BOOL antialias)211 static HRESULT WINAPI d3dx9_line_SetAntialias(ID3DXLine *iface, BOOL antialias)
212 {
213 FIXME("iface %p, antialias %#x stub!\n", iface, antialias);
214
215 return E_NOTIMPL;
216 }
217
d3dx9_line_GetAntialias(ID3DXLine * iface)218 static BOOL WINAPI d3dx9_line_GetAntialias(ID3DXLine *iface)
219 {
220 FIXME("iface %p stub!\n", iface);
221
222 return FALSE;
223 }
224
d3dx9_line_SetGLLines(ID3DXLine * iface,BOOL gl_lines)225 static HRESULT WINAPI d3dx9_line_SetGLLines(ID3DXLine *iface, BOOL gl_lines)
226 {
227 FIXME("iface %p, gl_lines %#x stub!\n", iface, gl_lines);
228
229 return E_NOTIMPL;
230 }
231
d3dx9_line_GetGLLines(ID3DXLine * iface)232 static BOOL WINAPI d3dx9_line_GetGLLines(ID3DXLine *iface)
233 {
234 FIXME("iface %p stub!\n", iface);
235
236 return FALSE;
237 }
238
d3dx9_line_End(ID3DXLine * iface)239 static HRESULT WINAPI d3dx9_line_End(ID3DXLine *iface)
240 {
241 struct d3dx9_line *line = impl_from_ID3DXLine(iface);
242
243 HRESULT hr;
244
245 TRACE("iface %p.\n", iface);
246
247 if (!line->state)
248 return D3DERR_INVALIDCALL;
249
250 hr = IDirect3DStateBlock9_Apply(line->state);
251 IDirect3DStateBlock9_Release(line->state);
252 line->state = NULL;
253
254 if (FAILED(hr))
255 return D3DXERR_INVALIDDATA;
256
257 return D3D_OK;
258 }
259
d3dx9_line_OnLostDevice(ID3DXLine * iface)260 static HRESULT WINAPI d3dx9_line_OnLostDevice(ID3DXLine *iface)
261 {
262 FIXME("iface %p stub!\n", iface);
263
264 return E_NOTIMPL;
265 }
d3dx9_line_OnResetDevice(ID3DXLine * iface)266 static HRESULT WINAPI d3dx9_line_OnResetDevice(ID3DXLine *iface)
267 {
268 FIXME("iface %p stub!\n", iface);
269
270 return S_OK;
271 }
272
273 static const struct ID3DXLineVtbl d3dx9_line_vtbl =
274 {
275 d3dx9_line_QueryInterface,
276 d3dx9_line_AddRef,
277 d3dx9_line_Release,
278 d3dx9_line_GetDevice,
279 d3dx9_line_Begin,
280 d3dx9_line_Draw,
281 d3dx9_line_DrawTransform,
282 d3dx9_line_SetPattern,
283 d3dx9_line_GetPattern,
284 d3dx9_line_SetPatternScale,
285 d3dx9_line_GetPatternScale,
286 d3dx9_line_SetWidth,
287 d3dx9_line_GetWidth,
288 d3dx9_line_SetAntialias,
289 d3dx9_line_GetAntialias,
290 d3dx9_line_SetGLLines,
291 d3dx9_line_GetGLLines,
292 d3dx9_line_End,
293 d3dx9_line_OnLostDevice,
294 d3dx9_line_OnResetDevice,
295 };
296
D3DXCreateLine(struct IDirect3DDevice9 * device,struct ID3DXLine ** line)297 HRESULT WINAPI D3DXCreateLine(struct IDirect3DDevice9 *device, struct ID3DXLine **line)
298 {
299 struct d3dx9_line *object;
300
301 TRACE("device %p, line %p.\n", device, line);
302
303 if (!device || !line)
304 return D3DERR_INVALIDCALL;
305
306 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
307 return E_OUTOFMEMORY;
308
309 object->ID3DXLine_iface.lpVtbl = &d3dx9_line_vtbl;
310 object->ref = 1;
311 object->device = device;
312 IDirect3DDevice9_AddRef(device);
313
314 *line = &object->ID3DXLine_iface;
315
316 return D3D_OK;
317 }
318