kernel32: Fix the size of ThreadAffinityMask to match PSDK.
[wine/multimedia.git] / dlls / ddraw / executebuffer.c
blob9dbff68bcaec2abe8eaed5a4ac7c28bd3f4c884b
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 DPRINTF("dwSize : %d\n", lpData->dwSize);
58 DPRINTF("Vertex Offset : %d Count : %d\n", lpData->dwVertexOffset, lpData->dwVertexCount);
59 DPRINTF("Instruction Offset : %d Length : %d\n", lpData->dwInstructionOffset, lpData->dwInstructionLength);
60 DPRINTF("HVertex Offset : %d\n", lpData->dwHVertexOffset);
63 static void _dump_D3DEXECUTEBUFFERDESC(const D3DEXECUTEBUFFERDESC *lpDesc) {
64 DPRINTF("dwSize : %d\n", lpDesc->dwSize);
65 DPRINTF("dwFlags : %x\n", lpDesc->dwFlags);
66 DPRINTF("dwCaps : %x\n", lpDesc->dwCaps);
67 DPRINTF("dwBufferSize : %d\n", lpDesc->dwBufferSize);
68 DPRINTF("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 IDirect3DDevice7_SetTransform(ICOM_INTERFACE(lpDevice, IDirect3DDevice7),
231 ci->u1.drstRenderStateType, (LPD3DMATRIX) lpDevice->Handles[ci->u2.dwArg[0] - 1].ptr);
233 instr += size;
235 } break;
237 case D3DOP_STATELIGHT: {
238 int i;
239 TRACE("STATELIGHT (%d)\n", count);
241 for (i = 0; i < count; i++) {
242 LPD3DSTATE ci = (LPD3DSTATE) instr;
244 TRACE("(%08x,%08x)\n",ci->u1.dlstLightStateType, ci->u2.dwArg[0]);
246 if (!ci->u1.dlstLightStateType && (ci->u1.dlstLightStateType > D3DLIGHTSTATE_COLORVERTEX))
247 ERR("Unexpected Light State Type\n");
248 else if (ci->u1.dlstLightStateType == D3DLIGHTSTATE_MATERIAL /* 1 */) {
249 IDirect3DMaterialImpl *mat = (IDirect3DMaterialImpl *) ci->u2.dwArg[0];
251 if (mat != NULL) {
252 mat->activate(mat);
253 } else {
254 FIXME(" D3DLIGHTSTATE_MATERIAL called with NULL material !!!\n");
257 else if (ci->u1.dlstLightStateType == D3DLIGHTSTATE_COLORMODEL /* 3 */) {
258 switch (ci->u2.dwArg[0]) {
259 case D3DCOLOR_MONO:
260 ERR("DDCOLOR_MONO should not happen!\n");
261 break;
262 case D3DCOLOR_RGB:
263 /* We are already in this mode */
264 break;
265 default:
266 ERR("Unknown color model!\n");
268 } else {
269 D3DRENDERSTATETYPE rs = 0;
270 switch (ci->u1.dlstLightStateType) {
272 case D3DLIGHTSTATE_AMBIENT: /* 2 */
273 rs = D3DRENDERSTATE_AMBIENT;
274 break;
275 case D3DLIGHTSTATE_FOGMODE: /* 4 */
276 rs = D3DRENDERSTATE_FOGVERTEXMODE;
277 break;
278 case D3DLIGHTSTATE_FOGSTART: /* 5 */
279 rs = D3DRENDERSTATE_FOGSTART;
280 break;
281 case D3DLIGHTSTATE_FOGEND: /* 6 */
282 rs = D3DRENDERSTATE_FOGEND;
283 break;
284 case D3DLIGHTSTATE_FOGDENSITY: /* 7 */
285 rs = D3DRENDERSTATE_FOGDENSITY;
286 break;
287 case D3DLIGHTSTATE_COLORVERTEX: /* 8 */
288 rs = D3DRENDERSTATE_COLORVERTEX;
289 break;
290 default:
291 break;
294 IDirect3DDevice7_SetRenderState(ICOM_INTERFACE(lpDevice, IDirect3DDevice7),
295 rs,ci->u2.dwArg[0]);
298 instr += size;
300 } break;
302 case D3DOP_STATERENDER: {
303 int i;
304 TRACE("STATERENDER (%d)\n", count);
306 for (i = 0; i < count; i++) {
307 LPD3DSTATE ci = (LPD3DSTATE) instr;
309 IDirect3DDevice7_SetRenderState(ICOM_INTERFACE(lpDevice, IDirect3DDevice7),
310 ci->u1.drstRenderStateType, ci->u2.dwArg[0]);
312 instr += size;
314 } break;
316 case D3DOP_PROCESSVERTICES:
318 /* TODO: Share code with IDirect3DVertexBuffer::ProcessVertices and / or
319 * IWineD3DDevice::ProcessVertices
321 int i;
322 D3DMATRIX view_mat, world_mat, proj_mat;
323 TRACE("PROCESSVERTICES (%d)\n", count);
325 /* Get the transform and world matrix */
326 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
328 IWineD3DDevice_GetTransform(lpDevice->wineD3DDevice,
329 D3DTRANSFORMSTATE_VIEW,
330 (WINED3DMATRIX*) &view_mat);
332 IWineD3DDevice_GetTransform(lpDevice->wineD3DDevice,
333 D3DTRANSFORMSTATE_PROJECTION,
334 (WINED3DMATRIX*) &proj_mat);
336 IWineD3DDevice_GetTransform(lpDevice->wineD3DDevice,
337 D3DTRANSFORMSTATE_WORLD,
338 (WINED3DMATRIX*) &world_mat);
340 for (i = 0; i < count; i++) {
341 LPD3DPROCESSVERTICES ci = (LPD3DPROCESSVERTICES) instr;
343 TRACE(" Start : %d Dest : %d Count : %d\n",
344 ci->wStart, ci->wDest, ci->dwCount);
345 TRACE(" Flags : ");
346 if (TRACE_ON(d3d7)) {
347 if (ci->dwFlags & D3DPROCESSVERTICES_COPY)
348 TRACE("COPY ");
349 if (ci->dwFlags & D3DPROCESSVERTICES_NOCOLOR)
350 TRACE("NOCOLOR ");
351 if (ci->dwFlags == D3DPROCESSVERTICES_OPMASK)
352 TRACE("OPMASK ");
353 if (ci->dwFlags & D3DPROCESSVERTICES_TRANSFORM)
354 TRACE("TRANSFORM ");
355 if (ci->dwFlags == D3DPROCESSVERTICES_TRANSFORMLIGHT)
356 TRACE("TRANSFORMLIGHT ");
357 if (ci->dwFlags & D3DPROCESSVERTICES_UPDATEEXTENTS)
358 TRACE("UPDATEEXTENTS ");
359 TRACE("\n");
362 /* This is where doing Direct3D on top on OpenGL is quite difficult.
363 This method transforms a set of vertices using the CURRENT state
364 (lighting, projection, ...) but does not rasterize them.
365 They will only be put on screen later (with the POINT / LINE and
366 TRIANGLE op-codes). The problem is that you can have a triangle
367 with each point having been transformed using another state...
369 In this implementation, I will emulate only ONE thing : each
370 vertex can have its own "WORLD" transformation (this is used in the
371 TWIST.EXE demo of the 5.2 SDK). I suppose that all vertices of the
372 execute buffer use the same state.
374 If I find applications that change other states, I will try to do a
375 more 'fine-tuned' state emulation (but I may become quite tricky if
376 it changes a light position in the middle of a triangle).
378 In this case, a 'direct' approach (i.e. without using OpenGL, but
379 writing our own 3D rasterizer) would be easier. */
381 /* The current method (with the hypothesis that only the WORLD matrix
382 will change between two points) is like this :
383 - I transform 'manually' all the vertices with the current WORLD
384 matrix and store them in the vertex buffer
385 - during the rasterization phase, the WORLD matrix will be set to
386 the Identity matrix */
388 /* Enough for the moment */
389 if (ci->dwFlags == D3DPROCESSVERTICES_TRANSFORMLIGHT) {
390 unsigned int nb;
391 D3DVERTEX *src = ((LPD3DVERTEX) ((char *)This->desc.lpData + vs)) + ci->wStart;
392 D3DTLVERTEX *dst = ((LPD3DTLVERTEX) (This->vertex_data)) + ci->wDest;
393 D3DMATRIX *mat2 = &world_mat;
394 D3DMATRIX mat;
395 D3DVALUE nx,ny,nz;
396 D3DVIEWPORT* Viewport = &lpViewport->viewports.vp1;
398 if (TRACE_ON(d3d7)) {
399 TRACE(" Projection Matrix : (%p)\n", &proj_mat);
400 dump_D3DMATRIX(&proj_mat);
401 TRACE(" View Matrix : (%p)\n", &view_mat);
402 dump_D3DMATRIX(&view_mat);
403 TRACE(" World Matrix : (%p)\n", &world_mat);
404 dump_D3DMATRIX(&world_mat);
407 multiply_matrix(&mat,&view_mat,&world_mat);
408 multiply_matrix(&mat,&proj_mat,&mat);
410 for (nb = 0; nb < ci->dwCount; nb++) {
411 /* Normals transformation */
412 nx = (src->u4.nx * mat2->_11) + (src->u5.ny * mat2->_21) + (src->u6.nz * mat2->_31);
413 ny = (src->u4.nx * mat2->_12) + (src->u5.ny * mat2->_22) + (src->u6.nz * mat2->_32);
414 nz = (src->u4.nx * mat2->_13) + (src->u5.ny * mat2->_23) + (src->u6.nz * mat2->_33);
416 /* No lighting yet */
417 dst->u5.color = 0xFFFFFFFF; /* Opaque white */
418 dst->u6.specular = 0xFF000000; /* No specular and no fog factor */
420 dst->u7.tu = src->u7.tu;
421 dst->u8.tv = src->u8.tv;
423 /* Now, the matrix multiplication */
424 dst->u1.sx = (src->u1.x * mat._11) + (src->u2.y * mat._21) + (src->u3.z * mat._31) + (1.0 * mat._41);
425 dst->u2.sy = (src->u1.x * mat._12) + (src->u2.y * mat._22) + (src->u3.z * mat._32) + (1.0 * mat._42);
426 dst->u3.sz = (src->u1.x * mat._13) + (src->u2.y * mat._23) + (src->u3.z * mat._33) + (1.0 * mat._43);
427 dst->u4.rhw = (src->u1.x * mat._14) + (src->u2.y * mat._24) + (src->u3.z * mat._34) + (1.0 * mat._44);
429 dst->u1.sx = dst->u1.sx / dst->u4.rhw * Viewport->dwWidth / 2
430 + Viewport->dwX + Viewport->dwWidth / 2;
431 dst->u2.sy = dst->u2.sy / dst->u4.rhw * Viewport->dwHeight / 2
432 + Viewport->dwY + Viewport->dwHeight / 2;
433 dst->u3.sz /= dst->u4.rhw;
434 dst->u4.rhw = 1 / dst->u4.rhw;
436 src++;
437 dst++;
440 } else if (ci->dwFlags == D3DPROCESSVERTICES_TRANSFORM) {
441 unsigned int nb;
442 D3DLVERTEX *src = ((LPD3DLVERTEX) ((char *)This->desc.lpData + vs)) + ci->wStart;
443 D3DTLVERTEX *dst = ((LPD3DTLVERTEX) (This->vertex_data)) + ci->wDest;
444 D3DMATRIX mat;
445 D3DVIEWPORT* Viewport = &lpViewport->viewports.vp1;
447 if (TRACE_ON(d3d7)) {
448 TRACE(" Projection Matrix : (%p)\n", &proj_mat);
449 dump_D3DMATRIX(&proj_mat);
450 TRACE(" View Matrix : (%p)\n",&view_mat);
451 dump_D3DMATRIX(&view_mat);
452 TRACE(" World Matrix : (%p)\n", &mat);
453 dump_D3DMATRIX(&mat);
456 multiply_matrix(&mat,&view_mat,&world_mat);
457 multiply_matrix(&mat,&proj_mat,&mat);
459 for (nb = 0; nb < ci->dwCount; nb++) {
460 dst->u5.color = src->u4.color;
461 dst->u6.specular = src->u5.specular;
462 dst->u7.tu = src->u6.tu;
463 dst->u8.tv = src->u7.tv;
465 /* Now, the matrix multiplication */
466 dst->u1.sx = (src->u1.x * mat._11) + (src->u2.y * mat._21) + (src->u3.z * mat._31) + (1.0 * mat._41);
467 dst->u2.sy = (src->u1.x * mat._12) + (src->u2.y * mat._22) + (src->u3.z * mat._32) + (1.0 * mat._42);
468 dst->u3.sz = (src->u1.x * mat._13) + (src->u2.y * mat._23) + (src->u3.z * mat._33) + (1.0 * mat._43);
469 dst->u4.rhw = (src->u1.x * mat._14) + (src->u2.y * mat._24) + (src->u3.z * mat._34) + (1.0 * mat._44);
471 dst->u1.sx /= dst->u4.rhw * Viewport->dvScaleX * Viewport->dwWidth / 2 + Viewport->dwX;
472 dst->u2.sy /= dst->u4.rhw * Viewport->dvScaleY * Viewport->dwHeight / 2 + Viewport->dwY;
473 dst->u3.sz /= dst->u4.rhw;
474 dst->u4.rhw = 1 / dst->u4.rhw;
476 src++;
477 dst++;
479 } else if (ci->dwFlags == D3DPROCESSVERTICES_COPY) {
480 D3DTLVERTEX *src = ((LPD3DTLVERTEX) ((char *)This->desc.lpData + vs)) + ci->wStart;
481 D3DTLVERTEX *dst = ((LPD3DTLVERTEX) (This->vertex_data)) + ci->wDest;
483 memcpy(dst, src, ci->dwCount * sizeof(D3DTLVERTEX));
484 } else {
485 ERR("Unhandled vertex processing !\n");
488 instr += size;
490 } break;
492 case D3DOP_TEXTURELOAD: {
493 WARN("TEXTURELOAD-s (%d)\n", count);
495 instr += count * size;
496 } break;
498 case D3DOP_EXIT: {
499 TRACE("EXIT (%d)\n", count);
500 /* We did this instruction */
501 instr += size;
502 /* Exit this loop */
503 goto end_of_buffer;
504 } break;
506 case D3DOP_BRANCHFORWARD: {
507 int i;
508 TRACE("BRANCHFORWARD (%d)\n", count);
510 for (i = 0; i < count; i++) {
511 LPD3DBRANCH ci = (LPD3DBRANCH) instr;
513 if ((This->data.dsStatus.dwStatus & ci->dwMask) == ci->dwValue) {
514 if (!ci->bNegate) {
515 TRACE(" Branch to %d\n", ci->dwOffset);
516 instr = (char*)current + ci->dwOffset;
517 break;
519 } else {
520 if (ci->bNegate) {
521 TRACE(" Branch to %d\n", ci->dwOffset);
522 instr = (char*)current + ci->dwOffset;
523 break;
527 instr += size;
529 } break;
531 case D3DOP_SPAN: {
532 WARN("SPAN-s (%d)\n", count);
534 instr += count * size;
535 } break;
537 case D3DOP_SETSTATUS: {
538 int i;
539 TRACE("SETSTATUS (%d)\n", count);
541 for (i = 0; i < count; i++) {
542 LPD3DSTATUS ci = (LPD3DSTATUS) instr;
544 This->data.dsStatus = *ci;
546 instr += size;
548 } break;
550 default:
551 ERR("Unhandled OpCode %d !!!\n",current->bOpcode);
552 /* Try to save ... */
553 instr += count * size;
554 break;
558 end_of_buffer:
562 /*****************************************************************************
563 * IDirect3DExecuteBuffer::QueryInterface
565 * Well, a usual QueryInterface function. Don't know fur sure which
566 * interfaces it can Query.
568 * Params:
569 * riid: The interface ID queried for
570 * obj: Address to return the interface pointer at
572 * Returns:
573 * D3D_OK in case of a success (S_OK? Think it's the same)
574 * OLE_E_ENUM_NOMORE if the interface wasn't found.
575 * (E_NOINTERFACE?? Don't know what I really need)
577 *****************************************************************************/
578 static HRESULT WINAPI
579 IDirect3DExecuteBufferImpl_QueryInterface(IDirect3DExecuteBuffer *iface,
580 REFIID riid,
581 void **obj)
583 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
584 TRACE("(%p/%p)->(%s,%p)\n", This, iface, debugstr_guid(riid), obj);
586 *obj = NULL;
588 if ( IsEqualGUID( &IID_IUnknown, riid ) ) {
589 IDirect3DExecuteBuffer_AddRef(ICOM_INTERFACE(This, IDirect3DExecuteBuffer));
590 *obj = iface;
591 TRACE(" Creating IUnknown interface at %p.\n", *obj);
592 return S_OK;
594 if ( IsEqualGUID( &IID_IDirect3DMaterial, riid ) ) {
595 IDirect3DExecuteBuffer_AddRef(ICOM_INTERFACE(This, IDirect3DExecuteBuffer));
596 *obj = ICOM_INTERFACE(This, IDirect3DExecuteBuffer);
597 TRACE(" Creating IDirect3DExecuteBuffer interface %p\n", *obj);
598 return S_OK;
600 FIXME("(%p): interface for IID %s NOT found!\n", This, debugstr_guid(riid));
601 return E_NOINTERFACE;
605 /*****************************************************************************
606 * IDirect3DExecuteBuffer::AddRef
608 * A normal AddRef method, nothing special
610 * Returns:
611 * The new refcount
613 *****************************************************************************/
614 static ULONG WINAPI
615 IDirect3DExecuteBufferImpl_AddRef(IDirect3DExecuteBuffer *iface)
617 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
618 ULONG ref = InterlockedIncrement(&This->ref);
620 FIXME("(%p)->()incrementing from %u.\n", This, ref - 1);
622 return ref;
625 /*****************************************************************************
626 * IDirect3DExecuteBuffer::Release
628 * A normal Release method, nothing special
630 * Returns:
631 * The new refcount
633 *****************************************************************************/
634 static ULONG WINAPI
635 IDirect3DExecuteBufferImpl_Release(IDirect3DExecuteBuffer *iface)
637 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
638 ULONG ref = InterlockedDecrement(&This->ref);
640 TRACE("(%p)->()decrementing from %u.\n", This, ref + 1);
642 if (!ref) {
643 if (This->need_free)
644 HeapFree(GetProcessHeap(),0,This->desc.lpData);
645 HeapFree(GetProcessHeap(),0,This->vertex_data);
646 HeapFree(GetProcessHeap(),0,This->indices);
647 HeapFree(GetProcessHeap(),0,This);
648 return 0;
651 return ref;
654 /*****************************************************************************
655 * IDirect3DExecuteBuffer::Initialize
657 * Initializes the Execute Buffer. This method exists for COM compliance
658 * Nothing to do here.
660 * Returns:
661 * D3D_OK
663 *****************************************************************************/
664 static HRESULT WINAPI
665 IDirect3DExecuteBufferImpl_Initialize(IDirect3DExecuteBuffer *iface,
666 IDirect3DDevice *lpDirect3DDevice,
667 D3DEXECUTEBUFFERDESC *lpDesc)
669 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
670 TRACE("(%p)->(%p,%p) no-op....\n", This, lpDirect3DDevice, lpDesc);
671 return D3D_OK;
674 /*****************************************************************************
675 * IDirect3DExecuteBuffer::Lock
677 * Locks the buffer, so the app can write into it.
679 * Params:
680 * Desc: Pointer to return the buffer description. This Description contains
681 * a pointer to the buffer data.
683 * Returns:
684 * This implementation always returns D3D_OK
686 *****************************************************************************/
687 static HRESULT WINAPI
688 IDirect3DExecuteBufferImpl_Lock(IDirect3DExecuteBuffer *iface,
689 D3DEXECUTEBUFFERDESC *lpDesc)
691 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
692 DWORD dwSize;
693 TRACE("(%p)->(%p)\n", This, lpDesc);
695 dwSize = lpDesc->dwSize;
696 memset(lpDesc, 0, dwSize);
697 memcpy(lpDesc, &This->desc, dwSize);
699 if (TRACE_ON(d3d7)) {
700 TRACE(" Returning description :\n");
701 _dump_D3DEXECUTEBUFFERDESC(lpDesc);
703 return D3D_OK;
706 /*****************************************************************************
707 * IDirect3DExecuteBuffer::Unlock
709 * Unlocks the buffer. We don't have anything to do here
711 * Returns:
712 * This implementation always returns D3D_OK
714 *****************************************************************************/
715 static HRESULT WINAPI
716 IDirect3DExecuteBufferImpl_Unlock(IDirect3DExecuteBuffer *iface)
718 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
719 TRACE("(%p)->() no-op...\n", This);
720 return D3D_OK;
723 /*****************************************************************************
724 * IDirect3DExecuteBuffer::SetExecuteData
726 * Sets the execute data. This data is used to describe the buffer's content
728 * Params:
729 * Data: Pointer to a D3DEXECUTEDATA structure containing the data to
730 * assign
732 * Returns:
733 * D3D_OK on success
734 * DDERR_OUTOFMEMORY if the vertex buffer allocation failed
736 *****************************************************************************/
737 static HRESULT WINAPI
738 IDirect3DExecuteBufferImpl_SetExecuteData(IDirect3DExecuteBuffer *iface,
739 D3DEXECUTEDATA *lpData)
741 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
742 DWORD nbvert;
743 TRACE("(%p)->(%p)\n", This, lpData);
745 memcpy(&This->data, lpData, lpData->dwSize);
747 /* Get the number of vertices in the execute buffer */
748 nbvert = This->data.dwVertexCount;
750 /* Prepares the transformed vertex buffer */
751 HeapFree(GetProcessHeap(), 0, This->vertex_data);
752 This->vertex_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nbvert * sizeof(D3DTLVERTEX));
754 if (TRACE_ON(d3d7)) {
755 _dump_executedata(lpData);
758 return D3D_OK;
761 /*****************************************************************************
762 * IDirect3DExecuteBuffer::GetExecuteData
764 * Returns the data in the execute buffer
766 * Params:
767 * Data: Pointer to a D3DEXECUTEDATA structure used to return data
769 * Returns:
770 * D3D_OK on success
772 *****************************************************************************/
773 static HRESULT WINAPI
774 IDirect3DExecuteBufferImpl_GetExecuteData(IDirect3DExecuteBuffer *iface,
775 D3DEXECUTEDATA *lpData)
777 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
778 DWORD dwSize;
779 TRACE("(%p)->(%p): stub!\n", This, lpData);
781 dwSize = lpData->dwSize;
782 memset(lpData, 0, dwSize);
783 memcpy(lpData, &This->data, dwSize);
785 if (TRACE_ON(d3d7)) {
786 TRACE("Returning data :\n");
787 _dump_executedata(lpData);
790 return DD_OK;
793 /*****************************************************************************
794 * IDirect3DExecuteBuffer::Validate
796 * DirectX 5 SDK: "The IDirect3DExecuteBuffer::Validate method is not
797 * currently implemented"
799 * Params:
802 * Returns:
803 * DDERR_UNSUPPORTED, because it's not implemented in Windows.
805 *****************************************************************************/
806 static HRESULT WINAPI
807 IDirect3DExecuteBufferImpl_Validate(IDirect3DExecuteBuffer *iface,
808 DWORD *Offset,
809 LPD3DVALIDATECALLBACK Func,
810 void *UserArg,
811 DWORD Reserved)
813 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
814 TRACE("(%p)->(%p,%p,%p,%08x): Unimplemented!\n", This, Offset, Func, UserArg, Reserved);
815 return DDERR_UNSUPPORTED; /* Unchecked */
818 /*****************************************************************************
819 * IDirect3DExecuteBuffer::Optimize
821 * DirectX5 SDK: "The IDirect3DExecuteBuffer::Optimize method is not
822 * currently supported"
824 * Params:
825 * Dummy: Seems to be an unused dummy ;)
827 * Returns:
828 * DDERR_UNSUPPORTED, because it's not implemented in Windows.
830 *****************************************************************************/
831 static HRESULT WINAPI
832 IDirect3DExecuteBufferImpl_Optimize(IDirect3DExecuteBuffer *iface,
833 DWORD Dummy)
835 ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
836 TRACE("(%p)->(%08x): Unimplemented\n", This, Dummy);
837 return DDERR_UNSUPPORTED; /* Unchecked */
840 const IDirect3DExecuteBufferVtbl IDirect3DExecuteBuffer_Vtbl =
842 IDirect3DExecuteBufferImpl_QueryInterface,
843 IDirect3DExecuteBufferImpl_AddRef,
844 IDirect3DExecuteBufferImpl_Release,
845 IDirect3DExecuteBufferImpl_Initialize,
846 IDirect3DExecuteBufferImpl_Lock,
847 IDirect3DExecuteBufferImpl_Unlock,
848 IDirect3DExecuteBufferImpl_SetExecuteData,
849 IDirect3DExecuteBufferImpl_GetExecuteData,
850 IDirect3DExecuteBufferImpl_Validate,
851 IDirect3DExecuteBufferImpl_Optimize,