user32/tests: Fix monitor test failures on some systems.
[wine.git] / dlls / ddraw / executebuffer.c
blob9f0fdb85e542bd8b1fa7712dd7b2efe616cd8038
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_device_set_stream_source(device->wined3d_device, 0,
79 buffer->dst_vertex_buffer, 0, sizeof(D3DTLVERTEX));
80 wined3d_device_set_vertex_declaration(device->wined3d_device,
81 ddraw_find_decl(device->ddraw, D3DFVF_TLVERTEX));
83 for (i = 0; i < count; ++i)
84 wined3d_device_draw_primitive(device->wined3d_device, p[i].wFirst, p[i].wCount);
86 instr += sizeof(*p) * count;
87 break;
90 case D3DOP_LINE:
91 primitive_size = 2;
92 wined3d_device_set_primitive_type(device->wined3d_device, WINED3D_PT_LINELIST, 0);
93 /* Drop through. */
94 case D3DOP_TRIANGLE:
96 WORD *indices;
97 unsigned int index_pos = buffer->index_pos, index_count;
98 TRACE("TRIANGLE (%d)\n", count);
100 if (!count)
101 break;
103 if (!primitive_size)
105 wined3d_device_set_primitive_type(device->wined3d_device, WINED3D_PT_TRIANGLELIST, 0);
106 primitive_size = 3;
109 index_count = count * primitive_size;
110 if (buffer->index_size < index_count)
112 unsigned int new_size = max(buffer->index_size * 2, index_count);
113 struct wined3d_buffer *new_buffer;
114 struct wined3d_buffer_desc desc;
116 desc.byte_width = new_size * sizeof(*indices);
117 desc.usage = WINED3DUSAGE_DYNAMIC | WINED3DUSAGE_STATICDECL;
118 desc.bind_flags = WINED3D_BIND_INDEX_BUFFER;
119 desc.access = WINED3D_RESOURCE_ACCESS_GPU | WINED3D_RESOURCE_ACCESS_MAP_W;
120 desc.misc_flags = 0;
121 desc.structure_byte_stride = 0;
123 if (FAILED(hr = wined3d_buffer_create(device->wined3d_device, &desc,
124 NULL, NULL, &ddraw_null_wined3d_parent_ops, &new_buffer)))
125 return hr;
127 buffer->index_size = new_size;
128 if (buffer->index_buffer)
129 wined3d_buffer_decref(buffer->index_buffer);
130 buffer->index_buffer = new_buffer;
131 index_pos = 0;
133 else if (buffer->index_size - index_count < index_pos)
135 index_pos = 0;
138 box.left = index_pos * sizeof(*indices);
139 box.right = (index_pos + index_count) * sizeof(*indices);
140 if (FAILED(hr = wined3d_resource_map(wined3d_buffer_get_resource(buffer->index_buffer), 0, &map_desc,
141 &box, WINED3D_MAP_WRITE | (index_pos ? WINED3D_MAP_NOOVERWRITE : WINED3D_MAP_DISCARD))))
142 return hr;
143 indices = map_desc.data;
145 for (i = 0; i < count; ++i)
147 D3DTRIANGLE *ci = (D3DTRIANGLE *)instr;
148 TRACE(" v1: %d v2: %d v3: %d\n",ci->u1.v1, ci->u2.v2, ci->u3.v3);
149 TRACE(" Flags : ");
150 if (TRACE_ON(ddraw))
152 /* Wireframe */
153 if (ci->wFlags & D3DTRIFLAG_EDGEENABLE1)
154 TRACE("EDGEENABLE1 ");
155 if (ci->wFlags & D3DTRIFLAG_EDGEENABLE2)
156 TRACE("EDGEENABLE2 ");
157 if (ci->wFlags & D3DTRIFLAG_EDGEENABLE1)
158 TRACE("EDGEENABLE3 ");
159 /* Strips / Fans */
160 if (ci->wFlags == D3DTRIFLAG_EVEN)
161 TRACE("EVEN ");
162 if (ci->wFlags == D3DTRIFLAG_ODD)
163 TRACE("ODD ");
164 if (ci->wFlags == D3DTRIFLAG_START)
165 TRACE("START ");
166 if ((ci->wFlags > 0) && (ci->wFlags < 30))
167 TRACE("STARTFLAT(%u) ", ci->wFlags);
168 TRACE("\n");
171 switch (primitive_size)
173 case 3:
174 indices[(i * primitive_size) + 2] = ci->u3.v3;
175 /* Drop through. */
176 case 2:
177 indices[(i * primitive_size) + 1] = ci->u2.v2;
178 indices[(i * primitive_size) ] = ci->u1.v1;
180 instr += size;
183 wined3d_resource_unmap(wined3d_buffer_get_resource(buffer->index_buffer), 0);
185 wined3d_device_set_stream_source(device->wined3d_device, 0,
186 buffer->dst_vertex_buffer, 0, sizeof(D3DTLVERTEX));
187 wined3d_device_set_vertex_declaration(device->wined3d_device,
188 ddraw_find_decl(device->ddraw, D3DFVF_TLVERTEX));
189 wined3d_device_set_index_buffer(device->wined3d_device, buffer->index_buffer, WINED3DFMT_R16_UINT, 0);
190 wined3d_device_draw_indexed_primitive(device->wined3d_device, index_pos, index_count);
192 buffer->index_pos = index_pos + index_count;
193 break;
196 case D3DOP_MATRIXLOAD:
197 WARN("MATRIXLOAD-s (%u)\n", count);
198 instr += count * size;
199 break;
201 case D3DOP_MATRIXMULTIPLY:
202 TRACE("MATRIXMULTIPLY (%d)\n", count);
203 for (i = 0; i < count; ++i)
205 D3DMATRIXMULTIPLY *ci = (D3DMATRIXMULTIPLY *)instr;
206 D3DMATRIX *a, *b, *c;
208 a = ddraw_get_object(&device->handle_table, ci->hDestMatrix - 1, DDRAW_HANDLE_MATRIX);
209 b = ddraw_get_object(&device->handle_table, ci->hSrcMatrix1 - 1, DDRAW_HANDLE_MATRIX);
210 c = ddraw_get_object(&device->handle_table, ci->hSrcMatrix2 - 1, DDRAW_HANDLE_MATRIX);
212 if (!a || !b || !c)
214 ERR("Invalid matrix handle (a %#x -> %p, b %#x -> %p, c %#x -> %p).\n",
215 ci->hDestMatrix, a, ci->hSrcMatrix1, b, ci->hSrcMatrix2, c);
217 else
219 TRACE("dst %p, src1 %p, src2 %p.\n", a, b, c);
220 multiply_matrix(a, c, b);
223 instr += size;
225 break;
227 case D3DOP_STATETRANSFORM:
228 TRACE("STATETRANSFORM (%d)\n", count);
229 for (i = 0; i < count; ++i)
231 D3DSTATE *ci = (D3DSTATE *)instr;
232 D3DMATRIX *m;
234 m = ddraw_get_object(&device->handle_table, ci->u2.dwArg[0] - 1, DDRAW_HANDLE_MATRIX);
235 if (!m)
237 ERR("Invalid matrix handle %#x.\n", ci->u2.dwArg[0]);
239 else
241 if (ci->u1.dtstTransformStateType == D3DTRANSFORMSTATE_WORLD)
242 device->world = ci->u2.dwArg[0];
243 if (ci->u1.dtstTransformStateType == D3DTRANSFORMSTATE_VIEW)
244 device->view = ci->u2.dwArg[0];
245 if (ci->u1.dtstTransformStateType == D3DTRANSFORMSTATE_PROJECTION)
246 device->proj = ci->u2.dwArg[0];
247 IDirect3DDevice3_SetTransform(&device->IDirect3DDevice3_iface,
248 ci->u1.dtstTransformStateType, m);
251 instr += size;
253 break;
255 case D3DOP_STATELIGHT:
256 TRACE("STATELIGHT (%d)\n", count);
257 for (i = 0; i < count; ++i)
259 D3DSTATE *ci = (D3DSTATE *)instr;
261 if (FAILED(IDirect3DDevice3_SetLightState(&device->IDirect3DDevice3_iface,
262 ci->u1.dlstLightStateType, ci->u2.dwArg[0])))
263 WARN("Failed to set light state.\n");
265 instr += size;
267 break;
269 case D3DOP_STATERENDER:
270 TRACE("STATERENDER (%d)\n", count);
271 for (i = 0; i < count; ++i)
273 D3DSTATE *ci = (D3DSTATE *)instr;
275 if (FAILED(IDirect3DDevice3_SetRenderState(&device->IDirect3DDevice3_iface,
276 ci->u1.drstRenderStateType, ci->u2.dwArg[0])))
277 WARN("Failed to set render state.\n");
279 instr += size;
281 break;
283 case D3DOP_PROCESSVERTICES:
284 TRACE("PROCESSVERTICES (%d)\n", count);
286 for (i = 0; i < count; ++i)
288 D3DPROCESSVERTICES *ci = (D3DPROCESSVERTICES *)instr;
289 DWORD op = ci->dwFlags & D3DPROCESSVERTICES_OPMASK;
291 TRACE(" start %u, dest %u, count %u, flags %#x.\n",
292 ci->wStart, ci->wDest, ci->dwCount, ci->dwFlags);
294 if (ci->dwFlags & D3DPROCESSVERTICES_UPDATEEXTENTS)
295 FIXME("D3DPROCESSVERTICES_UPDATEEXTENTS not implemented.\n");
296 if (ci->dwFlags & D3DPROCESSVERTICES_NOCOLOR)
297 FIXME("D3DPROCESSVERTICES_NOCOLOR not implemented.\n");
299 switch (op)
301 case D3DPROCESSVERTICES_TRANSFORMLIGHT:
302 case D3DPROCESSVERTICES_TRANSFORM:
303 wined3d_device_set_stream_source(device->wined3d_device, 0,
304 buffer->src_vertex_buffer, buffer->src_vertex_pos * sizeof(D3DVERTEX), sizeof(D3DVERTEX));
305 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_LIGHTING,
306 op == D3DPROCESSVERTICES_TRANSFORMLIGHT && !!device->material);
307 wined3d_device_set_vertex_declaration(device->wined3d_device,
308 ddraw_find_decl(device->ddraw, op == D3DPROCESSVERTICES_TRANSFORMLIGHT
309 ? D3DFVF_VERTEX : D3DFVF_LVERTEX));
310 wined3d_device_process_vertices(device->wined3d_device, ci->wStart, ci->wDest,
311 ci->dwCount, buffer->dst_vertex_buffer, NULL, 0, D3DFVF_TLVERTEX);
312 break;
314 case D3DPROCESSVERTICES_COPY:
315 box.left = (buffer->src_vertex_pos + ci->wStart) * sizeof(D3DTLVERTEX);
316 box.right = box.left + ci->dwCount * sizeof(D3DTLVERTEX);
317 box.top = box.front = 0;
318 box.bottom = box.back = 1;
319 wined3d_device_copy_sub_resource_region(device->wined3d_device,
320 wined3d_buffer_get_resource(buffer->dst_vertex_buffer), 0,
321 ci->wDest * sizeof(D3DTLVERTEX), 0, 0,
322 wined3d_buffer_get_resource(buffer->src_vertex_buffer), 0, &box, 0);
323 break;
325 default:
326 FIXME("Unhandled vertex processing op %#x.\n", op);
327 break;
330 instr += size;
332 break;
334 case D3DOP_TEXTURELOAD:
335 TRACE("TEXTURELOAD (%u)\n", count);
337 for (i = 0; i < count; ++i)
339 D3DTEXTURELOAD *ci = (D3DTEXTURELOAD *)instr;
340 struct ddraw_surface *dst, *src;
342 instr += size;
344 if (!(dst = ddraw_get_object(&device->handle_table,
345 ci->hDestTexture - 1, DDRAW_HANDLE_SURFACE)))
347 WARN("Invalid destination texture handle %#x.\n", ci->hDestTexture);
348 continue;
350 if (!(src = ddraw_get_object(&device->handle_table,
351 ci->hSrcTexture - 1, DDRAW_HANDLE_SURFACE)))
353 WARN("Invalid source texture handle %#x.\n", ci->hSrcTexture);
354 continue;
357 IDirect3DTexture2_Load(&dst->IDirect3DTexture2_iface, &src->IDirect3DTexture2_iface);
359 break;
361 case D3DOP_EXIT:
362 TRACE("EXIT (%u)\n", count);
363 instr += size;
364 goto end_of_buffer;
366 case D3DOP_BRANCHFORWARD:
367 TRACE("BRANCHFORWARD (%d)\n", count);
368 for (i = 0; i < count; ++i)
370 D3DBRANCH *ci = (D3DBRANCH *)instr;
372 if ((buffer->data.dsStatus.dwStatus & ci->dwMask) == ci->dwValue)
374 if (!ci->bNegate)
376 TRACE(" Branch to %d\n", ci->dwOffset);
377 if (ci->dwOffset) {
378 instr = (char*)current + ci->dwOffset;
379 break;
383 else
385 if (ci->bNegate)
387 TRACE(" Branch to %d\n", ci->dwOffset);
388 if (ci->dwOffset) {
389 instr = (char*)current + ci->dwOffset;
390 break;
395 instr += size;
397 break;
399 case D3DOP_SPAN:
400 WARN("SPAN-s (%u)\n", count);
401 instr += count * size;
402 break;
404 case D3DOP_SETSTATUS:
405 TRACE("SETSTATUS (%d)\n", count);
406 for (i = 0; i < count; ++i)
408 buffer->data.dsStatus = *(D3DSTATUS *)instr;
409 instr += size;
411 break;
413 default:
414 ERR("Unhandled OpCode %#x.\n",current->bOpcode);
415 instr += count * size;
416 break;
420 end_of_buffer:
421 return D3D_OK;
424 static inline struct d3d_execute_buffer *impl_from_IDirect3DExecuteBuffer(IDirect3DExecuteBuffer *iface)
426 return CONTAINING_RECORD(iface, struct d3d_execute_buffer, IDirect3DExecuteBuffer_iface);
429 static HRESULT WINAPI d3d_execute_buffer_QueryInterface(IDirect3DExecuteBuffer *iface, REFIID iid, void **out)
431 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
433 if (IsEqualGUID(&IID_IDirect3DExecuteBuffer, iid)
434 || IsEqualGUID(&IID_IUnknown, iid))
436 IDirect3DExecuteBuffer_AddRef(iface);
437 *out = iface;
438 return S_OK;
441 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
443 *out = NULL;
444 return E_NOINTERFACE;
447 /*****************************************************************************
448 * IDirect3DExecuteBuffer::AddRef
450 * A normal AddRef method, nothing special
452 * Returns:
453 * The new refcount
455 *****************************************************************************/
456 static ULONG WINAPI d3d_execute_buffer_AddRef(IDirect3DExecuteBuffer *iface)
458 struct d3d_execute_buffer *buffer = impl_from_IDirect3DExecuteBuffer(iface);
459 ULONG ref = InterlockedIncrement(&buffer->ref);
461 TRACE("%p increasing refcount to %u.\n", buffer, ref);
463 return ref;
466 /*****************************************************************************
467 * IDirect3DExecuteBuffer::Release
469 * A normal Release method, nothing special
471 * Returns:
472 * The new refcount
474 *****************************************************************************/
475 static ULONG WINAPI d3d_execute_buffer_Release(IDirect3DExecuteBuffer *iface)
477 struct d3d_execute_buffer *buffer = impl_from_IDirect3DExecuteBuffer(iface);
478 ULONG ref = InterlockedDecrement(&buffer->ref);
480 TRACE("%p decreasing refcount to %u.\n", buffer, ref);
482 if (!ref)
484 if (buffer->need_free)
485 heap_free(buffer->desc.lpData);
486 if (buffer->index_buffer)
487 wined3d_buffer_decref(buffer->index_buffer);
488 if (buffer->dst_vertex_buffer)
490 wined3d_buffer_decref(buffer->src_vertex_buffer);
491 wined3d_buffer_decref(buffer->dst_vertex_buffer);
493 heap_free(buffer);
496 return ref;
499 /*****************************************************************************
500 * IDirect3DExecuteBuffer::Initialize
502 * Initializes the Execute Buffer. This method exists for COM compliance
503 * Nothing to do here.
505 * Returns:
506 * D3D_OK
508 *****************************************************************************/
509 static HRESULT WINAPI d3d_execute_buffer_Initialize(IDirect3DExecuteBuffer *iface,
510 IDirect3DDevice *device, D3DEXECUTEBUFFERDESC *desc)
512 TRACE("iface %p, device %p, desc %p.\n", iface, device, desc);
514 return D3D_OK;
517 /*****************************************************************************
518 * IDirect3DExecuteBuffer::Lock
520 * Locks the buffer, so the app can write into it.
522 * Params:
523 * Desc: Pointer to return the buffer description. This Description contains
524 * a pointer to the buffer data.
526 * Returns:
527 * This implementation always returns D3D_OK
529 *****************************************************************************/
530 static HRESULT WINAPI d3d_execute_buffer_Lock(IDirect3DExecuteBuffer *iface, D3DEXECUTEBUFFERDESC *desc)
532 struct d3d_execute_buffer *buffer = impl_from_IDirect3DExecuteBuffer(iface);
533 DWORD dwSize;
535 TRACE("iface %p, desc %p.\n", iface, desc);
537 dwSize = desc->dwSize;
538 memcpy(desc, &buffer->desc, dwSize);
540 if (TRACE_ON(ddraw))
542 TRACE(" Returning description :\n");
543 _dump_D3DEXECUTEBUFFERDESC(desc);
545 return D3D_OK;
548 /*****************************************************************************
549 * IDirect3DExecuteBuffer::Unlock
551 * Unlocks the buffer. We don't have anything to do here
553 * Returns:
554 * This implementation always returns D3D_OK
556 *****************************************************************************/
557 static HRESULT WINAPI d3d_execute_buffer_Unlock(IDirect3DExecuteBuffer *iface)
559 TRACE("iface %p.\n", iface);
561 return D3D_OK;
564 /*****************************************************************************
565 * IDirect3DExecuteBuffer::SetExecuteData
567 * Sets the execute data. This data is used to describe the buffer's content
569 * Params:
570 * Data: Pointer to a D3DEXECUTEDATA structure containing the data to
571 * assign
573 * Returns:
574 * D3D_OK on success
575 * DDERR_OUTOFMEMORY if the vertex buffer allocation failed
577 *****************************************************************************/
578 static HRESULT WINAPI d3d_execute_buffer_SetExecuteData(IDirect3DExecuteBuffer *iface, D3DEXECUTEDATA *data)
580 struct d3d_execute_buffer *buffer = impl_from_IDirect3DExecuteBuffer(iface);
581 struct wined3d_map_desc map_desc;
582 struct wined3d_box box = {0};
583 HRESULT hr;
584 DWORD buf_size = buffer->desc.dwBufferSize, copy_size;
586 TRACE("iface %p, data %p.\n", iface, data);
588 if (data->dwSize != sizeof(*data))
590 WARN("data->dwSize is %u, returning DDERR_INVALIDPARAMS.\n", data->dwSize);
591 return DDERR_INVALIDPARAMS;
594 /* Skip past previous vertex data. */
595 buffer->src_vertex_pos += buffer->data.dwVertexCount;
597 if (buffer->vertex_size < data->dwVertexCount)
599 unsigned int new_size = max(data->dwVertexCount, buffer->vertex_size * 2);
600 struct wined3d_buffer *src_buffer, *dst_buffer;
601 struct wined3d_buffer_desc desc;
603 desc.byte_width = new_size * sizeof(D3DVERTEX);
604 desc.usage = 0;
605 desc.bind_flags = WINED3D_BIND_VERTEX_BUFFER;
606 desc.access = WINED3D_RESOURCE_ACCESS_CPU | WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W;
607 desc.misc_flags = 0;
608 desc.structure_byte_stride = 0;
610 if (FAILED(hr = wined3d_buffer_create(buffer->d3ddev->wined3d_device, &desc,
611 NULL, NULL, &ddraw_null_wined3d_parent_ops, &src_buffer)))
612 return hr;
614 desc.byte_width = new_size * sizeof(D3DTLVERTEX);
615 desc.usage = WINED3DUSAGE_STATICDECL;
616 desc.access = WINED3D_RESOURCE_ACCESS_GPU | WINED3D_RESOURCE_ACCESS_MAP_W;
618 if (FAILED(hr = wined3d_buffer_create(buffer->d3ddev->wined3d_device, &desc,
619 NULL, NULL, &ddraw_null_wined3d_parent_ops, &dst_buffer)))
621 wined3d_buffer_decref(src_buffer);
622 return hr;
625 if (buffer->dst_vertex_buffer)
627 wined3d_buffer_decref(buffer->src_vertex_buffer);
628 wined3d_buffer_decref(buffer->dst_vertex_buffer);
630 buffer->src_vertex_buffer = src_buffer;
631 buffer->dst_vertex_buffer = dst_buffer;
632 buffer->vertex_size = new_size;
633 buffer->src_vertex_pos = 0;
635 else if (buffer->vertex_size - data->dwVertexCount < buffer->src_vertex_pos)
637 buffer->src_vertex_pos = 0;
640 if (data->dwVertexCount && (!buf_size || data->dwVertexOffset < buf_size))
642 box.left = buffer->src_vertex_pos * sizeof(D3DVERTEX);
643 box.right = box.left + data->dwVertexCount * sizeof(D3DVERTEX);
644 if (FAILED(hr = wined3d_resource_map(wined3d_buffer_get_resource(buffer->src_vertex_buffer),
645 0, &map_desc, &box, WINED3D_MAP_WRITE)))
646 return hr;
648 copy_size = data->dwVertexCount * sizeof(D3DVERTEX);
649 if (buf_size)
650 copy_size = min(copy_size, buf_size - data->dwVertexOffset);
652 memcpy(map_desc.data, ((BYTE *)buffer->desc.lpData) + data->dwVertexOffset, copy_size);
654 wined3d_resource_unmap(wined3d_buffer_get_resource(buffer->src_vertex_buffer), 0);
657 memcpy(&buffer->data, data, data->dwSize);
659 if (TRACE_ON(ddraw))
660 _dump_executedata(data);
662 return D3D_OK;
665 /*****************************************************************************
666 * IDirect3DExecuteBuffer::GetExecuteData
668 * Returns the data in the execute buffer
670 * Params:
671 * Data: Pointer to a D3DEXECUTEDATA structure used to return data
673 * Returns:
674 * D3D_OK on success
676 *****************************************************************************/
677 static HRESULT WINAPI d3d_execute_buffer_GetExecuteData(IDirect3DExecuteBuffer *iface, D3DEXECUTEDATA *data)
679 struct d3d_execute_buffer *buffer = impl_from_IDirect3DExecuteBuffer(iface);
681 TRACE("iface %p, data %p.\n", iface, data);
683 /* Tests show that dwSize is ignored. */
684 memcpy(data, &buffer->data, sizeof(*data));
686 if (TRACE_ON(ddraw))
688 TRACE("Returning data :\n");
689 _dump_executedata(data);
692 return DD_OK;
695 /*****************************************************************************
696 * IDirect3DExecuteBuffer::Validate
698 * DirectX 5 SDK: "The IDirect3DExecuteBuffer::Validate method is not
699 * currently implemented"
701 * Params:
704 * Returns:
705 * DDERR_UNSUPPORTED, because it's not implemented in Windows.
707 *****************************************************************************/
708 static HRESULT WINAPI d3d_execute_buffer_Validate(IDirect3DExecuteBuffer *iface,
709 DWORD *offset, LPD3DVALIDATECALLBACK callback, void *context, DWORD reserved)
711 TRACE("iface %p, offset %p, callback %p, context %p, reserved %#x.\n",
712 iface, offset, callback, context, reserved);
714 WARN("Not implemented.\n");
716 return DDERR_UNSUPPORTED; /* Unchecked */
719 /*****************************************************************************
720 * IDirect3DExecuteBuffer::Optimize
722 * DirectX5 SDK: "The IDirect3DExecuteBuffer::Optimize method is not
723 * currently supported"
725 * Params:
726 * Dummy: Seems to be an unused dummy ;)
728 * Returns:
729 * DDERR_UNSUPPORTED, because it's not implemented in Windows.
731 *****************************************************************************/
732 static HRESULT WINAPI d3d_execute_buffer_Optimize(IDirect3DExecuteBuffer *iface, DWORD reserved)
734 TRACE("iface %p, reserved %#x.\n", iface, reserved);
736 WARN("Not implemented.\n");
738 return DDERR_UNSUPPORTED; /* Unchecked */
741 static const struct IDirect3DExecuteBufferVtbl d3d_execute_buffer_vtbl =
743 d3d_execute_buffer_QueryInterface,
744 d3d_execute_buffer_AddRef,
745 d3d_execute_buffer_Release,
746 d3d_execute_buffer_Initialize,
747 d3d_execute_buffer_Lock,
748 d3d_execute_buffer_Unlock,
749 d3d_execute_buffer_SetExecuteData,
750 d3d_execute_buffer_GetExecuteData,
751 d3d_execute_buffer_Validate,
752 d3d_execute_buffer_Optimize,
755 HRESULT d3d_execute_buffer_init(struct d3d_execute_buffer *execute_buffer,
756 struct d3d_device *device, D3DEXECUTEBUFFERDESC *desc)
758 execute_buffer->IDirect3DExecuteBuffer_iface.lpVtbl = &d3d_execute_buffer_vtbl;
759 execute_buffer->ref = 1;
760 execute_buffer->d3ddev = device;
762 /* Initializes memory */
763 memcpy(&execute_buffer->desc, desc, desc->dwSize);
765 /* No buffer given */
766 if (!(execute_buffer->desc.dwFlags & D3DDEB_LPDATA))
767 execute_buffer->desc.lpData = NULL;
769 /* No buffer size given */
770 if (!(execute_buffer->desc.dwFlags & D3DDEB_BUFSIZE))
771 execute_buffer->desc.dwBufferSize = 0;
773 /* Create buffer if asked */
774 if (!execute_buffer->desc.lpData && execute_buffer->desc.dwBufferSize)
776 execute_buffer->need_free = TRUE;
777 if (!(execute_buffer->desc.lpData = heap_alloc_zero(execute_buffer->desc.dwBufferSize)))
779 ERR("Failed to allocate execute buffer data.\n");
780 return DDERR_OUTOFMEMORY;
784 execute_buffer->desc.dwFlags |= D3DDEB_LPDATA;
786 return D3D_OK;
789 struct d3d_execute_buffer *unsafe_impl_from_IDirect3DExecuteBuffer(IDirect3DExecuteBuffer *iface)
791 if (!iface)
792 return NULL;
793 assert(iface->lpVtbl == &d3d_execute_buffer_vtbl);
795 return impl_from_IDirect3DExecuteBuffer(iface);