d3d10core: Implement d3d10_device_OMGetRenderTargets().
[wine.git] / dlls / d3d10core / device.c
blobbb5265ba0596ecd1d98976cd75adadc04bc5d7ec
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 FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
147 iface, start_slot, view_count, views);
150 static void STDMETHODCALLTYPE d3d10_device_PSSetShader(ID3D10Device1 *iface,
151 ID3D10PixelShader *shader)
153 struct d3d10_device *This = impl_from_ID3D10Device(iface);
154 struct d3d10_pixel_shader *ps = unsafe_impl_from_ID3D10PixelShader(shader);
156 TRACE("iface %p, shader %p\n", iface, shader);
158 wined3d_device_set_pixel_shader(This->wined3d_device, ps ? ps->wined3d_shader : NULL);
161 static void STDMETHODCALLTYPE d3d10_device_PSSetSamplers(ID3D10Device1 *iface,
162 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
164 struct d3d10_device *device = impl_from_ID3D10Device(iface);
165 unsigned int i;
167 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
168 iface, start_slot, sampler_count, samplers);
170 for (i = 0; i < sampler_count; ++i)
172 struct d3d10_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
174 wined3d_device_set_ps_sampler(device->wined3d_device, start_slot + i,
175 sampler ? sampler->wined3d_sampler : NULL);
179 static void STDMETHODCALLTYPE d3d10_device_VSSetShader(ID3D10Device1 *iface,
180 ID3D10VertexShader *shader)
182 struct d3d10_device *This = impl_from_ID3D10Device(iface);
183 struct d3d10_vertex_shader *vs = unsafe_impl_from_ID3D10VertexShader(shader);
185 TRACE("iface %p, shader %p\n", iface, shader);
187 wined3d_device_set_vertex_shader(This->wined3d_device, vs ? vs->wined3d_shader : NULL);
190 static void STDMETHODCALLTYPE d3d10_device_DrawIndexed(ID3D10Device1 *iface, UINT index_count,
191 UINT start_index_location, INT base_vertex_location)
193 struct d3d10_device *This = impl_from_ID3D10Device(iface);
195 TRACE("iface %p, index_count %u, start_index_location %u, base_vertex_location %d.\n",
196 iface, index_count, start_index_location, base_vertex_location);
198 wined3d_device_set_base_vertex_index(This->wined3d_device, base_vertex_location);
199 wined3d_device_draw_indexed_primitive(This->wined3d_device, start_index_location, index_count);
202 static void STDMETHODCALLTYPE d3d10_device_Draw(ID3D10Device1 *iface, UINT vertex_count,
203 UINT start_vertex_location)
205 struct d3d10_device *This = impl_from_ID3D10Device(iface);
207 TRACE("iface %p, vertex_count %u, start_vertex_location %u\n",
208 iface, vertex_count, start_vertex_location);
210 wined3d_device_draw_primitive(This->wined3d_device, start_vertex_location, vertex_count);
213 static void STDMETHODCALLTYPE d3d10_device_PSSetConstantBuffers(ID3D10Device1 *iface,
214 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
216 struct d3d10_device *device = impl_from_ID3D10Device(iface);
217 unsigned int i;
219 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
220 iface, start_slot, buffer_count, buffers);
222 for (i = 0; i < buffer_count; ++i)
224 struct d3d10_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
226 wined3d_device_set_ps_cb(device->wined3d_device, start_slot + i,
227 buffer ? buffer->wined3d_buffer : NULL);
231 static void STDMETHODCALLTYPE d3d10_device_IASetInputLayout(ID3D10Device1 *iface,
232 ID3D10InputLayout *input_layout)
234 struct d3d10_device *This = impl_from_ID3D10Device(iface);
235 struct d3d10_input_layout *layout = unsafe_impl_from_ID3D10InputLayout(input_layout);
237 TRACE("iface %p, input_layout %p\n", iface, input_layout);
239 wined3d_device_set_vertex_declaration(This->wined3d_device,
240 layout ? layout->wined3d_decl : NULL);
243 static void STDMETHODCALLTYPE d3d10_device_IASetVertexBuffers(ID3D10Device1 *iface, UINT start_slot,
244 UINT buffer_count, ID3D10Buffer *const *buffers, const UINT *strides, const UINT *offsets)
246 struct d3d10_device *This = impl_from_ID3D10Device(iface);
247 unsigned int i;
249 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p\n",
250 iface, start_slot, buffer_count, buffers, strides, offsets);
252 for (i = 0; i < buffer_count; ++i)
254 struct d3d10_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
256 wined3d_device_set_stream_source(This->wined3d_device, start_slot + i,
257 buffer ? buffer->wined3d_buffer : NULL, offsets[i], strides[i]);
261 static void STDMETHODCALLTYPE d3d10_device_IASetIndexBuffer(ID3D10Device1 *iface,
262 ID3D10Buffer *buffer, DXGI_FORMAT format, UINT offset)
264 struct d3d10_device *This = impl_from_ID3D10Device(iface);
265 struct d3d10_buffer *buffer_impl = unsafe_impl_from_ID3D10Buffer(buffer);
267 TRACE("iface %p, buffer %p, format %s, offset %u.\n",
268 iface, buffer, debug_dxgi_format(format), offset);
270 wined3d_device_set_index_buffer(This->wined3d_device,
271 buffer_impl ? buffer_impl->wined3d_buffer : NULL,
272 wined3dformat_from_dxgi_format(format));
273 if (offset) FIXME("offset %u not supported.\n", offset);
276 static void STDMETHODCALLTYPE d3d10_device_DrawIndexedInstanced(ID3D10Device1 *iface,
277 UINT instance_index_count, UINT instance_count, UINT start_index_location,
278 INT base_vertex_location, UINT start_instance_location)
280 struct d3d10_device *device = impl_from_ID3D10Device(iface);
282 TRACE("iface %p, instance_index_count %u, instance_count %u, start_index_location %u,\n"
283 "\tbase_vertex_location %d, start_instance_location %u.\n",
284 iface, instance_index_count, instance_count, start_index_location,
285 base_vertex_location, start_instance_location);
287 wined3d_device_set_base_vertex_index(device->wined3d_device, base_vertex_location);
288 wined3d_device_draw_indexed_primitive_instanced(device->wined3d_device, start_index_location,
289 instance_index_count, start_instance_location, instance_count);
292 static void STDMETHODCALLTYPE d3d10_device_DrawInstanced(ID3D10Device1 *iface,
293 UINT instance_vertex_count, UINT instance_count,
294 UINT start_vertex_location, UINT start_instance_location)
296 FIXME("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u,\n"
297 "\tstart_instance_location %u stub!\n", iface, instance_vertex_count, instance_count,
298 start_vertex_location, start_instance_location);
301 static void STDMETHODCALLTYPE d3d10_device_GSSetConstantBuffers(ID3D10Device1 *iface,
302 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
304 struct d3d10_device *device = impl_from_ID3D10Device(iface);
305 unsigned int i;
307 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
308 iface, start_slot, buffer_count, buffers);
310 for (i = 0; i < buffer_count; ++i)
312 struct d3d10_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
314 wined3d_device_set_gs_cb(device->wined3d_device, start_slot + i,
315 buffer ? buffer->wined3d_buffer : NULL);
319 static void STDMETHODCALLTYPE d3d10_device_GSSetShader(ID3D10Device1 *iface, ID3D10GeometryShader *shader)
321 struct d3d10_device *device = impl_from_ID3D10Device(iface);
322 struct d3d10_geometry_shader *gs = unsafe_impl_from_ID3D10GeometryShader(shader);
324 TRACE("iface %p, shader %p.\n", iface, shader);
326 wined3d_device_set_geometry_shader(device->wined3d_device, gs ? gs->wined3d_shader : NULL);
329 static void STDMETHODCALLTYPE d3d10_device_IASetPrimitiveTopology(ID3D10Device1 *iface,
330 D3D10_PRIMITIVE_TOPOLOGY topology)
332 struct d3d10_device *This = impl_from_ID3D10Device(iface);
334 TRACE("iface %p, topology %s\n", iface, debug_d3d10_primitive_topology(topology));
336 wined3d_device_set_primitive_type(This->wined3d_device, (enum wined3d_primitive_type)topology);
339 static void STDMETHODCALLTYPE d3d10_device_VSSetShaderResources(ID3D10Device1 *iface,
340 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
342 FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
343 iface, start_slot, view_count, views);
346 static void STDMETHODCALLTYPE d3d10_device_VSSetSamplers(ID3D10Device1 *iface,
347 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
349 struct d3d10_device *device = impl_from_ID3D10Device(iface);
350 unsigned int i;
352 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
353 iface, start_slot, sampler_count, samplers);
355 for (i = 0; i < sampler_count; ++i)
357 struct d3d10_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
359 wined3d_device_set_vs_sampler(device->wined3d_device, start_slot + i,
360 sampler ? sampler->wined3d_sampler : NULL);
364 static void STDMETHODCALLTYPE d3d10_device_SetPredication(ID3D10Device1 *iface, ID3D10Predicate *predicate, BOOL value)
366 FIXME("iface %p, predicate %p, value %d stub!\n", iface, predicate, value);
369 static void STDMETHODCALLTYPE d3d10_device_GSSetShaderResources(ID3D10Device1 *iface,
370 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
372 FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
373 iface, start_slot, view_count, views);
376 static void STDMETHODCALLTYPE d3d10_device_GSSetSamplers(ID3D10Device1 *iface,
377 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
379 struct d3d10_device *device = impl_from_ID3D10Device(iface);
380 unsigned int i;
382 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
383 iface, start_slot, sampler_count, samplers);
385 for (i = 0; i < sampler_count; ++i)
387 struct d3d10_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
389 wined3d_device_set_gs_sampler(device->wined3d_device, start_slot + i,
390 sampler ? sampler->wined3d_sampler : NULL);
394 static void STDMETHODCALLTYPE d3d10_device_OMSetRenderTargets(ID3D10Device1 *iface,
395 UINT render_target_view_count, ID3D10RenderTargetView *const *render_target_views,
396 ID3D10DepthStencilView *depth_stencil_view)
398 struct d3d10_device *device = impl_from_ID3D10Device(iface);
399 struct d3d10_depthstencil_view *dsv;
400 unsigned int i;
402 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
403 iface, render_target_view_count, render_target_views, depth_stencil_view);
405 for (i = 0; i < render_target_view_count; ++i)
407 struct d3d10_rendertarget_view *rtv = unsafe_impl_from_ID3D10RenderTargetView(render_target_views[i]);
409 wined3d_device_set_rendertarget_view(device->wined3d_device, i,
410 rtv ? rtv->wined3d_view : NULL, FALSE);
412 for (; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
414 wined3d_device_set_rendertarget_view(device->wined3d_device, i, NULL, FALSE);
417 dsv = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
418 wined3d_device_set_depth_stencil_view(device->wined3d_device,
419 dsv ? dsv->wined3d_view : NULL);
422 static void STDMETHODCALLTYPE d3d10_device_OMSetBlendState(ID3D10Device1 *iface,
423 ID3D10BlendState *blend_state, const FLOAT blend_factor[4], UINT sample_mask)
425 struct d3d10_device *device = impl_from_ID3D10Device(iface);
427 TRACE("iface %p, blend_state %p, blend_factor [%f %f %f %f], sample_mask 0x%08x.\n",
428 iface, blend_state, blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3], sample_mask);
430 device->blend_state = unsafe_impl_from_ID3D10BlendState(blend_state);
431 memcpy(device->blend_factor, blend_factor, 4 * sizeof(*blend_factor));
432 device->sample_mask = sample_mask;
435 static void STDMETHODCALLTYPE d3d10_device_OMSetDepthStencilState(ID3D10Device1 *iface,
436 ID3D10DepthStencilState *depth_stencil_state, UINT stencil_ref)
438 struct d3d10_device *device = impl_from_ID3D10Device(iface);
440 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
441 iface, depth_stencil_state, stencil_ref);
443 device->depth_stencil_state = unsafe_impl_from_ID3D10DepthStencilState(depth_stencil_state);
444 device->stencil_ref = stencil_ref;
447 static void STDMETHODCALLTYPE d3d10_device_SOSetTargets(ID3D10Device1 *iface,
448 UINT target_count, ID3D10Buffer *const *targets, const UINT *offsets)
450 struct d3d10_device *device = impl_from_ID3D10Device(iface);
451 unsigned int count, i;
453 TRACE("iface %p, target_count %u, targets %p, offsets %p.\n", iface, target_count, targets, offsets);
455 count = min(target_count, 4);
456 for (i = 0; i < count; ++i)
458 struct d3d10_buffer *buffer = unsafe_impl_from_ID3D10Buffer(targets[i]);
460 wined3d_device_set_stream_output(device->wined3d_device, i,
461 buffer ? buffer->wined3d_buffer : NULL, offsets[i]);
464 for (i = count; i < 4; ++i)
466 wined3d_device_set_stream_output(device->wined3d_device, i, NULL, 0);
470 static void STDMETHODCALLTYPE d3d10_device_DrawAuto(ID3D10Device1 *iface)
472 FIXME("iface %p stub!\n", iface);
475 static void STDMETHODCALLTYPE d3d10_device_RSSetState(ID3D10Device1 *iface, ID3D10RasterizerState *rasterizer_state)
477 struct d3d10_device *device = impl_from_ID3D10Device(iface);
479 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
481 device->rasterizer_state = unsafe_impl_from_ID3D10RasterizerState(rasterizer_state);
484 static void STDMETHODCALLTYPE d3d10_device_RSSetViewports(ID3D10Device1 *iface,
485 UINT viewport_count, const D3D10_VIEWPORT *viewports)
487 struct d3d10_device *device = impl_from_ID3D10Device(iface);
488 struct wined3d_viewport wined3d_vp;
490 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
492 if (viewport_count > 1)
493 FIXME("Multiple viewports not implemented.\n");
495 if (!viewport_count)
496 return;
498 wined3d_vp.x = viewports[0].TopLeftX;
499 wined3d_vp.y = viewports[0].TopLeftY;
500 wined3d_vp.width = viewports[0].Width;
501 wined3d_vp.height = viewports[0].Height;
502 wined3d_vp.min_z = viewports[0].MinDepth;
503 wined3d_vp.max_z = viewports[0].MaxDepth;
505 wined3d_device_set_viewport(device->wined3d_device, &wined3d_vp);
508 static void STDMETHODCALLTYPE d3d10_device_RSSetScissorRects(ID3D10Device1 *iface,
509 UINT rect_count, const D3D10_RECT *rects)
511 struct d3d10_device *device = impl_from_ID3D10Device(iface);
513 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
515 if (rect_count > 1)
516 FIXME("Multiple scissor rects not implemented.\n");
518 if (!rect_count)
519 return;
521 wined3d_device_set_scissor_rect(device->wined3d_device, rects);
524 static void STDMETHODCALLTYPE d3d10_device_CopySubresourceRegion(ID3D10Device1 *iface,
525 ID3D10Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
526 ID3D10Resource *src_resource, UINT src_subresource_idx, const D3D10_BOX *src_box)
528 FIXME("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u,\n"
529 "\tsrc_resource %p, src_subresource_idx %u, src_box %p stub!\n",
530 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
531 src_resource, src_subresource_idx, src_box);
534 static void STDMETHODCALLTYPE d3d10_device_CopyResource(ID3D10Device1 *iface,
535 ID3D10Resource *dst_resource, ID3D10Resource *src_resource)
537 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
538 struct d3d10_device *device = impl_from_ID3D10Device(iface);
540 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
542 wined3d_dst_resource = wined3d_resource_from_resource(dst_resource);
543 wined3d_src_resource = wined3d_resource_from_resource(src_resource);
544 wined3d_device_copy_resource(device->wined3d_device, wined3d_dst_resource, wined3d_src_resource);
547 static void STDMETHODCALLTYPE d3d10_device_UpdateSubresource(ID3D10Device1 *iface,
548 ID3D10Resource *resource, UINT subresource_idx, const D3D10_BOX *box,
549 const void *data, UINT row_pitch, UINT depth_pitch)
551 FIXME("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u stub!\n",
552 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
555 static void STDMETHODCALLTYPE d3d10_device_ClearRenderTargetView(ID3D10Device1 *iface,
556 ID3D10RenderTargetView *render_target_view, const FLOAT color_rgba[4])
558 struct d3d10_device *device = impl_from_ID3D10Device(iface);
559 struct d3d10_rendertarget_view *view = unsafe_impl_from_ID3D10RenderTargetView(render_target_view);
560 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
561 HRESULT hr;
563 TRACE("iface %p, render_target_view %p, color_rgba {%.8e, %.8e, %.8e, %.8e}.\n",
564 iface, render_target_view, color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]);
566 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL, &color)))
567 ERR("Failed to clear view, hr %#x.\n", hr);
570 static void STDMETHODCALLTYPE d3d10_device_ClearDepthStencilView(ID3D10Device1 *iface,
571 ID3D10DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
573 FIXME("iface %p, depth_stencil_view %p, flags %#x, depth %f, stencil %u stub!\n",
574 iface, depth_stencil_view, flags, depth, stencil);
577 static void STDMETHODCALLTYPE d3d10_device_GenerateMips(ID3D10Device1 *iface,
578 ID3D10ShaderResourceView *shader_resource_view)
580 FIXME("iface %p, shader_resource_view %p stub!\n", iface, shader_resource_view);
583 static void STDMETHODCALLTYPE d3d10_device_ResolveSubresource(ID3D10Device1 *iface,
584 ID3D10Resource *dst_resource, UINT dst_subresource_idx,
585 ID3D10Resource *src_resource, UINT src_subresource_idx, DXGI_FORMAT format)
587 FIXME("iface %p, dst_resource %p, dst_subresource_idx %u,\n"
588 "\tsrc_resource %p, src_subresource_idx %u, format %s stub!\n",
589 iface, dst_resource, dst_subresource_idx,
590 src_resource, src_subresource_idx, debug_dxgi_format(format));
593 static void STDMETHODCALLTYPE d3d10_device_VSGetConstantBuffers(ID3D10Device1 *iface,
594 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
596 struct d3d10_device *device = impl_from_ID3D10Device(iface);
597 unsigned int i;
599 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
600 iface, start_slot, buffer_count, buffers);
602 for (i = 0; i < buffer_count; ++i)
604 struct wined3d_buffer *wined3d_buffer;
605 struct d3d10_buffer *buffer_impl;
607 if (!(wined3d_buffer = wined3d_device_get_vs_cb(device->wined3d_device, start_slot + i)))
609 buffers[i] = NULL;
610 continue;
613 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
614 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
615 ID3D10Buffer_AddRef(buffers[i]);
619 static void STDMETHODCALLTYPE d3d10_device_PSGetShaderResources(ID3D10Device1 *iface,
620 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
622 FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
623 iface, start_slot, view_count, views);
626 static void STDMETHODCALLTYPE d3d10_device_PSGetShader(ID3D10Device1 *iface, ID3D10PixelShader **shader)
628 struct d3d10_device *device = impl_from_ID3D10Device(iface);
629 struct d3d10_pixel_shader *shader_impl;
630 struct wined3d_shader *wined3d_shader;
632 TRACE("iface %p, shader %p.\n", iface, shader);
634 if (!(wined3d_shader = wined3d_device_get_pixel_shader(device->wined3d_device)))
636 *shader = NULL;
637 return;
640 shader_impl = wined3d_shader_get_parent(wined3d_shader);
641 *shader = &shader_impl->ID3D10PixelShader_iface;
642 ID3D10PixelShader_AddRef(*shader);
645 static void STDMETHODCALLTYPE d3d10_device_PSGetSamplers(ID3D10Device1 *iface,
646 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
648 struct d3d10_device *device = impl_from_ID3D10Device(iface);
649 unsigned int i;
651 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
652 iface, start_slot, sampler_count, samplers);
654 for (i = 0; i < sampler_count; ++i)
656 struct d3d10_sampler_state *sampler_impl;
657 struct wined3d_sampler *wined3d_sampler;
659 if (!(wined3d_sampler = wined3d_device_get_ps_sampler(device->wined3d_device, start_slot + i)))
661 samplers[i] = NULL;
662 continue;
665 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
666 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
667 ID3D10SamplerState_AddRef(samplers[i]);
671 static void STDMETHODCALLTYPE d3d10_device_VSGetShader(ID3D10Device1 *iface, ID3D10VertexShader **shader)
673 struct d3d10_device *device = impl_from_ID3D10Device(iface);
674 struct d3d10_vertex_shader *shader_impl;
675 struct wined3d_shader *wined3d_shader;
677 TRACE("iface %p, shader %p.\n", iface, shader);
679 if (!(wined3d_shader = wined3d_device_get_vertex_shader(device->wined3d_device)))
681 *shader = NULL;
682 return;
685 shader_impl = wined3d_shader_get_parent(wined3d_shader);
686 *shader = &shader_impl->ID3D10VertexShader_iface;
687 ID3D10VertexShader_AddRef(*shader);
690 static void STDMETHODCALLTYPE d3d10_device_PSGetConstantBuffers(ID3D10Device1 *iface,
691 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
693 struct d3d10_device *device = impl_from_ID3D10Device(iface);
694 unsigned int i;
696 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
697 iface, start_slot, buffer_count, buffers);
699 for (i = 0; i < buffer_count; ++i)
701 struct wined3d_buffer *wined3d_buffer;
702 struct d3d10_buffer *buffer_impl;
704 if (!(wined3d_buffer = wined3d_device_get_ps_cb(device->wined3d_device, start_slot + i)))
706 buffers[i] = NULL;
707 continue;
710 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
711 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
712 ID3D10Buffer_AddRef(buffers[i]);
716 static void STDMETHODCALLTYPE d3d10_device_IAGetInputLayout(ID3D10Device1 *iface, ID3D10InputLayout **input_layout)
718 struct d3d10_device *device = impl_from_ID3D10Device(iface);
719 struct wined3d_vertex_declaration *wined3d_declaration;
720 struct d3d10_input_layout *input_layout_impl;
722 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
724 if (!(wined3d_declaration = wined3d_device_get_vertex_declaration(device->wined3d_device)))
726 *input_layout = NULL;
727 return;
730 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
731 *input_layout = &input_layout_impl->ID3D10InputLayout_iface;
732 ID3D10InputLayout_AddRef(*input_layout);
735 static void STDMETHODCALLTYPE d3d10_device_IAGetVertexBuffers(ID3D10Device1 *iface,
736 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers, UINT *strides, UINT *offsets)
738 struct d3d10_device *device = impl_from_ID3D10Device(iface);
739 unsigned int i;
741 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
742 iface, start_slot, buffer_count, buffers, strides, offsets);
744 for (i = 0; i < buffer_count; ++i)
746 struct wined3d_buffer *wined3d_buffer;
747 struct d3d10_buffer *buffer_impl;
749 if (FAILED(wined3d_device_get_stream_source(device->wined3d_device, start_slot + i,
750 &wined3d_buffer, &offsets[i], &strides[i])))
751 ERR("Failed to get vertex buffer.\n");
753 if (!wined3d_buffer)
755 buffers[i] = NULL;
756 continue;
759 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
760 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
761 ID3D10Buffer_AddRef(buffers[i]);
765 static void STDMETHODCALLTYPE d3d10_device_IAGetIndexBuffer(ID3D10Device1 *iface,
766 ID3D10Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
768 struct d3d10_device *device = impl_from_ID3D10Device(iface);
769 enum wined3d_format_id wined3d_format;
770 struct wined3d_buffer *wined3d_buffer;
771 struct d3d10_buffer *buffer_impl;
773 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
775 wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format);
776 *format = dxgi_format_from_wined3dformat(wined3d_format);
777 *offset = 0; /* FIXME */
778 if (!wined3d_buffer)
780 *buffer = NULL;
781 return;
784 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
785 *buffer = &buffer_impl->ID3D10Buffer_iface;
786 ID3D10Buffer_AddRef(*buffer);
789 static void STDMETHODCALLTYPE d3d10_device_GSGetConstantBuffers(ID3D10Device1 *iface,
790 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
792 struct d3d10_device *device = impl_from_ID3D10Device(iface);
793 unsigned int i;
795 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
796 iface, start_slot, buffer_count, buffers);
798 for (i = 0; i < buffer_count; ++i)
800 struct wined3d_buffer *wined3d_buffer;
801 struct d3d10_buffer *buffer_impl;
803 if (!(wined3d_buffer = wined3d_device_get_gs_cb(device->wined3d_device, start_slot + i)))
805 buffers[i] = NULL;
806 continue;
809 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
810 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
811 ID3D10Buffer_AddRef(buffers[i]);
815 static void STDMETHODCALLTYPE d3d10_device_GSGetShader(ID3D10Device1 *iface, ID3D10GeometryShader **shader)
817 struct d3d10_device *device = impl_from_ID3D10Device(iface);
818 struct d3d10_geometry_shader *shader_impl;
819 struct wined3d_shader *wined3d_shader;
821 TRACE("iface %p, shader %p.\n", iface, shader);
823 if (!(wined3d_shader = wined3d_device_get_geometry_shader(device->wined3d_device)))
825 *shader = NULL;
826 return;
829 shader_impl = wined3d_shader_get_parent(wined3d_shader);
830 *shader = &shader_impl->ID3D10GeometryShader_iface;
831 ID3D10GeometryShader_AddRef(*shader);
834 static void STDMETHODCALLTYPE d3d10_device_IAGetPrimitiveTopology(ID3D10Device1 *iface,
835 D3D10_PRIMITIVE_TOPOLOGY *topology)
837 struct d3d10_device *This = impl_from_ID3D10Device(iface);
839 TRACE("iface %p, topology %p\n", iface, topology);
841 wined3d_device_get_primitive_type(This->wined3d_device, (enum wined3d_primitive_type *)topology);
844 static void STDMETHODCALLTYPE d3d10_device_VSGetShaderResources(ID3D10Device1 *iface,
845 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
847 FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
848 iface, start_slot, view_count, views);
851 static void STDMETHODCALLTYPE d3d10_device_VSGetSamplers(ID3D10Device1 *iface,
852 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
854 struct d3d10_device *device = impl_from_ID3D10Device(iface);
855 unsigned int i;
857 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
858 iface, start_slot, sampler_count, samplers);
860 for (i = 0; i < sampler_count; ++i)
862 struct d3d10_sampler_state *sampler_impl;
863 struct wined3d_sampler *wined3d_sampler;
865 if (!(wined3d_sampler = wined3d_device_get_vs_sampler(device->wined3d_device, start_slot + i)))
867 samplers[i] = NULL;
868 continue;
871 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
872 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
873 ID3D10SamplerState_AddRef(samplers[i]);
877 static void STDMETHODCALLTYPE d3d10_device_GetPredication(ID3D10Device1 *iface,
878 ID3D10Predicate **predicate, BOOL *value)
880 FIXME("iface %p, predicate %p, value %p stub!\n", iface, predicate, value);
883 static void STDMETHODCALLTYPE d3d10_device_GSGetShaderResources(ID3D10Device1 *iface,
884 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
886 FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
887 iface, start_slot, view_count, views);
890 static void STDMETHODCALLTYPE d3d10_device_GSGetSamplers(ID3D10Device1 *iface,
891 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
893 struct d3d10_device *device = impl_from_ID3D10Device(iface);
894 unsigned int i;
896 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
897 iface, start_slot, sampler_count, samplers);
899 for (i = 0; i < sampler_count; ++i)
901 struct d3d10_sampler_state *sampler_impl;
902 struct wined3d_sampler *wined3d_sampler;
904 if (!(wined3d_sampler = wined3d_device_get_gs_sampler(device->wined3d_device, start_slot + i)))
906 samplers[i] = NULL;
907 continue;
910 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
911 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
912 ID3D10SamplerState_AddRef(samplers[i]);
916 static void STDMETHODCALLTYPE d3d10_device_OMGetRenderTargets(ID3D10Device1 *iface,
917 UINT view_count, ID3D10RenderTargetView **render_target_views, ID3D10DepthStencilView **depth_stencil_view)
919 struct d3d10_device *device = impl_from_ID3D10Device(iface);
920 struct wined3d_rendertarget_view *wined3d_view;
922 TRACE("iface %p, view_count %u, render_target_views %p, depth_stencil_view %p.\n",
923 iface, view_count, render_target_views, depth_stencil_view);
925 if (render_target_views)
927 struct d3d10_rendertarget_view *view_impl;
928 unsigned int i;
930 for (i = 0; i < view_count; ++i)
932 if (!(wined3d_view = wined3d_device_get_rendertarget_view(device->wined3d_device, i)))
934 render_target_views[i] = NULL;
935 continue;
938 view_impl = wined3d_rendertarget_view_get_parent(wined3d_view);
939 render_target_views[i] = &view_impl->ID3D10RenderTargetView_iface;
940 ID3D10RenderTargetView_AddRef(render_target_views[i]);
944 if (depth_stencil_view)
946 struct d3d10_depthstencil_view *view_impl;
948 if (!(wined3d_view = wined3d_device_get_depth_stencil_view(device->wined3d_device)))
950 *depth_stencil_view = NULL;
952 else
954 view_impl = wined3d_rendertarget_view_get_parent(wined3d_view);
955 *depth_stencil_view = &view_impl->ID3D10DepthStencilView_iface;
956 ID3D10DepthStencilView_AddRef(*depth_stencil_view);
961 static void STDMETHODCALLTYPE d3d10_device_OMGetBlendState(ID3D10Device1 *iface,
962 ID3D10BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
964 struct d3d10_device *device = impl_from_ID3D10Device(iface);
966 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
967 iface, blend_state, blend_factor, sample_mask);
969 if ((*blend_state = device->blend_state ? &device->blend_state->ID3D10BlendState_iface : NULL))
970 ID3D10BlendState_AddRef(*blend_state);
971 memcpy(blend_factor, device->blend_factor, 4 * sizeof(*blend_factor));
972 *sample_mask = device->sample_mask;
975 static void STDMETHODCALLTYPE d3d10_device_OMGetDepthStencilState(ID3D10Device1 *iface,
976 ID3D10DepthStencilState **depth_stencil_state, UINT *stencil_ref)
978 struct d3d10_device *device = impl_from_ID3D10Device(iface);
980 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
981 iface, depth_stencil_state, stencil_ref);
983 if ((*depth_stencil_state = device->depth_stencil_state
984 ? &device->depth_stencil_state->ID3D10DepthStencilState_iface : NULL))
985 ID3D10DepthStencilState_AddRef(*depth_stencil_state);
986 *stencil_ref = device->stencil_ref;
989 static void STDMETHODCALLTYPE d3d10_device_SOGetTargets(ID3D10Device1 *iface,
990 UINT buffer_count, ID3D10Buffer **buffers, UINT *offsets)
992 struct d3d10_device *device = impl_from_ID3D10Device(iface);
993 unsigned int i;
995 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n",
996 iface, buffer_count, buffers, offsets);
998 for (i = 0; i < buffer_count; ++i)
1000 struct wined3d_buffer *wined3d_buffer;
1001 struct d3d10_buffer *buffer_impl;
1003 if (!(wined3d_buffer = wined3d_device_get_stream_output(device->wined3d_device, i, &offsets[i])))
1005 buffers[i] = NULL;
1006 continue;
1009 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1010 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
1011 ID3D10Buffer_AddRef(buffers[i]);
1015 static void STDMETHODCALLTYPE d3d10_device_RSGetState(ID3D10Device1 *iface, ID3D10RasterizerState **rasterizer_state)
1017 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1019 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
1021 if ((*rasterizer_state = device->rasterizer_state ? &device->rasterizer_state->ID3D10RasterizerState_iface : NULL))
1022 ID3D10RasterizerState_AddRef(*rasterizer_state);
1025 static void STDMETHODCALLTYPE d3d10_device_RSGetViewports(ID3D10Device1 *iface,
1026 UINT *viewport_count, D3D10_VIEWPORT *viewports)
1028 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1029 struct wined3d_viewport wined3d_vp;
1031 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
1033 if (!viewports)
1035 *viewport_count = 1;
1036 return;
1039 if (!*viewport_count)
1040 return;
1042 wined3d_device_get_viewport(device->wined3d_device, &wined3d_vp);
1044 viewports[0].TopLeftX = wined3d_vp.x;
1045 viewports[0].TopLeftY = wined3d_vp.y;
1046 viewports[0].Width = wined3d_vp.width;
1047 viewports[0].Height = wined3d_vp.height;
1048 viewports[0].MinDepth = wined3d_vp.min_z;
1049 viewports[0].MaxDepth = wined3d_vp.max_z;
1051 if (*viewport_count > 1)
1052 memset(&viewports[1], 0, (*viewport_count - 1) * sizeof(*viewports));
1055 static void STDMETHODCALLTYPE d3d10_device_RSGetScissorRects(ID3D10Device1 *iface, UINT *rect_count, D3D10_RECT *rects)
1057 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1059 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
1061 if (!rects)
1063 *rect_count = 1;
1064 return;
1067 if (!*rect_count)
1068 return;
1070 wined3d_device_get_scissor_rect(device->wined3d_device, rects);
1071 if (*rect_count > 1)
1072 memset(&rects[1], 0, (*rect_count - 1) * sizeof(*rects));
1075 static HRESULT STDMETHODCALLTYPE d3d10_device_GetDeviceRemovedReason(ID3D10Device1 *iface)
1077 TRACE("iface %p.\n", iface);
1079 /* In the current implementation the device is never removed, so we can
1080 * just return S_OK here. */
1082 return S_OK;
1085 static HRESULT STDMETHODCALLTYPE d3d10_device_SetExceptionMode(ID3D10Device1 *iface, UINT flags)
1087 FIXME("iface %p, flags %#x stub!\n", iface, flags);
1089 return E_NOTIMPL;
1092 static UINT STDMETHODCALLTYPE d3d10_device_GetExceptionMode(ID3D10Device1 *iface)
1094 FIXME("iface %p stub!\n", iface);
1096 return 0;
1099 static HRESULT STDMETHODCALLTYPE d3d10_device_GetPrivateData(ID3D10Device1 *iface,
1100 REFGUID guid, UINT *data_size, void *data)
1102 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
1103 iface, debugstr_guid(guid), data_size, data);
1105 return E_NOTIMPL;
1108 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateData(ID3D10Device1 *iface,
1109 REFGUID guid, UINT data_size, const void *data)
1111 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
1112 iface, debugstr_guid(guid), data_size, data);
1114 return E_NOTIMPL;
1117 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateDataInterface(ID3D10Device1 *iface,
1118 REFGUID guid, const IUnknown *data)
1120 FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
1122 return E_NOTIMPL;
1125 static void STDMETHODCALLTYPE d3d10_device_ClearState(ID3D10Device1 *iface)
1127 FIXME("iface %p stub!\n", iface);
1130 static void STDMETHODCALLTYPE d3d10_device_Flush(ID3D10Device1 *iface)
1132 FIXME("iface %p stub!\n", iface);
1135 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBuffer(ID3D10Device1 *iface,
1136 const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Buffer **buffer)
1138 struct d3d10_device *This = impl_from_ID3D10Device(iface);
1139 struct d3d10_buffer *object;
1140 HRESULT hr;
1142 FIXME("iface %p, desc %p, data %p, buffer %p partial stub!\n", iface, desc, data, buffer);
1144 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1145 if (!object)
1146 return E_OUTOFMEMORY;
1148 hr = d3d10_buffer_init(object, This, desc, data);
1149 if (FAILED(hr))
1151 WARN("Failed to initialize buffer, hr %#x.\n", hr);
1152 HeapFree(GetProcessHeap(), 0, object);
1153 return hr;
1156 *buffer = &object->ID3D10Buffer_iface;
1158 TRACE("Created ID3D10Buffer %p\n", object);
1160 return S_OK;
1163 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture1D(ID3D10Device1 *iface,
1164 const D3D10_TEXTURE1D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Texture1D **texture)
1166 FIXME("iface %p, desc %p, data %p, texture %p stub!\n", iface, desc, data, texture);
1168 return E_NOTIMPL;
1171 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture2D(ID3D10Device1 *iface,
1172 const D3D10_TEXTURE2D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
1173 ID3D10Texture2D **texture)
1175 struct d3d10_device *This = impl_from_ID3D10Device(iface);
1176 struct d3d10_texture2d *object;
1177 HRESULT hr;
1179 FIXME("iface %p, desc %p, data %p, texture %p partial stub!\n", iface, desc, data, texture);
1181 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1182 if (!object)
1183 return E_OUTOFMEMORY;
1185 hr = d3d10_texture2d_init(object, This, desc);
1186 if (FAILED(hr))
1188 WARN("Failed to initialize texture, hr %#x.\n", hr);
1189 HeapFree(GetProcessHeap(), 0, object);
1190 return hr;
1193 *texture = &object->ID3D10Texture2D_iface;
1195 TRACE("Created ID3D10Texture2D %p\n", object);
1197 return S_OK;
1200 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture3D(ID3D10Device1 *iface,
1201 const D3D10_TEXTURE3D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
1202 ID3D10Texture3D **texture)
1204 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1205 struct d3d10_texture3d *object;
1206 HRESULT hr;
1208 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
1210 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1211 if (!object)
1212 return E_OUTOFMEMORY;
1214 hr = d3d10_texture3d_init(object, device, desc);
1215 if (FAILED(hr))
1217 WARN("Failed to initialize texture, hr %#x.\n", hr);
1218 HeapFree(GetProcessHeap(), 0, object);
1219 return hr;
1222 TRACE("Created 3D texture %p.\n", object);
1223 *texture = &object->ID3D10Texture3D_iface;
1225 return S_OK;
1228 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView(ID3D10Device1 *iface,
1229 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC *desc, ID3D10ShaderResourceView **view)
1231 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1232 struct d3d10_shader_resource_view *object;
1233 HRESULT hr;
1235 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
1237 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
1238 return E_OUTOFMEMORY;
1240 if (FAILED(hr = d3d10_shader_resource_view_init(object, device, resource, desc)))
1242 WARN("Failed to initialize shader resource view, hr %#x.\n", hr);
1243 HeapFree(GetProcessHeap(), 0, object);
1244 return hr;
1247 TRACE("Created shader resource view %p.\n", object);
1248 *view = &object->ID3D10ShaderResourceView_iface;
1250 return S_OK;
1253 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRenderTargetView(ID3D10Device1 *iface,
1254 ID3D10Resource *resource, const D3D10_RENDER_TARGET_VIEW_DESC *desc, ID3D10RenderTargetView **view)
1256 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1257 struct d3d10_rendertarget_view *object;
1258 HRESULT hr;
1260 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
1262 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
1263 return E_OUTOFMEMORY;
1265 if (FAILED(hr = d3d10_rendertarget_view_init(object, device, resource, desc)))
1267 WARN("Failed to initialize rendertarget view, hr %#x.\n", hr);
1268 HeapFree(GetProcessHeap(), 0, object);
1269 return hr;
1272 TRACE("Created rendertarget view %p.\n", object);
1273 *view = &object->ID3D10RenderTargetView_iface;
1275 return S_OK;
1278 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilView(ID3D10Device1 *iface,
1279 ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3D10DepthStencilView **view)
1281 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1282 struct d3d10_depthstencil_view *object;
1283 HRESULT hr;
1285 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
1287 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
1288 return E_OUTOFMEMORY;
1290 if (FAILED(hr = d3d10_depthstencil_view_init(object, device, resource, desc)))
1292 WARN("Failed to initialize depthstencil view, hr %#x.\n", hr);
1293 HeapFree(GetProcessHeap(), 0, object);
1294 return hr;
1297 TRACE("Created depthstencil view %p.\n", object);
1298 *view = &object->ID3D10DepthStencilView_iface;
1300 return S_OK;
1303 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateInputLayout(ID3D10Device1 *iface,
1304 const D3D10_INPUT_ELEMENT_DESC *element_descs, UINT element_count,
1305 const void *shader_byte_code, SIZE_T shader_byte_code_length,
1306 ID3D10InputLayout **input_layout)
1308 struct d3d10_device *This = impl_from_ID3D10Device(iface);
1309 struct d3d10_input_layout *object;
1310 HRESULT hr;
1312 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p,"
1313 "\tshader_byte_code_length %lu, input_layout %p\n",
1314 iface, element_descs, element_count, shader_byte_code,
1315 shader_byte_code_length, input_layout);
1317 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1318 if (!object)
1319 return E_OUTOFMEMORY;
1321 hr = d3d10_input_layout_init(object, This, element_descs, element_count,
1322 shader_byte_code, shader_byte_code_length);
1323 if (FAILED(hr))
1325 WARN("Failed to initialize input layout, hr %#x.\n", hr);
1326 HeapFree(GetProcessHeap(), 0, object);
1327 return hr;
1330 TRACE("Created input layout %p.\n", object);
1331 *input_layout = &object->ID3D10InputLayout_iface;
1333 return S_OK;
1336 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateVertexShader(ID3D10Device1 *iface,
1337 const void *byte_code, SIZE_T byte_code_length, ID3D10VertexShader **shader)
1339 struct d3d10_device *This = impl_from_ID3D10Device(iface);
1340 struct d3d10_vertex_shader *object;
1341 HRESULT hr;
1343 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p\n",
1344 iface, byte_code, byte_code_length, shader);
1346 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1347 if (!object)
1348 return E_OUTOFMEMORY;
1350 hr = d3d10_vertex_shader_init(object, This, byte_code, byte_code_length);
1351 if (FAILED(hr))
1353 WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
1354 HeapFree(GetProcessHeap(), 0, object);
1355 return hr;
1358 TRACE("Created vertex shader %p.\n", object);
1359 *shader = &object->ID3D10VertexShader_iface;
1361 return S_OK;
1364 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShader(ID3D10Device1 *iface,
1365 const void *byte_code, SIZE_T byte_code_length, ID3D10GeometryShader **shader)
1367 struct d3d10_device *This = impl_from_ID3D10Device(iface);
1368 struct d3d10_geometry_shader *object;
1369 HRESULT hr;
1371 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
1372 iface, byte_code, byte_code_length, shader);
1374 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1375 if (!object)
1376 return E_OUTOFMEMORY;
1378 hr = d3d10_geometry_shader_init(object, This, byte_code, byte_code_length);
1379 if (FAILED(hr))
1381 WARN("Failed to initialize geometry shader, hr %#x.\n", hr);
1382 HeapFree(GetProcessHeap(), 0, object);
1383 return hr;
1386 TRACE("Created geometry shader %p.\n", object);
1387 *shader = &object->ID3D10GeometryShader_iface;
1389 return S_OK;
1392 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShaderWithStreamOutput(ID3D10Device1 *iface,
1393 const void *byte_code, SIZE_T byte_code_length, const D3D10_SO_DECLARATION_ENTRY *output_stream_decls,
1394 UINT output_stream_decl_count, UINT output_stream_stride, ID3D10GeometryShader **shader)
1396 FIXME("iface %p, byte_code %p, byte_code_length %lu, output_stream_decls %p,\n"
1397 "\toutput_stream_decl_count %u, output_stream_stride %u, shader %p stub!\n",
1398 iface, byte_code, byte_code_length, output_stream_decls,
1399 output_stream_decl_count, output_stream_stride, shader);
1401 return E_NOTIMPL;
1404 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePixelShader(ID3D10Device1 *iface,
1405 const void *byte_code, SIZE_T byte_code_length, ID3D10PixelShader **shader)
1407 struct d3d10_device *This = impl_from_ID3D10Device(iface);
1408 struct d3d10_pixel_shader *object;
1409 HRESULT hr;
1411 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p\n",
1412 iface, byte_code, byte_code_length, shader);
1414 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1415 if (!object)
1416 return E_OUTOFMEMORY;
1418 hr = d3d10_pixel_shader_init(object, This, byte_code, byte_code_length);
1419 if (FAILED(hr))
1421 WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
1422 HeapFree(GetProcessHeap(), 0, object);
1423 return hr;
1426 TRACE("Created pixel shader %p.\n", object);
1427 *shader = &object->ID3D10PixelShader_iface;
1429 return S_OK;
1432 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState(ID3D10Device1 *iface,
1433 const D3D10_BLEND_DESC *desc, ID3D10BlendState **blend_state)
1435 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1436 struct d3d10_blend_state *object;
1437 struct wine_rb_entry *entry;
1438 HRESULT hr;
1440 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
1442 if (!desc)
1443 return E_INVALIDARG;
1445 if ((entry = wine_rb_get(&device->blend_states, desc)))
1447 object = WINE_RB_ENTRY_VALUE(entry, struct d3d10_blend_state, entry);
1449 TRACE("Returning existing blend state %p.\n", object);
1450 *blend_state = &object->ID3D10BlendState_iface;
1451 ID3D10BlendState_AddRef(*blend_state);
1453 return S_OK;
1456 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1457 if (!object)
1458 return E_OUTOFMEMORY;
1460 if (FAILED(hr = d3d10_blend_state_init(object, device, desc)))
1462 WARN("Failed to initialize blend state, hr %#x.\n", hr);
1463 HeapFree(GetProcessHeap(), 0, object);
1464 return hr;
1467 TRACE("Created blend state %p.\n", object);
1468 *blend_state = &object->ID3D10BlendState_iface;
1470 return S_OK;
1473 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilState(ID3D10Device1 *iface,
1474 const D3D10_DEPTH_STENCIL_DESC *desc, ID3D10DepthStencilState **depth_stencil_state)
1476 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1477 struct d3d10_depthstencil_state *object;
1478 struct wine_rb_entry *entry;
1479 HRESULT hr;
1481 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
1483 if (!desc)
1484 return E_INVALIDARG;
1486 if ((entry = wine_rb_get(&device->depthstencil_states, desc)))
1488 object = WINE_RB_ENTRY_VALUE(entry, struct d3d10_depthstencil_state, entry);
1490 TRACE("Returning existing depthstencil state %p.\n", object);
1491 *depth_stencil_state = &object->ID3D10DepthStencilState_iface;
1492 ID3D10DepthStencilState_AddRef(*depth_stencil_state);
1494 return S_OK;
1497 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1498 if (!object)
1499 return E_OUTOFMEMORY;
1501 if (FAILED(hr = d3d10_depthstencil_state_init(object, device, desc)))
1503 WARN("Failed to initialize depthstencil state, hr %#x.\n", hr);
1504 HeapFree(GetProcessHeap(), 0, object);
1505 return hr;
1508 TRACE("Created depthstencil state %p.\n", object);
1509 *depth_stencil_state = &object->ID3D10DepthStencilState_iface;
1511 return S_OK;
1514 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRasterizerState(ID3D10Device1 *iface,
1515 const D3D10_RASTERIZER_DESC *desc, ID3D10RasterizerState **rasterizer_state)
1517 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1518 struct d3d10_rasterizer_state *object;
1519 struct wine_rb_entry *entry;
1520 HRESULT hr;
1522 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
1524 if (!desc)
1525 return E_INVALIDARG;
1527 if ((entry = wine_rb_get(&device->rasterizer_states, desc)))
1529 object = WINE_RB_ENTRY_VALUE(entry, struct d3d10_rasterizer_state, entry);
1531 TRACE("Returning existing rasterizer state %p.\n", object);
1532 *rasterizer_state = &object->ID3D10RasterizerState_iface;
1533 ID3D10RasterizerState_AddRef(*rasterizer_state);
1535 return S_OK;
1539 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1540 if (!object)
1541 return E_OUTOFMEMORY;
1543 if (FAILED(hr = d3d10_rasterizer_state_init(object, device, desc)))
1545 WARN("Failed to initialize rasterizer state, hr %#x.\n", hr);
1546 HeapFree(GetProcessHeap(), 0, object);
1547 return hr;
1550 TRACE("Created rasterizer state %p.\n", object);
1551 *rasterizer_state = &object->ID3D10RasterizerState_iface;
1553 return S_OK;
1556 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateSamplerState(ID3D10Device1 *iface,
1557 const D3D10_SAMPLER_DESC *desc, ID3D10SamplerState **sampler_state)
1559 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1560 struct d3d10_sampler_state *object;
1561 struct wine_rb_entry *entry;
1562 HRESULT hr;
1564 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
1566 if (!desc)
1567 return E_INVALIDARG;
1569 if ((entry = wine_rb_get(&device->sampler_states, desc)))
1571 object = WINE_RB_ENTRY_VALUE(entry, struct d3d10_sampler_state, entry);
1573 TRACE("Returning existing sampler state %p.\n", object);
1574 *sampler_state = &object->ID3D10SamplerState_iface;
1575 ID3D10SamplerState_AddRef(*sampler_state);
1577 return S_OK;
1580 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1581 if (!object)
1582 return E_OUTOFMEMORY;
1584 if (FAILED(hr = d3d10_sampler_state_init(object, device, desc)))
1586 WARN("Failed to initialize sampler state, hr %#x.\n", hr);
1587 HeapFree(GetProcessHeap(), 0, object);
1588 return hr;
1591 TRACE("Created sampler state %p.\n", object);
1592 *sampler_state = &object->ID3D10SamplerState_iface;
1594 return S_OK;
1597 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateQuery(ID3D10Device1 *iface,
1598 const D3D10_QUERY_DESC *desc, ID3D10Query **query)
1600 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1601 struct d3d10_query *object;
1602 HRESULT hr;
1604 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
1606 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
1607 return E_OUTOFMEMORY;
1609 if (FAILED(hr = d3d10_query_init(object, device, FALSE)))
1611 WARN("Failed to initialize query, hr %#x.\n", hr);
1612 HeapFree(GetProcessHeap(), 0, object);
1613 return hr;
1616 TRACE("Created query %p.\n", object);
1617 *query = &object->ID3D10Query_iface;
1619 return S_OK;
1622 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePredicate(ID3D10Device1 *iface,
1623 const D3D10_QUERY_DESC *desc, ID3D10Predicate **predicate)
1625 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1626 struct d3d10_query *object;
1627 HRESULT hr;
1629 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
1631 if (!desc)
1632 return E_INVALIDARG;
1634 if (desc->Query != D3D10_QUERY_OCCLUSION_PREDICATE && desc->Query != D3D10_QUERY_SO_OVERFLOW_PREDICATE)
1636 WARN("Query type %#x is not a predicate.\n", desc->Query);
1637 return E_INVALIDARG;
1640 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
1641 return E_OUTOFMEMORY;
1643 if (FAILED(hr = d3d10_query_init(object, device, TRUE)))
1645 WARN("Failed to initialize predicate, hr %#x.\n", hr);
1646 HeapFree(GetProcessHeap(), 0, object);
1647 return hr;
1650 TRACE("Created predicate %p.\n", object);
1651 *predicate = (ID3D10Predicate *)&object->ID3D10Query_iface;
1653 return S_OK;
1656 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateCounter(ID3D10Device1 *iface,
1657 const D3D10_COUNTER_DESC *desc, ID3D10Counter **counter)
1659 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
1661 return E_NOTIMPL;
1664 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckFormatSupport(ID3D10Device1 *iface,
1665 DXGI_FORMAT format, UINT *format_support)
1667 FIXME("iface %p, format %s, format_support %p stub!\n",
1668 iface, debug_dxgi_format(format), format_support);
1670 return E_NOTIMPL;
1673 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckMultisampleQualityLevels(ID3D10Device1 *iface,
1674 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
1676 FIXME("iface %p, format %s, sample_count %u, quality_level_count %p stub!\n",
1677 iface, debug_dxgi_format(format), sample_count, quality_level_count);
1679 return E_NOTIMPL;
1682 static void STDMETHODCALLTYPE d3d10_device_CheckCounterInfo(ID3D10Device1 *iface, D3D10_COUNTER_INFO *counter_info)
1684 FIXME("iface %p, counter_info %p stub!\n", iface, counter_info);
1687 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckCounter(ID3D10Device1 *iface,
1688 const D3D10_COUNTER_DESC *desc, D3D10_COUNTER_TYPE *type, UINT *active_counters, char *name,
1689 UINT *name_length, char *units, UINT *units_length, char *description, UINT *description_length)
1691 FIXME("iface %p, desc %p, type %p, active_counters %p, name %p, name_length %p,\n"
1692 "\tunits %p, units_length %p, description %p, description_length %p stub!\n",
1693 iface, desc, type, active_counters, name, name_length,
1694 units, units_length, description, description_length);
1696 return E_NOTIMPL;
1699 static UINT STDMETHODCALLTYPE d3d10_device_GetCreationFlags(ID3D10Device1 *iface)
1701 FIXME("iface %p stub!\n", iface);
1703 return 0;
1706 static HRESULT STDMETHODCALLTYPE d3d10_device_OpenSharedResource(ID3D10Device1 *iface,
1707 HANDLE resource_handle, REFIID guid, void **resource)
1709 FIXME("iface %p, resource_handle %p, guid %s, resource %p stub!\n",
1710 iface, resource_handle, debugstr_guid(guid), resource);
1712 return E_NOTIMPL;
1715 static void STDMETHODCALLTYPE d3d10_device_SetTextFilterSize(ID3D10Device1 *iface, UINT width, UINT height)
1717 FIXME("iface %p, width %u, height %u stub!\n", iface, width, height);
1720 static void STDMETHODCALLTYPE d3d10_device_GetTextFilterSize(ID3D10Device1 *iface, UINT *width, UINT *height)
1722 FIXME("iface %p, width %p, height %p stub!\n", iface, width, height);
1725 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView1(ID3D10Device1 *iface,
1726 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC1 *desc, ID3D10ShaderResourceView1 **view)
1728 FIXME("iface %p, resource %p, desc %p, view %p stub!\n", iface, resource, desc, view);
1730 return E_NOTIMPL;
1733 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState1(ID3D10Device1 *iface,
1734 const D3D10_BLEND_DESC1 *desc, ID3D10BlendState1 **blend_state)
1736 FIXME("iface %p, desc %p, blend_state %p stub!\n", iface, desc, blend_state);
1738 return E_NOTIMPL;
1741 static D3D10_FEATURE_LEVEL1 STDMETHODCALLTYPE d3d10_device_GetFeatureLevel(ID3D10Device1 *iface)
1743 FIXME("iface %p stub!\n", iface);
1745 return D3D10_FEATURE_LEVEL_10_1;
1748 static const struct ID3D10Device1Vtbl d3d10_device1_vtbl =
1750 /* IUnknown methods */
1751 d3d10_device_QueryInterface,
1752 d3d10_device_AddRef,
1753 d3d10_device_Release,
1754 /* ID3D10Device methods */
1755 d3d10_device_VSSetConstantBuffers,
1756 d3d10_device_PSSetShaderResources,
1757 d3d10_device_PSSetShader,
1758 d3d10_device_PSSetSamplers,
1759 d3d10_device_VSSetShader,
1760 d3d10_device_DrawIndexed,
1761 d3d10_device_Draw,
1762 d3d10_device_PSSetConstantBuffers,
1763 d3d10_device_IASetInputLayout,
1764 d3d10_device_IASetVertexBuffers,
1765 d3d10_device_IASetIndexBuffer,
1766 d3d10_device_DrawIndexedInstanced,
1767 d3d10_device_DrawInstanced,
1768 d3d10_device_GSSetConstantBuffers,
1769 d3d10_device_GSSetShader,
1770 d3d10_device_IASetPrimitiveTopology,
1771 d3d10_device_VSSetShaderResources,
1772 d3d10_device_VSSetSamplers,
1773 d3d10_device_SetPredication,
1774 d3d10_device_GSSetShaderResources,
1775 d3d10_device_GSSetSamplers,
1776 d3d10_device_OMSetRenderTargets,
1777 d3d10_device_OMSetBlendState,
1778 d3d10_device_OMSetDepthStencilState,
1779 d3d10_device_SOSetTargets,
1780 d3d10_device_DrawAuto,
1781 d3d10_device_RSSetState,
1782 d3d10_device_RSSetViewports,
1783 d3d10_device_RSSetScissorRects,
1784 d3d10_device_CopySubresourceRegion,
1785 d3d10_device_CopyResource,
1786 d3d10_device_UpdateSubresource,
1787 d3d10_device_ClearRenderTargetView,
1788 d3d10_device_ClearDepthStencilView,
1789 d3d10_device_GenerateMips,
1790 d3d10_device_ResolveSubresource,
1791 d3d10_device_VSGetConstantBuffers,
1792 d3d10_device_PSGetShaderResources,
1793 d3d10_device_PSGetShader,
1794 d3d10_device_PSGetSamplers,
1795 d3d10_device_VSGetShader,
1796 d3d10_device_PSGetConstantBuffers,
1797 d3d10_device_IAGetInputLayout,
1798 d3d10_device_IAGetVertexBuffers,
1799 d3d10_device_IAGetIndexBuffer,
1800 d3d10_device_GSGetConstantBuffers,
1801 d3d10_device_GSGetShader,
1802 d3d10_device_IAGetPrimitiveTopology,
1803 d3d10_device_VSGetShaderResources,
1804 d3d10_device_VSGetSamplers,
1805 d3d10_device_GetPredication,
1806 d3d10_device_GSGetShaderResources,
1807 d3d10_device_GSGetSamplers,
1808 d3d10_device_OMGetRenderTargets,
1809 d3d10_device_OMGetBlendState,
1810 d3d10_device_OMGetDepthStencilState,
1811 d3d10_device_SOGetTargets,
1812 d3d10_device_RSGetState,
1813 d3d10_device_RSGetViewports,
1814 d3d10_device_RSGetScissorRects,
1815 d3d10_device_GetDeviceRemovedReason,
1816 d3d10_device_SetExceptionMode,
1817 d3d10_device_GetExceptionMode,
1818 d3d10_device_GetPrivateData,
1819 d3d10_device_SetPrivateData,
1820 d3d10_device_SetPrivateDataInterface,
1821 d3d10_device_ClearState,
1822 d3d10_device_Flush,
1823 d3d10_device_CreateBuffer,
1824 d3d10_device_CreateTexture1D,
1825 d3d10_device_CreateTexture2D,
1826 d3d10_device_CreateTexture3D,
1827 d3d10_device_CreateShaderResourceView,
1828 d3d10_device_CreateRenderTargetView,
1829 d3d10_device_CreateDepthStencilView,
1830 d3d10_device_CreateInputLayout,
1831 d3d10_device_CreateVertexShader,
1832 d3d10_device_CreateGeometryShader,
1833 d3d10_device_CreateGeometryShaderWithStreamOutput,
1834 d3d10_device_CreatePixelShader,
1835 d3d10_device_CreateBlendState,
1836 d3d10_device_CreateDepthStencilState,
1837 d3d10_device_CreateRasterizerState,
1838 d3d10_device_CreateSamplerState,
1839 d3d10_device_CreateQuery,
1840 d3d10_device_CreatePredicate,
1841 d3d10_device_CreateCounter,
1842 d3d10_device_CheckFormatSupport,
1843 d3d10_device_CheckMultisampleQualityLevels,
1844 d3d10_device_CheckCounterInfo,
1845 d3d10_device_CheckCounter,
1846 d3d10_device_GetCreationFlags,
1847 d3d10_device_OpenSharedResource,
1848 d3d10_device_SetTextFilterSize,
1849 d3d10_device_GetTextFilterSize,
1850 d3d10_device_CreateShaderResourceView1,
1851 d3d10_device_CreateBlendState1,
1852 d3d10_device_GetFeatureLevel,
1855 static const struct IUnknownVtbl d3d10_device_inner_unknown_vtbl =
1857 /* IUnknown methods */
1858 d3d10_device_inner_QueryInterface,
1859 d3d10_device_inner_AddRef,
1860 d3d10_device_inner_Release,
1863 static inline struct d3d10_device *impl_from_ID3D10Multithread(ID3D10Multithread *iface)
1865 return CONTAINING_RECORD(iface, struct d3d10_device, ID3D10Multithread_iface);
1868 static HRESULT STDMETHODCALLTYPE d3d10_multithread_QueryInterface(ID3D10Multithread *iface, REFIID iid, void **out)
1870 struct d3d10_device *device = impl_from_ID3D10Multithread(iface);
1872 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
1874 return IUnknown_QueryInterface(device->outer_unk, iid, out);
1877 static ULONG STDMETHODCALLTYPE d3d10_multithread_AddRef(ID3D10Multithread *iface)
1879 struct d3d10_device *device = impl_from_ID3D10Multithread(iface);
1881 TRACE("iface %p.\n", iface);
1883 return IUnknown_AddRef(device->outer_unk);
1886 static ULONG STDMETHODCALLTYPE d3d10_multithread_Release(ID3D10Multithread *iface)
1888 struct d3d10_device *device = impl_from_ID3D10Multithread(iface);
1890 TRACE("iface %p.\n", iface);
1892 return IUnknown_Release(device->outer_unk);
1895 static void STDMETHODCALLTYPE d3d10_multithread_Enter(ID3D10Multithread *iface)
1897 TRACE("iface %p.\n", iface);
1899 wined3d_mutex_lock();
1902 static void STDMETHODCALLTYPE d3d10_multithread_Leave(ID3D10Multithread *iface)
1904 TRACE("iface %p.\n", iface);
1906 wined3d_mutex_unlock();
1909 static BOOL STDMETHODCALLTYPE d3d10_multithread_SetMultithreadProtected(ID3D10Multithread *iface, BOOL protect)
1911 FIXME("iface %p, protect %#x stub!\n", iface, protect);
1913 return TRUE;
1916 static BOOL STDMETHODCALLTYPE d3d10_multithread_GetMultithreadProtected(ID3D10Multithread *iface)
1918 FIXME("iface %p stub!\n", iface);
1920 return TRUE;
1923 static const struct ID3D10MultithreadVtbl d3d10_multithread_vtbl =
1925 d3d10_multithread_QueryInterface,
1926 d3d10_multithread_AddRef,
1927 d3d10_multithread_Release,
1928 d3d10_multithread_Enter,
1929 d3d10_multithread_Leave,
1930 d3d10_multithread_SetMultithreadProtected,
1931 d3d10_multithread_GetMultithreadProtected,
1934 static void STDMETHODCALLTYPE d3d10_subresource_destroyed(void *parent) {}
1936 static const struct wined3d_parent_ops d3d10_subresource_parent_ops =
1938 d3d10_subresource_destroyed,
1941 /* IWineDXGIDeviceParent IUnknown methods */
1943 static inline struct d3d10_device *device_from_dxgi_device_parent(IWineDXGIDeviceParent *iface)
1945 return CONTAINING_RECORD(iface, struct d3d10_device, IWineDXGIDeviceParent_iface);
1948 static HRESULT STDMETHODCALLTYPE dxgi_device_parent_QueryInterface(IWineDXGIDeviceParent *iface,
1949 REFIID riid, void **ppv)
1951 struct d3d10_device *device = device_from_dxgi_device_parent(iface);
1952 return IUnknown_QueryInterface(device->outer_unk, riid, ppv);
1955 static ULONG STDMETHODCALLTYPE dxgi_device_parent_AddRef(IWineDXGIDeviceParent *iface)
1957 struct d3d10_device *device = device_from_dxgi_device_parent(iface);
1958 return IUnknown_AddRef(device->outer_unk);
1961 static ULONG STDMETHODCALLTYPE dxgi_device_parent_Release(IWineDXGIDeviceParent *iface)
1963 struct d3d10_device *device = device_from_dxgi_device_parent(iface);
1964 return IUnknown_Release(device->outer_unk);
1967 static struct wined3d_device_parent * STDMETHODCALLTYPE dxgi_device_parent_get_wined3d_device_parent(
1968 IWineDXGIDeviceParent *iface)
1970 struct d3d10_device *device = device_from_dxgi_device_parent(iface);
1971 return &device->device_parent;
1974 static const struct IWineDXGIDeviceParentVtbl d3d10_dxgi_device_parent_vtbl =
1976 /* IUnknown methods */
1977 dxgi_device_parent_QueryInterface,
1978 dxgi_device_parent_AddRef,
1979 dxgi_device_parent_Release,
1980 /* IWineDXGIDeviceParent methods */
1981 dxgi_device_parent_get_wined3d_device_parent,
1984 static inline struct d3d10_device *device_from_wined3d_device_parent(struct wined3d_device_parent *device_parent)
1986 return CONTAINING_RECORD(device_parent, struct d3d10_device, device_parent);
1989 static void CDECL device_parent_wined3d_device_created(struct wined3d_device_parent *device_parent,
1990 struct wined3d_device *wined3d_device)
1992 struct d3d10_device *device = device_from_wined3d_device_parent(device_parent);
1994 TRACE("device_parent %p, wined3d_device %p.\n", device_parent, wined3d_device);
1996 wined3d_device_incref(wined3d_device);
1997 device->wined3d_device = wined3d_device;
2000 static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent)
2002 TRACE("device_parent %p.\n", device_parent);
2005 static void CDECL device_parent_activate(struct wined3d_device_parent *device_parent, BOOL activate)
2007 TRACE("device_parent %p, activate %#x.\n", device_parent, activate);
2010 static HRESULT CDECL device_parent_surface_created(struct wined3d_device_parent *device_parent,
2011 void *container_parent, struct wined3d_surface *surface, void **parent,
2012 const struct wined3d_parent_ops **parent_ops)
2014 TRACE("device_parent %p, container_parent %p, surface %p, parent %p, parent_ops %p.\n",
2015 device_parent, container_parent, surface, parent, parent_ops);
2017 *parent = container_parent;
2018 *parent_ops = &d3d10_null_wined3d_parent_ops;
2020 return S_OK;
2023 static HRESULT CDECL device_parent_volume_created(struct wined3d_device_parent *device_parent,
2024 void *container_parent, struct wined3d_volume *volume, void **parent,
2025 const struct wined3d_parent_ops **parent_ops)
2027 TRACE("device_parent %p, container_parent %p, volume %p, parent %p, parent_ops %p.\n",
2028 device_parent, container_parent, volume, parent, parent_ops);
2030 *parent = container_parent;
2031 *parent_ops = &d3d10_null_wined3d_parent_ops;
2033 return S_OK;
2036 static HRESULT CDECL device_parent_create_swapchain_surface(struct wined3d_device_parent *device_parent,
2037 void *container_parent, const struct wined3d_resource_desc *wined3d_desc, struct wined3d_surface **surface)
2039 struct d3d10_device *device = device_from_wined3d_device_parent(device_parent);
2040 struct wined3d_resource *sub_resource;
2041 struct d3d10_texture2d *texture;
2042 D3D10_TEXTURE2D_DESC desc;
2043 HRESULT hr;
2045 FIXME("device_parent %p, container_parent %p, wined3d_desc %p, surface %p partial stub!\n",
2046 device_parent, container_parent, wined3d_desc, surface);
2048 FIXME("Implement DXGI<->wined3d usage conversion\n");
2050 desc.Width = wined3d_desc->width;
2051 desc.Height = wined3d_desc->height;
2052 desc.MipLevels = 1;
2053 desc.ArraySize = 1;
2054 desc.Format = dxgi_format_from_wined3dformat(wined3d_desc->format);
2055 desc.SampleDesc.Count = wined3d_desc->multisample_type ? wined3d_desc->multisample_type : 1;
2056 desc.SampleDesc.Quality = wined3d_desc->multisample_quality;
2057 desc.Usage = D3D10_USAGE_DEFAULT;
2058 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2059 desc.CPUAccessFlags = 0;
2060 desc.MiscFlags = 0;
2062 if (FAILED(hr = d3d10_device_CreateTexture2D(&device->ID3D10Device1_iface,
2063 &desc, NULL, (ID3D10Texture2D **)&texture)))
2065 ERR("CreateTexture2D failed, returning %#x\n", hr);
2066 return hr;
2069 sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, 0);
2070 *surface = wined3d_surface_from_resource(sub_resource);
2071 wined3d_surface_incref(*surface);
2072 ID3D10Texture2D_Release(&texture->ID3D10Texture2D_iface);
2074 return S_OK;
2077 static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent *device_parent,
2078 struct wined3d_swapchain_desc *desc, struct wined3d_swapchain **swapchain)
2080 struct d3d10_device *device = device_from_wined3d_device_parent(device_parent);
2081 IWineDXGIDevice *wine_device;
2082 HRESULT hr;
2084 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent, desc, swapchain);
2086 if (FAILED(hr = d3d10_device_QueryInterface(&device->ID3D10Device1_iface,
2087 &IID_IWineDXGIDevice, (void **)&wine_device)))
2089 ERR("Device should implement IWineDXGIDevice.\n");
2090 return E_FAIL;
2093 hr = IWineDXGIDevice_create_swapchain(wine_device, desc, swapchain);
2094 IWineDXGIDevice_Release(wine_device);
2095 if (FAILED(hr))
2097 ERR("Failed to create DXGI swapchain, returning %#x\n", hr);
2098 return hr;
2101 return S_OK;
2104 static const struct wined3d_device_parent_ops d3d10_wined3d_device_parent_ops =
2106 device_parent_wined3d_device_created,
2107 device_parent_mode_changed,
2108 device_parent_activate,
2109 device_parent_surface_created,
2110 device_parent_volume_created,
2111 device_parent_create_swapchain_surface,
2112 device_parent_create_swapchain,
2115 static void *d3d10_rb_alloc(size_t size)
2117 return HeapAlloc(GetProcessHeap(), 0, size);
2120 static void *d3d10_rb_realloc(void *ptr, size_t size)
2122 return HeapReAlloc(GetProcessHeap(), 0, ptr, size);
2125 static void d3d10_rb_free(void *ptr)
2127 HeapFree(GetProcessHeap(), 0, ptr);
2130 static int d3d10_sampler_state_compare(const void *key, const struct wine_rb_entry *entry)
2132 const D3D10_SAMPLER_DESC *ka = key;
2133 const D3D10_SAMPLER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d10_sampler_state, entry)->desc;
2135 return memcmp(ka, kb, sizeof(*ka));
2138 static const struct wine_rb_functions d3d10_sampler_state_rb_ops =
2140 d3d10_rb_alloc,
2141 d3d10_rb_realloc,
2142 d3d10_rb_free,
2143 d3d10_sampler_state_compare,
2146 static int d3d10_blend_state_compare(const void *key, const struct wine_rb_entry *entry)
2148 const D3D10_BLEND_DESC *ka = key;
2149 const D3D10_BLEND_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d10_blend_state, entry)->desc;
2151 return memcmp(ka, kb, sizeof(*ka));
2154 static const struct wine_rb_functions d3d10_blend_state_rb_ops =
2156 d3d10_rb_alloc,
2157 d3d10_rb_realloc,
2158 d3d10_rb_free,
2159 d3d10_blend_state_compare,
2162 static int d3d10_depthstencil_state_compare(const void *key, const struct wine_rb_entry *entry)
2164 const D3D10_DEPTH_STENCIL_DESC *ka = key;
2165 const D3D10_DEPTH_STENCIL_DESC *kb = &WINE_RB_ENTRY_VALUE(entry,
2166 const struct d3d10_depthstencil_state, entry)->desc;
2168 return memcmp(ka, kb, sizeof(*ka));
2171 static const struct wine_rb_functions d3d10_depthstencil_state_rb_ops =
2173 d3d10_rb_alloc,
2174 d3d10_rb_realloc,
2175 d3d10_rb_free,
2176 d3d10_depthstencil_state_compare,
2179 static int d3d10_rasterizer_state_compare(const void *key, const struct wine_rb_entry *entry)
2181 const D3D10_RASTERIZER_DESC *ka = key;
2182 const D3D10_RASTERIZER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d10_rasterizer_state, entry)->desc;
2184 return memcmp(ka, kb, sizeof(*ka));
2187 static const struct wine_rb_functions d3d10_rasterizer_state_rb_ops =
2189 d3d10_rb_alloc,
2190 d3d10_rb_realloc,
2191 d3d10_rb_free,
2192 d3d10_rasterizer_state_compare,
2195 HRESULT d3d10_device_init(struct d3d10_device *device, void *outer_unknown)
2197 device->IUnknown_inner.lpVtbl = &d3d10_device_inner_unknown_vtbl;
2198 device->ID3D10Device1_iface.lpVtbl = &d3d10_device1_vtbl;
2199 device->ID3D10Multithread_iface.lpVtbl = &d3d10_multithread_vtbl;
2200 device->IWineDXGIDeviceParent_iface.lpVtbl = &d3d10_dxgi_device_parent_vtbl;
2201 device->device_parent.ops = &d3d10_wined3d_device_parent_ops;
2202 device->refcount = 1;
2203 /* COM aggregation always takes place */
2204 device->outer_unk = outer_unknown;
2206 if (wine_rb_init(&device->blend_states, &d3d10_blend_state_rb_ops) == -1)
2208 WARN("Failed to initialize blend state rbtree.\n");
2209 return E_FAIL;
2212 if (wine_rb_init(&device->depthstencil_states, &d3d10_depthstencil_state_rb_ops) == -1)
2214 WARN("Failed to initialize depthstencil state rbtree.\n");
2215 wine_rb_destroy(&device->blend_states, NULL, NULL);
2216 return E_FAIL;
2219 if (wine_rb_init(&device->rasterizer_states, &d3d10_rasterizer_state_rb_ops) == -1)
2221 WARN("Failed to initialize rasterizer state rbtree.\n");
2222 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
2223 wine_rb_destroy(&device->blend_states, NULL, NULL);
2224 return E_FAIL;
2227 if (wine_rb_init(&device->sampler_states, &d3d10_sampler_state_rb_ops) == -1)
2229 WARN("Failed to initialize sampler state rbtree.\n");
2230 wine_rb_destroy(&device->rasterizer_states, NULL, NULL);
2231 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
2232 wine_rb_destroy(&device->blend_states, NULL, NULL);
2233 return E_FAIL;
2236 return S_OK;