d3d10core: Implement d3d10_device_PSSetShaderResources().
[wine/multimedia.git] / dlls / d3d10core / device.c
blobb69ca4df4029aeac89cd5cea7c46973a8d5021d5
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 FIXME("iface %p, predicate %p, value %d stub!\n", iface, predicate, value);
391 static void STDMETHODCALLTYPE d3d10_device_GSSetShaderResources(ID3D10Device1 *iface,
392 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
394 struct d3d10_device *device = impl_from_ID3D10Device(iface);
395 unsigned int i;
397 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
398 iface, start_slot, view_count, views);
400 for (i = 0; i < view_count; ++i)
402 struct d3d10_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
404 wined3d_device_set_gs_resource_view(device->wined3d_device, start_slot + i,
405 view ? view->wined3d_view : NULL);
409 static void STDMETHODCALLTYPE d3d10_device_GSSetSamplers(ID3D10Device1 *iface,
410 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
412 struct d3d10_device *device = impl_from_ID3D10Device(iface);
413 unsigned int i;
415 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
416 iface, start_slot, sampler_count, samplers);
418 for (i = 0; i < sampler_count; ++i)
420 struct d3d10_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
422 wined3d_device_set_gs_sampler(device->wined3d_device, start_slot + i,
423 sampler ? sampler->wined3d_sampler : NULL);
427 static void STDMETHODCALLTYPE d3d10_device_OMSetRenderTargets(ID3D10Device1 *iface,
428 UINT render_target_view_count, ID3D10RenderTargetView *const *render_target_views,
429 ID3D10DepthStencilView *depth_stencil_view)
431 struct d3d10_device *device = impl_from_ID3D10Device(iface);
432 struct d3d10_depthstencil_view *dsv;
433 unsigned int i;
435 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
436 iface, render_target_view_count, render_target_views, depth_stencil_view);
438 for (i = 0; i < render_target_view_count; ++i)
440 struct d3d10_rendertarget_view *rtv = unsafe_impl_from_ID3D10RenderTargetView(render_target_views[i]);
442 wined3d_device_set_rendertarget_view(device->wined3d_device, i,
443 rtv ? rtv->wined3d_view : NULL, FALSE);
445 for (; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
447 wined3d_device_set_rendertarget_view(device->wined3d_device, i, NULL, FALSE);
450 dsv = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
451 wined3d_device_set_depth_stencil_view(device->wined3d_device,
452 dsv ? dsv->wined3d_view : NULL);
455 static void STDMETHODCALLTYPE d3d10_device_OMSetBlendState(ID3D10Device1 *iface,
456 ID3D10BlendState *blend_state, const FLOAT blend_factor[4], UINT sample_mask)
458 struct d3d10_device *device = impl_from_ID3D10Device(iface);
460 TRACE("iface %p, blend_state %p, blend_factor [%f %f %f %f], sample_mask 0x%08x.\n",
461 iface, blend_state, blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3], sample_mask);
463 device->blend_state = unsafe_impl_from_ID3D10BlendState(blend_state);
464 memcpy(device->blend_factor, blend_factor, 4 * sizeof(*blend_factor));
465 device->sample_mask = sample_mask;
468 static void STDMETHODCALLTYPE d3d10_device_OMSetDepthStencilState(ID3D10Device1 *iface,
469 ID3D10DepthStencilState *depth_stencil_state, UINT stencil_ref)
471 struct d3d10_device *device = impl_from_ID3D10Device(iface);
473 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
474 iface, depth_stencil_state, stencil_ref);
476 device->depth_stencil_state = unsafe_impl_from_ID3D10DepthStencilState(depth_stencil_state);
477 device->stencil_ref = stencil_ref;
480 static void STDMETHODCALLTYPE d3d10_device_SOSetTargets(ID3D10Device1 *iface,
481 UINT target_count, ID3D10Buffer *const *targets, const UINT *offsets)
483 struct d3d10_device *device = impl_from_ID3D10Device(iface);
484 unsigned int count, i;
486 TRACE("iface %p, target_count %u, targets %p, offsets %p.\n", iface, target_count, targets, offsets);
488 count = min(target_count, 4);
489 for (i = 0; i < count; ++i)
491 struct d3d10_buffer *buffer = unsafe_impl_from_ID3D10Buffer(targets[i]);
493 wined3d_device_set_stream_output(device->wined3d_device, i,
494 buffer ? buffer->wined3d_buffer : NULL, offsets[i]);
497 for (i = count; i < 4; ++i)
499 wined3d_device_set_stream_output(device->wined3d_device, i, NULL, 0);
503 static void STDMETHODCALLTYPE d3d10_device_DrawAuto(ID3D10Device1 *iface)
505 FIXME("iface %p stub!\n", iface);
508 static void STDMETHODCALLTYPE d3d10_device_RSSetState(ID3D10Device1 *iface, ID3D10RasterizerState *rasterizer_state)
510 struct d3d10_device *device = impl_from_ID3D10Device(iface);
511 const D3D10_RASTERIZER_DESC *desc;
513 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
515 if (!(device->rasterizer_state = unsafe_impl_from_ID3D10RasterizerState(rasterizer_state)))
517 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_FILLMODE, WINED3D_FILL_SOLID);
518 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_CULLMODE, WINED3D_CULL_CCW);
519 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SCISSORTESTENABLE, FALSE);
520 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEANTIALIAS, FALSE);
521 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ANTIALIASEDLINEENABLE, FALSE);
522 return;
525 desc = &device->rasterizer_state->desc;
526 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_FILLMODE, desc->FillMode);
527 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_CULLMODE, desc->CullMode);
528 /* glFrontFace() */
529 if (desc->FrontCounterClockwise)
530 FIXME("Ignoring FrontCounterClockwise %#x.\n", desc->FrontCounterClockwise);
531 /* OpenGL style depth bias. */
532 if (desc->DepthBias || desc->SlopeScaledDepthBias)
533 FIXME("Ignoring depth bias.\n");
534 /* GL_DEPTH_CLAMP */
535 if (!desc->DepthClipEnable)
536 FIXME("Ignoring DepthClipEnable %#x.\n", desc->DepthClipEnable);
537 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SCISSORTESTENABLE, desc->ScissorEnable);
538 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEANTIALIAS, desc->MultisampleEnable);
539 wined3d_device_set_render_state(device->wined3d_device,
540 WINED3D_RS_ANTIALIASEDLINEENABLE, desc->AntialiasedLineEnable);
543 static void STDMETHODCALLTYPE d3d10_device_RSSetViewports(ID3D10Device1 *iface,
544 UINT viewport_count, const D3D10_VIEWPORT *viewports)
546 struct d3d10_device *device = impl_from_ID3D10Device(iface);
547 struct wined3d_viewport wined3d_vp;
549 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
551 if (viewport_count > 1)
552 FIXME("Multiple viewports not implemented.\n");
554 if (!viewport_count)
555 return;
557 wined3d_vp.x = viewports[0].TopLeftX;
558 wined3d_vp.y = viewports[0].TopLeftY;
559 wined3d_vp.width = viewports[0].Width;
560 wined3d_vp.height = viewports[0].Height;
561 wined3d_vp.min_z = viewports[0].MinDepth;
562 wined3d_vp.max_z = viewports[0].MaxDepth;
564 wined3d_device_set_viewport(device->wined3d_device, &wined3d_vp);
567 static void STDMETHODCALLTYPE d3d10_device_RSSetScissorRects(ID3D10Device1 *iface,
568 UINT rect_count, const D3D10_RECT *rects)
570 struct d3d10_device *device = impl_from_ID3D10Device(iface);
572 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
574 if (rect_count > 1)
575 FIXME("Multiple scissor rects not implemented.\n");
577 if (!rect_count)
578 return;
580 wined3d_device_set_scissor_rect(device->wined3d_device, rects);
583 static void STDMETHODCALLTYPE d3d10_device_CopySubresourceRegion(ID3D10Device1 *iface,
584 ID3D10Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
585 ID3D10Resource *src_resource, UINT src_subresource_idx, const D3D10_BOX *src_box)
587 FIXME("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u,\n"
588 "\tsrc_resource %p, src_subresource_idx %u, src_box %p stub!\n",
589 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
590 src_resource, src_subresource_idx, src_box);
593 static void STDMETHODCALLTYPE d3d10_device_CopyResource(ID3D10Device1 *iface,
594 ID3D10Resource *dst_resource, ID3D10Resource *src_resource)
596 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
597 struct d3d10_device *device = impl_from_ID3D10Device(iface);
599 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
601 wined3d_dst_resource = wined3d_resource_from_resource(dst_resource);
602 wined3d_src_resource = wined3d_resource_from_resource(src_resource);
603 wined3d_device_copy_resource(device->wined3d_device, wined3d_dst_resource, wined3d_src_resource);
606 static void STDMETHODCALLTYPE d3d10_device_UpdateSubresource(ID3D10Device1 *iface,
607 ID3D10Resource *resource, UINT subresource_idx, const D3D10_BOX *box,
608 const void *data, UINT row_pitch, UINT depth_pitch)
610 FIXME("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u stub!\n",
611 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
614 static void STDMETHODCALLTYPE d3d10_device_ClearRenderTargetView(ID3D10Device1 *iface,
615 ID3D10RenderTargetView *render_target_view, const FLOAT color_rgba[4])
617 struct d3d10_device *device = impl_from_ID3D10Device(iface);
618 struct d3d10_rendertarget_view *view = unsafe_impl_from_ID3D10RenderTargetView(render_target_view);
619 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
620 HRESULT hr;
622 TRACE("iface %p, render_target_view %p, color_rgba {%.8e, %.8e, %.8e, %.8e}.\n",
623 iface, render_target_view, color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]);
625 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL, &color)))
626 ERR("Failed to clear view, hr %#x.\n", hr);
629 static void STDMETHODCALLTYPE d3d10_device_ClearDepthStencilView(ID3D10Device1 *iface,
630 ID3D10DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
632 FIXME("iface %p, depth_stencil_view %p, flags %#x, depth %f, stencil %u stub!\n",
633 iface, depth_stencil_view, flags, depth, stencil);
636 static void STDMETHODCALLTYPE d3d10_device_GenerateMips(ID3D10Device1 *iface,
637 ID3D10ShaderResourceView *shader_resource_view)
639 FIXME("iface %p, shader_resource_view %p stub!\n", iface, shader_resource_view);
642 static void STDMETHODCALLTYPE d3d10_device_ResolveSubresource(ID3D10Device1 *iface,
643 ID3D10Resource *dst_resource, UINT dst_subresource_idx,
644 ID3D10Resource *src_resource, UINT src_subresource_idx, DXGI_FORMAT format)
646 FIXME("iface %p, dst_resource %p, dst_subresource_idx %u,\n"
647 "\tsrc_resource %p, src_subresource_idx %u, format %s stub!\n",
648 iface, dst_resource, dst_subresource_idx,
649 src_resource, src_subresource_idx, debug_dxgi_format(format));
652 static void STDMETHODCALLTYPE d3d10_device_VSGetConstantBuffers(ID3D10Device1 *iface,
653 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
655 struct d3d10_device *device = impl_from_ID3D10Device(iface);
656 unsigned int i;
658 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
659 iface, start_slot, buffer_count, buffers);
661 for (i = 0; i < buffer_count; ++i)
663 struct wined3d_buffer *wined3d_buffer;
664 struct d3d10_buffer *buffer_impl;
666 if (!(wined3d_buffer = wined3d_device_get_vs_cb(device->wined3d_device, start_slot + i)))
668 buffers[i] = NULL;
669 continue;
672 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
673 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
674 ID3D10Buffer_AddRef(buffers[i]);
678 static void STDMETHODCALLTYPE d3d10_device_PSGetShaderResources(ID3D10Device1 *iface,
679 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
681 FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
682 iface, start_slot, view_count, views);
685 static void STDMETHODCALLTYPE d3d10_device_PSGetShader(ID3D10Device1 *iface, ID3D10PixelShader **shader)
687 struct d3d10_device *device = impl_from_ID3D10Device(iface);
688 struct d3d10_pixel_shader *shader_impl;
689 struct wined3d_shader *wined3d_shader;
691 TRACE("iface %p, shader %p.\n", iface, shader);
693 if (!(wined3d_shader = wined3d_device_get_pixel_shader(device->wined3d_device)))
695 *shader = NULL;
696 return;
699 shader_impl = wined3d_shader_get_parent(wined3d_shader);
700 *shader = &shader_impl->ID3D10PixelShader_iface;
701 ID3D10PixelShader_AddRef(*shader);
704 static void STDMETHODCALLTYPE d3d10_device_PSGetSamplers(ID3D10Device1 *iface,
705 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
707 struct d3d10_device *device = impl_from_ID3D10Device(iface);
708 unsigned int i;
710 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
711 iface, start_slot, sampler_count, samplers);
713 for (i = 0; i < sampler_count; ++i)
715 struct d3d10_sampler_state *sampler_impl;
716 struct wined3d_sampler *wined3d_sampler;
718 if (!(wined3d_sampler = wined3d_device_get_ps_sampler(device->wined3d_device, start_slot + i)))
720 samplers[i] = NULL;
721 continue;
724 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
725 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
726 ID3D10SamplerState_AddRef(samplers[i]);
730 static void STDMETHODCALLTYPE d3d10_device_VSGetShader(ID3D10Device1 *iface, ID3D10VertexShader **shader)
732 struct d3d10_device *device = impl_from_ID3D10Device(iface);
733 struct d3d10_vertex_shader *shader_impl;
734 struct wined3d_shader *wined3d_shader;
736 TRACE("iface %p, shader %p.\n", iface, shader);
738 if (!(wined3d_shader = wined3d_device_get_vertex_shader(device->wined3d_device)))
740 *shader = NULL;
741 return;
744 shader_impl = wined3d_shader_get_parent(wined3d_shader);
745 *shader = &shader_impl->ID3D10VertexShader_iface;
746 ID3D10VertexShader_AddRef(*shader);
749 static void STDMETHODCALLTYPE d3d10_device_PSGetConstantBuffers(ID3D10Device1 *iface,
750 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
752 struct d3d10_device *device = impl_from_ID3D10Device(iface);
753 unsigned int i;
755 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
756 iface, start_slot, buffer_count, buffers);
758 for (i = 0; i < buffer_count; ++i)
760 struct wined3d_buffer *wined3d_buffer;
761 struct d3d10_buffer *buffer_impl;
763 if (!(wined3d_buffer = wined3d_device_get_ps_cb(device->wined3d_device, start_slot + i)))
765 buffers[i] = NULL;
766 continue;
769 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
770 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
771 ID3D10Buffer_AddRef(buffers[i]);
775 static void STDMETHODCALLTYPE d3d10_device_IAGetInputLayout(ID3D10Device1 *iface, ID3D10InputLayout **input_layout)
777 struct d3d10_device *device = impl_from_ID3D10Device(iface);
778 struct wined3d_vertex_declaration *wined3d_declaration;
779 struct d3d10_input_layout *input_layout_impl;
781 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
783 if (!(wined3d_declaration = wined3d_device_get_vertex_declaration(device->wined3d_device)))
785 *input_layout = NULL;
786 return;
789 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
790 *input_layout = &input_layout_impl->ID3D10InputLayout_iface;
791 ID3D10InputLayout_AddRef(*input_layout);
794 static void STDMETHODCALLTYPE d3d10_device_IAGetVertexBuffers(ID3D10Device1 *iface,
795 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers, UINT *strides, UINT *offsets)
797 struct d3d10_device *device = impl_from_ID3D10Device(iface);
798 unsigned int i;
800 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
801 iface, start_slot, buffer_count, buffers, strides, offsets);
803 for (i = 0; i < buffer_count; ++i)
805 struct wined3d_buffer *wined3d_buffer;
806 struct d3d10_buffer *buffer_impl;
808 if (FAILED(wined3d_device_get_stream_source(device->wined3d_device, start_slot + i,
809 &wined3d_buffer, &offsets[i], &strides[i])))
810 ERR("Failed to get vertex buffer.\n");
812 if (!wined3d_buffer)
814 buffers[i] = NULL;
815 continue;
818 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
819 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
820 ID3D10Buffer_AddRef(buffers[i]);
824 static void STDMETHODCALLTYPE d3d10_device_IAGetIndexBuffer(ID3D10Device1 *iface,
825 ID3D10Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
827 struct d3d10_device *device = impl_from_ID3D10Device(iface);
828 enum wined3d_format_id wined3d_format;
829 struct wined3d_buffer *wined3d_buffer;
830 struct d3d10_buffer *buffer_impl;
832 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
834 wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format);
835 *format = dxgi_format_from_wined3dformat(wined3d_format);
836 *offset = 0; /* FIXME */
837 if (!wined3d_buffer)
839 *buffer = NULL;
840 return;
843 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
844 *buffer = &buffer_impl->ID3D10Buffer_iface;
845 ID3D10Buffer_AddRef(*buffer);
848 static void STDMETHODCALLTYPE d3d10_device_GSGetConstantBuffers(ID3D10Device1 *iface,
849 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
851 struct d3d10_device *device = impl_from_ID3D10Device(iface);
852 unsigned int i;
854 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
855 iface, start_slot, buffer_count, buffers);
857 for (i = 0; i < buffer_count; ++i)
859 struct wined3d_buffer *wined3d_buffer;
860 struct d3d10_buffer *buffer_impl;
862 if (!(wined3d_buffer = wined3d_device_get_gs_cb(device->wined3d_device, start_slot + i)))
864 buffers[i] = NULL;
865 continue;
868 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
869 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
870 ID3D10Buffer_AddRef(buffers[i]);
874 static void STDMETHODCALLTYPE d3d10_device_GSGetShader(ID3D10Device1 *iface, ID3D10GeometryShader **shader)
876 struct d3d10_device *device = impl_from_ID3D10Device(iface);
877 struct d3d10_geometry_shader *shader_impl;
878 struct wined3d_shader *wined3d_shader;
880 TRACE("iface %p, shader %p.\n", iface, shader);
882 if (!(wined3d_shader = wined3d_device_get_geometry_shader(device->wined3d_device)))
884 *shader = NULL;
885 return;
888 shader_impl = wined3d_shader_get_parent(wined3d_shader);
889 *shader = &shader_impl->ID3D10GeometryShader_iface;
890 ID3D10GeometryShader_AddRef(*shader);
893 static void STDMETHODCALLTYPE d3d10_device_IAGetPrimitiveTopology(ID3D10Device1 *iface,
894 D3D10_PRIMITIVE_TOPOLOGY *topology)
896 struct d3d10_device *This = impl_from_ID3D10Device(iface);
898 TRACE("iface %p, topology %p\n", iface, topology);
900 wined3d_device_get_primitive_type(This->wined3d_device, (enum wined3d_primitive_type *)topology);
903 static void STDMETHODCALLTYPE d3d10_device_VSGetShaderResources(ID3D10Device1 *iface,
904 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
906 struct d3d10_device *device = impl_from_ID3D10Device(iface);
907 unsigned int i;
909 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
910 iface, start_slot, view_count, views);
912 for (i = 0; i < view_count; ++i)
914 struct wined3d_shader_resource_view *wined3d_view;
915 struct d3d10_shader_resource_view *view_impl;
917 if (!(wined3d_view = wined3d_device_get_vs_resource_view(device->wined3d_device, start_slot + i)))
919 views[i] = NULL;
920 continue;
923 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
924 views[i] = &view_impl->ID3D10ShaderResourceView_iface;
925 ID3D10ShaderResourceView_AddRef(views[i]);
929 static void STDMETHODCALLTYPE d3d10_device_VSGetSamplers(ID3D10Device1 *iface,
930 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
932 struct d3d10_device *device = impl_from_ID3D10Device(iface);
933 unsigned int i;
935 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
936 iface, start_slot, sampler_count, samplers);
938 for (i = 0; i < sampler_count; ++i)
940 struct d3d10_sampler_state *sampler_impl;
941 struct wined3d_sampler *wined3d_sampler;
943 if (!(wined3d_sampler = wined3d_device_get_vs_sampler(device->wined3d_device, start_slot + i)))
945 samplers[i] = NULL;
946 continue;
949 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
950 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
951 ID3D10SamplerState_AddRef(samplers[i]);
955 static void STDMETHODCALLTYPE d3d10_device_GetPredication(ID3D10Device1 *iface,
956 ID3D10Predicate **predicate, BOOL *value)
958 FIXME("iface %p, predicate %p, value %p stub!\n", iface, predicate, value);
961 static void STDMETHODCALLTYPE d3d10_device_GSGetShaderResources(ID3D10Device1 *iface,
962 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
964 struct d3d10_device *device = impl_from_ID3D10Device(iface);
965 unsigned int i;
967 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
968 iface, start_slot, view_count, views);
970 for (i = 0; i < view_count; ++i)
972 struct wined3d_shader_resource_view *wined3d_view;
973 struct d3d10_shader_resource_view *view_impl;
975 if (!(wined3d_view = wined3d_device_get_gs_resource_view(device->wined3d_device, start_slot + i)))
977 views[i] = NULL;
978 continue;
981 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
982 views[i] = &view_impl->ID3D10ShaderResourceView_iface;
983 ID3D10ShaderResourceView_AddRef(views[i]);
987 static void STDMETHODCALLTYPE d3d10_device_GSGetSamplers(ID3D10Device1 *iface,
988 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
990 struct d3d10_device *device = impl_from_ID3D10Device(iface);
991 unsigned int i;
993 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
994 iface, start_slot, sampler_count, samplers);
996 for (i = 0; i < sampler_count; ++i)
998 struct d3d10_sampler_state *sampler_impl;
999 struct wined3d_sampler *wined3d_sampler;
1001 if (!(wined3d_sampler = wined3d_device_get_gs_sampler(device->wined3d_device, start_slot + i)))
1003 samplers[i] = NULL;
1004 continue;
1007 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1008 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
1009 ID3D10SamplerState_AddRef(samplers[i]);
1013 static void STDMETHODCALLTYPE d3d10_device_OMGetRenderTargets(ID3D10Device1 *iface,
1014 UINT view_count, ID3D10RenderTargetView **render_target_views, ID3D10DepthStencilView **depth_stencil_view)
1016 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1017 struct wined3d_rendertarget_view *wined3d_view;
1019 TRACE("iface %p, view_count %u, render_target_views %p, depth_stencil_view %p.\n",
1020 iface, view_count, render_target_views, depth_stencil_view);
1022 if (render_target_views)
1024 struct d3d10_rendertarget_view *view_impl;
1025 unsigned int i;
1027 for (i = 0; i < view_count; ++i)
1029 if (!(wined3d_view = wined3d_device_get_rendertarget_view(device->wined3d_device, i))
1030 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
1032 render_target_views[i] = NULL;
1033 continue;
1036 render_target_views[i] = &view_impl->ID3D10RenderTargetView_iface;
1037 ID3D10RenderTargetView_AddRef(render_target_views[i]);
1041 if (depth_stencil_view)
1043 struct d3d10_depthstencil_view *view_impl;
1045 if (!(wined3d_view = wined3d_device_get_depth_stencil_view(device->wined3d_device))
1046 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
1048 *depth_stencil_view = NULL;
1050 else
1052 *depth_stencil_view = &view_impl->ID3D10DepthStencilView_iface;
1053 ID3D10DepthStencilView_AddRef(*depth_stencil_view);
1058 static void STDMETHODCALLTYPE d3d10_device_OMGetBlendState(ID3D10Device1 *iface,
1059 ID3D10BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
1061 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1063 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
1064 iface, blend_state, blend_factor, sample_mask);
1066 if ((*blend_state = device->blend_state ? &device->blend_state->ID3D10BlendState_iface : NULL))
1067 ID3D10BlendState_AddRef(*blend_state);
1068 memcpy(blend_factor, device->blend_factor, 4 * sizeof(*blend_factor));
1069 *sample_mask = device->sample_mask;
1072 static void STDMETHODCALLTYPE d3d10_device_OMGetDepthStencilState(ID3D10Device1 *iface,
1073 ID3D10DepthStencilState **depth_stencil_state, UINT *stencil_ref)
1075 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1077 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
1078 iface, depth_stencil_state, stencil_ref);
1080 if ((*depth_stencil_state = device->depth_stencil_state
1081 ? &device->depth_stencil_state->ID3D10DepthStencilState_iface : NULL))
1082 ID3D10DepthStencilState_AddRef(*depth_stencil_state);
1083 *stencil_ref = device->stencil_ref;
1086 static void STDMETHODCALLTYPE d3d10_device_SOGetTargets(ID3D10Device1 *iface,
1087 UINT buffer_count, ID3D10Buffer **buffers, UINT *offsets)
1089 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1090 unsigned int i;
1092 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n",
1093 iface, buffer_count, buffers, offsets);
1095 for (i = 0; i < buffer_count; ++i)
1097 struct wined3d_buffer *wined3d_buffer;
1098 struct d3d10_buffer *buffer_impl;
1100 if (!(wined3d_buffer = wined3d_device_get_stream_output(device->wined3d_device, i, &offsets[i])))
1102 buffers[i] = NULL;
1103 continue;
1106 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1107 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
1108 ID3D10Buffer_AddRef(buffers[i]);
1112 static void STDMETHODCALLTYPE d3d10_device_RSGetState(ID3D10Device1 *iface, ID3D10RasterizerState **rasterizer_state)
1114 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1116 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
1118 if ((*rasterizer_state = device->rasterizer_state ? &device->rasterizer_state->ID3D10RasterizerState_iface : NULL))
1119 ID3D10RasterizerState_AddRef(*rasterizer_state);
1122 static void STDMETHODCALLTYPE d3d10_device_RSGetViewports(ID3D10Device1 *iface,
1123 UINT *viewport_count, D3D10_VIEWPORT *viewports)
1125 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1126 struct wined3d_viewport wined3d_vp;
1128 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
1130 if (!viewports)
1132 *viewport_count = 1;
1133 return;
1136 if (!*viewport_count)
1137 return;
1139 wined3d_device_get_viewport(device->wined3d_device, &wined3d_vp);
1141 viewports[0].TopLeftX = wined3d_vp.x;
1142 viewports[0].TopLeftY = wined3d_vp.y;
1143 viewports[0].Width = wined3d_vp.width;
1144 viewports[0].Height = wined3d_vp.height;
1145 viewports[0].MinDepth = wined3d_vp.min_z;
1146 viewports[0].MaxDepth = wined3d_vp.max_z;
1148 if (*viewport_count > 1)
1149 memset(&viewports[1], 0, (*viewport_count - 1) * sizeof(*viewports));
1152 static void STDMETHODCALLTYPE d3d10_device_RSGetScissorRects(ID3D10Device1 *iface, UINT *rect_count, D3D10_RECT *rects)
1154 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1156 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
1158 if (!rects)
1160 *rect_count = 1;
1161 return;
1164 if (!*rect_count)
1165 return;
1167 wined3d_device_get_scissor_rect(device->wined3d_device, rects);
1168 if (*rect_count > 1)
1169 memset(&rects[1], 0, (*rect_count - 1) * sizeof(*rects));
1172 static HRESULT STDMETHODCALLTYPE d3d10_device_GetDeviceRemovedReason(ID3D10Device1 *iface)
1174 TRACE("iface %p.\n", iface);
1176 /* In the current implementation the device is never removed, so we can
1177 * just return S_OK here. */
1179 return S_OK;
1182 static HRESULT STDMETHODCALLTYPE d3d10_device_SetExceptionMode(ID3D10Device1 *iface, UINT flags)
1184 FIXME("iface %p, flags %#x stub!\n", iface, flags);
1186 return E_NOTIMPL;
1189 static UINT STDMETHODCALLTYPE d3d10_device_GetExceptionMode(ID3D10Device1 *iface)
1191 FIXME("iface %p stub!\n", iface);
1193 return 0;
1196 static HRESULT STDMETHODCALLTYPE d3d10_device_GetPrivateData(ID3D10Device1 *iface,
1197 REFGUID guid, UINT *data_size, void *data)
1199 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
1200 iface, debugstr_guid(guid), data_size, data);
1202 return E_NOTIMPL;
1205 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateData(ID3D10Device1 *iface,
1206 REFGUID guid, UINT data_size, const void *data)
1208 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
1209 iface, debugstr_guid(guid), data_size, data);
1211 return E_NOTIMPL;
1214 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateDataInterface(ID3D10Device1 *iface,
1215 REFGUID guid, const IUnknown *data)
1217 FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
1219 return E_NOTIMPL;
1222 static void STDMETHODCALLTYPE d3d10_device_ClearState(ID3D10Device1 *iface)
1224 FIXME("iface %p stub!\n", iface);
1227 static void STDMETHODCALLTYPE d3d10_device_Flush(ID3D10Device1 *iface)
1229 FIXME("iface %p stub!\n", iface);
1232 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBuffer(ID3D10Device1 *iface,
1233 const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Buffer **buffer)
1235 struct d3d10_device *This = impl_from_ID3D10Device(iface);
1236 struct d3d10_buffer *object;
1237 HRESULT hr;
1239 FIXME("iface %p, desc %p, data %p, buffer %p partial stub!\n", iface, desc, data, buffer);
1241 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1242 if (!object)
1243 return E_OUTOFMEMORY;
1245 hr = d3d10_buffer_init(object, This, desc, data);
1246 if (FAILED(hr))
1248 WARN("Failed to initialize buffer, hr %#x.\n", hr);
1249 HeapFree(GetProcessHeap(), 0, object);
1250 return hr;
1253 *buffer = &object->ID3D10Buffer_iface;
1255 TRACE("Created ID3D10Buffer %p\n", object);
1257 return S_OK;
1260 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture1D(ID3D10Device1 *iface,
1261 const D3D10_TEXTURE1D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Texture1D **texture)
1263 FIXME("iface %p, desc %p, data %p, texture %p stub!\n", iface, desc, data, texture);
1265 return E_NOTIMPL;
1268 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture2D(ID3D10Device1 *iface,
1269 const D3D10_TEXTURE2D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
1270 ID3D10Texture2D **texture)
1272 struct d3d10_device *This = impl_from_ID3D10Device(iface);
1273 struct d3d10_texture2d *object;
1274 HRESULT hr;
1276 FIXME("iface %p, desc %p, data %p, texture %p partial stub!\n", iface, desc, data, texture);
1278 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1279 if (!object)
1280 return E_OUTOFMEMORY;
1282 hr = d3d10_texture2d_init(object, This, desc);
1283 if (FAILED(hr))
1285 WARN("Failed to initialize texture, hr %#x.\n", hr);
1286 HeapFree(GetProcessHeap(), 0, object);
1287 return hr;
1290 *texture = &object->ID3D10Texture2D_iface;
1292 TRACE("Created ID3D10Texture2D %p\n", object);
1294 return S_OK;
1297 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture3D(ID3D10Device1 *iface,
1298 const D3D10_TEXTURE3D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
1299 ID3D10Texture3D **texture)
1301 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1302 struct d3d10_texture3d *object;
1303 HRESULT hr;
1305 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
1307 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1308 if (!object)
1309 return E_OUTOFMEMORY;
1311 hr = d3d10_texture3d_init(object, device, desc);
1312 if (FAILED(hr))
1314 WARN("Failed to initialize texture, hr %#x.\n", hr);
1315 HeapFree(GetProcessHeap(), 0, object);
1316 return hr;
1319 TRACE("Created 3D texture %p.\n", object);
1320 *texture = &object->ID3D10Texture3D_iface;
1322 return S_OK;
1325 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView(ID3D10Device1 *iface,
1326 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC *desc, ID3D10ShaderResourceView **view)
1328 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1329 struct d3d10_shader_resource_view *object;
1330 HRESULT hr;
1332 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
1334 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
1335 return E_OUTOFMEMORY;
1337 if (FAILED(hr = d3d10_shader_resource_view_init(object, device, resource, desc)))
1339 WARN("Failed to initialize shader resource view, hr %#x.\n", hr);
1340 HeapFree(GetProcessHeap(), 0, object);
1341 return hr;
1344 TRACE("Created shader resource view %p.\n", object);
1345 *view = &object->ID3D10ShaderResourceView_iface;
1347 return S_OK;
1350 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRenderTargetView(ID3D10Device1 *iface,
1351 ID3D10Resource *resource, const D3D10_RENDER_TARGET_VIEW_DESC *desc, ID3D10RenderTargetView **view)
1353 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1354 struct d3d10_rendertarget_view *object;
1355 HRESULT hr;
1357 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
1359 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
1360 return E_OUTOFMEMORY;
1362 if (FAILED(hr = d3d10_rendertarget_view_init(object, device, resource, desc)))
1364 WARN("Failed to initialize rendertarget view, hr %#x.\n", hr);
1365 HeapFree(GetProcessHeap(), 0, object);
1366 return hr;
1369 TRACE("Created rendertarget view %p.\n", object);
1370 *view = &object->ID3D10RenderTargetView_iface;
1372 return S_OK;
1375 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilView(ID3D10Device1 *iface,
1376 ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3D10DepthStencilView **view)
1378 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1379 struct d3d10_depthstencil_view *object;
1380 HRESULT hr;
1382 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
1384 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
1385 return E_OUTOFMEMORY;
1387 if (FAILED(hr = d3d10_depthstencil_view_init(object, device, resource, desc)))
1389 WARN("Failed to initialize depthstencil view, hr %#x.\n", hr);
1390 HeapFree(GetProcessHeap(), 0, object);
1391 return hr;
1394 TRACE("Created depthstencil view %p.\n", object);
1395 *view = &object->ID3D10DepthStencilView_iface;
1397 return S_OK;
1400 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateInputLayout(ID3D10Device1 *iface,
1401 const D3D10_INPUT_ELEMENT_DESC *element_descs, UINT element_count,
1402 const void *shader_byte_code, SIZE_T shader_byte_code_length,
1403 ID3D10InputLayout **input_layout)
1405 struct d3d10_device *This = impl_from_ID3D10Device(iface);
1406 struct d3d10_input_layout *object;
1407 HRESULT hr;
1409 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p,"
1410 "\tshader_byte_code_length %lu, input_layout %p\n",
1411 iface, element_descs, element_count, shader_byte_code,
1412 shader_byte_code_length, input_layout);
1414 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1415 if (!object)
1416 return E_OUTOFMEMORY;
1418 hr = d3d10_input_layout_init(object, This, element_descs, element_count,
1419 shader_byte_code, shader_byte_code_length);
1420 if (FAILED(hr))
1422 WARN("Failed to initialize input layout, hr %#x.\n", hr);
1423 HeapFree(GetProcessHeap(), 0, object);
1424 return hr;
1427 TRACE("Created input layout %p.\n", object);
1428 *input_layout = &object->ID3D10InputLayout_iface;
1430 return S_OK;
1433 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateVertexShader(ID3D10Device1 *iface,
1434 const void *byte_code, SIZE_T byte_code_length, ID3D10VertexShader **shader)
1436 struct d3d10_device *This = impl_from_ID3D10Device(iface);
1437 struct d3d10_vertex_shader *object;
1438 HRESULT hr;
1440 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p\n",
1441 iface, byte_code, byte_code_length, shader);
1443 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1444 if (!object)
1445 return E_OUTOFMEMORY;
1447 hr = d3d10_vertex_shader_init(object, This, byte_code, byte_code_length);
1448 if (FAILED(hr))
1450 WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
1451 HeapFree(GetProcessHeap(), 0, object);
1452 return hr;
1455 TRACE("Created vertex shader %p.\n", object);
1456 *shader = &object->ID3D10VertexShader_iface;
1458 return S_OK;
1461 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShader(ID3D10Device1 *iface,
1462 const void *byte_code, SIZE_T byte_code_length, ID3D10GeometryShader **shader)
1464 struct d3d10_device *This = impl_from_ID3D10Device(iface);
1465 struct d3d10_geometry_shader *object;
1466 HRESULT hr;
1468 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
1469 iface, byte_code, byte_code_length, shader);
1471 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1472 if (!object)
1473 return E_OUTOFMEMORY;
1475 hr = d3d10_geometry_shader_init(object, This, byte_code, byte_code_length);
1476 if (FAILED(hr))
1478 WARN("Failed to initialize geometry shader, hr %#x.\n", hr);
1479 HeapFree(GetProcessHeap(), 0, object);
1480 return hr;
1483 TRACE("Created geometry shader %p.\n", object);
1484 *shader = &object->ID3D10GeometryShader_iface;
1486 return S_OK;
1489 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShaderWithStreamOutput(ID3D10Device1 *iface,
1490 const void *byte_code, SIZE_T byte_code_length, const D3D10_SO_DECLARATION_ENTRY *output_stream_decls,
1491 UINT output_stream_decl_count, UINT output_stream_stride, ID3D10GeometryShader **shader)
1493 FIXME("iface %p, byte_code %p, byte_code_length %lu, output_stream_decls %p,\n"
1494 "\toutput_stream_decl_count %u, output_stream_stride %u, shader %p stub!\n",
1495 iface, byte_code, byte_code_length, output_stream_decls,
1496 output_stream_decl_count, output_stream_stride, shader);
1498 return E_NOTIMPL;
1501 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePixelShader(ID3D10Device1 *iface,
1502 const void *byte_code, SIZE_T byte_code_length, ID3D10PixelShader **shader)
1504 struct d3d10_device *This = impl_from_ID3D10Device(iface);
1505 struct d3d10_pixel_shader *object;
1506 HRESULT hr;
1508 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p\n",
1509 iface, byte_code, byte_code_length, shader);
1511 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1512 if (!object)
1513 return E_OUTOFMEMORY;
1515 hr = d3d10_pixel_shader_init(object, This, byte_code, byte_code_length);
1516 if (FAILED(hr))
1518 WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
1519 HeapFree(GetProcessHeap(), 0, object);
1520 return hr;
1523 TRACE("Created pixel shader %p.\n", object);
1524 *shader = &object->ID3D10PixelShader_iface;
1526 return S_OK;
1529 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState(ID3D10Device1 *iface,
1530 const D3D10_BLEND_DESC *desc, ID3D10BlendState **blend_state)
1532 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1533 struct d3d10_blend_state *object;
1534 struct wine_rb_entry *entry;
1535 HRESULT hr;
1537 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
1539 if (!desc)
1540 return E_INVALIDARG;
1542 if ((entry = wine_rb_get(&device->blend_states, desc)))
1544 object = WINE_RB_ENTRY_VALUE(entry, struct d3d10_blend_state, entry);
1546 TRACE("Returning existing blend state %p.\n", object);
1547 *blend_state = &object->ID3D10BlendState_iface;
1548 ID3D10BlendState_AddRef(*blend_state);
1550 return S_OK;
1553 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1554 if (!object)
1555 return E_OUTOFMEMORY;
1557 if (FAILED(hr = d3d10_blend_state_init(object, device, desc)))
1559 WARN("Failed to initialize blend state, hr %#x.\n", hr);
1560 HeapFree(GetProcessHeap(), 0, object);
1561 return hr;
1564 TRACE("Created blend state %p.\n", object);
1565 *blend_state = &object->ID3D10BlendState_iface;
1567 return S_OK;
1570 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilState(ID3D10Device1 *iface,
1571 const D3D10_DEPTH_STENCIL_DESC *desc, ID3D10DepthStencilState **depth_stencil_state)
1573 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1574 struct d3d10_depthstencil_state *object;
1575 struct wine_rb_entry *entry;
1576 HRESULT hr;
1578 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
1580 if (!desc)
1581 return E_INVALIDARG;
1583 if ((entry = wine_rb_get(&device->depthstencil_states, desc)))
1585 object = WINE_RB_ENTRY_VALUE(entry, struct d3d10_depthstencil_state, entry);
1587 TRACE("Returning existing depthstencil state %p.\n", object);
1588 *depth_stencil_state = &object->ID3D10DepthStencilState_iface;
1589 ID3D10DepthStencilState_AddRef(*depth_stencil_state);
1591 return S_OK;
1594 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1595 if (!object)
1596 return E_OUTOFMEMORY;
1598 if (FAILED(hr = d3d10_depthstencil_state_init(object, device, desc)))
1600 WARN("Failed to initialize depthstencil state, hr %#x.\n", hr);
1601 HeapFree(GetProcessHeap(), 0, object);
1602 return hr;
1605 TRACE("Created depthstencil state %p.\n", object);
1606 *depth_stencil_state = &object->ID3D10DepthStencilState_iface;
1608 return S_OK;
1611 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRasterizerState(ID3D10Device1 *iface,
1612 const D3D10_RASTERIZER_DESC *desc, ID3D10RasterizerState **rasterizer_state)
1614 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1615 struct d3d10_rasterizer_state *object;
1616 struct wine_rb_entry *entry;
1617 HRESULT hr;
1619 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
1621 if (!desc)
1622 return E_INVALIDARG;
1624 if ((entry = wine_rb_get(&device->rasterizer_states, desc)))
1626 object = WINE_RB_ENTRY_VALUE(entry, struct d3d10_rasterizer_state, entry);
1628 TRACE("Returning existing rasterizer state %p.\n", object);
1629 *rasterizer_state = &object->ID3D10RasterizerState_iface;
1630 ID3D10RasterizerState_AddRef(*rasterizer_state);
1632 return S_OK;
1636 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1637 if (!object)
1638 return E_OUTOFMEMORY;
1640 if (FAILED(hr = d3d10_rasterizer_state_init(object, device, desc)))
1642 WARN("Failed to initialize rasterizer state, hr %#x.\n", hr);
1643 HeapFree(GetProcessHeap(), 0, object);
1644 return hr;
1647 TRACE("Created rasterizer state %p.\n", object);
1648 *rasterizer_state = &object->ID3D10RasterizerState_iface;
1650 return S_OK;
1653 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateSamplerState(ID3D10Device1 *iface,
1654 const D3D10_SAMPLER_DESC *desc, ID3D10SamplerState **sampler_state)
1656 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1657 struct d3d10_sampler_state *object;
1658 struct wine_rb_entry *entry;
1659 HRESULT hr;
1661 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
1663 if (!desc)
1664 return E_INVALIDARG;
1666 if ((entry = wine_rb_get(&device->sampler_states, desc)))
1668 object = WINE_RB_ENTRY_VALUE(entry, struct d3d10_sampler_state, entry);
1670 TRACE("Returning existing sampler state %p.\n", object);
1671 *sampler_state = &object->ID3D10SamplerState_iface;
1672 ID3D10SamplerState_AddRef(*sampler_state);
1674 return S_OK;
1677 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1678 if (!object)
1679 return E_OUTOFMEMORY;
1681 if (FAILED(hr = d3d10_sampler_state_init(object, device, desc)))
1683 WARN("Failed to initialize sampler state, hr %#x.\n", hr);
1684 HeapFree(GetProcessHeap(), 0, object);
1685 return hr;
1688 TRACE("Created sampler state %p.\n", object);
1689 *sampler_state = &object->ID3D10SamplerState_iface;
1691 return S_OK;
1694 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateQuery(ID3D10Device1 *iface,
1695 const D3D10_QUERY_DESC *desc, ID3D10Query **query)
1697 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1698 struct d3d10_query *object;
1699 HRESULT hr;
1701 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
1703 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
1704 return E_OUTOFMEMORY;
1706 if (FAILED(hr = d3d10_query_init(object, device, FALSE)))
1708 WARN("Failed to initialize query, hr %#x.\n", hr);
1709 HeapFree(GetProcessHeap(), 0, object);
1710 return hr;
1713 TRACE("Created query %p.\n", object);
1714 *query = &object->ID3D10Query_iface;
1716 return S_OK;
1719 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePredicate(ID3D10Device1 *iface,
1720 const D3D10_QUERY_DESC *desc, ID3D10Predicate **predicate)
1722 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1723 struct d3d10_query *object;
1724 HRESULT hr;
1726 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
1728 if (!desc)
1729 return E_INVALIDARG;
1731 if (desc->Query != D3D10_QUERY_OCCLUSION_PREDICATE && desc->Query != D3D10_QUERY_SO_OVERFLOW_PREDICATE)
1733 WARN("Query type %#x is not a predicate.\n", desc->Query);
1734 return E_INVALIDARG;
1737 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
1738 return E_OUTOFMEMORY;
1740 if (FAILED(hr = d3d10_query_init(object, device, TRUE)))
1742 WARN("Failed to initialize predicate, hr %#x.\n", hr);
1743 HeapFree(GetProcessHeap(), 0, object);
1744 return hr;
1747 TRACE("Created predicate %p.\n", object);
1748 *predicate = (ID3D10Predicate *)&object->ID3D10Query_iface;
1750 return S_OK;
1753 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateCounter(ID3D10Device1 *iface,
1754 const D3D10_COUNTER_DESC *desc, ID3D10Counter **counter)
1756 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
1758 return E_NOTIMPL;
1761 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckFormatSupport(ID3D10Device1 *iface,
1762 DXGI_FORMAT format, UINT *format_support)
1764 FIXME("iface %p, format %s, format_support %p stub!\n",
1765 iface, debug_dxgi_format(format), format_support);
1767 return E_NOTIMPL;
1770 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckMultisampleQualityLevels(ID3D10Device1 *iface,
1771 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
1773 FIXME("iface %p, format %s, sample_count %u, quality_level_count %p stub!\n",
1774 iface, debug_dxgi_format(format), sample_count, quality_level_count);
1776 return E_NOTIMPL;
1779 static void STDMETHODCALLTYPE d3d10_device_CheckCounterInfo(ID3D10Device1 *iface, D3D10_COUNTER_INFO *counter_info)
1781 FIXME("iface %p, counter_info %p stub!\n", iface, counter_info);
1784 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckCounter(ID3D10Device1 *iface,
1785 const D3D10_COUNTER_DESC *desc, D3D10_COUNTER_TYPE *type, UINT *active_counters, char *name,
1786 UINT *name_length, char *units, UINT *units_length, char *description, UINT *description_length)
1788 FIXME("iface %p, desc %p, type %p, active_counters %p, name %p, name_length %p,\n"
1789 "\tunits %p, units_length %p, description %p, description_length %p stub!\n",
1790 iface, desc, type, active_counters, name, name_length,
1791 units, units_length, description, description_length);
1793 return E_NOTIMPL;
1796 static UINT STDMETHODCALLTYPE d3d10_device_GetCreationFlags(ID3D10Device1 *iface)
1798 FIXME("iface %p stub!\n", iface);
1800 return 0;
1803 static HRESULT STDMETHODCALLTYPE d3d10_device_OpenSharedResource(ID3D10Device1 *iface,
1804 HANDLE resource_handle, REFIID guid, void **resource)
1806 FIXME("iface %p, resource_handle %p, guid %s, resource %p stub!\n",
1807 iface, resource_handle, debugstr_guid(guid), resource);
1809 return E_NOTIMPL;
1812 static void STDMETHODCALLTYPE d3d10_device_SetTextFilterSize(ID3D10Device1 *iface, UINT width, UINT height)
1814 FIXME("iface %p, width %u, height %u stub!\n", iface, width, height);
1817 static void STDMETHODCALLTYPE d3d10_device_GetTextFilterSize(ID3D10Device1 *iface, UINT *width, UINT *height)
1819 FIXME("iface %p, width %p, height %p stub!\n", iface, width, height);
1822 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView1(ID3D10Device1 *iface,
1823 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC1 *desc, ID3D10ShaderResourceView1 **view)
1825 FIXME("iface %p, resource %p, desc %p, view %p stub!\n", iface, resource, desc, view);
1827 return E_NOTIMPL;
1830 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState1(ID3D10Device1 *iface,
1831 const D3D10_BLEND_DESC1 *desc, ID3D10BlendState1 **blend_state)
1833 FIXME("iface %p, desc %p, blend_state %p stub!\n", iface, desc, blend_state);
1835 return E_NOTIMPL;
1838 static D3D10_FEATURE_LEVEL1 STDMETHODCALLTYPE d3d10_device_GetFeatureLevel(ID3D10Device1 *iface)
1840 FIXME("iface %p stub!\n", iface);
1842 return D3D10_FEATURE_LEVEL_10_1;
1845 static const struct ID3D10Device1Vtbl d3d10_device1_vtbl =
1847 /* IUnknown methods */
1848 d3d10_device_QueryInterface,
1849 d3d10_device_AddRef,
1850 d3d10_device_Release,
1851 /* ID3D10Device methods */
1852 d3d10_device_VSSetConstantBuffers,
1853 d3d10_device_PSSetShaderResources,
1854 d3d10_device_PSSetShader,
1855 d3d10_device_PSSetSamplers,
1856 d3d10_device_VSSetShader,
1857 d3d10_device_DrawIndexed,
1858 d3d10_device_Draw,
1859 d3d10_device_PSSetConstantBuffers,
1860 d3d10_device_IASetInputLayout,
1861 d3d10_device_IASetVertexBuffers,
1862 d3d10_device_IASetIndexBuffer,
1863 d3d10_device_DrawIndexedInstanced,
1864 d3d10_device_DrawInstanced,
1865 d3d10_device_GSSetConstantBuffers,
1866 d3d10_device_GSSetShader,
1867 d3d10_device_IASetPrimitiveTopology,
1868 d3d10_device_VSSetShaderResources,
1869 d3d10_device_VSSetSamplers,
1870 d3d10_device_SetPredication,
1871 d3d10_device_GSSetShaderResources,
1872 d3d10_device_GSSetSamplers,
1873 d3d10_device_OMSetRenderTargets,
1874 d3d10_device_OMSetBlendState,
1875 d3d10_device_OMSetDepthStencilState,
1876 d3d10_device_SOSetTargets,
1877 d3d10_device_DrawAuto,
1878 d3d10_device_RSSetState,
1879 d3d10_device_RSSetViewports,
1880 d3d10_device_RSSetScissorRects,
1881 d3d10_device_CopySubresourceRegion,
1882 d3d10_device_CopyResource,
1883 d3d10_device_UpdateSubresource,
1884 d3d10_device_ClearRenderTargetView,
1885 d3d10_device_ClearDepthStencilView,
1886 d3d10_device_GenerateMips,
1887 d3d10_device_ResolveSubresource,
1888 d3d10_device_VSGetConstantBuffers,
1889 d3d10_device_PSGetShaderResources,
1890 d3d10_device_PSGetShader,
1891 d3d10_device_PSGetSamplers,
1892 d3d10_device_VSGetShader,
1893 d3d10_device_PSGetConstantBuffers,
1894 d3d10_device_IAGetInputLayout,
1895 d3d10_device_IAGetVertexBuffers,
1896 d3d10_device_IAGetIndexBuffer,
1897 d3d10_device_GSGetConstantBuffers,
1898 d3d10_device_GSGetShader,
1899 d3d10_device_IAGetPrimitiveTopology,
1900 d3d10_device_VSGetShaderResources,
1901 d3d10_device_VSGetSamplers,
1902 d3d10_device_GetPredication,
1903 d3d10_device_GSGetShaderResources,
1904 d3d10_device_GSGetSamplers,
1905 d3d10_device_OMGetRenderTargets,
1906 d3d10_device_OMGetBlendState,
1907 d3d10_device_OMGetDepthStencilState,
1908 d3d10_device_SOGetTargets,
1909 d3d10_device_RSGetState,
1910 d3d10_device_RSGetViewports,
1911 d3d10_device_RSGetScissorRects,
1912 d3d10_device_GetDeviceRemovedReason,
1913 d3d10_device_SetExceptionMode,
1914 d3d10_device_GetExceptionMode,
1915 d3d10_device_GetPrivateData,
1916 d3d10_device_SetPrivateData,
1917 d3d10_device_SetPrivateDataInterface,
1918 d3d10_device_ClearState,
1919 d3d10_device_Flush,
1920 d3d10_device_CreateBuffer,
1921 d3d10_device_CreateTexture1D,
1922 d3d10_device_CreateTexture2D,
1923 d3d10_device_CreateTexture3D,
1924 d3d10_device_CreateShaderResourceView,
1925 d3d10_device_CreateRenderTargetView,
1926 d3d10_device_CreateDepthStencilView,
1927 d3d10_device_CreateInputLayout,
1928 d3d10_device_CreateVertexShader,
1929 d3d10_device_CreateGeometryShader,
1930 d3d10_device_CreateGeometryShaderWithStreamOutput,
1931 d3d10_device_CreatePixelShader,
1932 d3d10_device_CreateBlendState,
1933 d3d10_device_CreateDepthStencilState,
1934 d3d10_device_CreateRasterizerState,
1935 d3d10_device_CreateSamplerState,
1936 d3d10_device_CreateQuery,
1937 d3d10_device_CreatePredicate,
1938 d3d10_device_CreateCounter,
1939 d3d10_device_CheckFormatSupport,
1940 d3d10_device_CheckMultisampleQualityLevels,
1941 d3d10_device_CheckCounterInfo,
1942 d3d10_device_CheckCounter,
1943 d3d10_device_GetCreationFlags,
1944 d3d10_device_OpenSharedResource,
1945 d3d10_device_SetTextFilterSize,
1946 d3d10_device_GetTextFilterSize,
1947 d3d10_device_CreateShaderResourceView1,
1948 d3d10_device_CreateBlendState1,
1949 d3d10_device_GetFeatureLevel,
1952 static const struct IUnknownVtbl d3d10_device_inner_unknown_vtbl =
1954 /* IUnknown methods */
1955 d3d10_device_inner_QueryInterface,
1956 d3d10_device_inner_AddRef,
1957 d3d10_device_inner_Release,
1960 static inline struct d3d10_device *impl_from_ID3D10Multithread(ID3D10Multithread *iface)
1962 return CONTAINING_RECORD(iface, struct d3d10_device, ID3D10Multithread_iface);
1965 static HRESULT STDMETHODCALLTYPE d3d10_multithread_QueryInterface(ID3D10Multithread *iface, REFIID iid, void **out)
1967 struct d3d10_device *device = impl_from_ID3D10Multithread(iface);
1969 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
1971 return IUnknown_QueryInterface(device->outer_unk, iid, out);
1974 static ULONG STDMETHODCALLTYPE d3d10_multithread_AddRef(ID3D10Multithread *iface)
1976 struct d3d10_device *device = impl_from_ID3D10Multithread(iface);
1978 TRACE("iface %p.\n", iface);
1980 return IUnknown_AddRef(device->outer_unk);
1983 static ULONG STDMETHODCALLTYPE d3d10_multithread_Release(ID3D10Multithread *iface)
1985 struct d3d10_device *device = impl_from_ID3D10Multithread(iface);
1987 TRACE("iface %p.\n", iface);
1989 return IUnknown_Release(device->outer_unk);
1992 static void STDMETHODCALLTYPE d3d10_multithread_Enter(ID3D10Multithread *iface)
1994 TRACE("iface %p.\n", iface);
1996 wined3d_mutex_lock();
1999 static void STDMETHODCALLTYPE d3d10_multithread_Leave(ID3D10Multithread *iface)
2001 TRACE("iface %p.\n", iface);
2003 wined3d_mutex_unlock();
2006 static BOOL STDMETHODCALLTYPE d3d10_multithread_SetMultithreadProtected(ID3D10Multithread *iface, BOOL protect)
2008 FIXME("iface %p, protect %#x stub!\n", iface, protect);
2010 return TRUE;
2013 static BOOL STDMETHODCALLTYPE d3d10_multithread_GetMultithreadProtected(ID3D10Multithread *iface)
2015 FIXME("iface %p stub!\n", iface);
2017 return TRUE;
2020 static const struct ID3D10MultithreadVtbl d3d10_multithread_vtbl =
2022 d3d10_multithread_QueryInterface,
2023 d3d10_multithread_AddRef,
2024 d3d10_multithread_Release,
2025 d3d10_multithread_Enter,
2026 d3d10_multithread_Leave,
2027 d3d10_multithread_SetMultithreadProtected,
2028 d3d10_multithread_GetMultithreadProtected,
2031 static void STDMETHODCALLTYPE d3d10_subresource_destroyed(void *parent) {}
2033 static const struct wined3d_parent_ops d3d10_subresource_parent_ops =
2035 d3d10_subresource_destroyed,
2038 /* IWineDXGIDeviceParent IUnknown methods */
2040 static inline struct d3d10_device *device_from_dxgi_device_parent(IWineDXGIDeviceParent *iface)
2042 return CONTAINING_RECORD(iface, struct d3d10_device, IWineDXGIDeviceParent_iface);
2045 static HRESULT STDMETHODCALLTYPE dxgi_device_parent_QueryInterface(IWineDXGIDeviceParent *iface,
2046 REFIID riid, void **ppv)
2048 struct d3d10_device *device = device_from_dxgi_device_parent(iface);
2049 return IUnknown_QueryInterface(device->outer_unk, riid, ppv);
2052 static ULONG STDMETHODCALLTYPE dxgi_device_parent_AddRef(IWineDXGIDeviceParent *iface)
2054 struct d3d10_device *device = device_from_dxgi_device_parent(iface);
2055 return IUnknown_AddRef(device->outer_unk);
2058 static ULONG STDMETHODCALLTYPE dxgi_device_parent_Release(IWineDXGIDeviceParent *iface)
2060 struct d3d10_device *device = device_from_dxgi_device_parent(iface);
2061 return IUnknown_Release(device->outer_unk);
2064 static struct wined3d_device_parent * STDMETHODCALLTYPE dxgi_device_parent_get_wined3d_device_parent(
2065 IWineDXGIDeviceParent *iface)
2067 struct d3d10_device *device = device_from_dxgi_device_parent(iface);
2068 return &device->device_parent;
2071 static const struct IWineDXGIDeviceParentVtbl d3d10_dxgi_device_parent_vtbl =
2073 /* IUnknown methods */
2074 dxgi_device_parent_QueryInterface,
2075 dxgi_device_parent_AddRef,
2076 dxgi_device_parent_Release,
2077 /* IWineDXGIDeviceParent methods */
2078 dxgi_device_parent_get_wined3d_device_parent,
2081 static inline struct d3d10_device *device_from_wined3d_device_parent(struct wined3d_device_parent *device_parent)
2083 return CONTAINING_RECORD(device_parent, struct d3d10_device, device_parent);
2086 static void CDECL device_parent_wined3d_device_created(struct wined3d_device_parent *device_parent,
2087 struct wined3d_device *wined3d_device)
2089 struct d3d10_device *device = device_from_wined3d_device_parent(device_parent);
2091 TRACE("device_parent %p, wined3d_device %p.\n", device_parent, wined3d_device);
2093 wined3d_device_incref(wined3d_device);
2094 device->wined3d_device = wined3d_device;
2097 static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent)
2099 TRACE("device_parent %p.\n", device_parent);
2102 static void CDECL device_parent_activate(struct wined3d_device_parent *device_parent, BOOL activate)
2104 TRACE("device_parent %p, activate %#x.\n", device_parent, activate);
2107 static HRESULT CDECL device_parent_surface_created(struct wined3d_device_parent *device_parent,
2108 void *container_parent, struct wined3d_surface *surface, void **parent,
2109 const struct wined3d_parent_ops **parent_ops)
2111 TRACE("device_parent %p, container_parent %p, surface %p, parent %p, parent_ops %p.\n",
2112 device_parent, container_parent, surface, parent, parent_ops);
2114 *parent = container_parent;
2115 *parent_ops = &d3d10_null_wined3d_parent_ops;
2117 return S_OK;
2120 static HRESULT CDECL device_parent_volume_created(struct wined3d_device_parent *device_parent,
2121 void *container_parent, struct wined3d_volume *volume, void **parent,
2122 const struct wined3d_parent_ops **parent_ops)
2124 TRACE("device_parent %p, container_parent %p, volume %p, parent %p, parent_ops %p.\n",
2125 device_parent, container_parent, volume, parent, parent_ops);
2127 *parent = container_parent;
2128 *parent_ops = &d3d10_null_wined3d_parent_ops;
2130 return S_OK;
2133 static HRESULT CDECL device_parent_create_swapchain_surface(struct wined3d_device_parent *device_parent,
2134 void *container_parent, const struct wined3d_resource_desc *wined3d_desc, struct wined3d_surface **surface)
2136 struct d3d10_device *device = device_from_wined3d_device_parent(device_parent);
2137 struct wined3d_resource *sub_resource;
2138 struct d3d10_texture2d *texture;
2139 D3D10_TEXTURE2D_DESC desc;
2140 HRESULT hr;
2142 FIXME("device_parent %p, container_parent %p, wined3d_desc %p, surface %p partial stub!\n",
2143 device_parent, container_parent, wined3d_desc, surface);
2145 FIXME("Implement DXGI<->wined3d usage conversion\n");
2147 desc.Width = wined3d_desc->width;
2148 desc.Height = wined3d_desc->height;
2149 desc.MipLevels = 1;
2150 desc.ArraySize = 1;
2151 desc.Format = dxgi_format_from_wined3dformat(wined3d_desc->format);
2152 desc.SampleDesc.Count = wined3d_desc->multisample_type ? wined3d_desc->multisample_type : 1;
2153 desc.SampleDesc.Quality = wined3d_desc->multisample_quality;
2154 desc.Usage = D3D10_USAGE_DEFAULT;
2155 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2156 desc.CPUAccessFlags = 0;
2157 desc.MiscFlags = 0;
2159 if (FAILED(hr = d3d10_device_CreateTexture2D(&device->ID3D10Device1_iface,
2160 &desc, NULL, (ID3D10Texture2D **)&texture)))
2162 ERR("CreateTexture2D failed, returning %#x\n", hr);
2163 return hr;
2166 sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, 0);
2167 *surface = wined3d_surface_from_resource(sub_resource);
2168 wined3d_surface_incref(*surface);
2169 ID3D10Texture2D_Release(&texture->ID3D10Texture2D_iface);
2171 return S_OK;
2174 static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent *device_parent,
2175 struct wined3d_swapchain_desc *desc, struct wined3d_swapchain **swapchain)
2177 struct d3d10_device *device = device_from_wined3d_device_parent(device_parent);
2178 IWineDXGIDevice *wine_device;
2179 HRESULT hr;
2181 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent, desc, swapchain);
2183 if (FAILED(hr = d3d10_device_QueryInterface(&device->ID3D10Device1_iface,
2184 &IID_IWineDXGIDevice, (void **)&wine_device)))
2186 ERR("Device should implement IWineDXGIDevice.\n");
2187 return E_FAIL;
2190 hr = IWineDXGIDevice_create_swapchain(wine_device, desc, swapchain);
2191 IWineDXGIDevice_Release(wine_device);
2192 if (FAILED(hr))
2194 ERR("Failed to create DXGI swapchain, returning %#x\n", hr);
2195 return hr;
2198 return S_OK;
2201 static const struct wined3d_device_parent_ops d3d10_wined3d_device_parent_ops =
2203 device_parent_wined3d_device_created,
2204 device_parent_mode_changed,
2205 device_parent_activate,
2206 device_parent_surface_created,
2207 device_parent_volume_created,
2208 device_parent_create_swapchain_surface,
2209 device_parent_create_swapchain,
2212 static void *d3d10_rb_alloc(size_t size)
2214 return HeapAlloc(GetProcessHeap(), 0, size);
2217 static void *d3d10_rb_realloc(void *ptr, size_t size)
2219 return HeapReAlloc(GetProcessHeap(), 0, ptr, size);
2222 static void d3d10_rb_free(void *ptr)
2224 HeapFree(GetProcessHeap(), 0, ptr);
2227 static int d3d10_sampler_state_compare(const void *key, const struct wine_rb_entry *entry)
2229 const D3D10_SAMPLER_DESC *ka = key;
2230 const D3D10_SAMPLER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d10_sampler_state, entry)->desc;
2232 return memcmp(ka, kb, sizeof(*ka));
2235 static const struct wine_rb_functions d3d10_sampler_state_rb_ops =
2237 d3d10_rb_alloc,
2238 d3d10_rb_realloc,
2239 d3d10_rb_free,
2240 d3d10_sampler_state_compare,
2243 static int d3d10_blend_state_compare(const void *key, const struct wine_rb_entry *entry)
2245 const D3D10_BLEND_DESC *ka = key;
2246 const D3D10_BLEND_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d10_blend_state, entry)->desc;
2248 return memcmp(ka, kb, sizeof(*ka));
2251 static const struct wine_rb_functions d3d10_blend_state_rb_ops =
2253 d3d10_rb_alloc,
2254 d3d10_rb_realloc,
2255 d3d10_rb_free,
2256 d3d10_blend_state_compare,
2259 static int d3d10_depthstencil_state_compare(const void *key, const struct wine_rb_entry *entry)
2261 const D3D10_DEPTH_STENCIL_DESC *ka = key;
2262 const D3D10_DEPTH_STENCIL_DESC *kb = &WINE_RB_ENTRY_VALUE(entry,
2263 const struct d3d10_depthstencil_state, entry)->desc;
2265 return memcmp(ka, kb, sizeof(*ka));
2268 static const struct wine_rb_functions d3d10_depthstencil_state_rb_ops =
2270 d3d10_rb_alloc,
2271 d3d10_rb_realloc,
2272 d3d10_rb_free,
2273 d3d10_depthstencil_state_compare,
2276 static int d3d10_rasterizer_state_compare(const void *key, const struct wine_rb_entry *entry)
2278 const D3D10_RASTERIZER_DESC *ka = key;
2279 const D3D10_RASTERIZER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d10_rasterizer_state, entry)->desc;
2281 return memcmp(ka, kb, sizeof(*ka));
2284 static const struct wine_rb_functions d3d10_rasterizer_state_rb_ops =
2286 d3d10_rb_alloc,
2287 d3d10_rb_realloc,
2288 d3d10_rb_free,
2289 d3d10_rasterizer_state_compare,
2292 HRESULT d3d10_device_init(struct d3d10_device *device, void *outer_unknown)
2294 device->IUnknown_inner.lpVtbl = &d3d10_device_inner_unknown_vtbl;
2295 device->ID3D10Device1_iface.lpVtbl = &d3d10_device1_vtbl;
2296 device->ID3D10Multithread_iface.lpVtbl = &d3d10_multithread_vtbl;
2297 device->IWineDXGIDeviceParent_iface.lpVtbl = &d3d10_dxgi_device_parent_vtbl;
2298 device->device_parent.ops = &d3d10_wined3d_device_parent_ops;
2299 device->refcount = 1;
2300 /* COM aggregation always takes place */
2301 device->outer_unk = outer_unknown;
2303 if (wine_rb_init(&device->blend_states, &d3d10_blend_state_rb_ops) == -1)
2305 WARN("Failed to initialize blend state rbtree.\n");
2306 return E_FAIL;
2309 if (wine_rb_init(&device->depthstencil_states, &d3d10_depthstencil_state_rb_ops) == -1)
2311 WARN("Failed to initialize depthstencil state rbtree.\n");
2312 wine_rb_destroy(&device->blend_states, NULL, NULL);
2313 return E_FAIL;
2316 if (wine_rb_init(&device->rasterizer_states, &d3d10_rasterizer_state_rb_ops) == -1)
2318 WARN("Failed to initialize rasterizer state rbtree.\n");
2319 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
2320 wine_rb_destroy(&device->blend_states, NULL, NULL);
2321 return E_FAIL;
2324 if (wine_rb_init(&device->sampler_states, &d3d10_sampler_state_rb_ops) == -1)
2326 WARN("Failed to initialize sampler state rbtree.\n");
2327 wine_rb_destroy(&device->rasterizer_states, NULL, NULL);
2328 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
2329 wine_rb_destroy(&device->blend_states, NULL, NULL);
2330 return E_FAIL;
2333 return S_OK;