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(d3d7);
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 *****************************************************************************/
72 IDirect3DExecuteBufferImpl_Execute(IDirect3DExecuteBufferImpl *This,
73 IDirect3DDeviceImpl *lpDevice,
74 IDirect3DViewportImpl *lpViewport)
76 /* DWORD bs = This->desc.dwBufferSize; */
77 DWORD vs = This->data.dwVertexOffset;
78 /* DWORD vc = This->data.dwVertexCount; */
79 DWORD is = This->data.dwInstructionOffset;
80 /* DWORD il = This->data.dwInstructionLength; */
82 char *instr = (char *)This->desc.lpData + is;
84 /* Should check if the viewport was added or not to the device */
86 /* Activate the viewport */
87 lpViewport->active_device = lpDevice;
88 viewport_activate(lpViewport, FALSE);
90 TRACE("ExecuteData :\n");
92 _dump_executedata(&(This->data));
95 LPD3DINSTRUCTION current = (LPD3DINSTRUCTION) instr;
99 count = current->wCount;
100 size = current->bSize;
101 instr += sizeof(D3DINSTRUCTION);
103 switch (current->bOpcode) {
105 WARN("POINT-s (%d)\n", count);
106 instr += count * size;
110 WARN("LINE-s (%d)\n", count);
111 instr += count * size;
114 case D3DOP_TRIANGLE: {
116 D3DTLVERTEX *tl_vx = This->vertex_data;
117 TRACE("TRIANGLE (%d)\n", count);
119 if (count*3>This->nb_indices) {
120 This->nb_indices = count * 3;
121 HeapFree(GetProcessHeap(),0,This->indices);
122 This->indices = HeapAlloc(GetProcessHeap(),0,sizeof(WORD)*This->nb_indices);
125 for (i = 0; i < count; i++) {
126 LPD3DTRIANGLE ci = (LPD3DTRIANGLE) instr;
127 TRACE_(d3d7)(" v1: %d v2: %d v3: %d\n",ci->u1.v1, ci->u2.v2, ci->u3.v3);
128 TRACE_(d3d7)(" Flags : ");
129 if (TRACE_ON(d3d7)) {
131 if (ci->wFlags & D3DTRIFLAG_EDGEENABLE1)
132 TRACE_(d3d7)("EDGEENABLE1 ");
133 if (ci->wFlags & D3DTRIFLAG_EDGEENABLE2)
134 TRACE_(d3d7)("EDGEENABLE2 ");
135 if (ci->wFlags & D3DTRIFLAG_EDGEENABLE1)
136 TRACE_(d3d7)("EDGEENABLE3 ");
138 if (ci->wFlags == D3DTRIFLAG_EVEN)
139 TRACE_(d3d7)("EVEN ");
140 if (ci->wFlags == D3DTRIFLAG_ODD)
141 TRACE_(d3d7)("ODD ");
142 if (ci->wFlags == D3DTRIFLAG_START)
143 TRACE_(d3d7)("START ");
144 if ((ci->wFlags > 0) && (ci->wFlags < 30))
145 TRACE_(d3d7)("STARTFLAT(%d) ", ci->wFlags);
148 This->indices[(i * 3) ] = ci->u1.v1;
149 This->indices[(i * 3) + 1] = ci->u2.v2;
150 This->indices[(i * 3) + 2] = ci->u3.v3;
153 /* IDirect3DDevices have color keying always enabled -
154 * enable it before drawing. This overwrites any ALPHA*
157 IWineD3DDevice_SetRenderState(lpDevice->wineD3DDevice,
158 WINED3DRS_COLORKEYENABLE,
160 IDirect3DDevice7_DrawIndexedPrimitive((IDirect3DDevice7 *)lpDevice,
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((IDirect3DDevice7 *)lpDevice,
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((IDirect3DDevice7 *)lpDevice, rs, ci->u2.dwArg[0]);
293 case D3DOP_STATERENDER: {
295 IDirect3DDevice2 *d3d_device2 = (IDirect3DDevice2 *)&lpDevice->IDirect3DDevice2_vtbl;
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 */
319 IWineD3DDevice_GetTransform(lpDevice->wineD3DDevice,
320 D3DTRANSFORMSTATE_VIEW,
321 (WINED3DMATRIX*) &view_mat);
323 IWineD3DDevice_GetTransform(lpDevice->wineD3DDevice,
324 D3DTRANSFORMSTATE_PROJECTION,
325 (WINED3DMATRIX*) &proj_mat);
327 IWineD3DDevice_GetTransform(lpDevice->wineD3DDevice,
328 WINED3DTS_WORLDMATRIX(0),
329 (WINED3DMATRIX*) &world_mat);
331 for (i = 0; i < count; i++) {
332 LPD3DPROCESSVERTICES ci = (LPD3DPROCESSVERTICES) instr;
334 TRACE(" Start : %d Dest : %d Count : %d\n",
335 ci->wStart, ci->wDest, ci->dwCount);
337 if (TRACE_ON(d3d7)) {
338 if (ci->dwFlags & D3DPROCESSVERTICES_COPY)
340 if (ci->dwFlags & D3DPROCESSVERTICES_NOCOLOR)
342 if (ci->dwFlags == D3DPROCESSVERTICES_OPMASK)
344 if (ci->dwFlags & D3DPROCESSVERTICES_TRANSFORM)
346 if (ci->dwFlags == D3DPROCESSVERTICES_TRANSFORMLIGHT)
347 TRACE("TRANSFORMLIGHT ");
348 if (ci->dwFlags & D3DPROCESSVERTICES_UPDATEEXTENTS)
349 TRACE("UPDATEEXTENTS ");
353 /* This is where doing Direct3D on top on OpenGL is quite difficult.
354 This method transforms a set of vertices using the CURRENT state
355 (lighting, projection, ...) but does not rasterize them.
356 They will only be put on screen later (with the POINT / LINE and
357 TRIANGLE op-codes). The problem is that you can have a triangle
358 with each point having been transformed using another state...
360 In this implementation, I will emulate only ONE thing : each
361 vertex can have its own "WORLD" transformation (this is used in the
362 TWIST.EXE demo of the 5.2 SDK). I suppose that all vertices of the
363 execute buffer use the same state.
365 If I find applications that change other states, I will try to do a
366 more 'fine-tuned' state emulation (but I may become quite tricky if
367 it changes a light position in the middle of a triangle).
369 In this case, a 'direct' approach (i.e. without using OpenGL, but
370 writing our own 3D rasterizer) would be easier. */
372 /* The current method (with the hypothesis that only the WORLD matrix
373 will change between two points) is like this :
374 - I transform 'manually' all the vertices with the current WORLD
375 matrix and store them in the vertex buffer
376 - during the rasterization phase, the WORLD matrix will be set to
377 the Identity matrix */
379 /* Enough for the moment */
380 if (ci->dwFlags == D3DPROCESSVERTICES_TRANSFORMLIGHT) {
382 D3DVERTEX *src = ((LPD3DVERTEX) ((char *)This->desc.lpData + vs)) + ci->wStart;
383 D3DTLVERTEX *dst = ((LPD3DTLVERTEX) (This->vertex_data)) + ci->wDest;
385 D3DVIEWPORT* Viewport = &lpViewport->viewports.vp1;
387 if (TRACE_ON(d3d7)) {
388 TRACE(" Projection Matrix : (%p)\n", &proj_mat);
389 dump_D3DMATRIX(&proj_mat);
390 TRACE(" View Matrix : (%p)\n", &view_mat);
391 dump_D3DMATRIX(&view_mat);
392 TRACE(" World Matrix : (%p)\n", &world_mat);
393 dump_D3DMATRIX(&world_mat);
396 multiply_matrix(&mat,&view_mat,&world_mat);
397 multiply_matrix(&mat,&proj_mat,&mat);
399 for (nb = 0; nb < ci->dwCount; nb++) {
400 /* No lighting yet */
401 dst->u5.color = 0xFFFFFFFF; /* Opaque white */
402 dst->u6.specular = 0xFF000000; /* No specular and no fog factor */
404 dst->u7.tu = src->u7.tu;
405 dst->u8.tv = src->u8.tv;
407 /* Now, the matrix multiplication */
408 dst->u1.sx = (src->u1.x * mat._11) + (src->u2.y * mat._21) + (src->u3.z * mat._31) + (1.0 * mat._41);
409 dst->u2.sy = (src->u1.x * mat._12) + (src->u2.y * mat._22) + (src->u3.z * mat._32) + (1.0 * mat._42);
410 dst->u3.sz = (src->u1.x * mat._13) + (src->u2.y * mat._23) + (src->u3.z * mat._33) + (1.0 * mat._43);
411 dst->u4.rhw = (src->u1.x * mat._14) + (src->u2.y * mat._24) + (src->u3.z * mat._34) + (1.0 * mat._44);
413 dst->u1.sx = dst->u1.sx / dst->u4.rhw * Viewport->dvScaleX
414 + Viewport->dwX + Viewport->dwWidth / 2;
415 dst->u2.sy = (-dst->u2.sy) / dst->u4.rhw * Viewport->dvScaleY
416 + Viewport->dwY + Viewport->dwHeight / 2;
417 dst->u3.sz /= dst->u4.rhw;
418 dst->u4.rhw = 1 / dst->u4.rhw;
424 } else if (ci->dwFlags == D3DPROCESSVERTICES_TRANSFORM) {
426 D3DLVERTEX *src = ((LPD3DLVERTEX) ((char *)This->desc.lpData + vs)) + ci->wStart;
427 D3DTLVERTEX *dst = ((LPD3DTLVERTEX) (This->vertex_data)) + ci->wDest;
429 D3DVIEWPORT* Viewport = &lpViewport->viewports.vp1;
431 if (TRACE_ON(d3d7)) {
432 TRACE(" Projection Matrix : (%p)\n", &proj_mat);
433 dump_D3DMATRIX(&proj_mat);
434 TRACE(" View Matrix : (%p)\n",&view_mat);
435 dump_D3DMATRIX(&view_mat);
436 TRACE(" World Matrix : (%p)\n", &world_mat);
437 dump_D3DMATRIX(&world_mat);
440 multiply_matrix(&mat,&view_mat,&world_mat);
441 multiply_matrix(&mat,&proj_mat,&mat);
443 for (nb = 0; nb < ci->dwCount; nb++) {
444 dst->u5.color = src->u4.color;
445 dst->u6.specular = src->u5.specular;
446 dst->u7.tu = src->u6.tu;
447 dst->u8.tv = src->u7.tv;
449 /* Now, the matrix multiplication */
450 dst->u1.sx = (src->u1.x * mat._11) + (src->u2.y * mat._21) + (src->u3.z * mat._31) + (1.0 * mat._41);
451 dst->u2.sy = (src->u1.x * mat._12) + (src->u2.y * mat._22) + (src->u3.z * mat._32) + (1.0 * mat._42);
452 dst->u3.sz = (src->u1.x * mat._13) + (src->u2.y * mat._23) + (src->u3.z * mat._33) + (1.0 * mat._43);
453 dst->u4.rhw = (src->u1.x * mat._14) + (src->u2.y * mat._24) + (src->u3.z * mat._34) + (1.0 * mat._44);
455 dst->u1.sx = dst->u1.sx / dst->u4.rhw * Viewport->dvScaleX
456 + Viewport->dwX + Viewport->dwWidth / 2;
457 dst->u2.sy = (-dst->u2.sy) / dst->u4.rhw * Viewport->dvScaleY
458 + Viewport->dwY + Viewport->dwHeight / 2;
460 dst->u3.sz /= dst->u4.rhw;
461 dst->u4.rhw = 1 / dst->u4.rhw;
466 } else if (ci->dwFlags == D3DPROCESSVERTICES_COPY) {
467 D3DTLVERTEX *src = ((LPD3DTLVERTEX) ((char *)This->desc.lpData + vs)) + ci->wStart;
468 D3DTLVERTEX *dst = ((LPD3DTLVERTEX) (This->vertex_data)) + ci->wDest;
470 memcpy(dst, src, ci->dwCount * sizeof(D3DTLVERTEX));
472 ERR("Unhandled vertex processing flag %#x.\n", ci->dwFlags);
479 case D3DOP_TEXTURELOAD: {
480 WARN("TEXTURELOAD-s (%d)\n", count);
482 instr += count * size;
486 TRACE("EXIT (%d)\n", count);
487 /* We did this instruction */
493 case D3DOP_BRANCHFORWARD: {
495 TRACE("BRANCHFORWARD (%d)\n", count);
497 for (i = 0; i < count; i++) {
498 LPD3DBRANCH ci = (LPD3DBRANCH) instr;
500 if ((This->data.dsStatus.dwStatus & ci->dwMask) == ci->dwValue) {
502 TRACE(" Branch to %d\n", ci->dwOffset);
504 instr = (char*)current + ci->dwOffset;
510 TRACE(" Branch to %d\n", ci->dwOffset);
512 instr = (char*)current + ci->dwOffset;
523 WARN("SPAN-s (%d)\n", count);
525 instr += count * size;
528 case D3DOP_SETSTATUS: {
530 TRACE("SETSTATUS (%d)\n", count);
532 for (i = 0; i < count; i++) {
533 LPD3DSTATUS ci = (LPD3DSTATUS) instr;
535 This->data.dsStatus = *ci;
542 ERR("Unhandled OpCode %d !!!\n",current->bOpcode);
543 /* Try to save ... */
544 instr += count * size;
553 /*****************************************************************************
554 * IDirect3DExecuteBuffer::QueryInterface
556 * Well, a usual QueryInterface function. Don't know fur sure which
557 * interfaces it can Query.
560 * riid: The interface ID queried for
561 * obj: Address to return the interface pointer at
564 * D3D_OK in case of a success (S_OK? Think it's the same)
565 * OLE_E_ENUM_NOMORE if the interface wasn't found.
566 * (E_NOINTERFACE?? Don't know what I really need)
568 *****************************************************************************/
569 static HRESULT WINAPI
570 IDirect3DExecuteBufferImpl_QueryInterface(IDirect3DExecuteBuffer *iface,
574 TRACE("(%p)->(%s,%p)\n", iface, debugstr_guid(riid), obj);
578 if ( IsEqualGUID( &IID_IUnknown, riid ) ) {
579 IDirect3DExecuteBuffer_AddRef(iface);
581 TRACE(" Creating IUnknown interface at %p.\n", *obj);
584 if ( IsEqualGUID( &IID_IDirect3DExecuteBuffer, riid ) ) {
585 IDirect3DExecuteBuffer_AddRef(iface);
587 TRACE(" Creating IDirect3DExecuteBuffer interface %p\n", *obj);
590 FIXME("(%p): interface for IID %s NOT found!\n", iface, debugstr_guid(riid));
591 return E_NOINTERFACE;
595 /*****************************************************************************
596 * IDirect3DExecuteBuffer::AddRef
598 * A normal AddRef method, nothing special
603 *****************************************************************************/
605 IDirect3DExecuteBufferImpl_AddRef(IDirect3DExecuteBuffer *iface)
607 IDirect3DExecuteBufferImpl *This = (IDirect3DExecuteBufferImpl *)iface;
608 ULONG ref = InterlockedIncrement(&This->ref);
610 FIXME("(%p)->()incrementing from %u.\n", This, ref - 1);
615 /*****************************************************************************
616 * IDirect3DExecuteBuffer::Release
618 * A normal Release method, nothing special
623 *****************************************************************************/
625 IDirect3DExecuteBufferImpl_Release(IDirect3DExecuteBuffer *iface)
627 IDirect3DExecuteBufferImpl *This = (IDirect3DExecuteBufferImpl *)iface;
628 ULONG ref = InterlockedDecrement(&This->ref);
630 TRACE("(%p)->()decrementing from %u.\n", This, ref + 1);
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
655 IDirect3DExecuteBufferImpl_Initialize(IDirect3DExecuteBuffer *iface,
656 IDirect3DDevice *lpDirect3DDevice,
657 D3DEXECUTEBUFFERDESC *lpDesc)
659 IDirect3DExecuteBufferImpl *This = (IDirect3DExecuteBufferImpl *)iface;
660 TRACE("(%p)->(%p,%p) no-op....\n", This, lpDirect3DDevice, lpDesc);
664 /*****************************************************************************
665 * IDirect3DExecuteBuffer::Lock
667 * Locks the buffer, so the app can write into it.
670 * Desc: Pointer to return the buffer description. This Description contains
671 * a pointer to the buffer data.
674 * This implementation always returns D3D_OK
676 *****************************************************************************/
677 static HRESULT WINAPI
678 IDirect3DExecuteBufferImpl_Lock(IDirect3DExecuteBuffer *iface,
679 D3DEXECUTEBUFFERDESC *lpDesc)
681 IDirect3DExecuteBufferImpl *This = (IDirect3DExecuteBufferImpl *)iface;
683 TRACE("(%p)->(%p)\n", This, lpDesc);
685 dwSize = lpDesc->dwSize;
686 memcpy(lpDesc, &This->desc, dwSize);
688 if (TRACE_ON(d3d7)) {
689 TRACE(" Returning description :\n");
690 _dump_D3DEXECUTEBUFFERDESC(lpDesc);
695 /*****************************************************************************
696 * IDirect3DExecuteBuffer::Unlock
698 * Unlocks the buffer. We don't have anything to do here
701 * This implementation always returns D3D_OK
703 *****************************************************************************/
704 static HRESULT WINAPI
705 IDirect3DExecuteBufferImpl_Unlock(IDirect3DExecuteBuffer *iface)
707 IDirect3DExecuteBufferImpl *This = (IDirect3DExecuteBufferImpl *)iface;
708 TRACE("(%p)->() no-op...\n", This);
712 /*****************************************************************************
713 * IDirect3DExecuteBuffer::SetExecuteData
715 * Sets the execute data. This data is used to describe the buffer's content
718 * Data: Pointer to a D3DEXECUTEDATA structure containing the data to
723 * DDERR_OUTOFMEMORY if the vertex buffer allocation failed
725 *****************************************************************************/
726 static HRESULT WINAPI
727 IDirect3DExecuteBufferImpl_SetExecuteData(IDirect3DExecuteBuffer *iface,
728 D3DEXECUTEDATA *lpData)
730 IDirect3DExecuteBufferImpl *This = (IDirect3DExecuteBufferImpl *)iface;
732 TRACE("(%p)->(%p)\n", This, lpData);
734 memcpy(&This->data, lpData, lpData->dwSize);
736 /* Get the number of vertices in the execute buffer */
737 nbvert = This->data.dwVertexCount;
739 /* Prepares the transformed vertex buffer */
740 HeapFree(GetProcessHeap(), 0, This->vertex_data);
741 This->vertex_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nbvert * sizeof(D3DTLVERTEX));
743 if (TRACE_ON(d3d7)) {
744 _dump_executedata(lpData);
750 /*****************************************************************************
751 * IDirect3DExecuteBuffer::GetExecuteData
753 * Returns the data in the execute buffer
756 * Data: Pointer to a D3DEXECUTEDATA structure used to return data
761 *****************************************************************************/
762 static HRESULT WINAPI
763 IDirect3DExecuteBufferImpl_GetExecuteData(IDirect3DExecuteBuffer *iface,
764 D3DEXECUTEDATA *lpData)
766 IDirect3DExecuteBufferImpl *This = (IDirect3DExecuteBufferImpl *)iface;
768 TRACE("(%p)->(%p): stub!\n", This, lpData);
770 dwSize = lpData->dwSize;
771 memcpy(lpData, &This->data, dwSize);
773 if (TRACE_ON(d3d7)) {
774 TRACE("Returning data :\n");
775 _dump_executedata(lpData);
781 /*****************************************************************************
782 * IDirect3DExecuteBuffer::Validate
784 * DirectX 5 SDK: "The IDirect3DExecuteBuffer::Validate method is not
785 * currently implemented"
791 * DDERR_UNSUPPORTED, because it's not implemented in Windows.
793 *****************************************************************************/
794 static HRESULT WINAPI
795 IDirect3DExecuteBufferImpl_Validate(IDirect3DExecuteBuffer *iface,
797 LPD3DVALIDATECALLBACK Func,
801 IDirect3DExecuteBufferImpl *This = (IDirect3DExecuteBufferImpl *)iface;
802 TRACE("(%p)->(%p,%p,%p,%08x): Unimplemented!\n", This, Offset, Func, UserArg, Reserved);
803 return DDERR_UNSUPPORTED; /* Unchecked */
806 /*****************************************************************************
807 * IDirect3DExecuteBuffer::Optimize
809 * DirectX5 SDK: "The IDirect3DExecuteBuffer::Optimize method is not
810 * currently supported"
813 * Dummy: Seems to be an unused dummy ;)
816 * DDERR_UNSUPPORTED, because it's not implemented in Windows.
818 *****************************************************************************/
819 static HRESULT WINAPI
820 IDirect3DExecuteBufferImpl_Optimize(IDirect3DExecuteBuffer *iface,
823 IDirect3DExecuteBufferImpl *This = (IDirect3DExecuteBufferImpl *)iface;
824 TRACE("(%p)->(%08x): Unimplemented\n", This, Dummy);
825 return DDERR_UNSUPPORTED; /* Unchecked */
828 static const struct IDirect3DExecuteBufferVtbl d3d_execute_buffer_vtbl =
830 IDirect3DExecuteBufferImpl_QueryInterface,
831 IDirect3DExecuteBufferImpl_AddRef,
832 IDirect3DExecuteBufferImpl_Release,
833 IDirect3DExecuteBufferImpl_Initialize,
834 IDirect3DExecuteBufferImpl_Lock,
835 IDirect3DExecuteBufferImpl_Unlock,
836 IDirect3DExecuteBufferImpl_SetExecuteData,
837 IDirect3DExecuteBufferImpl_GetExecuteData,
838 IDirect3DExecuteBufferImpl_Validate,
839 IDirect3DExecuteBufferImpl_Optimize,
842 HRESULT d3d_execute_buffer_init(IDirect3DExecuteBufferImpl *execute_buffer,
843 IDirect3DDeviceImpl *device, D3DEXECUTEBUFFERDESC *desc)
845 execute_buffer->lpVtbl = &d3d_execute_buffer_vtbl;
846 execute_buffer->ref = 1;
847 execute_buffer->d3ddev = device;
849 /* Initializes memory */
850 memcpy(&execute_buffer->desc, desc, desc->dwSize);
852 /* No buffer given */
853 if (!(execute_buffer->desc.dwFlags & D3DDEB_LPDATA))
854 execute_buffer->desc.lpData = NULL;
856 /* No buffer size given */
857 if (!(execute_buffer->desc.dwFlags & D3DDEB_BUFSIZE))
858 execute_buffer->desc.dwBufferSize = 0;
860 /* Create buffer if asked */
861 if (!execute_buffer->desc.lpData && execute_buffer->desc.dwBufferSize)
863 execute_buffer->need_free = TRUE;
864 execute_buffer->desc.lpData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, execute_buffer->desc.dwBufferSize);
865 if (!execute_buffer->desc.lpData)
867 ERR("Failed to allocate execute buffer data.\n");
868 return DDERR_OUTOFMEMORY;
872 execute_buffer->desc.dwFlags |= D3DDEB_LPDATA;