1 /* Direct3D ExecuteBuffer
2 * Copyright (c) 1998 Lionel ULMER
4 * This file contains the implementation of Direct3DExecuteBuffer.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
35 #include "wine/debug.h"
37 #include "d3d_private.h"
38 #include "mesa_private.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
42 static void _dump_d3dstatus(LPD3DSTATUS lpStatus) {
46 static void _dump_executedata(LPD3DEXECUTEDATA lpData) {
47 DPRINTF("dwSize : %ld\n", lpData->dwSize);
48 DPRINTF("Vertex Offset : %ld Count : %ld\n", lpData->dwVertexOffset, lpData->dwVertexCount);
49 DPRINTF("Instruction Offset : %ld Length : %ld\n", lpData->dwInstructionOffset, lpData->dwInstructionLength);
50 DPRINTF("HVertex Offset : %ld\n", lpData->dwHVertexOffset);
51 _dump_d3dstatus(&(lpData->dsStatus));
54 static void _dump_D3DEXECUTEBUFFERDESC(LPD3DEXECUTEBUFFERDESC lpDesc) {
58 static void execute(IDirect3DExecuteBufferImpl *This,
59 IDirect3DDeviceImpl *lpDevice,
60 IDirect3DViewportImpl *lpViewport)
62 /* DWORD bs = This->desc.dwBufferSize; */
63 DWORD vs = This->data.dwVertexOffset;
64 /* DWORD vc = This->data.dwVertexCount; */
65 DWORD is = This->data.dwInstructionOffset;
66 /* DWORD il = This->data.dwInstructionLength; */
68 char *instr = (char *)This->desc.lpData + is;
70 /* Should check if the viewport was added or not to the device */
72 /* Activate the viewport */
73 lpViewport->active_device = lpDevice;
74 lpViewport->activate(lpViewport);
76 TRACE("ExecuteData : \n");
78 _dump_executedata(&(This->data));
81 LPD3DINSTRUCTION current = (LPD3DINSTRUCTION) instr;
85 count = current->wCount;
86 size = current->bSize;
87 instr += sizeof(D3DINSTRUCTION);
89 switch (current->bOpcode) {
91 WARN("POINT-s (%d)\n", count);
92 instr += count * size;
96 WARN("LINE-s (%d)\n", count);
97 instr += count * size;
100 case D3DOP_TRIANGLE: {
102 D3DTLVERTEX *tl_vx = (D3DTLVERTEX *) This->vertex_data;
103 TRACE("TRIANGLE (%d)\n", count);
105 if (count*3>This->nb_indices) {
106 This->nb_indices = count * 3;
108 HeapFree(GetProcessHeap(),0,This->indices);
109 This->indices = HeapAlloc(GetProcessHeap(),0,sizeof(WORD)*This->nb_indices);
112 for (i = 0; i < count; i++) {
113 LPD3DTRIANGLE ci = (LPD3DTRIANGLE) instr;
114 TRACE(" v1: %d v2: %d v3: %d\n",ci->u1.v1, ci->u2.v2, ci->u3.v3);
116 if (TRACE_ON(ddraw)) {
118 if (ci->wFlags & D3DTRIFLAG_EDGEENABLE1)
119 TRACE("EDGEENABLE1 ");
120 if (ci->wFlags & D3DTRIFLAG_EDGEENABLE2)
121 TRACE("EDGEENABLE2 ");
122 if (ci->wFlags & D3DTRIFLAG_EDGEENABLE1)
123 TRACE("EDGEENABLE3 ");
125 if (ci->wFlags == D3DTRIFLAG_EVEN)
127 if (ci->wFlags == D3DTRIFLAG_ODD)
129 if (ci->wFlags == D3DTRIFLAG_START)
131 if ((ci->wFlags > 0) && (ci->wFlags < 30))
132 TRACE("STARTFLAT(%d) ", ci->wFlags);
135 This->indices[i*3]=ci->u1.v1;This->indices[i*3+1]=ci->u2.v2;This->indices[i*3+2]=ci->u3.v3;
138 IDirect3DDevice7_DrawIndexedPrimitive(ICOM_INTERFACE(lpDevice,IDirect3DDevice7),
139 D3DPT_TRIANGLELIST,D3DFVF_TLVERTEX,tl_vx,0,This->indices,count*3,0);
142 case D3DOP_MATRIXLOAD:
143 WARN("MATRIXLOAD-s (%d)\n", count);
144 instr += count * size;
147 case D3DOP_MATRIXMULTIPLY: {
149 TRACE("MATRIXMULTIPLY (%d)\n", count);
151 for (i = 0; i < count; i++) {
152 LPD3DMATRIXMULTIPLY ci = (LPD3DMATRIXMULTIPLY) instr;
153 LPD3DMATRIX a = (LPD3DMATRIX) ci->hDestMatrix;
154 LPD3DMATRIX b = (LPD3DMATRIX) ci->hSrcMatrix1;
155 LPD3DMATRIX c = (LPD3DMATRIX) ci->hSrcMatrix2;
157 TRACE(" Dest : %08lx Src1 : %08lx Src2 : %08lx\n",
158 ci->hDestMatrix, ci->hSrcMatrix1, ci->hSrcMatrix2);
160 multiply_matrix(a,c,b);
166 case D3DOP_STATETRANSFORM: {
168 TRACE("STATETRANSFORM (%d)\n", count);
170 for (i = 0; i < count; i++) {
171 LPD3DSTATE ci = (LPD3DSTATE) instr;
173 IDirect3DDevice7_SetTransform(ICOM_INTERFACE(lpDevice, IDirect3DDevice7),
174 ci->u1.drstRenderStateType, (LPD3DMATRIX)ci->u2.dwArg[0]);
180 case D3DOP_STATELIGHT: {
182 TRACE("STATELIGHT (%d)\n", count);
184 for (i = 0; i < count; i++) {
185 LPD3DSTATE ci = (LPD3DSTATE) instr;
187 TRACE("(%08x,%08lx)\n",ci->u1.dlstLightStateType, ci->u2.dwArg[0]);
189 if (!ci->u1.dlstLightStateType && (ci->u1.dlstLightStateType > D3DLIGHTSTATE_COLORVERTEX))
190 ERR("Unexpected Light State Type\n");
191 else if (ci->u1.dlstLightStateType == D3DLIGHTSTATE_MATERIAL /* 1 */) {
192 IDirect3DMaterialImpl *mat = (IDirect3DMaterialImpl *) ci->u2.dwArg[0];
197 ERR(" D3DLIGHTSTATE_MATERIAL called with NULL material !!!\n");
200 else if (ci->u1.dlstLightStateType == D3DLIGHTSTATE_COLORMODEL /* 3 */) {
201 switch (ci->u2.dwArg[0]) {
203 ERR("DDCOLOR_MONO should not happen!\n");
206 /* We are already in this mode */
209 ERR("Unknown color model!\n");
212 D3DRENDERSTATETYPE rs = 0;
213 switch (ci->u1.dlstLightStateType) {
215 case D3DLIGHTSTATE_AMBIENT: /* 2 */
216 rs = D3DRENDERSTATE_AMBIENT;
218 case D3DLIGHTSTATE_FOGMODE: /* 4 */
219 rs = D3DRENDERSTATE_FOGVERTEXMODE;
221 case D3DLIGHTSTATE_FOGSTART: /* 5 */
222 rs = D3DRENDERSTATE_FOGSTART;
224 case D3DLIGHTSTATE_FOGEND: /* 6 */
225 rs = D3DRENDERSTATE_FOGEND;
227 case D3DLIGHTSTATE_FOGDENSITY: /* 7 */
228 rs = D3DRENDERSTATE_FOGDENSITY;
230 case D3DLIGHTSTATE_COLORVERTEX: /* 8 */
231 rs = D3DRENDERSTATE_COLORVERTEX;
237 IDirect3DDevice7_SetRenderState(ICOM_INTERFACE(lpDevice, IDirect3DDevice7),
245 case D3DOP_STATERENDER: {
247 TRACE("STATERENDER (%d)\n", count);
249 for (i = 0; i < count; i++) {
250 LPD3DSTATE ci = (LPD3DSTATE) instr;
252 IDirect3DDevice7_SetRenderState(ICOM_INTERFACE(lpDevice, IDirect3DDevice7),
253 ci->u1.drstRenderStateType, ci->u2.dwArg[0]);
259 case D3DOP_PROCESSVERTICES: {
261 TRACE("PROCESSVERTICES (%d)\n", count);
263 for (i = 0; i < count; i++) {
264 LPD3DPROCESSVERTICES ci = (LPD3DPROCESSVERTICES) instr;
266 TRACE(" Start : %d Dest : %d Count : %ld\n",
267 ci->wStart, ci->wDest, ci->dwCount);
269 if (TRACE_ON(ddraw)) {
270 if (ci->dwFlags & D3DPROCESSVERTICES_COPY)
272 if (ci->dwFlags & D3DPROCESSVERTICES_NOCOLOR)
274 if (ci->dwFlags == D3DPROCESSVERTICES_OPMASK)
276 if (ci->dwFlags & D3DPROCESSVERTICES_TRANSFORM)
278 if (ci->dwFlags == D3DPROCESSVERTICES_TRANSFORMLIGHT)
279 TRACE("TRANSFORMLIGHT ");
280 if (ci->dwFlags & D3DPROCESSVERTICES_UPDATEEXTENTS)
281 TRACE("UPDATEEXTENTS ");
285 /* This is where doing Direct3D on top on OpenGL is quite difficult.
286 This method transforms a set of vertices using the CURRENT state
287 (lighting, projection, ...) but does not rasterize them.
288 They will only be put on screen later (with the POINT / LINE and
289 TRIANGLE op-codes). The problem is that you can have a triangle
290 with each point having been transformed using another state...
292 In this implementation, I will emulate only ONE thing : each
293 vertex can have its own "WORLD" transformation (this is used in the
294 TWIST.EXE demo of the 5.2 SDK). I suppose that all vertices of the
295 execute buffer use the same state.
297 If I find applications that change other states, I will try to do a
298 more 'fine-tuned' state emulation (but I may become quite tricky if
299 it changes a light position in the middle of a triangle).
301 In this case, a 'direct' approach (i.e. without using OpenGL, but
302 writing our own 3D rasterizer) would be easier. */
304 /* The current method (with the hypothesis that only the WORLD matrix
305 will change between two points) is like this :
306 - I transform 'manually' all the vertices with the current WORLD
307 matrix and store them in the vertex buffer
308 - during the rasterization phase, the WORLD matrix will be set to
309 the Identity matrix */
311 /* Enough for the moment */
312 if (ci->dwFlags == D3DPROCESSVERTICES_TRANSFORMLIGHT) {
314 D3DVERTEX *src = ((LPD3DVERTEX) ((char *)This->desc.lpData + vs)) + ci->wStart;
315 D3DTLVERTEX *dst = ((LPD3DTLVERTEX) (This->vertex_data)) + ci->wDest;
316 D3DMATRIX *mat2 = lpDevice->world_mat;
319 D3DVIEWPORT* Viewport = &lpViewport->viewports.vp1;
321 if (TRACE_ON(ddraw)) {
322 TRACE(" Projection Matrix : (%p)\n", lpDevice->proj_mat);
323 dump_D3DMATRIX(lpDevice->proj_mat);
324 TRACE(" View Matrix : (%p)\n", lpDevice->view_mat);
325 dump_D3DMATRIX(lpDevice->view_mat);
326 TRACE(" World Matrix : (%p)\n", &mat);
327 dump_D3DMATRIX(&mat);
330 multiply_matrix(&mat,lpDevice->view_mat,lpDevice->world_mat);
331 multiply_matrix(&mat,lpDevice->proj_mat,&mat);
333 for (nb = 0; nb < ci->dwCount; nb++) {
334 /* Normals transformation */
335 nx = (src->u4.nx * mat2->_11) + (src->u5.ny * mat2->_21) + (src->u6.nz * mat2->_31);
336 ny = (src->u4.nx * mat2->_12) + (src->u5.ny * mat2->_22) + (src->u6.nz * mat2->_32);
337 nz = (src->u4.nx * mat2->_13) + (src->u5.ny * mat2->_23) + (src->u6.nz * mat2->_33);
339 /* No lighting yet */
340 dst->u5.color = 0xFFFFFFFF; /* Opaque white */
341 dst->u6.specular = 0xFF000000; /* No specular and no fog factor */
343 dst->u7.tu = src->u7.tu;
344 dst->u8.tv = src->u8.tv;
346 /* Now, the matrix multiplication */
347 dst->u1.sx = (src->u1.x * mat._11) + (src->u2.y * mat._21) + (src->u3.z * mat._31) + (1.0 * mat._41);
348 dst->u2.sy = (src->u1.x * mat._12) + (src->u2.y * mat._22) + (src->u3.z * mat._32) + (1.0 * mat._42);
349 dst->u3.sz = (src->u1.x * mat._13) + (src->u2.y * mat._23) + (src->u3.z * mat._33) + (1.0 * mat._43);
350 dst->u4.rhw = (src->u1.x * mat._14) + (src->u2.y * mat._24) + (src->u3.z * mat._34) + (1.0 * mat._44);
352 dst->u1.sx = dst->u1.sx / dst->u4.rhw * Viewport->dwWidth / 2
353 + Viewport->dwX + Viewport->dwWidth / 2;
354 dst->u2.sy = dst->u2.sy / dst->u4.rhw * Viewport->dwHeight / 2
355 + Viewport->dwY + Viewport->dwHeight / 2;
356 dst->u3.sz /= dst->u4.rhw;
357 dst->u4.rhw = 1 / dst->u4.rhw;
363 } else if (ci->dwFlags == D3DPROCESSVERTICES_TRANSFORM) {
365 D3DLVERTEX *src = ((LPD3DLVERTEX) ((char *)This->desc.lpData + vs)) + ci->wStart;
366 D3DTLVERTEX *dst = ((LPD3DTLVERTEX) (This->vertex_data)) + ci->wDest;
368 D3DVIEWPORT* Viewport = &lpViewport->viewports.vp1;
370 if (TRACE_ON(ddraw)) {
371 TRACE(" Projection Matrix : (%p)\n", lpDevice->proj_mat);
372 dump_D3DMATRIX(lpDevice->proj_mat);
373 TRACE(" View Matrix : (%p)\n", lpDevice->view_mat);
374 dump_D3DMATRIX(lpDevice->view_mat);
375 TRACE(" World Matrix : (%p)\n", &mat);
376 dump_D3DMATRIX(&mat);
379 multiply_matrix(&mat,lpDevice->view_mat,lpDevice->world_mat);
380 multiply_matrix(&mat,lpDevice->proj_mat,&mat);
382 for (nb = 0; nb < ci->dwCount; nb++) {
383 dst->u5.color = src->u4.color;
384 dst->u6.specular = src->u5.specular;
385 dst->u7.tu = src->u6.tu;
386 dst->u8.tv = src->u7.tv;
388 /* Now, the matrix multiplication */
389 dst->u1.sx = (src->u1.x * mat._11) + (src->u2.y * mat._21) + (src->u3.z * mat._31) + (1.0 * mat._41);
390 dst->u2.sy = (src->u1.x * mat._12) + (src->u2.y * mat._22) + (src->u3.z * mat._32) + (1.0 * mat._42);
391 dst->u3.sz = (src->u1.x * mat._13) + (src->u2.y * mat._23) + (src->u3.z * mat._33) + (1.0 * mat._43);
392 dst->u4.rhw = (src->u1.x * mat._14) + (src->u2.y * mat._24) + (src->u3.z * mat._34) + (1.0 * mat._44);
394 dst->u1.sx /= dst->u4.rhw * Viewport->dvScaleX * Viewport->dwWidth / 2 + Viewport->dwX;
395 dst->u2.sy /= dst->u4.rhw * Viewport->dvScaleY * Viewport->dwHeight / 2 + Viewport->dwY;
396 dst->u3.sz /= dst->u4.rhw;
397 dst->u4.rhw = 1 / dst->u4.rhw;
402 } else if (ci->dwFlags == D3DPROCESSVERTICES_COPY) {
403 D3DTLVERTEX *src = ((LPD3DTLVERTEX) ((char *)This->desc.lpData + vs)) + ci->wStart;
404 D3DTLVERTEX *dst = ((LPD3DTLVERTEX) (This->vertex_data)) + ci->wDest;
406 memcpy(dst, src, ci->dwCount * sizeof(D3DTLVERTEX));
408 ERR("Unhandled vertex processing !\n");
415 case D3DOP_TEXTURELOAD: {
416 WARN("TEXTURELOAD-s (%d)\n", count);
418 instr += count * size;
422 TRACE("EXIT (%d)\n", count);
423 /* We did this instruction */
429 case D3DOP_BRANCHFORWARD: {
431 TRACE("BRANCHFORWARD (%d)\n", count);
433 for (i = 0; i < count; i++) {
434 LPD3DBRANCH ci = (LPD3DBRANCH) instr;
436 if ((This->data.dsStatus.dwStatus & ci->dwMask) == ci->dwValue) {
438 TRACE(" Branch to %ld\n", ci->dwOffset);
439 instr = (char*)current + ci->dwOffset;
444 TRACE(" Branch to %ld\n", ci->dwOffset);
445 instr = (char*)current + ci->dwOffset;
455 WARN("SPAN-s (%d)\n", count);
457 instr += count * size;
460 case D3DOP_SETSTATUS: {
462 TRACE("SETSTATUS (%d)\n", count);
464 for (i = 0; i < count; i++) {
465 LPD3DSTATUS ci = (LPD3DSTATUS) instr;
467 This->data.dsStatus = *ci;
474 ERR("Unhandled OpCode %d !!!\n",current->bOpcode);
475 /* Try to save ... */
476 instr += count * size;
486 Main_IDirect3DExecuteBufferImpl_1_QueryInterface(LPDIRECT3DEXECUTEBUFFER iface,
490 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
491 TRACE("(%p/%p)->(%s,%p)\n", This, iface, debugstr_guid(riid), obp);
495 if ( IsEqualGUID( &IID_IUnknown, riid ) ) {
496 IDirect3DExecuteBuffer_AddRef(ICOM_INTERFACE(This, IDirect3DExecuteBuffer));
498 TRACE(" Creating IUnknown interface at %p.\n", *obp);
501 if ( IsEqualGUID( &IID_IDirect3DMaterial, riid ) ) {
502 IDirect3DExecuteBuffer_AddRef(ICOM_INTERFACE(This, IDirect3DExecuteBuffer));
503 *obp = ICOM_INTERFACE(This, IDirect3DExecuteBuffer);
504 TRACE(" Creating IDirect3DExecuteBuffer interface %p\n", *obp);
507 FIXME("(%p): interface for IID %s NOT found!\n", This, debugstr_guid(riid));
508 return OLE_E_ENUM_NOMORE;
512 Main_IDirect3DExecuteBufferImpl_1_AddRef(LPDIRECT3DEXECUTEBUFFER iface)
514 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
515 FIXME("(%p/%p)->()incrementing from %lu.\n", This, iface, This->ref );
516 return ++(This->ref);
520 Main_IDirect3DExecuteBufferImpl_1_Release(LPDIRECT3DEXECUTEBUFFER iface)
522 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
523 TRACE("(%p/%p)->()decrementing from %lu.\n", This, iface, This->ref);
524 if (!--(This->ref)) {
525 if ((This->desc.lpData != NULL) && This->need_free)
526 HeapFree(GetProcessHeap(),0,This->desc.lpData);
527 if (This->vertex_data != NULL)
528 HeapFree(GetProcessHeap(),0,This->vertex_data);
529 if (This->indices != NULL)
530 HeapFree(GetProcessHeap(),0,This->indices);
531 HeapFree(GetProcessHeap(),0,This);
539 Main_IDirect3DExecuteBufferImpl_1_Initialize(LPDIRECT3DEXECUTEBUFFER iface,
540 LPDIRECT3DDEVICE lpDirect3DDevice,
541 LPD3DEXECUTEBUFFERDESC lpDesc)
543 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
544 TRACE("(%p/%p)->(%p,%p) no-op....\n", This, iface, lpDirect3DDevice, lpDesc);
549 Main_IDirect3DExecuteBufferImpl_1_Lock(LPDIRECT3DEXECUTEBUFFER iface,
550 LPD3DEXECUTEBUFFERDESC lpDesc)
552 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
554 TRACE("(%p/%p)->(%p)\n", This, iface, lpDesc);
556 dwSize = lpDesc->dwSize;
557 memset(lpDesc, 0, dwSize);
558 memcpy(lpDesc, &This->desc, dwSize);
560 if (TRACE_ON(ddraw)) {
561 TRACE(" Returning description : \n");
562 _dump_D3DEXECUTEBUFFERDESC(lpDesc);
568 Main_IDirect3DExecuteBufferImpl_1_Unlock(LPDIRECT3DEXECUTEBUFFER iface)
570 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
571 TRACE("(%p/%p)->() no-op...\n", This, iface);
576 Main_IDirect3DExecuteBufferImpl_1_SetExecuteData(LPDIRECT3DEXECUTEBUFFER iface,
577 LPD3DEXECUTEDATA lpData)
579 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
581 TRACE("(%p/%p)->(%p)\n", This, iface, lpData);
583 memcpy(&This->data, lpData, lpData->dwSize);
585 /* Get the number of vertices in the execute buffer */
586 nbvert = This->data.dwVertexCount;
588 /* Prepares the transformed vertex buffer */
589 if (This->vertex_data != NULL)
590 HeapFree(GetProcessHeap(), 0, This->vertex_data);
591 This->vertex_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nbvert * sizeof(D3DTLVERTEX));
593 if (TRACE_ON(ddraw)) {
594 _dump_executedata(lpData);
601 Main_IDirect3DExecuteBufferImpl_1_GetExecuteData(LPDIRECT3DEXECUTEBUFFER iface,
602 LPD3DEXECUTEDATA lpData)
604 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
606 TRACE("(%p/%p)->(%p): stub!\n", This, iface, lpData);
608 dwSize = lpData->dwSize;
609 memset(lpData, 0, dwSize);
610 memcpy(lpData, &This->data, dwSize);
612 if (TRACE_ON(ddraw)) {
613 TRACE("Returning data : \n");
614 _dump_executedata(lpData);
621 Main_IDirect3DExecuteBufferImpl_1_Validate(LPDIRECT3DEXECUTEBUFFER iface,
623 LPD3DVALIDATECALLBACK lpFunc,
627 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
628 FIXME("(%p/%p)->(%p,%p,%p,%08lx): stub!\n", This, iface, lpdwOffset, lpFunc, lpUserArg, dwReserved);
633 Main_IDirect3DExecuteBufferImpl_1_Optimize(LPDIRECT3DEXECUTEBUFFER iface,
636 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
637 TRACE("(%p/%p)->(%08lx) no-op...\n", This, iface, dwDummy);
641 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
642 # define XCAST(fun) (typeof(VTABLE_IDirect3DExecuteBuffer.fun))
644 # define XCAST(fun) (void*)
647 ICOM_VTABLE(IDirect3DExecuteBuffer) VTABLE_IDirect3DExecuteBuffer =
649 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
650 XCAST(QueryInterface) Main_IDirect3DExecuteBufferImpl_1_QueryInterface,
651 XCAST(AddRef) Main_IDirect3DExecuteBufferImpl_1_AddRef,
652 XCAST(Release) Main_IDirect3DExecuteBufferImpl_1_Release,
653 XCAST(Initialize) Main_IDirect3DExecuteBufferImpl_1_Initialize,
654 XCAST(Lock) Main_IDirect3DExecuteBufferImpl_1_Lock,
655 XCAST(Unlock) Main_IDirect3DExecuteBufferImpl_1_Unlock,
656 XCAST(SetExecuteData) Main_IDirect3DExecuteBufferImpl_1_SetExecuteData,
657 XCAST(GetExecuteData) Main_IDirect3DExecuteBufferImpl_1_GetExecuteData,
658 XCAST(Validate) Main_IDirect3DExecuteBufferImpl_1_Validate,
659 XCAST(Optimize) Main_IDirect3DExecuteBufferImpl_1_Optimize,
662 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
667 HRESULT d3dexecutebuffer_create(IDirect3DExecuteBufferImpl **obj, IDirectDrawImpl *d3d, IDirect3DDeviceImpl *d3ddev, LPD3DEXECUTEBUFFERDESC lpDesc)
669 IDirect3DExecuteBufferImpl* object;
671 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DExecuteBufferImpl));
673 ICOM_INIT_INTERFACE(object, IDirect3DExecuteBuffer, VTABLE_IDirect3DExecuteBuffer);
677 object->d3ddev = d3ddev;
679 /* Initializes memory */
680 memcpy(&object->desc, lpDesc, lpDesc->dwSize);
682 /* No buffer given */
683 if ((object->desc.dwFlags & D3DDEB_LPDATA) == 0)
684 object->desc.lpData = NULL;
686 /* No buffer size given */
687 if ((lpDesc->dwFlags & D3DDEB_BUFSIZE) == 0)
688 object->desc.dwBufferSize = 0;
690 /* Create buffer if asked */
691 if ((object->desc.lpData == NULL) && (object->desc.dwBufferSize > 0)) {
692 object->need_free = TRUE;
693 object->desc.lpData = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,object->desc.dwBufferSize);
695 object->need_free = FALSE;
698 /* No vertices for the moment */
699 object->vertex_data = NULL;
701 object->desc.dwFlags |= D3DDEB_LPDATA;
703 object->execute = execute;
705 object->indices = NULL;
706 object->nb_indices = 0;
710 TRACE(" creating implementation at %p.\n", *obj);