d3d8: Get rid of the format switching code in d3d8_device_CopyRects().
[wine.git] / dlls / d3dx9_36 / line.c
blob5de44f4084a5f23f02b94fc24673d69d84136d38
1 /*
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 struct d3dx9_line
27 ID3DXLine ID3DXLine_iface;
28 LONG ref;
30 IDirect3DDevice9 *device;
31 IDirect3DStateBlock9 *state;
34 static inline struct d3dx9_line *impl_from_ID3DXLine(ID3DXLine *iface)
36 return CONTAINING_RECORD(iface, struct d3dx9_line, ID3DXLine_iface);
39 static HRESULT WINAPI d3dx9_line_QueryInterface(ID3DXLine *iface, REFIID riid, void **out)
41 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
43 if (IsEqualGUID(riid, &IID_ID3DXLine)
44 || IsEqualGUID(riid, &IID_IUnknown))
46 ID3DXLine_AddRef(iface);
47 *out = iface;
48 return S_OK;
51 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
53 *out = NULL;
54 return E_NOINTERFACE;
57 static ULONG WINAPI d3dx9_line_AddRef(ID3DXLine *iface)
59 struct d3dx9_line *line = impl_from_ID3DXLine(iface);
60 ULONG refcount = InterlockedIncrement(&line->ref);
62 TRACE("%p increasing refcount to %u.\n", line, refcount);
64 return refcount;
67 static ULONG WINAPI d3dx9_line_Release(ID3DXLine *iface)
69 struct d3dx9_line *line = impl_from_ID3DXLine(iface);
70 ULONG refcount = InterlockedDecrement(&line->ref);
72 TRACE("%p decreasing refcount to %u.\n", line, refcount);
74 if (!refcount)
76 IDirect3DDevice9_Release(line->device);
77 HeapFree(GetProcessHeap(), 0, line);
80 return refcount;
83 static HRESULT WINAPI d3dx9_line_GetDevice(struct ID3DXLine *iface, struct IDirect3DDevice9 **device)
85 struct d3dx9_line *line = impl_from_ID3DXLine(iface);
87 TRACE("iface %p, device %p.\n", iface, line);
89 if (!device)
90 return D3DERR_INVALIDCALL;
92 *device = line->device;
93 IDirect3DDevice9_AddRef(line->device);
95 return D3D_OK;
98 static HRESULT WINAPI d3dx9_line_Begin(ID3DXLine *iface)
100 struct d3dx9_line *line = impl_from_ID3DXLine(iface);
101 D3DXMATRIX identity, projection;
102 D3DVIEWPORT9 vp;
104 TRACE("iface %p.\n", iface);
106 if (line->state)
107 return D3DERR_INVALIDCALL;
109 if (FAILED(IDirect3DDevice9_CreateStateBlock(line->device, D3DSBT_ALL, &line->state)))
110 return D3DXERR_INVALIDDATA;
112 if (FAILED(IDirect3DDevice9_GetViewport(line->device, &vp)))
113 goto failed;
115 D3DXMatrixIdentity(&identity);
116 D3DXMatrixOrthoOffCenterLH(&projection, 0.0, (FLOAT)vp.Width, (FLOAT)vp.Height, 0.0, 0.0, 1.0);
118 if (FAILED(IDirect3DDevice9_SetTransform(line->device, D3DTS_WORLD, &identity)))
119 goto failed;
120 if (FAILED(IDirect3DDevice9_SetTransform(line->device, D3DTS_VIEW, &identity)))
121 goto failed;
122 if (FAILED(IDirect3DDevice9_SetTransform(line->device, D3DTS_PROJECTION, &projection)))
123 goto failed;
125 if (FAILED(IDirect3DDevice9_SetRenderState(line->device, D3DRS_LIGHTING, FALSE)))
126 goto failed;
127 if (FAILED(IDirect3DDevice9_SetRenderState(line->device, D3DRS_FOGENABLE, FALSE)))
128 goto failed;
129 if (FAILED(IDirect3DDevice9_SetRenderState(line->device, D3DRS_SHADEMODE, D3DSHADE_FLAT)))
130 goto failed;
131 if (FAILED(IDirect3DDevice9_SetRenderState(line->device, D3DRS_ALPHABLENDENABLE, TRUE)))
132 goto failed;
133 if (FAILED(IDirect3DDevice9_SetRenderState(line->device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA)))
134 goto failed;
135 if (FAILED(IDirect3DDevice9_SetRenderState(line->device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA)))
136 goto failed;
138 return D3D_OK;
140 failed:
141 IDirect3DStateBlock9_Apply(line->state);
142 IDirect3DStateBlock9_Release(line->state);
143 line->state = NULL;
144 return D3DXERR_INVALIDDATA;
147 static HRESULT WINAPI d3dx9_line_Draw(ID3DXLine *iface, const D3DXVECTOR2 *vertex_list,
148 DWORD vertex_list_count, D3DCOLOR color)
150 FIXME("iface %p, vertex_list %p, vertex_list_count %u, color 0x%08x stub!\n",
151 iface, vertex_list, vertex_list_count, color);
153 return E_NOTIMPL;
156 static HRESULT WINAPI d3dx9_line_DrawTransform(ID3DXLine *iface, const D3DXVECTOR3 *vertex_list,
157 DWORD vertex_list_count, const D3DXMATRIX *transform, D3DCOLOR color)
159 FIXME("iface %p, vertex_list %p, vertex_list_count %u, transform %p, color 0x%08x stub!\n",
160 iface, vertex_list, vertex_list_count, transform, color);
162 return E_NOTIMPL;
165 static HRESULT WINAPI d3dx9_line_SetPattern(ID3DXLine *iface, DWORD pattern)
167 FIXME("iface %p, pattern 0x%08x stub!\n", iface, pattern);
169 return E_NOTIMPL;
172 static DWORD WINAPI d3dx9_line_GetPattern(ID3DXLine *iface)
174 FIXME("iface %p stub!\n", iface);
176 return 0xffffffff;
179 static HRESULT WINAPI d3dx9_line_SetPatternScale(ID3DXLine *iface, float scale)
181 FIXME("iface %p, scale %.8e stub!\n", iface, scale);
183 return E_NOTIMPL;
186 static float WINAPI d3dx9_line_GetPatternScale(ID3DXLine *iface)
188 FIXME("iface %p stub!\n", iface);
190 return 1.0f;
193 static HRESULT WINAPI d3dx9_line_SetWidth(ID3DXLine *iface, float width)
195 FIXME("iface %p, width %.8e stub!\n", iface, width);
197 return E_NOTIMPL;
200 static float WINAPI d3dx9_line_GetWidth(ID3DXLine *iface)
202 FIXME("iface %p stub!\n", iface);
204 return 1.0f;
207 static HRESULT WINAPI d3dx9_line_SetAntialias(ID3DXLine *iface, BOOL antialias)
209 FIXME("iface %p, antialias %#x stub!\n", iface, antialias);
211 return E_NOTIMPL;
214 static BOOL WINAPI d3dx9_line_GetAntialias(ID3DXLine *iface)
216 FIXME("iface %p stub!\n", iface);
218 return FALSE;
221 static HRESULT WINAPI d3dx9_line_SetGLLines(ID3DXLine *iface, BOOL gl_lines)
223 FIXME("iface %p, gl_lines %#x stub!\n", iface, gl_lines);
225 return E_NOTIMPL;
228 static BOOL WINAPI d3dx9_line_GetGLLines(ID3DXLine *iface)
230 FIXME("iface %p stub!\n", iface);
232 return FALSE;
235 static HRESULT WINAPI d3dx9_line_End(ID3DXLine *iface)
237 struct d3dx9_line *line = impl_from_ID3DXLine(iface);
239 HRESULT hr;
241 TRACE("iface %p.\n", iface);
243 if (!line->state)
244 return D3DERR_INVALIDCALL;
246 hr = IDirect3DStateBlock9_Apply(line->state);
247 IDirect3DStateBlock9_Release(line->state);
248 line->state = NULL;
250 if (FAILED(hr))
251 return D3DXERR_INVALIDDATA;
253 return D3D_OK;
256 static HRESULT WINAPI d3dx9_line_OnLostDevice(ID3DXLine *iface)
258 FIXME("iface %p stub!\n", iface);
260 return E_NOTIMPL;
262 static HRESULT WINAPI d3dx9_line_OnResetDevice(ID3DXLine *iface)
264 FIXME("iface %p stub!\n", iface);
266 return E_NOTIMPL;
269 static const struct ID3DXLineVtbl d3dx9_line_vtbl =
271 d3dx9_line_QueryInterface,
272 d3dx9_line_AddRef,
273 d3dx9_line_Release,
274 d3dx9_line_GetDevice,
275 d3dx9_line_Begin,
276 d3dx9_line_Draw,
277 d3dx9_line_DrawTransform,
278 d3dx9_line_SetPattern,
279 d3dx9_line_GetPattern,
280 d3dx9_line_SetPatternScale,
281 d3dx9_line_GetPatternScale,
282 d3dx9_line_SetWidth,
283 d3dx9_line_GetWidth,
284 d3dx9_line_SetAntialias,
285 d3dx9_line_GetAntialias,
286 d3dx9_line_SetGLLines,
287 d3dx9_line_GetGLLines,
288 d3dx9_line_End,
289 d3dx9_line_OnLostDevice,
290 d3dx9_line_OnResetDevice,
293 HRESULT WINAPI D3DXCreateLine(struct IDirect3DDevice9 *device, struct ID3DXLine **line)
295 struct d3dx9_line *object;
297 TRACE("device %p, line %p.\n", device, line);
299 if (!device || !line)
300 return D3DERR_INVALIDCALL;
302 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
303 return E_OUTOFMEMORY;
305 object->ID3DXLine_iface.lpVtbl = &d3dx9_line_vtbl;
306 object->ref = 1;
307 object->device = device;
308 IDirect3DDevice9_AddRef(device);
310 *line = &object->ID3DXLine_iface;
312 return D3D_OK;