d3d10core: Implement d3d10_device_PSGetShaderResources().
[wine.git] / dlls / d3d10core / device.c
blobf8c9d37c855f607aa6a72bad5efcd16cfee09a5e
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 struct d3d10_device *device = impl_from_ID3D10Device(iface);
682 unsigned int i;
684 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
685 iface, start_slot, view_count, views);
687 for (i = 0; i < view_count; ++i)
689 struct wined3d_shader_resource_view *wined3d_view;
690 struct d3d10_shader_resource_view *view_impl;
692 if (!(wined3d_view = wined3d_device_get_ps_resource_view(device->wined3d_device, start_slot + i)))
694 views[i] = NULL;
695 continue;
698 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
699 views[i] = &view_impl->ID3D10ShaderResourceView_iface;
700 ID3D10ShaderResourceView_AddRef(views[i]);
704 static void STDMETHODCALLTYPE d3d10_device_PSGetShader(ID3D10Device1 *iface, ID3D10PixelShader **shader)
706 struct d3d10_device *device = impl_from_ID3D10Device(iface);
707 struct d3d10_pixel_shader *shader_impl;
708 struct wined3d_shader *wined3d_shader;
710 TRACE("iface %p, shader %p.\n", iface, shader);
712 if (!(wined3d_shader = wined3d_device_get_pixel_shader(device->wined3d_device)))
714 *shader = NULL;
715 return;
718 shader_impl = wined3d_shader_get_parent(wined3d_shader);
719 *shader = &shader_impl->ID3D10PixelShader_iface;
720 ID3D10PixelShader_AddRef(*shader);
723 static void STDMETHODCALLTYPE d3d10_device_PSGetSamplers(ID3D10Device1 *iface,
724 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
726 struct d3d10_device *device = impl_from_ID3D10Device(iface);
727 unsigned int i;
729 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
730 iface, start_slot, sampler_count, samplers);
732 for (i = 0; i < sampler_count; ++i)
734 struct d3d10_sampler_state *sampler_impl;
735 struct wined3d_sampler *wined3d_sampler;
737 if (!(wined3d_sampler = wined3d_device_get_ps_sampler(device->wined3d_device, start_slot + i)))
739 samplers[i] = NULL;
740 continue;
743 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
744 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
745 ID3D10SamplerState_AddRef(samplers[i]);
749 static void STDMETHODCALLTYPE d3d10_device_VSGetShader(ID3D10Device1 *iface, ID3D10VertexShader **shader)
751 struct d3d10_device *device = impl_from_ID3D10Device(iface);
752 struct d3d10_vertex_shader *shader_impl;
753 struct wined3d_shader *wined3d_shader;
755 TRACE("iface %p, shader %p.\n", iface, shader);
757 if (!(wined3d_shader = wined3d_device_get_vertex_shader(device->wined3d_device)))
759 *shader = NULL;
760 return;
763 shader_impl = wined3d_shader_get_parent(wined3d_shader);
764 *shader = &shader_impl->ID3D10VertexShader_iface;
765 ID3D10VertexShader_AddRef(*shader);
768 static void STDMETHODCALLTYPE d3d10_device_PSGetConstantBuffers(ID3D10Device1 *iface,
769 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
771 struct d3d10_device *device = impl_from_ID3D10Device(iface);
772 unsigned int i;
774 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
775 iface, start_slot, buffer_count, buffers);
777 for (i = 0; i < buffer_count; ++i)
779 struct wined3d_buffer *wined3d_buffer;
780 struct d3d10_buffer *buffer_impl;
782 if (!(wined3d_buffer = wined3d_device_get_ps_cb(device->wined3d_device, start_slot + i)))
784 buffers[i] = NULL;
785 continue;
788 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
789 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
790 ID3D10Buffer_AddRef(buffers[i]);
794 static void STDMETHODCALLTYPE d3d10_device_IAGetInputLayout(ID3D10Device1 *iface, ID3D10InputLayout **input_layout)
796 struct d3d10_device *device = impl_from_ID3D10Device(iface);
797 struct wined3d_vertex_declaration *wined3d_declaration;
798 struct d3d10_input_layout *input_layout_impl;
800 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
802 if (!(wined3d_declaration = wined3d_device_get_vertex_declaration(device->wined3d_device)))
804 *input_layout = NULL;
805 return;
808 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
809 *input_layout = &input_layout_impl->ID3D10InputLayout_iface;
810 ID3D10InputLayout_AddRef(*input_layout);
813 static void STDMETHODCALLTYPE d3d10_device_IAGetVertexBuffers(ID3D10Device1 *iface,
814 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers, UINT *strides, UINT *offsets)
816 struct d3d10_device *device = impl_from_ID3D10Device(iface);
817 unsigned int i;
819 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
820 iface, start_slot, buffer_count, buffers, strides, offsets);
822 for (i = 0; i < buffer_count; ++i)
824 struct wined3d_buffer *wined3d_buffer;
825 struct d3d10_buffer *buffer_impl;
827 if (FAILED(wined3d_device_get_stream_source(device->wined3d_device, start_slot + i,
828 &wined3d_buffer, &offsets[i], &strides[i])))
829 ERR("Failed to get vertex buffer.\n");
831 if (!wined3d_buffer)
833 buffers[i] = NULL;
834 continue;
837 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
838 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
839 ID3D10Buffer_AddRef(buffers[i]);
843 static void STDMETHODCALLTYPE d3d10_device_IAGetIndexBuffer(ID3D10Device1 *iface,
844 ID3D10Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
846 struct d3d10_device *device = impl_from_ID3D10Device(iface);
847 enum wined3d_format_id wined3d_format;
848 struct wined3d_buffer *wined3d_buffer;
849 struct d3d10_buffer *buffer_impl;
851 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
853 wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format);
854 *format = dxgi_format_from_wined3dformat(wined3d_format);
855 *offset = 0; /* FIXME */
856 if (!wined3d_buffer)
858 *buffer = NULL;
859 return;
862 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
863 *buffer = &buffer_impl->ID3D10Buffer_iface;
864 ID3D10Buffer_AddRef(*buffer);
867 static void STDMETHODCALLTYPE d3d10_device_GSGetConstantBuffers(ID3D10Device1 *iface,
868 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
870 struct d3d10_device *device = impl_from_ID3D10Device(iface);
871 unsigned int i;
873 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
874 iface, start_slot, buffer_count, buffers);
876 for (i = 0; i < buffer_count; ++i)
878 struct wined3d_buffer *wined3d_buffer;
879 struct d3d10_buffer *buffer_impl;
881 if (!(wined3d_buffer = wined3d_device_get_gs_cb(device->wined3d_device, start_slot + i)))
883 buffers[i] = NULL;
884 continue;
887 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
888 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
889 ID3D10Buffer_AddRef(buffers[i]);
893 static void STDMETHODCALLTYPE d3d10_device_GSGetShader(ID3D10Device1 *iface, ID3D10GeometryShader **shader)
895 struct d3d10_device *device = impl_from_ID3D10Device(iface);
896 struct d3d10_geometry_shader *shader_impl;
897 struct wined3d_shader *wined3d_shader;
899 TRACE("iface %p, shader %p.\n", iface, shader);
901 if (!(wined3d_shader = wined3d_device_get_geometry_shader(device->wined3d_device)))
903 *shader = NULL;
904 return;
907 shader_impl = wined3d_shader_get_parent(wined3d_shader);
908 *shader = &shader_impl->ID3D10GeometryShader_iface;
909 ID3D10GeometryShader_AddRef(*shader);
912 static void STDMETHODCALLTYPE d3d10_device_IAGetPrimitiveTopology(ID3D10Device1 *iface,
913 D3D10_PRIMITIVE_TOPOLOGY *topology)
915 struct d3d10_device *This = impl_from_ID3D10Device(iface);
917 TRACE("iface %p, topology %p\n", iface, topology);
919 wined3d_device_get_primitive_type(This->wined3d_device, (enum wined3d_primitive_type *)topology);
922 static void STDMETHODCALLTYPE d3d10_device_VSGetShaderResources(ID3D10Device1 *iface,
923 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
925 struct d3d10_device *device = impl_from_ID3D10Device(iface);
926 unsigned int i;
928 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
929 iface, start_slot, view_count, views);
931 for (i = 0; i < view_count; ++i)
933 struct wined3d_shader_resource_view *wined3d_view;
934 struct d3d10_shader_resource_view *view_impl;
936 if (!(wined3d_view = wined3d_device_get_vs_resource_view(device->wined3d_device, start_slot + i)))
938 views[i] = NULL;
939 continue;
942 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
943 views[i] = &view_impl->ID3D10ShaderResourceView_iface;
944 ID3D10ShaderResourceView_AddRef(views[i]);
948 static void STDMETHODCALLTYPE d3d10_device_VSGetSamplers(ID3D10Device1 *iface,
949 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
951 struct d3d10_device *device = impl_from_ID3D10Device(iface);
952 unsigned int i;
954 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
955 iface, start_slot, sampler_count, samplers);
957 for (i = 0; i < sampler_count; ++i)
959 struct d3d10_sampler_state *sampler_impl;
960 struct wined3d_sampler *wined3d_sampler;
962 if (!(wined3d_sampler = wined3d_device_get_vs_sampler(device->wined3d_device, start_slot + i)))
964 samplers[i] = NULL;
965 continue;
968 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
969 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
970 ID3D10SamplerState_AddRef(samplers[i]);
974 static void STDMETHODCALLTYPE d3d10_device_GetPredication(ID3D10Device1 *iface,
975 ID3D10Predicate **predicate, BOOL *value)
977 FIXME("iface %p, predicate %p, value %p stub!\n", iface, predicate, value);
980 static void STDMETHODCALLTYPE d3d10_device_GSGetShaderResources(ID3D10Device1 *iface,
981 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
983 struct d3d10_device *device = impl_from_ID3D10Device(iface);
984 unsigned int i;
986 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
987 iface, start_slot, view_count, views);
989 for (i = 0; i < view_count; ++i)
991 struct wined3d_shader_resource_view *wined3d_view;
992 struct d3d10_shader_resource_view *view_impl;
994 if (!(wined3d_view = wined3d_device_get_gs_resource_view(device->wined3d_device, start_slot + i)))
996 views[i] = NULL;
997 continue;
1000 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1001 views[i] = &view_impl->ID3D10ShaderResourceView_iface;
1002 ID3D10ShaderResourceView_AddRef(views[i]);
1006 static void STDMETHODCALLTYPE d3d10_device_GSGetSamplers(ID3D10Device1 *iface,
1007 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
1009 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1010 unsigned int i;
1012 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1013 iface, start_slot, sampler_count, samplers);
1015 for (i = 0; i < sampler_count; ++i)
1017 struct d3d10_sampler_state *sampler_impl;
1018 struct wined3d_sampler *wined3d_sampler;
1020 if (!(wined3d_sampler = wined3d_device_get_gs_sampler(device->wined3d_device, start_slot + i)))
1022 samplers[i] = NULL;
1023 continue;
1026 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1027 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
1028 ID3D10SamplerState_AddRef(samplers[i]);
1032 static void STDMETHODCALLTYPE d3d10_device_OMGetRenderTargets(ID3D10Device1 *iface,
1033 UINT view_count, ID3D10RenderTargetView **render_target_views, ID3D10DepthStencilView **depth_stencil_view)
1035 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1036 struct wined3d_rendertarget_view *wined3d_view;
1038 TRACE("iface %p, view_count %u, render_target_views %p, depth_stencil_view %p.\n",
1039 iface, view_count, render_target_views, depth_stencil_view);
1041 if (render_target_views)
1043 struct d3d10_rendertarget_view *view_impl;
1044 unsigned int i;
1046 for (i = 0; i < view_count; ++i)
1048 if (!(wined3d_view = wined3d_device_get_rendertarget_view(device->wined3d_device, i))
1049 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
1051 render_target_views[i] = NULL;
1052 continue;
1055 render_target_views[i] = &view_impl->ID3D10RenderTargetView_iface;
1056 ID3D10RenderTargetView_AddRef(render_target_views[i]);
1060 if (depth_stencil_view)
1062 struct d3d10_depthstencil_view *view_impl;
1064 if (!(wined3d_view = wined3d_device_get_depth_stencil_view(device->wined3d_device))
1065 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
1067 *depth_stencil_view = NULL;
1069 else
1071 *depth_stencil_view = &view_impl->ID3D10DepthStencilView_iface;
1072 ID3D10DepthStencilView_AddRef(*depth_stencil_view);
1077 static void STDMETHODCALLTYPE d3d10_device_OMGetBlendState(ID3D10Device1 *iface,
1078 ID3D10BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
1080 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1082 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
1083 iface, blend_state, blend_factor, sample_mask);
1085 if ((*blend_state = device->blend_state ? &device->blend_state->ID3D10BlendState_iface : NULL))
1086 ID3D10BlendState_AddRef(*blend_state);
1087 memcpy(blend_factor, device->blend_factor, 4 * sizeof(*blend_factor));
1088 *sample_mask = device->sample_mask;
1091 static void STDMETHODCALLTYPE d3d10_device_OMGetDepthStencilState(ID3D10Device1 *iface,
1092 ID3D10DepthStencilState **depth_stencil_state, UINT *stencil_ref)
1094 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1096 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
1097 iface, depth_stencil_state, stencil_ref);
1099 if ((*depth_stencil_state = device->depth_stencil_state
1100 ? &device->depth_stencil_state->ID3D10DepthStencilState_iface : NULL))
1101 ID3D10DepthStencilState_AddRef(*depth_stencil_state);
1102 *stencil_ref = device->stencil_ref;
1105 static void STDMETHODCALLTYPE d3d10_device_SOGetTargets(ID3D10Device1 *iface,
1106 UINT buffer_count, ID3D10Buffer **buffers, UINT *offsets)
1108 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1109 unsigned int i;
1111 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n",
1112 iface, buffer_count, buffers, offsets);
1114 for (i = 0; i < buffer_count; ++i)
1116 struct wined3d_buffer *wined3d_buffer;
1117 struct d3d10_buffer *buffer_impl;
1119 if (!(wined3d_buffer = wined3d_device_get_stream_output(device->wined3d_device, i, &offsets[i])))
1121 buffers[i] = NULL;
1122 continue;
1125 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1126 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
1127 ID3D10Buffer_AddRef(buffers[i]);
1131 static void STDMETHODCALLTYPE d3d10_device_RSGetState(ID3D10Device1 *iface, ID3D10RasterizerState **rasterizer_state)
1133 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1135 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
1137 if ((*rasterizer_state = device->rasterizer_state ? &device->rasterizer_state->ID3D10RasterizerState_iface : NULL))
1138 ID3D10RasterizerState_AddRef(*rasterizer_state);
1141 static void STDMETHODCALLTYPE d3d10_device_RSGetViewports(ID3D10Device1 *iface,
1142 UINT *viewport_count, D3D10_VIEWPORT *viewports)
1144 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1145 struct wined3d_viewport wined3d_vp;
1147 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
1149 if (!viewports)
1151 *viewport_count = 1;
1152 return;
1155 if (!*viewport_count)
1156 return;
1158 wined3d_device_get_viewport(device->wined3d_device, &wined3d_vp);
1160 viewports[0].TopLeftX = wined3d_vp.x;
1161 viewports[0].TopLeftY = wined3d_vp.y;
1162 viewports[0].Width = wined3d_vp.width;
1163 viewports[0].Height = wined3d_vp.height;
1164 viewports[0].MinDepth = wined3d_vp.min_z;
1165 viewports[0].MaxDepth = wined3d_vp.max_z;
1167 if (*viewport_count > 1)
1168 memset(&viewports[1], 0, (*viewport_count - 1) * sizeof(*viewports));
1171 static void STDMETHODCALLTYPE d3d10_device_RSGetScissorRects(ID3D10Device1 *iface, UINT *rect_count, D3D10_RECT *rects)
1173 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1175 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
1177 if (!rects)
1179 *rect_count = 1;
1180 return;
1183 if (!*rect_count)
1184 return;
1186 wined3d_device_get_scissor_rect(device->wined3d_device, rects);
1187 if (*rect_count > 1)
1188 memset(&rects[1], 0, (*rect_count - 1) * sizeof(*rects));
1191 static HRESULT STDMETHODCALLTYPE d3d10_device_GetDeviceRemovedReason(ID3D10Device1 *iface)
1193 TRACE("iface %p.\n", iface);
1195 /* In the current implementation the device is never removed, so we can
1196 * just return S_OK here. */
1198 return S_OK;
1201 static HRESULT STDMETHODCALLTYPE d3d10_device_SetExceptionMode(ID3D10Device1 *iface, UINT flags)
1203 FIXME("iface %p, flags %#x stub!\n", iface, flags);
1205 return E_NOTIMPL;
1208 static UINT STDMETHODCALLTYPE d3d10_device_GetExceptionMode(ID3D10Device1 *iface)
1210 FIXME("iface %p stub!\n", iface);
1212 return 0;
1215 static HRESULT STDMETHODCALLTYPE d3d10_device_GetPrivateData(ID3D10Device1 *iface,
1216 REFGUID guid, UINT *data_size, void *data)
1218 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
1219 iface, debugstr_guid(guid), data_size, data);
1221 return E_NOTIMPL;
1224 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateData(ID3D10Device1 *iface,
1225 REFGUID guid, UINT data_size, const void *data)
1227 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
1228 iface, debugstr_guid(guid), data_size, data);
1230 return E_NOTIMPL;
1233 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateDataInterface(ID3D10Device1 *iface,
1234 REFGUID guid, const IUnknown *data)
1236 FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
1238 return E_NOTIMPL;
1241 static void STDMETHODCALLTYPE d3d10_device_ClearState(ID3D10Device1 *iface)
1243 FIXME("iface %p stub!\n", iface);
1246 static void STDMETHODCALLTYPE d3d10_device_Flush(ID3D10Device1 *iface)
1248 FIXME("iface %p stub!\n", iface);
1251 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBuffer(ID3D10Device1 *iface,
1252 const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Buffer **buffer)
1254 struct d3d10_device *This = impl_from_ID3D10Device(iface);
1255 struct d3d10_buffer *object;
1256 HRESULT hr;
1258 FIXME("iface %p, desc %p, data %p, buffer %p partial stub!\n", iface, desc, data, buffer);
1260 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1261 if (!object)
1262 return E_OUTOFMEMORY;
1264 hr = d3d10_buffer_init(object, This, desc, data);
1265 if (FAILED(hr))
1267 WARN("Failed to initialize buffer, hr %#x.\n", hr);
1268 HeapFree(GetProcessHeap(), 0, object);
1269 return hr;
1272 *buffer = &object->ID3D10Buffer_iface;
1274 TRACE("Created ID3D10Buffer %p\n", object);
1276 return S_OK;
1279 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture1D(ID3D10Device1 *iface,
1280 const D3D10_TEXTURE1D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Texture1D **texture)
1282 FIXME("iface %p, desc %p, data %p, texture %p stub!\n", iface, desc, data, texture);
1284 return E_NOTIMPL;
1287 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture2D(ID3D10Device1 *iface,
1288 const D3D10_TEXTURE2D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
1289 ID3D10Texture2D **texture)
1291 struct d3d10_device *This = impl_from_ID3D10Device(iface);
1292 struct d3d10_texture2d *object;
1293 HRESULT hr;
1295 FIXME("iface %p, desc %p, data %p, texture %p partial stub!\n", iface, desc, data, texture);
1297 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1298 if (!object)
1299 return E_OUTOFMEMORY;
1301 hr = d3d10_texture2d_init(object, This, desc);
1302 if (FAILED(hr))
1304 WARN("Failed to initialize texture, hr %#x.\n", hr);
1305 HeapFree(GetProcessHeap(), 0, object);
1306 return hr;
1309 *texture = &object->ID3D10Texture2D_iface;
1311 TRACE("Created ID3D10Texture2D %p\n", object);
1313 return S_OK;
1316 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture3D(ID3D10Device1 *iface,
1317 const D3D10_TEXTURE3D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
1318 ID3D10Texture3D **texture)
1320 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1321 struct d3d10_texture3d *object;
1322 HRESULT hr;
1324 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
1326 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1327 if (!object)
1328 return E_OUTOFMEMORY;
1330 hr = d3d10_texture3d_init(object, device, desc);
1331 if (FAILED(hr))
1333 WARN("Failed to initialize texture, hr %#x.\n", hr);
1334 HeapFree(GetProcessHeap(), 0, object);
1335 return hr;
1338 TRACE("Created 3D texture %p.\n", object);
1339 *texture = &object->ID3D10Texture3D_iface;
1341 return S_OK;
1344 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView(ID3D10Device1 *iface,
1345 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC *desc, ID3D10ShaderResourceView **view)
1347 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1348 struct d3d10_shader_resource_view *object;
1349 HRESULT hr;
1351 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
1353 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
1354 return E_OUTOFMEMORY;
1356 if (FAILED(hr = d3d10_shader_resource_view_init(object, device, resource, desc)))
1358 WARN("Failed to initialize shader resource view, hr %#x.\n", hr);
1359 HeapFree(GetProcessHeap(), 0, object);
1360 return hr;
1363 TRACE("Created shader resource view %p.\n", object);
1364 *view = &object->ID3D10ShaderResourceView_iface;
1366 return S_OK;
1369 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRenderTargetView(ID3D10Device1 *iface,
1370 ID3D10Resource *resource, const D3D10_RENDER_TARGET_VIEW_DESC *desc, ID3D10RenderTargetView **view)
1372 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1373 struct d3d10_rendertarget_view *object;
1374 HRESULT hr;
1376 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
1378 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
1379 return E_OUTOFMEMORY;
1381 if (FAILED(hr = d3d10_rendertarget_view_init(object, device, resource, desc)))
1383 WARN("Failed to initialize rendertarget view, hr %#x.\n", hr);
1384 HeapFree(GetProcessHeap(), 0, object);
1385 return hr;
1388 TRACE("Created rendertarget view %p.\n", object);
1389 *view = &object->ID3D10RenderTargetView_iface;
1391 return S_OK;
1394 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilView(ID3D10Device1 *iface,
1395 ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3D10DepthStencilView **view)
1397 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1398 struct d3d10_depthstencil_view *object;
1399 HRESULT hr;
1401 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
1403 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
1404 return E_OUTOFMEMORY;
1406 if (FAILED(hr = d3d10_depthstencil_view_init(object, device, resource, desc)))
1408 WARN("Failed to initialize depthstencil view, hr %#x.\n", hr);
1409 HeapFree(GetProcessHeap(), 0, object);
1410 return hr;
1413 TRACE("Created depthstencil view %p.\n", object);
1414 *view = &object->ID3D10DepthStencilView_iface;
1416 return S_OK;
1419 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateInputLayout(ID3D10Device1 *iface,
1420 const D3D10_INPUT_ELEMENT_DESC *element_descs, UINT element_count,
1421 const void *shader_byte_code, SIZE_T shader_byte_code_length,
1422 ID3D10InputLayout **input_layout)
1424 struct d3d10_device *This = impl_from_ID3D10Device(iface);
1425 struct d3d10_input_layout *object;
1426 HRESULT hr;
1428 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p,"
1429 "\tshader_byte_code_length %lu, input_layout %p\n",
1430 iface, element_descs, element_count, shader_byte_code,
1431 shader_byte_code_length, input_layout);
1433 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1434 if (!object)
1435 return E_OUTOFMEMORY;
1437 hr = d3d10_input_layout_init(object, This, element_descs, element_count,
1438 shader_byte_code, shader_byte_code_length);
1439 if (FAILED(hr))
1441 WARN("Failed to initialize input layout, hr %#x.\n", hr);
1442 HeapFree(GetProcessHeap(), 0, object);
1443 return hr;
1446 TRACE("Created input layout %p.\n", object);
1447 *input_layout = &object->ID3D10InputLayout_iface;
1449 return S_OK;
1452 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateVertexShader(ID3D10Device1 *iface,
1453 const void *byte_code, SIZE_T byte_code_length, ID3D10VertexShader **shader)
1455 struct d3d10_device *This = impl_from_ID3D10Device(iface);
1456 struct d3d10_vertex_shader *object;
1457 HRESULT hr;
1459 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p\n",
1460 iface, byte_code, byte_code_length, shader);
1462 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1463 if (!object)
1464 return E_OUTOFMEMORY;
1466 hr = d3d10_vertex_shader_init(object, This, byte_code, byte_code_length);
1467 if (FAILED(hr))
1469 WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
1470 HeapFree(GetProcessHeap(), 0, object);
1471 return hr;
1474 TRACE("Created vertex shader %p.\n", object);
1475 *shader = &object->ID3D10VertexShader_iface;
1477 return S_OK;
1480 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShader(ID3D10Device1 *iface,
1481 const void *byte_code, SIZE_T byte_code_length, ID3D10GeometryShader **shader)
1483 struct d3d10_device *This = impl_from_ID3D10Device(iface);
1484 struct d3d10_geometry_shader *object;
1485 HRESULT hr;
1487 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
1488 iface, byte_code, byte_code_length, shader);
1490 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1491 if (!object)
1492 return E_OUTOFMEMORY;
1494 hr = d3d10_geometry_shader_init(object, This, byte_code, byte_code_length);
1495 if (FAILED(hr))
1497 WARN("Failed to initialize geometry shader, hr %#x.\n", hr);
1498 HeapFree(GetProcessHeap(), 0, object);
1499 return hr;
1502 TRACE("Created geometry shader %p.\n", object);
1503 *shader = &object->ID3D10GeometryShader_iface;
1505 return S_OK;
1508 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShaderWithStreamOutput(ID3D10Device1 *iface,
1509 const void *byte_code, SIZE_T byte_code_length, const D3D10_SO_DECLARATION_ENTRY *output_stream_decls,
1510 UINT output_stream_decl_count, UINT output_stream_stride, ID3D10GeometryShader **shader)
1512 FIXME("iface %p, byte_code %p, byte_code_length %lu, output_stream_decls %p,\n"
1513 "\toutput_stream_decl_count %u, output_stream_stride %u, shader %p stub!\n",
1514 iface, byte_code, byte_code_length, output_stream_decls,
1515 output_stream_decl_count, output_stream_stride, shader);
1517 return E_NOTIMPL;
1520 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePixelShader(ID3D10Device1 *iface,
1521 const void *byte_code, SIZE_T byte_code_length, ID3D10PixelShader **shader)
1523 struct d3d10_device *This = impl_from_ID3D10Device(iface);
1524 struct d3d10_pixel_shader *object;
1525 HRESULT hr;
1527 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p\n",
1528 iface, byte_code, byte_code_length, shader);
1530 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1531 if (!object)
1532 return E_OUTOFMEMORY;
1534 hr = d3d10_pixel_shader_init(object, This, byte_code, byte_code_length);
1535 if (FAILED(hr))
1537 WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
1538 HeapFree(GetProcessHeap(), 0, object);
1539 return hr;
1542 TRACE("Created pixel shader %p.\n", object);
1543 *shader = &object->ID3D10PixelShader_iface;
1545 return S_OK;
1548 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState(ID3D10Device1 *iface,
1549 const D3D10_BLEND_DESC *desc, ID3D10BlendState **blend_state)
1551 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1552 struct d3d10_blend_state *object;
1553 struct wine_rb_entry *entry;
1554 HRESULT hr;
1556 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
1558 if (!desc)
1559 return E_INVALIDARG;
1561 if ((entry = wine_rb_get(&device->blend_states, desc)))
1563 object = WINE_RB_ENTRY_VALUE(entry, struct d3d10_blend_state, entry);
1565 TRACE("Returning existing blend state %p.\n", object);
1566 *blend_state = &object->ID3D10BlendState_iface;
1567 ID3D10BlendState_AddRef(*blend_state);
1569 return S_OK;
1572 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1573 if (!object)
1574 return E_OUTOFMEMORY;
1576 if (FAILED(hr = d3d10_blend_state_init(object, device, desc)))
1578 WARN("Failed to initialize blend state, hr %#x.\n", hr);
1579 HeapFree(GetProcessHeap(), 0, object);
1580 return hr;
1583 TRACE("Created blend state %p.\n", object);
1584 *blend_state = &object->ID3D10BlendState_iface;
1586 return S_OK;
1589 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilState(ID3D10Device1 *iface,
1590 const D3D10_DEPTH_STENCIL_DESC *desc, ID3D10DepthStencilState **depth_stencil_state)
1592 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1593 struct d3d10_depthstencil_state *object;
1594 struct wine_rb_entry *entry;
1595 HRESULT hr;
1597 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
1599 if (!desc)
1600 return E_INVALIDARG;
1602 if ((entry = wine_rb_get(&device->depthstencil_states, desc)))
1604 object = WINE_RB_ENTRY_VALUE(entry, struct d3d10_depthstencil_state, entry);
1606 TRACE("Returning existing depthstencil state %p.\n", object);
1607 *depth_stencil_state = &object->ID3D10DepthStencilState_iface;
1608 ID3D10DepthStencilState_AddRef(*depth_stencil_state);
1610 return S_OK;
1613 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1614 if (!object)
1615 return E_OUTOFMEMORY;
1617 if (FAILED(hr = d3d10_depthstencil_state_init(object, device, desc)))
1619 WARN("Failed to initialize depthstencil state, hr %#x.\n", hr);
1620 HeapFree(GetProcessHeap(), 0, object);
1621 return hr;
1624 TRACE("Created depthstencil state %p.\n", object);
1625 *depth_stencil_state = &object->ID3D10DepthStencilState_iface;
1627 return S_OK;
1630 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRasterizerState(ID3D10Device1 *iface,
1631 const D3D10_RASTERIZER_DESC *desc, ID3D10RasterizerState **rasterizer_state)
1633 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1634 struct d3d10_rasterizer_state *object;
1635 struct wine_rb_entry *entry;
1636 HRESULT hr;
1638 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
1640 if (!desc)
1641 return E_INVALIDARG;
1643 if ((entry = wine_rb_get(&device->rasterizer_states, desc)))
1645 object = WINE_RB_ENTRY_VALUE(entry, struct d3d10_rasterizer_state, entry);
1647 TRACE("Returning existing rasterizer state %p.\n", object);
1648 *rasterizer_state = &object->ID3D10RasterizerState_iface;
1649 ID3D10RasterizerState_AddRef(*rasterizer_state);
1651 return S_OK;
1655 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1656 if (!object)
1657 return E_OUTOFMEMORY;
1659 if (FAILED(hr = d3d10_rasterizer_state_init(object, device, desc)))
1661 WARN("Failed to initialize rasterizer state, hr %#x.\n", hr);
1662 HeapFree(GetProcessHeap(), 0, object);
1663 return hr;
1666 TRACE("Created rasterizer state %p.\n", object);
1667 *rasterizer_state = &object->ID3D10RasterizerState_iface;
1669 return S_OK;
1672 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateSamplerState(ID3D10Device1 *iface,
1673 const D3D10_SAMPLER_DESC *desc, ID3D10SamplerState **sampler_state)
1675 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1676 struct d3d10_sampler_state *object;
1677 struct wine_rb_entry *entry;
1678 HRESULT hr;
1680 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
1682 if (!desc)
1683 return E_INVALIDARG;
1685 if ((entry = wine_rb_get(&device->sampler_states, desc)))
1687 object = WINE_RB_ENTRY_VALUE(entry, struct d3d10_sampler_state, entry);
1689 TRACE("Returning existing sampler state %p.\n", object);
1690 *sampler_state = &object->ID3D10SamplerState_iface;
1691 ID3D10SamplerState_AddRef(*sampler_state);
1693 return S_OK;
1696 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1697 if (!object)
1698 return E_OUTOFMEMORY;
1700 if (FAILED(hr = d3d10_sampler_state_init(object, device, desc)))
1702 WARN("Failed to initialize sampler state, hr %#x.\n", hr);
1703 HeapFree(GetProcessHeap(), 0, object);
1704 return hr;
1707 TRACE("Created sampler state %p.\n", object);
1708 *sampler_state = &object->ID3D10SamplerState_iface;
1710 return S_OK;
1713 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateQuery(ID3D10Device1 *iface,
1714 const D3D10_QUERY_DESC *desc, ID3D10Query **query)
1716 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1717 struct d3d10_query *object;
1718 HRESULT hr;
1720 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
1722 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
1723 return E_OUTOFMEMORY;
1725 if (FAILED(hr = d3d10_query_init(object, device, FALSE)))
1727 WARN("Failed to initialize query, hr %#x.\n", hr);
1728 HeapFree(GetProcessHeap(), 0, object);
1729 return hr;
1732 TRACE("Created query %p.\n", object);
1733 *query = &object->ID3D10Query_iface;
1735 return S_OK;
1738 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePredicate(ID3D10Device1 *iface,
1739 const D3D10_QUERY_DESC *desc, ID3D10Predicate **predicate)
1741 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1742 struct d3d10_query *object;
1743 HRESULT hr;
1745 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
1747 if (!desc)
1748 return E_INVALIDARG;
1750 if (desc->Query != D3D10_QUERY_OCCLUSION_PREDICATE && desc->Query != D3D10_QUERY_SO_OVERFLOW_PREDICATE)
1752 WARN("Query type %#x is not a predicate.\n", desc->Query);
1753 return E_INVALIDARG;
1756 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
1757 return E_OUTOFMEMORY;
1759 if (FAILED(hr = d3d10_query_init(object, device, TRUE)))
1761 WARN("Failed to initialize predicate, hr %#x.\n", hr);
1762 HeapFree(GetProcessHeap(), 0, object);
1763 return hr;
1766 TRACE("Created predicate %p.\n", object);
1767 *predicate = (ID3D10Predicate *)&object->ID3D10Query_iface;
1769 return S_OK;
1772 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateCounter(ID3D10Device1 *iface,
1773 const D3D10_COUNTER_DESC *desc, ID3D10Counter **counter)
1775 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
1777 return E_NOTIMPL;
1780 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckFormatSupport(ID3D10Device1 *iface,
1781 DXGI_FORMAT format, UINT *format_support)
1783 FIXME("iface %p, format %s, format_support %p stub!\n",
1784 iface, debug_dxgi_format(format), format_support);
1786 return E_NOTIMPL;
1789 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckMultisampleQualityLevels(ID3D10Device1 *iface,
1790 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
1792 FIXME("iface %p, format %s, sample_count %u, quality_level_count %p stub!\n",
1793 iface, debug_dxgi_format(format), sample_count, quality_level_count);
1795 return E_NOTIMPL;
1798 static void STDMETHODCALLTYPE d3d10_device_CheckCounterInfo(ID3D10Device1 *iface, D3D10_COUNTER_INFO *counter_info)
1800 FIXME("iface %p, counter_info %p stub!\n", iface, counter_info);
1803 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckCounter(ID3D10Device1 *iface,
1804 const D3D10_COUNTER_DESC *desc, D3D10_COUNTER_TYPE *type, UINT *active_counters, char *name,
1805 UINT *name_length, char *units, UINT *units_length, char *description, UINT *description_length)
1807 FIXME("iface %p, desc %p, type %p, active_counters %p, name %p, name_length %p,\n"
1808 "\tunits %p, units_length %p, description %p, description_length %p stub!\n",
1809 iface, desc, type, active_counters, name, name_length,
1810 units, units_length, description, description_length);
1812 return E_NOTIMPL;
1815 static UINT STDMETHODCALLTYPE d3d10_device_GetCreationFlags(ID3D10Device1 *iface)
1817 FIXME("iface %p stub!\n", iface);
1819 return 0;
1822 static HRESULT STDMETHODCALLTYPE d3d10_device_OpenSharedResource(ID3D10Device1 *iface,
1823 HANDLE resource_handle, REFIID guid, void **resource)
1825 FIXME("iface %p, resource_handle %p, guid %s, resource %p stub!\n",
1826 iface, resource_handle, debugstr_guid(guid), resource);
1828 return E_NOTIMPL;
1831 static void STDMETHODCALLTYPE d3d10_device_SetTextFilterSize(ID3D10Device1 *iface, UINT width, UINT height)
1833 FIXME("iface %p, width %u, height %u stub!\n", iface, width, height);
1836 static void STDMETHODCALLTYPE d3d10_device_GetTextFilterSize(ID3D10Device1 *iface, UINT *width, UINT *height)
1838 FIXME("iface %p, width %p, height %p stub!\n", iface, width, height);
1841 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView1(ID3D10Device1 *iface,
1842 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC1 *desc, ID3D10ShaderResourceView1 **view)
1844 FIXME("iface %p, resource %p, desc %p, view %p stub!\n", iface, resource, desc, view);
1846 return E_NOTIMPL;
1849 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState1(ID3D10Device1 *iface,
1850 const D3D10_BLEND_DESC1 *desc, ID3D10BlendState1 **blend_state)
1852 FIXME("iface %p, desc %p, blend_state %p stub!\n", iface, desc, blend_state);
1854 return E_NOTIMPL;
1857 static D3D10_FEATURE_LEVEL1 STDMETHODCALLTYPE d3d10_device_GetFeatureLevel(ID3D10Device1 *iface)
1859 FIXME("iface %p stub!\n", iface);
1861 return D3D10_FEATURE_LEVEL_10_1;
1864 static const struct ID3D10Device1Vtbl d3d10_device1_vtbl =
1866 /* IUnknown methods */
1867 d3d10_device_QueryInterface,
1868 d3d10_device_AddRef,
1869 d3d10_device_Release,
1870 /* ID3D10Device methods */
1871 d3d10_device_VSSetConstantBuffers,
1872 d3d10_device_PSSetShaderResources,
1873 d3d10_device_PSSetShader,
1874 d3d10_device_PSSetSamplers,
1875 d3d10_device_VSSetShader,
1876 d3d10_device_DrawIndexed,
1877 d3d10_device_Draw,
1878 d3d10_device_PSSetConstantBuffers,
1879 d3d10_device_IASetInputLayout,
1880 d3d10_device_IASetVertexBuffers,
1881 d3d10_device_IASetIndexBuffer,
1882 d3d10_device_DrawIndexedInstanced,
1883 d3d10_device_DrawInstanced,
1884 d3d10_device_GSSetConstantBuffers,
1885 d3d10_device_GSSetShader,
1886 d3d10_device_IASetPrimitiveTopology,
1887 d3d10_device_VSSetShaderResources,
1888 d3d10_device_VSSetSamplers,
1889 d3d10_device_SetPredication,
1890 d3d10_device_GSSetShaderResources,
1891 d3d10_device_GSSetSamplers,
1892 d3d10_device_OMSetRenderTargets,
1893 d3d10_device_OMSetBlendState,
1894 d3d10_device_OMSetDepthStencilState,
1895 d3d10_device_SOSetTargets,
1896 d3d10_device_DrawAuto,
1897 d3d10_device_RSSetState,
1898 d3d10_device_RSSetViewports,
1899 d3d10_device_RSSetScissorRects,
1900 d3d10_device_CopySubresourceRegion,
1901 d3d10_device_CopyResource,
1902 d3d10_device_UpdateSubresource,
1903 d3d10_device_ClearRenderTargetView,
1904 d3d10_device_ClearDepthStencilView,
1905 d3d10_device_GenerateMips,
1906 d3d10_device_ResolveSubresource,
1907 d3d10_device_VSGetConstantBuffers,
1908 d3d10_device_PSGetShaderResources,
1909 d3d10_device_PSGetShader,
1910 d3d10_device_PSGetSamplers,
1911 d3d10_device_VSGetShader,
1912 d3d10_device_PSGetConstantBuffers,
1913 d3d10_device_IAGetInputLayout,
1914 d3d10_device_IAGetVertexBuffers,
1915 d3d10_device_IAGetIndexBuffer,
1916 d3d10_device_GSGetConstantBuffers,
1917 d3d10_device_GSGetShader,
1918 d3d10_device_IAGetPrimitiveTopology,
1919 d3d10_device_VSGetShaderResources,
1920 d3d10_device_VSGetSamplers,
1921 d3d10_device_GetPredication,
1922 d3d10_device_GSGetShaderResources,
1923 d3d10_device_GSGetSamplers,
1924 d3d10_device_OMGetRenderTargets,
1925 d3d10_device_OMGetBlendState,
1926 d3d10_device_OMGetDepthStencilState,
1927 d3d10_device_SOGetTargets,
1928 d3d10_device_RSGetState,
1929 d3d10_device_RSGetViewports,
1930 d3d10_device_RSGetScissorRects,
1931 d3d10_device_GetDeviceRemovedReason,
1932 d3d10_device_SetExceptionMode,
1933 d3d10_device_GetExceptionMode,
1934 d3d10_device_GetPrivateData,
1935 d3d10_device_SetPrivateData,
1936 d3d10_device_SetPrivateDataInterface,
1937 d3d10_device_ClearState,
1938 d3d10_device_Flush,
1939 d3d10_device_CreateBuffer,
1940 d3d10_device_CreateTexture1D,
1941 d3d10_device_CreateTexture2D,
1942 d3d10_device_CreateTexture3D,
1943 d3d10_device_CreateShaderResourceView,
1944 d3d10_device_CreateRenderTargetView,
1945 d3d10_device_CreateDepthStencilView,
1946 d3d10_device_CreateInputLayout,
1947 d3d10_device_CreateVertexShader,
1948 d3d10_device_CreateGeometryShader,
1949 d3d10_device_CreateGeometryShaderWithStreamOutput,
1950 d3d10_device_CreatePixelShader,
1951 d3d10_device_CreateBlendState,
1952 d3d10_device_CreateDepthStencilState,
1953 d3d10_device_CreateRasterizerState,
1954 d3d10_device_CreateSamplerState,
1955 d3d10_device_CreateQuery,
1956 d3d10_device_CreatePredicate,
1957 d3d10_device_CreateCounter,
1958 d3d10_device_CheckFormatSupport,
1959 d3d10_device_CheckMultisampleQualityLevels,
1960 d3d10_device_CheckCounterInfo,
1961 d3d10_device_CheckCounter,
1962 d3d10_device_GetCreationFlags,
1963 d3d10_device_OpenSharedResource,
1964 d3d10_device_SetTextFilterSize,
1965 d3d10_device_GetTextFilterSize,
1966 d3d10_device_CreateShaderResourceView1,
1967 d3d10_device_CreateBlendState1,
1968 d3d10_device_GetFeatureLevel,
1971 static const struct IUnknownVtbl d3d10_device_inner_unknown_vtbl =
1973 /* IUnknown methods */
1974 d3d10_device_inner_QueryInterface,
1975 d3d10_device_inner_AddRef,
1976 d3d10_device_inner_Release,
1979 static inline struct d3d10_device *impl_from_ID3D10Multithread(ID3D10Multithread *iface)
1981 return CONTAINING_RECORD(iface, struct d3d10_device, ID3D10Multithread_iface);
1984 static HRESULT STDMETHODCALLTYPE d3d10_multithread_QueryInterface(ID3D10Multithread *iface, REFIID iid, void **out)
1986 struct d3d10_device *device = impl_from_ID3D10Multithread(iface);
1988 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
1990 return IUnknown_QueryInterface(device->outer_unk, iid, out);
1993 static ULONG STDMETHODCALLTYPE d3d10_multithread_AddRef(ID3D10Multithread *iface)
1995 struct d3d10_device *device = impl_from_ID3D10Multithread(iface);
1997 TRACE("iface %p.\n", iface);
1999 return IUnknown_AddRef(device->outer_unk);
2002 static ULONG STDMETHODCALLTYPE d3d10_multithread_Release(ID3D10Multithread *iface)
2004 struct d3d10_device *device = impl_from_ID3D10Multithread(iface);
2006 TRACE("iface %p.\n", iface);
2008 return IUnknown_Release(device->outer_unk);
2011 static void STDMETHODCALLTYPE d3d10_multithread_Enter(ID3D10Multithread *iface)
2013 TRACE("iface %p.\n", iface);
2015 wined3d_mutex_lock();
2018 static void STDMETHODCALLTYPE d3d10_multithread_Leave(ID3D10Multithread *iface)
2020 TRACE("iface %p.\n", iface);
2022 wined3d_mutex_unlock();
2025 static BOOL STDMETHODCALLTYPE d3d10_multithread_SetMultithreadProtected(ID3D10Multithread *iface, BOOL protect)
2027 FIXME("iface %p, protect %#x stub!\n", iface, protect);
2029 return TRUE;
2032 static BOOL STDMETHODCALLTYPE d3d10_multithread_GetMultithreadProtected(ID3D10Multithread *iface)
2034 FIXME("iface %p stub!\n", iface);
2036 return TRUE;
2039 static const struct ID3D10MultithreadVtbl d3d10_multithread_vtbl =
2041 d3d10_multithread_QueryInterface,
2042 d3d10_multithread_AddRef,
2043 d3d10_multithread_Release,
2044 d3d10_multithread_Enter,
2045 d3d10_multithread_Leave,
2046 d3d10_multithread_SetMultithreadProtected,
2047 d3d10_multithread_GetMultithreadProtected,
2050 static void STDMETHODCALLTYPE d3d10_subresource_destroyed(void *parent) {}
2052 static const struct wined3d_parent_ops d3d10_subresource_parent_ops =
2054 d3d10_subresource_destroyed,
2057 /* IWineDXGIDeviceParent IUnknown methods */
2059 static inline struct d3d10_device *device_from_dxgi_device_parent(IWineDXGIDeviceParent *iface)
2061 return CONTAINING_RECORD(iface, struct d3d10_device, IWineDXGIDeviceParent_iface);
2064 static HRESULT STDMETHODCALLTYPE dxgi_device_parent_QueryInterface(IWineDXGIDeviceParent *iface,
2065 REFIID riid, void **ppv)
2067 struct d3d10_device *device = device_from_dxgi_device_parent(iface);
2068 return IUnknown_QueryInterface(device->outer_unk, riid, ppv);
2071 static ULONG STDMETHODCALLTYPE dxgi_device_parent_AddRef(IWineDXGIDeviceParent *iface)
2073 struct d3d10_device *device = device_from_dxgi_device_parent(iface);
2074 return IUnknown_AddRef(device->outer_unk);
2077 static ULONG STDMETHODCALLTYPE dxgi_device_parent_Release(IWineDXGIDeviceParent *iface)
2079 struct d3d10_device *device = device_from_dxgi_device_parent(iface);
2080 return IUnknown_Release(device->outer_unk);
2083 static struct wined3d_device_parent * STDMETHODCALLTYPE dxgi_device_parent_get_wined3d_device_parent(
2084 IWineDXGIDeviceParent *iface)
2086 struct d3d10_device *device = device_from_dxgi_device_parent(iface);
2087 return &device->device_parent;
2090 static const struct IWineDXGIDeviceParentVtbl d3d10_dxgi_device_parent_vtbl =
2092 /* IUnknown methods */
2093 dxgi_device_parent_QueryInterface,
2094 dxgi_device_parent_AddRef,
2095 dxgi_device_parent_Release,
2096 /* IWineDXGIDeviceParent methods */
2097 dxgi_device_parent_get_wined3d_device_parent,
2100 static inline struct d3d10_device *device_from_wined3d_device_parent(struct wined3d_device_parent *device_parent)
2102 return CONTAINING_RECORD(device_parent, struct d3d10_device, device_parent);
2105 static void CDECL device_parent_wined3d_device_created(struct wined3d_device_parent *device_parent,
2106 struct wined3d_device *wined3d_device)
2108 struct d3d10_device *device = device_from_wined3d_device_parent(device_parent);
2110 TRACE("device_parent %p, wined3d_device %p.\n", device_parent, wined3d_device);
2112 wined3d_device_incref(wined3d_device);
2113 device->wined3d_device = wined3d_device;
2116 static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent)
2118 TRACE("device_parent %p.\n", device_parent);
2121 static void CDECL device_parent_activate(struct wined3d_device_parent *device_parent, BOOL activate)
2123 TRACE("device_parent %p, activate %#x.\n", device_parent, activate);
2126 static HRESULT CDECL device_parent_surface_created(struct wined3d_device_parent *device_parent,
2127 void *container_parent, struct wined3d_surface *surface, void **parent,
2128 const struct wined3d_parent_ops **parent_ops)
2130 TRACE("device_parent %p, container_parent %p, surface %p, parent %p, parent_ops %p.\n",
2131 device_parent, container_parent, surface, parent, parent_ops);
2133 *parent = container_parent;
2134 *parent_ops = &d3d10_null_wined3d_parent_ops;
2136 return S_OK;
2139 static HRESULT CDECL device_parent_volume_created(struct wined3d_device_parent *device_parent,
2140 void *container_parent, struct wined3d_volume *volume, void **parent,
2141 const struct wined3d_parent_ops **parent_ops)
2143 TRACE("device_parent %p, container_parent %p, volume %p, parent %p, parent_ops %p.\n",
2144 device_parent, container_parent, volume, parent, parent_ops);
2146 *parent = container_parent;
2147 *parent_ops = &d3d10_null_wined3d_parent_ops;
2149 return S_OK;
2152 static HRESULT CDECL device_parent_create_swapchain_surface(struct wined3d_device_parent *device_parent,
2153 void *container_parent, const struct wined3d_resource_desc *wined3d_desc, struct wined3d_surface **surface)
2155 struct d3d10_device *device = device_from_wined3d_device_parent(device_parent);
2156 struct wined3d_resource *sub_resource;
2157 struct d3d10_texture2d *texture;
2158 D3D10_TEXTURE2D_DESC desc;
2159 HRESULT hr;
2161 FIXME("device_parent %p, container_parent %p, wined3d_desc %p, surface %p partial stub!\n",
2162 device_parent, container_parent, wined3d_desc, surface);
2164 FIXME("Implement DXGI<->wined3d usage conversion\n");
2166 desc.Width = wined3d_desc->width;
2167 desc.Height = wined3d_desc->height;
2168 desc.MipLevels = 1;
2169 desc.ArraySize = 1;
2170 desc.Format = dxgi_format_from_wined3dformat(wined3d_desc->format);
2171 desc.SampleDesc.Count = wined3d_desc->multisample_type ? wined3d_desc->multisample_type : 1;
2172 desc.SampleDesc.Quality = wined3d_desc->multisample_quality;
2173 desc.Usage = D3D10_USAGE_DEFAULT;
2174 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2175 desc.CPUAccessFlags = 0;
2176 desc.MiscFlags = 0;
2178 if (FAILED(hr = d3d10_device_CreateTexture2D(&device->ID3D10Device1_iface,
2179 &desc, NULL, (ID3D10Texture2D **)&texture)))
2181 ERR("CreateTexture2D failed, returning %#x\n", hr);
2182 return hr;
2185 sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, 0);
2186 *surface = wined3d_surface_from_resource(sub_resource);
2187 wined3d_surface_incref(*surface);
2188 ID3D10Texture2D_Release(&texture->ID3D10Texture2D_iface);
2190 return S_OK;
2193 static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent *device_parent,
2194 struct wined3d_swapchain_desc *desc, struct wined3d_swapchain **swapchain)
2196 struct d3d10_device *device = device_from_wined3d_device_parent(device_parent);
2197 IWineDXGIDevice *wine_device;
2198 HRESULT hr;
2200 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent, desc, swapchain);
2202 if (FAILED(hr = d3d10_device_QueryInterface(&device->ID3D10Device1_iface,
2203 &IID_IWineDXGIDevice, (void **)&wine_device)))
2205 ERR("Device should implement IWineDXGIDevice.\n");
2206 return E_FAIL;
2209 hr = IWineDXGIDevice_create_swapchain(wine_device, desc, swapchain);
2210 IWineDXGIDevice_Release(wine_device);
2211 if (FAILED(hr))
2213 ERR("Failed to create DXGI swapchain, returning %#x\n", hr);
2214 return hr;
2217 return S_OK;
2220 static const struct wined3d_device_parent_ops d3d10_wined3d_device_parent_ops =
2222 device_parent_wined3d_device_created,
2223 device_parent_mode_changed,
2224 device_parent_activate,
2225 device_parent_surface_created,
2226 device_parent_volume_created,
2227 device_parent_create_swapchain_surface,
2228 device_parent_create_swapchain,
2231 static void *d3d10_rb_alloc(size_t size)
2233 return HeapAlloc(GetProcessHeap(), 0, size);
2236 static void *d3d10_rb_realloc(void *ptr, size_t size)
2238 return HeapReAlloc(GetProcessHeap(), 0, ptr, size);
2241 static void d3d10_rb_free(void *ptr)
2243 HeapFree(GetProcessHeap(), 0, ptr);
2246 static int d3d10_sampler_state_compare(const void *key, const struct wine_rb_entry *entry)
2248 const D3D10_SAMPLER_DESC *ka = key;
2249 const D3D10_SAMPLER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d10_sampler_state, entry)->desc;
2251 return memcmp(ka, kb, sizeof(*ka));
2254 static const struct wine_rb_functions d3d10_sampler_state_rb_ops =
2256 d3d10_rb_alloc,
2257 d3d10_rb_realloc,
2258 d3d10_rb_free,
2259 d3d10_sampler_state_compare,
2262 static int d3d10_blend_state_compare(const void *key, const struct wine_rb_entry *entry)
2264 const D3D10_BLEND_DESC *ka = key;
2265 const D3D10_BLEND_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d10_blend_state, entry)->desc;
2267 return memcmp(ka, kb, sizeof(*ka));
2270 static const struct wine_rb_functions d3d10_blend_state_rb_ops =
2272 d3d10_rb_alloc,
2273 d3d10_rb_realloc,
2274 d3d10_rb_free,
2275 d3d10_blend_state_compare,
2278 static int d3d10_depthstencil_state_compare(const void *key, const struct wine_rb_entry *entry)
2280 const D3D10_DEPTH_STENCIL_DESC *ka = key;
2281 const D3D10_DEPTH_STENCIL_DESC *kb = &WINE_RB_ENTRY_VALUE(entry,
2282 const struct d3d10_depthstencil_state, entry)->desc;
2284 return memcmp(ka, kb, sizeof(*ka));
2287 static const struct wine_rb_functions d3d10_depthstencil_state_rb_ops =
2289 d3d10_rb_alloc,
2290 d3d10_rb_realloc,
2291 d3d10_rb_free,
2292 d3d10_depthstencil_state_compare,
2295 static int d3d10_rasterizer_state_compare(const void *key, const struct wine_rb_entry *entry)
2297 const D3D10_RASTERIZER_DESC *ka = key;
2298 const D3D10_RASTERIZER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d10_rasterizer_state, entry)->desc;
2300 return memcmp(ka, kb, sizeof(*ka));
2303 static const struct wine_rb_functions d3d10_rasterizer_state_rb_ops =
2305 d3d10_rb_alloc,
2306 d3d10_rb_realloc,
2307 d3d10_rb_free,
2308 d3d10_rasterizer_state_compare,
2311 HRESULT d3d10_device_init(struct d3d10_device *device, void *outer_unknown)
2313 device->IUnknown_inner.lpVtbl = &d3d10_device_inner_unknown_vtbl;
2314 device->ID3D10Device1_iface.lpVtbl = &d3d10_device1_vtbl;
2315 device->ID3D10Multithread_iface.lpVtbl = &d3d10_multithread_vtbl;
2316 device->IWineDXGIDeviceParent_iface.lpVtbl = &d3d10_dxgi_device_parent_vtbl;
2317 device->device_parent.ops = &d3d10_wined3d_device_parent_ops;
2318 device->refcount = 1;
2319 /* COM aggregation always takes place */
2320 device->outer_unk = outer_unknown;
2322 if (wine_rb_init(&device->blend_states, &d3d10_blend_state_rb_ops) == -1)
2324 WARN("Failed to initialize blend state rbtree.\n");
2325 return E_FAIL;
2328 if (wine_rb_init(&device->depthstencil_states, &d3d10_depthstencil_state_rb_ops) == -1)
2330 WARN("Failed to initialize depthstencil state rbtree.\n");
2331 wine_rb_destroy(&device->blend_states, NULL, NULL);
2332 return E_FAIL;
2335 if (wine_rb_init(&device->rasterizer_states, &d3d10_rasterizer_state_rb_ops) == -1)
2337 WARN("Failed to initialize rasterizer state rbtree.\n");
2338 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
2339 wine_rb_destroy(&device->blend_states, NULL, NULL);
2340 return E_FAIL;
2343 if (wine_rb_init(&device->sampler_states, &d3d10_sampler_state_rb_ops) == -1)
2345 WARN("Failed to initialize sampler state rbtree.\n");
2346 wine_rb_destroy(&device->rasterizer_states, NULL, NULL);
2347 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
2348 wine_rb_destroy(&device->blend_states, NULL, NULL);
2349 return E_FAIL;
2352 return S_OK;