mscoree: Add missing interfaces.
[wine/multimedia.git] / dlls / ddraw / executebuffer.c
blobfe24fe3e0d3a564a58ea398b56c208028933fe41
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
23 #include "config.h"
24 #include "wine/port.h"
26 #include <assert.h>
27 #include <stdarg.h>
28 #include <string.h>
29 #include <stdlib.h>
31 #define COBJMACROS
32 #define NONAMELESSUNION
34 #include "windef.h"
35 #include "winbase.h"
36 #include "winerror.h"
37 #include "wingdi.h"
38 #include "wine/exception.h"
40 #include "ddraw.h"
41 #include "d3d.h"
43 #include "ddraw_private.h"
44 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(d3d7);
48 /*****************************************************************************
49 * _dump_executedata
50 * _dump_D3DEXECUTEBUFFERDESC
52 * Debug functions which write the executebuffer data to the console
54 *****************************************************************************/
56 static void _dump_executedata(const D3DEXECUTEDATA *lpData) {
57 TRACE("dwSize : %d\n", lpData->dwSize);
58 TRACE("Vertex Offset : %d Count : %d\n", lpData->dwVertexOffset, lpData->dwVertexCount);
59 TRACE("Instruction Offset : %d Length : %d\n", lpData->dwInstructionOffset, lpData->dwInstructionLength);
60 TRACE("HVertex Offset : %d\n", lpData->dwHVertexOffset);
63 static void _dump_D3DEXECUTEBUFFERDESC(const D3DEXECUTEBUFFERDESC *lpDesc) {
64 TRACE("dwSize : %d\n", lpDesc->dwSize);
65 TRACE("dwFlags : %x\n", lpDesc->dwFlags);
66 TRACE("dwCaps : %x\n", lpDesc->dwCaps);
67 TRACE("dwBufferSize : %d\n", lpDesc->dwBufferSize);
68 TRACE("lpData : %p\n", lpDesc->lpData);
71 /*****************************************************************************
72 * IDirect3DExecuteBufferImpl_Execute
74 * The main functionality of the execute buffer
75 * It transforms the vertices if necessary, and calls IDirect3DDevice7
76 * for drawing the vertices. It is called from
77 * IDirect3DDevice::Execute
79 * TODO: Perhaps some comments about the various opcodes wouldn't hurt
81 * Don't declare this static, as it's called from device.c,
82 * IDirect3DDevice::Execute
84 * Params:
85 * Device: 3D Device associated to use for drawing
86 * Viewport: Viewport for this operation
88 *****************************************************************************/
89 void
90 IDirect3DExecuteBufferImpl_Execute(IDirect3DExecuteBufferImpl *This,
91 IDirect3DDeviceImpl *lpDevice,
92 IDirect3DViewportImpl *lpViewport)
94 /* DWORD bs = This->desc.dwBufferSize; */
95 DWORD vs = This->data.dwVertexOffset;
96 /* DWORD vc = This->data.dwVertexCount; */
97 DWORD is = This->data.dwInstructionOffset;
98 /* DWORD il = This->data.dwInstructionLength; */
100 char *instr = (char *)This->desc.lpData + is;
102 /* Should check if the viewport was added or not to the device */
104 /* Activate the viewport */
105 lpViewport->active_device = lpDevice;
106 lpViewport->activate(lpViewport);
108 TRACE("ExecuteData :\n");
109 if (TRACE_ON(d3d7))
110 _dump_executedata(&(This->data));
112 while (1) {
113 LPD3DINSTRUCTION current = (LPD3DINSTRUCTION) instr;
114 BYTE size;
115 WORD count;
117 count = current->wCount;
118 size = current->bSize;
119 instr += sizeof(D3DINSTRUCTION);
121 switch (current->bOpcode) {
122 case D3DOP_POINT: {
123 WARN("POINT-s (%d)\n", count);
124 instr += count * size;
125 } break;
127 case D3DOP_LINE: {
128 WARN("LINE-s (%d)\n", count);
129 instr += count * size;
130 } break;
132 case D3DOP_TRIANGLE: {
133 int i;
134 D3DTLVERTEX *tl_vx = (D3DTLVERTEX *) This->vertex_data;
135 TRACE("TRIANGLE (%d)\n", count);
137 if (count*3>This->nb_indices) {
138 This->nb_indices = count * 3;
139 HeapFree(GetProcessHeap(),0,This->indices);
140 This->indices = HeapAlloc(GetProcessHeap(),0,sizeof(WORD)*This->nb_indices);
143 for (i = 0; i < count; i++) {
144 LPD3DTRIANGLE ci = (LPD3DTRIANGLE) instr;
145 TRACE_(d3d7)(" v1: %d v2: %d v3: %d\n",ci->u1.v1, ci->u2.v2, ci->u3.v3);
146 TRACE_(d3d7)(" Flags : ");
147 if (TRACE_ON(d3d7)) {
148 /* Wireframe */
149 if (ci->wFlags & D3DTRIFLAG_EDGEENABLE1)
150 TRACE_(d3d7)("EDGEENABLE1 ");
151 if (ci->wFlags & D3DTRIFLAG_EDGEENABLE2)
152 TRACE_(d3d7)("EDGEENABLE2 ");
153 if (ci->wFlags & D3DTRIFLAG_EDGEENABLE1)
154 TRACE_(d3d7)("EDGEENABLE3 ");
155 /* Strips / Fans */
156 if (ci->wFlags == D3DTRIFLAG_EVEN)
157 TRACE_(d3d7)("EVEN ");
158 if (ci->wFlags == D3DTRIFLAG_ODD)
159 TRACE_(d3d7)("ODD ");
160 if (ci->wFlags == D3DTRIFLAG_START)
161 TRACE_(d3d7)("START ");
162 if ((ci->wFlags > 0) && (ci->wFlags < 30))
163 TRACE_(d3d7)("STARTFLAT(%d) ", ci->wFlags);
164 TRACE_(d3d7)("\n");
166 This->indices[(i * 3) ] = ci->u1.v1;
167 This->indices[(i * 3) + 1] = ci->u2.v2;
168 This->indices[(i * 3) + 2] = ci->u3.v3;
169 instr += size;
171 /* IDirect3DDevices have color keying always enabled -
172 * enable it before drawing. This overwrites any ALPHA*
173 * render state
175 IWineD3DDevice_SetRenderState(lpDevice->wineD3DDevice,
176 WINED3DRS_COLORKEYENABLE,
178 IDirect3DDevice7_DrawIndexedPrimitive(ICOM_INTERFACE(lpDevice,IDirect3DDevice7),
179 D3DPT_TRIANGLELIST,D3DFVF_TLVERTEX,tl_vx,0,This->indices,count*3,0);
180 } break;
182 case D3DOP_MATRIXLOAD:
183 WARN("MATRIXLOAD-s (%d)\n", count);
184 instr += count * size;
185 break;
187 case D3DOP_MATRIXMULTIPLY: {
188 int i;
189 TRACE("MATRIXMULTIPLY (%d)\n", count);
191 for (i = 0; i < count; i++) {
192 LPD3DMATRIXMULTIPLY ci = (LPD3DMATRIXMULTIPLY) instr;
193 LPD3DMATRIX a, b, c;
195 if(!ci->hDestMatrix || ci->hDestMatrix > lpDevice->numHandles ||
196 !ci->hSrcMatrix1 || ci->hSrcMatrix1 > lpDevice->numHandles ||
197 !ci->hSrcMatrix2 || ci->hSrcMatrix2 > lpDevice->numHandles) {
198 ERR("Handles out of bounds\n");
199 } else if (lpDevice->Handles[ci->hDestMatrix - 1].type != DDrawHandle_Matrix ||
200 lpDevice->Handles[ci->hSrcMatrix1 - 1].type != DDrawHandle_Matrix ||
201 lpDevice->Handles[ci->hSrcMatrix2 - 1].type != DDrawHandle_Matrix) {
202 ERR("Handle types invalid\n");
203 } else {
204 a = (LPD3DMATRIX) lpDevice->Handles[ci->hDestMatrix - 1].ptr;
205 b = (LPD3DMATRIX) lpDevice->Handles[ci->hSrcMatrix1 - 1].ptr;
206 c = (LPD3DMATRIX) lpDevice->Handles[ci->hSrcMatrix2 - 1].ptr;
207 TRACE(" Dest : %p Src1 : %p Src2 : %p\n",
208 a, b, c);
209 multiply_matrix(a,c,b);
212 instr += size;
214 } break;
216 case D3DOP_STATETRANSFORM: {
217 int i;
218 TRACE("STATETRANSFORM (%d)\n", count);
220 for (i = 0; i < count; i++) {
221 LPD3DSTATE ci = (LPD3DSTATE) instr;
223 if(!ci->u2.dwArg[0]) {
224 ERR("Setting a NULL matrix handle, what should I do?\n");
225 } else if(ci->u2.dwArg[0] > lpDevice->numHandles) {
226 ERR("Handle %d is out of bounds\n", ci->u2.dwArg[0]);
227 } else if(lpDevice->Handles[ci->u2.dwArg[0] - 1].type != DDrawHandle_Matrix) {
228 ERR("Handle %d is not a matrix handle\n", ci->u2.dwArg[0]);
229 } else {
230 if(ci->u1.drstRenderStateType == D3DTRANSFORMSTATE_WORLD)
231 lpDevice->world = ci->u2.dwArg[0];
232 if(ci->u1.drstRenderStateType == D3DTRANSFORMSTATE_VIEW)
233 lpDevice->view = ci->u2.dwArg[0];
234 if(ci->u1.drstRenderStateType == D3DTRANSFORMSTATE_PROJECTION)
235 lpDevice->proj = ci->u2.dwArg[0];
236 IDirect3DDevice7_SetTransform(ICOM_INTERFACE(lpDevice, IDirect3DDevice7),
237 ci->u1.drstRenderStateType, (LPD3DMATRIX) lpDevice->Handles[ci->u2.dwArg[0] - 1].ptr);
239 instr += size;
241 } break;
243 case D3DOP_STATELIGHT: {
244 int i;
245 TRACE("STATELIGHT (%d)\n", count);
247 for (i = 0; i < count; i++) {
248 LPD3DSTATE ci = (LPD3DSTATE) instr;
250 TRACE("(%08x,%08x)\n",ci->u1.dlstLightStateType, ci->u2.dwArg[0]);
252 if (!ci->u1.dlstLightStateType && (ci->u1.dlstLightStateType > D3DLIGHTSTATE_COLORVERTEX))
253 ERR("Unexpected Light State Type\n");
254 else if (ci->u1.dlstLightStateType == D3DLIGHTSTATE_MATERIAL /* 1 */) {
255 DWORD matHandle = ci->u2.dwArg[0];
257 if(!matHandle) {
258 FIXME(" D3DLIGHTSTATE_MATERIAL called with NULL material !!!\n");
259 } else if(matHandle >= lpDevice->numHandles) {
260 WARN("Material handle %d is invalid\n", matHandle);
261 } else if(lpDevice->Handles[matHandle - 1].type != DDrawHandle_Material) {
262 WARN("Handle %d is not a material handle\n", matHandle);
263 } else {
264 IDirect3DMaterialImpl *mat = (IDirect3DMaterialImpl *) lpDevice->Handles[matHandle - 1].ptr;
265 mat->activate(mat);
268 else if (ci->u1.dlstLightStateType == D3DLIGHTSTATE_COLORMODEL /* 3 */) {
269 switch (ci->u2.dwArg[0]) {
270 case D3DCOLOR_MONO:
271 ERR("DDCOLOR_MONO should not happen!\n");
272 break;
273 case D3DCOLOR_RGB:
274 /* We are already in this mode */
275 break;
276 default:
277 ERR("Unknown color model!\n");
279 } else {
280 D3DRENDERSTATETYPE rs = 0;
281 switch (ci->u1.dlstLightStateType) {
283 case D3DLIGHTSTATE_AMBIENT: /* 2 */
284 rs = D3DRENDERSTATE_AMBIENT;
285 break;
286 case D3DLIGHTSTATE_FOGMODE: /* 4 */
287 rs = D3DRENDERSTATE_FOGVERTEXMODE;
288 break;
289 case D3DLIGHTSTATE_FOGSTART: /* 5 */
290 rs = D3DRENDERSTATE_FOGSTART;
291 break;
292 case D3DLIGHTSTATE_FOGEND: /* 6 */
293 rs = D3DRENDERSTATE_FOGEND;
294 break;
295 case D3DLIGHTSTATE_FOGDENSITY: /* 7 */
296 rs = D3DRENDERSTATE_FOGDENSITY;
297 break;
298 case D3DLIGHTSTATE_COLORVERTEX: /* 8 */
299 rs = D3DRENDERSTATE_COLORVERTEX;
300 break;
301 default:
302 break;
305 IDirect3DDevice7_SetRenderState(ICOM_INTERFACE(lpDevice, IDirect3DDevice7),
306 rs,ci->u2.dwArg[0]);
309 instr += size;
311 } break;
313 case D3DOP_STATERENDER: {
314 int i;
315 TRACE("STATERENDER (%d)\n", count);
317 for (i = 0; i < count; i++) {
318 LPD3DSTATE ci = (LPD3DSTATE) instr;
320 IDirect3DDevice2_SetRenderState(ICOM_INTERFACE(lpDevice, IDirect3DDevice2),
321 ci->u1.drstRenderStateType, ci->u2.dwArg[0]);
323 instr += size;
325 } break;
327 case D3DOP_PROCESSVERTICES:
329 /* TODO: Share code with IDirect3DVertexBuffer::ProcessVertices and / or
330 * IWineD3DDevice::ProcessVertices
332 int i;
333 D3DMATRIX view_mat, world_mat, proj_mat;
334 TRACE("PROCESSVERTICES (%d)\n", count);
336 /* Get the transform and world matrix */
337 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
339 IWineD3DDevice_GetTransform(lpDevice->wineD3DDevice,
340 D3DTRANSFORMSTATE_VIEW,
341 (WINED3DMATRIX*) &view_mat);
343 IWineD3DDevice_GetTransform(lpDevice->wineD3DDevice,
344 D3DTRANSFORMSTATE_PROJECTION,
345 (WINED3DMATRIX*) &proj_mat);
347 IWineD3DDevice_GetTransform(lpDevice->wineD3DDevice,
348 WINED3DTS_WORLDMATRIX(0),
349 (WINED3DMATRIX*) &world_mat);
351 for (i = 0; i < count; i++) {
352 LPD3DPROCESSVERTICES ci = (LPD3DPROCESSVERTICES) instr;
354 TRACE(" Start : %d Dest : %d Count : %d\n",
355 ci->wStart, ci->wDest, ci->dwCount);
356 TRACE(" Flags : ");
357 if (TRACE_ON(d3d7)) {
358 if (ci->dwFlags & D3DPROCESSVERTICES_COPY)
359 TRACE("COPY ");
360 if (ci->dwFlags & D3DPROCESSVERTICES_NOCOLOR)
361 TRACE("NOCOLOR ");
362 if (ci->dwFlags == D3DPROCESSVERTICES_OPMASK)
363 TRACE("OPMASK ");
364 if (ci->dwFlags & D3DPROCESSVERTICES_TRANSFORM)
365 TRACE("TRANSFORM ");
366 if (ci->dwFlags == D3DPROCESSVERTICES_TRANSFORMLIGHT)
367 TRACE("TRANSFORMLIGHT ");
368 if (ci->dwFlags & D3DPROCESSVERTICES_UPDATEEXTENTS)
369 TRACE("UPDATEEXTENTS ");
370 TRACE("\n");
373 /* This is where doing Direct3D on top on OpenGL is quite difficult.
374 This method transforms a set of vertices using the CURRENT state
375 (lighting, projection, ...) but does not rasterize them.
376 They will only be put on screen later (with the POINT / LINE and
377 TRIANGLE op-codes). The problem is that you can have a triangle
378 with each point having been transformed using another state...
380 In this implementation, I will emulate only ONE thing : each
381 vertex can have its own "WORLD" transformation (this is used in the
382 TWIST.EXE demo of the 5.2 SDK). I suppose that all vertices of the
383 execute buffer use the same state.
385 If I find applications that change other states, I will try to do a
386 more 'fine-tuned' state emulation (but I may become quite tricky if
387 it changes a light position in the middle of a triangle).
389 In this case, a 'direct' approach (i.e. without using OpenGL, but
390 writing our own 3D rasterizer) would be easier. */
392 /* The current method (with the hypothesis that only the WORLD matrix
393 will change between two points) is like this :
394 - I transform 'manually' all the vertices with the current WORLD
395 matrix and store them in the vertex buffer
396 - during the rasterization phase, the WORLD matrix will be set to
397 the Identity matrix */
399 /* Enough for the moment */
400 if (ci->dwFlags == D3DPROCESSVERTICES_TRANSFORMLIGHT) {
401 unsigned int nb;
402 D3DVERTEX *src = ((LPD3DVERTEX) ((char *)This->desc.lpData + vs)) + ci->wStart;
403 D3DTLVERTEX *dst = ((LPD3DTLVERTEX) (This->vertex_data)) + ci->wDest;
404 D3DMATRIX *mat2 = &world_mat;
405 D3DMATRIX mat;
406 D3DVALUE nx,ny,nz;
407 D3DVIEWPORT* Viewport = &lpViewport->viewports.vp1;
409 if (TRACE_ON(d3d7)) {
410 TRACE(" Projection Matrix : (%p)\n", &proj_mat);
411 dump_D3DMATRIX(&proj_mat);
412 TRACE(" View Matrix : (%p)\n", &view_mat);
413 dump_D3DMATRIX(&view_mat);
414 TRACE(" World Matrix : (%p)\n", &world_mat);
415 dump_D3DMATRIX(&world_mat);
418 multiply_matrix(&mat,&view_mat,&world_mat);
419 multiply_matrix(&mat,&proj_mat,&mat);
421 for (nb = 0; nb < ci->dwCount; nb++) {
422 /* Normals transformation */
423 nx = (src->u4.nx * mat2->_11) + (src->u5.ny * mat2->_21) + (src->u6.nz * mat2->_31);
424 ny = (src->u4.nx * mat2->_12) + (src->u5.ny * mat2->_22) + (src->u6.nz * mat2->_32);
425 nz = (src->u4.nx * mat2->_13) + (src->u5.ny * mat2->_23) + (src->u6.nz * mat2->_33);
427 /* No lighting yet */
428 dst->u5.color = 0xFFFFFFFF; /* Opaque white */
429 dst->u6.specular = 0xFF000000; /* No specular and no fog factor */
431 dst->u7.tu = src->u7.tu;
432 dst->u8.tv = src->u8.tv;
434 /* Now, the matrix multiplication */
435 dst->u1.sx = (src->u1.x * mat._11) + (src->u2.y * mat._21) + (src->u3.z * mat._31) + (1.0 * mat._41);
436 dst->u2.sy = (src->u1.x * mat._12) + (src->u2.y * mat._22) + (src->u3.z * mat._32) + (1.0 * mat._42);
437 dst->u3.sz = (src->u1.x * mat._13) + (src->u2.y * mat._23) + (src->u3.z * mat._33) + (1.0 * mat._43);
438 dst->u4.rhw = (src->u1.x * mat._14) + (src->u2.y * mat._24) + (src->u3.z * mat._34) + (1.0 * mat._44);
440 dst->u1.sx = dst->u1.sx / dst->u4.rhw * Viewport->dvScaleX
441 + Viewport->dwX + Viewport->dwWidth / 2;
442 dst->u2.sy = (-dst->u2.sy) / dst->u4.rhw * Viewport->dvScaleY
443 + Viewport->dwY + Viewport->dwHeight / 2;
444 dst->u3.sz /= dst->u4.rhw;
445 dst->u4.rhw = 1 / dst->u4.rhw;
447 src++;
448 dst++;
451 } else if (ci->dwFlags == D3DPROCESSVERTICES_TRANSFORM) {
452 unsigned int nb;
453 D3DLVERTEX *src = ((LPD3DLVERTEX) ((char *)This->desc.lpData + vs)) + ci->wStart;
454 D3DTLVERTEX *dst = ((LPD3DTLVERTEX) (This->vertex_data)) + ci->wDest;
455 D3DMATRIX mat;
456 D3DVIEWPORT* Viewport = &lpViewport->viewports.vp1;
458 if (TRACE_ON(d3d7)) {
459 TRACE(" Projection Matrix : (%p)\n", &proj_mat);
460 dump_D3DMATRIX(&proj_mat);
461 TRACE(" View Matrix : (%p)\n",&view_mat);
462 dump_D3DMATRIX(&view_mat);
463 TRACE(" World Matrix : (%p)\n", &world_mat);
464 dump_D3DMATRIX(&world_mat);
467 multiply_matrix(&mat,&view_mat,&world_mat);
468 multiply_matrix(&mat,&proj_mat,&mat);
470 for (nb = 0; nb < ci->dwCount; nb++) {
471 dst->u5.color = src->u4.color;
472 dst->u6.specular = src->u5.specular;
473 dst->u7.tu = src->u6.tu;
474 dst->u8.tv = src->u7.tv;
476 /* Now, the matrix multiplication */
477 dst->u1.sx = (src->u1.x * mat._11) + (src->u2.y * mat._21) + (src->u3.z * mat._31) + (1.0 * mat._41);
478 dst->u2.sy = (src->u1.x * mat._12) + (src->u2.y * mat._22) + (src->u3.z * mat._32) + (1.0 * mat._42);
479 dst->u3.sz = (src->u1.x * mat._13) + (src->u2.y * mat._23) + (src->u3.z * mat._33) + (1.0 * mat._43);
480 dst->u4.rhw = (src->u1.x * mat._14) + (src->u2.y * mat._24) + (src->u3.z * mat._34) + (1.0 * mat._44);
482 dst->u1.sx = dst->u1.sx / dst->u4.rhw * Viewport->dvScaleX
483 + Viewport->dwX + Viewport->dwWidth / 2;
484 dst->u2.sy = (-dst->u2.sy) / dst->u4.rhw * Viewport->dvScaleY
485 + Viewport->dwY + Viewport->dwHeight / 2;
487 dst->u3.sz /= dst->u4.rhw;
488 dst->u4.rhw = 1 / dst->u4.rhw;
490 src++;
491 dst++;
493 } else if (ci->dwFlags == D3DPROCESSVERTICES_COPY) {
494 D3DTLVERTEX *src = ((LPD3DTLVERTEX) ((char *)This->desc.lpData + vs)) + ci->wStart;
495 D3DTLVERTEX *dst = ((LPD3DTLVERTEX) (This->vertex_data)) + ci->wDest;
497 memcpy(dst, src, ci->dwCount * sizeof(D3DTLVERTEX));
498 } else {
499 ERR("Unhandled vertex processing !\n");
502 instr += size;
504 } break;
506 case D3DOP_TEXTURELOAD: {
507 WARN("TEXTURELOAD-s (%d)\n", count);
509 instr += count * size;
510 } break;
512 case D3DOP_EXIT: {
513 TRACE("EXIT (%d)\n", count);
514 /* We did this instruction */
515 instr += size;
516 /* Exit this loop */
517 goto end_of_buffer;
518 } break;
520 case D3DOP_BRANCHFORWARD: {
521 int i;
522 TRACE("BRANCHFORWARD (%d)\n", count);
524 for (i = 0; i < count; i++) {
525 LPD3DBRANCH ci = (LPD3DBRANCH) instr;
527 if ((This->data.dsStatus.dwStatus & ci->dwMask) == ci->dwValue) {
528 if (!ci->bNegate) {
529 TRACE(" Branch to %d\n", ci->dwOffset);
530 if (ci->dwOffset) {
531 instr = (char*)current + ci->dwOffset;
532 break;
535 } else {
536 if (ci->bNegate) {
537 TRACE(" Branch to %d\n", ci->dwOffset);
538 if (ci->dwOffset) {
539 instr = (char*)current + ci->dwOffset;
540 break;
545 instr += size;
547 } break;
549 case D3DOP_SPAN: {
550 WARN("SPAN-s (%d)\n", count);
552 instr += count * size;
553 } break;
555 case D3DOP_SETSTATUS: {
556 int i;
557 TRACE("SETSTATUS (%d)\n", count);
559 for (i = 0; i < count; i++) {
560 LPD3DSTATUS ci = (LPD3DSTATUS) instr;
562 This->data.dsStatus = *ci;
564 instr += size;
566 } break;
568 default:
569 ERR("Unhandled OpCode %d !!!\n",current->bOpcode);
570 /* Try to save ... */
571 instr += count * size;
572 break;
576 end_of_buffer:
580 /*****************************************************************************
581 * IDirect3DExecuteBuffer::QueryInterface
583 * Well, a usual QueryInterface function. Don't know fur sure which
584 * interfaces it can Query.
586 * Params:
587 * riid: The interface ID queried for
588 * obj: Address to return the interface pointer at
590 * Returns:
591 * D3D_OK in case of a success (S_OK? Think it's the same)
592 * OLE_E_ENUM_NOMORE if the interface wasn't found.
593 * (E_NOINTERFACE?? Don't know what I really need)
595 *****************************************************************************/
596 static HRESULT WINAPI
597 IDirect3DExecuteBufferImpl_QueryInterface(IDirect3DExecuteBuffer *iface,
598 REFIID riid,
599 void **obj)
601 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
602 TRACE("(%p/%p)->(%s,%p)\n", This, iface, debugstr_guid(riid), obj);
604 *obj = NULL;
606 if ( IsEqualGUID( &IID_IUnknown, riid ) ) {
607 IDirect3DExecuteBuffer_AddRef(ICOM_INTERFACE(This, IDirect3DExecuteBuffer));
608 *obj = iface;
609 TRACE(" Creating IUnknown interface at %p.\n", *obj);
610 return S_OK;
612 if ( IsEqualGUID( &IID_IDirect3DMaterial, riid ) ) {
613 IDirect3DExecuteBuffer_AddRef(ICOM_INTERFACE(This, IDirect3DExecuteBuffer));
614 *obj = ICOM_INTERFACE(This, IDirect3DExecuteBuffer);
615 TRACE(" Creating IDirect3DExecuteBuffer interface %p\n", *obj);
616 return S_OK;
618 FIXME("(%p): interface for IID %s NOT found!\n", This, debugstr_guid(riid));
619 return E_NOINTERFACE;
623 /*****************************************************************************
624 * IDirect3DExecuteBuffer::AddRef
626 * A normal AddRef method, nothing special
628 * Returns:
629 * The new refcount
631 *****************************************************************************/
632 static ULONG WINAPI
633 IDirect3DExecuteBufferImpl_AddRef(IDirect3DExecuteBuffer *iface)
635 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
636 ULONG ref = InterlockedIncrement(&This->ref);
638 FIXME("(%p)->()incrementing from %u.\n", This, ref - 1);
640 return ref;
643 /*****************************************************************************
644 * IDirect3DExecuteBuffer::Release
646 * A normal Release method, nothing special
648 * Returns:
649 * The new refcount
651 *****************************************************************************/
652 static ULONG WINAPI
653 IDirect3DExecuteBufferImpl_Release(IDirect3DExecuteBuffer *iface)
655 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
656 ULONG ref = InterlockedDecrement(&This->ref);
658 TRACE("(%p)->()decrementing from %u.\n", This, ref + 1);
660 if (!ref) {
661 if (This->need_free)
662 HeapFree(GetProcessHeap(),0,This->desc.lpData);
663 HeapFree(GetProcessHeap(),0,This->vertex_data);
664 HeapFree(GetProcessHeap(),0,This->indices);
665 HeapFree(GetProcessHeap(),0,This);
666 return 0;
669 return ref;
672 /*****************************************************************************
673 * IDirect3DExecuteBuffer::Initialize
675 * Initializes the Execute Buffer. This method exists for COM compliance
676 * Nothing to do here.
678 * Returns:
679 * D3D_OK
681 *****************************************************************************/
682 static HRESULT WINAPI
683 IDirect3DExecuteBufferImpl_Initialize(IDirect3DExecuteBuffer *iface,
684 IDirect3DDevice *lpDirect3DDevice,
685 D3DEXECUTEBUFFERDESC *lpDesc)
687 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
688 TRACE("(%p)->(%p,%p) no-op....\n", This, lpDirect3DDevice, lpDesc);
689 return D3D_OK;
692 /*****************************************************************************
693 * IDirect3DExecuteBuffer::Lock
695 * Locks the buffer, so the app can write into it.
697 * Params:
698 * Desc: Pointer to return the buffer description. This Description contains
699 * a pointer to the buffer data.
701 * Returns:
702 * This implementation always returns D3D_OK
704 *****************************************************************************/
705 static HRESULT WINAPI
706 IDirect3DExecuteBufferImpl_Lock(IDirect3DExecuteBuffer *iface,
707 D3DEXECUTEBUFFERDESC *lpDesc)
709 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
710 DWORD dwSize;
711 TRACE("(%p)->(%p)\n", This, lpDesc);
713 dwSize = lpDesc->dwSize;
714 memset(lpDesc, 0, dwSize);
715 memcpy(lpDesc, &This->desc, dwSize);
717 if (TRACE_ON(d3d7)) {
718 TRACE(" Returning description :\n");
719 _dump_D3DEXECUTEBUFFERDESC(lpDesc);
721 return D3D_OK;
724 /*****************************************************************************
725 * IDirect3DExecuteBuffer::Unlock
727 * Unlocks the buffer. We don't have anything to do here
729 * Returns:
730 * This implementation always returns D3D_OK
732 *****************************************************************************/
733 static HRESULT WINAPI
734 IDirect3DExecuteBufferImpl_Unlock(IDirect3DExecuteBuffer *iface)
736 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
737 TRACE("(%p)->() no-op...\n", This);
738 return D3D_OK;
741 /*****************************************************************************
742 * IDirect3DExecuteBuffer::SetExecuteData
744 * Sets the execute data. This data is used to describe the buffer's content
746 * Params:
747 * Data: Pointer to a D3DEXECUTEDATA structure containing the data to
748 * assign
750 * Returns:
751 * D3D_OK on success
752 * DDERR_OUTOFMEMORY if the vertex buffer allocation failed
754 *****************************************************************************/
755 static HRESULT WINAPI
756 IDirect3DExecuteBufferImpl_SetExecuteData(IDirect3DExecuteBuffer *iface,
757 D3DEXECUTEDATA *lpData)
759 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
760 DWORD nbvert;
761 TRACE("(%p)->(%p)\n", This, lpData);
763 memcpy(&This->data, lpData, lpData->dwSize);
765 /* Get the number of vertices in the execute buffer */
766 nbvert = This->data.dwVertexCount;
768 /* Prepares the transformed vertex buffer */
769 HeapFree(GetProcessHeap(), 0, This->vertex_data);
770 This->vertex_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nbvert * sizeof(D3DTLVERTEX));
772 if (TRACE_ON(d3d7)) {
773 _dump_executedata(lpData);
776 return D3D_OK;
779 /*****************************************************************************
780 * IDirect3DExecuteBuffer::GetExecuteData
782 * Returns the data in the execute buffer
784 * Params:
785 * Data: Pointer to a D3DEXECUTEDATA structure used to return data
787 * Returns:
788 * D3D_OK on success
790 *****************************************************************************/
791 static HRESULT WINAPI
792 IDirect3DExecuteBufferImpl_GetExecuteData(IDirect3DExecuteBuffer *iface,
793 D3DEXECUTEDATA *lpData)
795 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
796 DWORD dwSize;
797 TRACE("(%p)->(%p): stub!\n", This, lpData);
799 dwSize = lpData->dwSize;
800 memset(lpData, 0, dwSize);
801 memcpy(lpData, &This->data, dwSize);
803 if (TRACE_ON(d3d7)) {
804 TRACE("Returning data :\n");
805 _dump_executedata(lpData);
808 return DD_OK;
811 /*****************************************************************************
812 * IDirect3DExecuteBuffer::Validate
814 * DirectX 5 SDK: "The IDirect3DExecuteBuffer::Validate method is not
815 * currently implemented"
817 * Params:
820 * Returns:
821 * DDERR_UNSUPPORTED, because it's not implemented in Windows.
823 *****************************************************************************/
824 static HRESULT WINAPI
825 IDirect3DExecuteBufferImpl_Validate(IDirect3DExecuteBuffer *iface,
826 DWORD *Offset,
827 LPD3DVALIDATECALLBACK Func,
828 void *UserArg,
829 DWORD Reserved)
831 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
832 TRACE("(%p)->(%p,%p,%p,%08x): Unimplemented!\n", This, Offset, Func, UserArg, Reserved);
833 return DDERR_UNSUPPORTED; /* Unchecked */
836 /*****************************************************************************
837 * IDirect3DExecuteBuffer::Optimize
839 * DirectX5 SDK: "The IDirect3DExecuteBuffer::Optimize method is not
840 * currently supported"
842 * Params:
843 * Dummy: Seems to be an unused dummy ;)
845 * Returns:
846 * DDERR_UNSUPPORTED, because it's not implemented in Windows.
848 *****************************************************************************/
849 static HRESULT WINAPI
850 IDirect3DExecuteBufferImpl_Optimize(IDirect3DExecuteBuffer *iface,
851 DWORD Dummy)
853 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
854 TRACE("(%p)->(%08x): Unimplemented\n", This, Dummy);
855 return DDERR_UNSUPPORTED; /* Unchecked */
858 const IDirect3DExecuteBufferVtbl IDirect3DExecuteBuffer_Vtbl =
860 IDirect3DExecuteBufferImpl_QueryInterface,
861 IDirect3DExecuteBufferImpl_AddRef,
862 IDirect3DExecuteBufferImpl_Release,
863 IDirect3DExecuteBufferImpl_Initialize,
864 IDirect3DExecuteBufferImpl_Lock,
865 IDirect3DExecuteBufferImpl_Unlock,
866 IDirect3DExecuteBufferImpl_SetExecuteData,
867 IDirect3DExecuteBufferImpl_GetExecuteData,
868 IDirect3DExecuteBufferImpl_Validate,
869 IDirect3DExecuteBufferImpl_Optimize,