riched20: Mark internal symbols with hidden visibility.
[wine/multimedia.git] / dlls / d3d10core / state.c
blob6d6087d9e38e0a16ffe2b4dd62c220869c331b63
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 "d3d10core_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d10core);
27 #define D3D10_FILTER_MIP_MASK 0x01
28 #define D3D10_FILTER_MAG_MASK 0x04
29 #define D3D10_FILTER_MIN_MASK 0x10
30 #define D3D10_FILTER_ANISO_MASK 0x40
31 #define D3D10_FILTER_COMPARE_MASK 0x80
33 static inline struct d3d10_blend_state *impl_from_ID3D10BlendState(ID3D10BlendState *iface)
35 return CONTAINING_RECORD(iface, struct d3d10_blend_state, ID3D10BlendState_iface);
38 /* IUnknown methods */
40 static HRESULT STDMETHODCALLTYPE d3d10_blend_state_QueryInterface(ID3D10BlendState *iface,
41 REFIID riid, void **object)
43 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
45 if (IsEqualGUID(riid, &IID_ID3D10BlendState)
46 || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
47 || IsEqualGUID(riid, &IID_IUnknown))
49 IUnknown_AddRef(iface);
50 *object = iface;
51 return S_OK;
54 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
56 *object = NULL;
57 return E_NOINTERFACE;
60 static ULONG STDMETHODCALLTYPE d3d10_blend_state_AddRef(ID3D10BlendState *iface)
62 struct d3d10_blend_state *This = impl_from_ID3D10BlendState(iface);
63 ULONG refcount = InterlockedIncrement(&This->refcount);
65 TRACE("%p increasing refcount to %u.\n", This, refcount);
67 return refcount;
70 static ULONG STDMETHODCALLTYPE d3d10_blend_state_Release(ID3D10BlendState *iface)
72 struct d3d10_blend_state *state = impl_from_ID3D10BlendState(iface);
73 ULONG refcount = InterlockedDecrement(&state->refcount);
75 TRACE("%p decreasing refcount to %u.\n", state, refcount);
77 if (!refcount)
79 struct d3d10_device *device = impl_from_ID3D10Device(state->device);
80 wine_rb_remove(&device->blend_states, &state->desc);
81 ID3D10Device1_Release(state->device);
82 wined3d_private_store_cleanup(&state->private_store);
83 HeapFree(GetProcessHeap(), 0, state);
86 return refcount;
89 /* ID3D10DeviceChild methods */
91 static void STDMETHODCALLTYPE d3d10_blend_state_GetDevice(ID3D10BlendState *iface, ID3D10Device **device)
93 struct d3d10_blend_state *state = impl_from_ID3D10BlendState(iface);
95 TRACE("iface %p, device %p.\n", iface, device);
97 *device = (ID3D10Device *)state->device;
98 ID3D10Device_AddRef(*device);
101 static HRESULT STDMETHODCALLTYPE d3d10_blend_state_GetPrivateData(ID3D10BlendState *iface,
102 REFGUID guid, UINT *data_size, void *data)
104 struct d3d10_blend_state *state = impl_from_ID3D10BlendState(iface);
106 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
107 iface, debugstr_guid(guid), data_size, data);
109 return d3d10_get_private_data(&state->private_store, guid, data_size, data);
112 static HRESULT STDMETHODCALLTYPE d3d10_blend_state_SetPrivateData(ID3D10BlendState *iface,
113 REFGUID guid, UINT data_size, const void *data)
115 struct d3d10_blend_state *state = impl_from_ID3D10BlendState(iface);
117 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
118 iface, debugstr_guid(guid), data_size, data);
120 return d3d10_set_private_data(&state->private_store, guid, data_size, data);
123 static HRESULT STDMETHODCALLTYPE d3d10_blend_state_SetPrivateDataInterface(ID3D10BlendState *iface,
124 REFGUID guid, const IUnknown *data)
126 struct d3d10_blend_state *state = impl_from_ID3D10BlendState(iface);
128 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
130 return d3d10_set_private_data_interface(&state->private_store, guid, data);
133 /* ID3D10BlendState methods */
135 static void STDMETHODCALLTYPE d3d10_blend_state_GetDesc(ID3D10BlendState *iface,
136 D3D10_BLEND_DESC *desc)
138 struct d3d10_blend_state *state = impl_from_ID3D10BlendState(iface);
140 TRACE("iface %p, desc %p.\n", iface, desc);
142 *desc = state->desc;
145 static const struct ID3D10BlendStateVtbl d3d10_blend_state_vtbl =
147 /* IUnknown methods */
148 d3d10_blend_state_QueryInterface,
149 d3d10_blend_state_AddRef,
150 d3d10_blend_state_Release,
151 /* ID3D10DeviceChild methods */
152 d3d10_blend_state_GetDevice,
153 d3d10_blend_state_GetPrivateData,
154 d3d10_blend_state_SetPrivateData,
155 d3d10_blend_state_SetPrivateDataInterface,
156 /* ID3D10BlendState methods */
157 d3d10_blend_state_GetDesc,
160 HRESULT d3d10_blend_state_init(struct d3d10_blend_state *state, struct d3d10_device *device,
161 const D3D10_BLEND_DESC *desc)
163 state->ID3D10BlendState_iface.lpVtbl = &d3d10_blend_state_vtbl;
164 state->refcount = 1;
165 wined3d_private_store_init(&state->private_store);
166 state->desc = *desc;
168 if (wine_rb_put(&device->blend_states, desc, &state->entry) == -1)
170 ERR("Failed to insert blend state entry.\n");
171 wined3d_private_store_cleanup(&state->private_store);
172 return E_FAIL;
175 state->device = &device->ID3D10Device1_iface;
176 ID3D10Device1_AddRef(state->device);
178 return S_OK;
181 struct d3d10_blend_state *unsafe_impl_from_ID3D10BlendState(ID3D10BlendState *iface)
183 if (!iface)
184 return NULL;
185 assert(iface->lpVtbl == &d3d10_blend_state_vtbl);
187 return impl_from_ID3D10BlendState(iface);
190 static inline struct d3d10_depthstencil_state *impl_from_ID3D10DepthStencilState(ID3D10DepthStencilState *iface)
192 return CONTAINING_RECORD(iface, struct d3d10_depthstencil_state, ID3D10DepthStencilState_iface);
195 /* IUnknown methods */
197 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_state_QueryInterface(ID3D10DepthStencilState *iface,
198 REFIID riid, void **object)
200 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
202 if (IsEqualGUID(riid, &IID_ID3D10DepthStencilState)
203 || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
204 || IsEqualGUID(riid, &IID_IUnknown))
206 IUnknown_AddRef(iface);
207 *object = iface;
208 return S_OK;
211 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
213 *object = NULL;
214 return E_NOINTERFACE;
217 static ULONG STDMETHODCALLTYPE d3d10_depthstencil_state_AddRef(ID3D10DepthStencilState *iface)
219 struct d3d10_depthstencil_state *This = impl_from_ID3D10DepthStencilState(iface);
220 ULONG refcount = InterlockedIncrement(&This->refcount);
222 TRACE("%p increasing refcount to %u.\n", This, refcount);
224 return refcount;
227 static ULONG STDMETHODCALLTYPE d3d10_depthstencil_state_Release(ID3D10DepthStencilState *iface)
229 struct d3d10_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
230 ULONG refcount = InterlockedDecrement(&state->refcount);
232 TRACE("%p decreasing refcount to %u.\n", state, refcount);
234 if (!refcount)
236 struct d3d10_device *device = impl_from_ID3D10Device(state->device);
237 wine_rb_remove(&device->depthstencil_states, &state->desc);
238 ID3D10Device1_Release(state->device);
239 wined3d_private_store_cleanup(&state->private_store);
240 HeapFree(GetProcessHeap(), 0, state);
243 return refcount;
246 /* ID3D10DeviceChild methods */
248 static void STDMETHODCALLTYPE d3d10_depthstencil_state_GetDevice(ID3D10DepthStencilState *iface, ID3D10Device **device)
250 struct d3d10_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
252 TRACE("iface %p, device %p.\n", iface, device);
254 *device = (ID3D10Device *)state->device;
255 ID3D10Device_AddRef(*device);
258 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_state_GetPrivateData(ID3D10DepthStencilState *iface,
259 REFGUID guid, UINT *data_size, void *data)
261 struct d3d10_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
263 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
264 iface, debugstr_guid(guid), data_size, data);
266 return d3d10_get_private_data(&state->private_store, guid, data_size, data);
269 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_state_SetPrivateData(ID3D10DepthStencilState *iface,
270 REFGUID guid, UINT data_size, const void *data)
272 struct d3d10_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
274 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
275 iface, debugstr_guid(guid), data_size, data);
277 return d3d10_set_private_data(&state->private_store, guid, data_size, data);
280 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_state_SetPrivateDataInterface(ID3D10DepthStencilState *iface,
281 REFGUID guid, const IUnknown *data)
283 struct d3d10_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
285 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
287 return d3d10_set_private_data_interface(&state->private_store, guid, data);
290 /* ID3D10DepthStencilState methods */
292 static void STDMETHODCALLTYPE d3d10_depthstencil_state_GetDesc(ID3D10DepthStencilState *iface,
293 D3D10_DEPTH_STENCIL_DESC *desc)
295 struct d3d10_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
297 TRACE("iface %p, desc %p.\n", iface, desc);
299 *desc = state->desc;
302 static const struct ID3D10DepthStencilStateVtbl d3d10_depthstencil_state_vtbl =
304 /* IUnknown methods */
305 d3d10_depthstencil_state_QueryInterface,
306 d3d10_depthstencil_state_AddRef,
307 d3d10_depthstencil_state_Release,
308 /* ID3D10DeviceChild methods */
309 d3d10_depthstencil_state_GetDevice,
310 d3d10_depthstencil_state_GetPrivateData,
311 d3d10_depthstencil_state_SetPrivateData,
312 d3d10_depthstencil_state_SetPrivateDataInterface,
313 /* ID3D10DepthStencilState methods */
314 d3d10_depthstencil_state_GetDesc,
317 HRESULT d3d10_depthstencil_state_init(struct d3d10_depthstencil_state *state, struct d3d10_device *device,
318 const D3D10_DEPTH_STENCIL_DESC *desc)
320 state->ID3D10DepthStencilState_iface.lpVtbl = &d3d10_depthstencil_state_vtbl;
321 state->refcount = 1;
322 wined3d_private_store_init(&state->private_store);
323 state->desc = *desc;
325 if (wine_rb_put(&device->depthstencil_states, desc, &state->entry) == -1)
327 ERR("Failed to insert depthstencil state entry.\n");
328 wined3d_private_store_cleanup(&state->private_store);
329 return E_FAIL;
332 state->device = &device->ID3D10Device1_iface;
333 ID3D10Device1_AddRef(state->device);
335 return S_OK;
338 struct d3d10_depthstencil_state *unsafe_impl_from_ID3D10DepthStencilState(ID3D10DepthStencilState *iface)
340 if (!iface)
341 return NULL;
342 assert(iface->lpVtbl == &d3d10_depthstencil_state_vtbl);
344 return impl_from_ID3D10DepthStencilState(iface);
347 static inline struct d3d10_rasterizer_state *impl_from_ID3D10RasterizerState(ID3D10RasterizerState *iface)
349 return CONTAINING_RECORD(iface, struct d3d10_rasterizer_state, ID3D10RasterizerState_iface);
352 /* IUnknown methods */
354 static HRESULT STDMETHODCALLTYPE d3d10_rasterizer_state_QueryInterface(ID3D10RasterizerState *iface,
355 REFIID riid, void **object)
357 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
359 if (IsEqualGUID(riid, &IID_ID3D10RasterizerState)
360 || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
361 || IsEqualGUID(riid, &IID_IUnknown))
363 IUnknown_AddRef(iface);
364 *object = iface;
365 return S_OK;
368 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
370 *object = NULL;
371 return E_NOINTERFACE;
374 static ULONG STDMETHODCALLTYPE d3d10_rasterizer_state_AddRef(ID3D10RasterizerState *iface)
376 struct d3d10_rasterizer_state *This = impl_from_ID3D10RasterizerState(iface);
377 ULONG refcount = InterlockedIncrement(&This->refcount);
379 TRACE("%p increasing refcount to %u.\n", This, refcount);
381 return refcount;
384 static ULONG STDMETHODCALLTYPE d3d10_rasterizer_state_Release(ID3D10RasterizerState *iface)
386 struct d3d10_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
387 ULONG refcount = InterlockedDecrement(&state->refcount);
389 TRACE("%p decreasing refcount to %u.\n", state, refcount);
391 if (!refcount)
393 struct d3d10_device *device = impl_from_ID3D10Device(state->device);
394 wine_rb_remove(&device->rasterizer_states, &state->desc);
395 ID3D10Device1_Release(state->device);
396 wined3d_private_store_cleanup(&state->private_store);
397 HeapFree(GetProcessHeap(), 0, state);
400 return refcount;
403 /* ID3D10DeviceChild methods */
405 static void STDMETHODCALLTYPE d3d10_rasterizer_state_GetDevice(ID3D10RasterizerState *iface, ID3D10Device **device)
407 struct d3d10_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
409 TRACE("iface %p, device %p.\n", iface, device);
411 *device = (ID3D10Device *)state->device;
412 ID3D10Device_AddRef(*device);
415 static HRESULT STDMETHODCALLTYPE d3d10_rasterizer_state_GetPrivateData(ID3D10RasterizerState *iface,
416 REFGUID guid, UINT *data_size, void *data)
418 struct d3d10_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
420 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
421 iface, debugstr_guid(guid), data_size, data);
423 return d3d10_get_private_data(&state->private_store, guid, data_size, data);
426 static HRESULT STDMETHODCALLTYPE d3d10_rasterizer_state_SetPrivateData(ID3D10RasterizerState *iface,
427 REFGUID guid, UINT data_size, const void *data)
429 struct d3d10_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
431 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
432 iface, debugstr_guid(guid), data_size, data);
434 return d3d10_set_private_data(&state->private_store, guid, data_size, data);
437 static HRESULT STDMETHODCALLTYPE d3d10_rasterizer_state_SetPrivateDataInterface(ID3D10RasterizerState *iface,
438 REFGUID guid, const IUnknown *data)
440 struct d3d10_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
442 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
444 return d3d10_set_private_data_interface(&state->private_store, guid, data);
447 /* ID3D10RasterizerState methods */
449 static void STDMETHODCALLTYPE d3d10_rasterizer_state_GetDesc(ID3D10RasterizerState *iface,
450 D3D10_RASTERIZER_DESC *desc)
452 struct d3d10_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
454 TRACE("iface %p, desc %p.\n", iface, desc);
456 *desc = state->desc;
459 static const struct ID3D10RasterizerStateVtbl d3d10_rasterizer_state_vtbl =
461 /* IUnknown methods */
462 d3d10_rasterizer_state_QueryInterface,
463 d3d10_rasterizer_state_AddRef,
464 d3d10_rasterizer_state_Release,
465 /* ID3D10DeviceChild methods */
466 d3d10_rasterizer_state_GetDevice,
467 d3d10_rasterizer_state_GetPrivateData,
468 d3d10_rasterizer_state_SetPrivateData,
469 d3d10_rasterizer_state_SetPrivateDataInterface,
470 /* ID3D10RasterizerState methods */
471 d3d10_rasterizer_state_GetDesc,
474 HRESULT d3d10_rasterizer_state_init(struct d3d10_rasterizer_state *state, struct d3d10_device *device,
475 const D3D10_RASTERIZER_DESC *desc)
477 state->ID3D10RasterizerState_iface.lpVtbl = &d3d10_rasterizer_state_vtbl;
478 state->refcount = 1;
479 wined3d_private_store_init(&state->private_store);
480 state->desc = *desc;
482 if (wine_rb_put(&device->rasterizer_states, desc, &state->entry) == -1)
484 ERR("Failed to insert rasterizer state entry.\n");
485 wined3d_private_store_cleanup(&state->private_store);
486 return E_FAIL;
489 state->device = &device->ID3D10Device1_iface;
490 ID3D10Device1_AddRef(state->device);
492 return S_OK;
495 struct d3d10_rasterizer_state *unsafe_impl_from_ID3D10RasterizerState(ID3D10RasterizerState *iface)
497 if (!iface)
498 return NULL;
499 assert(iface->lpVtbl == &d3d10_rasterizer_state_vtbl);
501 return impl_from_ID3D10RasterizerState(iface);
504 static inline struct d3d10_sampler_state *impl_from_ID3D10SamplerState(ID3D10SamplerState *iface)
506 return CONTAINING_RECORD(iface, struct d3d10_sampler_state, ID3D10SamplerState_iface);
509 /* IUnknown methods */
511 static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_QueryInterface(ID3D10SamplerState *iface,
512 REFIID riid, void **object)
514 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
516 if (IsEqualGUID(riid, &IID_ID3D10SamplerState)
517 || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
518 || IsEqualGUID(riid, &IID_IUnknown))
520 IUnknown_AddRef(iface);
521 *object = iface;
522 return S_OK;
525 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
527 *object = NULL;
528 return E_NOINTERFACE;
531 static ULONG STDMETHODCALLTYPE d3d10_sampler_state_AddRef(ID3D10SamplerState *iface)
533 struct d3d10_sampler_state *This = impl_from_ID3D10SamplerState(iface);
534 ULONG refcount = InterlockedIncrement(&This->refcount);
536 TRACE("%p increasing refcount to %u.\n", This, refcount);
538 return refcount;
541 static ULONG STDMETHODCALLTYPE d3d10_sampler_state_Release(ID3D10SamplerState *iface)
543 struct d3d10_sampler_state *state = impl_from_ID3D10SamplerState(iface);
544 ULONG refcount = InterlockedDecrement(&state->refcount);
546 TRACE("%p decreasing refcount to %u.\n", state, refcount);
548 if (!refcount)
550 struct d3d10_device *device = impl_from_ID3D10Device(state->device);
552 wined3d_sampler_decref(state->wined3d_sampler);
553 wine_rb_remove(&device->sampler_states, &state->desc);
554 ID3D10Device1_Release(state->device);
555 wined3d_private_store_cleanup(&state->private_store);
556 HeapFree(GetProcessHeap(), 0, state);
559 return refcount;
562 /* ID3D10DeviceChild methods */
564 static void STDMETHODCALLTYPE d3d10_sampler_state_GetDevice(ID3D10SamplerState *iface, ID3D10Device **device)
566 struct d3d10_sampler_state *state = impl_from_ID3D10SamplerState(iface);
568 TRACE("iface %p, device %p.\n", iface, device);
570 *device = (ID3D10Device *)state->device;
571 ID3D10Device_AddRef(*device);
574 static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_GetPrivateData(ID3D10SamplerState *iface,
575 REFGUID guid, UINT *data_size, void *data)
577 struct d3d10_sampler_state *state = impl_from_ID3D10SamplerState(iface);
579 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
580 iface, debugstr_guid(guid), data_size, data);
582 return d3d10_get_private_data(&state->private_store, guid, data_size, data);
585 static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_SetPrivateData(ID3D10SamplerState *iface,
586 REFGUID guid, UINT data_size, const void *data)
588 struct d3d10_sampler_state *state = impl_from_ID3D10SamplerState(iface);
590 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
591 iface, debugstr_guid(guid), data_size, data);
593 return d3d10_set_private_data(&state->private_store, guid, data_size, data);
596 static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_SetPrivateDataInterface(ID3D10SamplerState *iface,
597 REFGUID guid, const IUnknown *data)
599 struct d3d10_sampler_state *state = impl_from_ID3D10SamplerState(iface);
601 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
603 return d3d10_set_private_data_interface(&state->private_store, guid, data);
606 /* ID3D10SamplerState methods */
608 static void STDMETHODCALLTYPE d3d10_sampler_state_GetDesc(ID3D10SamplerState *iface,
609 D3D10_SAMPLER_DESC *desc)
611 struct d3d10_sampler_state *state = impl_from_ID3D10SamplerState(iface);
613 TRACE("iface %p, desc %p.\n", iface, desc);
615 *desc = state->desc;
618 static const struct ID3D10SamplerStateVtbl d3d10_sampler_state_vtbl =
620 /* IUnknown methods */
621 d3d10_sampler_state_QueryInterface,
622 d3d10_sampler_state_AddRef,
623 d3d10_sampler_state_Release,
624 /* ID3D10DeviceChild methods */
625 d3d10_sampler_state_GetDevice,
626 d3d10_sampler_state_GetPrivateData,
627 d3d10_sampler_state_SetPrivateData,
628 d3d10_sampler_state_SetPrivateDataInterface,
629 /* ID3D10SamplerState methods */
630 d3d10_sampler_state_GetDesc,
633 static enum wined3d_texture_address wined3d_texture_address_from_d3d10core(enum D3D10_TEXTURE_ADDRESS_MODE t)
635 return (enum wined3d_texture_address)t;
638 static enum wined3d_texture_filter_type wined3d_texture_filter_mip_from_d3d10core(enum D3D10_FILTER f)
640 if (f & D3D10_FILTER_MIP_MASK)
641 return WINED3D_TEXF_LINEAR;
642 return WINED3D_TEXF_POINT;
645 static enum wined3d_texture_filter_type wined3d_texture_filter_mag_from_d3d10core(enum D3D10_FILTER f)
647 if (f & D3D10_FILTER_MAG_MASK)
648 return WINED3D_TEXF_LINEAR;
649 return WINED3D_TEXF_POINT;
652 static enum wined3d_texture_filter_type wined3d_texture_filter_min_from_d3d10core(enum D3D10_FILTER f)
654 if (f & D3D10_FILTER_MIN_MASK)
655 return WINED3D_TEXF_LINEAR;
656 return WINED3D_TEXF_POINT;
659 static BOOL wined3d_texture_compare_from_d3d10core(enum D3D10_FILTER f)
661 return f & D3D10_FILTER_COMPARE_MASK;
664 static enum wined3d_cmp_func wined3d_cmp_func_from_d3d10core(D3D10_COMPARISON_FUNC f)
666 return (enum wined3d_cmp_func)f;
669 HRESULT d3d10_sampler_state_init(struct d3d10_sampler_state *state, struct d3d10_device *device,
670 const D3D10_SAMPLER_DESC *desc)
672 struct wined3d_sampler_desc wined3d_desc;
673 HRESULT hr;
675 state->ID3D10SamplerState_iface.lpVtbl = &d3d10_sampler_state_vtbl;
676 state->refcount = 1;
677 wined3d_private_store_init(&state->private_store);
678 state->desc = *desc;
680 wined3d_desc.address_u = wined3d_texture_address_from_d3d10core(desc->AddressU);
681 wined3d_desc.address_v = wined3d_texture_address_from_d3d10core(desc->AddressV);
682 wined3d_desc.address_w = wined3d_texture_address_from_d3d10core(desc->AddressW);
683 memcpy(wined3d_desc.border_color, desc->BorderColor, sizeof(wined3d_desc.border_color));
684 wined3d_desc.mag_filter = wined3d_texture_filter_mag_from_d3d10core(desc->Filter);
685 wined3d_desc.min_filter = wined3d_texture_filter_min_from_d3d10core(desc->Filter);
686 wined3d_desc.mip_filter = wined3d_texture_filter_mip_from_d3d10core(desc->Filter);
687 wined3d_desc.lod_bias = desc->MipLODBias;
688 wined3d_desc.min_lod = desc->MinLOD;
689 wined3d_desc.max_lod = desc->MaxLOD;
690 wined3d_desc.max_anisotropy = desc->Filter & D3D10_FILTER_ANISO_MASK ? desc->MaxAnisotropy : 1;
691 wined3d_desc.compare = wined3d_texture_compare_from_d3d10core(desc->Filter);
692 wined3d_desc.comparison_func = wined3d_cmp_func_from_d3d10core(desc->ComparisonFunc);
693 wined3d_desc.srgb_decode = FALSE;
695 if (FAILED(hr = wined3d_sampler_create(device->wined3d_device, &wined3d_desc, state, &state->wined3d_sampler)))
697 WARN("Failed to create wined3d sampler, hr %#x.\n", hr);
698 wined3d_private_store_cleanup(&state->private_store);
699 return hr;
702 if (wine_rb_put(&device->sampler_states, desc, &state->entry) == -1)
704 ERR("Failed to insert sampler state entry.\n");
705 wined3d_sampler_decref(state->wined3d_sampler);
706 wined3d_private_store_cleanup(&state->private_store);
707 return E_FAIL;
710 state->device = &device->ID3D10Device1_iface;
711 ID3D10Device1_AddRef(state->device);
713 return S_OK;
716 struct d3d10_sampler_state *unsafe_impl_from_ID3D10SamplerState(ID3D10SamplerState *iface)
718 if (!iface)
719 return NULL;
720 assert(iface->lpVtbl == &d3d10_sampler_state_vtbl);
722 return impl_from_ID3D10SamplerState(iface);