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 /*****************************************************************************
54 * IDirect3DExecuteBufferImpl_Execute
56 * The main functionality of the execute buffer
57 * It transforms the vertices if necessary, and calls IDirect3DDevice7
58 * for drawing the vertices. It is called from
59 * IDirect3DDevice::Execute
61 * TODO: Perhaps some comments about the various opcodes wouldn't hurt
63 * Don't declare this static, as it's called from device.c,
64 * IDirect3DDevice::Execute
67 * Device: 3D Device associated to use for drawing
68 * Viewport: Viewport for this operation
70 *****************************************************************************/
71 HRESULT d3d_execute_buffer_execute(IDirect3DExecuteBufferImpl *This,
72 IDirect3DDeviceImpl *lpDevice, IDirect3DViewportImpl *lpViewport)
74 /* DWORD bs = This->desc.dwBufferSize; */
75 DWORD vs = This->data.dwVertexOffset;
76 /* DWORD vc = This->data.dwVertexCount; */
77 DWORD is = This->data.dwInstructionOffset;
78 /* DWORD il = This->data.dwInstructionLength; */
80 char *instr = (char *)This->desc.lpData + is;
82 if (lpViewport->active_device != lpDevice)
84 WARN("Viewport %p active device is %p.\n",
85 lpViewport, lpViewport->active_device);
86 return DDERR_INVALIDPARAMS;
89 /* Activate the viewport */
90 viewport_activate(lpViewport, FALSE);
92 TRACE("ExecuteData :\n");
94 _dump_executedata(&(This->data));
97 LPD3DINSTRUCTION current = (LPD3DINSTRUCTION) instr;
101 count = current->wCount;
102 size = current->bSize;
103 instr += sizeof(D3DINSTRUCTION);
105 switch (current->bOpcode) {
107 WARN("POINT-s (%d)\n", count);
108 instr += count * size;
112 WARN("LINE-s (%d)\n", count);
113 instr += count * size;
116 case D3DOP_TRIANGLE: {
118 D3DTLVERTEX *tl_vx = This->vertex_data;
119 TRACE("TRIANGLE (%d)\n", count);
121 if (count*3>This->nb_indices) {
122 This->nb_indices = count * 3;
123 HeapFree(GetProcessHeap(),0,This->indices);
124 This->indices = HeapAlloc(GetProcessHeap(),0,sizeof(WORD)*This->nb_indices);
127 for (i = 0; i < count; i++) {
128 LPD3DTRIANGLE ci = (LPD3DTRIANGLE) instr;
129 TRACE(" v1: %d v2: %d v3: %d\n",ci->u1.v1, ci->u2.v2, ci->u3.v3);
134 if (ci->wFlags & D3DTRIFLAG_EDGEENABLE1)
135 TRACE("EDGEENABLE1 ");
136 if (ci->wFlags & D3DTRIFLAG_EDGEENABLE2)
137 TRACE("EDGEENABLE2 ");
138 if (ci->wFlags & D3DTRIFLAG_EDGEENABLE1)
139 TRACE("EDGEENABLE3 ");
141 if (ci->wFlags == D3DTRIFLAG_EVEN)
143 if (ci->wFlags == D3DTRIFLAG_ODD)
145 if (ci->wFlags == D3DTRIFLAG_START)
147 if ((ci->wFlags > 0) && (ci->wFlags < 30))
148 TRACE("STARTFLAT(%u) ", ci->wFlags);
151 This->indices[(i * 3) ] = ci->u1.v1;
152 This->indices[(i * 3) + 1] = ci->u2.v2;
153 This->indices[(i * 3) + 2] = ci->u3.v3;
156 /* IDirect3DDevices have color keying always enabled -
157 * enable it before drawing. This overwrites any ALPHA*
160 IWineD3DDevice_SetRenderState(lpDevice->wineD3DDevice,
161 WINED3DRS_COLORKEYENABLE,
163 IDirect3DDevice7_DrawIndexedPrimitive((IDirect3DDevice7 *)lpDevice,
164 D3DPT_TRIANGLELIST, D3DFVF_TLVERTEX, tl_vx, 0, This->indices, count * 3, 0);
167 case D3DOP_MATRIXLOAD:
168 WARN("MATRIXLOAD-s (%d)\n", count);
169 instr += count * size;
172 case D3DOP_MATRIXMULTIPLY: {
174 TRACE("MATRIXMULTIPLY (%d)\n", count);
176 for (i = 0; i < count; ++i)
178 D3DMATRIXMULTIPLY *ci = (D3DMATRIXMULTIPLY *)instr;
179 D3DMATRIX *a, *b, *c;
181 a = ddraw_get_object(&lpDevice->handle_table, ci->hDestMatrix - 1, DDRAW_HANDLE_MATRIX);
182 b = ddraw_get_object(&lpDevice->handle_table, ci->hSrcMatrix1 - 1, DDRAW_HANDLE_MATRIX);
183 c = ddraw_get_object(&lpDevice->handle_table, ci->hSrcMatrix2 - 1, DDRAW_HANDLE_MATRIX);
187 ERR("Invalid matrix handle (a %#x -> %p, b %#x -> %p, c %#x -> %p).\n",
188 ci->hDestMatrix, a, ci->hSrcMatrix1, b, ci->hSrcMatrix2, c);
192 TRACE("dst %p, src1 %p, src2 %p.\n", a, b, c);
193 multiply_matrix(a, c, b);
200 case D3DOP_STATETRANSFORM: {
202 TRACE("STATETRANSFORM (%d)\n", count);
204 for (i = 0; i < count; ++i)
206 D3DSTATE *ci = (D3DSTATE *)instr;
209 m = ddraw_get_object(&lpDevice->handle_table, ci->u2.dwArg[0] - 1, DDRAW_HANDLE_MATRIX);
212 ERR("Invalid matrix handle %#x.\n", ci->u2.dwArg[0]);
216 if (ci->u1.dtstTransformStateType == D3DTRANSFORMSTATE_WORLD)
217 lpDevice->world = ci->u2.dwArg[0];
218 if (ci->u1.dtstTransformStateType == D3DTRANSFORMSTATE_VIEW)
219 lpDevice->view = ci->u2.dwArg[0];
220 if (ci->u1.dtstTransformStateType == D3DTRANSFORMSTATE_PROJECTION)
221 lpDevice->proj = ci->u2.dwArg[0];
222 IDirect3DDevice7_SetTransform((IDirect3DDevice7 *)lpDevice,
223 ci->u1.dtstTransformStateType, m);
230 case D3DOP_STATELIGHT: {
232 TRACE("STATELIGHT (%d)\n", count);
234 for (i = 0; i < count; i++) {
235 LPD3DSTATE ci = (LPD3DSTATE) instr;
237 TRACE("(%08x,%08x)\n", ci->u1.dlstLightStateType, ci->u2.dwArg[0]);
239 if (!ci->u1.dlstLightStateType || (ci->u1.dlstLightStateType > D3DLIGHTSTATE_COLORVERTEX))
240 ERR("Unexpected Light State Type %d\n", ci->u1.dlstLightStateType);
241 else if (ci->u1.dlstLightStateType == D3DLIGHTSTATE_MATERIAL /* 1 */)
243 IDirect3DMaterialImpl *m;
245 m = ddraw_get_object(&lpDevice->handle_table, ci->u2.dwArg[0] - 1, DDRAW_HANDLE_MATERIAL);
247 ERR("Invalid material handle %#x.\n", ci->u2.dwArg[0]);
249 material_activate(m);
251 else if (ci->u1.dlstLightStateType == D3DLIGHTSTATE_COLORMODEL /* 3 */)
253 switch (ci->u2.dwArg[0]) {
255 ERR("DDCOLOR_MONO should not happen!\n");
258 /* We are already in this mode */
261 ERR("Unknown color model!\n");
264 D3DRENDERSTATETYPE rs = 0;
265 switch (ci->u1.dlstLightStateType) {
267 case D3DLIGHTSTATE_AMBIENT: /* 2 */
268 rs = D3DRENDERSTATE_AMBIENT;
270 case D3DLIGHTSTATE_FOGMODE: /* 4 */
271 rs = D3DRENDERSTATE_FOGVERTEXMODE;
273 case D3DLIGHTSTATE_FOGSTART: /* 5 */
274 rs = D3DRENDERSTATE_FOGSTART;
276 case D3DLIGHTSTATE_FOGEND: /* 6 */
277 rs = D3DRENDERSTATE_FOGEND;
279 case D3DLIGHTSTATE_FOGDENSITY: /* 7 */
280 rs = D3DRENDERSTATE_FOGDENSITY;
282 case D3DLIGHTSTATE_COLORVERTEX: /* 8 */
283 rs = D3DRENDERSTATE_COLORVERTEX;
289 IDirect3DDevice7_SetRenderState((IDirect3DDevice7 *)lpDevice, rs, ci->u2.dwArg[0]);
296 case D3DOP_STATERENDER: {
298 IDirect3DDevice2 *d3d_device2 = (IDirect3DDevice2 *)&lpDevice->IDirect3DDevice2_vtbl;
299 TRACE("STATERENDER (%d)\n", count);
301 for (i = 0; i < count; i++) {
302 LPD3DSTATE ci = (LPD3DSTATE) instr;
304 IDirect3DDevice2_SetRenderState(d3d_device2, ci->u1.drstRenderStateType, ci->u2.dwArg[0]);
310 case D3DOP_PROCESSVERTICES:
312 /* TODO: Share code with IDirect3DVertexBuffer::ProcessVertices and / or
313 * IWineD3DDevice::ProcessVertices
316 D3DMATRIX view_mat, world_mat, proj_mat;
317 TRACE("PROCESSVERTICES (%d)\n", count);
319 /* Get the transform and world matrix */
320 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
322 IWineD3DDevice_GetTransform(lpDevice->wineD3DDevice,
323 D3DTRANSFORMSTATE_VIEW,
324 (WINED3DMATRIX*) &view_mat);
326 IWineD3DDevice_GetTransform(lpDevice->wineD3DDevice,
327 D3DTRANSFORMSTATE_PROJECTION,
328 (WINED3DMATRIX*) &proj_mat);
330 IWineD3DDevice_GetTransform(lpDevice->wineD3DDevice,
331 WINED3DTS_WORLDMATRIX(0),
332 (WINED3DMATRIX*) &world_mat);
334 for (i = 0; i < count; i++) {
335 LPD3DPROCESSVERTICES ci = (LPD3DPROCESSVERTICES) instr;
337 TRACE(" Start : %d Dest : %d Count : %d\n",
338 ci->wStart, ci->wDest, ci->dwCount);
342 if (ci->dwFlags & D3DPROCESSVERTICES_COPY)
344 if (ci->dwFlags & D3DPROCESSVERTICES_NOCOLOR)
346 if (ci->dwFlags == D3DPROCESSVERTICES_OPMASK)
348 if (ci->dwFlags & D3DPROCESSVERTICES_TRANSFORM)
350 if (ci->dwFlags == D3DPROCESSVERTICES_TRANSFORMLIGHT)
351 TRACE("TRANSFORMLIGHT ");
352 if (ci->dwFlags & D3DPROCESSVERTICES_UPDATEEXTENTS)
353 TRACE("UPDATEEXTENTS ");
357 /* This is where doing Direct3D on top on OpenGL is quite difficult.
358 This method transforms a set of vertices using the CURRENT state
359 (lighting, projection, ...) but does not rasterize them.
360 They will only be put on screen later (with the POINT / LINE and
361 TRIANGLE op-codes). The problem is that you can have a triangle
362 with each point having been transformed using another state...
364 In this implementation, I will emulate only ONE thing : each
365 vertex can have its own "WORLD" transformation (this is used in the
366 TWIST.EXE demo of the 5.2 SDK). I suppose that all vertices of the
367 execute buffer use the same state.
369 If I find applications that change other states, I will try to do a
370 more 'fine-tuned' state emulation (but I may become quite tricky if
371 it changes a light position in the middle of a triangle).
373 In this case, a 'direct' approach (i.e. without using OpenGL, but
374 writing our own 3D rasterizer) would be easier. */
376 /* The current method (with the hypothesis that only the WORLD matrix
377 will change between two points) is like this :
378 - I transform 'manually' all the vertices with the current WORLD
379 matrix and store them in the vertex buffer
380 - during the rasterization phase, the WORLD matrix will be set to
381 the Identity matrix */
383 /* Enough for the moment */
384 if (ci->dwFlags == D3DPROCESSVERTICES_TRANSFORMLIGHT) {
386 D3DVERTEX *src = ((LPD3DVERTEX) ((char *)This->desc.lpData + vs)) + ci->wStart;
387 D3DTLVERTEX *dst = ((LPD3DTLVERTEX) (This->vertex_data)) + ci->wDest;
389 D3DVIEWPORT* Viewport = &lpViewport->viewports.vp1;
393 TRACE(" Projection Matrix : (%p)\n", &proj_mat);
394 dump_D3DMATRIX(&proj_mat);
395 TRACE(" View Matrix : (%p)\n", &view_mat);
396 dump_D3DMATRIX(&view_mat);
397 TRACE(" World Matrix : (%p)\n", &world_mat);
398 dump_D3DMATRIX(&world_mat);
401 multiply_matrix(&mat,&view_mat,&world_mat);
402 multiply_matrix(&mat,&proj_mat,&mat);
404 for (nb = 0; nb < ci->dwCount; nb++) {
405 /* No lighting yet */
406 dst->u5.color = 0xFFFFFFFF; /* Opaque white */
407 dst->u6.specular = 0xFF000000; /* No specular and no fog factor */
409 dst->u7.tu = src->u7.tu;
410 dst->u8.tv = src->u8.tv;
412 /* Now, the matrix multiplication */
413 dst->u1.sx = (src->u1.x * mat._11) + (src->u2.y * mat._21) + (src->u3.z * mat._31) + (1.0 * mat._41);
414 dst->u2.sy = (src->u1.x * mat._12) + (src->u2.y * mat._22) + (src->u3.z * mat._32) + (1.0 * mat._42);
415 dst->u3.sz = (src->u1.x * mat._13) + (src->u2.y * mat._23) + (src->u3.z * mat._33) + (1.0 * mat._43);
416 dst->u4.rhw = (src->u1.x * mat._14) + (src->u2.y * mat._24) + (src->u3.z * mat._34) + (1.0 * mat._44);
418 dst->u1.sx = dst->u1.sx / dst->u4.rhw * Viewport->dvScaleX
419 + Viewport->dwX + Viewport->dwWidth / 2;
420 dst->u2.sy = (-dst->u2.sy) / dst->u4.rhw * Viewport->dvScaleY
421 + Viewport->dwY + Viewport->dwHeight / 2;
422 dst->u3.sz /= dst->u4.rhw;
423 dst->u4.rhw = 1 / dst->u4.rhw;
429 } else if (ci->dwFlags == D3DPROCESSVERTICES_TRANSFORM) {
431 D3DLVERTEX *src = ((LPD3DLVERTEX) ((char *)This->desc.lpData + vs)) + ci->wStart;
432 D3DTLVERTEX *dst = ((LPD3DTLVERTEX) (This->vertex_data)) + ci->wDest;
434 D3DVIEWPORT* Viewport = &lpViewport->viewports.vp1;
438 TRACE(" Projection Matrix : (%p)\n", &proj_mat);
439 dump_D3DMATRIX(&proj_mat);
440 TRACE(" View Matrix : (%p)\n",&view_mat);
441 dump_D3DMATRIX(&view_mat);
442 TRACE(" World Matrix : (%p)\n", &world_mat);
443 dump_D3DMATRIX(&world_mat);
446 multiply_matrix(&mat,&view_mat,&world_mat);
447 multiply_matrix(&mat,&proj_mat,&mat);
449 for (nb = 0; nb < ci->dwCount; nb++) {
450 dst->u5.color = src->u4.color;
451 dst->u6.specular = src->u5.specular;
452 dst->u7.tu = src->u6.tu;
453 dst->u8.tv = src->u7.tv;
455 /* Now, the matrix multiplication */
456 dst->u1.sx = (src->u1.x * mat._11) + (src->u2.y * mat._21) + (src->u3.z * mat._31) + (1.0 * mat._41);
457 dst->u2.sy = (src->u1.x * mat._12) + (src->u2.y * mat._22) + (src->u3.z * mat._32) + (1.0 * mat._42);
458 dst->u3.sz = (src->u1.x * mat._13) + (src->u2.y * mat._23) + (src->u3.z * mat._33) + (1.0 * mat._43);
459 dst->u4.rhw = (src->u1.x * mat._14) + (src->u2.y * mat._24) + (src->u3.z * mat._34) + (1.0 * mat._44);
461 dst->u1.sx = dst->u1.sx / dst->u4.rhw * Viewport->dvScaleX
462 + Viewport->dwX + Viewport->dwWidth / 2;
463 dst->u2.sy = (-dst->u2.sy) / dst->u4.rhw * Viewport->dvScaleY
464 + Viewport->dwY + Viewport->dwHeight / 2;
466 dst->u3.sz /= dst->u4.rhw;
467 dst->u4.rhw = 1 / dst->u4.rhw;
472 } else if (ci->dwFlags == D3DPROCESSVERTICES_COPY) {
473 D3DTLVERTEX *src = ((LPD3DTLVERTEX) ((char *)This->desc.lpData + vs)) + ci->wStart;
474 D3DTLVERTEX *dst = ((LPD3DTLVERTEX) (This->vertex_data)) + ci->wDest;
476 memcpy(dst, src, ci->dwCount * sizeof(D3DTLVERTEX));
478 ERR("Unhandled vertex processing flag %#x.\n", ci->dwFlags);
485 case D3DOP_TEXTURELOAD: {
486 WARN("TEXTURELOAD-s (%d)\n", count);
488 instr += count * size;
492 TRACE("EXIT (%d)\n", count);
493 /* We did this instruction */
499 case D3DOP_BRANCHFORWARD: {
501 TRACE("BRANCHFORWARD (%d)\n", count);
503 for (i = 0; i < count; i++) {
504 LPD3DBRANCH ci = (LPD3DBRANCH) instr;
506 if ((This->data.dsStatus.dwStatus & ci->dwMask) == ci->dwValue) {
508 TRACE(" Branch to %d\n", ci->dwOffset);
510 instr = (char*)current + ci->dwOffset;
516 TRACE(" Branch to %d\n", ci->dwOffset);
518 instr = (char*)current + ci->dwOffset;
529 WARN("SPAN-s (%d)\n", count);
531 instr += count * size;
534 case D3DOP_SETSTATUS: {
536 TRACE("SETSTATUS (%d)\n", count);
538 for (i = 0; i < count; i++) {
539 LPD3DSTATUS ci = (LPD3DSTATUS) instr;
541 This->data.dsStatus = *ci;
548 ERR("Unhandled OpCode %d !!!\n",current->bOpcode);
549 /* Try to save ... */
550 instr += count * size;
559 /*****************************************************************************
560 * IDirect3DExecuteBuffer::QueryInterface
562 * Well, a usual QueryInterface function. Don't know fur sure which
563 * interfaces it can Query.
566 * riid: The interface ID queried for
567 * obj: Address to return the interface pointer at
570 * D3D_OK in case of a success (S_OK? Think it's the same)
571 * OLE_E_ENUM_NOMORE if the interface wasn't found.
572 * (E_NOINTERFACE?? Don't know what I really need)
574 *****************************************************************************/
575 static HRESULT WINAPI
576 IDirect3DExecuteBufferImpl_QueryInterface(IDirect3DExecuteBuffer *iface,
580 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), obj);
584 if ( IsEqualGUID( &IID_IUnknown, riid ) ) {
585 IDirect3DExecuteBuffer_AddRef(iface);
587 TRACE(" Creating IUnknown interface at %p.\n", *obj);
590 if ( IsEqualGUID( &IID_IDirect3DExecuteBuffer, riid ) ) {
591 IDirect3DExecuteBuffer_AddRef(iface);
593 TRACE(" Creating IDirect3DExecuteBuffer interface %p\n", *obj);
596 FIXME("(%p): interface for IID %s NOT found!\n", iface, debugstr_guid(riid));
597 return E_NOINTERFACE;
601 /*****************************************************************************
602 * IDirect3DExecuteBuffer::AddRef
604 * A normal AddRef method, nothing special
609 *****************************************************************************/
611 IDirect3DExecuteBufferImpl_AddRef(IDirect3DExecuteBuffer *iface)
613 IDirect3DExecuteBufferImpl *This = (IDirect3DExecuteBufferImpl *)iface;
614 ULONG ref = InterlockedIncrement(&This->ref);
616 TRACE("%p increasing refcount to %u.\n", This, ref);
621 /*****************************************************************************
622 * IDirect3DExecuteBuffer::Release
624 * A normal Release method, nothing special
629 *****************************************************************************/
631 IDirect3DExecuteBufferImpl_Release(IDirect3DExecuteBuffer *iface)
633 IDirect3DExecuteBufferImpl *This = (IDirect3DExecuteBufferImpl *)iface;
634 ULONG ref = InterlockedDecrement(&This->ref);
636 TRACE("%p decreasing refcount to %u.\n", This, ref);
640 HeapFree(GetProcessHeap(),0,This->desc.lpData);
641 HeapFree(GetProcessHeap(),0,This->vertex_data);
642 HeapFree(GetProcessHeap(),0,This->indices);
643 HeapFree(GetProcessHeap(),0,This);
650 /*****************************************************************************
651 * IDirect3DExecuteBuffer::Initialize
653 * Initializes the Execute Buffer. This method exists for COM compliance
654 * Nothing to do here.
659 *****************************************************************************/
660 static HRESULT WINAPI IDirect3DExecuteBufferImpl_Initialize(IDirect3DExecuteBuffer *iface,
661 IDirect3DDevice *device, D3DEXECUTEBUFFERDESC *desc)
663 TRACE("iface %p, device %p, desc %p.\n", iface, device, desc);
668 /*****************************************************************************
669 * IDirect3DExecuteBuffer::Lock
671 * Locks the buffer, so the app can write into it.
674 * Desc: Pointer to return the buffer description. This Description contains
675 * a pointer to the buffer data.
678 * This implementation always returns D3D_OK
680 *****************************************************************************/
681 static HRESULT WINAPI
682 IDirect3DExecuteBufferImpl_Lock(IDirect3DExecuteBuffer *iface,
683 D3DEXECUTEBUFFERDESC *lpDesc)
685 IDirect3DExecuteBufferImpl *This = (IDirect3DExecuteBufferImpl *)iface;
688 TRACE("iface %p, desc %p.\n", iface, lpDesc);
690 dwSize = lpDesc->dwSize;
691 memcpy(lpDesc, &This->desc, dwSize);
695 TRACE(" Returning description :\n");
696 _dump_D3DEXECUTEBUFFERDESC(lpDesc);
701 /*****************************************************************************
702 * IDirect3DExecuteBuffer::Unlock
704 * Unlocks the buffer. We don't have anything to do here
707 * This implementation always returns D3D_OK
709 *****************************************************************************/
710 static HRESULT WINAPI IDirect3DExecuteBufferImpl_Unlock(IDirect3DExecuteBuffer *iface)
712 TRACE("iface %p.\n", iface);
717 /*****************************************************************************
718 * IDirect3DExecuteBuffer::SetExecuteData
720 * Sets the execute data. This data is used to describe the buffer's content
723 * Data: Pointer to a D3DEXECUTEDATA structure containing the data to
728 * DDERR_OUTOFMEMORY if the vertex buffer allocation failed
730 *****************************************************************************/
731 static HRESULT WINAPI
732 IDirect3DExecuteBufferImpl_SetExecuteData(IDirect3DExecuteBuffer *iface,
733 D3DEXECUTEDATA *lpData)
735 IDirect3DExecuteBufferImpl *This = (IDirect3DExecuteBufferImpl *)iface;
738 TRACE("iface %p, data %p.\n", iface, lpData);
740 memcpy(&This->data, lpData, lpData->dwSize);
742 /* Get the number of vertices in the execute buffer */
743 nbvert = This->data.dwVertexCount;
745 /* Prepares the transformed vertex buffer */
746 HeapFree(GetProcessHeap(), 0, This->vertex_data);
747 This->vertex_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nbvert * sizeof(D3DTLVERTEX));
750 _dump_executedata(lpData);
755 /*****************************************************************************
756 * IDirect3DExecuteBuffer::GetExecuteData
758 * Returns the data in the execute buffer
761 * Data: Pointer to a D3DEXECUTEDATA structure used to return data
766 *****************************************************************************/
767 static HRESULT WINAPI
768 IDirect3DExecuteBufferImpl_GetExecuteData(IDirect3DExecuteBuffer *iface,
769 D3DEXECUTEDATA *lpData)
771 IDirect3DExecuteBufferImpl *This = (IDirect3DExecuteBufferImpl *)iface;
774 TRACE("iface %p, data %p.\n", iface, lpData);
776 dwSize = lpData->dwSize;
777 memcpy(lpData, &This->data, dwSize);
781 TRACE("Returning data :\n");
782 _dump_executedata(lpData);
788 /*****************************************************************************
789 * IDirect3DExecuteBuffer::Validate
791 * DirectX 5 SDK: "The IDirect3DExecuteBuffer::Validate method is not
792 * currently implemented"
798 * DDERR_UNSUPPORTED, because it's not implemented in Windows.
800 *****************************************************************************/
801 static HRESULT WINAPI IDirect3DExecuteBufferImpl_Validate(IDirect3DExecuteBuffer *iface,
802 DWORD *offset, LPD3DVALIDATECALLBACK callback, void *context, DWORD reserved)
804 TRACE("iface %p, offset %p, callback %p, context %p, reserved %#x.\n",
805 iface, offset, callback, context, reserved);
807 WARN("Not implemented.\n");
809 return DDERR_UNSUPPORTED; /* Unchecked */
812 /*****************************************************************************
813 * IDirect3DExecuteBuffer::Optimize
815 * DirectX5 SDK: "The IDirect3DExecuteBuffer::Optimize method is not
816 * currently supported"
819 * Dummy: Seems to be an unused dummy ;)
822 * DDERR_UNSUPPORTED, because it's not implemented in Windows.
824 *****************************************************************************/
825 static HRESULT WINAPI IDirect3DExecuteBufferImpl_Optimize(IDirect3DExecuteBuffer *iface, DWORD reserved)
827 TRACE("iface %p, reserved %#x.\n", iface, reserved);
829 WARN("Not implemented.\n");
831 return DDERR_UNSUPPORTED; /* Unchecked */
834 static const struct IDirect3DExecuteBufferVtbl d3d_execute_buffer_vtbl =
836 IDirect3DExecuteBufferImpl_QueryInterface,
837 IDirect3DExecuteBufferImpl_AddRef,
838 IDirect3DExecuteBufferImpl_Release,
839 IDirect3DExecuteBufferImpl_Initialize,
840 IDirect3DExecuteBufferImpl_Lock,
841 IDirect3DExecuteBufferImpl_Unlock,
842 IDirect3DExecuteBufferImpl_SetExecuteData,
843 IDirect3DExecuteBufferImpl_GetExecuteData,
844 IDirect3DExecuteBufferImpl_Validate,
845 IDirect3DExecuteBufferImpl_Optimize,
848 HRESULT d3d_execute_buffer_init(IDirect3DExecuteBufferImpl *execute_buffer,
849 IDirect3DDeviceImpl *device, D3DEXECUTEBUFFERDESC *desc)
851 execute_buffer->lpVtbl = &d3d_execute_buffer_vtbl;
852 execute_buffer->ref = 1;
853 execute_buffer->d3ddev = device;
855 /* Initializes memory */
856 memcpy(&execute_buffer->desc, desc, desc->dwSize);
858 /* No buffer given */
859 if (!(execute_buffer->desc.dwFlags & D3DDEB_LPDATA))
860 execute_buffer->desc.lpData = NULL;
862 /* No buffer size given */
863 if (!(execute_buffer->desc.dwFlags & D3DDEB_BUFSIZE))
864 execute_buffer->desc.dwBufferSize = 0;
866 /* Create buffer if asked */
867 if (!execute_buffer->desc.lpData && execute_buffer->desc.dwBufferSize)
869 execute_buffer->need_free = TRUE;
870 execute_buffer->desc.lpData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, execute_buffer->desc.dwBufferSize);
871 if (!execute_buffer->desc.lpData)
873 ERR("Failed to allocate execute buffer data.\n");
874 return DDERR_OUTOFMEMORY;
878 execute_buffer->desc.dwFlags |= D3DDEB_LPDATA;