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 *****************************************************************************/
72 IDirect3DExecuteBufferImpl_Execute(IDirect3DExecuteBufferImpl *This,
73 IDirect3DDeviceImpl *lpDevice,
74 IDirect3DViewportImpl *lpViewport)
76 /* DWORD bs = This->desc.dwBufferSize; */
77 DWORD vs = This->data.dwVertexOffset;
78 /* DWORD vc = This->data.dwVertexCount; */
79 DWORD is = This->data.dwInstructionOffset;
80 /* DWORD il = This->data.dwInstructionLength; */
82 char *instr = (char *)This->desc.lpData + is;
84 /* Should check if the viewport was added or not to the device */
86 /* Activate the viewport */
87 lpViewport->active_device = lpDevice;
88 viewport_activate(lpViewport, FALSE);
90 TRACE("ExecuteData :\n");
92 _dump_executedata(&(This->data));
95 LPD3DINSTRUCTION current = (LPD3DINSTRUCTION) instr;
99 count = current->wCount;
100 size = current->bSize;
101 instr += sizeof(D3DINSTRUCTION);
103 switch (current->bOpcode) {
105 WARN("POINT-s (%d)\n", count);
106 instr += count * size;
110 WARN("LINE-s (%d)\n", count);
111 instr += count * size;
114 case D3DOP_TRIANGLE: {
116 D3DTLVERTEX *tl_vx = This->vertex_data;
117 TRACE("TRIANGLE (%d)\n", count);
119 if (count*3>This->nb_indices) {
120 This->nb_indices = count * 3;
121 HeapFree(GetProcessHeap(),0,This->indices);
122 This->indices = HeapAlloc(GetProcessHeap(),0,sizeof(WORD)*This->nb_indices);
125 for (i = 0; i < count; i++) {
126 LPD3DTRIANGLE ci = (LPD3DTRIANGLE) instr;
127 TRACE(" v1: %d v2: %d v3: %d\n",ci->u1.v1, ci->u2.v2, ci->u3.v3);
132 if (ci->wFlags & D3DTRIFLAG_EDGEENABLE1)
133 TRACE("EDGEENABLE1 ");
134 if (ci->wFlags & D3DTRIFLAG_EDGEENABLE2)
135 TRACE("EDGEENABLE2 ");
136 if (ci->wFlags & D3DTRIFLAG_EDGEENABLE1)
137 TRACE("EDGEENABLE3 ");
139 if (ci->wFlags == D3DTRIFLAG_EVEN)
141 if (ci->wFlags == D3DTRIFLAG_ODD)
143 if (ci->wFlags == D3DTRIFLAG_START)
145 if ((ci->wFlags > 0) && (ci->wFlags < 30))
146 TRACE("STARTFLAT(%u) ", ci->wFlags);
149 This->indices[(i * 3) ] = ci->u1.v1;
150 This->indices[(i * 3) + 1] = ci->u2.v2;
151 This->indices[(i * 3) + 2] = ci->u3.v3;
154 /* IDirect3DDevices have color keying always enabled -
155 * enable it before drawing. This overwrites any ALPHA*
158 IWineD3DDevice_SetRenderState(lpDevice->wineD3DDevice,
159 WINED3DRS_COLORKEYENABLE,
161 IDirect3DDevice7_DrawIndexedPrimitive((IDirect3DDevice7 *)lpDevice,
162 D3DPT_TRIANGLELIST, D3DFVF_TLVERTEX, tl_vx, 0, This->indices, count * 3, 0);
165 case D3DOP_MATRIXLOAD:
166 WARN("MATRIXLOAD-s (%d)\n", count);
167 instr += count * size;
170 case D3DOP_MATRIXMULTIPLY: {
172 TRACE("MATRIXMULTIPLY (%d)\n", count);
174 for (i = 0; i < count; ++i)
176 D3DMATRIXMULTIPLY *ci = (D3DMATRIXMULTIPLY *)instr;
177 D3DMATRIX *a, *b, *c;
179 a = ddraw_get_object(&lpDevice->handle_table, ci->hDestMatrix - 1, DDRAW_HANDLE_MATRIX);
180 b = ddraw_get_object(&lpDevice->handle_table, ci->hSrcMatrix1 - 1, DDRAW_HANDLE_MATRIX);
181 c = ddraw_get_object(&lpDevice->handle_table, ci->hSrcMatrix2 - 1, DDRAW_HANDLE_MATRIX);
185 ERR("Invalid matrix handle (a %#x -> %p, b %#x -> %p, c %#x -> %p).\n",
186 ci->hDestMatrix, a, ci->hSrcMatrix1, b, ci->hSrcMatrix2, c);
190 TRACE("dst %p, src1 %p, src2 %p.\n", a, b, c);
191 multiply_matrix(a, c, b);
198 case D3DOP_STATETRANSFORM: {
200 TRACE("STATETRANSFORM (%d)\n", count);
202 for (i = 0; i < count; ++i)
204 D3DSTATE *ci = (D3DSTATE *)instr;
207 m = ddraw_get_object(&lpDevice->handle_table, ci->u2.dwArg[0] - 1, DDRAW_HANDLE_MATRIX);
210 ERR("Invalid matrix handle %#x.\n", ci->u2.dwArg[0]);
214 if (ci->u1.dtstTransformStateType == D3DTRANSFORMSTATE_WORLD)
215 lpDevice->world = ci->u2.dwArg[0];
216 if (ci->u1.dtstTransformStateType == D3DTRANSFORMSTATE_VIEW)
217 lpDevice->view = ci->u2.dwArg[0];
218 if (ci->u1.dtstTransformStateType == D3DTRANSFORMSTATE_PROJECTION)
219 lpDevice->proj = ci->u2.dwArg[0];
220 IDirect3DDevice7_SetTransform((IDirect3DDevice7 *)lpDevice,
221 ci->u1.dtstTransformStateType, m);
228 case D3DOP_STATELIGHT: {
230 TRACE("STATELIGHT (%d)\n", count);
232 for (i = 0; i < count; i++) {
233 LPD3DSTATE ci = (LPD3DSTATE) instr;
235 TRACE("(%08x,%08x)\n", ci->u1.dlstLightStateType, ci->u2.dwArg[0]);
237 if (!ci->u1.dlstLightStateType || (ci->u1.dlstLightStateType > D3DLIGHTSTATE_COLORVERTEX))
238 ERR("Unexpected Light State Type %d\n", ci->u1.dlstLightStateType);
239 else if (ci->u1.dlstLightStateType == D3DLIGHTSTATE_MATERIAL /* 1 */)
241 IDirect3DMaterialImpl *m;
243 m = ddraw_get_object(&lpDevice->handle_table, ci->u2.dwArg[0] - 1, DDRAW_HANDLE_MATERIAL);
245 ERR("Invalid material handle %#x.\n", ci->u2.dwArg[0]);
247 material_activate(m);
249 else if (ci->u1.dlstLightStateType == D3DLIGHTSTATE_COLORMODEL /* 3 */)
251 switch (ci->u2.dwArg[0]) {
253 ERR("DDCOLOR_MONO should not happen!\n");
256 /* We are already in this mode */
259 ERR("Unknown color model!\n");
262 D3DRENDERSTATETYPE rs = 0;
263 switch (ci->u1.dlstLightStateType) {
265 case D3DLIGHTSTATE_AMBIENT: /* 2 */
266 rs = D3DRENDERSTATE_AMBIENT;
268 case D3DLIGHTSTATE_FOGMODE: /* 4 */
269 rs = D3DRENDERSTATE_FOGVERTEXMODE;
271 case D3DLIGHTSTATE_FOGSTART: /* 5 */
272 rs = D3DRENDERSTATE_FOGSTART;
274 case D3DLIGHTSTATE_FOGEND: /* 6 */
275 rs = D3DRENDERSTATE_FOGEND;
277 case D3DLIGHTSTATE_FOGDENSITY: /* 7 */
278 rs = D3DRENDERSTATE_FOGDENSITY;
280 case D3DLIGHTSTATE_COLORVERTEX: /* 8 */
281 rs = D3DRENDERSTATE_COLORVERTEX;
287 IDirect3DDevice7_SetRenderState((IDirect3DDevice7 *)lpDevice, rs, ci->u2.dwArg[0]);
294 case D3DOP_STATERENDER: {
296 IDirect3DDevice2 *d3d_device2 = (IDirect3DDevice2 *)&lpDevice->IDirect3DDevice2_vtbl;
297 TRACE("STATERENDER (%d)\n", count);
299 for (i = 0; i < count; i++) {
300 LPD3DSTATE ci = (LPD3DSTATE) instr;
302 IDirect3DDevice2_SetRenderState(d3d_device2, ci->u1.drstRenderStateType, ci->u2.dwArg[0]);
308 case D3DOP_PROCESSVERTICES:
310 /* TODO: Share code with IDirect3DVertexBuffer::ProcessVertices and / or
311 * IWineD3DDevice::ProcessVertices
314 D3DMATRIX view_mat, world_mat, proj_mat;
315 TRACE("PROCESSVERTICES (%d)\n", count);
317 /* Get the transform and world matrix */
318 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
320 IWineD3DDevice_GetTransform(lpDevice->wineD3DDevice,
321 D3DTRANSFORMSTATE_VIEW,
322 (WINED3DMATRIX*) &view_mat);
324 IWineD3DDevice_GetTransform(lpDevice->wineD3DDevice,
325 D3DTRANSFORMSTATE_PROJECTION,
326 (WINED3DMATRIX*) &proj_mat);
328 IWineD3DDevice_GetTransform(lpDevice->wineD3DDevice,
329 WINED3DTS_WORLDMATRIX(0),
330 (WINED3DMATRIX*) &world_mat);
332 for (i = 0; i < count; i++) {
333 LPD3DPROCESSVERTICES ci = (LPD3DPROCESSVERTICES) instr;
335 TRACE(" Start : %d Dest : %d Count : %d\n",
336 ci->wStart, ci->wDest, ci->dwCount);
340 if (ci->dwFlags & D3DPROCESSVERTICES_COPY)
342 if (ci->dwFlags & D3DPROCESSVERTICES_NOCOLOR)
344 if (ci->dwFlags == D3DPROCESSVERTICES_OPMASK)
346 if (ci->dwFlags & D3DPROCESSVERTICES_TRANSFORM)
348 if (ci->dwFlags == D3DPROCESSVERTICES_TRANSFORMLIGHT)
349 TRACE("TRANSFORMLIGHT ");
350 if (ci->dwFlags & D3DPROCESSVERTICES_UPDATEEXTENTS)
351 TRACE("UPDATEEXTENTS ");
355 /* This is where doing Direct3D on top on OpenGL is quite difficult.
356 This method transforms a set of vertices using the CURRENT state
357 (lighting, projection, ...) but does not rasterize them.
358 They will only be put on screen later (with the POINT / LINE and
359 TRIANGLE op-codes). The problem is that you can have a triangle
360 with each point having been transformed using another state...
362 In this implementation, I will emulate only ONE thing : each
363 vertex can have its own "WORLD" transformation (this is used in the
364 TWIST.EXE demo of the 5.2 SDK). I suppose that all vertices of the
365 execute buffer use the same state.
367 If I find applications that change other states, I will try to do a
368 more 'fine-tuned' state emulation (but I may become quite tricky if
369 it changes a light position in the middle of a triangle).
371 In this case, a 'direct' approach (i.e. without using OpenGL, but
372 writing our own 3D rasterizer) would be easier. */
374 /* The current method (with the hypothesis that only the WORLD matrix
375 will change between two points) is like this :
376 - I transform 'manually' all the vertices with the current WORLD
377 matrix and store them in the vertex buffer
378 - during the rasterization phase, the WORLD matrix will be set to
379 the Identity matrix */
381 /* Enough for the moment */
382 if (ci->dwFlags == D3DPROCESSVERTICES_TRANSFORMLIGHT) {
384 D3DVERTEX *src = ((LPD3DVERTEX) ((char *)This->desc.lpData + vs)) + ci->wStart;
385 D3DTLVERTEX *dst = ((LPD3DTLVERTEX) (This->vertex_data)) + ci->wDest;
387 D3DVIEWPORT* Viewport = &lpViewport->viewports.vp1;
391 TRACE(" Projection Matrix : (%p)\n", &proj_mat);
392 dump_D3DMATRIX(&proj_mat);
393 TRACE(" View Matrix : (%p)\n", &view_mat);
394 dump_D3DMATRIX(&view_mat);
395 TRACE(" World Matrix : (%p)\n", &world_mat);
396 dump_D3DMATRIX(&world_mat);
399 multiply_matrix(&mat,&view_mat,&world_mat);
400 multiply_matrix(&mat,&proj_mat,&mat);
402 for (nb = 0; nb < ci->dwCount; nb++) {
403 /* No lighting yet */
404 dst->u5.color = 0xFFFFFFFF; /* Opaque white */
405 dst->u6.specular = 0xFF000000; /* No specular and no fog factor */
407 dst->u7.tu = src->u7.tu;
408 dst->u8.tv = src->u8.tv;
410 /* Now, the matrix multiplication */
411 dst->u1.sx = (src->u1.x * mat._11) + (src->u2.y * mat._21) + (src->u3.z * mat._31) + (1.0 * mat._41);
412 dst->u2.sy = (src->u1.x * mat._12) + (src->u2.y * mat._22) + (src->u3.z * mat._32) + (1.0 * mat._42);
413 dst->u3.sz = (src->u1.x * mat._13) + (src->u2.y * mat._23) + (src->u3.z * mat._33) + (1.0 * mat._43);
414 dst->u4.rhw = (src->u1.x * mat._14) + (src->u2.y * mat._24) + (src->u3.z * mat._34) + (1.0 * mat._44);
416 dst->u1.sx = dst->u1.sx / dst->u4.rhw * Viewport->dvScaleX
417 + Viewport->dwX + Viewport->dwWidth / 2;
418 dst->u2.sy = (-dst->u2.sy) / dst->u4.rhw * Viewport->dvScaleY
419 + Viewport->dwY + Viewport->dwHeight / 2;
420 dst->u3.sz /= dst->u4.rhw;
421 dst->u4.rhw = 1 / dst->u4.rhw;
427 } else if (ci->dwFlags == D3DPROCESSVERTICES_TRANSFORM) {
429 D3DLVERTEX *src = ((LPD3DLVERTEX) ((char *)This->desc.lpData + vs)) + ci->wStart;
430 D3DTLVERTEX *dst = ((LPD3DTLVERTEX) (This->vertex_data)) + ci->wDest;
432 D3DVIEWPORT* Viewport = &lpViewport->viewports.vp1;
436 TRACE(" Projection Matrix : (%p)\n", &proj_mat);
437 dump_D3DMATRIX(&proj_mat);
438 TRACE(" View Matrix : (%p)\n",&view_mat);
439 dump_D3DMATRIX(&view_mat);
440 TRACE(" World Matrix : (%p)\n", &world_mat);
441 dump_D3DMATRIX(&world_mat);
444 multiply_matrix(&mat,&view_mat,&world_mat);
445 multiply_matrix(&mat,&proj_mat,&mat);
447 for (nb = 0; nb < ci->dwCount; nb++) {
448 dst->u5.color = src->u4.color;
449 dst->u6.specular = src->u5.specular;
450 dst->u7.tu = src->u6.tu;
451 dst->u8.tv = src->u7.tv;
453 /* Now, the matrix multiplication */
454 dst->u1.sx = (src->u1.x * mat._11) + (src->u2.y * mat._21) + (src->u3.z * mat._31) + (1.0 * mat._41);
455 dst->u2.sy = (src->u1.x * mat._12) + (src->u2.y * mat._22) + (src->u3.z * mat._32) + (1.0 * mat._42);
456 dst->u3.sz = (src->u1.x * mat._13) + (src->u2.y * mat._23) + (src->u3.z * mat._33) + (1.0 * mat._43);
457 dst->u4.rhw = (src->u1.x * mat._14) + (src->u2.y * mat._24) + (src->u3.z * mat._34) + (1.0 * mat._44);
459 dst->u1.sx = dst->u1.sx / dst->u4.rhw * Viewport->dvScaleX
460 + Viewport->dwX + Viewport->dwWidth / 2;
461 dst->u2.sy = (-dst->u2.sy) / dst->u4.rhw * Viewport->dvScaleY
462 + Viewport->dwY + Viewport->dwHeight / 2;
464 dst->u3.sz /= dst->u4.rhw;
465 dst->u4.rhw = 1 / dst->u4.rhw;
470 } else if (ci->dwFlags == D3DPROCESSVERTICES_COPY) {
471 D3DTLVERTEX *src = ((LPD3DTLVERTEX) ((char *)This->desc.lpData + vs)) + ci->wStart;
472 D3DTLVERTEX *dst = ((LPD3DTLVERTEX) (This->vertex_data)) + ci->wDest;
474 memcpy(dst, src, ci->dwCount * sizeof(D3DTLVERTEX));
476 ERR("Unhandled vertex processing flag %#x.\n", ci->dwFlags);
483 case D3DOP_TEXTURELOAD: {
484 WARN("TEXTURELOAD-s (%d)\n", count);
486 instr += count * size;
490 TRACE("EXIT (%d)\n", count);
491 /* We did this instruction */
497 case D3DOP_BRANCHFORWARD: {
499 TRACE("BRANCHFORWARD (%d)\n", count);
501 for (i = 0; i < count; i++) {
502 LPD3DBRANCH ci = (LPD3DBRANCH) instr;
504 if ((This->data.dsStatus.dwStatus & ci->dwMask) == ci->dwValue) {
506 TRACE(" Branch to %d\n", ci->dwOffset);
508 instr = (char*)current + ci->dwOffset;
514 TRACE(" Branch to %d\n", ci->dwOffset);
516 instr = (char*)current + ci->dwOffset;
527 WARN("SPAN-s (%d)\n", count);
529 instr += count * size;
532 case D3DOP_SETSTATUS: {
534 TRACE("SETSTATUS (%d)\n", count);
536 for (i = 0; i < count; i++) {
537 LPD3DSTATUS ci = (LPD3DSTATUS) instr;
539 This->data.dsStatus = *ci;
546 ERR("Unhandled OpCode %d !!!\n",current->bOpcode);
547 /* Try to save ... */
548 instr += count * size;
557 /*****************************************************************************
558 * IDirect3DExecuteBuffer::QueryInterface
560 * Well, a usual QueryInterface function. Don't know fur sure which
561 * interfaces it can Query.
564 * riid: The interface ID queried for
565 * obj: Address to return the interface pointer at
568 * D3D_OK in case of a success (S_OK? Think it's the same)
569 * OLE_E_ENUM_NOMORE if the interface wasn't found.
570 * (E_NOINTERFACE?? Don't know what I really need)
572 *****************************************************************************/
573 static HRESULT WINAPI
574 IDirect3DExecuteBufferImpl_QueryInterface(IDirect3DExecuteBuffer *iface,
578 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), obj);
582 if ( IsEqualGUID( &IID_IUnknown, riid ) ) {
583 IDirect3DExecuteBuffer_AddRef(iface);
585 TRACE(" Creating IUnknown interface at %p.\n", *obj);
588 if ( IsEqualGUID( &IID_IDirect3DExecuteBuffer, riid ) ) {
589 IDirect3DExecuteBuffer_AddRef(iface);
591 TRACE(" Creating IDirect3DExecuteBuffer interface %p\n", *obj);
594 FIXME("(%p): interface for IID %s NOT found!\n", iface, debugstr_guid(riid));
595 return E_NOINTERFACE;
599 /*****************************************************************************
600 * IDirect3DExecuteBuffer::AddRef
602 * A normal AddRef method, nothing special
607 *****************************************************************************/
609 IDirect3DExecuteBufferImpl_AddRef(IDirect3DExecuteBuffer *iface)
611 IDirect3DExecuteBufferImpl *This = (IDirect3DExecuteBufferImpl *)iface;
612 ULONG ref = InterlockedIncrement(&This->ref);
614 TRACE("%p increasing refcount to %u.\n", This, ref);
619 /*****************************************************************************
620 * IDirect3DExecuteBuffer::Release
622 * A normal Release method, nothing special
627 *****************************************************************************/
629 IDirect3DExecuteBufferImpl_Release(IDirect3DExecuteBuffer *iface)
631 IDirect3DExecuteBufferImpl *This = (IDirect3DExecuteBufferImpl *)iface;
632 ULONG ref = InterlockedDecrement(&This->ref);
634 TRACE("%p decreasing refcount to %u.\n", This, ref);
638 HeapFree(GetProcessHeap(),0,This->desc.lpData);
639 HeapFree(GetProcessHeap(),0,This->vertex_data);
640 HeapFree(GetProcessHeap(),0,This->indices);
641 HeapFree(GetProcessHeap(),0,This);
648 /*****************************************************************************
649 * IDirect3DExecuteBuffer::Initialize
651 * Initializes the Execute Buffer. This method exists for COM compliance
652 * Nothing to do here.
657 *****************************************************************************/
658 static HRESULT WINAPI IDirect3DExecuteBufferImpl_Initialize(IDirect3DExecuteBuffer *iface,
659 IDirect3DDevice *device, D3DEXECUTEBUFFERDESC *desc)
661 TRACE("iface %p, device %p, desc %p.\n", iface, device, desc);
666 /*****************************************************************************
667 * IDirect3DExecuteBuffer::Lock
669 * Locks the buffer, so the app can write into it.
672 * Desc: Pointer to return the buffer description. This Description contains
673 * a pointer to the buffer data.
676 * This implementation always returns D3D_OK
678 *****************************************************************************/
679 static HRESULT WINAPI
680 IDirect3DExecuteBufferImpl_Lock(IDirect3DExecuteBuffer *iface,
681 D3DEXECUTEBUFFERDESC *lpDesc)
683 IDirect3DExecuteBufferImpl *This = (IDirect3DExecuteBufferImpl *)iface;
686 TRACE("iface %p, desc %p.\n", iface, lpDesc);
688 dwSize = lpDesc->dwSize;
689 memcpy(lpDesc, &This->desc, dwSize);
693 TRACE(" Returning description :\n");
694 _dump_D3DEXECUTEBUFFERDESC(lpDesc);
699 /*****************************************************************************
700 * IDirect3DExecuteBuffer::Unlock
702 * Unlocks the buffer. We don't have anything to do here
705 * This implementation always returns D3D_OK
707 *****************************************************************************/
708 static HRESULT WINAPI IDirect3DExecuteBufferImpl_Unlock(IDirect3DExecuteBuffer *iface)
710 TRACE("iface %p.\n", iface);
715 /*****************************************************************************
716 * IDirect3DExecuteBuffer::SetExecuteData
718 * Sets the execute data. This data is used to describe the buffer's content
721 * Data: Pointer to a D3DEXECUTEDATA structure containing the data to
726 * DDERR_OUTOFMEMORY if the vertex buffer allocation failed
728 *****************************************************************************/
729 static HRESULT WINAPI
730 IDirect3DExecuteBufferImpl_SetExecuteData(IDirect3DExecuteBuffer *iface,
731 D3DEXECUTEDATA *lpData)
733 IDirect3DExecuteBufferImpl *This = (IDirect3DExecuteBufferImpl *)iface;
736 TRACE("iface %p, data %p.\n", iface, lpData);
738 memcpy(&This->data, lpData, lpData->dwSize);
740 /* Get the number of vertices in the execute buffer */
741 nbvert = This->data.dwVertexCount;
743 /* Prepares the transformed vertex buffer */
744 HeapFree(GetProcessHeap(), 0, This->vertex_data);
745 This->vertex_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nbvert * sizeof(D3DTLVERTEX));
748 _dump_executedata(lpData);
753 /*****************************************************************************
754 * IDirect3DExecuteBuffer::GetExecuteData
756 * Returns the data in the execute buffer
759 * Data: Pointer to a D3DEXECUTEDATA structure used to return data
764 *****************************************************************************/
765 static HRESULT WINAPI
766 IDirect3DExecuteBufferImpl_GetExecuteData(IDirect3DExecuteBuffer *iface,
767 D3DEXECUTEDATA *lpData)
769 IDirect3DExecuteBufferImpl *This = (IDirect3DExecuteBufferImpl *)iface;
772 TRACE("iface %p, data %p.\n", iface, lpData);
774 dwSize = lpData->dwSize;
775 memcpy(lpData, &This->data, dwSize);
779 TRACE("Returning data :\n");
780 _dump_executedata(lpData);
786 /*****************************************************************************
787 * IDirect3DExecuteBuffer::Validate
789 * DirectX 5 SDK: "The IDirect3DExecuteBuffer::Validate method is not
790 * currently implemented"
796 * DDERR_UNSUPPORTED, because it's not implemented in Windows.
798 *****************************************************************************/
799 static HRESULT WINAPI IDirect3DExecuteBufferImpl_Validate(IDirect3DExecuteBuffer *iface,
800 DWORD *offset, LPD3DVALIDATECALLBACK callback, void *context, DWORD reserved)
802 TRACE("iface %p, offset %p, callback %p, context %p, reserved %#x.\n",
803 iface, offset, callback, context, reserved);
805 WARN("Not implemented.\n");
807 return DDERR_UNSUPPORTED; /* Unchecked */
810 /*****************************************************************************
811 * IDirect3DExecuteBuffer::Optimize
813 * DirectX5 SDK: "The IDirect3DExecuteBuffer::Optimize method is not
814 * currently supported"
817 * Dummy: Seems to be an unused dummy ;)
820 * DDERR_UNSUPPORTED, because it's not implemented in Windows.
822 *****************************************************************************/
823 static HRESULT WINAPI IDirect3DExecuteBufferImpl_Optimize(IDirect3DExecuteBuffer *iface, DWORD reserved)
825 TRACE("iface %p, reserved %#x.\n", iface, reserved);
827 WARN("Not implemented.\n");
829 return DDERR_UNSUPPORTED; /* Unchecked */
832 static const struct IDirect3DExecuteBufferVtbl d3d_execute_buffer_vtbl =
834 IDirect3DExecuteBufferImpl_QueryInterface,
835 IDirect3DExecuteBufferImpl_AddRef,
836 IDirect3DExecuteBufferImpl_Release,
837 IDirect3DExecuteBufferImpl_Initialize,
838 IDirect3DExecuteBufferImpl_Lock,
839 IDirect3DExecuteBufferImpl_Unlock,
840 IDirect3DExecuteBufferImpl_SetExecuteData,
841 IDirect3DExecuteBufferImpl_GetExecuteData,
842 IDirect3DExecuteBufferImpl_Validate,
843 IDirect3DExecuteBufferImpl_Optimize,
846 HRESULT d3d_execute_buffer_init(IDirect3DExecuteBufferImpl *execute_buffer,
847 IDirect3DDeviceImpl *device, D3DEXECUTEBUFFERDESC *desc)
849 execute_buffer->lpVtbl = &d3d_execute_buffer_vtbl;
850 execute_buffer->ref = 1;
851 execute_buffer->d3ddev = device;
853 /* Initializes memory */
854 memcpy(&execute_buffer->desc, desc, desc->dwSize);
856 /* No buffer given */
857 if (!(execute_buffer->desc.dwFlags & D3DDEB_LPDATA))
858 execute_buffer->desc.lpData = NULL;
860 /* No buffer size given */
861 if (!(execute_buffer->desc.dwFlags & D3DDEB_BUFSIZE))
862 execute_buffer->desc.dwBufferSize = 0;
864 /* Create buffer if asked */
865 if (!execute_buffer->desc.lpData && execute_buffer->desc.dwBufferSize)
867 execute_buffer->need_free = TRUE;
868 execute_buffer->desc.lpData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, execute_buffer->desc.dwBufferSize);
869 if (!execute_buffer->desc.lpData)
871 ERR("Failed to allocate execute buffer data.\n");
872 return DDERR_OUTOFMEMORY;
876 execute_buffer->desc.dwFlags |= D3DDEB_LPDATA;