ddraw: Use wined3d_buffer_create() in d3d_execute_buffer_SetExecuteData().
[wine.git] / dlls / ddraw / executebuffer.c
blobb1afcf5c2d288d167e1d4c962c43f34e8c5bbb5a
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 "config.h"
22 #include "wine/port.h"
24 #include "ddraw_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
28 /*****************************************************************************
29 * _dump_executedata
30 * _dump_D3DEXECUTEBUFFERDESC
32 * Debug functions which write the executebuffer data to the console
34 *****************************************************************************/
36 static void _dump_executedata(const D3DEXECUTEDATA *lpData) {
37 TRACE("dwSize : %d\n", lpData->dwSize);
38 TRACE("Vertex Offset : %d Count : %d\n", lpData->dwVertexOffset, lpData->dwVertexCount);
39 TRACE("Instruction Offset : %d Length : %d\n", lpData->dwInstructionOffset, lpData->dwInstructionLength);
40 TRACE("HVertex Offset : %d\n", lpData->dwHVertexOffset);
43 static void _dump_D3DEXECUTEBUFFERDESC(const D3DEXECUTEBUFFERDESC *lpDesc) {
44 TRACE("dwSize : %d\n", lpDesc->dwSize);
45 TRACE("dwFlags : %x\n", lpDesc->dwFlags);
46 TRACE("dwCaps : %x\n", lpDesc->dwCaps);
47 TRACE("dwBufferSize : %d\n", lpDesc->dwBufferSize);
48 TRACE("lpData : %p\n", lpDesc->lpData);
51 HRESULT d3d_execute_buffer_execute(struct d3d_execute_buffer *buffer,
52 struct d3d_device *device, struct d3d_viewport *viewport)
54 DWORD is = buffer->data.dwInstructionOffset;
55 char *instr = (char *)buffer->desc.lpData + is;
56 unsigned int i, primitive_size;
57 struct wined3d_map_desc map_desc;
58 struct wined3d_box box = {0};
59 HRESULT hr;
61 if (viewport->active_device != device)
63 WARN("Viewport %p active device is %p.\n",
64 viewport, viewport->active_device);
65 return DDERR_INVALIDPARAMS;
68 /* Activate the viewport */
69 viewport_activate(viewport, FALSE);
71 TRACE("ExecuteData :\n");
72 if (TRACE_ON(ddraw))
73 _dump_executedata(&(buffer->data));
75 for (;;)
77 D3DINSTRUCTION *current = (D3DINSTRUCTION *)instr;
78 BYTE size;
79 WORD count;
81 count = current->wCount;
82 size = current->bSize;
83 instr += sizeof(*current);
84 primitive_size = 0;
86 switch (current->bOpcode)
88 case D3DOP_POINT:
90 const D3DPOINT *p = (D3DPOINT *)instr;
91 wined3d_device_set_primitive_type(device->wined3d_device, WINED3D_PT_POINTLIST, 0);
92 wined3d_device_set_stream_source(device->wined3d_device, 0,
93 buffer->dst_vertex_buffer, 0, sizeof(D3DTLVERTEX));
94 wined3d_device_set_vertex_declaration(device->wined3d_device,
95 ddraw_find_decl(device->ddraw, D3DFVF_TLVERTEX));
97 for (i = 0; i < count; ++i)
98 wined3d_device_draw_primitive(device->wined3d_device, p[i].wFirst, p[i].wCount);
100 instr += sizeof(*p) * count;
101 break;
104 case D3DOP_LINE:
105 primitive_size = 2;
106 wined3d_device_set_primitive_type(device->wined3d_device, WINED3D_PT_LINELIST, 0);
107 /* Drop through. */
108 case D3DOP_TRIANGLE:
110 WORD *indices;
111 unsigned int index_pos = buffer->index_pos, index_count;
112 TRACE("TRIANGLE (%d)\n", count);
114 if (!count)
115 break;
117 if (!primitive_size)
119 wined3d_device_set_primitive_type(device->wined3d_device, WINED3D_PT_TRIANGLELIST, 0);
120 primitive_size = 3;
123 index_count = count * primitive_size;
125 if (buffer->index_size < index_count)
127 unsigned int new_size = max(buffer->index_size * 2, index_count);
128 struct wined3d_buffer *new_buffer;
129 struct wined3d_buffer_desc desc;
131 desc.byte_width = new_size * sizeof(*indices);
132 desc.usage = WINED3DUSAGE_DYNAMIC | WINED3DUSAGE_WRITEONLY | WINED3DUSAGE_STATICDECL;
133 desc.bind_flags = WINED3D_BIND_INDEX_BUFFER;
134 desc.access = WINED3D_RESOURCE_ACCESS_GPU;
135 desc.misc_flags = 0;
136 desc.structure_byte_stride = 0;
138 if (FAILED(hr = wined3d_buffer_create(device->wined3d_device, &desc,
139 NULL, NULL, &ddraw_null_wined3d_parent_ops, &new_buffer)))
140 return hr;
142 buffer->index_size = new_size;
143 if (buffer->index_buffer)
144 wined3d_buffer_decref(buffer->index_buffer);
145 buffer->index_buffer = new_buffer;
146 index_pos = 0;
148 else if (buffer->index_size - index_count < index_pos)
150 index_pos = 0;
153 box.left = index_pos * sizeof(*indices);
154 box.right = (index_pos + index_count) * sizeof(*indices);
155 hr = wined3d_resource_map(wined3d_buffer_get_resource(buffer->index_buffer), 0,
156 &map_desc, &box, index_pos ? WINED3D_MAP_NOOVERWRITE : WINED3D_MAP_DISCARD);
157 if (FAILED(hr))
158 return hr;
159 indices = map_desc.data;
161 for (i = 0; i < count; ++i)
163 D3DTRIANGLE *ci = (D3DTRIANGLE *)instr;
164 TRACE(" v1: %d v2: %d v3: %d\n",ci->u1.v1, ci->u2.v2, ci->u3.v3);
165 TRACE(" Flags : ");
166 if (TRACE_ON(ddraw))
168 /* Wireframe */
169 if (ci->wFlags & D3DTRIFLAG_EDGEENABLE1)
170 TRACE("EDGEENABLE1 ");
171 if (ci->wFlags & D3DTRIFLAG_EDGEENABLE2)
172 TRACE("EDGEENABLE2 ");
173 if (ci->wFlags & D3DTRIFLAG_EDGEENABLE1)
174 TRACE("EDGEENABLE3 ");
175 /* Strips / Fans */
176 if (ci->wFlags == D3DTRIFLAG_EVEN)
177 TRACE("EVEN ");
178 if (ci->wFlags == D3DTRIFLAG_ODD)
179 TRACE("ODD ");
180 if (ci->wFlags == D3DTRIFLAG_START)
181 TRACE("START ");
182 if ((ci->wFlags > 0) && (ci->wFlags < 30))
183 TRACE("STARTFLAT(%u) ", ci->wFlags);
184 TRACE("\n");
187 switch (primitive_size)
189 case 3:
190 indices[(i * primitive_size) + 2] = ci->u3.v3;
191 /* Drop through. */
192 case 2:
193 indices[(i * primitive_size) + 1] = ci->u2.v2;
194 indices[(i * primitive_size) ] = ci->u1.v1;
196 instr += size;
199 wined3d_resource_unmap(wined3d_buffer_get_resource(buffer->index_buffer), 0);
201 wined3d_device_set_stream_source(device->wined3d_device, 0,
202 buffer->dst_vertex_buffer, 0, sizeof(D3DTLVERTEX));
203 wined3d_device_set_vertex_declaration(device->wined3d_device,
204 ddraw_find_decl(device->ddraw, D3DFVF_TLVERTEX));
205 wined3d_device_set_index_buffer(device->wined3d_device, buffer->index_buffer, WINED3DFMT_R16_UINT, 0);
206 wined3d_device_draw_indexed_primitive(device->wined3d_device, index_pos, index_count);
208 buffer->index_pos = index_pos + index_count;
209 break;
212 case D3DOP_MATRIXLOAD:
213 WARN("MATRIXLOAD-s (%u)\n", count);
214 instr += count * size;
215 break;
217 case D3DOP_MATRIXMULTIPLY:
218 TRACE("MATRIXMULTIPLY (%d)\n", count);
219 for (i = 0; i < count; ++i)
221 D3DMATRIXMULTIPLY *ci = (D3DMATRIXMULTIPLY *)instr;
222 D3DMATRIX *a, *b, *c;
224 a = ddraw_get_object(&device->handle_table, ci->hDestMatrix - 1, DDRAW_HANDLE_MATRIX);
225 b = ddraw_get_object(&device->handle_table, ci->hSrcMatrix1 - 1, DDRAW_HANDLE_MATRIX);
226 c = ddraw_get_object(&device->handle_table, ci->hSrcMatrix2 - 1, DDRAW_HANDLE_MATRIX);
228 if (!a || !b || !c)
230 ERR("Invalid matrix handle (a %#x -> %p, b %#x -> %p, c %#x -> %p).\n",
231 ci->hDestMatrix, a, ci->hSrcMatrix1, b, ci->hSrcMatrix2, c);
233 else
235 TRACE("dst %p, src1 %p, src2 %p.\n", a, b, c);
236 multiply_matrix(a, c, b);
239 instr += size;
241 break;
243 case D3DOP_STATETRANSFORM:
244 TRACE("STATETRANSFORM (%d)\n", count);
245 for (i = 0; i < count; ++i)
247 D3DSTATE *ci = (D3DSTATE *)instr;
248 D3DMATRIX *m;
250 m = ddraw_get_object(&device->handle_table, ci->u2.dwArg[0] - 1, DDRAW_HANDLE_MATRIX);
251 if (!m)
253 ERR("Invalid matrix handle %#x.\n", ci->u2.dwArg[0]);
255 else
257 if (ci->u1.dtstTransformStateType == D3DTRANSFORMSTATE_WORLD)
258 device->world = ci->u2.dwArg[0];
259 if (ci->u1.dtstTransformStateType == D3DTRANSFORMSTATE_VIEW)
260 device->view = ci->u2.dwArg[0];
261 if (ci->u1.dtstTransformStateType == D3DTRANSFORMSTATE_PROJECTION)
262 device->proj = ci->u2.dwArg[0];
263 IDirect3DDevice3_SetTransform(&device->IDirect3DDevice3_iface,
264 ci->u1.dtstTransformStateType, m);
267 instr += size;
269 break;
271 case D3DOP_STATELIGHT:
272 TRACE("STATELIGHT (%d)\n", count);
273 for (i = 0; i < count; ++i)
275 D3DSTATE *ci = (D3DSTATE *)instr;
277 if (FAILED(IDirect3DDevice3_SetLightState(&device->IDirect3DDevice3_iface,
278 ci->u1.dlstLightStateType, ci->u2.dwArg[0])))
279 WARN("Failed to set light state.\n");
281 instr += size;
283 break;
285 case D3DOP_STATERENDER:
286 TRACE("STATERENDER (%d)\n", count);
287 for (i = 0; i < count; ++i)
289 D3DSTATE *ci = (D3DSTATE *)instr;
291 if (FAILED(IDirect3DDevice3_SetRenderState(&device->IDirect3DDevice3_iface,
292 ci->u1.drstRenderStateType, ci->u2.dwArg[0])))
293 WARN("Failed to set render state.\n");
295 instr += size;
297 break;
299 case D3DOP_PROCESSVERTICES:
300 TRACE("PROCESSVERTICES (%d)\n", count);
302 for (i = 0; i < count; ++i)
304 D3DPROCESSVERTICES *ci = (D3DPROCESSVERTICES *)instr;
305 DWORD op = ci->dwFlags & D3DPROCESSVERTICES_OPMASK;
307 TRACE(" start %u, dest %u, count %u, flags %#x.\n",
308 ci->wStart, ci->wDest, ci->dwCount, ci->dwFlags);
310 if (ci->dwFlags & D3DPROCESSVERTICES_UPDATEEXTENTS)
311 FIXME("D3DPROCESSVERTICES_UPDATEEXTENTS not implemented.\n");
312 if (ci->dwFlags & D3DPROCESSVERTICES_NOCOLOR)
313 FIXME("D3DPROCESSVERTICES_NOCOLOR not implemented.\n");
315 switch (op)
317 case D3DPROCESSVERTICES_TRANSFORMLIGHT:
318 case D3DPROCESSVERTICES_TRANSFORM:
319 wined3d_device_set_stream_source(device->wined3d_device, 0,
320 buffer->src_vertex_buffer, buffer->src_vertex_pos, sizeof(D3DVERTEX));
321 if (op == D3DPROCESSVERTICES_TRANSFORMLIGHT)
323 wined3d_device_set_vertex_declaration(device->wined3d_device,
324 ddraw_find_decl(device->ddraw, D3DFVF_VERTEX));
325 wined3d_device_set_render_state(device->wined3d_device,
326 WINED3D_RS_LIGHTING, TRUE);
328 else
330 wined3d_device_set_vertex_declaration(device->wined3d_device,
331 ddraw_find_decl(device->ddraw, D3DFVF_LVERTEX));
332 wined3d_device_set_render_state(device->wined3d_device,
333 WINED3D_RS_LIGHTING, FALSE);
336 wined3d_device_process_vertices(device->wined3d_device, ci->wStart, ci->wDest,
337 ci->dwCount, buffer->dst_vertex_buffer, NULL, 0, D3DFVF_TLVERTEX);
338 break;
340 case D3DPROCESSVERTICES_COPY:
341 box.left = (buffer->src_vertex_pos + ci->wStart) * sizeof(D3DTLVERTEX);
342 box.right = box.left + ci->dwCount * sizeof(D3DTLVERTEX);
343 box.top = box.front = 0;
344 box.bottom = box.back = 1;
345 wined3d_device_copy_sub_resource_region(device->wined3d_device,
346 wined3d_buffer_get_resource(buffer->dst_vertex_buffer), 0,
347 ci->wDest * sizeof(D3DTLVERTEX), 0, 0,
348 wined3d_buffer_get_resource(buffer->src_vertex_buffer), 0, &box);
349 break;
351 default:
352 FIXME("Unhandled vertex processing op %#x.\n", op);
353 break;
356 instr += size;
358 break;
360 case D3DOP_TEXTURELOAD:
361 TRACE("TEXTURELOAD (%u)\n", count);
363 for (i = 0; i < count; ++i)
365 D3DTEXTURELOAD *ci = (D3DTEXTURELOAD *)instr;
366 struct ddraw_surface *dst, *src;
368 instr += size;
370 if (!(dst = ddraw_get_object(&device->handle_table,
371 ci->hDestTexture - 1, DDRAW_HANDLE_SURFACE)))
373 WARN("Invalid destination texture handle %#x.\n", ci->hDestTexture);
374 continue;
376 if (!(src = ddraw_get_object(&device->handle_table,
377 ci->hSrcTexture - 1, DDRAW_HANDLE_SURFACE)))
379 WARN("Invalid source texture handle %#x.\n", ci->hSrcTexture);
380 continue;
383 IDirect3DTexture2_Load(&dst->IDirect3DTexture2_iface, &src->IDirect3DTexture2_iface);
385 break;
387 case D3DOP_EXIT:
388 TRACE("EXIT (%u)\n", count);
389 instr += size;
390 goto end_of_buffer;
392 case D3DOP_BRANCHFORWARD:
393 TRACE("BRANCHFORWARD (%d)\n", count);
394 for (i = 0; i < count; ++i)
396 D3DBRANCH *ci = (D3DBRANCH *)instr;
398 if ((buffer->data.dsStatus.dwStatus & ci->dwMask) == ci->dwValue)
400 if (!ci->bNegate)
402 TRACE(" Branch to %d\n", ci->dwOffset);
403 if (ci->dwOffset) {
404 instr = (char*)current + ci->dwOffset;
405 break;
409 else
411 if (ci->bNegate)
413 TRACE(" Branch to %d\n", ci->dwOffset);
414 if (ci->dwOffset) {
415 instr = (char*)current + ci->dwOffset;
416 break;
421 instr += size;
423 break;
425 case D3DOP_SPAN:
426 WARN("SPAN-s (%u)\n", count);
427 instr += count * size;
428 break;
430 case D3DOP_SETSTATUS:
431 TRACE("SETSTATUS (%d)\n", count);
432 for (i = 0; i < count; ++i)
434 buffer->data.dsStatus = *(D3DSTATUS *)instr;
435 instr += size;
437 break;
439 default:
440 ERR("Unhandled OpCode %#x.\n",current->bOpcode);
441 instr += count * size;
442 break;
446 end_of_buffer:
447 return D3D_OK;
450 static inline struct d3d_execute_buffer *impl_from_IDirect3DExecuteBuffer(IDirect3DExecuteBuffer *iface)
452 return CONTAINING_RECORD(iface, struct d3d_execute_buffer, IDirect3DExecuteBuffer_iface);
455 static HRESULT WINAPI d3d_execute_buffer_QueryInterface(IDirect3DExecuteBuffer *iface, REFIID iid, void **out)
457 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
459 if (IsEqualGUID(&IID_IDirect3DExecuteBuffer, iid)
460 || IsEqualGUID(&IID_IUnknown, iid))
462 IDirect3DExecuteBuffer_AddRef(iface);
463 *out = iface;
464 return S_OK;
467 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
469 *out = NULL;
470 return E_NOINTERFACE;
473 /*****************************************************************************
474 * IDirect3DExecuteBuffer::AddRef
476 * A normal AddRef method, nothing special
478 * Returns:
479 * The new refcount
481 *****************************************************************************/
482 static ULONG WINAPI d3d_execute_buffer_AddRef(IDirect3DExecuteBuffer *iface)
484 struct d3d_execute_buffer *buffer = impl_from_IDirect3DExecuteBuffer(iface);
485 ULONG ref = InterlockedIncrement(&buffer->ref);
487 TRACE("%p increasing refcount to %u.\n", buffer, ref);
489 return ref;
492 /*****************************************************************************
493 * IDirect3DExecuteBuffer::Release
495 * A normal Release method, nothing special
497 * Returns:
498 * The new refcount
500 *****************************************************************************/
501 static ULONG WINAPI d3d_execute_buffer_Release(IDirect3DExecuteBuffer *iface)
503 struct d3d_execute_buffer *buffer = impl_from_IDirect3DExecuteBuffer(iface);
504 ULONG ref = InterlockedDecrement(&buffer->ref);
506 TRACE("%p decreasing refcount to %u.\n", buffer, ref);
508 if (!ref)
510 if (buffer->need_free)
511 HeapFree(GetProcessHeap(), 0, buffer->desc.lpData);
512 if (buffer->index_buffer)
513 wined3d_buffer_decref(buffer->index_buffer);
514 if (buffer->dst_vertex_buffer)
516 wined3d_buffer_decref(buffer->src_vertex_buffer);
517 wined3d_buffer_decref(buffer->dst_vertex_buffer);
519 HeapFree(GetProcessHeap(), 0, buffer);
522 return ref;
525 /*****************************************************************************
526 * IDirect3DExecuteBuffer::Initialize
528 * Initializes the Execute Buffer. This method exists for COM compliance
529 * Nothing to do here.
531 * Returns:
532 * D3D_OK
534 *****************************************************************************/
535 static HRESULT WINAPI d3d_execute_buffer_Initialize(IDirect3DExecuteBuffer *iface,
536 IDirect3DDevice *device, D3DEXECUTEBUFFERDESC *desc)
538 TRACE("iface %p, device %p, desc %p.\n", iface, device, desc);
540 return D3D_OK;
543 /*****************************************************************************
544 * IDirect3DExecuteBuffer::Lock
546 * Locks the buffer, so the app can write into it.
548 * Params:
549 * Desc: Pointer to return the buffer description. This Description contains
550 * a pointer to the buffer data.
552 * Returns:
553 * This implementation always returns D3D_OK
555 *****************************************************************************/
556 static HRESULT WINAPI d3d_execute_buffer_Lock(IDirect3DExecuteBuffer *iface, D3DEXECUTEBUFFERDESC *desc)
558 struct d3d_execute_buffer *buffer = impl_from_IDirect3DExecuteBuffer(iface);
559 DWORD dwSize;
561 TRACE("iface %p, desc %p.\n", iface, desc);
563 dwSize = desc->dwSize;
564 memcpy(desc, &buffer->desc, dwSize);
566 if (TRACE_ON(ddraw))
568 TRACE(" Returning description :\n");
569 _dump_D3DEXECUTEBUFFERDESC(desc);
571 return D3D_OK;
574 /*****************************************************************************
575 * IDirect3DExecuteBuffer::Unlock
577 * Unlocks the buffer. We don't have anything to do here
579 * Returns:
580 * This implementation always returns D3D_OK
582 *****************************************************************************/
583 static HRESULT WINAPI d3d_execute_buffer_Unlock(IDirect3DExecuteBuffer *iface)
585 TRACE("iface %p.\n", iface);
587 return D3D_OK;
590 /*****************************************************************************
591 * IDirect3DExecuteBuffer::SetExecuteData
593 * Sets the execute data. This data is used to describe the buffer's content
595 * Params:
596 * Data: Pointer to a D3DEXECUTEDATA structure containing the data to
597 * assign
599 * Returns:
600 * D3D_OK on success
601 * DDERR_OUTOFMEMORY if the vertex buffer allocation failed
603 *****************************************************************************/
604 static HRESULT WINAPI d3d_execute_buffer_SetExecuteData(IDirect3DExecuteBuffer *iface, D3DEXECUTEDATA *data)
606 struct d3d_execute_buffer *buffer = impl_from_IDirect3DExecuteBuffer(iface);
607 struct wined3d_map_desc map_desc;
608 struct wined3d_box box = {0};
609 HRESULT hr;
611 TRACE("iface %p, data %p.\n", iface, data);
613 /* Skip past previous vertex data. */
614 buffer->src_vertex_pos += buffer->data.dwVertexCount;
616 if (buffer->vertex_size < data->dwVertexCount)
618 unsigned int new_size = max(data->dwVertexCount, buffer->vertex_size * 2);
619 struct wined3d_buffer *src_buffer, *dst_buffer;
620 struct wined3d_buffer_desc desc;
622 desc.byte_width = new_size * sizeof(D3DVERTEX);
623 desc.usage = WINED3DUSAGE_DYNAMIC | WINED3DUSAGE_WRITEONLY;
624 desc.bind_flags = WINED3D_BIND_VERTEX_BUFFER;
625 desc.access = WINED3D_RESOURCE_ACCESS_CPU | WINED3D_RESOURCE_ACCESS_MAP;
626 desc.misc_flags = 0;
627 desc.structure_byte_stride = 0;
629 if (FAILED(hr = wined3d_buffer_create(buffer->d3ddev->wined3d_device, &desc,
630 NULL, NULL, &ddraw_null_wined3d_parent_ops, &src_buffer)))
631 return hr;
633 desc.byte_width = new_size * sizeof(D3DTLVERTEX);
634 desc.usage = WINED3DUSAGE_STATICDECL;
635 desc.access = WINED3D_RESOURCE_ACCESS_GPU;
637 if (FAILED(hr = wined3d_buffer_create(buffer->d3ddev->wined3d_device, &desc,
638 NULL, NULL, &ddraw_null_wined3d_parent_ops, &dst_buffer)))
640 wined3d_buffer_decref(src_buffer);
641 return hr;
644 if (buffer->dst_vertex_buffer)
646 wined3d_buffer_decref(buffer->src_vertex_buffer);
647 wined3d_buffer_decref(buffer->dst_vertex_buffer);
649 buffer->src_vertex_buffer = src_buffer;
650 buffer->dst_vertex_buffer = dst_buffer;
651 buffer->vertex_size = new_size;
652 buffer->src_vertex_pos = 0;
654 else if (buffer->vertex_size - data->dwVertexCount < buffer->src_vertex_pos)
656 buffer->src_vertex_pos = 0;
659 if (data->dwVertexCount)
661 box.left = buffer->src_vertex_pos * sizeof(D3DVERTEX);
662 box.right = box.left + data->dwVertexCount * sizeof(D3DVERTEX);
663 hr = wined3d_resource_map(wined3d_buffer_get_resource(buffer->src_vertex_buffer), 0,
664 &map_desc, &box, buffer->src_vertex_pos ? WINED3D_MAP_NOOVERWRITE : WINED3D_MAP_DISCARD);
665 if (FAILED(hr))
666 return hr;
668 memcpy(map_desc.data, ((BYTE *)buffer->desc.lpData) + data->dwVertexOffset,
669 data->dwVertexCount * sizeof(D3DVERTEX));
671 wined3d_resource_unmap(wined3d_buffer_get_resource(buffer->src_vertex_buffer), 0);
674 memcpy(&buffer->data, data, data->dwSize);
676 if (TRACE_ON(ddraw))
677 _dump_executedata(data);
679 return D3D_OK;
682 /*****************************************************************************
683 * IDirect3DExecuteBuffer::GetExecuteData
685 * Returns the data in the execute buffer
687 * Params:
688 * Data: Pointer to a D3DEXECUTEDATA structure used to return data
690 * Returns:
691 * D3D_OK on success
693 *****************************************************************************/
694 static HRESULT WINAPI d3d_execute_buffer_GetExecuteData(IDirect3DExecuteBuffer *iface, D3DEXECUTEDATA *data)
696 struct d3d_execute_buffer *buffer = impl_from_IDirect3DExecuteBuffer(iface);
697 DWORD dwSize;
699 TRACE("iface %p, data %p.\n", iface, data);
701 dwSize = data->dwSize;
702 memcpy(data, &buffer->data, dwSize);
704 if (TRACE_ON(ddraw))
706 TRACE("Returning data :\n");
707 _dump_executedata(data);
710 return DD_OK;
713 /*****************************************************************************
714 * IDirect3DExecuteBuffer::Validate
716 * DirectX 5 SDK: "The IDirect3DExecuteBuffer::Validate method is not
717 * currently implemented"
719 * Params:
722 * Returns:
723 * DDERR_UNSUPPORTED, because it's not implemented in Windows.
725 *****************************************************************************/
726 static HRESULT WINAPI d3d_execute_buffer_Validate(IDirect3DExecuteBuffer *iface,
727 DWORD *offset, LPD3DVALIDATECALLBACK callback, void *context, DWORD reserved)
729 TRACE("iface %p, offset %p, callback %p, context %p, reserved %#x.\n",
730 iface, offset, callback, context, reserved);
732 WARN("Not implemented.\n");
734 return DDERR_UNSUPPORTED; /* Unchecked */
737 /*****************************************************************************
738 * IDirect3DExecuteBuffer::Optimize
740 * DirectX5 SDK: "The IDirect3DExecuteBuffer::Optimize method is not
741 * currently supported"
743 * Params:
744 * Dummy: Seems to be an unused dummy ;)
746 * Returns:
747 * DDERR_UNSUPPORTED, because it's not implemented in Windows.
749 *****************************************************************************/
750 static HRESULT WINAPI d3d_execute_buffer_Optimize(IDirect3DExecuteBuffer *iface, DWORD reserved)
752 TRACE("iface %p, reserved %#x.\n", iface, reserved);
754 WARN("Not implemented.\n");
756 return DDERR_UNSUPPORTED; /* Unchecked */
759 static const struct IDirect3DExecuteBufferVtbl d3d_execute_buffer_vtbl =
761 d3d_execute_buffer_QueryInterface,
762 d3d_execute_buffer_AddRef,
763 d3d_execute_buffer_Release,
764 d3d_execute_buffer_Initialize,
765 d3d_execute_buffer_Lock,
766 d3d_execute_buffer_Unlock,
767 d3d_execute_buffer_SetExecuteData,
768 d3d_execute_buffer_GetExecuteData,
769 d3d_execute_buffer_Validate,
770 d3d_execute_buffer_Optimize,
773 HRESULT d3d_execute_buffer_init(struct d3d_execute_buffer *execute_buffer,
774 struct d3d_device *device, D3DEXECUTEBUFFERDESC *desc)
776 execute_buffer->IDirect3DExecuteBuffer_iface.lpVtbl = &d3d_execute_buffer_vtbl;
777 execute_buffer->ref = 1;
778 execute_buffer->d3ddev = device;
780 /* Initializes memory */
781 memcpy(&execute_buffer->desc, desc, desc->dwSize);
783 /* No buffer given */
784 if (!(execute_buffer->desc.dwFlags & D3DDEB_LPDATA))
785 execute_buffer->desc.lpData = NULL;
787 /* No buffer size given */
788 if (!(execute_buffer->desc.dwFlags & D3DDEB_BUFSIZE))
789 execute_buffer->desc.dwBufferSize = 0;
791 /* Create buffer if asked */
792 if (!execute_buffer->desc.lpData && execute_buffer->desc.dwBufferSize)
794 execute_buffer->need_free = TRUE;
795 execute_buffer->desc.lpData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, execute_buffer->desc.dwBufferSize);
796 if (!execute_buffer->desc.lpData)
798 ERR("Failed to allocate execute buffer data.\n");
799 return DDERR_OUTOFMEMORY;
803 execute_buffer->desc.dwFlags |= D3DDEB_LPDATA;
805 return D3D_OK;
808 struct d3d_execute_buffer *unsafe_impl_from_IDirect3DExecuteBuffer(IDirect3DExecuteBuffer *iface)
810 if (!iface)
811 return NULL;
812 assert(iface->lpVtbl == &d3d_execute_buffer_vtbl);
814 return impl_from_IDirect3DExecuteBuffer(iface);