2 * Copyright 2002-2003 Jason Edmeades
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "d3d9_private.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
25 static inline IDirect3DVertexShader9Impl *impl_from_IDirect3DVertexShader9(IDirect3DVertexShader9 *iface)
27 return CONTAINING_RECORD(iface, IDirect3DVertexShader9Impl, IDirect3DVertexShader9_iface);
30 static HRESULT WINAPI d3d9_vertexshader_QueryInterface(IDirect3DVertexShader9 *iface, REFIID riid, void **object)
32 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
34 if (IsEqualGUID(riid, &IID_IDirect3DVertexShader9)
35 || IsEqualGUID(riid, &IID_IUnknown))
37 IDirect3DVertexShader9_AddRef(iface);
42 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
48 static ULONG WINAPI d3d9_vertexshader_AddRef(IDirect3DVertexShader9 *iface)
50 IDirect3DVertexShader9Impl *shader = impl_from_IDirect3DVertexShader9(iface);
51 ULONG refcount = InterlockedIncrement(&shader->ref);
53 TRACE("%p increasing refcount to %u.\n", iface, refcount);
57 IDirect3DDevice9Ex_AddRef(shader->parentDevice);
59 wined3d_shader_incref(shader->wined3d_shader);
60 wined3d_mutex_unlock();
66 static ULONG WINAPI d3d9_vertexshader_Release(IDirect3DVertexShader9 *iface)
68 IDirect3DVertexShader9Impl *shader = impl_from_IDirect3DVertexShader9(iface);
69 ULONG refcount = InterlockedDecrement(&shader->ref);
71 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
75 IDirect3DDevice9Ex *device = shader->parentDevice;
78 wined3d_shader_decref(shader->wined3d_shader);
79 wined3d_mutex_unlock();
81 /* Release the device last, as it may cause the device to be destroyed. */
82 IDirect3DDevice9Ex_Release(device);
88 static HRESULT WINAPI d3d9_vertexshader_GetDevice(IDirect3DVertexShader9 *iface, IDirect3DDevice9 **device)
90 IDirect3DVertexShader9Impl *shader = impl_from_IDirect3DVertexShader9(iface);
92 TRACE("iface %p, device %p.\n", iface, device);
94 *device = (IDirect3DDevice9 *)shader->parentDevice;
95 IDirect3DDevice9_AddRef(*device);
97 TRACE("Returning device %p.\n", *device);
102 static HRESULT WINAPI d3d9_vertexshader_GetFunction(IDirect3DVertexShader9 *iface,
103 void *data, UINT *data_size)
105 IDirect3DVertexShader9Impl *shader = impl_from_IDirect3DVertexShader9(iface);
108 TRACE("iface %p, data %p, data_size %p.\n", iface, data, data_size);
110 wined3d_mutex_lock();
111 hr = wined3d_shader_get_byte_code(shader->wined3d_shader, data, data_size);
112 wined3d_mutex_unlock();
117 static const IDirect3DVertexShader9Vtbl d3d9_vertexshader_vtbl =
120 d3d9_vertexshader_QueryInterface,
121 d3d9_vertexshader_AddRef,
122 d3d9_vertexshader_Release,
123 /* IDirect3DVertexShader9 */
124 d3d9_vertexshader_GetDevice,
125 d3d9_vertexshader_GetFunction,
128 static void STDMETHODCALLTYPE d3d9_vertexshader_wined3d_object_destroyed(void *parent)
130 HeapFree(GetProcessHeap(), 0, parent);
133 static const struct wined3d_parent_ops d3d9_vertexshader_wined3d_parent_ops =
135 d3d9_vertexshader_wined3d_object_destroyed,
138 HRESULT vertexshader_init(IDirect3DVertexShader9Impl *shader, struct d3d9_device *device, const DWORD *byte_code)
143 shader->IDirect3DVertexShader9_iface.lpVtbl = &d3d9_vertexshader_vtbl;
145 wined3d_mutex_lock();
146 hr = wined3d_shader_create_vs(device->wined3d_device, byte_code, NULL,
147 shader, &d3d9_vertexshader_wined3d_parent_ops, &shader->wined3d_shader, 3);
148 wined3d_mutex_unlock();
151 WARN("Failed to create wined3d vertex shader, hr %#x.\n", hr);
155 shader->parentDevice = &device->IDirect3DDevice9Ex_iface;
156 IDirect3DDevice9Ex_AddRef(shader->parentDevice);
161 IDirect3DVertexShader9Impl *unsafe_impl_from_IDirect3DVertexShader9(IDirect3DVertexShader9 *iface)
165 assert(iface->lpVtbl == &d3d9_vertexshader_vtbl);
167 return impl_from_IDirect3DVertexShader9(iface);
170 static inline IDirect3DPixelShader9Impl *impl_from_IDirect3DPixelShader9(IDirect3DPixelShader9 *iface)
172 return CONTAINING_RECORD(iface, IDirect3DPixelShader9Impl, IDirect3DPixelShader9_iface);
175 static HRESULT WINAPI d3d9_pixelshader_QueryInterface(IDirect3DPixelShader9 *iface, REFIID riid, void **object)
177 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
179 if (IsEqualGUID(riid, &IID_IDirect3DPixelShader9)
180 || IsEqualGUID(riid, &IID_IUnknown))
182 IDirect3DPixelShader9_AddRef(iface);
187 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
190 return E_NOINTERFACE;
193 static ULONG WINAPI d3d9_pixelshader_AddRef(IDirect3DPixelShader9 *iface)
195 IDirect3DPixelShader9Impl *shader = impl_from_IDirect3DPixelShader9(iface);
196 ULONG refcount = InterlockedIncrement(&shader->ref);
198 TRACE("%p increasing refcount to %u.\n", iface, refcount);
202 IDirect3DDevice9Ex_AddRef(shader->parentDevice);
203 wined3d_mutex_lock();
204 wined3d_shader_incref(shader->wined3d_shader);
205 wined3d_mutex_unlock();
211 static ULONG WINAPI d3d9_pixelshader_Release(IDirect3DPixelShader9 *iface)
213 IDirect3DPixelShader9Impl *shader = impl_from_IDirect3DPixelShader9(iface);
214 ULONG refcount = InterlockedDecrement(&shader->ref);
216 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
220 IDirect3DDevice9Ex *device = shader->parentDevice;
222 wined3d_mutex_lock();
223 wined3d_shader_decref(shader->wined3d_shader);
224 wined3d_mutex_unlock();
226 /* Release the device last, as it may cause the device to be destroyed. */
227 IDirect3DDevice9Ex_Release(device);
233 static HRESULT WINAPI d3d9_pixelshader_GetDevice(IDirect3DPixelShader9 *iface,
234 IDirect3DDevice9 **device)
236 IDirect3DPixelShader9Impl *shader = impl_from_IDirect3DPixelShader9(iface);
238 TRACE("iface %p, device %p.\n", iface, device);
240 *device = (IDirect3DDevice9 *)shader->parentDevice;
241 IDirect3DDevice9_AddRef(*device);
243 TRACE("Returning device %p.\n", *device);
248 static HRESULT WINAPI d3d9_pixelshader_GetFunction(IDirect3DPixelShader9 *iface, void *data,
251 IDirect3DPixelShader9Impl *shader = impl_from_IDirect3DPixelShader9(iface);
254 TRACE("iface %p, data %p, data_size %p.\n", iface, data, data_size);
256 wined3d_mutex_lock();
257 hr = wined3d_shader_get_byte_code(shader->wined3d_shader, data, data_size);
258 wined3d_mutex_unlock();
263 static const IDirect3DPixelShader9Vtbl d3d9_pixelshader_vtbl =
266 d3d9_pixelshader_QueryInterface,
267 d3d9_pixelshader_AddRef,
268 d3d9_pixelshader_Release,
269 /* IDirect3DPixelShader9 */
270 d3d9_pixelshader_GetDevice,
271 d3d9_pixelshader_GetFunction,
274 static void STDMETHODCALLTYPE d3d9_pixelshader_wined3d_object_destroyed(void *parent)
276 HeapFree(GetProcessHeap(), 0, parent);
279 static const struct wined3d_parent_ops d3d9_pixelshader_wined3d_parent_ops =
281 d3d9_pixelshader_wined3d_object_destroyed,
284 HRESULT pixelshader_init(IDirect3DPixelShader9Impl *shader, struct d3d9_device *device, const DWORD *byte_code)
289 shader->IDirect3DPixelShader9_iface.lpVtbl = &d3d9_pixelshader_vtbl;
291 wined3d_mutex_lock();
292 hr = wined3d_shader_create_ps(device->wined3d_device, byte_code, NULL, shader,
293 &d3d9_pixelshader_wined3d_parent_ops, &shader->wined3d_shader, 3);
294 wined3d_mutex_unlock();
297 WARN("Failed to created wined3d pixel shader, hr %#x.\n", hr);
301 shader->parentDevice = &device->IDirect3DDevice9Ex_iface;
302 IDirect3DDevice9Ex_AddRef(shader->parentDevice);
307 IDirect3DPixelShader9Impl *unsafe_impl_from_IDirect3DPixelShader9(IDirect3DPixelShader9 *iface)
311 assert(iface->lpVtbl == &d3d9_pixelshader_vtbl);
313 return impl_from_IDirect3DPixelShader9(iface);