1 /* Direct3D ExecuteBuffer
2 * Copyright (c) 1998-2004 Lionel ULMER
3 * Copyright (c) 2002-2004 Christian Costa
4 * Copyright (c) 2006 Stefan Dösinger
6 * This file contains the implementation of IDirect3DExecuteBuffer.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
32 #define NONAMELESSUNION
38 #include "wine/exception.h"
43 #include "ddraw_private.h"
44 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(d3d7
);
48 /*****************************************************************************
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
85 * Device: 3D Device associated to use for drawing
86 * Viewport: Viewport for this operation
88 *****************************************************************************/
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
, FALSE
);
108 TRACE("ExecuteData :\n");
110 _dump_executedata(&(This
->data
));
113 LPD3DINSTRUCTION current
= (LPD3DINSTRUCTION
) instr
;
117 count
= current
->wCount
;
118 size
= current
->bSize
;
119 instr
+= sizeof(D3DINSTRUCTION
);
121 switch (current
->bOpcode
) {
123 WARN("POINT-s (%d)\n", count
);
124 instr
+= count
* size
;
128 WARN("LINE-s (%d)\n", count
);
129 instr
+= count
* size
;
132 case D3DOP_TRIANGLE
: {
134 D3DTLVERTEX
*tl_vx
= 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
)) {
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 ");
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
);
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
;
171 /* IDirect3DDevices have color keying always enabled -
172 * enable it before drawing. This overwrites any ALPHA*
175 IWineD3DDevice_SetRenderState(lpDevice
->wineD3DDevice
,
176 WINED3DRS_COLORKEYENABLE
,
178 IDirect3DDevice7_DrawIndexedPrimitive((IDirect3DDevice7
*)lpDevice
,
179 D3DPT_TRIANGLELIST
, D3DFVF_TLVERTEX
, tl_vx
, 0, This
->indices
, count
* 3, 0);
182 case D3DOP_MATRIXLOAD
:
183 WARN("MATRIXLOAD-s (%d)\n", count
);
184 instr
+= count
* size
;
187 case D3DOP_MATRIXMULTIPLY
: {
189 TRACE("MATRIXMULTIPLY (%d)\n", count
);
191 for (i
= 0; i
< count
; ++i
)
193 D3DMATRIXMULTIPLY
*ci
= (D3DMATRIXMULTIPLY
*)instr
;
194 D3DMATRIX
*a
, *b
, *c
;
196 a
= ddraw_get_object(&lpDevice
->handle_table
, ci
->hDestMatrix
- 1, DDRAW_HANDLE_MATRIX
);
197 b
= ddraw_get_object(&lpDevice
->handle_table
, ci
->hSrcMatrix1
- 1, DDRAW_HANDLE_MATRIX
);
198 c
= ddraw_get_object(&lpDevice
->handle_table
, ci
->hSrcMatrix2
- 1, DDRAW_HANDLE_MATRIX
);
202 ERR("Invalid matrix handle (a %#x -> %p, b %#x -> %p, c %#x -> %p).\n",
203 ci
->hDestMatrix
, a
, ci
->hSrcMatrix1
, b
, ci
->hSrcMatrix2
, c
);
207 TRACE("dst %p, src1 %p, src2 %p.\n", a
, b
, c
);
208 multiply_matrix(a
, c
, b
);
215 case D3DOP_STATETRANSFORM
: {
217 TRACE("STATETRANSFORM (%d)\n", count
);
219 for (i
= 0; i
< count
; ++i
)
221 D3DSTATE
*ci
= (D3DSTATE
*)instr
;
224 m
= ddraw_get_object(&lpDevice
->handle_table
, ci
->u2
.dwArg
[0] - 1, DDRAW_HANDLE_MATRIX
);
227 ERR("Invalid matrix handle %#x.\n", ci
->u2
.dwArg
[0]);
231 if (ci
->u1
.dtstTransformStateType
== D3DTRANSFORMSTATE_WORLD
)
232 lpDevice
->world
= ci
->u2
.dwArg
[0];
233 if (ci
->u1
.dtstTransformStateType
== D3DTRANSFORMSTATE_VIEW
)
234 lpDevice
->view
= ci
->u2
.dwArg
[0];
235 if (ci
->u1
.dtstTransformStateType
== D3DTRANSFORMSTATE_PROJECTION
)
236 lpDevice
->proj
= ci
->u2
.dwArg
[0];
237 IDirect3DDevice7_SetTransform((IDirect3DDevice7
*)lpDevice
,
238 ci
->u1
.dtstTransformStateType
, m
);
245 case D3DOP_STATELIGHT
: {
247 TRACE("STATELIGHT (%d)\n", count
);
249 for (i
= 0; i
< count
; i
++) {
250 LPD3DSTATE ci
= (LPD3DSTATE
) instr
;
252 TRACE("(%08x,%08x)\n", ci
->u1
.dlstLightStateType
, ci
->u2
.dwArg
[0]);
254 if (!ci
->u1
.dlstLightStateType
|| (ci
->u1
.dlstLightStateType
> D3DLIGHTSTATE_COLORVERTEX
))
255 ERR("Unexpected Light State Type %d\n", ci
->u1
.dlstLightStateType
);
256 else if (ci
->u1
.dlstLightStateType
== D3DLIGHTSTATE_MATERIAL
/* 1 */)
258 IDirect3DMaterialImpl
*m
;
260 m
= ddraw_get_object(&lpDevice
->handle_table
, ci
->u2
.dwArg
[0] - 1, DDRAW_HANDLE_MATERIAL
);
262 ERR("Invalid material handle %#x.\n", ci
->u2
.dwArg
[0]);
266 else if (ci
->u1
.dlstLightStateType
== D3DLIGHTSTATE_COLORMODEL
/* 3 */)
268 switch (ci
->u2
.dwArg
[0]) {
270 ERR("DDCOLOR_MONO should not happen!\n");
273 /* We are already in this mode */
276 ERR("Unknown color model!\n");
279 D3DRENDERSTATETYPE rs
= 0;
280 switch (ci
->u1
.dlstLightStateType
) {
282 case D3DLIGHTSTATE_AMBIENT
: /* 2 */
283 rs
= D3DRENDERSTATE_AMBIENT
;
285 case D3DLIGHTSTATE_FOGMODE
: /* 4 */
286 rs
= D3DRENDERSTATE_FOGVERTEXMODE
;
288 case D3DLIGHTSTATE_FOGSTART
: /* 5 */
289 rs
= D3DRENDERSTATE_FOGSTART
;
291 case D3DLIGHTSTATE_FOGEND
: /* 6 */
292 rs
= D3DRENDERSTATE_FOGEND
;
294 case D3DLIGHTSTATE_FOGDENSITY
: /* 7 */
295 rs
= D3DRENDERSTATE_FOGDENSITY
;
297 case D3DLIGHTSTATE_COLORVERTEX
: /* 8 */
298 rs
= D3DRENDERSTATE_COLORVERTEX
;
304 IDirect3DDevice7_SetRenderState((IDirect3DDevice7
*)lpDevice
, rs
, ci
->u2
.dwArg
[0]);
311 case D3DOP_STATERENDER
: {
313 IDirect3DDevice2
*d3d_device2
= (IDirect3DDevice2
*)&lpDevice
->IDirect3DDevice2_vtbl
;
314 TRACE("STATERENDER (%d)\n", count
);
316 for (i
= 0; i
< count
; i
++) {
317 LPD3DSTATE ci
= (LPD3DSTATE
) instr
;
319 IDirect3DDevice2_SetRenderState(d3d_device2
, ci
->u1
.drstRenderStateType
, ci
->u2
.dwArg
[0]);
325 case D3DOP_PROCESSVERTICES
:
327 /* TODO: Share code with IDirect3DVertexBuffer::ProcessVertices and / or
328 * IWineD3DDevice::ProcessVertices
331 D3DMATRIX view_mat
, world_mat
, proj_mat
;
332 TRACE("PROCESSVERTICES (%d)\n", count
);
334 /* Get the transform and world matrix */
335 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
337 IWineD3DDevice_GetTransform(lpDevice
->wineD3DDevice
,
338 D3DTRANSFORMSTATE_VIEW
,
339 (WINED3DMATRIX
*) &view_mat
);
341 IWineD3DDevice_GetTransform(lpDevice
->wineD3DDevice
,
342 D3DTRANSFORMSTATE_PROJECTION
,
343 (WINED3DMATRIX
*) &proj_mat
);
345 IWineD3DDevice_GetTransform(lpDevice
->wineD3DDevice
,
346 WINED3DTS_WORLDMATRIX(0),
347 (WINED3DMATRIX
*) &world_mat
);
349 for (i
= 0; i
< count
; i
++) {
350 LPD3DPROCESSVERTICES ci
= (LPD3DPROCESSVERTICES
) instr
;
352 TRACE(" Start : %d Dest : %d Count : %d\n",
353 ci
->wStart
, ci
->wDest
, ci
->dwCount
);
355 if (TRACE_ON(d3d7
)) {
356 if (ci
->dwFlags
& D3DPROCESSVERTICES_COPY
)
358 if (ci
->dwFlags
& D3DPROCESSVERTICES_NOCOLOR
)
360 if (ci
->dwFlags
== D3DPROCESSVERTICES_OPMASK
)
362 if (ci
->dwFlags
& D3DPROCESSVERTICES_TRANSFORM
)
364 if (ci
->dwFlags
== D3DPROCESSVERTICES_TRANSFORMLIGHT
)
365 TRACE("TRANSFORMLIGHT ");
366 if (ci
->dwFlags
& D3DPROCESSVERTICES_UPDATEEXTENTS
)
367 TRACE("UPDATEEXTENTS ");
371 /* This is where doing Direct3D on top on OpenGL is quite difficult.
372 This method transforms a set of vertices using the CURRENT state
373 (lighting, projection, ...) but does not rasterize them.
374 They will only be put on screen later (with the POINT / LINE and
375 TRIANGLE op-codes). The problem is that you can have a triangle
376 with each point having been transformed using another state...
378 In this implementation, I will emulate only ONE thing : each
379 vertex can have its own "WORLD" transformation (this is used in the
380 TWIST.EXE demo of the 5.2 SDK). I suppose that all vertices of the
381 execute buffer use the same state.
383 If I find applications that change other states, I will try to do a
384 more 'fine-tuned' state emulation (but I may become quite tricky if
385 it changes a light position in the middle of a triangle).
387 In this case, a 'direct' approach (i.e. without using OpenGL, but
388 writing our own 3D rasterizer) would be easier. */
390 /* The current method (with the hypothesis that only the WORLD matrix
391 will change between two points) is like this :
392 - I transform 'manually' all the vertices with the current WORLD
393 matrix and store them in the vertex buffer
394 - during the rasterization phase, the WORLD matrix will be set to
395 the Identity matrix */
397 /* Enough for the moment */
398 if (ci
->dwFlags
== D3DPROCESSVERTICES_TRANSFORMLIGHT
) {
400 D3DVERTEX
*src
= ((LPD3DVERTEX
) ((char *)This
->desc
.lpData
+ vs
)) + ci
->wStart
;
401 D3DTLVERTEX
*dst
= ((LPD3DTLVERTEX
) (This
->vertex_data
)) + ci
->wDest
;
403 D3DVIEWPORT
* Viewport
= &lpViewport
->viewports
.vp1
;
405 if (TRACE_ON(d3d7
)) {
406 TRACE(" Projection Matrix : (%p)\n", &proj_mat
);
407 dump_D3DMATRIX(&proj_mat
);
408 TRACE(" View Matrix : (%p)\n", &view_mat
);
409 dump_D3DMATRIX(&view_mat
);
410 TRACE(" World Matrix : (%p)\n", &world_mat
);
411 dump_D3DMATRIX(&world_mat
);
414 multiply_matrix(&mat
,&view_mat
,&world_mat
);
415 multiply_matrix(&mat
,&proj_mat
,&mat
);
417 for (nb
= 0; nb
< ci
->dwCount
; nb
++) {
418 /* No lighting yet */
419 dst
->u5
.color
= 0xFFFFFFFF; /* Opaque white */
420 dst
->u6
.specular
= 0xFF000000; /* No specular and no fog factor */
422 dst
->u7
.tu
= src
->u7
.tu
;
423 dst
->u8
.tv
= src
->u8
.tv
;
425 /* Now, the matrix multiplication */
426 dst
->u1
.sx
= (src
->u1
.x
* mat
._11
) + (src
->u2
.y
* mat
._21
) + (src
->u3
.z
* mat
._31
) + (1.0 * mat
._41
);
427 dst
->u2
.sy
= (src
->u1
.x
* mat
._12
) + (src
->u2
.y
* mat
._22
) + (src
->u3
.z
* mat
._32
) + (1.0 * mat
._42
);
428 dst
->u3
.sz
= (src
->u1
.x
* mat
._13
) + (src
->u2
.y
* mat
._23
) + (src
->u3
.z
* mat
._33
) + (1.0 * mat
._43
);
429 dst
->u4
.rhw
= (src
->u1
.x
* mat
._14
) + (src
->u2
.y
* mat
._24
) + (src
->u3
.z
* mat
._34
) + (1.0 * mat
._44
);
431 dst
->u1
.sx
= dst
->u1
.sx
/ dst
->u4
.rhw
* Viewport
->dvScaleX
432 + Viewport
->dwX
+ Viewport
->dwWidth
/ 2;
433 dst
->u2
.sy
= (-dst
->u2
.sy
) / dst
->u4
.rhw
* Viewport
->dvScaleY
434 + Viewport
->dwY
+ Viewport
->dwHeight
/ 2;
435 dst
->u3
.sz
/= dst
->u4
.rhw
;
436 dst
->u4
.rhw
= 1 / dst
->u4
.rhw
;
442 } else if (ci
->dwFlags
== D3DPROCESSVERTICES_TRANSFORM
) {
444 D3DLVERTEX
*src
= ((LPD3DLVERTEX
) ((char *)This
->desc
.lpData
+ vs
)) + ci
->wStart
;
445 D3DTLVERTEX
*dst
= ((LPD3DTLVERTEX
) (This
->vertex_data
)) + ci
->wDest
;
447 D3DVIEWPORT
* Viewport
= &lpViewport
->viewports
.vp1
;
449 if (TRACE_ON(d3d7
)) {
450 TRACE(" Projection Matrix : (%p)\n", &proj_mat
);
451 dump_D3DMATRIX(&proj_mat
);
452 TRACE(" View Matrix : (%p)\n",&view_mat
);
453 dump_D3DMATRIX(&view_mat
);
454 TRACE(" World Matrix : (%p)\n", &world_mat
);
455 dump_D3DMATRIX(&world_mat
);
458 multiply_matrix(&mat
,&view_mat
,&world_mat
);
459 multiply_matrix(&mat
,&proj_mat
,&mat
);
461 for (nb
= 0; nb
< ci
->dwCount
; nb
++) {
462 dst
->u5
.color
= src
->u4
.color
;
463 dst
->u6
.specular
= src
->u5
.specular
;
464 dst
->u7
.tu
= src
->u6
.tu
;
465 dst
->u8
.tv
= src
->u7
.tv
;
467 /* Now, the matrix multiplication */
468 dst
->u1
.sx
= (src
->u1
.x
* mat
._11
) + (src
->u2
.y
* mat
._21
) + (src
->u3
.z
* mat
._31
) + (1.0 * mat
._41
);
469 dst
->u2
.sy
= (src
->u1
.x
* mat
._12
) + (src
->u2
.y
* mat
._22
) + (src
->u3
.z
* mat
._32
) + (1.0 * mat
._42
);
470 dst
->u3
.sz
= (src
->u1
.x
* mat
._13
) + (src
->u2
.y
* mat
._23
) + (src
->u3
.z
* mat
._33
) + (1.0 * mat
._43
);
471 dst
->u4
.rhw
= (src
->u1
.x
* mat
._14
) + (src
->u2
.y
* mat
._24
) + (src
->u3
.z
* mat
._34
) + (1.0 * mat
._44
);
473 dst
->u1
.sx
= dst
->u1
.sx
/ dst
->u4
.rhw
* Viewport
->dvScaleX
474 + Viewport
->dwX
+ Viewport
->dwWidth
/ 2;
475 dst
->u2
.sy
= (-dst
->u2
.sy
) / dst
->u4
.rhw
* Viewport
->dvScaleY
476 + Viewport
->dwY
+ Viewport
->dwHeight
/ 2;
478 dst
->u3
.sz
/= dst
->u4
.rhw
;
479 dst
->u4
.rhw
= 1 / dst
->u4
.rhw
;
484 } else if (ci
->dwFlags
== D3DPROCESSVERTICES_COPY
) {
485 D3DTLVERTEX
*src
= ((LPD3DTLVERTEX
) ((char *)This
->desc
.lpData
+ vs
)) + ci
->wStart
;
486 D3DTLVERTEX
*dst
= ((LPD3DTLVERTEX
) (This
->vertex_data
)) + ci
->wDest
;
488 memcpy(dst
, src
, ci
->dwCount
* sizeof(D3DTLVERTEX
));
490 ERR("Unhandled vertex processing flag %#x.\n", ci
->dwFlags
);
497 case D3DOP_TEXTURELOAD
: {
498 WARN("TEXTURELOAD-s (%d)\n", count
);
500 instr
+= count
* size
;
504 TRACE("EXIT (%d)\n", count
);
505 /* We did this instruction */
511 case D3DOP_BRANCHFORWARD
: {
513 TRACE("BRANCHFORWARD (%d)\n", count
);
515 for (i
= 0; i
< count
; i
++) {
516 LPD3DBRANCH ci
= (LPD3DBRANCH
) instr
;
518 if ((This
->data
.dsStatus
.dwStatus
& ci
->dwMask
) == ci
->dwValue
) {
520 TRACE(" Branch to %d\n", ci
->dwOffset
);
522 instr
= (char*)current
+ ci
->dwOffset
;
528 TRACE(" Branch to %d\n", ci
->dwOffset
);
530 instr
= (char*)current
+ ci
->dwOffset
;
541 WARN("SPAN-s (%d)\n", count
);
543 instr
+= count
* size
;
546 case D3DOP_SETSTATUS
: {
548 TRACE("SETSTATUS (%d)\n", count
);
550 for (i
= 0; i
< count
; i
++) {
551 LPD3DSTATUS ci
= (LPD3DSTATUS
) instr
;
553 This
->data
.dsStatus
= *ci
;
560 ERR("Unhandled OpCode %d !!!\n",current
->bOpcode
);
561 /* Try to save ... */
562 instr
+= count
* size
;
571 /*****************************************************************************
572 * IDirect3DExecuteBuffer::QueryInterface
574 * Well, a usual QueryInterface function. Don't know fur sure which
575 * interfaces it can Query.
578 * riid: The interface ID queried for
579 * obj: Address to return the interface pointer at
582 * D3D_OK in case of a success (S_OK? Think it's the same)
583 * OLE_E_ENUM_NOMORE if the interface wasn't found.
584 * (E_NOINTERFACE?? Don't know what I really need)
586 *****************************************************************************/
587 static HRESULT WINAPI
588 IDirect3DExecuteBufferImpl_QueryInterface(IDirect3DExecuteBuffer
*iface
,
592 TRACE("(%p)->(%s,%p)\n", iface
, debugstr_guid(riid
), obj
);
596 if ( IsEqualGUID( &IID_IUnknown
, riid
) ) {
597 IDirect3DExecuteBuffer_AddRef(iface
);
599 TRACE(" Creating IUnknown interface at %p.\n", *obj
);
602 if ( IsEqualGUID( &IID_IDirect3DExecuteBuffer
, riid
) ) {
603 IDirect3DExecuteBuffer_AddRef(iface
);
605 TRACE(" Creating IDirect3DExecuteBuffer interface %p\n", *obj
);
608 FIXME("(%p): interface for IID %s NOT found!\n", iface
, debugstr_guid(riid
));
609 return E_NOINTERFACE
;
613 /*****************************************************************************
614 * IDirect3DExecuteBuffer::AddRef
616 * A normal AddRef method, nothing special
621 *****************************************************************************/
623 IDirect3DExecuteBufferImpl_AddRef(IDirect3DExecuteBuffer
*iface
)
625 IDirect3DExecuteBufferImpl
*This
= (IDirect3DExecuteBufferImpl
*)iface
;
626 ULONG ref
= InterlockedIncrement(&This
->ref
);
628 FIXME("(%p)->()incrementing from %u.\n", This
, ref
- 1);
633 /*****************************************************************************
634 * IDirect3DExecuteBuffer::Release
636 * A normal Release method, nothing special
641 *****************************************************************************/
643 IDirect3DExecuteBufferImpl_Release(IDirect3DExecuteBuffer
*iface
)
645 IDirect3DExecuteBufferImpl
*This
= (IDirect3DExecuteBufferImpl
*)iface
;
646 ULONG ref
= InterlockedDecrement(&This
->ref
);
648 TRACE("(%p)->()decrementing from %u.\n", This
, ref
+ 1);
652 HeapFree(GetProcessHeap(),0,This
->desc
.lpData
);
653 HeapFree(GetProcessHeap(),0,This
->vertex_data
);
654 HeapFree(GetProcessHeap(),0,This
->indices
);
655 HeapFree(GetProcessHeap(),0,This
);
662 /*****************************************************************************
663 * IDirect3DExecuteBuffer::Initialize
665 * Initializes the Execute Buffer. This method exists for COM compliance
666 * Nothing to do here.
671 *****************************************************************************/
672 static HRESULT WINAPI
673 IDirect3DExecuteBufferImpl_Initialize(IDirect3DExecuteBuffer
*iface
,
674 IDirect3DDevice
*lpDirect3DDevice
,
675 D3DEXECUTEBUFFERDESC
*lpDesc
)
677 IDirect3DExecuteBufferImpl
*This
= (IDirect3DExecuteBufferImpl
*)iface
;
678 TRACE("(%p)->(%p,%p) no-op....\n", This
, lpDirect3DDevice
, lpDesc
);
682 /*****************************************************************************
683 * IDirect3DExecuteBuffer::Lock
685 * Locks the buffer, so the app can write into it.
688 * Desc: Pointer to return the buffer description. This Description contains
689 * a pointer to the buffer data.
692 * This implementation always returns D3D_OK
694 *****************************************************************************/
695 static HRESULT WINAPI
696 IDirect3DExecuteBufferImpl_Lock(IDirect3DExecuteBuffer
*iface
,
697 D3DEXECUTEBUFFERDESC
*lpDesc
)
699 IDirect3DExecuteBufferImpl
*This
= (IDirect3DExecuteBufferImpl
*)iface
;
701 TRACE("(%p)->(%p)\n", This
, lpDesc
);
703 dwSize
= lpDesc
->dwSize
;
704 memcpy(lpDesc
, &This
->desc
, dwSize
);
706 if (TRACE_ON(d3d7
)) {
707 TRACE(" Returning description :\n");
708 _dump_D3DEXECUTEBUFFERDESC(lpDesc
);
713 /*****************************************************************************
714 * IDirect3DExecuteBuffer::Unlock
716 * Unlocks the buffer. We don't have anything to do here
719 * This implementation always returns D3D_OK
721 *****************************************************************************/
722 static HRESULT WINAPI
723 IDirect3DExecuteBufferImpl_Unlock(IDirect3DExecuteBuffer
*iface
)
725 IDirect3DExecuteBufferImpl
*This
= (IDirect3DExecuteBufferImpl
*)iface
;
726 TRACE("(%p)->() no-op...\n", This
);
730 /*****************************************************************************
731 * IDirect3DExecuteBuffer::SetExecuteData
733 * Sets the execute data. This data is used to describe the buffer's content
736 * Data: Pointer to a D3DEXECUTEDATA structure containing the data to
741 * DDERR_OUTOFMEMORY if the vertex buffer allocation failed
743 *****************************************************************************/
744 static HRESULT WINAPI
745 IDirect3DExecuteBufferImpl_SetExecuteData(IDirect3DExecuteBuffer
*iface
,
746 D3DEXECUTEDATA
*lpData
)
748 IDirect3DExecuteBufferImpl
*This
= (IDirect3DExecuteBufferImpl
*)iface
;
750 TRACE("(%p)->(%p)\n", This
, lpData
);
752 memcpy(&This
->data
, lpData
, lpData
->dwSize
);
754 /* Get the number of vertices in the execute buffer */
755 nbvert
= This
->data
.dwVertexCount
;
757 /* Prepares the transformed vertex buffer */
758 HeapFree(GetProcessHeap(), 0, This
->vertex_data
);
759 This
->vertex_data
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, nbvert
* sizeof(D3DTLVERTEX
));
761 if (TRACE_ON(d3d7
)) {
762 _dump_executedata(lpData
);
768 /*****************************************************************************
769 * IDirect3DExecuteBuffer::GetExecuteData
771 * Returns the data in the execute buffer
774 * Data: Pointer to a D3DEXECUTEDATA structure used to return data
779 *****************************************************************************/
780 static HRESULT WINAPI
781 IDirect3DExecuteBufferImpl_GetExecuteData(IDirect3DExecuteBuffer
*iface
,
782 D3DEXECUTEDATA
*lpData
)
784 IDirect3DExecuteBufferImpl
*This
= (IDirect3DExecuteBufferImpl
*)iface
;
786 TRACE("(%p)->(%p): stub!\n", This
, lpData
);
788 dwSize
= lpData
->dwSize
;
789 memcpy(lpData
, &This
->data
, dwSize
);
791 if (TRACE_ON(d3d7
)) {
792 TRACE("Returning data :\n");
793 _dump_executedata(lpData
);
799 /*****************************************************************************
800 * IDirect3DExecuteBuffer::Validate
802 * DirectX 5 SDK: "The IDirect3DExecuteBuffer::Validate method is not
803 * currently implemented"
809 * DDERR_UNSUPPORTED, because it's not implemented in Windows.
811 *****************************************************************************/
812 static HRESULT WINAPI
813 IDirect3DExecuteBufferImpl_Validate(IDirect3DExecuteBuffer
*iface
,
815 LPD3DVALIDATECALLBACK Func
,
819 IDirect3DExecuteBufferImpl
*This
= (IDirect3DExecuteBufferImpl
*)iface
;
820 TRACE("(%p)->(%p,%p,%p,%08x): Unimplemented!\n", This
, Offset
, Func
, UserArg
, Reserved
);
821 return DDERR_UNSUPPORTED
; /* Unchecked */
824 /*****************************************************************************
825 * IDirect3DExecuteBuffer::Optimize
827 * DirectX5 SDK: "The IDirect3DExecuteBuffer::Optimize method is not
828 * currently supported"
831 * Dummy: Seems to be an unused dummy ;)
834 * DDERR_UNSUPPORTED, because it's not implemented in Windows.
836 *****************************************************************************/
837 static HRESULT WINAPI
838 IDirect3DExecuteBufferImpl_Optimize(IDirect3DExecuteBuffer
*iface
,
841 IDirect3DExecuteBufferImpl
*This
= (IDirect3DExecuteBufferImpl
*)iface
;
842 TRACE("(%p)->(%08x): Unimplemented\n", This
, Dummy
);
843 return DDERR_UNSUPPORTED
; /* Unchecked */
846 const IDirect3DExecuteBufferVtbl IDirect3DExecuteBuffer_Vtbl
=
848 IDirect3DExecuteBufferImpl_QueryInterface
,
849 IDirect3DExecuteBufferImpl_AddRef
,
850 IDirect3DExecuteBufferImpl_Release
,
851 IDirect3DExecuteBufferImpl_Initialize
,
852 IDirect3DExecuteBufferImpl_Lock
,
853 IDirect3DExecuteBufferImpl_Unlock
,
854 IDirect3DExecuteBufferImpl_SetExecuteData
,
855 IDirect3DExecuteBufferImpl_GetExecuteData
,
856 IDirect3DExecuteBufferImpl_Validate
,
857 IDirect3DExecuteBufferImpl_Optimize
,