mf/tests: Add some more tests for SAR current type.
[wine.git] / dlls / ddraw / executebuffer.c
blobe0a9445bf71ec5b258f023348fbd3d8083586617
1 /* Direct3D ExecuteBuffer
2 * Copyright (c) 1998-2004 Lionel ULMER
3 * Copyright (c) 2002-2004 Christian Costa
4 * Copyright (c) 2006 Stefan Dösinger
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "ddraw_private.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
25 /*****************************************************************************
26 * _dump_executedata
27 * _dump_D3DEXECUTEBUFFERDESC
29 * Debug functions which write the executebuffer data to the console
31 *****************************************************************************/
33 static void _dump_executedata(const D3DEXECUTEDATA *lpData) {
34 TRACE("dwSize : %d\n", lpData->dwSize);
35 TRACE("Vertex Offset : %d Count : %d\n", lpData->dwVertexOffset, lpData->dwVertexCount);
36 TRACE("Instruction Offset : %d Length : %d\n", lpData->dwInstructionOffset, lpData->dwInstructionLength);
37 TRACE("HVertex Offset : %d\n", lpData->dwHVertexOffset);
40 static void _dump_D3DEXECUTEBUFFERDESC(const D3DEXECUTEBUFFERDESC *lpDesc) {
41 TRACE("dwSize : %d\n", lpDesc->dwSize);
42 TRACE("dwFlags : %x\n", lpDesc->dwFlags);
43 TRACE("dwCaps : %x\n", lpDesc->dwCaps);
44 TRACE("dwBufferSize : %d\n", lpDesc->dwBufferSize);
45 TRACE("lpData : %p\n", lpDesc->lpData);
48 HRESULT d3d_execute_buffer_execute(struct d3d_execute_buffer *buffer, struct d3d_device *device)
50 DWORD is = buffer->data.dwInstructionOffset;
51 char *instr = (char *)buffer->desc.lpData + is;
52 unsigned int i, primitive_size;
53 struct wined3d_map_desc map_desc;
54 struct wined3d_box box = {0};
55 HRESULT hr;
57 TRACE("ExecuteData :\n");
58 if (TRACE_ON(ddraw))
59 _dump_executedata(&(buffer->data));
61 for (;;)
63 D3DINSTRUCTION *current = (D3DINSTRUCTION *)instr;
64 BYTE size;
65 WORD count;
67 count = current->wCount;
68 size = current->bSize;
69 instr += sizeof(*current);
70 primitive_size = 0;
72 switch (current->bOpcode)
74 case D3DOP_POINT:
76 const D3DPOINT *p = (D3DPOINT *)instr;
77 wined3d_device_set_primitive_type(device->wined3d_device, WINED3D_PT_POINTLIST, 0);
78 wined3d_stateblock_set_stream_source(device->state, 0,
79 buffer->dst_vertex_buffer, 0, sizeof(D3DTLVERTEX));
80 wined3d_stateblock_set_vertex_declaration(device->state,
81 ddraw_find_decl(device->ddraw, D3DFVF_TLVERTEX));
83 wined3d_device_apply_stateblock(device->wined3d_device, device->state);
84 for (i = 0; i < count; ++i)
85 wined3d_device_draw_primitive(device->wined3d_device, p[i].wFirst, p[i].wCount);
87 instr += sizeof(*p) * count;
88 break;
91 case D3DOP_LINE:
92 primitive_size = 2;
93 wined3d_device_set_primitive_type(device->wined3d_device, WINED3D_PT_LINELIST, 0);
94 /* Drop through. */
95 case D3DOP_TRIANGLE:
97 WORD *indices;
98 unsigned int index_pos = buffer->index_pos, index_count;
99 TRACE("TRIANGLE (%d)\n", count);
101 if (!count)
102 break;
104 if (!primitive_size)
106 wined3d_device_set_primitive_type(device->wined3d_device, WINED3D_PT_TRIANGLELIST, 0);
107 primitive_size = 3;
110 index_count = count * primitive_size;
111 if (buffer->index_size < index_count)
113 unsigned int new_size = max(buffer->index_size * 2, index_count);
114 struct wined3d_buffer *new_buffer;
115 struct wined3d_buffer_desc desc;
117 desc.byte_width = new_size * sizeof(*indices);
118 desc.usage = WINED3DUSAGE_DYNAMIC | WINED3DUSAGE_STATICDECL;
119 desc.bind_flags = WINED3D_BIND_INDEX_BUFFER;
120 desc.access = WINED3D_RESOURCE_ACCESS_GPU | WINED3D_RESOURCE_ACCESS_MAP_W;
121 desc.misc_flags = 0;
122 desc.structure_byte_stride = 0;
124 if (FAILED(hr = wined3d_buffer_create(device->wined3d_device, &desc,
125 NULL, NULL, &ddraw_null_wined3d_parent_ops, &new_buffer)))
126 return hr;
128 buffer->index_size = new_size;
129 if (buffer->index_buffer)
130 wined3d_buffer_decref(buffer->index_buffer);
131 buffer->index_buffer = new_buffer;
132 index_pos = 0;
134 else if (buffer->index_size - index_count < index_pos)
136 index_pos = 0;
139 box.left = index_pos * sizeof(*indices);
140 box.right = (index_pos + index_count) * sizeof(*indices);
141 if (FAILED(hr = wined3d_resource_map(wined3d_buffer_get_resource(buffer->index_buffer), 0, &map_desc,
142 &box, WINED3D_MAP_WRITE | (index_pos ? WINED3D_MAP_NOOVERWRITE : WINED3D_MAP_DISCARD))))
143 return hr;
144 indices = map_desc.data;
146 for (i = 0; i < count; ++i)
148 D3DTRIANGLE *ci = (D3DTRIANGLE *)instr;
149 TRACE(" v1: %d v2: %d v3: %d\n",ci->u1.v1, ci->u2.v2, ci->u3.v3);
150 TRACE(" Flags : ");
151 if (TRACE_ON(ddraw))
153 /* Wireframe */
154 if (ci->wFlags & D3DTRIFLAG_EDGEENABLE1)
155 TRACE("EDGEENABLE1 ");
156 if (ci->wFlags & D3DTRIFLAG_EDGEENABLE2)
157 TRACE("EDGEENABLE2 ");
158 if (ci->wFlags & D3DTRIFLAG_EDGEENABLE1)
159 TRACE("EDGEENABLE3 ");
160 /* Strips / Fans */
161 if (ci->wFlags == D3DTRIFLAG_EVEN)
162 TRACE("EVEN ");
163 if (ci->wFlags == D3DTRIFLAG_ODD)
164 TRACE("ODD ");
165 if (ci->wFlags == D3DTRIFLAG_START)
166 TRACE("START ");
167 if ((ci->wFlags > 0) && (ci->wFlags < 30))
168 TRACE("STARTFLAT(%u) ", ci->wFlags);
169 TRACE("\n");
172 switch (primitive_size)
174 case 3:
175 indices[(i * primitive_size) + 2] = ci->u3.v3;
176 /* Drop through. */
177 case 2:
178 indices[(i * primitive_size) + 1] = ci->u2.v2;
179 indices[(i * primitive_size) ] = ci->u1.v1;
181 instr += size;
184 wined3d_resource_unmap(wined3d_buffer_get_resource(buffer->index_buffer), 0);
186 wined3d_stateblock_set_stream_source(device->state, 0,
187 buffer->dst_vertex_buffer, 0, sizeof(D3DTLVERTEX));
188 wined3d_stateblock_set_vertex_declaration(device->state,
189 ddraw_find_decl(device->ddraw, D3DFVF_TLVERTEX));
190 wined3d_stateblock_set_index_buffer(device->state, buffer->index_buffer, WINED3DFMT_R16_UINT);
191 wined3d_device_apply_stateblock(device->wined3d_device, device->state);
192 wined3d_device_draw_indexed_primitive(device->wined3d_device, index_pos, index_count);
194 buffer->index_pos = index_pos + index_count;
195 break;
198 case D3DOP_MATRIXLOAD:
199 WARN("MATRIXLOAD-s (%u)\n", count);
200 instr += count * size;
201 break;
203 case D3DOP_MATRIXMULTIPLY:
204 TRACE("MATRIXMULTIPLY (%d)\n", count);
205 for (i = 0; i < count; ++i)
207 D3DMATRIXMULTIPLY *ci = (D3DMATRIXMULTIPLY *)instr;
208 struct wined3d_matrix *a, *b, *c;
210 a = ddraw_get_object(&device->handle_table, ci->hDestMatrix - 1, DDRAW_HANDLE_MATRIX);
211 b = ddraw_get_object(&device->handle_table, ci->hSrcMatrix1 - 1, DDRAW_HANDLE_MATRIX);
212 c = ddraw_get_object(&device->handle_table, ci->hSrcMatrix2 - 1, DDRAW_HANDLE_MATRIX);
214 if (!a || !b || !c)
216 ERR("Invalid matrix handle (a %#x -> %p, b %#x -> %p, c %#x -> %p).\n",
217 ci->hDestMatrix, a, ci->hSrcMatrix1, b, ci->hSrcMatrix2, c);
219 else
221 TRACE("dst %p, src1 %p, src2 %p.\n", a, b, c);
222 multiply_matrix(a, c, b);
225 instr += size;
227 break;
229 case D3DOP_STATETRANSFORM:
230 TRACE("STATETRANSFORM (%d)\n", count);
231 for (i = 0; i < count; ++i)
233 D3DSTATE *ci = (D3DSTATE *)instr;
234 D3DMATRIX *m;
236 m = ddraw_get_object(&device->handle_table, ci->u2.dwArg[0] - 1, DDRAW_HANDLE_MATRIX);
237 if (!m)
239 ERR("Invalid matrix handle %#x.\n", ci->u2.dwArg[0]);
241 else
243 if (ci->u1.dtstTransformStateType == D3DTRANSFORMSTATE_WORLD)
244 device->world = ci->u2.dwArg[0];
245 if (ci->u1.dtstTransformStateType == D3DTRANSFORMSTATE_VIEW)
246 device->view = ci->u2.dwArg[0];
247 if (ci->u1.dtstTransformStateType == D3DTRANSFORMSTATE_PROJECTION)
248 device->proj = ci->u2.dwArg[0];
249 IDirect3DDevice3_SetTransform(&device->IDirect3DDevice3_iface,
250 ci->u1.dtstTransformStateType, m);
253 instr += size;
255 break;
257 case D3DOP_STATELIGHT:
258 TRACE("STATELIGHT (%d)\n", count);
259 for (i = 0; i < count; ++i)
261 D3DSTATE *ci = (D3DSTATE *)instr;
263 if (FAILED(IDirect3DDevice3_SetLightState(&device->IDirect3DDevice3_iface,
264 ci->u1.dlstLightStateType, ci->u2.dwArg[0])))
265 WARN("Failed to set light state.\n");
267 instr += size;
269 break;
271 case D3DOP_STATERENDER:
272 TRACE("STATERENDER (%d)\n", count);
273 for (i = 0; i < count; ++i)
275 D3DSTATE *ci = (D3DSTATE *)instr;
277 if (FAILED(IDirect3DDevice3_SetRenderState(&device->IDirect3DDevice3_iface,
278 ci->u1.drstRenderStateType, ci->u2.dwArg[0])))
279 WARN("Failed to set render state.\n");
281 instr += size;
283 break;
285 case D3DOP_PROCESSVERTICES:
286 TRACE("PROCESSVERTICES (%d)\n", count);
288 for (i = 0; i < count; ++i)
290 D3DPROCESSVERTICES *ci = (D3DPROCESSVERTICES *)instr;
291 DWORD op = ci->dwFlags & D3DPROCESSVERTICES_OPMASK;
293 TRACE(" start %u, dest %u, count %u, flags %#x.\n",
294 ci->wStart, ci->wDest, ci->dwCount, ci->dwFlags);
296 if (ci->dwFlags & D3DPROCESSVERTICES_UPDATEEXTENTS)
297 FIXME("D3DPROCESSVERTICES_UPDATEEXTENTS not implemented.\n");
298 if (ci->dwFlags & D3DPROCESSVERTICES_NOCOLOR)
299 FIXME("D3DPROCESSVERTICES_NOCOLOR not implemented.\n");
301 switch (op)
303 case D3DPROCESSVERTICES_TRANSFORMLIGHT:
304 case D3DPROCESSVERTICES_TRANSFORM:
305 wined3d_stateblock_set_stream_source(device->state, 0,
306 buffer->src_vertex_buffer, buffer->src_vertex_pos * sizeof(D3DVERTEX), sizeof(D3DVERTEX));
307 wined3d_stateblock_set_render_state(device->state, WINED3D_RS_LIGHTING,
308 op == D3DPROCESSVERTICES_TRANSFORMLIGHT && !!device->material);
309 wined3d_stateblock_set_vertex_declaration(device->state,
310 ddraw_find_decl(device->ddraw, op == D3DPROCESSVERTICES_TRANSFORMLIGHT
311 ? D3DFVF_VERTEX : D3DFVF_LVERTEX));
312 wined3d_device_apply_stateblock(device->wined3d_device, device->state);
313 wined3d_device_process_vertices(device->wined3d_device, ci->wStart, ci->wDest,
314 ci->dwCount, buffer->dst_vertex_buffer, NULL, 0, D3DFVF_TLVERTEX);
315 break;
317 case D3DPROCESSVERTICES_COPY:
318 box.left = (buffer->src_vertex_pos + ci->wStart) * sizeof(D3DTLVERTEX);
319 box.right = box.left + ci->dwCount * sizeof(D3DTLVERTEX);
320 box.top = box.front = 0;
321 box.bottom = box.back = 1;
322 wined3d_device_copy_sub_resource_region(device->wined3d_device,
323 wined3d_buffer_get_resource(buffer->dst_vertex_buffer), 0,
324 ci->wDest * sizeof(D3DTLVERTEX), 0, 0,
325 wined3d_buffer_get_resource(buffer->src_vertex_buffer), 0, &box, 0);
326 break;
328 default:
329 FIXME("Unhandled vertex processing op %#x.\n", op);
330 break;
333 instr += size;
335 break;
337 case D3DOP_TEXTURELOAD:
338 TRACE("TEXTURELOAD (%u)\n", count);
340 for (i = 0; i < count; ++i)
342 D3DTEXTURELOAD *ci = (D3DTEXTURELOAD *)instr;
343 struct ddraw_surface *dst, *src;
345 instr += size;
347 if (!(dst = ddraw_get_object(&device->handle_table,
348 ci->hDestTexture - 1, DDRAW_HANDLE_SURFACE)))
350 WARN("Invalid destination texture handle %#x.\n", ci->hDestTexture);
351 continue;
353 if (!(src = ddraw_get_object(&device->handle_table,
354 ci->hSrcTexture - 1, DDRAW_HANDLE_SURFACE)))
356 WARN("Invalid source texture handle %#x.\n", ci->hSrcTexture);
357 continue;
360 IDirect3DTexture2_Load(&dst->IDirect3DTexture2_iface, &src->IDirect3DTexture2_iface);
362 break;
364 case D3DOP_EXIT:
365 TRACE("EXIT (%u)\n", count);
366 instr += size;
367 goto end_of_buffer;
369 case D3DOP_BRANCHFORWARD:
370 TRACE("BRANCHFORWARD (%d)\n", count);
371 for (i = 0; i < count; ++i)
373 D3DBRANCH *ci = (D3DBRANCH *)instr;
375 if ((buffer->data.dsStatus.dwStatus & ci->dwMask) == ci->dwValue)
377 if (!ci->bNegate)
379 TRACE(" Branch to %d\n", ci->dwOffset);
380 if (ci->dwOffset) {
381 instr = (char*)current + ci->dwOffset;
382 break;
386 else
388 if (ci->bNegate)
390 TRACE(" Branch to %d\n", ci->dwOffset);
391 if (ci->dwOffset) {
392 instr = (char*)current + ci->dwOffset;
393 break;
398 instr += size;
400 break;
402 case D3DOP_SPAN:
403 WARN("SPAN-s (%u)\n", count);
404 instr += count * size;
405 break;
407 case D3DOP_SETSTATUS:
408 TRACE("SETSTATUS (%d)\n", count);
409 for (i = 0; i < count; ++i)
411 buffer->data.dsStatus = *(D3DSTATUS *)instr;
412 instr += size;
414 break;
416 default:
417 ERR("Unhandled OpCode %#x.\n",current->bOpcode);
418 instr += count * size;
419 break;
423 end_of_buffer:
424 return D3D_OK;
427 static inline struct d3d_execute_buffer *impl_from_IDirect3DExecuteBuffer(IDirect3DExecuteBuffer *iface)
429 return CONTAINING_RECORD(iface, struct d3d_execute_buffer, IDirect3DExecuteBuffer_iface);
432 static HRESULT WINAPI d3d_execute_buffer_QueryInterface(IDirect3DExecuteBuffer *iface, REFIID iid, void **out)
434 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
436 if (IsEqualGUID(&IID_IDirect3DExecuteBuffer, iid)
437 || IsEqualGUID(&IID_IUnknown, iid))
439 IDirect3DExecuteBuffer_AddRef(iface);
440 *out = iface;
441 return S_OK;
444 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
446 *out = NULL;
447 return E_NOINTERFACE;
450 /*****************************************************************************
451 * IDirect3DExecuteBuffer::AddRef
453 * A normal AddRef method, nothing special
455 * Returns:
456 * The new refcount
458 *****************************************************************************/
459 static ULONG WINAPI d3d_execute_buffer_AddRef(IDirect3DExecuteBuffer *iface)
461 struct d3d_execute_buffer *buffer = impl_from_IDirect3DExecuteBuffer(iface);
462 ULONG ref = InterlockedIncrement(&buffer->ref);
464 TRACE("%p increasing refcount to %u.\n", buffer, ref);
466 return ref;
469 /*****************************************************************************
470 * IDirect3DExecuteBuffer::Release
472 * A normal Release method, nothing special
474 * Returns:
475 * The new refcount
477 *****************************************************************************/
478 static ULONG WINAPI d3d_execute_buffer_Release(IDirect3DExecuteBuffer *iface)
480 struct d3d_execute_buffer *buffer = impl_from_IDirect3DExecuteBuffer(iface);
481 ULONG ref = InterlockedDecrement(&buffer->ref);
483 TRACE("%p decreasing refcount to %u.\n", buffer, ref);
485 if (!ref)
487 if (buffer->need_free)
488 heap_free(buffer->desc.lpData);
489 if (buffer->index_buffer)
490 wined3d_buffer_decref(buffer->index_buffer);
491 if (buffer->dst_vertex_buffer)
493 wined3d_buffer_decref(buffer->src_vertex_buffer);
494 wined3d_buffer_decref(buffer->dst_vertex_buffer);
496 heap_free(buffer);
499 return ref;
502 /*****************************************************************************
503 * IDirect3DExecuteBuffer::Initialize
505 * Initializes the Execute Buffer. This method exists for COM compliance
506 * Nothing to do here.
508 * Returns:
509 * D3D_OK
511 *****************************************************************************/
512 static HRESULT WINAPI d3d_execute_buffer_Initialize(IDirect3DExecuteBuffer *iface,
513 IDirect3DDevice *device, D3DEXECUTEBUFFERDESC *desc)
515 TRACE("iface %p, device %p, desc %p.\n", iface, device, desc);
517 return D3D_OK;
520 /*****************************************************************************
521 * IDirect3DExecuteBuffer::Lock
523 * Locks the buffer, so the app can write into it.
525 * Params:
526 * Desc: Pointer to return the buffer description. This Description contains
527 * a pointer to the buffer data.
529 * Returns:
530 * This implementation always returns D3D_OK
532 *****************************************************************************/
533 static HRESULT WINAPI d3d_execute_buffer_Lock(IDirect3DExecuteBuffer *iface, D3DEXECUTEBUFFERDESC *desc)
535 struct d3d_execute_buffer *buffer = impl_from_IDirect3DExecuteBuffer(iface);
536 DWORD dwSize;
538 TRACE("iface %p, desc %p.\n", iface, desc);
540 dwSize = desc->dwSize;
541 memcpy(desc, &buffer->desc, dwSize);
543 if (TRACE_ON(ddraw))
545 TRACE(" Returning description :\n");
546 _dump_D3DEXECUTEBUFFERDESC(desc);
548 return D3D_OK;
551 /*****************************************************************************
552 * IDirect3DExecuteBuffer::Unlock
554 * Unlocks the buffer. We don't have anything to do here
556 * Returns:
557 * This implementation always returns D3D_OK
559 *****************************************************************************/
560 static HRESULT WINAPI d3d_execute_buffer_Unlock(IDirect3DExecuteBuffer *iface)
562 TRACE("iface %p.\n", iface);
564 return D3D_OK;
567 /*****************************************************************************
568 * IDirect3DExecuteBuffer::SetExecuteData
570 * Sets the execute data. This data is used to describe the buffer's content
572 * Params:
573 * Data: Pointer to a D3DEXECUTEDATA structure containing the data to
574 * assign
576 * Returns:
577 * D3D_OK on success
578 * DDERR_OUTOFMEMORY if the vertex buffer allocation failed
580 *****************************************************************************/
581 static HRESULT WINAPI d3d_execute_buffer_SetExecuteData(IDirect3DExecuteBuffer *iface, D3DEXECUTEDATA *data)
583 struct d3d_execute_buffer *buffer = impl_from_IDirect3DExecuteBuffer(iface);
584 struct wined3d_map_desc map_desc;
585 struct wined3d_box box = {0};
586 HRESULT hr;
587 DWORD buf_size = buffer->desc.dwBufferSize, copy_size;
589 TRACE("iface %p, data %p.\n", iface, data);
591 if (data->dwSize != sizeof(*data))
593 WARN("data->dwSize is %u, returning DDERR_INVALIDPARAMS.\n", data->dwSize);
594 return DDERR_INVALIDPARAMS;
597 /* Skip past previous vertex data. */
598 buffer->src_vertex_pos += buffer->data.dwVertexCount;
600 if (buffer->vertex_size < data->dwVertexCount)
602 unsigned int new_size = max(data->dwVertexCount, buffer->vertex_size * 2);
603 struct wined3d_buffer *src_buffer, *dst_buffer;
604 struct wined3d_buffer_desc desc;
606 desc.byte_width = new_size * sizeof(D3DVERTEX);
607 desc.usage = 0;
608 desc.bind_flags = WINED3D_BIND_VERTEX_BUFFER;
609 desc.access = WINED3D_RESOURCE_ACCESS_CPU | WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W;
610 desc.misc_flags = 0;
611 desc.structure_byte_stride = 0;
613 if (FAILED(hr = wined3d_buffer_create(buffer->d3ddev->wined3d_device, &desc,
614 NULL, NULL, &ddraw_null_wined3d_parent_ops, &src_buffer)))
615 return hr;
617 desc.byte_width = new_size * sizeof(D3DTLVERTEX);
618 desc.usage = WINED3DUSAGE_STATICDECL;
619 desc.access = WINED3D_RESOURCE_ACCESS_GPU | WINED3D_RESOURCE_ACCESS_MAP_W;
621 if (FAILED(hr = wined3d_buffer_create(buffer->d3ddev->wined3d_device, &desc,
622 NULL, NULL, &ddraw_null_wined3d_parent_ops, &dst_buffer)))
624 wined3d_buffer_decref(src_buffer);
625 return hr;
628 if (buffer->dst_vertex_buffer)
630 wined3d_buffer_decref(buffer->src_vertex_buffer);
631 wined3d_buffer_decref(buffer->dst_vertex_buffer);
633 buffer->src_vertex_buffer = src_buffer;
634 buffer->dst_vertex_buffer = dst_buffer;
635 buffer->vertex_size = new_size;
636 buffer->src_vertex_pos = 0;
638 else if (buffer->vertex_size - data->dwVertexCount < buffer->src_vertex_pos)
640 buffer->src_vertex_pos = 0;
643 if (data->dwVertexCount && (!buf_size || data->dwVertexOffset < buf_size))
645 box.left = buffer->src_vertex_pos * sizeof(D3DVERTEX);
646 box.right = box.left + data->dwVertexCount * sizeof(D3DVERTEX);
647 if (FAILED(hr = wined3d_resource_map(wined3d_buffer_get_resource(buffer->src_vertex_buffer),
648 0, &map_desc, &box, WINED3D_MAP_WRITE)))
649 return hr;
651 copy_size = data->dwVertexCount * sizeof(D3DVERTEX);
652 if (buf_size)
653 copy_size = min(copy_size, buf_size - data->dwVertexOffset);
655 memcpy(map_desc.data, ((BYTE *)buffer->desc.lpData) + data->dwVertexOffset, copy_size);
657 wined3d_resource_unmap(wined3d_buffer_get_resource(buffer->src_vertex_buffer), 0);
660 memcpy(&buffer->data, data, data->dwSize);
662 if (TRACE_ON(ddraw))
663 _dump_executedata(data);
665 return D3D_OK;
668 /*****************************************************************************
669 * IDirect3DExecuteBuffer::GetExecuteData
671 * Returns the data in the execute buffer
673 * Params:
674 * Data: Pointer to a D3DEXECUTEDATA structure used to return data
676 * Returns:
677 * D3D_OK on success
679 *****************************************************************************/
680 static HRESULT WINAPI d3d_execute_buffer_GetExecuteData(IDirect3DExecuteBuffer *iface, D3DEXECUTEDATA *data)
682 struct d3d_execute_buffer *buffer = impl_from_IDirect3DExecuteBuffer(iface);
684 TRACE("iface %p, data %p.\n", iface, data);
686 /* Tests show that dwSize is ignored. */
687 memcpy(data, &buffer->data, sizeof(*data));
689 if (TRACE_ON(ddraw))
691 TRACE("Returning data :\n");
692 _dump_executedata(data);
695 return DD_OK;
698 /*****************************************************************************
699 * IDirect3DExecuteBuffer::Validate
701 * DirectX 5 SDK: "The IDirect3DExecuteBuffer::Validate method is not
702 * currently implemented"
704 * Params:
707 * Returns:
708 * DDERR_UNSUPPORTED, because it's not implemented in Windows.
710 *****************************************************************************/
711 static HRESULT WINAPI d3d_execute_buffer_Validate(IDirect3DExecuteBuffer *iface,
712 DWORD *offset, LPD3DVALIDATECALLBACK callback, void *context, DWORD reserved)
714 TRACE("iface %p, offset %p, callback %p, context %p, reserved %#x.\n",
715 iface, offset, callback, context, reserved);
717 WARN("Not implemented.\n");
719 return DDERR_UNSUPPORTED; /* Unchecked */
722 /*****************************************************************************
723 * IDirect3DExecuteBuffer::Optimize
725 * DirectX5 SDK: "The IDirect3DExecuteBuffer::Optimize method is not
726 * currently supported"
728 * Params:
729 * Dummy: Seems to be an unused dummy ;)
731 * Returns:
732 * DDERR_UNSUPPORTED, because it's not implemented in Windows.
734 *****************************************************************************/
735 static HRESULT WINAPI d3d_execute_buffer_Optimize(IDirect3DExecuteBuffer *iface, DWORD reserved)
737 TRACE("iface %p, reserved %#x.\n", iface, reserved);
739 WARN("Not implemented.\n");
741 return DDERR_UNSUPPORTED; /* Unchecked */
744 static const struct IDirect3DExecuteBufferVtbl d3d_execute_buffer_vtbl =
746 d3d_execute_buffer_QueryInterface,
747 d3d_execute_buffer_AddRef,
748 d3d_execute_buffer_Release,
749 d3d_execute_buffer_Initialize,
750 d3d_execute_buffer_Lock,
751 d3d_execute_buffer_Unlock,
752 d3d_execute_buffer_SetExecuteData,
753 d3d_execute_buffer_GetExecuteData,
754 d3d_execute_buffer_Validate,
755 d3d_execute_buffer_Optimize,
758 HRESULT d3d_execute_buffer_init(struct d3d_execute_buffer *execute_buffer,
759 struct d3d_device *device, D3DEXECUTEBUFFERDESC *desc)
761 execute_buffer->IDirect3DExecuteBuffer_iface.lpVtbl = &d3d_execute_buffer_vtbl;
762 execute_buffer->ref = 1;
763 execute_buffer->d3ddev = device;
765 /* Initializes memory */
766 memcpy(&execute_buffer->desc, desc, desc->dwSize);
768 /* No buffer given */
769 if (!(execute_buffer->desc.dwFlags & D3DDEB_LPDATA))
770 execute_buffer->desc.lpData = NULL;
772 /* No buffer size given */
773 if (!(execute_buffer->desc.dwFlags & D3DDEB_BUFSIZE))
774 execute_buffer->desc.dwBufferSize = 0;
776 /* Create buffer if asked */
777 if (!execute_buffer->desc.lpData && execute_buffer->desc.dwBufferSize)
779 execute_buffer->need_free = TRUE;
780 if (!(execute_buffer->desc.lpData = heap_alloc_zero(execute_buffer->desc.dwBufferSize)))
782 ERR("Failed to allocate execute buffer data.\n");
783 return DDERR_OUTOFMEMORY;
787 execute_buffer->desc.dwFlags |= D3DDEB_LPDATA;
789 return D3D_OK;
792 struct d3d_execute_buffer *unsafe_impl_from_IDirect3DExecuteBuffer(IDirect3DExecuteBuffer *iface)
794 if (!iface)
795 return NULL;
796 assert(iface->lpVtbl == &d3d_execute_buffer_vtbl);
798 return impl_from_IDirect3DExecuteBuffer(iface);