winecfg: Widen "Folder" column to accommodate Catalan translation.
[wine.git] / dlls / d3d11 / state.c
blob3ec9b1f62f1573eb3778706058d9c224e9339a0d
1 /*
2 * Copyright 2009 Henri Verbeet for CodeWeavers
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 "config.h"
21 #include "wine/port.h"
23 #include "d3d11_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d11);
27 /* ID3D11BlendState methods */
29 static inline struct d3d_blend_state *impl_from_ID3D11BlendState(ID3D11BlendState *iface)
31 return CONTAINING_RECORD(iface, struct d3d_blend_state, ID3D11BlendState_iface);
34 static HRESULT STDMETHODCALLTYPE d3d11_blend_state_QueryInterface(ID3D11BlendState *iface,
35 REFIID riid, void **object)
37 struct d3d_blend_state *state = impl_from_ID3D11BlendState(iface);
39 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
41 if (IsEqualGUID(riid, &IID_ID3D11BlendState)
42 || IsEqualGUID(riid, &IID_ID3D11DeviceChild)
43 || IsEqualGUID(riid, &IID_IUnknown))
45 ID3D11BlendState_AddRef(iface);
46 *object = iface;
47 return S_OK;
50 if (IsEqualGUID(riid, &IID_ID3D10BlendState1)
51 || IsEqualGUID(riid, &IID_ID3D10BlendState)
52 || IsEqualGUID(riid, &IID_ID3D10DeviceChild))
54 ID3D10BlendState1_AddRef(&state->ID3D10BlendState1_iface);
55 *object = &state->ID3D10BlendState1_iface;
56 return S_OK;
59 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
61 *object = NULL;
62 return E_NOINTERFACE;
65 static ULONG STDMETHODCALLTYPE d3d11_blend_state_AddRef(ID3D11BlendState *iface)
67 struct d3d_blend_state *state = impl_from_ID3D11BlendState(iface);
68 ULONG refcount = InterlockedIncrement(&state->refcount);
70 TRACE("%p increasing refcount to %u.\n", state, refcount);
72 return refcount;
75 static ULONG STDMETHODCALLTYPE d3d11_blend_state_Release(ID3D11BlendState *iface)
77 struct d3d_blend_state *state = impl_from_ID3D11BlendState(iface);
78 ULONG refcount = InterlockedDecrement(&state->refcount);
80 TRACE("%p decreasing refcount to %u.\n", state, refcount);
82 if (!refcount)
84 struct d3d_device *device = impl_from_ID3D11Device(state->device);
85 wined3d_mutex_lock();
86 wine_rb_remove(&device->blend_states, &state->desc);
87 ID3D11Device_Release(state->device);
88 wined3d_private_store_cleanup(&state->private_store);
89 wined3d_mutex_unlock();
90 HeapFree(GetProcessHeap(), 0, state);
93 return refcount;
96 static void STDMETHODCALLTYPE d3d11_blend_state_GetDevice(ID3D11BlendState *iface,
97 ID3D11Device **device)
99 struct d3d_blend_state *state = impl_from_ID3D11BlendState(iface);
101 TRACE("iface %p, device %p.\n", iface, device);
103 *device = state->device;
104 ID3D11Device_AddRef(*device);
107 static HRESULT STDMETHODCALLTYPE d3d11_blend_state_GetPrivateData(ID3D11BlendState *iface,
108 REFGUID guid, UINT *data_size, void *data)
110 struct d3d_blend_state *state = impl_from_ID3D11BlendState(iface);
112 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
114 return d3d_get_private_data(&state->private_store, guid, data_size, data);
117 static HRESULT STDMETHODCALLTYPE d3d11_blend_state_SetPrivateData(ID3D11BlendState *iface,
118 REFGUID guid, UINT data_size, const void *data)
120 struct d3d_blend_state *state = impl_from_ID3D11BlendState(iface);
122 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
124 return d3d_set_private_data(&state->private_store, guid, data_size, data);
127 static HRESULT STDMETHODCALLTYPE d3d11_blend_state_SetPrivateDataInterface(ID3D11BlendState *iface,
128 REFGUID guid, const IUnknown *data)
130 struct d3d_blend_state *state = impl_from_ID3D11BlendState(iface);
132 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
134 return d3d_set_private_data_interface(&state->private_store, guid, data);
137 static void STDMETHODCALLTYPE d3d11_blend_state_GetDesc(ID3D11BlendState *iface, D3D11_BLEND_DESC *desc)
139 struct d3d_blend_state *state = impl_from_ID3D11BlendState(iface);
141 TRACE("iface %p, desc %p.\n", iface, desc);
143 *desc = state->desc;
146 static const struct ID3D11BlendStateVtbl d3d11_blend_state_vtbl =
148 /* IUnknown methods */
149 d3d11_blend_state_QueryInterface,
150 d3d11_blend_state_AddRef,
151 d3d11_blend_state_Release,
152 /* ID3D11DeviceChild methods */
153 d3d11_blend_state_GetDevice,
154 d3d11_blend_state_GetPrivateData,
155 d3d11_blend_state_SetPrivateData,
156 d3d11_blend_state_SetPrivateDataInterface,
157 /* ID3D11BlendState methods */
158 d3d11_blend_state_GetDesc,
161 /* ID3D10BlendState methods */
163 static inline struct d3d_blend_state *impl_from_ID3D10BlendState(ID3D10BlendState1 *iface)
165 return CONTAINING_RECORD(iface, struct d3d_blend_state, ID3D10BlendState1_iface);
168 /* IUnknown methods */
170 static HRESULT STDMETHODCALLTYPE d3d10_blend_state_QueryInterface(ID3D10BlendState1 *iface,
171 REFIID riid, void **object)
173 struct d3d_blend_state *state = impl_from_ID3D10BlendState(iface);
175 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
177 return d3d11_blend_state_QueryInterface(&state->ID3D11BlendState_iface, riid, object);
180 static ULONG STDMETHODCALLTYPE d3d10_blend_state_AddRef(ID3D10BlendState1 *iface)
182 struct d3d_blend_state *state = impl_from_ID3D10BlendState(iface);
184 TRACE("iface %p.\n", iface);
186 return d3d11_blend_state_AddRef(&state->ID3D11BlendState_iface);
189 static ULONG STDMETHODCALLTYPE d3d10_blend_state_Release(ID3D10BlendState1 *iface)
191 struct d3d_blend_state *state = impl_from_ID3D10BlendState(iface);
193 TRACE("iface %p.\n", iface);
195 return d3d11_blend_state_Release(&state->ID3D11BlendState_iface);
198 /* ID3D10DeviceChild methods */
200 static void STDMETHODCALLTYPE d3d10_blend_state_GetDevice(ID3D10BlendState1 *iface, ID3D10Device **device)
202 struct d3d_blend_state *state = impl_from_ID3D10BlendState(iface);
204 TRACE("iface %p, device %p.\n", iface, device);
206 ID3D11Device_QueryInterface(state->device, &IID_ID3D10Device, (void **)device);
209 static HRESULT STDMETHODCALLTYPE d3d10_blend_state_GetPrivateData(ID3D10BlendState1 *iface,
210 REFGUID guid, UINT *data_size, void *data)
212 struct d3d_blend_state *state = impl_from_ID3D10BlendState(iface);
214 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
215 iface, debugstr_guid(guid), data_size, data);
217 return d3d_get_private_data(&state->private_store, guid, data_size, data);
220 static HRESULT STDMETHODCALLTYPE d3d10_blend_state_SetPrivateData(ID3D10BlendState1 *iface,
221 REFGUID guid, UINT data_size, const void *data)
223 struct d3d_blend_state *state = impl_from_ID3D10BlendState(iface);
225 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
226 iface, debugstr_guid(guid), data_size, data);
228 return d3d_set_private_data(&state->private_store, guid, data_size, data);
231 static HRESULT STDMETHODCALLTYPE d3d10_blend_state_SetPrivateDataInterface(ID3D10BlendState1 *iface,
232 REFGUID guid, const IUnknown *data)
234 struct d3d_blend_state *state = impl_from_ID3D10BlendState(iface);
236 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
238 return d3d_set_private_data_interface(&state->private_store, guid, data);
241 /* ID3D10BlendState methods */
243 static void STDMETHODCALLTYPE d3d10_blend_state_GetDesc(ID3D10BlendState1 *iface, D3D10_BLEND_DESC *desc)
245 struct d3d_blend_state *state = impl_from_ID3D10BlendState(iface);
246 const D3D11_BLEND_DESC *d3d11_desc = &state->desc;
247 unsigned int i;
249 TRACE("iface %p, desc %p.\n", iface, desc);
251 desc->AlphaToCoverageEnable = d3d11_desc->AlphaToCoverageEnable;
252 desc->SrcBlend = d3d11_desc->RenderTarget[0].SrcBlend;
253 desc->DestBlend = d3d11_desc->RenderTarget[0].DestBlend;
254 desc->BlendOp = d3d11_desc->RenderTarget[0].BlendOp;
255 desc->SrcBlendAlpha = d3d11_desc->RenderTarget[0].SrcBlendAlpha;
256 desc->DestBlendAlpha = d3d11_desc->RenderTarget[0].DestBlendAlpha;
257 desc->BlendOpAlpha = d3d11_desc->RenderTarget[0].BlendOpAlpha;
258 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
260 desc->BlendEnable[i] = d3d11_desc->RenderTarget[i].BlendEnable;
261 desc->RenderTargetWriteMask[i] = d3d11_desc->RenderTarget[i].RenderTargetWriteMask;
265 static void STDMETHODCALLTYPE d3d10_blend_state_GetDesc1(ID3D10BlendState1 *iface, D3D10_BLEND_DESC1 *desc)
267 struct d3d_blend_state *state = impl_from_ID3D10BlendState(iface);
269 TRACE("iface %p, desc %p.\n", iface, desc);
271 memcpy(desc, &state->desc, sizeof(*desc));
274 static const struct ID3D10BlendState1Vtbl d3d10_blend_state_vtbl =
276 /* IUnknown methods */
277 d3d10_blend_state_QueryInterface,
278 d3d10_blend_state_AddRef,
279 d3d10_blend_state_Release,
280 /* ID3D10DeviceChild methods */
281 d3d10_blend_state_GetDevice,
282 d3d10_blend_state_GetPrivateData,
283 d3d10_blend_state_SetPrivateData,
284 d3d10_blend_state_SetPrivateDataInterface,
285 /* ID3D10BlendState methods */
286 d3d10_blend_state_GetDesc,
287 /* ID3D10BlendState1 methods */
288 d3d10_blend_state_GetDesc1,
291 HRESULT d3d_blend_state_init(struct d3d_blend_state *state, struct d3d_device *device,
292 const D3D11_BLEND_DESC *desc)
294 state->ID3D11BlendState_iface.lpVtbl = &d3d11_blend_state_vtbl;
295 state->ID3D10BlendState1_iface.lpVtbl = &d3d10_blend_state_vtbl;
296 state->refcount = 1;
297 wined3d_mutex_lock();
298 wined3d_private_store_init(&state->private_store);
299 state->desc = *desc;
301 if (wine_rb_put(&device->blend_states, desc, &state->entry) == -1)
303 ERR("Failed to insert blend state entry.\n");
304 wined3d_private_store_cleanup(&state->private_store);
305 wined3d_mutex_unlock();
306 return E_FAIL;
308 wined3d_mutex_unlock();
310 state->device = &device->ID3D11Device_iface;
311 ID3D11Device_AddRef(state->device);
313 return S_OK;
316 struct d3d_blend_state *unsafe_impl_from_ID3D11BlendState(ID3D11BlendState *iface)
318 if (!iface)
319 return NULL;
320 assert(iface->lpVtbl == &d3d11_blend_state_vtbl);
322 return impl_from_ID3D11BlendState(iface);
325 struct d3d_blend_state *unsafe_impl_from_ID3D10BlendState(ID3D10BlendState *iface)
327 if (!iface)
328 return NULL;
329 assert(iface->lpVtbl == (ID3D10BlendStateVtbl *)&d3d10_blend_state_vtbl);
331 return impl_from_ID3D10BlendState((ID3D10BlendState1 *)iface);
334 /* ID3D11DepthStencilState methods */
336 static inline struct d3d_depthstencil_state *impl_from_ID3D11DepthStencilState(ID3D11DepthStencilState *iface)
338 return CONTAINING_RECORD(iface, struct d3d_depthstencil_state, ID3D11DepthStencilState_iface);
341 static HRESULT STDMETHODCALLTYPE d3d11_depthstencil_state_QueryInterface(ID3D11DepthStencilState *iface,
342 REFIID riid, void **object)
344 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
346 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
348 if (IsEqualGUID(riid, &IID_ID3D11DepthStencilState)
349 || IsEqualGUID(riid, &IID_ID3D11DeviceChild)
350 || IsEqualGUID(riid, &IID_IUnknown))
352 ID3D11DepthStencilState_AddRef(iface);
353 *object = iface;
354 return S_OK;
357 if (IsEqualGUID(riid, &IID_ID3D10DepthStencilState)
358 || IsEqualGUID(riid, &IID_ID3D10DeviceChild))
360 ID3D10DepthStencilState_AddRef(&state->ID3D10DepthStencilState_iface);
361 *object = &state->ID3D10DepthStencilState_iface;
362 return S_OK;
365 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
367 *object = NULL;
368 return E_NOINTERFACE;
371 static ULONG STDMETHODCALLTYPE d3d11_depthstencil_state_AddRef(ID3D11DepthStencilState *iface)
373 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
374 ULONG refcount = InterlockedIncrement(&state->refcount);
376 TRACE("%p increasing refcount to %u.\n", state, refcount);
378 return refcount;
381 static ULONG STDMETHODCALLTYPE d3d11_depthstencil_state_Release(ID3D11DepthStencilState *iface)
383 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
384 ULONG refcount = InterlockedDecrement(&state->refcount);
386 TRACE("%p decreasing refcount to %u.\n", state, refcount);
388 if (!refcount)
390 struct d3d_device *device = impl_from_ID3D11Device(state->device);
391 wined3d_mutex_lock();
392 wine_rb_remove(&device->depthstencil_states, &state->desc);
393 ID3D11Device_Release(state->device);
394 wined3d_private_store_cleanup(&state->private_store);
395 wined3d_mutex_unlock();
396 HeapFree(GetProcessHeap(), 0, state);
399 return refcount;
402 static void STDMETHODCALLTYPE d3d11_depthstencil_state_GetDevice(ID3D11DepthStencilState *iface,
403 ID3D11Device **device)
405 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
407 TRACE("iface %p, device %p.\n", iface, device);
409 *device = state->device;
410 ID3D11Device_AddRef(*device);
413 static HRESULT STDMETHODCALLTYPE d3d11_depthstencil_state_GetPrivateData(ID3D11DepthStencilState *iface,
414 REFGUID guid, UINT *data_size, void *data)
416 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
418 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
420 return d3d_get_private_data(&state->private_store, guid, data_size, data);
423 static HRESULT STDMETHODCALLTYPE d3d11_depthstencil_state_SetPrivateData(ID3D11DepthStencilState *iface,
424 REFGUID guid, UINT data_size, const void *data)
426 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
428 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
430 return d3d_set_private_data(&state->private_store, guid, data_size, data);
433 static HRESULT STDMETHODCALLTYPE d3d11_depthstencil_state_SetPrivateDataInterface(ID3D11DepthStencilState *iface,
434 REFGUID guid, const IUnknown *data)
436 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
438 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
440 return d3d_set_private_data_interface(&state->private_store, guid, data);
443 static void STDMETHODCALLTYPE d3d11_depthstencil_state_GetDesc(ID3D11DepthStencilState *iface,
444 D3D11_DEPTH_STENCIL_DESC *desc)
446 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
448 TRACE("iface %p, desc %p.\n", iface, desc);
450 *desc = state->desc;
453 static const struct ID3D11DepthStencilStateVtbl d3d11_depthstencil_state_vtbl =
455 /* IUnknown methods */
456 d3d11_depthstencil_state_QueryInterface,
457 d3d11_depthstencil_state_AddRef,
458 d3d11_depthstencil_state_Release,
459 /* ID3D11DeviceChild methods */
460 d3d11_depthstencil_state_GetDevice,
461 d3d11_depthstencil_state_GetPrivateData,
462 d3d11_depthstencil_state_SetPrivateData,
463 d3d11_depthstencil_state_SetPrivateDataInterface,
464 /* ID3D11DepthStencilState methods */
465 d3d11_depthstencil_state_GetDesc,
468 /* ID3D10DepthStencilState methods */
470 static inline struct d3d_depthstencil_state *impl_from_ID3D10DepthStencilState(ID3D10DepthStencilState *iface)
472 return CONTAINING_RECORD(iface, struct d3d_depthstencil_state, ID3D10DepthStencilState_iface);
475 /* IUnknown methods */
477 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_state_QueryInterface(ID3D10DepthStencilState *iface,
478 REFIID riid, void **object)
480 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
482 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
484 return d3d11_depthstencil_state_QueryInterface(&state->ID3D11DepthStencilState_iface, riid, object);
487 static ULONG STDMETHODCALLTYPE d3d10_depthstencil_state_AddRef(ID3D10DepthStencilState *iface)
489 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
491 TRACE("iface %p.\n", iface);
493 return d3d11_depthstencil_state_AddRef(&state->ID3D11DepthStencilState_iface);
496 static ULONG STDMETHODCALLTYPE d3d10_depthstencil_state_Release(ID3D10DepthStencilState *iface)
498 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
500 TRACE("iface %p.\n", iface);
502 return d3d11_depthstencil_state_Release(&state->ID3D11DepthStencilState_iface);
505 /* ID3D10DeviceChild methods */
507 static void STDMETHODCALLTYPE d3d10_depthstencil_state_GetDevice(ID3D10DepthStencilState *iface, ID3D10Device **device)
509 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
511 TRACE("iface %p, device %p.\n", iface, device);
513 ID3D11Device_QueryInterface(state->device, &IID_ID3D10Device, (void **)device);
516 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_state_GetPrivateData(ID3D10DepthStencilState *iface,
517 REFGUID guid, UINT *data_size, void *data)
519 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
521 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
522 iface, debugstr_guid(guid), data_size, data);
524 return d3d_get_private_data(&state->private_store, guid, data_size, data);
527 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_state_SetPrivateData(ID3D10DepthStencilState *iface,
528 REFGUID guid, UINT data_size, const void *data)
530 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
532 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
533 iface, debugstr_guid(guid), data_size, data);
535 return d3d_set_private_data(&state->private_store, guid, data_size, data);
538 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_state_SetPrivateDataInterface(ID3D10DepthStencilState *iface,
539 REFGUID guid, const IUnknown *data)
541 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
543 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
545 return d3d_set_private_data_interface(&state->private_store, guid, data);
548 /* ID3D10DepthStencilState methods */
550 static void STDMETHODCALLTYPE d3d10_depthstencil_state_GetDesc(ID3D10DepthStencilState *iface,
551 D3D10_DEPTH_STENCIL_DESC *desc)
553 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
555 TRACE("iface %p, desc %p.\n", iface, desc);
557 memcpy(desc, &state->desc, sizeof(*desc));
560 static const struct ID3D10DepthStencilStateVtbl d3d10_depthstencil_state_vtbl =
562 /* IUnknown methods */
563 d3d10_depthstencil_state_QueryInterface,
564 d3d10_depthstencil_state_AddRef,
565 d3d10_depthstencil_state_Release,
566 /* ID3D10DeviceChild methods */
567 d3d10_depthstencil_state_GetDevice,
568 d3d10_depthstencil_state_GetPrivateData,
569 d3d10_depthstencil_state_SetPrivateData,
570 d3d10_depthstencil_state_SetPrivateDataInterface,
571 /* ID3D10DepthStencilState methods */
572 d3d10_depthstencil_state_GetDesc,
575 HRESULT d3d_depthstencil_state_init(struct d3d_depthstencil_state *state, struct d3d_device *device,
576 const D3D11_DEPTH_STENCIL_DESC *desc)
578 state->ID3D11DepthStencilState_iface.lpVtbl = &d3d11_depthstencil_state_vtbl;
579 state->ID3D10DepthStencilState_iface.lpVtbl = &d3d10_depthstencil_state_vtbl;
580 state->refcount = 1;
581 wined3d_mutex_lock();
582 wined3d_private_store_init(&state->private_store);
583 state->desc = *desc;
585 if (wine_rb_put(&device->depthstencil_states, desc, &state->entry) == -1)
587 ERR("Failed to insert depthstencil state entry.\n");
588 wined3d_private_store_cleanup(&state->private_store);
589 wined3d_mutex_unlock();
590 return E_FAIL;
592 wined3d_mutex_unlock();
594 state->device = &device->ID3D11Device_iface;
595 ID3D11Device_AddRef(state->device);
597 return S_OK;
600 struct d3d_depthstencil_state *unsafe_impl_from_ID3D10DepthStencilState(ID3D10DepthStencilState *iface)
602 if (!iface)
603 return NULL;
604 assert(iface->lpVtbl == &d3d10_depthstencil_state_vtbl);
606 return impl_from_ID3D10DepthStencilState(iface);
609 /* ID3D11RasterizerState methods */
611 static inline struct d3d_rasterizer_state *impl_from_ID3D11RasterizerState(ID3D11RasterizerState *iface)
613 return CONTAINING_RECORD(iface, struct d3d_rasterizer_state, ID3D11RasterizerState_iface);
616 static HRESULT STDMETHODCALLTYPE d3d11_rasterizer_state_QueryInterface(ID3D11RasterizerState *iface,
617 REFIID riid, void **object)
619 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
621 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
623 if (IsEqualGUID(riid, &IID_ID3D11RasterizerState)
624 || IsEqualGUID(riid, &IID_ID3D11DeviceChild)
625 || IsEqualGUID(riid, &IID_IUnknown))
627 ID3D11RasterizerState_AddRef(iface);
628 *object = iface;
629 return S_OK;
632 if (IsEqualGUID(riid, &IID_ID3D10RasterizerState)
633 || IsEqualGUID(riid, &IID_ID3D10DeviceChild))
635 ID3D10RasterizerState_AddRef(&state->ID3D10RasterizerState_iface);
636 *object = &state->ID3D10RasterizerState_iface;
637 return S_OK;
640 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
642 *object = NULL;
643 return E_NOINTERFACE;
646 static ULONG STDMETHODCALLTYPE d3d11_rasterizer_state_AddRef(ID3D11RasterizerState *iface)
648 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
649 ULONG refcount = InterlockedIncrement(&state->refcount);
651 TRACE("%p increasing refcount to %u.\n", state, refcount);
653 return refcount;
656 static ULONG STDMETHODCALLTYPE d3d11_rasterizer_state_Release(ID3D11RasterizerState *iface)
658 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
659 ULONG refcount = InterlockedDecrement(&state->refcount);
661 TRACE("%p decreasing refcount to %u.\n", state, refcount);
663 if (!refcount)
665 struct d3d_device *device = impl_from_ID3D11Device(state->device);
666 wined3d_mutex_lock();
667 wine_rb_remove(&device->rasterizer_states, &state->desc);
668 ID3D11Device_Release(state->device);
669 wined3d_private_store_cleanup(&state->private_store);
670 wined3d_mutex_unlock();
671 HeapFree(GetProcessHeap(), 0, state);
674 return refcount;
677 static void STDMETHODCALLTYPE d3d11_rasterizer_state_GetDevice(ID3D11RasterizerState *iface,
678 ID3D11Device **device)
680 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
682 TRACE("iface %p, device %p.\n", iface, device);
684 *device = state->device;
685 ID3D11Device_AddRef(*device);
688 static HRESULT STDMETHODCALLTYPE d3d11_rasterizer_state_GetPrivateData(ID3D11RasterizerState *iface,
689 REFGUID guid, UINT *data_size, void *data)
691 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
693 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
695 return d3d_get_private_data(&state->private_store, guid, data_size, data);
698 static HRESULT STDMETHODCALLTYPE d3d11_rasterizer_state_SetPrivateData(ID3D11RasterizerState *iface,
699 REFGUID guid, UINT data_size, const void *data)
701 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
703 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
705 return d3d_set_private_data(&state->private_store, guid, data_size, data);
708 static HRESULT STDMETHODCALLTYPE d3d11_rasterizer_state_SetPrivateDataInterface(ID3D11RasterizerState *iface,
709 REFGUID guid, const IUnknown *data)
711 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
713 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
715 return d3d_set_private_data_interface(&state->private_store, guid, data);
718 static void STDMETHODCALLTYPE d3d11_rasterizer_state_GetDesc(ID3D11RasterizerState *iface,
719 D3D11_RASTERIZER_DESC *desc)
721 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
723 TRACE("iface %p, desc %p.\n", iface, desc);
725 *desc = state->desc;
728 static const struct ID3D11RasterizerStateVtbl d3d11_rasterizer_state_vtbl =
730 /* IUnknown methods */
731 d3d11_rasterizer_state_QueryInterface,
732 d3d11_rasterizer_state_AddRef,
733 d3d11_rasterizer_state_Release,
734 /* ID3D11DeviceChild methods */
735 d3d11_rasterizer_state_GetDevice,
736 d3d11_rasterizer_state_GetPrivateData,
737 d3d11_rasterizer_state_SetPrivateData,
738 d3d11_rasterizer_state_SetPrivateDataInterface,
739 /* ID3D11RasterizerState methods */
740 d3d11_rasterizer_state_GetDesc,
743 /* ID3D10RasterizerState methods */
745 static inline struct d3d_rasterizer_state *impl_from_ID3D10RasterizerState(ID3D10RasterizerState *iface)
747 return CONTAINING_RECORD(iface, struct d3d_rasterizer_state, ID3D10RasterizerState_iface);
750 /* IUnknown methods */
752 static HRESULT STDMETHODCALLTYPE d3d10_rasterizer_state_QueryInterface(ID3D10RasterizerState *iface,
753 REFIID riid, void **object)
755 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
757 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
759 return d3d11_rasterizer_state_QueryInterface(&state->ID3D11RasterizerState_iface, riid, object);
762 static ULONG STDMETHODCALLTYPE d3d10_rasterizer_state_AddRef(ID3D10RasterizerState *iface)
764 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
766 TRACE("iface %p.\n", iface);
768 return d3d11_rasterizer_state_AddRef(&state->ID3D11RasterizerState_iface);
771 static ULONG STDMETHODCALLTYPE d3d10_rasterizer_state_Release(ID3D10RasterizerState *iface)
773 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
775 TRACE("iface %p.\n", state);
777 return d3d11_rasterizer_state_Release(&state->ID3D11RasterizerState_iface);
780 /* ID3D10DeviceChild methods */
782 static void STDMETHODCALLTYPE d3d10_rasterizer_state_GetDevice(ID3D10RasterizerState *iface, ID3D10Device **device)
784 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
786 TRACE("iface %p, device %p.\n", iface, device);
788 ID3D11Device_QueryInterface(state->device, &IID_ID3D10Device, (void **)device);
791 static HRESULT STDMETHODCALLTYPE d3d10_rasterizer_state_GetPrivateData(ID3D10RasterizerState *iface,
792 REFGUID guid, UINT *data_size, void *data)
794 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
796 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
797 iface, debugstr_guid(guid), data_size, data);
799 return d3d_get_private_data(&state->private_store, guid, data_size, data);
802 static HRESULT STDMETHODCALLTYPE d3d10_rasterizer_state_SetPrivateData(ID3D10RasterizerState *iface,
803 REFGUID guid, UINT data_size, const void *data)
805 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
807 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
808 iface, debugstr_guid(guid), data_size, data);
810 return d3d_set_private_data(&state->private_store, guid, data_size, data);
813 static HRESULT STDMETHODCALLTYPE d3d10_rasterizer_state_SetPrivateDataInterface(ID3D10RasterizerState *iface,
814 REFGUID guid, const IUnknown *data)
816 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
818 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
820 return d3d_set_private_data_interface(&state->private_store, guid, data);
823 /* ID3D10RasterizerState methods */
825 static void STDMETHODCALLTYPE d3d10_rasterizer_state_GetDesc(ID3D10RasterizerState *iface,
826 D3D10_RASTERIZER_DESC *desc)
828 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
830 TRACE("iface %p, desc %p.\n", iface, desc);
832 memcpy(desc, &state->desc, sizeof(*desc));
835 static const struct ID3D10RasterizerStateVtbl d3d10_rasterizer_state_vtbl =
837 /* IUnknown methods */
838 d3d10_rasterizer_state_QueryInterface,
839 d3d10_rasterizer_state_AddRef,
840 d3d10_rasterizer_state_Release,
841 /* ID3D10DeviceChild methods */
842 d3d10_rasterizer_state_GetDevice,
843 d3d10_rasterizer_state_GetPrivateData,
844 d3d10_rasterizer_state_SetPrivateData,
845 d3d10_rasterizer_state_SetPrivateDataInterface,
846 /* ID3D10RasterizerState methods */
847 d3d10_rasterizer_state_GetDesc,
850 HRESULT d3d_rasterizer_state_init(struct d3d_rasterizer_state *state, struct d3d_device *device,
851 const D3D11_RASTERIZER_DESC *desc)
853 state->ID3D11RasterizerState_iface.lpVtbl = &d3d11_rasterizer_state_vtbl;
854 state->ID3D10RasterizerState_iface.lpVtbl = &d3d10_rasterizer_state_vtbl;
855 state->refcount = 1;
856 wined3d_mutex_lock();
857 wined3d_private_store_init(&state->private_store);
858 state->desc = *desc;
860 if (wine_rb_put(&device->rasterizer_states, desc, &state->entry) == -1)
862 ERR("Failed to insert rasterizer state entry.\n");
863 wined3d_private_store_cleanup(&state->private_store);
864 wined3d_mutex_unlock();
865 return E_FAIL;
867 wined3d_mutex_unlock();
869 state->device = &device->ID3D11Device_iface;
870 ID3D11Device_AddRef(state->device);
872 return S_OK;
875 struct d3d_rasterizer_state *unsafe_impl_from_ID3D11RasterizerState(ID3D11RasterizerState *iface)
877 if (!iface)
878 return NULL;
879 assert(iface->lpVtbl == &d3d11_rasterizer_state_vtbl);
881 return impl_from_ID3D11RasterizerState(iface);
884 struct d3d_rasterizer_state *unsafe_impl_from_ID3D10RasterizerState(ID3D10RasterizerState *iface)
886 if (!iface)
887 return NULL;
888 assert(iface->lpVtbl == &d3d10_rasterizer_state_vtbl);
890 return impl_from_ID3D10RasterizerState(iface);
893 /* ID3D11SampleState methods */
895 static inline struct d3d_sampler_state *impl_from_ID3D11SamplerState(ID3D11SamplerState *iface)
897 return CONTAINING_RECORD(iface, struct d3d_sampler_state, ID3D11SamplerState_iface);
900 static HRESULT STDMETHODCALLTYPE d3d11_sampler_state_QueryInterface(ID3D11SamplerState *iface,
901 REFIID riid, void **object)
903 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
905 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
907 if (IsEqualGUID(riid, &IID_ID3D11SamplerState)
908 || IsEqualGUID(riid, &IID_ID3D11DeviceChild)
909 || IsEqualGUID(riid, &IID_IUnknown))
911 ID3D11SamplerState_AddRef(iface);
912 *object = iface;
913 return S_OK;
916 if (IsEqualGUID(riid, &IID_ID3D10SamplerState)
917 || IsEqualGUID(riid, &IID_ID3D10DeviceChild))
919 ID3D10SamplerState_AddRef(&state->ID3D10SamplerState_iface);
920 *object = &state->ID3D10SamplerState_iface;
921 return S_OK;
924 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
926 *object = NULL;
927 return E_NOINTERFACE;
930 static ULONG STDMETHODCALLTYPE d3d11_sampler_state_AddRef(ID3D11SamplerState *iface)
932 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
933 ULONG refcount = InterlockedIncrement(&state->refcount);
935 TRACE("%p increasing refcount to %u.\n", state, refcount);
937 return refcount;
940 static ULONG STDMETHODCALLTYPE d3d11_sampler_state_Release(ID3D11SamplerState *iface)
942 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
943 ULONG refcount = InterlockedDecrement(&state->refcount);
945 TRACE("%p decreasing refcount to %u.\n", state, refcount);
947 if (!refcount)
949 struct d3d_device *device = impl_from_ID3D11Device(state->device);
951 wined3d_mutex_lock();
952 wined3d_sampler_decref(state->wined3d_sampler);
953 wine_rb_remove(&device->sampler_states, &state->desc);
954 ID3D11Device_Release(state->device);
955 wined3d_private_store_cleanup(&state->private_store);
956 wined3d_mutex_unlock();
957 HeapFree(GetProcessHeap(), 0, state);
960 return refcount;
963 static void STDMETHODCALLTYPE d3d11_sampler_state_GetDevice(ID3D11SamplerState *iface,
964 ID3D11Device **device)
966 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
968 TRACE("iface %p, device %p.\n", iface, device);
970 *device = state->device;
971 ID3D11Device_AddRef(*device);
974 static HRESULT STDMETHODCALLTYPE d3d11_sampler_state_GetPrivateData(ID3D11SamplerState *iface,
975 REFGUID guid, UINT *data_size, void *data)
977 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
979 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
981 return d3d_get_private_data(&state->private_store, guid, data_size, data);
984 static HRESULT STDMETHODCALLTYPE d3d11_sampler_state_SetPrivateData(ID3D11SamplerState *iface,
985 REFGUID guid, UINT data_size, const void *data)
987 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
989 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
991 return d3d_set_private_data(&state->private_store, guid, data_size, data);
994 static HRESULT STDMETHODCALLTYPE d3d11_sampler_state_SetPrivateDataInterface(ID3D11SamplerState *iface,
995 REFGUID guid, const IUnknown *data)
997 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
999 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
1001 return d3d_set_private_data_interface(&state->private_store, guid, data);
1004 static void STDMETHODCALLTYPE d3d11_sampler_state_GetDesc(ID3D11SamplerState *iface,
1005 D3D11_SAMPLER_DESC *desc)
1007 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
1009 TRACE("iface %p, desc %p.\n", iface, desc);
1011 *desc = state->desc;
1014 static const struct ID3D11SamplerStateVtbl d3d11_sampler_state_vtbl =
1016 /* IUnknown methods */
1017 d3d11_sampler_state_QueryInterface,
1018 d3d11_sampler_state_AddRef,
1019 d3d11_sampler_state_Release,
1020 /* ID3D11DeviceChild methods */
1021 d3d11_sampler_state_GetDevice,
1022 d3d11_sampler_state_GetPrivateData,
1023 d3d11_sampler_state_SetPrivateData,
1024 d3d11_sampler_state_SetPrivateDataInterface,
1025 /* ID3D11SamplerState methods */
1026 d3d11_sampler_state_GetDesc,
1029 /* ID3D10SamplerState methods */
1031 static inline struct d3d_sampler_state *impl_from_ID3D10SamplerState(ID3D10SamplerState *iface)
1033 return CONTAINING_RECORD(iface, struct d3d_sampler_state, ID3D10SamplerState_iface);
1036 /* IUnknown methods */
1038 static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_QueryInterface(ID3D10SamplerState *iface,
1039 REFIID riid, void **object)
1041 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1043 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
1045 return d3d11_sampler_state_QueryInterface(&state->ID3D11SamplerState_iface, riid, object);
1048 static ULONG STDMETHODCALLTYPE d3d10_sampler_state_AddRef(ID3D10SamplerState *iface)
1050 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1052 TRACE("iface %p.\n", iface);
1054 return d3d11_sampler_state_AddRef(&state->ID3D11SamplerState_iface);
1057 static ULONG STDMETHODCALLTYPE d3d10_sampler_state_Release(ID3D10SamplerState *iface)
1059 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1061 TRACE("iface %p.\n", iface);
1063 return d3d11_sampler_state_Release(&state->ID3D11SamplerState_iface);
1066 /* ID3D10DeviceChild methods */
1068 static void STDMETHODCALLTYPE d3d10_sampler_state_GetDevice(ID3D10SamplerState *iface, ID3D10Device **device)
1070 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1072 TRACE("iface %p, device %p.\n", iface, device);
1074 ID3D11Device_QueryInterface(state->device, &IID_ID3D10Device, (void **)device);
1077 static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_GetPrivateData(ID3D10SamplerState *iface,
1078 REFGUID guid, UINT *data_size, void *data)
1080 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1082 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
1083 iface, debugstr_guid(guid), data_size, data);
1085 return d3d_get_private_data(&state->private_store, guid, data_size, data);
1088 static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_SetPrivateData(ID3D10SamplerState *iface,
1089 REFGUID guid, UINT data_size, const void *data)
1091 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1093 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
1094 iface, debugstr_guid(guid), data_size, data);
1096 return d3d_set_private_data(&state->private_store, guid, data_size, data);
1099 static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_SetPrivateDataInterface(ID3D10SamplerState *iface,
1100 REFGUID guid, const IUnknown *data)
1102 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1104 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
1106 return d3d_set_private_data_interface(&state->private_store, guid, data);
1109 /* ID3D10SamplerState methods */
1111 static void STDMETHODCALLTYPE d3d10_sampler_state_GetDesc(ID3D10SamplerState *iface,
1112 D3D10_SAMPLER_DESC *desc)
1114 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1116 TRACE("iface %p, desc %p.\n", iface, desc);
1118 memcpy(desc, &state->desc, sizeof(*desc));
1121 static const struct ID3D10SamplerStateVtbl d3d10_sampler_state_vtbl =
1123 /* IUnknown methods */
1124 d3d10_sampler_state_QueryInterface,
1125 d3d10_sampler_state_AddRef,
1126 d3d10_sampler_state_Release,
1127 /* ID3D10DeviceChild methods */
1128 d3d10_sampler_state_GetDevice,
1129 d3d10_sampler_state_GetPrivateData,
1130 d3d10_sampler_state_SetPrivateData,
1131 d3d10_sampler_state_SetPrivateDataInterface,
1132 /* ID3D10SamplerState methods */
1133 d3d10_sampler_state_GetDesc,
1136 static enum wined3d_texture_address wined3d_texture_address_from_d3d11(enum D3D11_TEXTURE_ADDRESS_MODE t)
1138 return (enum wined3d_texture_address)t;
1141 static enum wined3d_texture_filter_type wined3d_texture_filter_mip_from_d3d11(enum D3D11_FILTER f)
1143 if (D3D11_DECODE_MIP_FILTER(f) == D3D11_FILTER_TYPE_LINEAR)
1144 return WINED3D_TEXF_LINEAR;
1145 return WINED3D_TEXF_POINT;
1148 static enum wined3d_texture_filter_type wined3d_texture_filter_mag_from_d3d11(enum D3D11_FILTER f)
1150 if (D3D11_DECODE_MAG_FILTER(f) == D3D11_FILTER_TYPE_LINEAR)
1151 return WINED3D_TEXF_LINEAR;
1152 return WINED3D_TEXF_POINT;
1155 static enum wined3d_texture_filter_type wined3d_texture_filter_min_from_d3d11(enum D3D11_FILTER f)
1157 if (D3D11_DECODE_MIN_FILTER(f) == D3D11_FILTER_TYPE_LINEAR)
1158 return WINED3D_TEXF_LINEAR;
1159 return WINED3D_TEXF_POINT;
1162 static BOOL wined3d_texture_compare_from_d3d11(enum D3D11_FILTER f)
1164 return D3D11_DECODE_IS_COMPARISON_FILTER(f);
1167 static enum wined3d_cmp_func wined3d_cmp_func_from_d3d11(D3D11_COMPARISON_FUNC f)
1169 return (enum wined3d_cmp_func)f;
1172 HRESULT d3d_sampler_state_init(struct d3d_sampler_state *state, struct d3d_device *device,
1173 const D3D11_SAMPLER_DESC *desc)
1175 struct wined3d_sampler_desc wined3d_desc;
1176 HRESULT hr;
1178 state->ID3D11SamplerState_iface.lpVtbl = &d3d11_sampler_state_vtbl;
1179 state->ID3D10SamplerState_iface.lpVtbl = &d3d10_sampler_state_vtbl;
1180 state->refcount = 1;
1181 wined3d_mutex_lock();
1182 wined3d_private_store_init(&state->private_store);
1183 state->desc = *desc;
1185 wined3d_desc.address_u = wined3d_texture_address_from_d3d11(desc->AddressU);
1186 wined3d_desc.address_v = wined3d_texture_address_from_d3d11(desc->AddressV);
1187 wined3d_desc.address_w = wined3d_texture_address_from_d3d11(desc->AddressW);
1188 memcpy(wined3d_desc.border_color, desc->BorderColor, sizeof(wined3d_desc.border_color));
1189 wined3d_desc.mag_filter = wined3d_texture_filter_mag_from_d3d11(desc->Filter);
1190 wined3d_desc.min_filter = wined3d_texture_filter_min_from_d3d11(desc->Filter);
1191 wined3d_desc.mip_filter = wined3d_texture_filter_mip_from_d3d11(desc->Filter);
1192 wined3d_desc.lod_bias = desc->MipLODBias;
1193 wined3d_desc.min_lod = desc->MinLOD;
1194 wined3d_desc.max_lod = desc->MaxLOD;
1195 wined3d_desc.max_anisotropy = D3D11_DECODE_IS_ANISOTROPIC_FILTER(desc->Filter) ? desc->MaxAnisotropy : 1;
1196 wined3d_desc.compare = wined3d_texture_compare_from_d3d11(desc->Filter);
1197 wined3d_desc.comparison_func = wined3d_cmp_func_from_d3d11(desc->ComparisonFunc);
1198 wined3d_desc.srgb_decode = FALSE;
1200 if (FAILED(hr = wined3d_sampler_create(device->wined3d_device, &wined3d_desc, state, &state->wined3d_sampler)))
1202 WARN("Failed to create wined3d sampler, hr %#x.\n", hr);
1203 wined3d_private_store_cleanup(&state->private_store);
1204 wined3d_mutex_unlock();
1205 return hr;
1208 if (wine_rb_put(&device->sampler_states, desc, &state->entry) == -1)
1210 ERR("Failed to insert sampler state entry.\n");
1211 wined3d_sampler_decref(state->wined3d_sampler);
1212 wined3d_private_store_cleanup(&state->private_store);
1213 wined3d_mutex_unlock();
1214 return E_FAIL;
1216 wined3d_mutex_unlock();
1218 state->device = &device->ID3D11Device_iface;
1219 ID3D11Device_AddRef(state->device);
1221 return S_OK;
1224 struct d3d_sampler_state *unsafe_impl_from_ID3D11SamplerState(ID3D11SamplerState *iface)
1226 if (!iface)
1227 return NULL;
1228 assert(iface->lpVtbl == &d3d11_sampler_state_vtbl);
1230 return impl_from_ID3D11SamplerState(iface);
1233 struct d3d_sampler_state *unsafe_impl_from_ID3D10SamplerState(ID3D10SamplerState *iface)
1235 if (!iface)
1236 return NULL;
1237 assert(iface->lpVtbl == &d3d10_sampler_state_vtbl);
1239 return impl_from_ID3D10SamplerState(iface);