2 * Copyright 2010 Christian Costa
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
20 #include "wine/debug.h"
21 #include "d3dx9_36_private.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
25 static const struct ID3DXLineVtbl ID3DXLine_Vtbl;
27 typedef struct ID3DXLineImpl {
28 ID3DXLine ID3DXLine_iface;
31 IDirect3DDevice9 *device;
32 IDirect3DStateBlock9 *state;
35 static inline ID3DXLineImpl *impl_from_ID3DXLine(ID3DXLine *iface)
37 return CONTAINING_RECORD(iface, ID3DXLineImpl, ID3DXLine_iface);
40 /*** IUnknown methods ***/
41 static HRESULT WINAPI ID3DXLineImpl_QueryInterface(ID3DXLine* iface, REFIID riid, LPVOID* object)
43 ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
45 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), object);
47 if (IsEqualGUID(riid, &IID_IUnknown) ||
48 IsEqualGUID(riid, &IID_ID3DXLine))
50 ID3DXLine_AddRef(iface);
55 ERR("Interface %s not found\n", debugstr_guid(riid));
60 static ULONG WINAPI ID3DXLineImpl_AddRef(ID3DXLine* iface)
62 ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
64 TRACE("(%p)->(): AddRef from %u\n", This, This->ref);
66 return InterlockedIncrement(&This->ref);
69 static ULONG WINAPI ID3DXLineImpl_Release(ID3DXLine* iface)
71 ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
72 ULONG ref = InterlockedDecrement(&This->ref);
74 TRACE("(%p)->(): Release from %u\n", This, ref + 1);
78 IDirect3DDevice9_Release(This->device);
79 HeapFree(GetProcessHeap(), 0, This);
85 /*** ID3DXLine methods ***/
86 static HRESULT WINAPI ID3DXLineImpl_GetDevice(ID3DXLine* iface, LPDIRECT3DDEVICE9* device)
88 ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
90 TRACE ("(%p)->(%p): relay\n", This, device);
92 if (device == NULL) return D3DERR_INVALIDCALL;
94 *device = This->device;
95 IDirect3DDevice9_AddRef(This->device);
100 static HRESULT WINAPI ID3DXLineImpl_Begin(ID3DXLine* iface)
102 ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
105 D3DXMATRIX identity, projection;
108 TRACE ("(%p)->()\n", This);
110 if (This->state != NULL) /* We already began. Return error. */
111 return D3DERR_INVALIDCALL;
113 hr = IDirect3DDevice9_CreateStateBlock(This->device, D3DSBT_ALL, &This->state);
114 if (FAILED(hr)) return D3DXERR_INVALIDDATA;
116 hr = IDirect3DDevice9_GetViewport(This->device, &vp);
117 if (FAILED(hr)) goto failed;
119 D3DXMatrixIdentity(&identity);
120 D3DXMatrixOrthoOffCenterLH(&projection,
121 0.0, vp.Width, /* Min and max x */
122 vp.Height, 0.0, /* Min and max y. Screen y is on top so this is inverted */
123 0.0, 1.0); /* Min and max z */
125 hr = IDirect3DDevice9_SetTransform(This->device, D3DTS_WORLD, &identity);
126 if (FAILED(hr)) goto failed;
128 hr = IDirect3DDevice9_SetTransform(This->device, D3DTS_VIEW, &identity);
129 if (FAILED(hr)) goto failed;
131 hr = IDirect3DDevice9_SetTransform(This->device, D3DTS_PROJECTION, &projection);
132 if (FAILED(hr)) goto failed;
134 /* Windows sets similar states so we do the same */
136 hr = IDirect3DDevice9_SetRenderState(This->device, D3DRS_LIGHTING, FALSE);
137 if (FAILED(hr)) goto failed;
139 hr = IDirect3DDevice9_SetRenderState(This->device, D3DRS_FOGENABLE, FALSE);
140 if (FAILED(hr)) goto failed;
142 hr = IDirect3DDevice9_SetRenderState(This->device, D3DRS_SHADEMODE, D3DSHADE_FLAT);
143 if (FAILED(hr)) goto failed;
145 hr = IDirect3DDevice9_SetRenderState(This->device, D3DRS_ALPHABLENDENABLE, TRUE);
146 if (FAILED(hr)) goto failed;
148 hr = IDirect3DDevice9_SetRenderState(This->device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
149 if (FAILED(hr)) goto failed;
151 hr = IDirect3DDevice9_SetRenderState(This->device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
152 if (FAILED(hr)) goto failed;
156 IDirect3DStateBlock9_Apply(This->state);
157 IDirect3DStateBlock9_Release(This->state);
159 return D3DXERR_INVALIDDATA;
162 static HRESULT WINAPI ID3DXLineImpl_Draw(ID3DXLine* iface, CONST D3DXVECTOR2* vertexlist, DWORD vertexlistcount, D3DCOLOR color)
164 ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
166 FIXME("(%p)->(%p, %u, %#x): stub\n", This, vertexlist, vertexlistcount, color);
171 static HRESULT WINAPI ID3DXLineImpl_DrawTransform(ID3DXLine* iface, CONST D3DXVECTOR3* vertexlist, DWORD vertexlistcount,
172 CONST D3DXMATRIX* transform, D3DCOLOR color)
174 ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
176 FIXME("(%p)->(%p, %u, %p, %#x): stub\n", This, vertexlist, vertexlistcount, transform, color);
181 static HRESULT WINAPI ID3DXLineImpl_SetPattern(ID3DXLine* iface, DWORD pattern)
183 ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
185 FIXME("(%p)->(%#x): stub\n", This, pattern);
190 static DWORD WINAPI ID3DXLineImpl_GetPattern(ID3DXLine* iface)
192 ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
194 FIXME("(%p)->(): stub\n", This);
199 static HRESULT WINAPI ID3DXLineImpl_SetPatternScale(ID3DXLine* iface, FLOAT scale)
201 ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
203 FIXME("(%p)->(%f): stub\n", This, scale);
208 static FLOAT WINAPI ID3DXLineImpl_GetPatternScale(ID3DXLine* iface)
210 ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
212 FIXME("(%p)->(): stub\n", This);
217 static HRESULT WINAPI ID3DXLineImpl_SetWidth(ID3DXLine* iface, FLOAT width)
219 ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
221 FIXME("(%p)->(%f): stub\n", This, width);
226 static FLOAT WINAPI ID3DXLineImpl_GetWidth(ID3DXLine* iface)
228 ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
230 FIXME("(%p)->(): stub\n", This);
235 static HRESULT WINAPI ID3DXLineImpl_SetAntialias(ID3DXLine* iface, BOOL antialias)
237 ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
239 FIXME("(%p)->(%u): stub\n", This, antialias);
244 static BOOL WINAPI ID3DXLineImpl_GetAntialias(ID3DXLine* iface)
246 ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
248 FIXME("(%p)->(): stub\n", This);
253 static HRESULT WINAPI ID3DXLineImpl_SetGLLines(ID3DXLine* iface, BOOL gl_lines)
255 ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
257 FIXME("(%p)->(%u): stub\n", This, gl_lines);
262 static BOOL WINAPI ID3DXLineImpl_GetGLLines(ID3DXLine* iface)
264 ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
266 FIXME("(%p)->(): stub\n", This);
271 static HRESULT WINAPI ID3DXLineImpl_End(ID3DXLine* iface)
273 ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
277 TRACE ("(%p)->()\n", This);
279 if (This->state == NULL) /* We haven't begun yet. */
280 return D3DERR_INVALIDCALL;
282 hr = IDirect3DStateBlock9_Apply(This->state);
283 IDirect3DStateBlock9_Release(This->state);
286 if (FAILED(hr)) return D3DXERR_INVALIDDATA;
290 static HRESULT WINAPI ID3DXLineImpl_OnLostDevice(ID3DXLine* iface)
292 ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
294 FIXME("(%p)->(): stub\n", This);
298 static HRESULT WINAPI ID3DXLineImpl_OnResetDevice(ID3DXLine* iface)
300 ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
302 FIXME("(%p)->(): stub\n", This);
307 static const struct ID3DXLineVtbl ID3DXLine_Vtbl =
309 /*** IUnknown methods ***/
310 ID3DXLineImpl_QueryInterface,
311 ID3DXLineImpl_AddRef,
312 ID3DXLineImpl_Release,
313 /*** ID3DXLine methods ***/
314 ID3DXLineImpl_GetDevice,
317 ID3DXLineImpl_DrawTransform,
318 ID3DXLineImpl_SetPattern,
319 ID3DXLineImpl_GetPattern,
320 ID3DXLineImpl_SetPatternScale,
321 ID3DXLineImpl_GetPatternScale,
322 ID3DXLineImpl_SetWidth,
323 ID3DXLineImpl_GetWidth,
324 ID3DXLineImpl_SetAntialias,
325 ID3DXLineImpl_GetAntialias,
326 ID3DXLineImpl_SetGLLines,
327 ID3DXLineImpl_GetGLLines,
329 ID3DXLineImpl_OnLostDevice,
330 ID3DXLineImpl_OnResetDevice
333 HRESULT WINAPI D3DXCreateLine(LPDIRECT3DDEVICE9 device, LPD3DXLINE* line)
335 ID3DXLineImpl* object;
337 TRACE("(%p, %p)\n", device, line);
339 if (!device || !line)
340 return D3DERR_INVALIDCALL;
342 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ID3DXLineImpl));
345 ERR("Out of memory\n");
346 return E_OUTOFMEMORY;
349 object->ID3DXLine_iface.lpVtbl = &ID3DXLine_Vtbl;
351 object->device = device;
352 object->state = NULL; /* We only initialize it on Begin */
353 IDirect3DDevice9_AddRef(device);
355 *line = &object->ID3DXLine_iface;