1 /* Direct3D ExecuteBuffer
2 * Copyright (c) 1998-2004 Lionel ULMER
3 * Copyright (c) 2002-2004 Christian Costa
5 * This file contains the implementation of Direct3DExecuteBuffer.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
39 #include "wine/debug.h"
41 #include "d3d_private.h"
42 #include "opengl_private.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
45 WINE_DECLARE_DEBUG_CHANNEL(ddraw_geom);
47 static void _dump_d3dstatus(LPD3DSTATUS lpStatus) {
51 static void _dump_executedata(LPD3DEXECUTEDATA lpData) {
52 DPRINTF("dwSize : %ld\n", lpData->dwSize);
53 DPRINTF("Vertex Offset : %ld Count : %ld\n", lpData->dwVertexOffset, lpData->dwVertexCount);
54 DPRINTF("Instruction Offset : %ld Length : %ld\n", lpData->dwInstructionOffset, lpData->dwInstructionLength);
55 DPRINTF("HVertex Offset : %ld\n", lpData->dwHVertexOffset);
56 _dump_d3dstatus(&(lpData->dsStatus));
59 static void _dump_D3DEXECUTEBUFFERDESC(LPD3DEXECUTEBUFFERDESC lpDesc) {
60 DPRINTF("dwSize : %ld\n", lpDesc->dwSize);
61 DPRINTF("dwFlags : %lx\n", lpDesc->dwFlags);
62 DPRINTF("dwCaps : %lx\n", lpDesc->dwCaps);
63 DPRINTF("dwBufferSize : %ld\n", lpDesc->dwBufferSize);
64 DPRINTF("lpData : %p\n", lpDesc->lpData);
67 static void execute(IDirect3DExecuteBufferImpl *This,
68 IDirect3DDeviceImpl *lpDevice,
69 IDirect3DViewportImpl *lpViewport)
71 /* DWORD bs = This->desc.dwBufferSize; */
72 DWORD vs = This->data.dwVertexOffset;
73 /* DWORD vc = This->data.dwVertexCount; */
74 DWORD is = This->data.dwInstructionOffset;
75 /* DWORD il = This->data.dwInstructionLength; */
77 char *instr = (char *)This->desc.lpData + is;
79 /* Should check if the viewport was added or not to the device */
81 /* Activate the viewport */
82 lpViewport->active_device = lpDevice;
83 lpViewport->activate(lpViewport);
85 TRACE("ExecuteData : \n");
87 _dump_executedata(&(This->data));
90 LPD3DINSTRUCTION current = (LPD3DINSTRUCTION) instr;
94 count = current->wCount;
95 size = current->bSize;
96 instr += sizeof(D3DINSTRUCTION);
98 switch (current->bOpcode) {
100 WARN("POINT-s (%d)\n", count);
101 instr += count * size;
105 WARN("LINE-s (%d)\n", count);
106 instr += count * size;
109 case D3DOP_TRIANGLE: {
111 D3DTLVERTEX *tl_vx = (D3DTLVERTEX *) This->vertex_data;
112 TRACE("TRIANGLE (%d)\n", count);
114 if (count*3>This->nb_indices) {
115 This->nb_indices = count * 3;
116 HeapFree(GetProcessHeap(),0,This->indices);
117 This->indices = HeapAlloc(GetProcessHeap(),0,sizeof(WORD)*This->nb_indices);
120 for (i = 0; i < count; i++) {
121 LPD3DTRIANGLE ci = (LPD3DTRIANGLE) instr;
122 TRACE_(ddraw_geom)(" v1: %d v2: %d v3: %d\n",ci->u1.v1, ci->u2.v2, ci->u3.v3);
123 TRACE_(ddraw_geom)(" Flags : ");
124 if (TRACE_ON(ddraw)) {
126 if (ci->wFlags & D3DTRIFLAG_EDGEENABLE1)
127 TRACE_(ddraw_geom)("EDGEENABLE1 ");
128 if (ci->wFlags & D3DTRIFLAG_EDGEENABLE2)
129 TRACE_(ddraw_geom)("EDGEENABLE2 ");
130 if (ci->wFlags & D3DTRIFLAG_EDGEENABLE1)
131 TRACE_(ddraw_geom)("EDGEENABLE3 ");
133 if (ci->wFlags == D3DTRIFLAG_EVEN)
134 TRACE_(ddraw_geom)("EVEN ");
135 if (ci->wFlags == D3DTRIFLAG_ODD)
136 TRACE_(ddraw_geom)("ODD ");
137 if (ci->wFlags == D3DTRIFLAG_START)
138 TRACE_(ddraw_geom)("START ");
139 if ((ci->wFlags > 0) && (ci->wFlags < 30))
140 TRACE_(ddraw_geom)("STARTFLAT(%d) ", ci->wFlags);
141 TRACE_(ddraw_geom)("\n");
143 This->indices[(i * 3) ] = ci->u1.v1;
144 This->indices[(i * 3) + 1] = ci->u2.v2;
145 This->indices[(i * 3) + 2] = ci->u3.v3;
148 IDirect3DDevice7_DrawIndexedPrimitive(ICOM_INTERFACE(lpDevice,IDirect3DDevice7),
149 D3DPT_TRIANGLELIST,D3DFVF_TLVERTEX,tl_vx,0,This->indices,count*3,0);
152 case D3DOP_MATRIXLOAD:
153 WARN("MATRIXLOAD-s (%d)\n", count);
154 instr += count * size;
157 case D3DOP_MATRIXMULTIPLY: {
159 TRACE("MATRIXMULTIPLY (%d)\n", count);
161 for (i = 0; i < count; i++) {
162 LPD3DMATRIXMULTIPLY ci = (LPD3DMATRIXMULTIPLY) instr;
163 LPD3DMATRIX a = (LPD3DMATRIX) ci->hDestMatrix;
164 LPD3DMATRIX b = (LPD3DMATRIX) ci->hSrcMatrix1;
165 LPD3DMATRIX c = (LPD3DMATRIX) ci->hSrcMatrix2;
167 TRACE(" Dest : %08lx Src1 : %08lx Src2 : %08lx\n",
168 ci->hDestMatrix, ci->hSrcMatrix1, ci->hSrcMatrix2);
170 multiply_matrix(a,c,b);
176 case D3DOP_STATETRANSFORM: {
178 TRACE("STATETRANSFORM (%d)\n", count);
180 for (i = 0; i < count; i++) {
181 LPD3DSTATE ci = (LPD3DSTATE) instr;
183 IDirect3DDevice7_SetTransform(ICOM_INTERFACE(lpDevice, IDirect3DDevice7),
184 ci->u1.drstRenderStateType, (LPD3DMATRIX)ci->u2.dwArg[0]);
190 case D3DOP_STATELIGHT: {
192 TRACE("STATELIGHT (%d)\n", count);
194 for (i = 0; i < count; i++) {
195 LPD3DSTATE ci = (LPD3DSTATE) instr;
197 TRACE("(%08x,%08lx)\n",ci->u1.dlstLightStateType, ci->u2.dwArg[0]);
199 if (!ci->u1.dlstLightStateType && (ci->u1.dlstLightStateType > D3DLIGHTSTATE_COLORVERTEX))
200 ERR("Unexpected Light State Type\n");
201 else if (ci->u1.dlstLightStateType == D3DLIGHTSTATE_MATERIAL /* 1 */) {
202 IDirect3DMaterialImpl *mat = (IDirect3DMaterialImpl *) ci->u2.dwArg[0];
207 FIXME(" D3DLIGHTSTATE_MATERIAL called with NULL material !!!\n");
210 else if (ci->u1.dlstLightStateType == D3DLIGHTSTATE_COLORMODEL /* 3 */) {
211 switch (ci->u2.dwArg[0]) {
213 ERR("DDCOLOR_MONO should not happen!\n");
216 /* We are already in this mode */
219 ERR("Unknown color model!\n");
222 D3DRENDERSTATETYPE rs = 0;
223 switch (ci->u1.dlstLightStateType) {
225 case D3DLIGHTSTATE_AMBIENT: /* 2 */
226 rs = D3DRENDERSTATE_AMBIENT;
228 case D3DLIGHTSTATE_FOGMODE: /* 4 */
229 rs = D3DRENDERSTATE_FOGVERTEXMODE;
231 case D3DLIGHTSTATE_FOGSTART: /* 5 */
232 rs = D3DRENDERSTATE_FOGSTART;
234 case D3DLIGHTSTATE_FOGEND: /* 6 */
235 rs = D3DRENDERSTATE_FOGEND;
237 case D3DLIGHTSTATE_FOGDENSITY: /* 7 */
238 rs = D3DRENDERSTATE_FOGDENSITY;
240 case D3DLIGHTSTATE_COLORVERTEX: /* 8 */
241 rs = D3DRENDERSTATE_COLORVERTEX;
247 IDirect3DDevice7_SetRenderState(ICOM_INTERFACE(lpDevice, IDirect3DDevice7),
255 case D3DOP_STATERENDER: {
257 TRACE("STATERENDER (%d)\n", count);
259 for (i = 0; i < count; i++) {
260 LPD3DSTATE ci = (LPD3DSTATE) instr;
262 IDirect3DDevice7_SetRenderState(ICOM_INTERFACE(lpDevice, IDirect3DDevice7),
263 ci->u1.drstRenderStateType, ci->u2.dwArg[0]);
269 case D3DOP_PROCESSVERTICES: {
271 TRACE("PROCESSVERTICES (%d)\n", count);
273 for (i = 0; i < count; i++) {
274 LPD3DPROCESSVERTICES ci = (LPD3DPROCESSVERTICES) instr;
276 TRACE(" Start : %d Dest : %d Count : %ld\n",
277 ci->wStart, ci->wDest, ci->dwCount);
279 if (TRACE_ON(ddraw)) {
280 if (ci->dwFlags & D3DPROCESSVERTICES_COPY)
282 if (ci->dwFlags & D3DPROCESSVERTICES_NOCOLOR)
284 if (ci->dwFlags == D3DPROCESSVERTICES_OPMASK)
286 if (ci->dwFlags & D3DPROCESSVERTICES_TRANSFORM)
288 if (ci->dwFlags == D3DPROCESSVERTICES_TRANSFORMLIGHT)
289 TRACE("TRANSFORMLIGHT ");
290 if (ci->dwFlags & D3DPROCESSVERTICES_UPDATEEXTENTS)
291 TRACE("UPDATEEXTENTS ");
295 /* This is where doing Direct3D on top on OpenGL is quite difficult.
296 This method transforms a set of vertices using the CURRENT state
297 (lighting, projection, ...) but does not rasterize them.
298 They will only be put on screen later (with the POINT / LINE and
299 TRIANGLE op-codes). The problem is that you can have a triangle
300 with each point having been transformed using another state...
302 In this implementation, I will emulate only ONE thing : each
303 vertex can have its own "WORLD" transformation (this is used in the
304 TWIST.EXE demo of the 5.2 SDK). I suppose that all vertices of the
305 execute buffer use the same state.
307 If I find applications that change other states, I will try to do a
308 more 'fine-tuned' state emulation (but I may become quite tricky if
309 it changes a light position in the middle of a triangle).
311 In this case, a 'direct' approach (i.e. without using OpenGL, but
312 writing our own 3D rasterizer) would be easier. */
314 /* The current method (with the hypothesis that only the WORLD matrix
315 will change between two points) is like this :
316 - I transform 'manually' all the vertices with the current WORLD
317 matrix and store them in the vertex buffer
318 - during the rasterization phase, the WORLD matrix will be set to
319 the Identity matrix */
321 /* Enough for the moment */
322 if (ci->dwFlags == D3DPROCESSVERTICES_TRANSFORMLIGHT) {
324 D3DVERTEX *src = ((LPD3DVERTEX) ((char *)This->desc.lpData + vs)) + ci->wStart;
325 D3DTLVERTEX *dst = ((LPD3DTLVERTEX) (This->vertex_data)) + ci->wDest;
326 D3DMATRIX *mat2 = lpDevice->world_mat;
329 D3DVIEWPORT* Viewport = &lpViewport->viewports.vp1;
331 if (TRACE_ON(ddraw)) {
332 TRACE(" Projection Matrix : (%p)\n", lpDevice->proj_mat);
333 dump_D3DMATRIX(lpDevice->proj_mat);
334 TRACE(" View Matrix : (%p)\n", lpDevice->view_mat);
335 dump_D3DMATRIX(lpDevice->view_mat);
336 TRACE(" World Matrix : (%p)\n", lpDevice->world_mat);
337 dump_D3DMATRIX(lpDevice->world_mat);
340 multiply_matrix(&mat,lpDevice->view_mat,lpDevice->world_mat);
341 multiply_matrix(&mat,lpDevice->proj_mat,&mat);
343 for (nb = 0; nb < ci->dwCount; nb++) {
344 /* Normals transformation */
345 nx = (src->u4.nx * mat2->_11) + (src->u5.ny * mat2->_21) + (src->u6.nz * mat2->_31);
346 ny = (src->u4.nx * mat2->_12) + (src->u5.ny * mat2->_22) + (src->u6.nz * mat2->_32);
347 nz = (src->u4.nx * mat2->_13) + (src->u5.ny * mat2->_23) + (src->u6.nz * mat2->_33);
349 /* No lighting yet */
350 dst->u5.color = 0xFFFFFFFF; /* Opaque white */
351 dst->u6.specular = 0xFF000000; /* No specular and no fog factor */
353 dst->u7.tu = src->u7.tu;
354 dst->u8.tv = src->u8.tv;
356 /* Now, the matrix multiplication */
357 dst->u1.sx = (src->u1.x * mat._11) + (src->u2.y * mat._21) + (src->u3.z * mat._31) + (1.0 * mat._41);
358 dst->u2.sy = (src->u1.x * mat._12) + (src->u2.y * mat._22) + (src->u3.z * mat._32) + (1.0 * mat._42);
359 dst->u3.sz = (src->u1.x * mat._13) + (src->u2.y * mat._23) + (src->u3.z * mat._33) + (1.0 * mat._43);
360 dst->u4.rhw = (src->u1.x * mat._14) + (src->u2.y * mat._24) + (src->u3.z * mat._34) + (1.0 * mat._44);
362 dst->u1.sx = dst->u1.sx / dst->u4.rhw * Viewport->dwWidth / 2
363 + Viewport->dwX + Viewport->dwWidth / 2;
364 dst->u2.sy = dst->u2.sy / dst->u4.rhw * Viewport->dwHeight / 2
365 + Viewport->dwY + Viewport->dwHeight / 2;
366 dst->u3.sz /= dst->u4.rhw;
367 dst->u4.rhw = 1 / dst->u4.rhw;
373 } else if (ci->dwFlags == D3DPROCESSVERTICES_TRANSFORM) {
375 D3DLVERTEX *src = ((LPD3DLVERTEX) ((char *)This->desc.lpData + vs)) + ci->wStart;
376 D3DTLVERTEX *dst = ((LPD3DTLVERTEX) (This->vertex_data)) + ci->wDest;
378 D3DVIEWPORT* Viewport = &lpViewport->viewports.vp1;
380 if (TRACE_ON(ddraw)) {
381 TRACE(" Projection Matrix : (%p)\n", lpDevice->proj_mat);
382 dump_D3DMATRIX(lpDevice->proj_mat);
383 TRACE(" View Matrix : (%p)\n", lpDevice->view_mat);
384 dump_D3DMATRIX(lpDevice->view_mat);
385 TRACE(" World Matrix : (%p)\n", &mat);
386 dump_D3DMATRIX(&mat);
389 multiply_matrix(&mat,lpDevice->view_mat,lpDevice->world_mat);
390 multiply_matrix(&mat,lpDevice->proj_mat,&mat);
392 for (nb = 0; nb < ci->dwCount; nb++) {
393 dst->u5.color = src->u4.color;
394 dst->u6.specular = src->u5.specular;
395 dst->u7.tu = src->u6.tu;
396 dst->u8.tv = src->u7.tv;
398 /* Now, the matrix multiplication */
399 dst->u1.sx = (src->u1.x * mat._11) + (src->u2.y * mat._21) + (src->u3.z * mat._31) + (1.0 * mat._41);
400 dst->u2.sy = (src->u1.x * mat._12) + (src->u2.y * mat._22) + (src->u3.z * mat._32) + (1.0 * mat._42);
401 dst->u3.sz = (src->u1.x * mat._13) + (src->u2.y * mat._23) + (src->u3.z * mat._33) + (1.0 * mat._43);
402 dst->u4.rhw = (src->u1.x * mat._14) + (src->u2.y * mat._24) + (src->u3.z * mat._34) + (1.0 * mat._44);
404 dst->u1.sx /= dst->u4.rhw * Viewport->dvScaleX * Viewport->dwWidth / 2 + Viewport->dwX;
405 dst->u2.sy /= dst->u4.rhw * Viewport->dvScaleY * Viewport->dwHeight / 2 + Viewport->dwY;
406 dst->u3.sz /= dst->u4.rhw;
407 dst->u4.rhw = 1 / dst->u4.rhw;
412 } else if (ci->dwFlags == D3DPROCESSVERTICES_COPY) {
413 D3DTLVERTEX *src = ((LPD3DTLVERTEX) ((char *)This->desc.lpData + vs)) + ci->wStart;
414 D3DTLVERTEX *dst = ((LPD3DTLVERTEX) (This->vertex_data)) + ci->wDest;
416 memcpy(dst, src, ci->dwCount * sizeof(D3DTLVERTEX));
418 ERR("Unhandled vertex processing !\n");
425 case D3DOP_TEXTURELOAD: {
426 WARN("TEXTURELOAD-s (%d)\n", count);
428 instr += count * size;
432 TRACE("EXIT (%d)\n", count);
433 /* We did this instruction */
439 case D3DOP_BRANCHFORWARD: {
441 TRACE("BRANCHFORWARD (%d)\n", count);
443 for (i = 0; i < count; i++) {
444 LPD3DBRANCH ci = (LPD3DBRANCH) instr;
446 if ((This->data.dsStatus.dwStatus & ci->dwMask) == ci->dwValue) {
448 TRACE(" Branch to %ld\n", ci->dwOffset);
449 instr = (char*)current + ci->dwOffset;
454 TRACE(" Branch to %ld\n", ci->dwOffset);
455 instr = (char*)current + ci->dwOffset;
465 WARN("SPAN-s (%d)\n", count);
467 instr += count * size;
470 case D3DOP_SETSTATUS: {
472 TRACE("SETSTATUS (%d)\n", count);
474 for (i = 0; i < count; i++) {
475 LPD3DSTATUS ci = (LPD3DSTATUS) instr;
477 This->data.dsStatus = *ci;
484 ERR("Unhandled OpCode %d !!!\n",current->bOpcode);
485 /* Try to save ... */
486 instr += count * size;
496 Main_IDirect3DExecuteBufferImpl_1_QueryInterface(LPDIRECT3DEXECUTEBUFFER iface,
500 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
501 TRACE("(%p/%p)->(%s,%p)\n", This, iface, debugstr_guid(riid), obp);
505 if ( IsEqualGUID( &IID_IUnknown, riid ) ) {
506 IDirect3DExecuteBuffer_AddRef(ICOM_INTERFACE(This, IDirect3DExecuteBuffer));
508 TRACE(" Creating IUnknown interface at %p.\n", *obp);
511 if ( IsEqualGUID( &IID_IDirect3DMaterial, riid ) ) {
512 IDirect3DExecuteBuffer_AddRef(ICOM_INTERFACE(This, IDirect3DExecuteBuffer));
513 *obp = ICOM_INTERFACE(This, IDirect3DExecuteBuffer);
514 TRACE(" Creating IDirect3DExecuteBuffer interface %p\n", *obp);
517 FIXME("(%p): interface for IID %s NOT found!\n", This, debugstr_guid(riid));
518 return OLE_E_ENUM_NOMORE;
522 Main_IDirect3DExecuteBufferImpl_1_AddRef(LPDIRECT3DEXECUTEBUFFER iface)
524 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
525 ULONG ref = InterlockedIncrement(&This->ref);
527 FIXME("(%p/%p)->()incrementing from %lu.\n", This, iface, ref - 1);
533 Main_IDirect3DExecuteBufferImpl_1_Release(LPDIRECT3DEXECUTEBUFFER iface)
535 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
536 ULONG ref = InterlockedDecrement(&This->ref);
538 TRACE("(%p/%p)->()decrementing from %lu.\n", This, iface, ref + 1);
541 if ((This->desc.lpData != NULL) && This->need_free)
542 HeapFree(GetProcessHeap(),0,This->desc.lpData);
543 HeapFree(GetProcessHeap(),0,This->vertex_data);
544 HeapFree(GetProcessHeap(),0,This->indices);
545 HeapFree(GetProcessHeap(),0,This);
553 Main_IDirect3DExecuteBufferImpl_1_Initialize(LPDIRECT3DEXECUTEBUFFER iface,
554 LPDIRECT3DDEVICE lpDirect3DDevice,
555 LPD3DEXECUTEBUFFERDESC lpDesc)
557 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
558 TRACE("(%p/%p)->(%p,%p) no-op....\n", This, iface, lpDirect3DDevice, lpDesc);
563 Main_IDirect3DExecuteBufferImpl_1_Lock(LPDIRECT3DEXECUTEBUFFER iface,
564 LPD3DEXECUTEBUFFERDESC lpDesc)
566 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
568 TRACE("(%p/%p)->(%p)\n", This, iface, lpDesc);
570 dwSize = lpDesc->dwSize;
571 memset(lpDesc, 0, dwSize);
572 memcpy(lpDesc, &This->desc, dwSize);
574 if (TRACE_ON(ddraw)) {
575 TRACE(" Returning description : \n");
576 _dump_D3DEXECUTEBUFFERDESC(lpDesc);
582 Main_IDirect3DExecuteBufferImpl_1_Unlock(LPDIRECT3DEXECUTEBUFFER iface)
584 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
585 TRACE("(%p/%p)->() no-op...\n", This, iface);
590 Main_IDirect3DExecuteBufferImpl_1_SetExecuteData(LPDIRECT3DEXECUTEBUFFER iface,
591 LPD3DEXECUTEDATA lpData)
593 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
595 TRACE("(%p/%p)->(%p)\n", This, iface, lpData);
597 memcpy(&This->data, lpData, lpData->dwSize);
599 /* Get the number of vertices in the execute buffer */
600 nbvert = This->data.dwVertexCount;
602 /* Prepares the transformed vertex buffer */
603 HeapFree(GetProcessHeap(), 0, This->vertex_data);
604 This->vertex_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nbvert * sizeof(D3DTLVERTEX));
606 if (TRACE_ON(ddraw)) {
607 _dump_executedata(lpData);
614 Main_IDirect3DExecuteBufferImpl_1_GetExecuteData(LPDIRECT3DEXECUTEBUFFER iface,
615 LPD3DEXECUTEDATA lpData)
617 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
619 TRACE("(%p/%p)->(%p): stub!\n", This, iface, lpData);
621 dwSize = lpData->dwSize;
622 memset(lpData, 0, dwSize);
623 memcpy(lpData, &This->data, dwSize);
625 if (TRACE_ON(ddraw)) {
626 TRACE("Returning data : \n");
627 _dump_executedata(lpData);
634 Main_IDirect3DExecuteBufferImpl_1_Validate(LPDIRECT3DEXECUTEBUFFER iface,
636 LPD3DVALIDATECALLBACK lpFunc,
640 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
641 FIXME("(%p/%p)->(%p,%p,%p,%08lx): stub!\n", This, iface, lpdwOffset, lpFunc, lpUserArg, dwReserved);
646 Main_IDirect3DExecuteBufferImpl_1_Optimize(LPDIRECT3DEXECUTEBUFFER iface,
649 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
650 TRACE("(%p/%p)->(%08lx) no-op...\n", This, iface, dwDummy);
654 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
655 # define XCAST(fun) (typeof(VTABLE_IDirect3DExecuteBuffer.fun))
657 # define XCAST(fun) (void*)
660 static const IDirect3DExecuteBufferVtbl VTABLE_IDirect3DExecuteBuffer =
662 XCAST(QueryInterface) Main_IDirect3DExecuteBufferImpl_1_QueryInterface,
663 XCAST(AddRef) Main_IDirect3DExecuteBufferImpl_1_AddRef,
664 XCAST(Release) Main_IDirect3DExecuteBufferImpl_1_Release,
665 XCAST(Initialize) Main_IDirect3DExecuteBufferImpl_1_Initialize,
666 XCAST(Lock) Main_IDirect3DExecuteBufferImpl_1_Lock,
667 XCAST(Unlock) Main_IDirect3DExecuteBufferImpl_1_Unlock,
668 XCAST(SetExecuteData) Main_IDirect3DExecuteBufferImpl_1_SetExecuteData,
669 XCAST(GetExecuteData) Main_IDirect3DExecuteBufferImpl_1_GetExecuteData,
670 XCAST(Validate) Main_IDirect3DExecuteBufferImpl_1_Validate,
671 XCAST(Optimize) Main_IDirect3DExecuteBufferImpl_1_Optimize,
674 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
679 HRESULT d3dexecutebuffer_create(IDirect3DExecuteBufferImpl **obj, IDirectDrawImpl *d3d, IDirect3DDeviceImpl *d3ddev, LPD3DEXECUTEBUFFERDESC lpDesc)
681 IDirect3DExecuteBufferImpl* object;
683 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DExecuteBufferImpl));
685 ICOM_INIT_INTERFACE(object, IDirect3DExecuteBuffer, VTABLE_IDirect3DExecuteBuffer);
689 object->d3ddev = d3ddev;
691 /* Initializes memory */
692 memcpy(&object->desc, lpDesc, lpDesc->dwSize);
694 /* No buffer given */
695 if ((object->desc.dwFlags & D3DDEB_LPDATA) == 0)
696 object->desc.lpData = NULL;
698 /* No buffer size given */
699 if ((lpDesc->dwFlags & D3DDEB_BUFSIZE) == 0)
700 object->desc.dwBufferSize = 0;
702 /* Create buffer if asked */
703 if ((object->desc.lpData == NULL) && (object->desc.dwBufferSize > 0)) {
704 object->need_free = TRUE;
705 object->desc.lpData = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,object->desc.dwBufferSize);
707 object->need_free = FALSE;
710 /* No vertices for the moment */
711 object->vertex_data = NULL;
713 object->desc.dwFlags |= D3DDEB_LPDATA;
715 object->execute = execute;
717 object->indices = NULL;
718 object->nb_indices = 0;
722 TRACE(" creating implementation at %p.\n", *obj);