d3d10core: Get rid of the "partial stub" FIXME in d3d10_device_CreateBuffer().
[wine/multimedia.git] / dlls / d3d10core / device.c
blob7b811a646504e90a35606e3009bb977c4062f632
1 /*
2 * Copyright 2008-2012 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 static void STDMETHODCALLTYPE d3d10_null_wined3d_object_destroyed(void *parent) {}
29 const struct wined3d_parent_ops d3d10_null_wined3d_parent_ops =
31 d3d10_null_wined3d_object_destroyed,
34 /* Inner IUnknown methods */
36 static inline struct d3d10_device *impl_from_IUnknown(IUnknown *iface)
38 return CONTAINING_RECORD(iface, struct d3d10_device, IUnknown_inner);
41 static HRESULT STDMETHODCALLTYPE d3d10_device_inner_QueryInterface(IUnknown *iface, REFIID riid, void **out)
43 struct d3d10_device *device = impl_from_IUnknown(iface);
45 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
47 if (IsEqualGUID(riid, &IID_ID3D10Device1)
48 || IsEqualGUID(riid, &IID_ID3D10Device)
49 || IsEqualGUID(riid, &IID_IUnknown))
51 *out = &device->ID3D10Device1_iface;
53 else if (IsEqualGUID(riid, &IID_ID3D10Multithread))
55 *out = &device->ID3D10Multithread_iface;
57 else if (IsEqualGUID(riid, &IID_IWineDXGIDeviceParent))
59 *out = &device->IWineDXGIDeviceParent_iface;
61 else
63 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
64 *out = NULL;
65 return E_NOINTERFACE;
68 IUnknown_AddRef((IUnknown *)*out);
69 return S_OK;
72 static ULONG STDMETHODCALLTYPE d3d10_device_inner_AddRef(IUnknown *iface)
74 struct d3d10_device *This = impl_from_IUnknown(iface);
75 ULONG refcount = InterlockedIncrement(&This->refcount);
77 TRACE("%p increasing refcount to %u\n", This, refcount);
79 return refcount;
82 static ULONG STDMETHODCALLTYPE d3d10_device_inner_Release(IUnknown *iface)
84 struct d3d10_device *device = impl_from_IUnknown(iface);
85 ULONG refcount = InterlockedDecrement(&device->refcount);
87 TRACE("%p decreasing refcount to %u.\n", device, refcount);
89 if (!refcount)
91 if (device->wined3d_device)
92 wined3d_device_decref(device->wined3d_device);
93 wine_rb_destroy(&device->sampler_states, NULL, NULL);
94 wine_rb_destroy(&device->rasterizer_states, NULL, NULL);
95 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
96 wine_rb_destroy(&device->blend_states, NULL, NULL);
99 return refcount;
102 /* IUnknown methods */
104 static HRESULT STDMETHODCALLTYPE d3d10_device_QueryInterface(ID3D10Device1 *iface, REFIID riid,
105 void **ppv)
107 struct d3d10_device *This = impl_from_ID3D10Device(iface);
108 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
111 static ULONG STDMETHODCALLTYPE d3d10_device_AddRef(ID3D10Device1 *iface)
113 struct d3d10_device *This = impl_from_ID3D10Device(iface);
114 return IUnknown_AddRef(This->outer_unk);
117 static ULONG STDMETHODCALLTYPE d3d10_device_Release(ID3D10Device1 *iface)
119 struct d3d10_device *This = impl_from_ID3D10Device(iface);
120 return IUnknown_Release(This->outer_unk);
123 /* ID3D10Device methods */
125 static void STDMETHODCALLTYPE d3d10_device_VSSetConstantBuffers(ID3D10Device1 *iface,
126 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
128 struct d3d10_device *device = impl_from_ID3D10Device(iface);
129 unsigned int i;
131 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
132 iface, start_slot, buffer_count, buffers);
134 for (i = 0; i < buffer_count; ++i)
136 struct d3d10_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
138 wined3d_device_set_vs_cb(device->wined3d_device, start_slot + i,
139 buffer ? buffer->wined3d_buffer : NULL);
143 static void STDMETHODCALLTYPE d3d10_device_PSSetShaderResources(ID3D10Device1 *iface,
144 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
146 struct d3d10_device *device = impl_from_ID3D10Device(iface);
147 unsigned int i;
149 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
150 iface, start_slot, view_count, views);
152 for (i = 0; i < view_count; ++i)
154 struct d3d10_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
156 wined3d_device_set_ps_resource_view(device->wined3d_device, start_slot + i,
157 view ? view->wined3d_view : NULL);
161 static void STDMETHODCALLTYPE d3d10_device_PSSetShader(ID3D10Device1 *iface,
162 ID3D10PixelShader *shader)
164 struct d3d10_device *This = impl_from_ID3D10Device(iface);
165 struct d3d10_pixel_shader *ps = unsafe_impl_from_ID3D10PixelShader(shader);
167 TRACE("iface %p, shader %p\n", iface, shader);
169 wined3d_device_set_pixel_shader(This->wined3d_device, ps ? ps->wined3d_shader : NULL);
172 static void STDMETHODCALLTYPE d3d10_device_PSSetSamplers(ID3D10Device1 *iface,
173 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
175 struct d3d10_device *device = impl_from_ID3D10Device(iface);
176 unsigned int i;
178 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
179 iface, start_slot, sampler_count, samplers);
181 for (i = 0; i < sampler_count; ++i)
183 struct d3d10_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
185 wined3d_device_set_ps_sampler(device->wined3d_device, start_slot + i,
186 sampler ? sampler->wined3d_sampler : NULL);
190 static void STDMETHODCALLTYPE d3d10_device_VSSetShader(ID3D10Device1 *iface,
191 ID3D10VertexShader *shader)
193 struct d3d10_device *This = impl_from_ID3D10Device(iface);
194 struct d3d10_vertex_shader *vs = unsafe_impl_from_ID3D10VertexShader(shader);
196 TRACE("iface %p, shader %p\n", iface, shader);
198 wined3d_device_set_vertex_shader(This->wined3d_device, vs ? vs->wined3d_shader : NULL);
201 static void STDMETHODCALLTYPE d3d10_device_DrawIndexed(ID3D10Device1 *iface, UINT index_count,
202 UINT start_index_location, INT base_vertex_location)
204 struct d3d10_device *This = impl_from_ID3D10Device(iface);
206 TRACE("iface %p, index_count %u, start_index_location %u, base_vertex_location %d.\n",
207 iface, index_count, start_index_location, base_vertex_location);
209 wined3d_device_set_base_vertex_index(This->wined3d_device, base_vertex_location);
210 wined3d_device_draw_indexed_primitive(This->wined3d_device, start_index_location, index_count);
213 static void STDMETHODCALLTYPE d3d10_device_Draw(ID3D10Device1 *iface, UINT vertex_count,
214 UINT start_vertex_location)
216 struct d3d10_device *This = impl_from_ID3D10Device(iface);
218 TRACE("iface %p, vertex_count %u, start_vertex_location %u\n",
219 iface, vertex_count, start_vertex_location);
221 wined3d_device_draw_primitive(This->wined3d_device, start_vertex_location, vertex_count);
224 static void STDMETHODCALLTYPE d3d10_device_PSSetConstantBuffers(ID3D10Device1 *iface,
225 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
227 struct d3d10_device *device = impl_from_ID3D10Device(iface);
228 unsigned int i;
230 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
231 iface, start_slot, buffer_count, buffers);
233 for (i = 0; i < buffer_count; ++i)
235 struct d3d10_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
237 wined3d_device_set_ps_cb(device->wined3d_device, start_slot + i,
238 buffer ? buffer->wined3d_buffer : NULL);
242 static void STDMETHODCALLTYPE d3d10_device_IASetInputLayout(ID3D10Device1 *iface,
243 ID3D10InputLayout *input_layout)
245 struct d3d10_device *This = impl_from_ID3D10Device(iface);
246 struct d3d10_input_layout *layout = unsafe_impl_from_ID3D10InputLayout(input_layout);
248 TRACE("iface %p, input_layout %p\n", iface, input_layout);
250 wined3d_device_set_vertex_declaration(This->wined3d_device,
251 layout ? layout->wined3d_decl : NULL);
254 static void STDMETHODCALLTYPE d3d10_device_IASetVertexBuffers(ID3D10Device1 *iface, UINT start_slot,
255 UINT buffer_count, ID3D10Buffer *const *buffers, const UINT *strides, const UINT *offsets)
257 struct d3d10_device *This = impl_from_ID3D10Device(iface);
258 unsigned int i;
260 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p\n",
261 iface, start_slot, buffer_count, buffers, strides, offsets);
263 for (i = 0; i < buffer_count; ++i)
265 struct d3d10_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
267 wined3d_device_set_stream_source(This->wined3d_device, start_slot + i,
268 buffer ? buffer->wined3d_buffer : NULL, offsets[i], strides[i]);
272 static void STDMETHODCALLTYPE d3d10_device_IASetIndexBuffer(ID3D10Device1 *iface,
273 ID3D10Buffer *buffer, DXGI_FORMAT format, UINT offset)
275 struct d3d10_device *This = impl_from_ID3D10Device(iface);
276 struct d3d10_buffer *buffer_impl = unsafe_impl_from_ID3D10Buffer(buffer);
278 TRACE("iface %p, buffer %p, format %s, offset %u.\n",
279 iface, buffer, debug_dxgi_format(format), offset);
281 wined3d_device_set_index_buffer(This->wined3d_device,
282 buffer_impl ? buffer_impl->wined3d_buffer : NULL,
283 wined3dformat_from_dxgi_format(format));
284 if (offset) FIXME("offset %u not supported.\n", offset);
287 static void STDMETHODCALLTYPE d3d10_device_DrawIndexedInstanced(ID3D10Device1 *iface,
288 UINT instance_index_count, UINT instance_count, UINT start_index_location,
289 INT base_vertex_location, UINT start_instance_location)
291 struct d3d10_device *device = impl_from_ID3D10Device(iface);
293 TRACE("iface %p, instance_index_count %u, instance_count %u, start_index_location %u,\n"
294 "\tbase_vertex_location %d, start_instance_location %u.\n",
295 iface, instance_index_count, instance_count, start_index_location,
296 base_vertex_location, start_instance_location);
298 wined3d_device_set_base_vertex_index(device->wined3d_device, base_vertex_location);
299 wined3d_device_draw_indexed_primitive_instanced(device->wined3d_device, start_index_location,
300 instance_index_count, start_instance_location, instance_count);
303 static void STDMETHODCALLTYPE d3d10_device_DrawInstanced(ID3D10Device1 *iface,
304 UINT instance_vertex_count, UINT instance_count,
305 UINT start_vertex_location, UINT start_instance_location)
307 FIXME("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u,\n"
308 "\tstart_instance_location %u stub!\n", iface, instance_vertex_count, instance_count,
309 start_vertex_location, start_instance_location);
312 static void STDMETHODCALLTYPE d3d10_device_GSSetConstantBuffers(ID3D10Device1 *iface,
313 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
315 struct d3d10_device *device = impl_from_ID3D10Device(iface);
316 unsigned int i;
318 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
319 iface, start_slot, buffer_count, buffers);
321 for (i = 0; i < buffer_count; ++i)
323 struct d3d10_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
325 wined3d_device_set_gs_cb(device->wined3d_device, start_slot + i,
326 buffer ? buffer->wined3d_buffer : NULL);
330 static void STDMETHODCALLTYPE d3d10_device_GSSetShader(ID3D10Device1 *iface, ID3D10GeometryShader *shader)
332 struct d3d10_device *device = impl_from_ID3D10Device(iface);
333 struct d3d10_geometry_shader *gs = unsafe_impl_from_ID3D10GeometryShader(shader);
335 TRACE("iface %p, shader %p.\n", iface, shader);
337 wined3d_device_set_geometry_shader(device->wined3d_device, gs ? gs->wined3d_shader : NULL);
340 static void STDMETHODCALLTYPE d3d10_device_IASetPrimitiveTopology(ID3D10Device1 *iface,
341 D3D10_PRIMITIVE_TOPOLOGY topology)
343 struct d3d10_device *This = impl_from_ID3D10Device(iface);
345 TRACE("iface %p, topology %s\n", iface, debug_d3d10_primitive_topology(topology));
347 wined3d_device_set_primitive_type(This->wined3d_device, (enum wined3d_primitive_type)topology);
350 static void STDMETHODCALLTYPE d3d10_device_VSSetShaderResources(ID3D10Device1 *iface,
351 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
353 struct d3d10_device *device = impl_from_ID3D10Device(iface);
354 unsigned int i;
356 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
357 iface, start_slot, view_count, views);
359 for (i = 0; i < view_count; ++i)
361 struct d3d10_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
363 wined3d_device_set_vs_resource_view(device->wined3d_device, start_slot + i,
364 view ? view->wined3d_view : NULL);
368 static void STDMETHODCALLTYPE d3d10_device_VSSetSamplers(ID3D10Device1 *iface,
369 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
371 struct d3d10_device *device = impl_from_ID3D10Device(iface);
372 unsigned int i;
374 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
375 iface, start_slot, sampler_count, samplers);
377 for (i = 0; i < sampler_count; ++i)
379 struct d3d10_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
381 wined3d_device_set_vs_sampler(device->wined3d_device, start_slot + i,
382 sampler ? sampler->wined3d_sampler : NULL);
386 static void STDMETHODCALLTYPE d3d10_device_SetPredication(ID3D10Device1 *iface, ID3D10Predicate *predicate, BOOL value)
388 struct d3d10_device *device = impl_from_ID3D10Device(iface);
389 struct d3d10_query *query;
391 TRACE("iface %p, predicate %p, value %#x.\n", iface, predicate, value);
393 query = unsafe_impl_from_ID3D10Query((ID3D10Query *)predicate);
394 wined3d_device_set_predication(device->wined3d_device, query ? query->wined3d_query : NULL, value);
397 static void STDMETHODCALLTYPE d3d10_device_GSSetShaderResources(ID3D10Device1 *iface,
398 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
400 struct d3d10_device *device = impl_from_ID3D10Device(iface);
401 unsigned int i;
403 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
404 iface, start_slot, view_count, views);
406 for (i = 0; i < view_count; ++i)
408 struct d3d10_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
410 wined3d_device_set_gs_resource_view(device->wined3d_device, start_slot + i,
411 view ? view->wined3d_view : NULL);
415 static void STDMETHODCALLTYPE d3d10_device_GSSetSamplers(ID3D10Device1 *iface,
416 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
418 struct d3d10_device *device = impl_from_ID3D10Device(iface);
419 unsigned int i;
421 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
422 iface, start_slot, sampler_count, samplers);
424 for (i = 0; i < sampler_count; ++i)
426 struct d3d10_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
428 wined3d_device_set_gs_sampler(device->wined3d_device, start_slot + i,
429 sampler ? sampler->wined3d_sampler : NULL);
433 static void STDMETHODCALLTYPE d3d10_device_OMSetRenderTargets(ID3D10Device1 *iface,
434 UINT render_target_view_count, ID3D10RenderTargetView *const *render_target_views,
435 ID3D10DepthStencilView *depth_stencil_view)
437 struct d3d10_device *device = impl_from_ID3D10Device(iface);
438 struct d3d10_depthstencil_view *dsv;
439 unsigned int i;
441 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
442 iface, render_target_view_count, render_target_views, depth_stencil_view);
444 for (i = 0; i < render_target_view_count; ++i)
446 struct d3d10_rendertarget_view *rtv = unsafe_impl_from_ID3D10RenderTargetView(render_target_views[i]);
448 wined3d_device_set_rendertarget_view(device->wined3d_device, i,
449 rtv ? rtv->wined3d_view : NULL, FALSE);
451 for (; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
453 wined3d_device_set_rendertarget_view(device->wined3d_device, i, NULL, FALSE);
456 dsv = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
457 wined3d_device_set_depth_stencil_view(device->wined3d_device,
458 dsv ? dsv->wined3d_view : NULL);
461 static void STDMETHODCALLTYPE d3d10_device_OMSetBlendState(ID3D10Device1 *iface,
462 ID3D10BlendState *blend_state, const FLOAT blend_factor[4], UINT sample_mask)
464 struct d3d10_device *device = impl_from_ID3D10Device(iface);
465 const D3D10_BLEND_DESC *desc;
467 TRACE("iface %p, blend_state %p, blend_factor {%.8e %.8e %.8e %.8e}, sample_mask 0x%08x.\n",
468 iface, blend_state, blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3], sample_mask);
470 if (blend_factor[0] != 1.0f || blend_factor[1] != 1.0f || blend_factor[2] != 1.0f || blend_factor[3] != 1.0f)
471 FIXME("Ignoring blend factor {%.8e %.8e %.8e %.8e}.\n",
472 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
473 memcpy(device->blend_factor, blend_factor, 4 * sizeof(*blend_factor));
474 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEMASK, sample_mask);
475 if (!(device->blend_state = unsafe_impl_from_ID3D10BlendState(blend_state)))
477 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ALPHABLENDENABLE, FALSE);
478 wined3d_device_set_render_state(device->wined3d_device,
479 WINED3D_RS_COLORWRITEENABLE, D3D10_COLOR_WRITE_ENABLE_ALL);
480 wined3d_device_set_render_state(device->wined3d_device,
481 WINED3D_RS_COLORWRITEENABLE1, D3D10_COLOR_WRITE_ENABLE_ALL);
482 wined3d_device_set_render_state(device->wined3d_device,
483 WINED3D_RS_COLORWRITEENABLE2, D3D10_COLOR_WRITE_ENABLE_ALL);
484 wined3d_device_set_render_state(device->wined3d_device,
485 WINED3D_RS_COLORWRITEENABLE3, D3D10_COLOR_WRITE_ENABLE_ALL);
486 return;
489 desc = &device->blend_state->desc;
490 /* glSampleCoverage() */
491 if (desc->AlphaToCoverageEnable)
492 FIXME("Ignoring AlphaToCoverageEnable %#x.\n", desc->AlphaToCoverageEnable);
493 /* glEnableIndexedEXT(GL_BLEND, ...) */
494 FIXME("Per-rendertarget blend enable not implemented.\n");
495 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ALPHABLENDENABLE, desc->BlendEnable[0]);
496 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SRCBLEND, desc->SrcBlend);
497 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_DESTBLEND, desc->DestBlend);
498 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_BLENDOP, desc->BlendOp);
499 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SEPARATEALPHABLENDENABLE, TRUE);
500 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SRCBLENDALPHA, desc->SrcBlendAlpha);
501 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_DESTBLENDALPHA, desc->DestBlendAlpha);
502 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_BLENDOPALPHA, desc->BlendOpAlpha);
503 FIXME("Color mask > 3 not implemented.\n");
504 wined3d_device_set_render_state(device->wined3d_device,
505 WINED3D_RS_COLORWRITEENABLE, desc->RenderTargetWriteMask[0]);
506 wined3d_device_set_render_state(device->wined3d_device,
507 WINED3D_RS_COLORWRITEENABLE1, desc->RenderTargetWriteMask[1]);
508 wined3d_device_set_render_state(device->wined3d_device,
509 WINED3D_RS_COLORWRITEENABLE2, desc->RenderTargetWriteMask[2]);
510 wined3d_device_set_render_state(device->wined3d_device,
511 WINED3D_RS_COLORWRITEENABLE3, desc->RenderTargetWriteMask[3]);
514 static void STDMETHODCALLTYPE d3d10_device_OMSetDepthStencilState(ID3D10Device1 *iface,
515 ID3D10DepthStencilState *depth_stencil_state, UINT stencil_ref)
517 struct d3d10_device *device = impl_from_ID3D10Device(iface);
519 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
520 iface, depth_stencil_state, stencil_ref);
522 device->depth_stencil_state = unsafe_impl_from_ID3D10DepthStencilState(depth_stencil_state);
523 device->stencil_ref = stencil_ref;
526 static void STDMETHODCALLTYPE d3d10_device_SOSetTargets(ID3D10Device1 *iface,
527 UINT target_count, ID3D10Buffer *const *targets, const UINT *offsets)
529 struct d3d10_device *device = impl_from_ID3D10Device(iface);
530 unsigned int count, i;
532 TRACE("iface %p, target_count %u, targets %p, offsets %p.\n", iface, target_count, targets, offsets);
534 count = min(target_count, 4);
535 for (i = 0; i < count; ++i)
537 struct d3d10_buffer *buffer = unsafe_impl_from_ID3D10Buffer(targets[i]);
539 wined3d_device_set_stream_output(device->wined3d_device, i,
540 buffer ? buffer->wined3d_buffer : NULL, offsets[i]);
543 for (i = count; i < 4; ++i)
545 wined3d_device_set_stream_output(device->wined3d_device, i, NULL, 0);
549 static void STDMETHODCALLTYPE d3d10_device_DrawAuto(ID3D10Device1 *iface)
551 FIXME("iface %p stub!\n", iface);
554 static void STDMETHODCALLTYPE d3d10_device_RSSetState(ID3D10Device1 *iface, ID3D10RasterizerState *rasterizer_state)
556 struct d3d10_device *device = impl_from_ID3D10Device(iface);
557 const D3D10_RASTERIZER_DESC *desc;
559 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
561 if (!(device->rasterizer_state = unsafe_impl_from_ID3D10RasterizerState(rasterizer_state)))
563 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_FILLMODE, WINED3D_FILL_SOLID);
564 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_CULLMODE, WINED3D_CULL_CCW);
565 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SCISSORTESTENABLE, FALSE);
566 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEANTIALIAS, FALSE);
567 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ANTIALIASEDLINEENABLE, FALSE);
568 return;
571 desc = &device->rasterizer_state->desc;
572 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_FILLMODE, desc->FillMode);
573 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_CULLMODE, desc->CullMode);
574 /* glFrontFace() */
575 if (desc->FrontCounterClockwise)
576 FIXME("Ignoring FrontCounterClockwise %#x.\n", desc->FrontCounterClockwise);
577 /* OpenGL style depth bias. */
578 if (desc->DepthBias || desc->SlopeScaledDepthBias)
579 FIXME("Ignoring depth bias.\n");
580 /* GL_DEPTH_CLAMP */
581 if (!desc->DepthClipEnable)
582 FIXME("Ignoring DepthClipEnable %#x.\n", desc->DepthClipEnable);
583 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SCISSORTESTENABLE, desc->ScissorEnable);
584 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEANTIALIAS, desc->MultisampleEnable);
585 wined3d_device_set_render_state(device->wined3d_device,
586 WINED3D_RS_ANTIALIASEDLINEENABLE, desc->AntialiasedLineEnable);
589 static void STDMETHODCALLTYPE d3d10_device_RSSetViewports(ID3D10Device1 *iface,
590 UINT viewport_count, const D3D10_VIEWPORT *viewports)
592 struct d3d10_device *device = impl_from_ID3D10Device(iface);
593 struct wined3d_viewport wined3d_vp;
595 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
597 if (viewport_count > 1)
598 FIXME("Multiple viewports not implemented.\n");
600 if (!viewport_count)
601 return;
603 wined3d_vp.x = viewports[0].TopLeftX;
604 wined3d_vp.y = viewports[0].TopLeftY;
605 wined3d_vp.width = viewports[0].Width;
606 wined3d_vp.height = viewports[0].Height;
607 wined3d_vp.min_z = viewports[0].MinDepth;
608 wined3d_vp.max_z = viewports[0].MaxDepth;
610 wined3d_device_set_viewport(device->wined3d_device, &wined3d_vp);
613 static void STDMETHODCALLTYPE d3d10_device_RSSetScissorRects(ID3D10Device1 *iface,
614 UINT rect_count, const D3D10_RECT *rects)
616 struct d3d10_device *device = impl_from_ID3D10Device(iface);
618 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
620 if (rect_count > 1)
621 FIXME("Multiple scissor rects not implemented.\n");
623 if (!rect_count)
624 return;
626 wined3d_device_set_scissor_rect(device->wined3d_device, rects);
629 static void STDMETHODCALLTYPE d3d10_device_CopySubresourceRegion(ID3D10Device1 *iface,
630 ID3D10Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
631 ID3D10Resource *src_resource, UINT src_subresource_idx, const D3D10_BOX *src_box)
633 FIXME("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u,\n"
634 "\tsrc_resource %p, src_subresource_idx %u, src_box %p stub!\n",
635 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
636 src_resource, src_subresource_idx, src_box);
639 static void STDMETHODCALLTYPE d3d10_device_CopyResource(ID3D10Device1 *iface,
640 ID3D10Resource *dst_resource, ID3D10Resource *src_resource)
642 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
643 struct d3d10_device *device = impl_from_ID3D10Device(iface);
645 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
647 wined3d_dst_resource = wined3d_resource_from_resource(dst_resource);
648 wined3d_src_resource = wined3d_resource_from_resource(src_resource);
649 wined3d_device_copy_resource(device->wined3d_device, wined3d_dst_resource, wined3d_src_resource);
652 static void STDMETHODCALLTYPE d3d10_device_UpdateSubresource(ID3D10Device1 *iface,
653 ID3D10Resource *resource, UINT subresource_idx, const D3D10_BOX *box,
654 const void *data, UINT row_pitch, UINT depth_pitch)
656 FIXME("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u stub!\n",
657 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
660 static void STDMETHODCALLTYPE d3d10_device_ClearRenderTargetView(ID3D10Device1 *iface,
661 ID3D10RenderTargetView *render_target_view, const FLOAT color_rgba[4])
663 struct d3d10_device *device = impl_from_ID3D10Device(iface);
664 struct d3d10_rendertarget_view *view = unsafe_impl_from_ID3D10RenderTargetView(render_target_view);
665 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
666 HRESULT hr;
668 TRACE("iface %p, render_target_view %p, color_rgba {%.8e, %.8e, %.8e, %.8e}.\n",
669 iface, render_target_view, color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]);
671 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL, &color)))
672 ERR("Failed to clear view, hr %#x.\n", hr);
675 static void STDMETHODCALLTYPE d3d10_device_ClearDepthStencilView(ID3D10Device1 *iface,
676 ID3D10DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
678 FIXME("iface %p, depth_stencil_view %p, flags %#x, depth %f, stencil %u stub!\n",
679 iface, depth_stencil_view, flags, depth, stencil);
682 static void STDMETHODCALLTYPE d3d10_device_GenerateMips(ID3D10Device1 *iface,
683 ID3D10ShaderResourceView *shader_resource_view)
685 FIXME("iface %p, shader_resource_view %p stub!\n", iface, shader_resource_view);
688 static void STDMETHODCALLTYPE d3d10_device_ResolveSubresource(ID3D10Device1 *iface,
689 ID3D10Resource *dst_resource, UINT dst_subresource_idx,
690 ID3D10Resource *src_resource, UINT src_subresource_idx, DXGI_FORMAT format)
692 FIXME("iface %p, dst_resource %p, dst_subresource_idx %u,\n"
693 "\tsrc_resource %p, src_subresource_idx %u, format %s stub!\n",
694 iface, dst_resource, dst_subresource_idx,
695 src_resource, src_subresource_idx, debug_dxgi_format(format));
698 static void STDMETHODCALLTYPE d3d10_device_VSGetConstantBuffers(ID3D10Device1 *iface,
699 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
701 struct d3d10_device *device = impl_from_ID3D10Device(iface);
702 unsigned int i;
704 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
705 iface, start_slot, buffer_count, buffers);
707 for (i = 0; i < buffer_count; ++i)
709 struct wined3d_buffer *wined3d_buffer;
710 struct d3d10_buffer *buffer_impl;
712 if (!(wined3d_buffer = wined3d_device_get_vs_cb(device->wined3d_device, start_slot + i)))
714 buffers[i] = NULL;
715 continue;
718 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
719 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
720 ID3D10Buffer_AddRef(buffers[i]);
724 static void STDMETHODCALLTYPE d3d10_device_PSGetShaderResources(ID3D10Device1 *iface,
725 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
727 struct d3d10_device *device = impl_from_ID3D10Device(iface);
728 unsigned int i;
730 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
731 iface, start_slot, view_count, views);
733 for (i = 0; i < view_count; ++i)
735 struct wined3d_shader_resource_view *wined3d_view;
736 struct d3d10_shader_resource_view *view_impl;
738 if (!(wined3d_view = wined3d_device_get_ps_resource_view(device->wined3d_device, start_slot + i)))
740 views[i] = NULL;
741 continue;
744 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
745 views[i] = &view_impl->ID3D10ShaderResourceView_iface;
746 ID3D10ShaderResourceView_AddRef(views[i]);
750 static void STDMETHODCALLTYPE d3d10_device_PSGetShader(ID3D10Device1 *iface, ID3D10PixelShader **shader)
752 struct d3d10_device *device = impl_from_ID3D10Device(iface);
753 struct d3d10_pixel_shader *shader_impl;
754 struct wined3d_shader *wined3d_shader;
756 TRACE("iface %p, shader %p.\n", iface, shader);
758 if (!(wined3d_shader = wined3d_device_get_pixel_shader(device->wined3d_device)))
760 *shader = NULL;
761 return;
764 shader_impl = wined3d_shader_get_parent(wined3d_shader);
765 *shader = &shader_impl->ID3D10PixelShader_iface;
766 ID3D10PixelShader_AddRef(*shader);
769 static void STDMETHODCALLTYPE d3d10_device_PSGetSamplers(ID3D10Device1 *iface,
770 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
772 struct d3d10_device *device = impl_from_ID3D10Device(iface);
773 unsigned int i;
775 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
776 iface, start_slot, sampler_count, samplers);
778 for (i = 0; i < sampler_count; ++i)
780 struct d3d10_sampler_state *sampler_impl;
781 struct wined3d_sampler *wined3d_sampler;
783 if (!(wined3d_sampler = wined3d_device_get_ps_sampler(device->wined3d_device, start_slot + i)))
785 samplers[i] = NULL;
786 continue;
789 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
790 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
791 ID3D10SamplerState_AddRef(samplers[i]);
795 static void STDMETHODCALLTYPE d3d10_device_VSGetShader(ID3D10Device1 *iface, ID3D10VertexShader **shader)
797 struct d3d10_device *device = impl_from_ID3D10Device(iface);
798 struct d3d10_vertex_shader *shader_impl;
799 struct wined3d_shader *wined3d_shader;
801 TRACE("iface %p, shader %p.\n", iface, shader);
803 if (!(wined3d_shader = wined3d_device_get_vertex_shader(device->wined3d_device)))
805 *shader = NULL;
806 return;
809 shader_impl = wined3d_shader_get_parent(wined3d_shader);
810 *shader = &shader_impl->ID3D10VertexShader_iface;
811 ID3D10VertexShader_AddRef(*shader);
814 static void STDMETHODCALLTYPE d3d10_device_PSGetConstantBuffers(ID3D10Device1 *iface,
815 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
817 struct d3d10_device *device = impl_from_ID3D10Device(iface);
818 unsigned int i;
820 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
821 iface, start_slot, buffer_count, buffers);
823 for (i = 0; i < buffer_count; ++i)
825 struct wined3d_buffer *wined3d_buffer;
826 struct d3d10_buffer *buffer_impl;
828 if (!(wined3d_buffer = wined3d_device_get_ps_cb(device->wined3d_device, start_slot + i)))
830 buffers[i] = NULL;
831 continue;
834 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
835 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
836 ID3D10Buffer_AddRef(buffers[i]);
840 static void STDMETHODCALLTYPE d3d10_device_IAGetInputLayout(ID3D10Device1 *iface, ID3D10InputLayout **input_layout)
842 struct d3d10_device *device = impl_from_ID3D10Device(iface);
843 struct wined3d_vertex_declaration *wined3d_declaration;
844 struct d3d10_input_layout *input_layout_impl;
846 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
848 if (!(wined3d_declaration = wined3d_device_get_vertex_declaration(device->wined3d_device)))
850 *input_layout = NULL;
851 return;
854 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
855 *input_layout = &input_layout_impl->ID3D10InputLayout_iface;
856 ID3D10InputLayout_AddRef(*input_layout);
859 static void STDMETHODCALLTYPE d3d10_device_IAGetVertexBuffers(ID3D10Device1 *iface,
860 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers, UINT *strides, UINT *offsets)
862 struct d3d10_device *device = impl_from_ID3D10Device(iface);
863 unsigned int i;
865 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
866 iface, start_slot, buffer_count, buffers, strides, offsets);
868 for (i = 0; i < buffer_count; ++i)
870 struct wined3d_buffer *wined3d_buffer;
871 struct d3d10_buffer *buffer_impl;
873 if (FAILED(wined3d_device_get_stream_source(device->wined3d_device, start_slot + i,
874 &wined3d_buffer, &offsets[i], &strides[i])))
875 ERR("Failed to get vertex buffer.\n");
877 if (!wined3d_buffer)
879 buffers[i] = NULL;
880 continue;
883 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
884 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
885 ID3D10Buffer_AddRef(buffers[i]);
889 static void STDMETHODCALLTYPE d3d10_device_IAGetIndexBuffer(ID3D10Device1 *iface,
890 ID3D10Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
892 struct d3d10_device *device = impl_from_ID3D10Device(iface);
893 enum wined3d_format_id wined3d_format;
894 struct wined3d_buffer *wined3d_buffer;
895 struct d3d10_buffer *buffer_impl;
897 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
899 wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format);
900 *format = dxgi_format_from_wined3dformat(wined3d_format);
901 *offset = 0; /* FIXME */
902 if (!wined3d_buffer)
904 *buffer = NULL;
905 return;
908 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
909 *buffer = &buffer_impl->ID3D10Buffer_iface;
910 ID3D10Buffer_AddRef(*buffer);
913 static void STDMETHODCALLTYPE d3d10_device_GSGetConstantBuffers(ID3D10Device1 *iface,
914 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
916 struct d3d10_device *device = impl_from_ID3D10Device(iface);
917 unsigned int i;
919 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
920 iface, start_slot, buffer_count, buffers);
922 for (i = 0; i < buffer_count; ++i)
924 struct wined3d_buffer *wined3d_buffer;
925 struct d3d10_buffer *buffer_impl;
927 if (!(wined3d_buffer = wined3d_device_get_gs_cb(device->wined3d_device, start_slot + i)))
929 buffers[i] = NULL;
930 continue;
933 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
934 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
935 ID3D10Buffer_AddRef(buffers[i]);
939 static void STDMETHODCALLTYPE d3d10_device_GSGetShader(ID3D10Device1 *iface, ID3D10GeometryShader **shader)
941 struct d3d10_device *device = impl_from_ID3D10Device(iface);
942 struct d3d10_geometry_shader *shader_impl;
943 struct wined3d_shader *wined3d_shader;
945 TRACE("iface %p, shader %p.\n", iface, shader);
947 if (!(wined3d_shader = wined3d_device_get_geometry_shader(device->wined3d_device)))
949 *shader = NULL;
950 return;
953 shader_impl = wined3d_shader_get_parent(wined3d_shader);
954 *shader = &shader_impl->ID3D10GeometryShader_iface;
955 ID3D10GeometryShader_AddRef(*shader);
958 static void STDMETHODCALLTYPE d3d10_device_IAGetPrimitiveTopology(ID3D10Device1 *iface,
959 D3D10_PRIMITIVE_TOPOLOGY *topology)
961 struct d3d10_device *This = impl_from_ID3D10Device(iface);
963 TRACE("iface %p, topology %p\n", iface, topology);
965 wined3d_device_get_primitive_type(This->wined3d_device, (enum wined3d_primitive_type *)topology);
968 static void STDMETHODCALLTYPE d3d10_device_VSGetShaderResources(ID3D10Device1 *iface,
969 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
971 struct d3d10_device *device = impl_from_ID3D10Device(iface);
972 unsigned int i;
974 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
975 iface, start_slot, view_count, views);
977 for (i = 0; i < view_count; ++i)
979 struct wined3d_shader_resource_view *wined3d_view;
980 struct d3d10_shader_resource_view *view_impl;
982 if (!(wined3d_view = wined3d_device_get_vs_resource_view(device->wined3d_device, start_slot + i)))
984 views[i] = NULL;
985 continue;
988 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
989 views[i] = &view_impl->ID3D10ShaderResourceView_iface;
990 ID3D10ShaderResourceView_AddRef(views[i]);
994 static void STDMETHODCALLTYPE d3d10_device_VSGetSamplers(ID3D10Device1 *iface,
995 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
997 struct d3d10_device *device = impl_from_ID3D10Device(iface);
998 unsigned int i;
1000 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1001 iface, start_slot, sampler_count, samplers);
1003 for (i = 0; i < sampler_count; ++i)
1005 struct d3d10_sampler_state *sampler_impl;
1006 struct wined3d_sampler *wined3d_sampler;
1008 if (!(wined3d_sampler = wined3d_device_get_vs_sampler(device->wined3d_device, start_slot + i)))
1010 samplers[i] = NULL;
1011 continue;
1014 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1015 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
1016 ID3D10SamplerState_AddRef(samplers[i]);
1020 static void STDMETHODCALLTYPE d3d10_device_GetPredication(ID3D10Device1 *iface,
1021 ID3D10Predicate **predicate, BOOL *value)
1023 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1024 struct wined3d_query *wined3d_predicate;
1025 struct d3d10_query *predicate_impl;
1027 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
1029 if (!(wined3d_predicate = wined3d_device_get_predication(device->wined3d_device, value)))
1031 *predicate = NULL;
1032 return;
1035 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
1036 *predicate = (ID3D10Predicate *)&predicate_impl->ID3D10Query_iface;
1037 ID3D10Predicate_AddRef(*predicate);
1040 static void STDMETHODCALLTYPE d3d10_device_GSGetShaderResources(ID3D10Device1 *iface,
1041 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
1043 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1044 unsigned int i;
1046 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1047 iface, start_slot, view_count, views);
1049 for (i = 0; i < view_count; ++i)
1051 struct wined3d_shader_resource_view *wined3d_view;
1052 struct d3d10_shader_resource_view *view_impl;
1054 if (!(wined3d_view = wined3d_device_get_gs_resource_view(device->wined3d_device, start_slot + i)))
1056 views[i] = NULL;
1057 continue;
1060 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1061 views[i] = &view_impl->ID3D10ShaderResourceView_iface;
1062 ID3D10ShaderResourceView_AddRef(views[i]);
1066 static void STDMETHODCALLTYPE d3d10_device_GSGetSamplers(ID3D10Device1 *iface,
1067 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
1069 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1070 unsigned int i;
1072 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1073 iface, start_slot, sampler_count, samplers);
1075 for (i = 0; i < sampler_count; ++i)
1077 struct d3d10_sampler_state *sampler_impl;
1078 struct wined3d_sampler *wined3d_sampler;
1080 if (!(wined3d_sampler = wined3d_device_get_gs_sampler(device->wined3d_device, start_slot + i)))
1082 samplers[i] = NULL;
1083 continue;
1086 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1087 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
1088 ID3D10SamplerState_AddRef(samplers[i]);
1092 static void STDMETHODCALLTYPE d3d10_device_OMGetRenderTargets(ID3D10Device1 *iface,
1093 UINT view_count, ID3D10RenderTargetView **render_target_views, ID3D10DepthStencilView **depth_stencil_view)
1095 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1096 struct wined3d_rendertarget_view *wined3d_view;
1098 TRACE("iface %p, view_count %u, render_target_views %p, depth_stencil_view %p.\n",
1099 iface, view_count, render_target_views, depth_stencil_view);
1101 if (render_target_views)
1103 struct d3d10_rendertarget_view *view_impl;
1104 unsigned int i;
1106 for (i = 0; i < view_count; ++i)
1108 if (!(wined3d_view = wined3d_device_get_rendertarget_view(device->wined3d_device, i))
1109 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
1111 render_target_views[i] = NULL;
1112 continue;
1115 render_target_views[i] = &view_impl->ID3D10RenderTargetView_iface;
1116 ID3D10RenderTargetView_AddRef(render_target_views[i]);
1120 if (depth_stencil_view)
1122 struct d3d10_depthstencil_view *view_impl;
1124 if (!(wined3d_view = wined3d_device_get_depth_stencil_view(device->wined3d_device))
1125 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
1127 *depth_stencil_view = NULL;
1129 else
1131 *depth_stencil_view = &view_impl->ID3D10DepthStencilView_iface;
1132 ID3D10DepthStencilView_AddRef(*depth_stencil_view);
1137 static void STDMETHODCALLTYPE d3d10_device_OMGetBlendState(ID3D10Device1 *iface,
1138 ID3D10BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
1140 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1142 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
1143 iface, blend_state, blend_factor, sample_mask);
1145 if ((*blend_state = device->blend_state ? &device->blend_state->ID3D10BlendState_iface : NULL))
1146 ID3D10BlendState_AddRef(*blend_state);
1147 memcpy(blend_factor, device->blend_factor, 4 * sizeof(*blend_factor));
1148 *sample_mask = wined3d_device_get_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEMASK);
1151 static void STDMETHODCALLTYPE d3d10_device_OMGetDepthStencilState(ID3D10Device1 *iface,
1152 ID3D10DepthStencilState **depth_stencil_state, UINT *stencil_ref)
1154 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1156 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
1157 iface, depth_stencil_state, stencil_ref);
1159 if ((*depth_stencil_state = device->depth_stencil_state
1160 ? &device->depth_stencil_state->ID3D10DepthStencilState_iface : NULL))
1161 ID3D10DepthStencilState_AddRef(*depth_stencil_state);
1162 *stencil_ref = device->stencil_ref;
1165 static void STDMETHODCALLTYPE d3d10_device_SOGetTargets(ID3D10Device1 *iface,
1166 UINT buffer_count, ID3D10Buffer **buffers, UINT *offsets)
1168 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1169 unsigned int i;
1171 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n",
1172 iface, buffer_count, buffers, offsets);
1174 for (i = 0; i < buffer_count; ++i)
1176 struct wined3d_buffer *wined3d_buffer;
1177 struct d3d10_buffer *buffer_impl;
1179 if (!(wined3d_buffer = wined3d_device_get_stream_output(device->wined3d_device, i, &offsets[i])))
1181 buffers[i] = NULL;
1182 continue;
1185 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1186 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
1187 ID3D10Buffer_AddRef(buffers[i]);
1191 static void STDMETHODCALLTYPE d3d10_device_RSGetState(ID3D10Device1 *iface, ID3D10RasterizerState **rasterizer_state)
1193 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1195 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
1197 if ((*rasterizer_state = device->rasterizer_state ? &device->rasterizer_state->ID3D10RasterizerState_iface : NULL))
1198 ID3D10RasterizerState_AddRef(*rasterizer_state);
1201 static void STDMETHODCALLTYPE d3d10_device_RSGetViewports(ID3D10Device1 *iface,
1202 UINT *viewport_count, D3D10_VIEWPORT *viewports)
1204 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1205 struct wined3d_viewport wined3d_vp;
1207 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
1209 if (!viewports)
1211 *viewport_count = 1;
1212 return;
1215 if (!*viewport_count)
1216 return;
1218 wined3d_device_get_viewport(device->wined3d_device, &wined3d_vp);
1220 viewports[0].TopLeftX = wined3d_vp.x;
1221 viewports[0].TopLeftY = wined3d_vp.y;
1222 viewports[0].Width = wined3d_vp.width;
1223 viewports[0].Height = wined3d_vp.height;
1224 viewports[0].MinDepth = wined3d_vp.min_z;
1225 viewports[0].MaxDepth = wined3d_vp.max_z;
1227 if (*viewport_count > 1)
1228 memset(&viewports[1], 0, (*viewport_count - 1) * sizeof(*viewports));
1231 static void STDMETHODCALLTYPE d3d10_device_RSGetScissorRects(ID3D10Device1 *iface, UINT *rect_count, D3D10_RECT *rects)
1233 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1235 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
1237 if (!rects)
1239 *rect_count = 1;
1240 return;
1243 if (!*rect_count)
1244 return;
1246 wined3d_device_get_scissor_rect(device->wined3d_device, rects);
1247 if (*rect_count > 1)
1248 memset(&rects[1], 0, (*rect_count - 1) * sizeof(*rects));
1251 static HRESULT STDMETHODCALLTYPE d3d10_device_GetDeviceRemovedReason(ID3D10Device1 *iface)
1253 TRACE("iface %p.\n", iface);
1255 /* In the current implementation the device is never removed, so we can
1256 * just return S_OK here. */
1258 return S_OK;
1261 static HRESULT STDMETHODCALLTYPE d3d10_device_SetExceptionMode(ID3D10Device1 *iface, UINT flags)
1263 FIXME("iface %p, flags %#x stub!\n", iface, flags);
1265 return E_NOTIMPL;
1268 static UINT STDMETHODCALLTYPE d3d10_device_GetExceptionMode(ID3D10Device1 *iface)
1270 FIXME("iface %p stub!\n", iface);
1272 return 0;
1275 static HRESULT STDMETHODCALLTYPE d3d10_device_GetPrivateData(ID3D10Device1 *iface,
1276 REFGUID guid, UINT *data_size, void *data)
1278 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
1279 iface, debugstr_guid(guid), data_size, data);
1281 return E_NOTIMPL;
1284 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateData(ID3D10Device1 *iface,
1285 REFGUID guid, UINT data_size, const void *data)
1287 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
1288 iface, debugstr_guid(guid), data_size, data);
1290 return E_NOTIMPL;
1293 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateDataInterface(ID3D10Device1 *iface,
1294 REFGUID guid, const IUnknown *data)
1296 FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
1298 return E_NOTIMPL;
1301 static void STDMETHODCALLTYPE d3d10_device_ClearState(ID3D10Device1 *iface)
1303 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
1304 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1305 unsigned int i;
1307 TRACE("iface %p.\n", iface);
1309 wined3d_device_set_vertex_shader(device->wined3d_device, NULL);
1310 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1312 wined3d_device_set_vs_sampler(device->wined3d_device, i, NULL);
1314 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1316 wined3d_device_set_vs_resource_view(device->wined3d_device, i, NULL);
1318 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1320 wined3d_device_set_vs_cb(device->wined3d_device, i, NULL);
1322 wined3d_device_set_geometry_shader(device->wined3d_device, NULL);
1323 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1325 wined3d_device_set_gs_sampler(device->wined3d_device, i, NULL);
1327 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1329 wined3d_device_set_gs_resource_view(device->wined3d_device, i, NULL);
1331 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1333 wined3d_device_set_gs_cb(device->wined3d_device, i, NULL);
1335 wined3d_device_set_pixel_shader(device->wined3d_device, NULL);
1336 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1338 wined3d_device_set_ps_sampler(device->wined3d_device, i, NULL);
1340 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1342 wined3d_device_set_ps_resource_view(device->wined3d_device, i, NULL);
1344 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1346 wined3d_device_set_ps_cb(device->wined3d_device, i, NULL);
1348 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
1350 wined3d_device_set_stream_source(device->wined3d_device, i, NULL, 0, 0);
1352 wined3d_device_set_index_buffer(device->wined3d_device, NULL, WINED3DFMT_UNKNOWN);
1353 wined3d_device_set_vertex_declaration(device->wined3d_device, NULL);
1354 wined3d_device_set_primitive_type(device->wined3d_device, WINED3D_PT_UNDEFINED);
1355 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
1357 wined3d_device_set_rendertarget_view(device->wined3d_device, i, NULL, FALSE);
1359 wined3d_device_set_depth_stencil_view(device->wined3d_device, NULL);
1360 ID3D10Device1_OMSetDepthStencilState(iface, NULL, 0);
1361 ID3D10Device1_OMSetBlendState(iface, NULL, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
1362 ID3D10Device1_RSSetViewports(iface, 0, NULL);
1363 ID3D10Device1_RSSetScissorRects(iface, 0, NULL);
1364 ID3D10Device1_RSSetState(iface, NULL);
1365 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
1367 wined3d_device_set_stream_output(device->wined3d_device, i, NULL, 0);
1369 wined3d_device_set_predication(device->wined3d_device, NULL, FALSE);
1372 static void STDMETHODCALLTYPE d3d10_device_Flush(ID3D10Device1 *iface)
1374 FIXME("iface %p stub!\n", iface);
1377 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBuffer(ID3D10Device1 *iface,
1378 const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Buffer **buffer)
1380 struct d3d10_device *This = impl_from_ID3D10Device(iface);
1381 struct d3d10_buffer *object;
1382 HRESULT hr;
1384 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
1386 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1387 if (!object)
1388 return E_OUTOFMEMORY;
1390 hr = d3d10_buffer_init(object, This, desc, data);
1391 if (FAILED(hr))
1393 WARN("Failed to initialize buffer, hr %#x.\n", hr);
1394 HeapFree(GetProcessHeap(), 0, object);
1395 return hr;
1398 *buffer = &object->ID3D10Buffer_iface;
1400 TRACE("Created ID3D10Buffer %p\n", object);
1402 return S_OK;
1405 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture1D(ID3D10Device1 *iface,
1406 const D3D10_TEXTURE1D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Texture1D **texture)
1408 FIXME("iface %p, desc %p, data %p, texture %p stub!\n", iface, desc, data, texture);
1410 return E_NOTIMPL;
1413 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture2D(ID3D10Device1 *iface,
1414 const D3D10_TEXTURE2D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
1415 ID3D10Texture2D **texture)
1417 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1418 struct d3d10_texture2d *object;
1419 HRESULT hr;
1421 FIXME("iface %p, desc %p, data %p, texture %p partial stub!\n", iface, desc, data, texture);
1423 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1424 if (!object)
1425 return E_OUTOFMEMORY;
1427 if (FAILED(hr = d3d10_texture2d_init(object, device, desc, data)))
1429 WARN("Failed to initialize texture, hr %#x.\n", hr);
1430 HeapFree(GetProcessHeap(), 0, object);
1431 return hr;
1434 *texture = &object->ID3D10Texture2D_iface;
1436 TRACE("Created ID3D10Texture2D %p\n", object);
1438 return S_OK;
1441 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture3D(ID3D10Device1 *iface,
1442 const D3D10_TEXTURE3D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
1443 ID3D10Texture3D **texture)
1445 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1446 struct d3d10_texture3d *object;
1447 HRESULT hr;
1449 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
1451 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1452 if (!object)
1453 return E_OUTOFMEMORY;
1455 if (FAILED(hr = d3d10_texture3d_init(object, device, desc, data)))
1457 WARN("Failed to initialize texture, hr %#x.\n", hr);
1458 HeapFree(GetProcessHeap(), 0, object);
1459 return hr;
1462 TRACE("Created 3D texture %p.\n", object);
1463 *texture = &object->ID3D10Texture3D_iface;
1465 return S_OK;
1468 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView(ID3D10Device1 *iface,
1469 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC *desc, ID3D10ShaderResourceView **view)
1471 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1472 struct d3d10_shader_resource_view *object;
1473 HRESULT hr;
1475 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
1477 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
1478 return E_OUTOFMEMORY;
1480 if (FAILED(hr = d3d10_shader_resource_view_init(object, device, resource, desc)))
1482 WARN("Failed to initialize shader resource view, hr %#x.\n", hr);
1483 HeapFree(GetProcessHeap(), 0, object);
1484 return hr;
1487 TRACE("Created shader resource view %p.\n", object);
1488 *view = &object->ID3D10ShaderResourceView_iface;
1490 return S_OK;
1493 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRenderTargetView(ID3D10Device1 *iface,
1494 ID3D10Resource *resource, const D3D10_RENDER_TARGET_VIEW_DESC *desc, ID3D10RenderTargetView **view)
1496 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1497 struct d3d10_rendertarget_view *object;
1498 HRESULT hr;
1500 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
1502 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
1503 return E_OUTOFMEMORY;
1505 if (FAILED(hr = d3d10_rendertarget_view_init(object, device, resource, desc)))
1507 WARN("Failed to initialize rendertarget view, hr %#x.\n", hr);
1508 HeapFree(GetProcessHeap(), 0, object);
1509 return hr;
1512 TRACE("Created rendertarget view %p.\n", object);
1513 *view = &object->ID3D10RenderTargetView_iface;
1515 return S_OK;
1518 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilView(ID3D10Device1 *iface,
1519 ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3D10DepthStencilView **view)
1521 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1522 struct d3d10_depthstencil_view *object;
1523 HRESULT hr;
1525 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
1527 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
1528 return E_OUTOFMEMORY;
1530 if (FAILED(hr = d3d10_depthstencil_view_init(object, device, resource, desc)))
1532 WARN("Failed to initialize depthstencil view, hr %#x.\n", hr);
1533 HeapFree(GetProcessHeap(), 0, object);
1534 return hr;
1537 TRACE("Created depthstencil view %p.\n", object);
1538 *view = &object->ID3D10DepthStencilView_iface;
1540 return S_OK;
1543 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateInputLayout(ID3D10Device1 *iface,
1544 const D3D10_INPUT_ELEMENT_DESC *element_descs, UINT element_count,
1545 const void *shader_byte_code, SIZE_T shader_byte_code_length,
1546 ID3D10InputLayout **input_layout)
1548 struct d3d10_device *This = impl_from_ID3D10Device(iface);
1549 struct d3d10_input_layout *object;
1550 HRESULT hr;
1552 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p,"
1553 "\tshader_byte_code_length %lu, input_layout %p\n",
1554 iface, element_descs, element_count, shader_byte_code,
1555 shader_byte_code_length, input_layout);
1557 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1558 if (!object)
1559 return E_OUTOFMEMORY;
1561 hr = d3d10_input_layout_init(object, This, element_descs, element_count,
1562 shader_byte_code, shader_byte_code_length);
1563 if (FAILED(hr))
1565 WARN("Failed to initialize input layout, hr %#x.\n", hr);
1566 HeapFree(GetProcessHeap(), 0, object);
1567 return hr;
1570 TRACE("Created input layout %p.\n", object);
1571 *input_layout = &object->ID3D10InputLayout_iface;
1573 return S_OK;
1576 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateVertexShader(ID3D10Device1 *iface,
1577 const void *byte_code, SIZE_T byte_code_length, ID3D10VertexShader **shader)
1579 struct d3d10_device *This = impl_from_ID3D10Device(iface);
1580 struct d3d10_vertex_shader *object;
1581 HRESULT hr;
1583 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p\n",
1584 iface, byte_code, byte_code_length, shader);
1586 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1587 if (!object)
1588 return E_OUTOFMEMORY;
1590 hr = d3d10_vertex_shader_init(object, This, byte_code, byte_code_length);
1591 if (FAILED(hr))
1593 WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
1594 HeapFree(GetProcessHeap(), 0, object);
1595 return hr;
1598 TRACE("Created vertex shader %p.\n", object);
1599 *shader = &object->ID3D10VertexShader_iface;
1601 return S_OK;
1604 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShader(ID3D10Device1 *iface,
1605 const void *byte_code, SIZE_T byte_code_length, ID3D10GeometryShader **shader)
1607 struct d3d10_device *This = impl_from_ID3D10Device(iface);
1608 struct d3d10_geometry_shader *object;
1609 HRESULT hr;
1611 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
1612 iface, byte_code, byte_code_length, shader);
1614 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1615 if (!object)
1616 return E_OUTOFMEMORY;
1618 hr = d3d10_geometry_shader_init(object, This, byte_code, byte_code_length);
1619 if (FAILED(hr))
1621 WARN("Failed to initialize geometry shader, hr %#x.\n", hr);
1622 HeapFree(GetProcessHeap(), 0, object);
1623 return hr;
1626 TRACE("Created geometry shader %p.\n", object);
1627 *shader = &object->ID3D10GeometryShader_iface;
1629 return S_OK;
1632 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShaderWithStreamOutput(ID3D10Device1 *iface,
1633 const void *byte_code, SIZE_T byte_code_length, const D3D10_SO_DECLARATION_ENTRY *output_stream_decls,
1634 UINT output_stream_decl_count, UINT output_stream_stride, ID3D10GeometryShader **shader)
1636 FIXME("iface %p, byte_code %p, byte_code_length %lu, output_stream_decls %p,\n"
1637 "\toutput_stream_decl_count %u, output_stream_stride %u, shader %p stub!\n",
1638 iface, byte_code, byte_code_length, output_stream_decls,
1639 output_stream_decl_count, output_stream_stride, shader);
1641 return E_NOTIMPL;
1644 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePixelShader(ID3D10Device1 *iface,
1645 const void *byte_code, SIZE_T byte_code_length, ID3D10PixelShader **shader)
1647 struct d3d10_device *This = impl_from_ID3D10Device(iface);
1648 struct d3d10_pixel_shader *object;
1649 HRESULT hr;
1651 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p\n",
1652 iface, byte_code, byte_code_length, shader);
1654 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1655 if (!object)
1656 return E_OUTOFMEMORY;
1658 hr = d3d10_pixel_shader_init(object, This, byte_code, byte_code_length);
1659 if (FAILED(hr))
1661 WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
1662 HeapFree(GetProcessHeap(), 0, object);
1663 return hr;
1666 TRACE("Created pixel shader %p.\n", object);
1667 *shader = &object->ID3D10PixelShader_iface;
1669 return S_OK;
1672 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState(ID3D10Device1 *iface,
1673 const D3D10_BLEND_DESC *desc, ID3D10BlendState **blend_state)
1675 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1676 struct d3d10_blend_state *object;
1677 struct wine_rb_entry *entry;
1678 HRESULT hr;
1680 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
1682 if (!desc)
1683 return E_INVALIDARG;
1685 if ((entry = wine_rb_get(&device->blend_states, desc)))
1687 object = WINE_RB_ENTRY_VALUE(entry, struct d3d10_blend_state, entry);
1689 TRACE("Returning existing blend state %p.\n", object);
1690 *blend_state = &object->ID3D10BlendState_iface;
1691 ID3D10BlendState_AddRef(*blend_state);
1693 return S_OK;
1696 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1697 if (!object)
1698 return E_OUTOFMEMORY;
1700 if (FAILED(hr = d3d10_blend_state_init(object, device, desc)))
1702 WARN("Failed to initialize blend state, hr %#x.\n", hr);
1703 HeapFree(GetProcessHeap(), 0, object);
1704 return hr;
1707 TRACE("Created blend state %p.\n", object);
1708 *blend_state = &object->ID3D10BlendState_iface;
1710 return S_OK;
1713 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilState(ID3D10Device1 *iface,
1714 const D3D10_DEPTH_STENCIL_DESC *desc, ID3D10DepthStencilState **depth_stencil_state)
1716 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1717 struct d3d10_depthstencil_state *object;
1718 struct wine_rb_entry *entry;
1719 HRESULT hr;
1721 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
1723 if (!desc)
1724 return E_INVALIDARG;
1726 if ((entry = wine_rb_get(&device->depthstencil_states, desc)))
1728 object = WINE_RB_ENTRY_VALUE(entry, struct d3d10_depthstencil_state, entry);
1730 TRACE("Returning existing depthstencil state %p.\n", object);
1731 *depth_stencil_state = &object->ID3D10DepthStencilState_iface;
1732 ID3D10DepthStencilState_AddRef(*depth_stencil_state);
1734 return S_OK;
1737 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1738 if (!object)
1739 return E_OUTOFMEMORY;
1741 if (FAILED(hr = d3d10_depthstencil_state_init(object, device, desc)))
1743 WARN("Failed to initialize depthstencil state, hr %#x.\n", hr);
1744 HeapFree(GetProcessHeap(), 0, object);
1745 return hr;
1748 TRACE("Created depthstencil state %p.\n", object);
1749 *depth_stencil_state = &object->ID3D10DepthStencilState_iface;
1751 return S_OK;
1754 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRasterizerState(ID3D10Device1 *iface,
1755 const D3D10_RASTERIZER_DESC *desc, ID3D10RasterizerState **rasterizer_state)
1757 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1758 struct d3d10_rasterizer_state *object;
1759 struct wine_rb_entry *entry;
1760 HRESULT hr;
1762 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
1764 if (!desc)
1765 return E_INVALIDARG;
1767 if ((entry = wine_rb_get(&device->rasterizer_states, desc)))
1769 object = WINE_RB_ENTRY_VALUE(entry, struct d3d10_rasterizer_state, entry);
1771 TRACE("Returning existing rasterizer state %p.\n", object);
1772 *rasterizer_state = &object->ID3D10RasterizerState_iface;
1773 ID3D10RasterizerState_AddRef(*rasterizer_state);
1775 return S_OK;
1779 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1780 if (!object)
1781 return E_OUTOFMEMORY;
1783 if (FAILED(hr = d3d10_rasterizer_state_init(object, device, desc)))
1785 WARN("Failed to initialize rasterizer state, hr %#x.\n", hr);
1786 HeapFree(GetProcessHeap(), 0, object);
1787 return hr;
1790 TRACE("Created rasterizer state %p.\n", object);
1791 *rasterizer_state = &object->ID3D10RasterizerState_iface;
1793 return S_OK;
1796 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateSamplerState(ID3D10Device1 *iface,
1797 const D3D10_SAMPLER_DESC *desc, ID3D10SamplerState **sampler_state)
1799 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1800 struct d3d10_sampler_state *object;
1801 struct wine_rb_entry *entry;
1802 HRESULT hr;
1804 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
1806 if (!desc)
1807 return E_INVALIDARG;
1809 if ((entry = wine_rb_get(&device->sampler_states, desc)))
1811 object = WINE_RB_ENTRY_VALUE(entry, struct d3d10_sampler_state, entry);
1813 TRACE("Returning existing sampler state %p.\n", object);
1814 *sampler_state = &object->ID3D10SamplerState_iface;
1815 ID3D10SamplerState_AddRef(*sampler_state);
1817 return S_OK;
1820 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1821 if (!object)
1822 return E_OUTOFMEMORY;
1824 if (FAILED(hr = d3d10_sampler_state_init(object, device, desc)))
1826 WARN("Failed to initialize sampler state, hr %#x.\n", hr);
1827 HeapFree(GetProcessHeap(), 0, object);
1828 return hr;
1831 TRACE("Created sampler state %p.\n", object);
1832 *sampler_state = &object->ID3D10SamplerState_iface;
1834 return S_OK;
1837 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateQuery(ID3D10Device1 *iface,
1838 const D3D10_QUERY_DESC *desc, ID3D10Query **query)
1840 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1841 struct d3d10_query *object;
1842 HRESULT hr;
1844 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
1846 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
1847 return E_OUTOFMEMORY;
1849 if (FAILED(hr = d3d10_query_init(object, device, desc, FALSE)))
1851 WARN("Failed to initialize query, hr %#x.\n", hr);
1852 HeapFree(GetProcessHeap(), 0, object);
1853 return hr;
1856 TRACE("Created query %p.\n", object);
1857 *query = &object->ID3D10Query_iface;
1859 return S_OK;
1862 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePredicate(ID3D10Device1 *iface,
1863 const D3D10_QUERY_DESC *desc, ID3D10Predicate **predicate)
1865 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1866 struct d3d10_query *object;
1867 HRESULT hr;
1869 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
1871 if (!desc)
1872 return E_INVALIDARG;
1874 if (desc->Query != D3D10_QUERY_OCCLUSION_PREDICATE && desc->Query != D3D10_QUERY_SO_OVERFLOW_PREDICATE)
1876 WARN("Query type %#x is not a predicate.\n", desc->Query);
1877 return E_INVALIDARG;
1880 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
1881 return E_OUTOFMEMORY;
1883 if (FAILED(hr = d3d10_query_init(object, device, desc, TRUE)))
1885 WARN("Failed to initialize predicate, hr %#x.\n", hr);
1886 HeapFree(GetProcessHeap(), 0, object);
1887 return hr;
1890 TRACE("Created predicate %p.\n", object);
1891 *predicate = (ID3D10Predicate *)&object->ID3D10Query_iface;
1893 return S_OK;
1896 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateCounter(ID3D10Device1 *iface,
1897 const D3D10_COUNTER_DESC *desc, ID3D10Counter **counter)
1899 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
1901 return E_NOTIMPL;
1904 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckFormatSupport(ID3D10Device1 *iface,
1905 DXGI_FORMAT format, UINT *format_support)
1907 FIXME("iface %p, format %s, format_support %p stub!\n",
1908 iface, debug_dxgi_format(format), format_support);
1910 return E_NOTIMPL;
1913 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckMultisampleQualityLevels(ID3D10Device1 *iface,
1914 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
1916 FIXME("iface %p, format %s, sample_count %u, quality_level_count %p stub!\n",
1917 iface, debug_dxgi_format(format), sample_count, quality_level_count);
1919 return E_NOTIMPL;
1922 static void STDMETHODCALLTYPE d3d10_device_CheckCounterInfo(ID3D10Device1 *iface, D3D10_COUNTER_INFO *counter_info)
1924 FIXME("iface %p, counter_info %p stub!\n", iface, counter_info);
1927 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckCounter(ID3D10Device1 *iface,
1928 const D3D10_COUNTER_DESC *desc, D3D10_COUNTER_TYPE *type, UINT *active_counters, char *name,
1929 UINT *name_length, char *units, UINT *units_length, char *description, UINT *description_length)
1931 FIXME("iface %p, desc %p, type %p, active_counters %p, name %p, name_length %p,\n"
1932 "\tunits %p, units_length %p, description %p, description_length %p stub!\n",
1933 iface, desc, type, active_counters, name, name_length,
1934 units, units_length, description, description_length);
1936 return E_NOTIMPL;
1939 static UINT STDMETHODCALLTYPE d3d10_device_GetCreationFlags(ID3D10Device1 *iface)
1941 FIXME("iface %p stub!\n", iface);
1943 return 0;
1946 static HRESULT STDMETHODCALLTYPE d3d10_device_OpenSharedResource(ID3D10Device1 *iface,
1947 HANDLE resource_handle, REFIID guid, void **resource)
1949 FIXME("iface %p, resource_handle %p, guid %s, resource %p stub!\n",
1950 iface, resource_handle, debugstr_guid(guid), resource);
1952 return E_NOTIMPL;
1955 static void STDMETHODCALLTYPE d3d10_device_SetTextFilterSize(ID3D10Device1 *iface, UINT width, UINT height)
1957 FIXME("iface %p, width %u, height %u stub!\n", iface, width, height);
1960 static void STDMETHODCALLTYPE d3d10_device_GetTextFilterSize(ID3D10Device1 *iface, UINT *width, UINT *height)
1962 FIXME("iface %p, width %p, height %p stub!\n", iface, width, height);
1965 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView1(ID3D10Device1 *iface,
1966 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC1 *desc, ID3D10ShaderResourceView1 **view)
1968 FIXME("iface %p, resource %p, desc %p, view %p stub!\n", iface, resource, desc, view);
1970 return E_NOTIMPL;
1973 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState1(ID3D10Device1 *iface,
1974 const D3D10_BLEND_DESC1 *desc, ID3D10BlendState1 **blend_state)
1976 FIXME("iface %p, desc %p, blend_state %p stub!\n", iface, desc, blend_state);
1978 return E_NOTIMPL;
1981 static D3D10_FEATURE_LEVEL1 STDMETHODCALLTYPE d3d10_device_GetFeatureLevel(ID3D10Device1 *iface)
1983 FIXME("iface %p stub!\n", iface);
1985 return D3D10_FEATURE_LEVEL_10_1;
1988 static const struct ID3D10Device1Vtbl d3d10_device1_vtbl =
1990 /* IUnknown methods */
1991 d3d10_device_QueryInterface,
1992 d3d10_device_AddRef,
1993 d3d10_device_Release,
1994 /* ID3D10Device methods */
1995 d3d10_device_VSSetConstantBuffers,
1996 d3d10_device_PSSetShaderResources,
1997 d3d10_device_PSSetShader,
1998 d3d10_device_PSSetSamplers,
1999 d3d10_device_VSSetShader,
2000 d3d10_device_DrawIndexed,
2001 d3d10_device_Draw,
2002 d3d10_device_PSSetConstantBuffers,
2003 d3d10_device_IASetInputLayout,
2004 d3d10_device_IASetVertexBuffers,
2005 d3d10_device_IASetIndexBuffer,
2006 d3d10_device_DrawIndexedInstanced,
2007 d3d10_device_DrawInstanced,
2008 d3d10_device_GSSetConstantBuffers,
2009 d3d10_device_GSSetShader,
2010 d3d10_device_IASetPrimitiveTopology,
2011 d3d10_device_VSSetShaderResources,
2012 d3d10_device_VSSetSamplers,
2013 d3d10_device_SetPredication,
2014 d3d10_device_GSSetShaderResources,
2015 d3d10_device_GSSetSamplers,
2016 d3d10_device_OMSetRenderTargets,
2017 d3d10_device_OMSetBlendState,
2018 d3d10_device_OMSetDepthStencilState,
2019 d3d10_device_SOSetTargets,
2020 d3d10_device_DrawAuto,
2021 d3d10_device_RSSetState,
2022 d3d10_device_RSSetViewports,
2023 d3d10_device_RSSetScissorRects,
2024 d3d10_device_CopySubresourceRegion,
2025 d3d10_device_CopyResource,
2026 d3d10_device_UpdateSubresource,
2027 d3d10_device_ClearRenderTargetView,
2028 d3d10_device_ClearDepthStencilView,
2029 d3d10_device_GenerateMips,
2030 d3d10_device_ResolveSubresource,
2031 d3d10_device_VSGetConstantBuffers,
2032 d3d10_device_PSGetShaderResources,
2033 d3d10_device_PSGetShader,
2034 d3d10_device_PSGetSamplers,
2035 d3d10_device_VSGetShader,
2036 d3d10_device_PSGetConstantBuffers,
2037 d3d10_device_IAGetInputLayout,
2038 d3d10_device_IAGetVertexBuffers,
2039 d3d10_device_IAGetIndexBuffer,
2040 d3d10_device_GSGetConstantBuffers,
2041 d3d10_device_GSGetShader,
2042 d3d10_device_IAGetPrimitiveTopology,
2043 d3d10_device_VSGetShaderResources,
2044 d3d10_device_VSGetSamplers,
2045 d3d10_device_GetPredication,
2046 d3d10_device_GSGetShaderResources,
2047 d3d10_device_GSGetSamplers,
2048 d3d10_device_OMGetRenderTargets,
2049 d3d10_device_OMGetBlendState,
2050 d3d10_device_OMGetDepthStencilState,
2051 d3d10_device_SOGetTargets,
2052 d3d10_device_RSGetState,
2053 d3d10_device_RSGetViewports,
2054 d3d10_device_RSGetScissorRects,
2055 d3d10_device_GetDeviceRemovedReason,
2056 d3d10_device_SetExceptionMode,
2057 d3d10_device_GetExceptionMode,
2058 d3d10_device_GetPrivateData,
2059 d3d10_device_SetPrivateData,
2060 d3d10_device_SetPrivateDataInterface,
2061 d3d10_device_ClearState,
2062 d3d10_device_Flush,
2063 d3d10_device_CreateBuffer,
2064 d3d10_device_CreateTexture1D,
2065 d3d10_device_CreateTexture2D,
2066 d3d10_device_CreateTexture3D,
2067 d3d10_device_CreateShaderResourceView,
2068 d3d10_device_CreateRenderTargetView,
2069 d3d10_device_CreateDepthStencilView,
2070 d3d10_device_CreateInputLayout,
2071 d3d10_device_CreateVertexShader,
2072 d3d10_device_CreateGeometryShader,
2073 d3d10_device_CreateGeometryShaderWithStreamOutput,
2074 d3d10_device_CreatePixelShader,
2075 d3d10_device_CreateBlendState,
2076 d3d10_device_CreateDepthStencilState,
2077 d3d10_device_CreateRasterizerState,
2078 d3d10_device_CreateSamplerState,
2079 d3d10_device_CreateQuery,
2080 d3d10_device_CreatePredicate,
2081 d3d10_device_CreateCounter,
2082 d3d10_device_CheckFormatSupport,
2083 d3d10_device_CheckMultisampleQualityLevels,
2084 d3d10_device_CheckCounterInfo,
2085 d3d10_device_CheckCounter,
2086 d3d10_device_GetCreationFlags,
2087 d3d10_device_OpenSharedResource,
2088 d3d10_device_SetTextFilterSize,
2089 d3d10_device_GetTextFilterSize,
2090 d3d10_device_CreateShaderResourceView1,
2091 d3d10_device_CreateBlendState1,
2092 d3d10_device_GetFeatureLevel,
2095 static const struct IUnknownVtbl d3d10_device_inner_unknown_vtbl =
2097 /* IUnknown methods */
2098 d3d10_device_inner_QueryInterface,
2099 d3d10_device_inner_AddRef,
2100 d3d10_device_inner_Release,
2103 static inline struct d3d10_device *impl_from_ID3D10Multithread(ID3D10Multithread *iface)
2105 return CONTAINING_RECORD(iface, struct d3d10_device, ID3D10Multithread_iface);
2108 static HRESULT STDMETHODCALLTYPE d3d10_multithread_QueryInterface(ID3D10Multithread *iface, REFIID iid, void **out)
2110 struct d3d10_device *device = impl_from_ID3D10Multithread(iface);
2112 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
2114 return IUnknown_QueryInterface(device->outer_unk, iid, out);
2117 static ULONG STDMETHODCALLTYPE d3d10_multithread_AddRef(ID3D10Multithread *iface)
2119 struct d3d10_device *device = impl_from_ID3D10Multithread(iface);
2121 TRACE("iface %p.\n", iface);
2123 return IUnknown_AddRef(device->outer_unk);
2126 static ULONG STDMETHODCALLTYPE d3d10_multithread_Release(ID3D10Multithread *iface)
2128 struct d3d10_device *device = impl_from_ID3D10Multithread(iface);
2130 TRACE("iface %p.\n", iface);
2132 return IUnknown_Release(device->outer_unk);
2135 static void STDMETHODCALLTYPE d3d10_multithread_Enter(ID3D10Multithread *iface)
2137 TRACE("iface %p.\n", iface);
2139 wined3d_mutex_lock();
2142 static void STDMETHODCALLTYPE d3d10_multithread_Leave(ID3D10Multithread *iface)
2144 TRACE("iface %p.\n", iface);
2146 wined3d_mutex_unlock();
2149 static BOOL STDMETHODCALLTYPE d3d10_multithread_SetMultithreadProtected(ID3D10Multithread *iface, BOOL protect)
2151 FIXME("iface %p, protect %#x stub!\n", iface, protect);
2153 return TRUE;
2156 static BOOL STDMETHODCALLTYPE d3d10_multithread_GetMultithreadProtected(ID3D10Multithread *iface)
2158 FIXME("iface %p stub!\n", iface);
2160 return TRUE;
2163 static const struct ID3D10MultithreadVtbl d3d10_multithread_vtbl =
2165 d3d10_multithread_QueryInterface,
2166 d3d10_multithread_AddRef,
2167 d3d10_multithread_Release,
2168 d3d10_multithread_Enter,
2169 d3d10_multithread_Leave,
2170 d3d10_multithread_SetMultithreadProtected,
2171 d3d10_multithread_GetMultithreadProtected,
2174 /* IWineDXGIDeviceParent IUnknown methods */
2176 static inline struct d3d10_device *device_from_dxgi_device_parent(IWineDXGIDeviceParent *iface)
2178 return CONTAINING_RECORD(iface, struct d3d10_device, IWineDXGIDeviceParent_iface);
2181 static HRESULT STDMETHODCALLTYPE dxgi_device_parent_QueryInterface(IWineDXGIDeviceParent *iface,
2182 REFIID riid, void **ppv)
2184 struct d3d10_device *device = device_from_dxgi_device_parent(iface);
2185 return IUnknown_QueryInterface(device->outer_unk, riid, ppv);
2188 static ULONG STDMETHODCALLTYPE dxgi_device_parent_AddRef(IWineDXGIDeviceParent *iface)
2190 struct d3d10_device *device = device_from_dxgi_device_parent(iface);
2191 return IUnknown_AddRef(device->outer_unk);
2194 static ULONG STDMETHODCALLTYPE dxgi_device_parent_Release(IWineDXGIDeviceParent *iface)
2196 struct d3d10_device *device = device_from_dxgi_device_parent(iface);
2197 return IUnknown_Release(device->outer_unk);
2200 static struct wined3d_device_parent * STDMETHODCALLTYPE dxgi_device_parent_get_wined3d_device_parent(
2201 IWineDXGIDeviceParent *iface)
2203 struct d3d10_device *device = device_from_dxgi_device_parent(iface);
2204 return &device->device_parent;
2207 static const struct IWineDXGIDeviceParentVtbl d3d10_dxgi_device_parent_vtbl =
2209 /* IUnknown methods */
2210 dxgi_device_parent_QueryInterface,
2211 dxgi_device_parent_AddRef,
2212 dxgi_device_parent_Release,
2213 /* IWineDXGIDeviceParent methods */
2214 dxgi_device_parent_get_wined3d_device_parent,
2217 static inline struct d3d10_device *device_from_wined3d_device_parent(struct wined3d_device_parent *device_parent)
2219 return CONTAINING_RECORD(device_parent, struct d3d10_device, device_parent);
2222 static void CDECL device_parent_wined3d_device_created(struct wined3d_device_parent *device_parent,
2223 struct wined3d_device *wined3d_device)
2225 struct d3d10_device *device = device_from_wined3d_device_parent(device_parent);
2227 TRACE("device_parent %p, wined3d_device %p.\n", device_parent, wined3d_device);
2229 wined3d_device_incref(wined3d_device);
2230 device->wined3d_device = wined3d_device;
2233 static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent)
2235 TRACE("device_parent %p.\n", device_parent);
2238 static void CDECL device_parent_activate(struct wined3d_device_parent *device_parent, BOOL activate)
2240 TRACE("device_parent %p, activate %#x.\n", device_parent, activate);
2243 static HRESULT CDECL device_parent_surface_created(struct wined3d_device_parent *device_parent,
2244 void *container_parent, struct wined3d_surface *surface, void **parent,
2245 const struct wined3d_parent_ops **parent_ops)
2247 TRACE("device_parent %p, container_parent %p, surface %p, parent %p, parent_ops %p.\n",
2248 device_parent, container_parent, surface, parent, parent_ops);
2250 *parent = container_parent;
2251 *parent_ops = &d3d10_null_wined3d_parent_ops;
2253 return S_OK;
2256 static HRESULT CDECL device_parent_volume_created(struct wined3d_device_parent *device_parent,
2257 void *container_parent, struct wined3d_volume *volume, void **parent,
2258 const struct wined3d_parent_ops **parent_ops)
2260 TRACE("device_parent %p, container_parent %p, volume %p, parent %p, parent_ops %p.\n",
2261 device_parent, container_parent, volume, parent, parent_ops);
2263 *parent = container_parent;
2264 *parent_ops = &d3d10_null_wined3d_parent_ops;
2266 return S_OK;
2269 static HRESULT CDECL device_parent_create_swapchain_surface(struct wined3d_device_parent *device_parent,
2270 void *container_parent, const struct wined3d_resource_desc *wined3d_desc, struct wined3d_surface **surface)
2272 struct d3d10_device *device = device_from_wined3d_device_parent(device_parent);
2273 struct wined3d_resource *sub_resource;
2274 struct d3d10_texture2d *texture;
2275 D3D10_TEXTURE2D_DESC desc;
2276 HRESULT hr;
2278 FIXME("device_parent %p, container_parent %p, wined3d_desc %p, surface %p partial stub!\n",
2279 device_parent, container_parent, wined3d_desc, surface);
2281 FIXME("Implement DXGI<->wined3d usage conversion\n");
2283 desc.Width = wined3d_desc->width;
2284 desc.Height = wined3d_desc->height;
2285 desc.MipLevels = 1;
2286 desc.ArraySize = 1;
2287 desc.Format = dxgi_format_from_wined3dformat(wined3d_desc->format);
2288 desc.SampleDesc.Count = wined3d_desc->multisample_type ? wined3d_desc->multisample_type : 1;
2289 desc.SampleDesc.Quality = wined3d_desc->multisample_quality;
2290 desc.Usage = D3D10_USAGE_DEFAULT;
2291 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2292 desc.CPUAccessFlags = 0;
2293 desc.MiscFlags = 0;
2295 if (FAILED(hr = d3d10_device_CreateTexture2D(&device->ID3D10Device1_iface,
2296 &desc, NULL, (ID3D10Texture2D **)&texture)))
2298 ERR("CreateTexture2D failed, returning %#x\n", hr);
2299 return hr;
2302 sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, 0);
2303 *surface = wined3d_surface_from_resource(sub_resource);
2304 wined3d_surface_incref(*surface);
2305 ID3D10Texture2D_Release(&texture->ID3D10Texture2D_iface);
2307 return S_OK;
2310 static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent *device_parent,
2311 struct wined3d_swapchain_desc *desc, struct wined3d_swapchain **swapchain)
2313 struct d3d10_device *device = device_from_wined3d_device_parent(device_parent);
2314 IWineDXGIDevice *wine_device;
2315 HRESULT hr;
2317 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent, desc, swapchain);
2319 if (FAILED(hr = d3d10_device_QueryInterface(&device->ID3D10Device1_iface,
2320 &IID_IWineDXGIDevice, (void **)&wine_device)))
2322 ERR("Device should implement IWineDXGIDevice.\n");
2323 return E_FAIL;
2326 hr = IWineDXGIDevice_create_swapchain(wine_device, desc, swapchain);
2327 IWineDXGIDevice_Release(wine_device);
2328 if (FAILED(hr))
2330 ERR("Failed to create DXGI swapchain, returning %#x\n", hr);
2331 return hr;
2334 return S_OK;
2337 static const struct wined3d_device_parent_ops d3d10_wined3d_device_parent_ops =
2339 device_parent_wined3d_device_created,
2340 device_parent_mode_changed,
2341 device_parent_activate,
2342 device_parent_surface_created,
2343 device_parent_volume_created,
2344 device_parent_create_swapchain_surface,
2345 device_parent_create_swapchain,
2348 static void *d3d10_rb_alloc(size_t size)
2350 return HeapAlloc(GetProcessHeap(), 0, size);
2353 static void *d3d10_rb_realloc(void *ptr, size_t size)
2355 return HeapReAlloc(GetProcessHeap(), 0, ptr, size);
2358 static void d3d10_rb_free(void *ptr)
2360 HeapFree(GetProcessHeap(), 0, ptr);
2363 static int d3d10_sampler_state_compare(const void *key, const struct wine_rb_entry *entry)
2365 const D3D10_SAMPLER_DESC *ka = key;
2366 const D3D10_SAMPLER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d10_sampler_state, entry)->desc;
2368 return memcmp(ka, kb, sizeof(*ka));
2371 static const struct wine_rb_functions d3d10_sampler_state_rb_ops =
2373 d3d10_rb_alloc,
2374 d3d10_rb_realloc,
2375 d3d10_rb_free,
2376 d3d10_sampler_state_compare,
2379 static int d3d10_blend_state_compare(const void *key, const struct wine_rb_entry *entry)
2381 const D3D10_BLEND_DESC *ka = key;
2382 const D3D10_BLEND_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d10_blend_state, entry)->desc;
2384 return memcmp(ka, kb, sizeof(*ka));
2387 static const struct wine_rb_functions d3d10_blend_state_rb_ops =
2389 d3d10_rb_alloc,
2390 d3d10_rb_realloc,
2391 d3d10_rb_free,
2392 d3d10_blend_state_compare,
2395 static int d3d10_depthstencil_state_compare(const void *key, const struct wine_rb_entry *entry)
2397 const D3D10_DEPTH_STENCIL_DESC *ka = key;
2398 const D3D10_DEPTH_STENCIL_DESC *kb = &WINE_RB_ENTRY_VALUE(entry,
2399 const struct d3d10_depthstencil_state, entry)->desc;
2401 return memcmp(ka, kb, sizeof(*ka));
2404 static const struct wine_rb_functions d3d10_depthstencil_state_rb_ops =
2406 d3d10_rb_alloc,
2407 d3d10_rb_realloc,
2408 d3d10_rb_free,
2409 d3d10_depthstencil_state_compare,
2412 static int d3d10_rasterizer_state_compare(const void *key, const struct wine_rb_entry *entry)
2414 const D3D10_RASTERIZER_DESC *ka = key;
2415 const D3D10_RASTERIZER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d10_rasterizer_state, entry)->desc;
2417 return memcmp(ka, kb, sizeof(*ka));
2420 static const struct wine_rb_functions d3d10_rasterizer_state_rb_ops =
2422 d3d10_rb_alloc,
2423 d3d10_rb_realloc,
2424 d3d10_rb_free,
2425 d3d10_rasterizer_state_compare,
2428 HRESULT d3d10_device_init(struct d3d10_device *device, void *outer_unknown)
2430 device->IUnknown_inner.lpVtbl = &d3d10_device_inner_unknown_vtbl;
2431 device->ID3D10Device1_iface.lpVtbl = &d3d10_device1_vtbl;
2432 device->ID3D10Multithread_iface.lpVtbl = &d3d10_multithread_vtbl;
2433 device->IWineDXGIDeviceParent_iface.lpVtbl = &d3d10_dxgi_device_parent_vtbl;
2434 device->device_parent.ops = &d3d10_wined3d_device_parent_ops;
2435 device->refcount = 1;
2436 /* COM aggregation always takes place */
2437 device->outer_unk = outer_unknown;
2439 if (wine_rb_init(&device->blend_states, &d3d10_blend_state_rb_ops) == -1)
2441 WARN("Failed to initialize blend state rbtree.\n");
2442 return E_FAIL;
2444 device->blend_factor[0] = 1.0f;
2445 device->blend_factor[1] = 1.0f;
2446 device->blend_factor[2] = 1.0f;
2447 device->blend_factor[3] = 1.0f;
2449 if (wine_rb_init(&device->depthstencil_states, &d3d10_depthstencil_state_rb_ops) == -1)
2451 WARN("Failed to initialize depthstencil state rbtree.\n");
2452 wine_rb_destroy(&device->blend_states, NULL, NULL);
2453 return E_FAIL;
2456 if (wine_rb_init(&device->rasterizer_states, &d3d10_rasterizer_state_rb_ops) == -1)
2458 WARN("Failed to initialize rasterizer state rbtree.\n");
2459 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
2460 wine_rb_destroy(&device->blend_states, NULL, NULL);
2461 return E_FAIL;
2464 if (wine_rb_init(&device->sampler_states, &d3d10_sampler_state_rb_ops) == -1)
2466 WARN("Failed to initialize sampler state rbtree.\n");
2467 wine_rb_destroy(&device->rasterizer_states, NULL, NULL);
2468 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
2469 wine_rb_destroy(&device->blend_states, NULL, NULL);
2470 return E_FAIL;
2473 return S_OK;