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 file contains the implementation of IDirect3DExecuteBuffer.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
26 #include "ddraw_private.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
30 /*****************************************************************************
32 * _dump_D3DEXECUTEBUFFERDESC
34 * Debug functions which write the executebuffer data to the console
36 *****************************************************************************/
38 static void _dump_executedata(const D3DEXECUTEDATA *lpData) {
39 TRACE("dwSize : %d\n", lpData->dwSize);
40 TRACE("Vertex Offset : %d Count : %d\n", lpData->dwVertexOffset, lpData->dwVertexCount);
41 TRACE("Instruction Offset : %d Length : %d\n", lpData->dwInstructionOffset, lpData->dwInstructionLength);
42 TRACE("HVertex Offset : %d\n", lpData->dwHVertexOffset);
45 static void _dump_D3DEXECUTEBUFFERDESC(const D3DEXECUTEBUFFERDESC *lpDesc) {
46 TRACE("dwSize : %d\n", lpDesc->dwSize);
47 TRACE("dwFlags : %x\n", lpDesc->dwFlags);
48 TRACE("dwCaps : %x\n", lpDesc->dwCaps);
49 TRACE("dwBufferSize : %d\n", lpDesc->dwBufferSize);
50 TRACE("lpData : %p\n", lpDesc->lpData);
53 HRESULT d3d_execute_buffer_execute(struct d3d_execute_buffer *buffer,
54 struct d3d_device *device, struct d3d_viewport *viewport)
56 DWORD vs = buffer->data.dwVertexOffset;
57 DWORD is = buffer->data.dwInstructionOffset;
58 char *instr = (char *)buffer->desc.lpData + is;
60 if (viewport->active_device != device)
62 WARN("Viewport %p active device is %p.\n",
63 viewport, viewport->active_device);
64 return DDERR_INVALIDPARAMS;
67 /* Activate the viewport */
68 viewport_activate(viewport, FALSE);
70 TRACE("ExecuteData :\n");
72 _dump_executedata(&(buffer->data));
76 D3DINSTRUCTION *current = (D3DINSTRUCTION *)instr;
80 count = current->wCount;
81 size = current->bSize;
82 instr += sizeof(D3DINSTRUCTION);
84 switch (current->bOpcode) {
86 WARN("POINT-s (%d)\n", count);
87 instr += count * size;
91 WARN("LINE-s (%d)\n", count);
92 instr += count * size;
95 case D3DOP_TRIANGLE: {
97 D3DTLVERTEX *tl_vx = buffer->vertex_data;
98 TRACE("TRIANGLE (%d)\n", count);
100 if (buffer->nb_indices < count * 3)
102 buffer->nb_indices = count * 3;
103 HeapFree(GetProcessHeap(), 0, buffer->indices);
104 buffer->indices = HeapAlloc(GetProcessHeap(), 0, sizeof(*buffer->indices) * buffer->nb_indices);
107 for (i = 0; i < count; i++) {
108 LPD3DTRIANGLE ci = (LPD3DTRIANGLE) instr;
109 TRACE(" v1: %d v2: %d v3: %d\n",ci->u1.v1, ci->u2.v2, ci->u3.v3);
114 if (ci->wFlags & D3DTRIFLAG_EDGEENABLE1)
115 TRACE("EDGEENABLE1 ");
116 if (ci->wFlags & D3DTRIFLAG_EDGEENABLE2)
117 TRACE("EDGEENABLE2 ");
118 if (ci->wFlags & D3DTRIFLAG_EDGEENABLE1)
119 TRACE("EDGEENABLE3 ");
121 if (ci->wFlags == D3DTRIFLAG_EVEN)
123 if (ci->wFlags == D3DTRIFLAG_ODD)
125 if (ci->wFlags == D3DTRIFLAG_START)
127 if ((ci->wFlags > 0) && (ci->wFlags < 30))
128 TRACE("STARTFLAT(%u) ", ci->wFlags);
131 buffer->indices[(i * 3) ] = ci->u1.v1;
132 buffer->indices[(i * 3) + 1] = ci->u2.v2;
133 buffer->indices[(i * 3) + 2] = ci->u3.v3;
136 IDirect3DDevice7_DrawIndexedPrimitive(&device->IDirect3DDevice7_iface,
137 D3DPT_TRIANGLELIST, D3DFVF_TLVERTEX, tl_vx, buffer->nb_vertices,
138 buffer->indices, count * 3, 0);
141 case D3DOP_MATRIXLOAD:
142 WARN("MATRIXLOAD-s (%d)\n", count);
143 instr += count * size;
146 case D3DOP_MATRIXMULTIPLY: {
148 TRACE("MATRIXMULTIPLY (%d)\n", count);
150 for (i = 0; i < count; ++i)
152 D3DMATRIXMULTIPLY *ci = (D3DMATRIXMULTIPLY *)instr;
153 D3DMATRIX *a, *b, *c;
155 a = ddraw_get_object(&device->handle_table, ci->hDestMatrix - 1, DDRAW_HANDLE_MATRIX);
156 b = ddraw_get_object(&device->handle_table, ci->hSrcMatrix1 - 1, DDRAW_HANDLE_MATRIX);
157 c = ddraw_get_object(&device->handle_table, ci->hSrcMatrix2 - 1, DDRAW_HANDLE_MATRIX);
161 ERR("Invalid matrix handle (a %#x -> %p, b %#x -> %p, c %#x -> %p).\n",
162 ci->hDestMatrix, a, ci->hSrcMatrix1, b, ci->hSrcMatrix2, c);
166 TRACE("dst %p, src1 %p, src2 %p.\n", a, b, c);
167 multiply_matrix(a, c, b);
174 case D3DOP_STATETRANSFORM: {
176 TRACE("STATETRANSFORM (%d)\n", count);
178 for (i = 0; i < count; ++i)
180 D3DSTATE *ci = (D3DSTATE *)instr;
183 m = ddraw_get_object(&device->handle_table, ci->u2.dwArg[0] - 1, DDRAW_HANDLE_MATRIX);
186 ERR("Invalid matrix handle %#x.\n", ci->u2.dwArg[0]);
190 if (ci->u1.dtstTransformStateType == D3DTRANSFORMSTATE_WORLD)
191 device->world = ci->u2.dwArg[0];
192 if (ci->u1.dtstTransformStateType == D3DTRANSFORMSTATE_VIEW)
193 device->view = ci->u2.dwArg[0];
194 if (ci->u1.dtstTransformStateType == D3DTRANSFORMSTATE_PROJECTION)
195 device->proj = ci->u2.dwArg[0];
196 IDirect3DDevice7_SetTransform(&device->IDirect3DDevice7_iface,
197 ci->u1.dtstTransformStateType, m);
204 case D3DOP_STATELIGHT: {
206 TRACE("STATELIGHT (%d)\n", count);
208 for (i = 0; i < count; ++i)
210 D3DSTATE *ci = (D3DSTATE *)instr;
212 TRACE("(%08x,%08x)\n", ci->u1.dlstLightStateType, ci->u2.dwArg[0]);
214 if (!ci->u1.dlstLightStateType || (ci->u1.dlstLightStateType > D3DLIGHTSTATE_COLORVERTEX))
215 ERR("Unexpected Light State Type %d\n", ci->u1.dlstLightStateType);
216 else if (ci->u1.dlstLightStateType == D3DLIGHTSTATE_MATERIAL /* 1 */)
218 struct d3d_material *m;
220 m = ddraw_get_object(&device->handle_table, ci->u2.dwArg[0] - 1, DDRAW_HANDLE_MATERIAL);
222 ERR("Invalid material handle %#x.\n", ci->u2.dwArg[0]);
224 material_activate(m);
226 else if (ci->u1.dlstLightStateType == D3DLIGHTSTATE_COLORMODEL /* 3 */)
228 switch (ci->u2.dwArg[0]) {
230 ERR("DDCOLOR_MONO should not happen!\n");
233 /* We are already in this mode */
236 ERR("Unknown color model!\n");
239 D3DRENDERSTATETYPE rs = 0;
240 switch (ci->u1.dlstLightStateType) {
242 case D3DLIGHTSTATE_AMBIENT: /* 2 */
243 rs = D3DRENDERSTATE_AMBIENT;
245 case D3DLIGHTSTATE_FOGMODE: /* 4 */
246 rs = D3DRENDERSTATE_FOGVERTEXMODE;
248 case D3DLIGHTSTATE_FOGSTART: /* 5 */
249 rs = D3DRENDERSTATE_FOGSTART;
251 case D3DLIGHTSTATE_FOGEND: /* 6 */
252 rs = D3DRENDERSTATE_FOGEND;
254 case D3DLIGHTSTATE_FOGDENSITY: /* 7 */
255 rs = D3DRENDERSTATE_FOGDENSITY;
257 case D3DLIGHTSTATE_COLORVERTEX: /* 8 */
258 rs = D3DRENDERSTATE_COLORVERTEX;
264 IDirect3DDevice7_SetRenderState(&device->IDirect3DDevice7_iface, rs, ci->u2.dwArg[0]);
271 case D3DOP_STATERENDER: {
273 IDirect3DDevice2 *d3d_device2 = &device->IDirect3DDevice2_iface;
274 TRACE("STATERENDER (%d)\n", count);
276 for (i = 0; i < count; ++i)
278 D3DSTATE *ci = (D3DSTATE *)instr;
280 IDirect3DDevice2_SetRenderState(d3d_device2, ci->u1.drstRenderStateType, ci->u2.dwArg[0]);
286 case D3DOP_PROCESSVERTICES:
288 /* TODO: Share code with IDirect3DVertexBuffer::ProcessVertices and / or
289 * IWineD3DDevice::ProcessVertices
292 D3DMATRIX view_mat, world_mat, proj_mat;
293 TRACE("PROCESSVERTICES (%d)\n", count);
295 /* Get the transform and world matrix */
296 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
297 wined3d_device_get_transform(device->wined3d_device,
298 D3DTRANSFORMSTATE_VIEW, (struct wined3d_matrix *)&view_mat);
299 wined3d_device_get_transform(device->wined3d_device,
300 D3DTRANSFORMSTATE_PROJECTION, (struct wined3d_matrix *)&proj_mat);
301 wined3d_device_get_transform(device->wined3d_device,
302 WINED3D_TS_WORLD_MATRIX(0), (struct wined3d_matrix *)&world_mat);
304 for (i = 0; i < count; ++i)
306 D3DPROCESSVERTICES *ci = (D3DPROCESSVERTICES *)instr;
308 TRACE(" Start : %d Dest : %d Count : %d\n",
309 ci->wStart, ci->wDest, ci->dwCount);
313 if (ci->dwFlags & D3DPROCESSVERTICES_COPY)
315 if (ci->dwFlags & D3DPROCESSVERTICES_NOCOLOR)
317 if (ci->dwFlags == D3DPROCESSVERTICES_OPMASK)
319 if (ci->dwFlags & D3DPROCESSVERTICES_TRANSFORM)
321 if (ci->dwFlags == D3DPROCESSVERTICES_TRANSFORMLIGHT)
322 TRACE("TRANSFORMLIGHT ");
323 if (ci->dwFlags & D3DPROCESSVERTICES_UPDATEEXTENTS)
324 TRACE("UPDATEEXTENTS ");
328 /* This is where doing Direct3D on top on OpenGL is quite difficult.
329 This method transforms a set of vertices using the CURRENT state
330 (lighting, projection, ...) but does not rasterize them.
331 They will only be put on screen later (with the POINT / LINE and
332 TRIANGLE op-codes). The problem is that you can have a triangle
333 with each point having been transformed using another state...
335 In this implementation, I will emulate only ONE thing : each
336 vertex can have its own "WORLD" transformation (this is used in the
337 TWIST.EXE demo of the 5.2 SDK). I suppose that all vertices of the
338 execute buffer use the same state.
340 If I find applications that change other states, I will try to do a
341 more 'fine-tuned' state emulation (but I may become quite tricky if
342 it changes a light position in the middle of a triangle).
344 In this case, a 'direct' approach (i.e. without using OpenGL, but
345 writing our own 3D rasterizer) would be easier. */
347 /* The current method (with the hypothesis that only the WORLD matrix
348 will change between two points) is like this :
349 - I transform 'manually' all the vertices with the current WORLD
350 matrix and store them in the vertex buffer
351 - during the rasterization phase, the WORLD matrix will be set to
352 the Identity matrix */
354 /* Enough for the moment */
355 if (ci->dwFlags == D3DPROCESSVERTICES_TRANSFORMLIGHT) {
357 D3DVERTEX *src = ((D3DVERTEX *)((char *)buffer->desc.lpData + vs)) + ci->wStart;
358 D3DTLVERTEX *dst = ((D3DTLVERTEX *)buffer->vertex_data) + ci->wDest;
359 D3DVIEWPORT *Viewport = &viewport->viewports.vp1;
364 TRACE(" Projection Matrix : (%p)\n", &proj_mat);
365 dump_D3DMATRIX(&proj_mat);
366 TRACE(" View Matrix : (%p)\n", &view_mat);
367 dump_D3DMATRIX(&view_mat);
368 TRACE(" World Matrix : (%p)\n", &world_mat);
369 dump_D3DMATRIX(&world_mat);
372 multiply_matrix(&mat,&view_mat,&world_mat);
373 multiply_matrix(&mat,&proj_mat,&mat);
375 for (nb = 0; nb < ci->dwCount; nb++) {
376 /* No lighting yet */
377 dst->u5.color = 0xFFFFFFFF; /* Opaque white */
378 dst->u6.specular = 0xFF000000; /* No specular and no fog factor */
380 dst->u7.tu = src->u7.tu;
381 dst->u8.tv = src->u8.tv;
383 /* Now, the matrix multiplication */
384 dst->u1.sx = (src->u1.x * mat._11) + (src->u2.y * mat._21) + (src->u3.z * mat._31) + (1.0 * mat._41);
385 dst->u2.sy = (src->u1.x * mat._12) + (src->u2.y * mat._22) + (src->u3.z * mat._32) + (1.0 * mat._42);
386 dst->u3.sz = (src->u1.x * mat._13) + (src->u2.y * mat._23) + (src->u3.z * mat._33) + (1.0 * mat._43);
387 dst->u4.rhw = (src->u1.x * mat._14) + (src->u2.y * mat._24) + (src->u3.z * mat._34) + (1.0 * mat._44);
389 dst->u1.sx = dst->u1.sx / dst->u4.rhw * Viewport->dvScaleX
390 + Viewport->dwX + Viewport->dwWidth / 2;
391 dst->u2.sy = (-dst->u2.sy) / dst->u4.rhw * Viewport->dvScaleY
392 + Viewport->dwY + Viewport->dwHeight / 2;
393 dst->u3.sz /= dst->u4.rhw;
394 dst->u4.rhw = 1 / dst->u4.rhw;
400 } else if (ci->dwFlags == D3DPROCESSVERTICES_TRANSFORM) {
402 D3DLVERTEX *src = ((D3DLVERTEX *)((char *)buffer->desc.lpData + vs)) + ci->wStart;
403 D3DTLVERTEX *dst = ((D3DTLVERTEX *)buffer->vertex_data) + ci->wDest;
404 D3DVIEWPORT *Viewport = &viewport->viewports.vp1;
409 TRACE(" Projection Matrix : (%p)\n", &proj_mat);
410 dump_D3DMATRIX(&proj_mat);
411 TRACE(" View Matrix : (%p)\n",&view_mat);
412 dump_D3DMATRIX(&view_mat);
413 TRACE(" World Matrix : (%p)\n", &world_mat);
414 dump_D3DMATRIX(&world_mat);
417 multiply_matrix(&mat,&view_mat,&world_mat);
418 multiply_matrix(&mat,&proj_mat,&mat);
420 for (nb = 0; nb < ci->dwCount; nb++) {
421 dst->u5.color = src->u4.color;
422 dst->u6.specular = src->u5.specular;
423 dst->u7.tu = src->u6.tu;
424 dst->u8.tv = src->u7.tv;
426 /* Now, the matrix multiplication */
427 dst->u1.sx = (src->u1.x * mat._11) + (src->u2.y * mat._21) + (src->u3.z * mat._31) + (1.0 * mat._41);
428 dst->u2.sy = (src->u1.x * mat._12) + (src->u2.y * mat._22) + (src->u3.z * mat._32) + (1.0 * mat._42);
429 dst->u3.sz = (src->u1.x * mat._13) + (src->u2.y * mat._23) + (src->u3.z * mat._33) + (1.0 * mat._43);
430 dst->u4.rhw = (src->u1.x * mat._14) + (src->u2.y * mat._24) + (src->u3.z * mat._34) + (1.0 * mat._44);
432 dst->u1.sx = dst->u1.sx / dst->u4.rhw * Viewport->dvScaleX
433 + Viewport->dwX + Viewport->dwWidth / 2;
434 dst->u2.sy = (-dst->u2.sy) / dst->u4.rhw * Viewport->dvScaleY
435 + Viewport->dwY + Viewport->dwHeight / 2;
437 dst->u3.sz /= dst->u4.rhw;
438 dst->u4.rhw = 1 / dst->u4.rhw;
444 else if (ci->dwFlags == D3DPROCESSVERTICES_COPY)
446 D3DTLVERTEX *src = ((D3DTLVERTEX *)((char *)buffer->desc.lpData + vs)) + ci->wStart;
447 D3DTLVERTEX *dst = ((D3DTLVERTEX *)buffer->vertex_data) + ci->wDest;
449 memcpy(dst, src, ci->dwCount * sizeof(D3DTLVERTEX));
451 ERR("Unhandled vertex processing flag %#x.\n", ci->dwFlags);
458 case D3DOP_TEXTURELOAD: {
459 WARN("TEXTURELOAD-s (%d)\n", count);
461 instr += count * size;
465 TRACE("EXIT (%d)\n", count);
466 /* We did this instruction */
472 case D3DOP_BRANCHFORWARD: {
474 TRACE("BRANCHFORWARD (%d)\n", count);
476 for (i = 0; i < count; i++) {
477 LPD3DBRANCH ci = (LPD3DBRANCH) instr;
479 if ((buffer->data.dsStatus.dwStatus & ci->dwMask) == ci->dwValue)
483 TRACE(" Branch to %d\n", ci->dwOffset);
485 instr = (char*)current + ci->dwOffset;
491 TRACE(" Branch to %d\n", ci->dwOffset);
493 instr = (char*)current + ci->dwOffset;
504 WARN("SPAN-s (%d)\n", count);
506 instr += count * size;
509 case D3DOP_SETSTATUS: {
511 TRACE("SETSTATUS (%d)\n", count);
513 for (i = 0; i < count; i++) {
514 LPD3DSTATUS ci = (LPD3DSTATUS) instr;
516 buffer->data.dsStatus = *ci;
523 ERR("Unhandled OpCode %d !!!\n",current->bOpcode);
524 /* Try to save ... */
525 instr += count * size;
534 static inline struct d3d_execute_buffer *impl_from_IDirect3DExecuteBuffer(IDirect3DExecuteBuffer *iface)
536 return CONTAINING_RECORD(iface, struct d3d_execute_buffer, IDirect3DExecuteBuffer_iface);
539 /*****************************************************************************
540 * IDirect3DExecuteBuffer::QueryInterface
542 * Well, a usual QueryInterface function. Don't know fur sure which
543 * interfaces it can Query.
546 * riid: The interface ID queried for
547 * obj: Address to return the interface pointer at
550 * D3D_OK in case of a success (S_OK? Think it's the same)
551 * OLE_E_ENUM_NOMORE if the interface wasn't found.
552 * (E_NOINTERFACE?? Don't know what I really need)
554 *****************************************************************************/
555 static HRESULT WINAPI d3d_execute_buffer_QueryInterface(IDirect3DExecuteBuffer *iface, REFIID riid, void **obj)
557 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), obj);
561 if ( IsEqualGUID( &IID_IUnknown, riid ) ) {
562 IDirect3DExecuteBuffer_AddRef(iface);
564 TRACE(" Creating IUnknown interface at %p.\n", *obj);
567 if ( IsEqualGUID( &IID_IDirect3DExecuteBuffer, riid ) ) {
568 IDirect3DExecuteBuffer_AddRef(iface);
570 TRACE(" Creating IDirect3DExecuteBuffer interface %p\n", *obj);
573 FIXME("(%p): interface for IID %s NOT found!\n", iface, debugstr_guid(riid));
574 return E_NOINTERFACE;
578 /*****************************************************************************
579 * IDirect3DExecuteBuffer::AddRef
581 * A normal AddRef method, nothing special
586 *****************************************************************************/
587 static ULONG WINAPI d3d_execute_buffer_AddRef(IDirect3DExecuteBuffer *iface)
589 struct d3d_execute_buffer *buffer = impl_from_IDirect3DExecuteBuffer(iface);
590 ULONG ref = InterlockedIncrement(&buffer->ref);
592 TRACE("%p increasing refcount to %u.\n", buffer, ref);
597 /*****************************************************************************
598 * IDirect3DExecuteBuffer::Release
600 * A normal Release method, nothing special
605 *****************************************************************************/
606 static ULONG WINAPI d3d_execute_buffer_Release(IDirect3DExecuteBuffer *iface)
608 struct d3d_execute_buffer *buffer = impl_from_IDirect3DExecuteBuffer(iface);
609 ULONG ref = InterlockedDecrement(&buffer->ref);
611 TRACE("%p decreasing refcount to %u.\n", buffer, ref);
615 if (buffer->need_free)
616 HeapFree(GetProcessHeap(), 0, buffer->desc.lpData);
617 HeapFree(GetProcessHeap(), 0, buffer->vertex_data);
618 HeapFree(GetProcessHeap(), 0, buffer->indices);
619 HeapFree(GetProcessHeap(), 0, buffer);
625 /*****************************************************************************
626 * IDirect3DExecuteBuffer::Initialize
628 * Initializes the Execute Buffer. This method exists for COM compliance
629 * Nothing to do here.
634 *****************************************************************************/
635 static HRESULT WINAPI d3d_execute_buffer_Initialize(IDirect3DExecuteBuffer *iface,
636 IDirect3DDevice *device, D3DEXECUTEBUFFERDESC *desc)
638 TRACE("iface %p, device %p, desc %p.\n", iface, device, desc);
643 /*****************************************************************************
644 * IDirect3DExecuteBuffer::Lock
646 * Locks the buffer, so the app can write into it.
649 * Desc: Pointer to return the buffer description. This Description contains
650 * a pointer to the buffer data.
653 * This implementation always returns D3D_OK
655 *****************************************************************************/
656 static HRESULT WINAPI d3d_execute_buffer_Lock(IDirect3DExecuteBuffer *iface, D3DEXECUTEBUFFERDESC *desc)
658 struct d3d_execute_buffer *buffer = impl_from_IDirect3DExecuteBuffer(iface);
661 TRACE("iface %p, desc %p.\n", iface, desc);
663 dwSize = desc->dwSize;
664 memcpy(desc, &buffer->desc, dwSize);
668 TRACE(" Returning description :\n");
669 _dump_D3DEXECUTEBUFFERDESC(desc);
674 /*****************************************************************************
675 * IDirect3DExecuteBuffer::Unlock
677 * Unlocks the buffer. We don't have anything to do here
680 * This implementation always returns D3D_OK
682 *****************************************************************************/
683 static HRESULT WINAPI d3d_execute_buffer_Unlock(IDirect3DExecuteBuffer *iface)
685 TRACE("iface %p.\n", iface);
690 /*****************************************************************************
691 * IDirect3DExecuteBuffer::SetExecuteData
693 * Sets the execute data. This data is used to describe the buffer's content
696 * Data: Pointer to a D3DEXECUTEDATA structure containing the data to
701 * DDERR_OUTOFMEMORY if the vertex buffer allocation failed
703 *****************************************************************************/
704 static HRESULT WINAPI d3d_execute_buffer_SetExecuteData(IDirect3DExecuteBuffer *iface, D3DEXECUTEDATA *data)
706 struct d3d_execute_buffer *buffer = impl_from_IDirect3DExecuteBuffer(iface);
709 TRACE("iface %p, data %p.\n", iface, data);
711 memcpy(&buffer->data, data, data->dwSize);
713 /* Get the number of vertices in the execute buffer */
714 nbvert = buffer->data.dwVertexCount;
716 /* Prepares the transformed vertex buffer */
717 HeapFree(GetProcessHeap(), 0, buffer->vertex_data);
718 buffer->vertex_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nbvert * sizeof(D3DTLVERTEX));
719 buffer->nb_vertices = nbvert;
722 _dump_executedata(data);
727 /*****************************************************************************
728 * IDirect3DExecuteBuffer::GetExecuteData
730 * Returns the data in the execute buffer
733 * Data: Pointer to a D3DEXECUTEDATA structure used to return data
738 *****************************************************************************/
739 static HRESULT WINAPI d3d_execute_buffer_GetExecuteData(IDirect3DExecuteBuffer *iface, D3DEXECUTEDATA *data)
741 struct d3d_execute_buffer *buffer = impl_from_IDirect3DExecuteBuffer(iface);
744 TRACE("iface %p, data %p.\n", iface, data);
746 dwSize = data->dwSize;
747 memcpy(data, &buffer->data, dwSize);
751 TRACE("Returning data :\n");
752 _dump_executedata(data);
758 /*****************************************************************************
759 * IDirect3DExecuteBuffer::Validate
761 * DirectX 5 SDK: "The IDirect3DExecuteBuffer::Validate method is not
762 * currently implemented"
768 * DDERR_UNSUPPORTED, because it's not implemented in Windows.
770 *****************************************************************************/
771 static HRESULT WINAPI d3d_execute_buffer_Validate(IDirect3DExecuteBuffer *iface,
772 DWORD *offset, LPD3DVALIDATECALLBACK callback, void *context, DWORD reserved)
774 TRACE("iface %p, offset %p, callback %p, context %p, reserved %#x.\n",
775 iface, offset, callback, context, reserved);
777 WARN("Not implemented.\n");
779 return DDERR_UNSUPPORTED; /* Unchecked */
782 /*****************************************************************************
783 * IDirect3DExecuteBuffer::Optimize
785 * DirectX5 SDK: "The IDirect3DExecuteBuffer::Optimize method is not
786 * currently supported"
789 * Dummy: Seems to be an unused dummy ;)
792 * DDERR_UNSUPPORTED, because it's not implemented in Windows.
794 *****************************************************************************/
795 static HRESULT WINAPI d3d_execute_buffer_Optimize(IDirect3DExecuteBuffer *iface, DWORD reserved)
797 TRACE("iface %p, reserved %#x.\n", iface, reserved);
799 WARN("Not implemented.\n");
801 return DDERR_UNSUPPORTED; /* Unchecked */
804 static const struct IDirect3DExecuteBufferVtbl d3d_execute_buffer_vtbl =
806 d3d_execute_buffer_QueryInterface,
807 d3d_execute_buffer_AddRef,
808 d3d_execute_buffer_Release,
809 d3d_execute_buffer_Initialize,
810 d3d_execute_buffer_Lock,
811 d3d_execute_buffer_Unlock,
812 d3d_execute_buffer_SetExecuteData,
813 d3d_execute_buffer_GetExecuteData,
814 d3d_execute_buffer_Validate,
815 d3d_execute_buffer_Optimize,
818 HRESULT d3d_execute_buffer_init(struct d3d_execute_buffer *execute_buffer,
819 struct d3d_device *device, D3DEXECUTEBUFFERDESC *desc)
821 execute_buffer->IDirect3DExecuteBuffer_iface.lpVtbl = &d3d_execute_buffer_vtbl;
822 execute_buffer->ref = 1;
823 execute_buffer->d3ddev = device;
825 /* Initializes memory */
826 memcpy(&execute_buffer->desc, desc, desc->dwSize);
828 /* No buffer given */
829 if (!(execute_buffer->desc.dwFlags & D3DDEB_LPDATA))
830 execute_buffer->desc.lpData = NULL;
832 /* No buffer size given */
833 if (!(execute_buffer->desc.dwFlags & D3DDEB_BUFSIZE))
834 execute_buffer->desc.dwBufferSize = 0;
836 /* Create buffer if asked */
837 if (!execute_buffer->desc.lpData && execute_buffer->desc.dwBufferSize)
839 execute_buffer->need_free = TRUE;
840 execute_buffer->desc.lpData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, execute_buffer->desc.dwBufferSize);
841 if (!execute_buffer->desc.lpData)
843 ERR("Failed to allocate execute buffer data.\n");
844 return DDERR_OUTOFMEMORY;
848 execute_buffer->desc.dwFlags |= D3DDEB_LPDATA;
853 struct d3d_execute_buffer *unsafe_impl_from_IDirect3DExecuteBuffer(IDirect3DExecuteBuffer *iface)
857 assert(iface->lpVtbl == &d3d_execute_buffer_vtbl);
859 return impl_from_IDirect3DExecuteBuffer(iface);