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"
26 #include "ddraw_private.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
30 /*****************************************************************************
32 * _dump_D3DEXECUTEBUFFERDESC
34 * Debug functions which write the executebuffer data to the console
36 *****************************************************************************/
38 static void _dump_executedata(const D3DEXECUTEDATA
*lpData
) {
39 TRACE("dwSize : %d\n", lpData
->dwSize
);
40 TRACE("Vertex Offset : %d Count : %d\n", lpData
->dwVertexOffset
, lpData
->dwVertexCount
);
41 TRACE("Instruction Offset : %d Length : %d\n", lpData
->dwInstructionOffset
, lpData
->dwInstructionLength
);
42 TRACE("HVertex Offset : %d\n", lpData
->dwHVertexOffset
);
45 static void _dump_D3DEXECUTEBUFFERDESC(const D3DEXECUTEBUFFERDESC
*lpDesc
) {
46 TRACE("dwSize : %d\n", lpDesc
->dwSize
);
47 TRACE("dwFlags : %x\n", lpDesc
->dwFlags
);
48 TRACE("dwCaps : %x\n", lpDesc
->dwCaps
);
49 TRACE("dwBufferSize : %d\n", lpDesc
->dwBufferSize
);
50 TRACE("lpData : %p\n", lpDesc
->lpData
);
53 /*****************************************************************************
54 * IDirect3DExecuteBufferImpl_Execute
56 * The main functionality of the execute buffer
57 * It transforms the vertices if necessary, and calls IDirect3DDevice7
58 * for drawing the vertices. It is called from
59 * IDirect3DDevice::Execute
61 * TODO: Perhaps some comments about the various opcodes wouldn't hurt
63 * Don't declare this static, as it's called from device.c,
64 * IDirect3DDevice::Execute
67 * Device: 3D Device associated to use for drawing
68 * Viewport: Viewport for this operation
70 *****************************************************************************/
71 HRESULT
d3d_execute_buffer_execute(IDirect3DExecuteBufferImpl
*This
,
72 IDirect3DDeviceImpl
*lpDevice
, IDirect3DViewportImpl
*lpViewport
)
74 /* DWORD bs = This->desc.dwBufferSize; */
75 DWORD vs
= This
->data
.dwVertexOffset
;
76 /* DWORD vc = This->data.dwVertexCount; */
77 DWORD is
= This
->data
.dwInstructionOffset
;
78 /* DWORD il = This->data.dwInstructionLength; */
80 char *instr
= (char *)This
->desc
.lpData
+ is
;
82 if (lpViewport
->active_device
!= lpDevice
)
84 WARN("Viewport %p active device is %p.\n",
85 lpViewport
, lpViewport
->active_device
);
86 return DDERR_INVALIDPARAMS
;
89 /* Activate the viewport */
90 viewport_activate(lpViewport
, FALSE
);
92 TRACE("ExecuteData :\n");
94 _dump_executedata(&(This
->data
));
97 LPD3DINSTRUCTION current
= (LPD3DINSTRUCTION
) instr
;
101 count
= current
->wCount
;
102 size
= current
->bSize
;
103 instr
+= sizeof(D3DINSTRUCTION
);
105 switch (current
->bOpcode
) {
107 WARN("POINT-s (%d)\n", count
);
108 instr
+= count
* size
;
112 WARN("LINE-s (%d)\n", count
);
113 instr
+= count
* size
;
116 case D3DOP_TRIANGLE
: {
118 D3DTLVERTEX
*tl_vx
= This
->vertex_data
;
119 TRACE("TRIANGLE (%d)\n", count
);
121 if (count
*3>This
->nb_indices
) {
122 This
->nb_indices
= count
* 3;
123 HeapFree(GetProcessHeap(),0,This
->indices
);
124 This
->indices
= HeapAlloc(GetProcessHeap(),0,sizeof(WORD
)*This
->nb_indices
);
127 for (i
= 0; i
< count
; i
++) {
128 LPD3DTRIANGLE ci
= (LPD3DTRIANGLE
) instr
;
129 TRACE(" v1: %d v2: %d v3: %d\n",ci
->u1
.v1
, ci
->u2
.v2
, ci
->u3
.v3
);
134 if (ci
->wFlags
& D3DTRIFLAG_EDGEENABLE1
)
135 TRACE("EDGEENABLE1 ");
136 if (ci
->wFlags
& D3DTRIFLAG_EDGEENABLE2
)
137 TRACE("EDGEENABLE2 ");
138 if (ci
->wFlags
& D3DTRIFLAG_EDGEENABLE1
)
139 TRACE("EDGEENABLE3 ");
141 if (ci
->wFlags
== D3DTRIFLAG_EVEN
)
143 if (ci
->wFlags
== D3DTRIFLAG_ODD
)
145 if (ci
->wFlags
== D3DTRIFLAG_START
)
147 if ((ci
->wFlags
> 0) && (ci
->wFlags
< 30))
148 TRACE("STARTFLAT(%u) ", ci
->wFlags
);
151 This
->indices
[(i
* 3) ] = ci
->u1
.v1
;
152 This
->indices
[(i
* 3) + 1] = ci
->u2
.v2
;
153 This
->indices
[(i
* 3) + 2] = ci
->u3
.v3
;
156 /* IDirect3DDevices have color keying always enabled -
157 * enable it before drawing. This overwrites any ALPHA*
159 wined3d_device_set_render_state(lpDevice
->wined3d_device
, WINED3DRS_COLORKEYENABLE
, 1);
160 IDirect3DDevice7_DrawIndexedPrimitive(&lpDevice
->IDirect3DDevice7_iface
,
161 D3DPT_TRIANGLELIST
, D3DFVF_TLVERTEX
, tl_vx
, 0, This
->indices
, count
* 3, 0);
164 case D3DOP_MATRIXLOAD
:
165 WARN("MATRIXLOAD-s (%d)\n", count
);
166 instr
+= count
* size
;
169 case D3DOP_MATRIXMULTIPLY
: {
171 TRACE("MATRIXMULTIPLY (%d)\n", count
);
173 for (i
= 0; i
< count
; ++i
)
175 D3DMATRIXMULTIPLY
*ci
= (D3DMATRIXMULTIPLY
*)instr
;
176 D3DMATRIX
*a
, *b
, *c
;
178 a
= ddraw_get_object(&lpDevice
->handle_table
, ci
->hDestMatrix
- 1, DDRAW_HANDLE_MATRIX
);
179 b
= ddraw_get_object(&lpDevice
->handle_table
, ci
->hSrcMatrix1
- 1, DDRAW_HANDLE_MATRIX
);
180 c
= ddraw_get_object(&lpDevice
->handle_table
, ci
->hSrcMatrix2
- 1, DDRAW_HANDLE_MATRIX
);
184 ERR("Invalid matrix handle (a %#x -> %p, b %#x -> %p, c %#x -> %p).\n",
185 ci
->hDestMatrix
, a
, ci
->hSrcMatrix1
, b
, ci
->hSrcMatrix2
, c
);
189 TRACE("dst %p, src1 %p, src2 %p.\n", a
, b
, c
);
190 multiply_matrix(a
, c
, b
);
197 case D3DOP_STATETRANSFORM
: {
199 TRACE("STATETRANSFORM (%d)\n", count
);
201 for (i
= 0; i
< count
; ++i
)
203 D3DSTATE
*ci
= (D3DSTATE
*)instr
;
206 m
= ddraw_get_object(&lpDevice
->handle_table
, ci
->u2
.dwArg
[0] - 1, DDRAW_HANDLE_MATRIX
);
209 ERR("Invalid matrix handle %#x.\n", ci
->u2
.dwArg
[0]);
213 if (ci
->u1
.dtstTransformStateType
== D3DTRANSFORMSTATE_WORLD
)
214 lpDevice
->world
= ci
->u2
.dwArg
[0];
215 if (ci
->u1
.dtstTransformStateType
== D3DTRANSFORMSTATE_VIEW
)
216 lpDevice
->view
= ci
->u2
.dwArg
[0];
217 if (ci
->u1
.dtstTransformStateType
== D3DTRANSFORMSTATE_PROJECTION
)
218 lpDevice
->proj
= ci
->u2
.dwArg
[0];
219 IDirect3DDevice7_SetTransform(&lpDevice
->IDirect3DDevice7_iface
,
220 ci
->u1
.dtstTransformStateType
, m
);
227 case D3DOP_STATELIGHT
: {
229 TRACE("STATELIGHT (%d)\n", count
);
231 for (i
= 0; i
< count
; i
++) {
232 LPD3DSTATE ci
= (LPD3DSTATE
) instr
;
234 TRACE("(%08x,%08x)\n", ci
->u1
.dlstLightStateType
, ci
->u2
.dwArg
[0]);
236 if (!ci
->u1
.dlstLightStateType
|| (ci
->u1
.dlstLightStateType
> D3DLIGHTSTATE_COLORVERTEX
))
237 ERR("Unexpected Light State Type %d\n", ci
->u1
.dlstLightStateType
);
238 else if (ci
->u1
.dlstLightStateType
== D3DLIGHTSTATE_MATERIAL
/* 1 */)
240 IDirect3DMaterialImpl
*m
;
242 m
= ddraw_get_object(&lpDevice
->handle_table
, ci
->u2
.dwArg
[0] - 1, DDRAW_HANDLE_MATERIAL
);
244 ERR("Invalid material handle %#x.\n", ci
->u2
.dwArg
[0]);
246 material_activate(m
);
248 else if (ci
->u1
.dlstLightStateType
== D3DLIGHTSTATE_COLORMODEL
/* 3 */)
250 switch (ci
->u2
.dwArg
[0]) {
252 ERR("DDCOLOR_MONO should not happen!\n");
255 /* We are already in this mode */
258 ERR("Unknown color model!\n");
261 D3DRENDERSTATETYPE rs
= 0;
262 switch (ci
->u1
.dlstLightStateType
) {
264 case D3DLIGHTSTATE_AMBIENT
: /* 2 */
265 rs
= D3DRENDERSTATE_AMBIENT
;
267 case D3DLIGHTSTATE_FOGMODE
: /* 4 */
268 rs
= D3DRENDERSTATE_FOGVERTEXMODE
;
270 case D3DLIGHTSTATE_FOGSTART
: /* 5 */
271 rs
= D3DRENDERSTATE_FOGSTART
;
273 case D3DLIGHTSTATE_FOGEND
: /* 6 */
274 rs
= D3DRENDERSTATE_FOGEND
;
276 case D3DLIGHTSTATE_FOGDENSITY
: /* 7 */
277 rs
= D3DRENDERSTATE_FOGDENSITY
;
279 case D3DLIGHTSTATE_COLORVERTEX
: /* 8 */
280 rs
= D3DRENDERSTATE_COLORVERTEX
;
286 IDirect3DDevice7_SetRenderState(&lpDevice
->IDirect3DDevice7_iface
, rs
, ci
->u2
.dwArg
[0]);
293 case D3DOP_STATERENDER
: {
295 IDirect3DDevice2
*d3d_device2
= &lpDevice
->IDirect3DDevice2_iface
;
296 TRACE("STATERENDER (%d)\n", count
);
298 for (i
= 0; i
< count
; i
++) {
299 LPD3DSTATE ci
= (LPD3DSTATE
) instr
;
301 IDirect3DDevice2_SetRenderState(d3d_device2
, ci
->u1
.drstRenderStateType
, ci
->u2
.dwArg
[0]);
307 case D3DOP_PROCESSVERTICES
:
309 /* TODO: Share code with IDirect3DVertexBuffer::ProcessVertices and / or
310 * IWineD3DDevice::ProcessVertices
313 D3DMATRIX view_mat
, world_mat
, proj_mat
;
314 TRACE("PROCESSVERTICES (%d)\n", count
);
316 /* Get the transform and world matrix */
317 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
318 wined3d_device_get_transform(lpDevice
->wined3d_device
,
319 D3DTRANSFORMSTATE_VIEW
, (WINED3DMATRIX
*)&view_mat
);
320 wined3d_device_get_transform(lpDevice
->wined3d_device
,
321 D3DTRANSFORMSTATE_PROJECTION
, (WINED3DMATRIX
*)&proj_mat
);
322 wined3d_device_get_transform(lpDevice
->wined3d_device
,
323 WINED3DTS_WORLDMATRIX(0), (WINED3DMATRIX
*)&world_mat
);
325 for (i
= 0; i
< count
; i
++) {
326 LPD3DPROCESSVERTICES ci
= (LPD3DPROCESSVERTICES
) instr
;
328 TRACE(" Start : %d Dest : %d Count : %d\n",
329 ci
->wStart
, ci
->wDest
, ci
->dwCount
);
333 if (ci
->dwFlags
& D3DPROCESSVERTICES_COPY
)
335 if (ci
->dwFlags
& D3DPROCESSVERTICES_NOCOLOR
)
337 if (ci
->dwFlags
== D3DPROCESSVERTICES_OPMASK
)
339 if (ci
->dwFlags
& D3DPROCESSVERTICES_TRANSFORM
)
341 if (ci
->dwFlags
== D3DPROCESSVERTICES_TRANSFORMLIGHT
)
342 TRACE("TRANSFORMLIGHT ");
343 if (ci
->dwFlags
& D3DPROCESSVERTICES_UPDATEEXTENTS
)
344 TRACE("UPDATEEXTENTS ");
348 /* This is where doing Direct3D on top on OpenGL is quite difficult.
349 This method transforms a set of vertices using the CURRENT state
350 (lighting, projection, ...) but does not rasterize them.
351 They will only be put on screen later (with the POINT / LINE and
352 TRIANGLE op-codes). The problem is that you can have a triangle
353 with each point having been transformed using another state...
355 In this implementation, I will emulate only ONE thing : each
356 vertex can have its own "WORLD" transformation (this is used in the
357 TWIST.EXE demo of the 5.2 SDK). I suppose that all vertices of the
358 execute buffer use the same state.
360 If I find applications that change other states, I will try to do a
361 more 'fine-tuned' state emulation (but I may become quite tricky if
362 it changes a light position in the middle of a triangle).
364 In this case, a 'direct' approach (i.e. without using OpenGL, but
365 writing our own 3D rasterizer) would be easier. */
367 /* The current method (with the hypothesis that only the WORLD matrix
368 will change between two points) is like this :
369 - I transform 'manually' all the vertices with the current WORLD
370 matrix and store them in the vertex buffer
371 - during the rasterization phase, the WORLD matrix will be set to
372 the Identity matrix */
374 /* Enough for the moment */
375 if (ci
->dwFlags
== D3DPROCESSVERTICES_TRANSFORMLIGHT
) {
377 D3DVERTEX
*src
= ((LPD3DVERTEX
) ((char *)This
->desc
.lpData
+ vs
)) + ci
->wStart
;
378 D3DTLVERTEX
*dst
= ((LPD3DTLVERTEX
) (This
->vertex_data
)) + ci
->wDest
;
380 D3DVIEWPORT
* Viewport
= &lpViewport
->viewports
.vp1
;
384 TRACE(" Projection Matrix : (%p)\n", &proj_mat
);
385 dump_D3DMATRIX(&proj_mat
);
386 TRACE(" View Matrix : (%p)\n", &view_mat
);
387 dump_D3DMATRIX(&view_mat
);
388 TRACE(" World Matrix : (%p)\n", &world_mat
);
389 dump_D3DMATRIX(&world_mat
);
392 multiply_matrix(&mat
,&view_mat
,&world_mat
);
393 multiply_matrix(&mat
,&proj_mat
,&mat
);
395 for (nb
= 0; nb
< ci
->dwCount
; nb
++) {
396 /* No lighting yet */
397 dst
->u5
.color
= 0xFFFFFFFF; /* Opaque white */
398 dst
->u6
.specular
= 0xFF000000; /* No specular and no fog factor */
400 dst
->u7
.tu
= src
->u7
.tu
;
401 dst
->u8
.tv
= src
->u8
.tv
;
403 /* Now, the matrix multiplication */
404 dst
->u1
.sx
= (src
->u1
.x
* mat
._11
) + (src
->u2
.y
* mat
._21
) + (src
->u3
.z
* mat
._31
) + (1.0 * mat
._41
);
405 dst
->u2
.sy
= (src
->u1
.x
* mat
._12
) + (src
->u2
.y
* mat
._22
) + (src
->u3
.z
* mat
._32
) + (1.0 * mat
._42
);
406 dst
->u3
.sz
= (src
->u1
.x
* mat
._13
) + (src
->u2
.y
* mat
._23
) + (src
->u3
.z
* mat
._33
) + (1.0 * mat
._43
);
407 dst
->u4
.rhw
= (src
->u1
.x
* mat
._14
) + (src
->u2
.y
* mat
._24
) + (src
->u3
.z
* mat
._34
) + (1.0 * mat
._44
);
409 dst
->u1
.sx
= dst
->u1
.sx
/ dst
->u4
.rhw
* Viewport
->dvScaleX
410 + Viewport
->dwX
+ Viewport
->dwWidth
/ 2;
411 dst
->u2
.sy
= (-dst
->u2
.sy
) / dst
->u4
.rhw
* Viewport
->dvScaleY
412 + Viewport
->dwY
+ Viewport
->dwHeight
/ 2;
413 dst
->u3
.sz
/= dst
->u4
.rhw
;
414 dst
->u4
.rhw
= 1 / dst
->u4
.rhw
;
420 } else if (ci
->dwFlags
== D3DPROCESSVERTICES_TRANSFORM
) {
422 D3DLVERTEX
*src
= ((LPD3DLVERTEX
) ((char *)This
->desc
.lpData
+ vs
)) + ci
->wStart
;
423 D3DTLVERTEX
*dst
= ((LPD3DTLVERTEX
) (This
->vertex_data
)) + ci
->wDest
;
425 D3DVIEWPORT
* Viewport
= &lpViewport
->viewports
.vp1
;
429 TRACE(" Projection Matrix : (%p)\n", &proj_mat
);
430 dump_D3DMATRIX(&proj_mat
);
431 TRACE(" View Matrix : (%p)\n",&view_mat
);
432 dump_D3DMATRIX(&view_mat
);
433 TRACE(" World Matrix : (%p)\n", &world_mat
);
434 dump_D3DMATRIX(&world_mat
);
437 multiply_matrix(&mat
,&view_mat
,&world_mat
);
438 multiply_matrix(&mat
,&proj_mat
,&mat
);
440 for (nb
= 0; nb
< ci
->dwCount
; nb
++) {
441 dst
->u5
.color
= src
->u4
.color
;
442 dst
->u6
.specular
= src
->u5
.specular
;
443 dst
->u7
.tu
= src
->u6
.tu
;
444 dst
->u8
.tv
= src
->u7
.tv
;
446 /* Now, the matrix multiplication */
447 dst
->u1
.sx
= (src
->u1
.x
* mat
._11
) + (src
->u2
.y
* mat
._21
) + (src
->u3
.z
* mat
._31
) + (1.0 * mat
._41
);
448 dst
->u2
.sy
= (src
->u1
.x
* mat
._12
) + (src
->u2
.y
* mat
._22
) + (src
->u3
.z
* mat
._32
) + (1.0 * mat
._42
);
449 dst
->u3
.sz
= (src
->u1
.x
* mat
._13
) + (src
->u2
.y
* mat
._23
) + (src
->u3
.z
* mat
._33
) + (1.0 * mat
._43
);
450 dst
->u4
.rhw
= (src
->u1
.x
* mat
._14
) + (src
->u2
.y
* mat
._24
) + (src
->u3
.z
* mat
._34
) + (1.0 * mat
._44
);
452 dst
->u1
.sx
= dst
->u1
.sx
/ dst
->u4
.rhw
* Viewport
->dvScaleX
453 + Viewport
->dwX
+ Viewport
->dwWidth
/ 2;
454 dst
->u2
.sy
= (-dst
->u2
.sy
) / dst
->u4
.rhw
* Viewport
->dvScaleY
455 + Viewport
->dwY
+ Viewport
->dwHeight
/ 2;
457 dst
->u3
.sz
/= dst
->u4
.rhw
;
458 dst
->u4
.rhw
= 1 / dst
->u4
.rhw
;
463 } else if (ci
->dwFlags
== D3DPROCESSVERTICES_COPY
) {
464 D3DTLVERTEX
*src
= ((LPD3DTLVERTEX
) ((char *)This
->desc
.lpData
+ vs
)) + ci
->wStart
;
465 D3DTLVERTEX
*dst
= ((LPD3DTLVERTEX
) (This
->vertex_data
)) + ci
->wDest
;
467 memcpy(dst
, src
, ci
->dwCount
* sizeof(D3DTLVERTEX
));
469 ERR("Unhandled vertex processing flag %#x.\n", ci
->dwFlags
);
476 case D3DOP_TEXTURELOAD
: {
477 WARN("TEXTURELOAD-s (%d)\n", count
);
479 instr
+= count
* size
;
483 TRACE("EXIT (%d)\n", count
);
484 /* We did this instruction */
490 case D3DOP_BRANCHFORWARD
: {
492 TRACE("BRANCHFORWARD (%d)\n", count
);
494 for (i
= 0; i
< count
; i
++) {
495 LPD3DBRANCH ci
= (LPD3DBRANCH
) instr
;
497 if ((This
->data
.dsStatus
.dwStatus
& ci
->dwMask
) == ci
->dwValue
) {
499 TRACE(" Branch to %d\n", ci
->dwOffset
);
501 instr
= (char*)current
+ ci
->dwOffset
;
507 TRACE(" Branch to %d\n", ci
->dwOffset
);
509 instr
= (char*)current
+ ci
->dwOffset
;
520 WARN("SPAN-s (%d)\n", count
);
522 instr
+= count
* size
;
525 case D3DOP_SETSTATUS
: {
527 TRACE("SETSTATUS (%d)\n", count
);
529 for (i
= 0; i
< count
; i
++) {
530 LPD3DSTATUS ci
= (LPD3DSTATUS
) instr
;
532 This
->data
.dsStatus
= *ci
;
539 ERR("Unhandled OpCode %d !!!\n",current
->bOpcode
);
540 /* Try to save ... */
541 instr
+= count
* size
;
550 static inline IDirect3DExecuteBufferImpl
*impl_from_IDirect3DExecuteBuffer(IDirect3DExecuteBuffer
*iface
)
552 return CONTAINING_RECORD(iface
, IDirect3DExecuteBufferImpl
, IDirect3DExecuteBuffer_iface
);
555 /*****************************************************************************
556 * IDirect3DExecuteBuffer::QueryInterface
558 * Well, a usual QueryInterface function. Don't know fur sure which
559 * interfaces it can Query.
562 * riid: The interface ID queried for
563 * obj: Address to return the interface pointer at
566 * D3D_OK in case of a success (S_OK? Think it's the same)
567 * OLE_E_ENUM_NOMORE if the interface wasn't found.
568 * (E_NOINTERFACE?? Don't know what I really need)
570 *****************************************************************************/
571 static HRESULT WINAPI
572 IDirect3DExecuteBufferImpl_QueryInterface(IDirect3DExecuteBuffer
*iface
,
576 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), obj
);
580 if ( IsEqualGUID( &IID_IUnknown
, riid
) ) {
581 IDirect3DExecuteBuffer_AddRef(iface
);
583 TRACE(" Creating IUnknown interface at %p.\n", *obj
);
586 if ( IsEqualGUID( &IID_IDirect3DExecuteBuffer
, riid
) ) {
587 IDirect3DExecuteBuffer_AddRef(iface
);
589 TRACE(" Creating IDirect3DExecuteBuffer interface %p\n", *obj
);
592 FIXME("(%p): interface for IID %s NOT found!\n", iface
, debugstr_guid(riid
));
593 return E_NOINTERFACE
;
597 /*****************************************************************************
598 * IDirect3DExecuteBuffer::AddRef
600 * A normal AddRef method, nothing special
605 *****************************************************************************/
606 static ULONG WINAPI
IDirect3DExecuteBufferImpl_AddRef(IDirect3DExecuteBuffer
*iface
)
608 IDirect3DExecuteBufferImpl
*This
= impl_from_IDirect3DExecuteBuffer(iface
);
609 ULONG ref
= InterlockedIncrement(&This
->ref
);
611 TRACE("%p increasing refcount to %u.\n", This
, ref
);
616 /*****************************************************************************
617 * IDirect3DExecuteBuffer::Release
619 * A normal Release method, nothing special
624 *****************************************************************************/
625 static ULONG WINAPI
IDirect3DExecuteBufferImpl_Release(IDirect3DExecuteBuffer
*iface
)
627 IDirect3DExecuteBufferImpl
*This
= impl_from_IDirect3DExecuteBuffer(iface
);
628 ULONG ref
= InterlockedDecrement(&This
->ref
);
630 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
634 HeapFree(GetProcessHeap(),0,This
->desc
.lpData
);
635 HeapFree(GetProcessHeap(),0,This
->vertex_data
);
636 HeapFree(GetProcessHeap(),0,This
->indices
);
637 HeapFree(GetProcessHeap(),0,This
);
644 /*****************************************************************************
645 * IDirect3DExecuteBuffer::Initialize
647 * Initializes the Execute Buffer. This method exists for COM compliance
648 * Nothing to do here.
653 *****************************************************************************/
654 static HRESULT WINAPI
IDirect3DExecuteBufferImpl_Initialize(IDirect3DExecuteBuffer
*iface
,
655 IDirect3DDevice
*device
, D3DEXECUTEBUFFERDESC
*desc
)
657 TRACE("iface %p, device %p, desc %p.\n", iface
, device
, desc
);
662 /*****************************************************************************
663 * IDirect3DExecuteBuffer::Lock
665 * Locks the buffer, so the app can write into it.
668 * Desc: Pointer to return the buffer description. This Description contains
669 * a pointer to the buffer data.
672 * This implementation always returns D3D_OK
674 *****************************************************************************/
675 static HRESULT WINAPI
IDirect3DExecuteBufferImpl_Lock(IDirect3DExecuteBuffer
*iface
,
676 D3DEXECUTEBUFFERDESC
*lpDesc
)
678 IDirect3DExecuteBufferImpl
*This
= impl_from_IDirect3DExecuteBuffer(iface
);
681 TRACE("iface %p, desc %p.\n", iface
, lpDesc
);
683 dwSize
= lpDesc
->dwSize
;
684 memcpy(lpDesc
, &This
->desc
, dwSize
);
688 TRACE(" Returning description :\n");
689 _dump_D3DEXECUTEBUFFERDESC(lpDesc
);
694 /*****************************************************************************
695 * IDirect3DExecuteBuffer::Unlock
697 * Unlocks the buffer. We don't have anything to do here
700 * This implementation always returns D3D_OK
702 *****************************************************************************/
703 static HRESULT WINAPI
IDirect3DExecuteBufferImpl_Unlock(IDirect3DExecuteBuffer
*iface
)
705 TRACE("iface %p.\n", iface
);
710 /*****************************************************************************
711 * IDirect3DExecuteBuffer::SetExecuteData
713 * Sets the execute data. This data is used to describe the buffer's content
716 * Data: Pointer to a D3DEXECUTEDATA structure containing the data to
721 * DDERR_OUTOFMEMORY if the vertex buffer allocation failed
723 *****************************************************************************/
724 static HRESULT WINAPI
IDirect3DExecuteBufferImpl_SetExecuteData(IDirect3DExecuteBuffer
*iface
,
725 D3DEXECUTEDATA
*lpData
)
727 IDirect3DExecuteBufferImpl
*This
= impl_from_IDirect3DExecuteBuffer(iface
);
730 TRACE("iface %p, data %p.\n", iface
, lpData
);
732 memcpy(&This
->data
, lpData
, lpData
->dwSize
);
734 /* Get the number of vertices in the execute buffer */
735 nbvert
= This
->data
.dwVertexCount
;
737 /* Prepares the transformed vertex buffer */
738 HeapFree(GetProcessHeap(), 0, This
->vertex_data
);
739 This
->vertex_data
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, nbvert
* sizeof(D3DTLVERTEX
));
742 _dump_executedata(lpData
);
747 /*****************************************************************************
748 * IDirect3DExecuteBuffer::GetExecuteData
750 * Returns the data in the execute buffer
753 * Data: Pointer to a D3DEXECUTEDATA structure used to return data
758 *****************************************************************************/
759 static HRESULT WINAPI
IDirect3DExecuteBufferImpl_GetExecuteData(IDirect3DExecuteBuffer
*iface
,
760 D3DEXECUTEDATA
*lpData
)
762 IDirect3DExecuteBufferImpl
*This
= impl_from_IDirect3DExecuteBuffer(iface
);
765 TRACE("iface %p, data %p.\n", iface
, lpData
);
767 dwSize
= lpData
->dwSize
;
768 memcpy(lpData
, &This
->data
, dwSize
);
772 TRACE("Returning data :\n");
773 _dump_executedata(lpData
);
779 /*****************************************************************************
780 * IDirect3DExecuteBuffer::Validate
782 * DirectX 5 SDK: "The IDirect3DExecuteBuffer::Validate method is not
783 * currently implemented"
789 * DDERR_UNSUPPORTED, because it's not implemented in Windows.
791 *****************************************************************************/
792 static HRESULT WINAPI
IDirect3DExecuteBufferImpl_Validate(IDirect3DExecuteBuffer
*iface
,
793 DWORD
*offset
, LPD3DVALIDATECALLBACK callback
, void *context
, DWORD reserved
)
795 TRACE("iface %p, offset %p, callback %p, context %p, reserved %#x.\n",
796 iface
, offset
, callback
, context
, reserved
);
798 WARN("Not implemented.\n");
800 return DDERR_UNSUPPORTED
; /* Unchecked */
803 /*****************************************************************************
804 * IDirect3DExecuteBuffer::Optimize
806 * DirectX5 SDK: "The IDirect3DExecuteBuffer::Optimize method is not
807 * currently supported"
810 * Dummy: Seems to be an unused dummy ;)
813 * DDERR_UNSUPPORTED, because it's not implemented in Windows.
815 *****************************************************************************/
816 static HRESULT WINAPI
IDirect3DExecuteBufferImpl_Optimize(IDirect3DExecuteBuffer
*iface
, DWORD reserved
)
818 TRACE("iface %p, reserved %#x.\n", iface
, reserved
);
820 WARN("Not implemented.\n");
822 return DDERR_UNSUPPORTED
; /* Unchecked */
825 static const struct IDirect3DExecuteBufferVtbl d3d_execute_buffer_vtbl
=
827 IDirect3DExecuteBufferImpl_QueryInterface
,
828 IDirect3DExecuteBufferImpl_AddRef
,
829 IDirect3DExecuteBufferImpl_Release
,
830 IDirect3DExecuteBufferImpl_Initialize
,
831 IDirect3DExecuteBufferImpl_Lock
,
832 IDirect3DExecuteBufferImpl_Unlock
,
833 IDirect3DExecuteBufferImpl_SetExecuteData
,
834 IDirect3DExecuteBufferImpl_GetExecuteData
,
835 IDirect3DExecuteBufferImpl_Validate
,
836 IDirect3DExecuteBufferImpl_Optimize
,
839 HRESULT
d3d_execute_buffer_init(IDirect3DExecuteBufferImpl
*execute_buffer
,
840 IDirect3DDeviceImpl
*device
, D3DEXECUTEBUFFERDESC
*desc
)
842 execute_buffer
->IDirect3DExecuteBuffer_iface
.lpVtbl
= &d3d_execute_buffer_vtbl
;
843 execute_buffer
->ref
= 1;
844 execute_buffer
->d3ddev
= device
;
846 /* Initializes memory */
847 memcpy(&execute_buffer
->desc
, desc
, desc
->dwSize
);
849 /* No buffer given */
850 if (!(execute_buffer
->desc
.dwFlags
& D3DDEB_LPDATA
))
851 execute_buffer
->desc
.lpData
= NULL
;
853 /* No buffer size given */
854 if (!(execute_buffer
->desc
.dwFlags
& D3DDEB_BUFSIZE
))
855 execute_buffer
->desc
.dwBufferSize
= 0;
857 /* Create buffer if asked */
858 if (!execute_buffer
->desc
.lpData
&& execute_buffer
->desc
.dwBufferSize
)
860 execute_buffer
->need_free
= TRUE
;
861 execute_buffer
->desc
.lpData
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, execute_buffer
->desc
.dwBufferSize
);
862 if (!execute_buffer
->desc
.lpData
)
864 ERR("Failed to allocate execute buffer data.\n");
865 return DDERR_OUTOFMEMORY
;
869 execute_buffer
->desc
.dwFlags
|= D3DDEB_LPDATA
;
874 IDirect3DExecuteBufferImpl
*unsafe_impl_from_IDirect3DExecuteBuffer(IDirect3DExecuteBuffer
*iface
)
878 assert(iface
->lpVtbl
== &d3d_execute_buffer_vtbl
);
880 return impl_from_IDirect3DExecuteBuffer(iface
);