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 HRESULT d3d_execute_buffer_execute(struct d3d_execute_buffer *buffer,
54 struct d3d_device *device, struct d3d_viewport *viewport)
56 DWORD vs = buffer->data.dwVertexOffset;
57 DWORD is = buffer->data.dwInstructionOffset;
58 char *instr = (char *)buffer->desc.lpData + is;
60 if (viewport->active_device != device)
62 WARN("Viewport %p active device is %p.\n",
63 viewport, viewport->active_device);
64 return DDERR_INVALIDPARAMS;
67 /* Activate the viewport */
68 viewport_activate(viewport, FALSE);
70 TRACE("ExecuteData :\n");
72 _dump_executedata(&(buffer->data));
75 LPD3DINSTRUCTION current = (LPD3DINSTRUCTION) instr;
79 count = current->wCount;
80 size = current->bSize;
81 instr += sizeof(D3DINSTRUCTION);
83 switch (current->bOpcode) {
85 WARN("POINT-s (%d)\n", count);
86 instr += count * size;
90 WARN("LINE-s (%d)\n", count);
91 instr += count * size;
94 case D3DOP_TRIANGLE: {
96 D3DTLVERTEX *tl_vx = buffer->vertex_data;
97 TRACE("TRIANGLE (%d)\n", count);
99 if (buffer->nb_indices < count * 3)
101 buffer->nb_indices = count * 3;
102 HeapFree(GetProcessHeap(), 0, buffer->indices);
103 buffer->indices = HeapAlloc(GetProcessHeap(), 0, sizeof(*buffer->indices) * buffer->nb_indices);
106 for (i = 0; i < count; i++) {
107 LPD3DTRIANGLE ci = (LPD3DTRIANGLE) instr;
108 TRACE(" v1: %d v2: %d v3: %d\n",ci->u1.v1, ci->u2.v2, ci->u3.v3);
113 if (ci->wFlags & D3DTRIFLAG_EDGEENABLE1)
114 TRACE("EDGEENABLE1 ");
115 if (ci->wFlags & D3DTRIFLAG_EDGEENABLE2)
116 TRACE("EDGEENABLE2 ");
117 if (ci->wFlags & D3DTRIFLAG_EDGEENABLE1)
118 TRACE("EDGEENABLE3 ");
120 if (ci->wFlags == D3DTRIFLAG_EVEN)
122 if (ci->wFlags == D3DTRIFLAG_ODD)
124 if (ci->wFlags == D3DTRIFLAG_START)
126 if ((ci->wFlags > 0) && (ci->wFlags < 30))
127 TRACE("STARTFLAT(%u) ", ci->wFlags);
130 buffer->indices[(i * 3) ] = ci->u1.v1;
131 buffer->indices[(i * 3) + 1] = ci->u2.v2;
132 buffer->indices[(i * 3) + 2] = ci->u3.v3;
135 IDirect3DDevice7_DrawIndexedPrimitive(&device->IDirect3DDevice7_iface,
136 D3DPT_TRIANGLELIST, D3DFVF_TLVERTEX, tl_vx, buffer->nb_vertices,
137 buffer->indices, count * 3, 0);
140 case D3DOP_MATRIXLOAD:
141 WARN("MATRIXLOAD-s (%d)\n", count);
142 instr += count * size;
145 case D3DOP_MATRIXMULTIPLY: {
147 TRACE("MATRIXMULTIPLY (%d)\n", count);
149 for (i = 0; i < count; ++i)
151 D3DMATRIXMULTIPLY *ci = (D3DMATRIXMULTIPLY *)instr;
152 D3DMATRIX *a, *b, *c;
154 a = ddraw_get_object(&device->handle_table, ci->hDestMatrix - 1, DDRAW_HANDLE_MATRIX);
155 b = ddraw_get_object(&device->handle_table, ci->hSrcMatrix1 - 1, DDRAW_HANDLE_MATRIX);
156 c = ddraw_get_object(&device->handle_table, ci->hSrcMatrix2 - 1, DDRAW_HANDLE_MATRIX);
160 ERR("Invalid matrix handle (a %#x -> %p, b %#x -> %p, c %#x -> %p).\n",
161 ci->hDestMatrix, a, ci->hSrcMatrix1, b, ci->hSrcMatrix2, c);
165 TRACE("dst %p, src1 %p, src2 %p.\n", a, b, c);
166 multiply_matrix(a, c, b);
173 case D3DOP_STATETRANSFORM: {
175 TRACE("STATETRANSFORM (%d)\n", count);
177 for (i = 0; i < count; ++i)
179 D3DSTATE *ci = (D3DSTATE *)instr;
182 m = ddraw_get_object(&device->handle_table, ci->u2.dwArg[0] - 1, DDRAW_HANDLE_MATRIX);
185 ERR("Invalid matrix handle %#x.\n", ci->u2.dwArg[0]);
189 if (ci->u1.dtstTransformStateType == D3DTRANSFORMSTATE_WORLD)
190 device->world = ci->u2.dwArg[0];
191 if (ci->u1.dtstTransformStateType == D3DTRANSFORMSTATE_VIEW)
192 device->view = ci->u2.dwArg[0];
193 if (ci->u1.dtstTransformStateType == D3DTRANSFORMSTATE_PROJECTION)
194 device->proj = ci->u2.dwArg[0];
195 IDirect3DDevice7_SetTransform(&device->IDirect3DDevice7_iface,
196 ci->u1.dtstTransformStateType, m);
203 case D3DOP_STATELIGHT: {
205 TRACE("STATELIGHT (%d)\n", count);
207 for (i = 0; i < count; i++) {
208 LPD3DSTATE ci = (LPD3DSTATE) instr;
210 TRACE("(%08x,%08x)\n", ci->u1.dlstLightStateType, ci->u2.dwArg[0]);
212 if (!ci->u1.dlstLightStateType || (ci->u1.dlstLightStateType > D3DLIGHTSTATE_COLORVERTEX))
213 ERR("Unexpected Light State Type %d\n", ci->u1.dlstLightStateType);
214 else if (ci->u1.dlstLightStateType == D3DLIGHTSTATE_MATERIAL /* 1 */)
216 struct d3d_material *m;
218 m = ddraw_get_object(&device->handle_table, ci->u2.dwArg[0] - 1, DDRAW_HANDLE_MATERIAL);
220 ERR("Invalid material handle %#x.\n", ci->u2.dwArg[0]);
222 material_activate(m);
224 else if (ci->u1.dlstLightStateType == D3DLIGHTSTATE_COLORMODEL /* 3 */)
226 switch (ci->u2.dwArg[0]) {
228 ERR("DDCOLOR_MONO should not happen!\n");
231 /* We are already in this mode */
234 ERR("Unknown color model!\n");
237 D3DRENDERSTATETYPE rs = 0;
238 switch (ci->u1.dlstLightStateType) {
240 case D3DLIGHTSTATE_AMBIENT: /* 2 */
241 rs = D3DRENDERSTATE_AMBIENT;
243 case D3DLIGHTSTATE_FOGMODE: /* 4 */
244 rs = D3DRENDERSTATE_FOGVERTEXMODE;
246 case D3DLIGHTSTATE_FOGSTART: /* 5 */
247 rs = D3DRENDERSTATE_FOGSTART;
249 case D3DLIGHTSTATE_FOGEND: /* 6 */
250 rs = D3DRENDERSTATE_FOGEND;
252 case D3DLIGHTSTATE_FOGDENSITY: /* 7 */
253 rs = D3DRENDERSTATE_FOGDENSITY;
255 case D3DLIGHTSTATE_COLORVERTEX: /* 8 */
256 rs = D3DRENDERSTATE_COLORVERTEX;
262 IDirect3DDevice7_SetRenderState(&device->IDirect3DDevice7_iface, rs, ci->u2.dwArg[0]);
269 case D3DOP_STATERENDER: {
271 IDirect3DDevice2 *d3d_device2 = &device->IDirect3DDevice2_iface;
272 TRACE("STATERENDER (%d)\n", count);
274 for (i = 0; i < count; i++) {
275 LPD3DSTATE ci = (LPD3DSTATE) instr;
277 IDirect3DDevice2_SetRenderState(d3d_device2, ci->u1.drstRenderStateType, ci->u2.dwArg[0]);
283 case D3DOP_PROCESSVERTICES:
285 /* TODO: Share code with IDirect3DVertexBuffer::ProcessVertices and / or
286 * IWineD3DDevice::ProcessVertices
289 D3DMATRIX view_mat, world_mat, proj_mat;
290 TRACE("PROCESSVERTICES (%d)\n", count);
292 /* Get the transform and world matrix */
293 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
294 wined3d_device_get_transform(device->wined3d_device,
295 D3DTRANSFORMSTATE_VIEW, (struct wined3d_matrix *)&view_mat);
296 wined3d_device_get_transform(device->wined3d_device,
297 D3DTRANSFORMSTATE_PROJECTION, (struct wined3d_matrix *)&proj_mat);
298 wined3d_device_get_transform(device->wined3d_device,
299 WINED3D_TS_WORLD_MATRIX(0), (struct wined3d_matrix *)&world_mat);
301 for (i = 0; i < count; i++) {
302 LPD3DPROCESSVERTICES ci = (LPD3DPROCESSVERTICES) instr;
304 TRACE(" Start : %d Dest : %d Count : %d\n",
305 ci->wStart, ci->wDest, ci->dwCount);
309 if (ci->dwFlags & D3DPROCESSVERTICES_COPY)
311 if (ci->dwFlags & D3DPROCESSVERTICES_NOCOLOR)
313 if (ci->dwFlags == D3DPROCESSVERTICES_OPMASK)
315 if (ci->dwFlags & D3DPROCESSVERTICES_TRANSFORM)
317 if (ci->dwFlags == D3DPROCESSVERTICES_TRANSFORMLIGHT)
318 TRACE("TRANSFORMLIGHT ");
319 if (ci->dwFlags & D3DPROCESSVERTICES_UPDATEEXTENTS)
320 TRACE("UPDATEEXTENTS ");
324 /* This is where doing Direct3D on top on OpenGL is quite difficult.
325 This method transforms a set of vertices using the CURRENT state
326 (lighting, projection, ...) but does not rasterize them.
327 They will only be put on screen later (with the POINT / LINE and
328 TRIANGLE op-codes). The problem is that you can have a triangle
329 with each point having been transformed using another state...
331 In this implementation, I will emulate only ONE thing : each
332 vertex can have its own "WORLD" transformation (this is used in the
333 TWIST.EXE demo of the 5.2 SDK). I suppose that all vertices of the
334 execute buffer use the same state.
336 If I find applications that change other states, I will try to do a
337 more 'fine-tuned' state emulation (but I may become quite tricky if
338 it changes a light position in the middle of a triangle).
340 In this case, a 'direct' approach (i.e. without using OpenGL, but
341 writing our own 3D rasterizer) would be easier. */
343 /* The current method (with the hypothesis that only the WORLD matrix
344 will change between two points) is like this :
345 - I transform 'manually' all the vertices with the current WORLD
346 matrix and store them in the vertex buffer
347 - during the rasterization phase, the WORLD matrix will be set to
348 the Identity matrix */
350 /* Enough for the moment */
351 if (ci->dwFlags == D3DPROCESSVERTICES_TRANSFORMLIGHT) {
353 D3DVERTEX *src = ((D3DVERTEX *)((char *)buffer->desc.lpData + vs)) + ci->wStart;
354 D3DTLVERTEX *dst = ((D3DTLVERTEX *)buffer->vertex_data) + ci->wDest;
355 D3DVIEWPORT *Viewport = &viewport->viewports.vp1;
360 TRACE(" Projection Matrix : (%p)\n", &proj_mat);
361 dump_D3DMATRIX(&proj_mat);
362 TRACE(" View Matrix : (%p)\n", &view_mat);
363 dump_D3DMATRIX(&view_mat);
364 TRACE(" World Matrix : (%p)\n", &world_mat);
365 dump_D3DMATRIX(&world_mat);
368 multiply_matrix(&mat,&view_mat,&world_mat);
369 multiply_matrix(&mat,&proj_mat,&mat);
371 for (nb = 0; nb < ci->dwCount; nb++) {
372 /* No lighting yet */
373 dst->u5.color = 0xFFFFFFFF; /* Opaque white */
374 dst->u6.specular = 0xFF000000; /* No specular and no fog factor */
376 dst->u7.tu = src->u7.tu;
377 dst->u8.tv = src->u8.tv;
379 /* Now, the matrix multiplication */
380 dst->u1.sx = (src->u1.x * mat._11) + (src->u2.y * mat._21) + (src->u3.z * mat._31) + (1.0 * mat._41);
381 dst->u2.sy = (src->u1.x * mat._12) + (src->u2.y * mat._22) + (src->u3.z * mat._32) + (1.0 * mat._42);
382 dst->u3.sz = (src->u1.x * mat._13) + (src->u2.y * mat._23) + (src->u3.z * mat._33) + (1.0 * mat._43);
383 dst->u4.rhw = (src->u1.x * mat._14) + (src->u2.y * mat._24) + (src->u3.z * mat._34) + (1.0 * mat._44);
385 dst->u1.sx = dst->u1.sx / dst->u4.rhw * Viewport->dvScaleX
386 + Viewport->dwX + Viewport->dwWidth / 2;
387 dst->u2.sy = (-dst->u2.sy) / dst->u4.rhw * Viewport->dvScaleY
388 + Viewport->dwY + Viewport->dwHeight / 2;
389 dst->u3.sz /= dst->u4.rhw;
390 dst->u4.rhw = 1 / dst->u4.rhw;
396 } else if (ci->dwFlags == D3DPROCESSVERTICES_TRANSFORM) {
398 D3DLVERTEX *src = ((D3DLVERTEX *)((char *)buffer->desc.lpData + vs)) + ci->wStart;
399 D3DTLVERTEX *dst = ((D3DTLVERTEX *)buffer->vertex_data) + ci->wDest;
400 D3DVIEWPORT *Viewport = &viewport->viewports.vp1;
405 TRACE(" Projection Matrix : (%p)\n", &proj_mat);
406 dump_D3DMATRIX(&proj_mat);
407 TRACE(" View Matrix : (%p)\n",&view_mat);
408 dump_D3DMATRIX(&view_mat);
409 TRACE(" World Matrix : (%p)\n", &world_mat);
410 dump_D3DMATRIX(&world_mat);
413 multiply_matrix(&mat,&view_mat,&world_mat);
414 multiply_matrix(&mat,&proj_mat,&mat);
416 for (nb = 0; nb < ci->dwCount; nb++) {
417 dst->u5.color = src->u4.color;
418 dst->u6.specular = src->u5.specular;
419 dst->u7.tu = src->u6.tu;
420 dst->u8.tv = src->u7.tv;
422 /* Now, the matrix multiplication */
423 dst->u1.sx = (src->u1.x * mat._11) + (src->u2.y * mat._21) + (src->u3.z * mat._31) + (1.0 * mat._41);
424 dst->u2.sy = (src->u1.x * mat._12) + (src->u2.y * mat._22) + (src->u3.z * mat._32) + (1.0 * mat._42);
425 dst->u3.sz = (src->u1.x * mat._13) + (src->u2.y * mat._23) + (src->u3.z * mat._33) + (1.0 * mat._43);
426 dst->u4.rhw = (src->u1.x * mat._14) + (src->u2.y * mat._24) + (src->u3.z * mat._34) + (1.0 * mat._44);
428 dst->u1.sx = dst->u1.sx / dst->u4.rhw * Viewport->dvScaleX
429 + Viewport->dwX + Viewport->dwWidth / 2;
430 dst->u2.sy = (-dst->u2.sy) / dst->u4.rhw * Viewport->dvScaleY
431 + Viewport->dwY + Viewport->dwHeight / 2;
433 dst->u3.sz /= dst->u4.rhw;
434 dst->u4.rhw = 1 / dst->u4.rhw;
440 else if (ci->dwFlags == D3DPROCESSVERTICES_COPY)
442 D3DTLVERTEX *src = ((D3DTLVERTEX *)((char *)buffer->desc.lpData + vs)) + ci->wStart;
443 D3DTLVERTEX *dst = ((D3DTLVERTEX *)buffer->vertex_data) + ci->wDest;
445 memcpy(dst, src, ci->dwCount * sizeof(D3DTLVERTEX));
447 ERR("Unhandled vertex processing flag %#x.\n", ci->dwFlags);
454 case D3DOP_TEXTURELOAD: {
455 WARN("TEXTURELOAD-s (%d)\n", count);
457 instr += count * size;
461 TRACE("EXIT (%d)\n", count);
462 /* We did this instruction */
468 case D3DOP_BRANCHFORWARD: {
470 TRACE("BRANCHFORWARD (%d)\n", count);
472 for (i = 0; i < count; i++) {
473 LPD3DBRANCH ci = (LPD3DBRANCH) instr;
475 if ((buffer->data.dsStatus.dwStatus & ci->dwMask) == ci->dwValue)
479 TRACE(" Branch to %d\n", ci->dwOffset);
481 instr = (char*)current + ci->dwOffset;
487 TRACE(" Branch to %d\n", ci->dwOffset);
489 instr = (char*)current + ci->dwOffset;
500 WARN("SPAN-s (%d)\n", count);
502 instr += count * size;
505 case D3DOP_SETSTATUS: {
507 TRACE("SETSTATUS (%d)\n", count);
509 for (i = 0; i < count; i++) {
510 LPD3DSTATUS ci = (LPD3DSTATUS) instr;
512 buffer->data.dsStatus = *ci;
519 ERR("Unhandled OpCode %d !!!\n",current->bOpcode);
520 /* Try to save ... */
521 instr += count * size;
530 static inline struct d3d_execute_buffer *impl_from_IDirect3DExecuteBuffer(IDirect3DExecuteBuffer *iface)
532 return CONTAINING_RECORD(iface, struct d3d_execute_buffer, IDirect3DExecuteBuffer_iface);
535 /*****************************************************************************
536 * IDirect3DExecuteBuffer::QueryInterface
538 * Well, a usual QueryInterface function. Don't know fur sure which
539 * interfaces it can Query.
542 * riid: The interface ID queried for
543 * obj: Address to return the interface pointer at
546 * D3D_OK in case of a success (S_OK? Think it's the same)
547 * OLE_E_ENUM_NOMORE if the interface wasn't found.
548 * (E_NOINTERFACE?? Don't know what I really need)
550 *****************************************************************************/
551 static HRESULT WINAPI d3d_execute_buffer_QueryInterface(IDirect3DExecuteBuffer *iface, REFIID riid, void **obj)
553 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), obj);
557 if ( IsEqualGUID( &IID_IUnknown, riid ) ) {
558 IDirect3DExecuteBuffer_AddRef(iface);
560 TRACE(" Creating IUnknown interface at %p.\n", *obj);
563 if ( IsEqualGUID( &IID_IDirect3DExecuteBuffer, riid ) ) {
564 IDirect3DExecuteBuffer_AddRef(iface);
566 TRACE(" Creating IDirect3DExecuteBuffer interface %p\n", *obj);
569 FIXME("(%p): interface for IID %s NOT found!\n", iface, debugstr_guid(riid));
570 return E_NOINTERFACE;
574 /*****************************************************************************
575 * IDirect3DExecuteBuffer::AddRef
577 * A normal AddRef method, nothing special
582 *****************************************************************************/
583 static ULONG WINAPI d3d_execute_buffer_AddRef(IDirect3DExecuteBuffer *iface)
585 struct d3d_execute_buffer *buffer = impl_from_IDirect3DExecuteBuffer(iface);
586 ULONG ref = InterlockedIncrement(&buffer->ref);
588 TRACE("%p increasing refcount to %u.\n", buffer, ref);
593 /*****************************************************************************
594 * IDirect3DExecuteBuffer::Release
596 * A normal Release method, nothing special
601 *****************************************************************************/
602 static ULONG WINAPI d3d_execute_buffer_Release(IDirect3DExecuteBuffer *iface)
604 struct d3d_execute_buffer *buffer = impl_from_IDirect3DExecuteBuffer(iface);
605 ULONG ref = InterlockedDecrement(&buffer->ref);
607 TRACE("%p decreasing refcount to %u.\n", buffer, ref);
611 if (buffer->need_free)
612 HeapFree(GetProcessHeap(), 0, buffer->desc.lpData);
613 HeapFree(GetProcessHeap(), 0, buffer->vertex_data);
614 HeapFree(GetProcessHeap(), 0, buffer->indices);
615 HeapFree(GetProcessHeap(), 0, buffer);
621 /*****************************************************************************
622 * IDirect3DExecuteBuffer::Initialize
624 * Initializes the Execute Buffer. This method exists for COM compliance
625 * Nothing to do here.
630 *****************************************************************************/
631 static HRESULT WINAPI d3d_execute_buffer_Initialize(IDirect3DExecuteBuffer *iface,
632 IDirect3DDevice *device, D3DEXECUTEBUFFERDESC *desc)
634 TRACE("iface %p, device %p, desc %p.\n", iface, device, desc);
639 /*****************************************************************************
640 * IDirect3DExecuteBuffer::Lock
642 * Locks the buffer, so the app can write into it.
645 * Desc: Pointer to return the buffer description. This Description contains
646 * a pointer to the buffer data.
649 * This implementation always returns D3D_OK
651 *****************************************************************************/
652 static HRESULT WINAPI d3d_execute_buffer_Lock(IDirect3DExecuteBuffer *iface, D3DEXECUTEBUFFERDESC *desc)
654 struct d3d_execute_buffer *buffer = impl_from_IDirect3DExecuteBuffer(iface);
657 TRACE("iface %p, desc %p.\n", iface, desc);
659 dwSize = desc->dwSize;
660 memcpy(desc, &buffer->desc, dwSize);
664 TRACE(" Returning description :\n");
665 _dump_D3DEXECUTEBUFFERDESC(desc);
670 /*****************************************************************************
671 * IDirect3DExecuteBuffer::Unlock
673 * Unlocks the buffer. We don't have anything to do here
676 * This implementation always returns D3D_OK
678 *****************************************************************************/
679 static HRESULT WINAPI d3d_execute_buffer_Unlock(IDirect3DExecuteBuffer *iface)
681 TRACE("iface %p.\n", iface);
686 /*****************************************************************************
687 * IDirect3DExecuteBuffer::SetExecuteData
689 * Sets the execute data. This data is used to describe the buffer's content
692 * Data: Pointer to a D3DEXECUTEDATA structure containing the data to
697 * DDERR_OUTOFMEMORY if the vertex buffer allocation failed
699 *****************************************************************************/
700 static HRESULT WINAPI d3d_execute_buffer_SetExecuteData(IDirect3DExecuteBuffer *iface, D3DEXECUTEDATA *data)
702 struct d3d_execute_buffer *buffer = impl_from_IDirect3DExecuteBuffer(iface);
705 TRACE("iface %p, data %p.\n", iface, data);
707 memcpy(&buffer->data, data, data->dwSize);
709 /* Get the number of vertices in the execute buffer */
710 nbvert = buffer->data.dwVertexCount;
712 /* Prepares the transformed vertex buffer */
713 HeapFree(GetProcessHeap(), 0, buffer->vertex_data);
714 buffer->vertex_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nbvert * sizeof(D3DTLVERTEX));
715 buffer->nb_vertices = nbvert;
718 _dump_executedata(data);
723 /*****************************************************************************
724 * IDirect3DExecuteBuffer::GetExecuteData
726 * Returns the data in the execute buffer
729 * Data: Pointer to a D3DEXECUTEDATA structure used to return data
734 *****************************************************************************/
735 static HRESULT WINAPI d3d_execute_buffer_GetExecuteData(IDirect3DExecuteBuffer *iface, D3DEXECUTEDATA *data)
737 struct d3d_execute_buffer *buffer = impl_from_IDirect3DExecuteBuffer(iface);
740 TRACE("iface %p, data %p.\n", iface, data);
742 dwSize = data->dwSize;
743 memcpy(data, &buffer->data, dwSize);
747 TRACE("Returning data :\n");
748 _dump_executedata(data);
754 /*****************************************************************************
755 * IDirect3DExecuteBuffer::Validate
757 * DirectX 5 SDK: "The IDirect3DExecuteBuffer::Validate method is not
758 * currently implemented"
764 * DDERR_UNSUPPORTED, because it's not implemented in Windows.
766 *****************************************************************************/
767 static HRESULT WINAPI d3d_execute_buffer_Validate(IDirect3DExecuteBuffer *iface,
768 DWORD *offset, LPD3DVALIDATECALLBACK callback, void *context, DWORD reserved)
770 TRACE("iface %p, offset %p, callback %p, context %p, reserved %#x.\n",
771 iface, offset, callback, context, reserved);
773 WARN("Not implemented.\n");
775 return DDERR_UNSUPPORTED; /* Unchecked */
778 /*****************************************************************************
779 * IDirect3DExecuteBuffer::Optimize
781 * DirectX5 SDK: "The IDirect3DExecuteBuffer::Optimize method is not
782 * currently supported"
785 * Dummy: Seems to be an unused dummy ;)
788 * DDERR_UNSUPPORTED, because it's not implemented in Windows.
790 *****************************************************************************/
791 static HRESULT WINAPI d3d_execute_buffer_Optimize(IDirect3DExecuteBuffer *iface, DWORD reserved)
793 TRACE("iface %p, reserved %#x.\n", iface, reserved);
795 WARN("Not implemented.\n");
797 return DDERR_UNSUPPORTED; /* Unchecked */
800 static const struct IDirect3DExecuteBufferVtbl d3d_execute_buffer_vtbl =
802 d3d_execute_buffer_QueryInterface,
803 d3d_execute_buffer_AddRef,
804 d3d_execute_buffer_Release,
805 d3d_execute_buffer_Initialize,
806 d3d_execute_buffer_Lock,
807 d3d_execute_buffer_Unlock,
808 d3d_execute_buffer_SetExecuteData,
809 d3d_execute_buffer_GetExecuteData,
810 d3d_execute_buffer_Validate,
811 d3d_execute_buffer_Optimize,
814 HRESULT d3d_execute_buffer_init(struct d3d_execute_buffer *execute_buffer,
815 struct d3d_device *device, D3DEXECUTEBUFFERDESC *desc)
817 execute_buffer->IDirect3DExecuteBuffer_iface.lpVtbl = &d3d_execute_buffer_vtbl;
818 execute_buffer->ref = 1;
819 execute_buffer->d3ddev = device;
821 /* Initializes memory */
822 memcpy(&execute_buffer->desc, desc, desc->dwSize);
824 /* No buffer given */
825 if (!(execute_buffer->desc.dwFlags & D3DDEB_LPDATA))
826 execute_buffer->desc.lpData = NULL;
828 /* No buffer size given */
829 if (!(execute_buffer->desc.dwFlags & D3DDEB_BUFSIZE))
830 execute_buffer->desc.dwBufferSize = 0;
832 /* Create buffer if asked */
833 if (!execute_buffer->desc.lpData && execute_buffer->desc.dwBufferSize)
835 execute_buffer->need_free = TRUE;
836 execute_buffer->desc.lpData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, execute_buffer->desc.dwBufferSize);
837 if (!execute_buffer->desc.lpData)
839 ERR("Failed to allocate execute buffer data.\n");
840 return DDERR_OUTOFMEMORY;
844 execute_buffer->desc.dwFlags |= D3DDEB_LPDATA;
849 struct d3d_execute_buffer *unsafe_impl_from_IDirect3DExecuteBuffer(IDirect3DExecuteBuffer *iface)
853 assert(iface->lpVtbl == &d3d_execute_buffer_vtbl);
855 return impl_from_IDirect3DExecuteBuffer(iface);