1999-01-03 18:00:19 +01:00
|
|
|
/* Direct3D ExecuteBuffer
|
2004-08-02 20:26:53 +02:00
|
|
|
* Copyright (c) 1998-2004 Lionel ULMER
|
|
|
|
* Copyright (c) 2002-2004 Christian Costa
|
2008-10-18 19:19:45 +02:00
|
|
|
* Copyright (c) 2006 Stefan Dösinger
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
2006-06-09 19:36:12 +02:00
|
|
|
* This file contains the implementation of IDirect3DExecuteBuffer.
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-03-10 00:29:33 +01:00
|
|
|
*/
|
1999-01-03 18:00:19 +01:00
|
|
|
|
|
|
|
#include "config.h"
|
2006-06-09 19:36:12 +02:00
|
|
|
#include "wine/port.h"
|
2001-10-14 18:18:52 +02:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
#include "ddraw_private.h"
|
1999-01-03 18:00:19 +01:00
|
|
|
|
2010-08-19 18:57:50 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
|
1999-01-03 18:00:19 +01:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* _dump_executedata
|
|
|
|
* _dump_D3DEXECUTEBUFFERDESC
|
|
|
|
*
|
|
|
|
* Debug functions which write the executebuffer data to the console
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2007-04-21 23:16:34 +02:00
|
|
|
static void _dump_executedata(const D3DEXECUTEDATA *lpData) {
|
2007-12-04 23:27:33 +01:00
|
|
|
TRACE("dwSize : %d\n", lpData->dwSize);
|
|
|
|
TRACE("Vertex Offset : %d Count : %d\n", lpData->dwVertexOffset, lpData->dwVertexCount);
|
|
|
|
TRACE("Instruction Offset : %d Length : %d\n", lpData->dwInstructionOffset, lpData->dwInstructionLength);
|
|
|
|
TRACE("HVertex Offset : %d\n", lpData->dwHVertexOffset);
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2007-04-21 23:16:34 +02:00
|
|
|
static void _dump_D3DEXECUTEBUFFERDESC(const D3DEXECUTEBUFFERDESC *lpDesc) {
|
2007-12-04 23:27:33 +01:00
|
|
|
TRACE("dwSize : %d\n", lpDesc->dwSize);
|
|
|
|
TRACE("dwFlags : %x\n", lpDesc->dwFlags);
|
|
|
|
TRACE("dwCaps : %x\n", lpDesc->dwCaps);
|
|
|
|
TRACE("dwBufferSize : %d\n", lpDesc->dwBufferSize);
|
|
|
|
TRACE("lpData : %p\n", lpDesc->lpData);
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DExecuteBufferImpl_Execute
|
|
|
|
*
|
|
|
|
* The main functionality of the execute buffer
|
|
|
|
* It transforms the vertices if necessary, and calls IDirect3DDevice7
|
|
|
|
* for drawing the vertices. It is called from
|
|
|
|
* IDirect3DDevice::Execute
|
|
|
|
*
|
2006-06-23 18:18:02 +02:00
|
|
|
* TODO: Perhaps some comments about the various opcodes wouldn't hurt
|
2006-06-09 19:36:12 +02:00
|
|
|
*
|
|
|
|
* Don't declare this static, as it's called from device.c,
|
|
|
|
* IDirect3DDevice::Execute
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* Device: 3D Device associated to use for drawing
|
|
|
|
* Viewport: Viewport for this operation
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2011-04-19 00:08:00 +02:00
|
|
|
HRESULT d3d_execute_buffer_execute(IDirect3DExecuteBufferImpl *This,
|
|
|
|
IDirect3DDeviceImpl *lpDevice, IDirect3DViewportImpl *lpViewport)
|
2002-11-24 23:14:40 +01:00
|
|
|
{
|
|
|
|
/* DWORD bs = This->desc.dwBufferSize; */
|
|
|
|
DWORD vs = This->data.dwVertexOffset;
|
|
|
|
/* DWORD vc = This->data.dwVertexCount; */
|
|
|
|
DWORD is = This->data.dwInstructionOffset;
|
|
|
|
/* DWORD il = This->data.dwInstructionLength; */
|
2003-01-23 22:32:35 +01:00
|
|
|
|
|
|
|
char *instr = (char *)This->desc.lpData + is;
|
2002-11-21 22:04:16 +01:00
|
|
|
|
2011-04-19 00:08:00 +02:00
|
|
|
if (lpViewport->active_device != lpDevice)
|
|
|
|
{
|
|
|
|
WARN("Viewport %p active device is %p.\n",
|
|
|
|
lpViewport, lpViewport->active_device);
|
|
|
|
return DDERR_INVALIDPARAMS;
|
|
|
|
}
|
2002-11-21 22:04:16 +01:00
|
|
|
|
|
|
|
/* Activate the viewport */
|
2010-08-17 19:03:25 +02:00
|
|
|
viewport_activate(lpViewport, FALSE);
|
2002-11-21 22:04:16 +01:00
|
|
|
|
2005-11-10 13:14:56 +01:00
|
|
|
TRACE("ExecuteData :\n");
|
2010-08-19 18:57:50 +02:00
|
|
|
if (TRACE_ON(ddraw))
|
2002-11-24 23:14:40 +01:00
|
|
|
_dump_executedata(&(This->data));
|
2002-11-21 22:04:16 +01:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
LPD3DINSTRUCTION current = (LPD3DINSTRUCTION) instr;
|
|
|
|
BYTE size;
|
|
|
|
WORD count;
|
|
|
|
|
|
|
|
count = current->wCount;
|
|
|
|
size = current->bSize;
|
|
|
|
instr += sizeof(D3DINSTRUCTION);
|
|
|
|
|
|
|
|
switch (current->bOpcode) {
|
|
|
|
case D3DOP_POINT: {
|
2003-01-02 20:59:49 +01:00
|
|
|
WARN("POINT-s (%d)\n", count);
|
2002-11-21 22:04:16 +01:00
|
|
|
instr += count * size;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case D3DOP_LINE: {
|
2003-01-02 20:59:49 +01:00
|
|
|
WARN("LINE-s (%d)\n", count);
|
2002-11-21 22:04:16 +01:00
|
|
|
instr += count * size;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case D3DOP_TRIANGLE: {
|
|
|
|
int i;
|
2009-01-13 23:31:09 +01:00
|
|
|
D3DTLVERTEX *tl_vx = This->vertex_data;
|
2002-11-21 22:04:16 +01:00
|
|
|
TRACE("TRIANGLE (%d)\n", count);
|
|
|
|
|
2003-05-20 19:49:40 +02:00
|
|
|
if (count*3>This->nb_indices) {
|
|
|
|
This->nb_indices = count * 3;
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree(GetProcessHeap(),0,This->indices);
|
2003-05-20 19:49:40 +02:00
|
|
|
This->indices = HeapAlloc(GetProcessHeap(),0,sizeof(WORD)*This->nb_indices);
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
2003-05-20 19:49:40 +02:00
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
LPD3DTRIANGLE ci = (LPD3DTRIANGLE) instr;
|
2010-08-19 18:57:50 +02:00
|
|
|
TRACE(" v1: %d v2: %d v3: %d\n",ci->u1.v1, ci->u2.v2, ci->u3.v3);
|
|
|
|
TRACE(" Flags : ");
|
|
|
|
if (TRACE_ON(ddraw))
|
|
|
|
{
|
|
|
|
/* Wireframe */
|
|
|
|
if (ci->wFlags & D3DTRIFLAG_EDGEENABLE1)
|
|
|
|
TRACE("EDGEENABLE1 ");
|
|
|
|
if (ci->wFlags & D3DTRIFLAG_EDGEENABLE2)
|
|
|
|
TRACE("EDGEENABLE2 ");
|
|
|
|
if (ci->wFlags & D3DTRIFLAG_EDGEENABLE1)
|
|
|
|
TRACE("EDGEENABLE3 ");
|
|
|
|
/* Strips / Fans */
|
|
|
|
if (ci->wFlags == D3DTRIFLAG_EVEN)
|
|
|
|
TRACE("EVEN ");
|
|
|
|
if (ci->wFlags == D3DTRIFLAG_ODD)
|
|
|
|
TRACE("ODD ");
|
|
|
|
if (ci->wFlags == D3DTRIFLAG_START)
|
|
|
|
TRACE("START ");
|
|
|
|
if ((ci->wFlags > 0) && (ci->wFlags < 30))
|
|
|
|
TRACE("STARTFLAT(%u) ", ci->wFlags);
|
|
|
|
TRACE("\n");
|
|
|
|
}
|
2003-09-15 21:59:19 +02:00
|
|
|
This->indices[(i * 3) ] = ci->u1.v1;
|
|
|
|
This->indices[(i * 3) + 1] = ci->u2.v2;
|
|
|
|
This->indices[(i * 3) + 2] = ci->u3.v3;
|
2003-05-20 19:49:40 +02:00
|
|
|
instr += size;
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
2006-06-09 19:36:12 +02:00
|
|
|
/* IDirect3DDevices have color keying always enabled -
|
|
|
|
* enable it before drawing. This overwrites any ALPHA*
|
2011-05-16 23:01:21 +02:00
|
|
|
* render state. */
|
2011-05-16 23:01:22 +02:00
|
|
|
wined3d_device_set_render_state(lpDevice->wined3d_device, WINED3DRS_COLORKEYENABLE, 1);
|
2011-10-17 15:58:51 +02:00
|
|
|
IDirect3DDevice7_DrawIndexedPrimitive(&lpDevice->IDirect3DDevice7_iface,
|
2009-01-21 09:56:13 +01:00
|
|
|
D3DPT_TRIANGLELIST, D3DFVF_TLVERTEX, tl_vx, 0, This->indices, count * 3, 0);
|
2002-11-21 22:04:16 +01:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case D3DOP_MATRIXLOAD:
|
2003-01-02 20:59:49 +01:00
|
|
|
WARN("MATRIXLOAD-s (%d)\n", count);
|
2002-11-21 22:04:16 +01:00
|
|
|
instr += count * size;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3DOP_MATRIXMULTIPLY: {
|
|
|
|
int i;
|
|
|
|
TRACE("MATRIXMULTIPLY (%d)\n", count);
|
|
|
|
|
2010-07-29 12:56:58 +02:00
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
{
|
|
|
|
D3DMATRIXMULTIPLY *ci = (D3DMATRIXMULTIPLY *)instr;
|
|
|
|
D3DMATRIX *a, *b, *c;
|
|
|
|
|
|
|
|
a = ddraw_get_object(&lpDevice->handle_table, ci->hDestMatrix - 1, DDRAW_HANDLE_MATRIX);
|
|
|
|
b = ddraw_get_object(&lpDevice->handle_table, ci->hSrcMatrix1 - 1, DDRAW_HANDLE_MATRIX);
|
|
|
|
c = ddraw_get_object(&lpDevice->handle_table, ci->hSrcMatrix2 - 1, DDRAW_HANDLE_MATRIX);
|
|
|
|
|
|
|
|
if (!a || !b || !c)
|
|
|
|
{
|
|
|
|
ERR("Invalid matrix handle (a %#x -> %p, b %#x -> %p, c %#x -> %p).\n",
|
|
|
|
ci->hDestMatrix, a, ci->hSrcMatrix1, b, ci->hSrcMatrix2, c);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE("dst %p, src1 %p, src2 %p.\n", a, b, c);
|
|
|
|
multiply_matrix(a, c, b);
|
2006-06-29 14:15:03 +02:00
|
|
|
}
|
2003-05-20 19:49:40 +02:00
|
|
|
|
2006-06-29 14:15:03 +02:00
|
|
|
instr += size;
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case D3DOP_STATETRANSFORM: {
|
|
|
|
int i;
|
|
|
|
TRACE("STATETRANSFORM (%d)\n", count);
|
|
|
|
|
2010-07-29 12:56:58 +02:00
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
{
|
|
|
|
D3DSTATE *ci = (D3DSTATE *)instr;
|
|
|
|
D3DMATRIX *m;
|
|
|
|
|
|
|
|
m = ddraw_get_object(&lpDevice->handle_table, ci->u2.dwArg[0] - 1, DDRAW_HANDLE_MATRIX);
|
|
|
|
if (!m)
|
|
|
|
{
|
|
|
|
ERR("Invalid matrix handle %#x.\n", ci->u2.dwArg[0]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (ci->u1.dtstTransformStateType == D3DTRANSFORMSTATE_WORLD)
|
2007-07-01 23:28:21 +02:00
|
|
|
lpDevice->world = ci->u2.dwArg[0];
|
2010-07-29 12:56:58 +02:00
|
|
|
if (ci->u1.dtstTransformStateType == D3DTRANSFORMSTATE_VIEW)
|
2007-07-01 23:28:21 +02:00
|
|
|
lpDevice->view = ci->u2.dwArg[0];
|
2010-07-29 12:56:58 +02:00
|
|
|
if (ci->u1.dtstTransformStateType == D3DTRANSFORMSTATE_PROJECTION)
|
2007-07-01 23:28:21 +02:00
|
|
|
lpDevice->proj = ci->u2.dwArg[0];
|
2011-10-17 15:58:51 +02:00
|
|
|
IDirect3DDevice7_SetTransform(&lpDevice->IDirect3DDevice7_iface,
|
2010-07-29 12:56:58 +02:00
|
|
|
ci->u1.dtstTransformStateType, m);
|
2006-06-29 14:15:03 +02:00
|
|
|
}
|
2010-07-29 12:56:58 +02:00
|
|
|
|
|
|
|
instr += size;
|
|
|
|
}
|
2002-11-21 22:04:16 +01:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case D3DOP_STATELIGHT: {
|
2008-05-07 01:06:06 +02:00
|
|
|
int i;
|
2002-11-21 22:04:16 +01:00
|
|
|
TRACE("STATELIGHT (%d)\n", count);
|
2008-05-07 01:06:06 +02:00
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
LPD3DSTATE ci = (LPD3DSTATE) instr;
|
2003-05-20 19:49:40 +02:00
|
|
|
|
2008-05-07 01:06:06 +02:00
|
|
|
TRACE("(%08x,%08x)\n", ci->u1.dlstLightStateType, ci->u2.dwArg[0]);
|
2003-05-20 19:49:40 +02:00
|
|
|
|
2009-06-19 19:01:21 +02:00
|
|
|
if (!ci->u1.dlstLightStateType || (ci->u1.dlstLightStateType > D3DLIGHTSTATE_COLORVERTEX))
|
2009-12-23 08:46:19 +01:00
|
|
|
ERR("Unexpected Light State Type %d\n", ci->u1.dlstLightStateType);
|
2010-07-29 12:56:57 +02:00
|
|
|
else if (ci->u1.dlstLightStateType == D3DLIGHTSTATE_MATERIAL /* 1 */)
|
|
|
|
{
|
|
|
|
IDirect3DMaterialImpl *m;
|
2008-05-07 01:06:06 +02:00
|
|
|
|
2010-07-29 12:56:57 +02:00
|
|
|
m = ddraw_get_object(&lpDevice->handle_table, ci->u2.dwArg[0] - 1, DDRAW_HANDLE_MATERIAL);
|
|
|
|
if (!m)
|
|
|
|
ERR("Invalid material handle %#x.\n", ci->u2.dwArg[0]);
|
|
|
|
else
|
2010-08-17 19:03:24 +02:00
|
|
|
material_activate(m);
|
2010-07-29 12:56:57 +02:00
|
|
|
}
|
|
|
|
else if (ci->u1.dlstLightStateType == D3DLIGHTSTATE_COLORMODEL /* 3 */)
|
|
|
|
{
|
2003-05-20 19:49:40 +02:00
|
|
|
switch (ci->u2.dwArg[0]) {
|
|
|
|
case D3DCOLOR_MONO:
|
2008-05-07 01:06:06 +02:00
|
|
|
ERR("DDCOLOR_MONO should not happen!\n");
|
|
|
|
break;
|
2003-05-20 19:49:40 +02:00
|
|
|
case D3DCOLOR_RGB:
|
2008-05-07 01:06:06 +02:00
|
|
|
/* We are already in this mode */
|
|
|
|
break;
|
2003-05-20 19:49:40 +02:00
|
|
|
default:
|
2008-05-07 01:06:06 +02:00
|
|
|
ERR("Unknown color model!\n");
|
2003-05-20 19:49:40 +02:00
|
|
|
}
|
|
|
|
} else {
|
2008-05-07 01:06:06 +02:00
|
|
|
D3DRENDERSTATETYPE rs = 0;
|
|
|
|
switch (ci->u1.dlstLightStateType) {
|
2003-05-20 19:49:40 +02:00
|
|
|
|
2008-05-07 01:06:06 +02:00
|
|
|
case D3DLIGHTSTATE_AMBIENT: /* 2 */
|
2003-05-20 19:49:40 +02:00
|
|
|
rs = D3DRENDERSTATE_AMBIENT;
|
2008-05-07 01:06:06 +02:00
|
|
|
break;
|
2003-05-20 19:49:40 +02:00
|
|
|
case D3DLIGHTSTATE_FOGMODE: /* 4 */
|
|
|
|
rs = D3DRENDERSTATE_FOGVERTEXMODE;
|
|
|
|
break;
|
|
|
|
case D3DLIGHTSTATE_FOGSTART: /* 5 */
|
|
|
|
rs = D3DRENDERSTATE_FOGSTART;
|
|
|
|
break;
|
|
|
|
case D3DLIGHTSTATE_FOGEND: /* 6 */
|
|
|
|
rs = D3DRENDERSTATE_FOGEND;
|
|
|
|
break;
|
|
|
|
case D3DLIGHTSTATE_FOGDENSITY: /* 7 */
|
|
|
|
rs = D3DRENDERSTATE_FOGDENSITY;
|
|
|
|
break;
|
|
|
|
case D3DLIGHTSTATE_COLORVERTEX: /* 8 */
|
|
|
|
rs = D3DRENDERSTATE_COLORVERTEX;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-10-17 15:58:51 +02:00
|
|
|
IDirect3DDevice7_SetRenderState(&lpDevice->IDirect3DDevice7_iface, rs, ci->u2.dwArg[0]);
|
2008-05-07 01:06:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
instr += size;
|
2003-05-20 19:49:40 +02:00
|
|
|
}
|
2002-11-21 22:04:16 +01:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case D3DOP_STATERENDER: {
|
|
|
|
int i;
|
2011-10-17 15:57:46 +02:00
|
|
|
IDirect3DDevice2 *d3d_device2 = &lpDevice->IDirect3DDevice2_iface;
|
2002-11-21 22:04:16 +01:00
|
|
|
TRACE("STATERENDER (%d)\n", count);
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
LPD3DSTATE ci = (LPD3DSTATE) instr;
|
2009-09-01 09:09:37 +02:00
|
|
|
|
2009-01-21 09:56:13 +01:00
|
|
|
IDirect3DDevice2_SetRenderState(d3d_device2, ci->u1.drstRenderStateType, ci->u2.dwArg[0]);
|
2002-11-21 22:04:16 +01:00
|
|
|
|
|
|
|
instr += size;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
case D3DOP_PROCESSVERTICES:
|
|
|
|
{
|
|
|
|
/* TODO: Share code with IDirect3DVertexBuffer::ProcessVertices and / or
|
|
|
|
* IWineD3DDevice::ProcessVertices
|
|
|
|
*/
|
|
|
|
int i;
|
|
|
|
D3DMATRIX view_mat, world_mat, proj_mat;
|
|
|
|
TRACE("PROCESSVERTICES (%d)\n", count);
|
|
|
|
|
|
|
|
/* Get the transform and world matrix */
|
2006-10-12 08:21:39 +02:00
|
|
|
/* Note: D3DMATRIX is compatible with WINED3DMATRIX */
|
2011-05-16 23:01:22 +02:00
|
|
|
wined3d_device_get_transform(lpDevice->wined3d_device,
|
2011-05-16 23:01:21 +02:00
|
|
|
D3DTRANSFORMSTATE_VIEW, (WINED3DMATRIX *)&view_mat);
|
2011-05-16 23:01:22 +02:00
|
|
|
wined3d_device_get_transform(lpDevice->wined3d_device,
|
2011-05-16 23:01:21 +02:00
|
|
|
D3DTRANSFORMSTATE_PROJECTION, (WINED3DMATRIX *)&proj_mat);
|
2011-05-16 23:01:22 +02:00
|
|
|
wined3d_device_get_transform(lpDevice->wined3d_device,
|
2011-05-16 23:01:21 +02:00
|
|
|
WINED3DTS_WORLDMATRIX(0), (WINED3DMATRIX *)&world_mat);
|
2002-11-21 22:04:16 +01:00
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
LPD3DPROCESSVERTICES ci = (LPD3DPROCESSVERTICES) instr;
|
|
|
|
|
2006-10-10 19:23:27 +02:00
|
|
|
TRACE(" Start : %d Dest : %d Count : %d\n",
|
2002-11-21 22:04:16 +01:00
|
|
|
ci->wStart, ci->wDest, ci->dwCount);
|
|
|
|
TRACE(" Flags : ");
|
2010-08-19 18:57:50 +02:00
|
|
|
if (TRACE_ON(ddraw))
|
|
|
|
{
|
2002-11-21 22:04:16 +01:00
|
|
|
if (ci->dwFlags & D3DPROCESSVERTICES_COPY)
|
2003-03-15 01:12:42 +01:00
|
|
|
TRACE("COPY ");
|
2002-11-21 22:04:16 +01:00
|
|
|
if (ci->dwFlags & D3DPROCESSVERTICES_NOCOLOR)
|
2003-03-15 01:12:42 +01:00
|
|
|
TRACE("NOCOLOR ");
|
2002-11-21 22:04:16 +01:00
|
|
|
if (ci->dwFlags == D3DPROCESSVERTICES_OPMASK)
|
2003-03-15 01:12:42 +01:00
|
|
|
TRACE("OPMASK ");
|
2002-11-21 22:04:16 +01:00
|
|
|
if (ci->dwFlags & D3DPROCESSVERTICES_TRANSFORM)
|
2003-03-15 01:12:42 +01:00
|
|
|
TRACE("TRANSFORM ");
|
2002-11-21 22:04:16 +01:00
|
|
|
if (ci->dwFlags == D3DPROCESSVERTICES_TRANSFORMLIGHT)
|
2003-03-15 01:12:42 +01:00
|
|
|
TRACE("TRANSFORMLIGHT ");
|
2002-11-21 22:04:16 +01:00
|
|
|
if (ci->dwFlags & D3DPROCESSVERTICES_UPDATEEXTENTS)
|
2003-03-15 01:12:42 +01:00
|
|
|
TRACE("UPDATEEXTENTS ");
|
|
|
|
TRACE("\n");
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
2009-09-01 09:09:37 +02:00
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
/* This is where doing Direct3D on top on OpenGL is quite difficult.
|
|
|
|
This method transforms a set of vertices using the CURRENT state
|
|
|
|
(lighting, projection, ...) but does not rasterize them.
|
|
|
|
They will only be put on screen later (with the POINT / LINE and
|
|
|
|
TRIANGLE op-codes). The problem is that you can have a triangle
|
|
|
|
with each point having been transformed using another state...
|
2009-09-01 09:09:37 +02:00
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
In this implementation, I will emulate only ONE thing : each
|
|
|
|
vertex can have its own "WORLD" transformation (this is used in the
|
|
|
|
TWIST.EXE demo of the 5.2 SDK). I suppose that all vertices of the
|
|
|
|
execute buffer use the same state.
|
2009-09-01 09:09:37 +02:00
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
If I find applications that change other states, I will try to do a
|
|
|
|
more 'fine-tuned' state emulation (but I may become quite tricky if
|
|
|
|
it changes a light position in the middle of a triangle).
|
2009-09-01 09:09:37 +02:00
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
In this case, a 'direct' approach (i.e. without using OpenGL, but
|
|
|
|
writing our own 3D rasterizer) would be easier. */
|
2009-09-01 09:09:37 +02:00
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
/* The current method (with the hypothesis that only the WORLD matrix
|
|
|
|
will change between two points) is like this :
|
|
|
|
- I transform 'manually' all the vertices with the current WORLD
|
|
|
|
matrix and store them in the vertex buffer
|
|
|
|
- during the rasterization phase, the WORLD matrix will be set to
|
|
|
|
the Identity matrix */
|
2009-09-01 09:09:37 +02:00
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
/* Enough for the moment */
|
|
|
|
if (ci->dwFlags == D3DPROCESSVERTICES_TRANSFORMLIGHT) {
|
2004-09-08 03:23:57 +02:00
|
|
|
unsigned int nb;
|
2003-01-23 22:32:35 +01:00
|
|
|
D3DVERTEX *src = ((LPD3DVERTEX) ((char *)This->desc.lpData + vs)) + ci->wStart;
|
2003-05-20 19:49:40 +02:00
|
|
|
D3DTLVERTEX *dst = ((LPD3DTLVERTEX) (This->vertex_data)) + ci->wDest;
|
|
|
|
D3DMATRIX mat;
|
|
|
|
D3DVIEWPORT* Viewport = &lpViewport->viewports.vp1;
|
2002-11-21 22:04:16 +01:00
|
|
|
|
2010-08-19 18:57:50 +02:00
|
|
|
if (TRACE_ON(ddraw))
|
|
|
|
{
|
2006-06-09 19:36:12 +02:00
|
|
|
TRACE(" Projection Matrix : (%p)\n", &proj_mat);
|
|
|
|
dump_D3DMATRIX(&proj_mat);
|
|
|
|
TRACE(" View Matrix : (%p)\n", &view_mat);
|
|
|
|
dump_D3DMATRIX(&view_mat);
|
|
|
|
TRACE(" World Matrix : (%p)\n", &world_mat);
|
|
|
|
dump_D3DMATRIX(&world_mat);
|
2003-05-20 19:49:40 +02:00
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
multiply_matrix(&mat,&view_mat,&world_mat);
|
|
|
|
multiply_matrix(&mat,&proj_mat,&mat);
|
2002-11-21 22:04:16 +01:00
|
|
|
|
|
|
|
for (nb = 0; nb < ci->dwCount; nb++) {
|
2003-05-20 19:49:40 +02:00
|
|
|
/* No lighting yet */
|
|
|
|
dst->u5.color = 0xFFFFFFFF; /* Opaque white */
|
|
|
|
dst->u6.specular = 0xFF000000; /* No specular and no fog factor */
|
2008-04-17 23:43:49 +02:00
|
|
|
|
2003-05-20 19:49:40 +02:00
|
|
|
dst->u7.tu = src->u7.tu;
|
|
|
|
dst->u8.tv = src->u8.tv;
|
2008-04-17 23:43:49 +02:00
|
|
|
|
2003-05-20 19:49:40 +02:00
|
|
|
/* Now, the matrix multiplication */
|
|
|
|
dst->u1.sx = (src->u1.x * mat._11) + (src->u2.y * mat._21) + (src->u3.z * mat._31) + (1.0 * mat._41);
|
|
|
|
dst->u2.sy = (src->u1.x * mat._12) + (src->u2.y * mat._22) + (src->u3.z * mat._32) + (1.0 * mat._42);
|
|
|
|
dst->u3.sz = (src->u1.x * mat._13) + (src->u2.y * mat._23) + (src->u3.z * mat._33) + (1.0 * mat._43);
|
|
|
|
dst->u4.rhw = (src->u1.x * mat._14) + (src->u2.y * mat._24) + (src->u3.z * mat._34) + (1.0 * mat._44);
|
|
|
|
|
2008-03-23 16:18:44 +01:00
|
|
|
dst->u1.sx = dst->u1.sx / dst->u4.rhw * Viewport->dvScaleX
|
2003-05-20 19:49:40 +02:00
|
|
|
+ Viewport->dwX + Viewport->dwWidth / 2;
|
2008-03-23 16:18:44 +01:00
|
|
|
dst->u2.sy = (-dst->u2.sy) / dst->u4.rhw * Viewport->dvScaleY
|
2003-05-20 19:49:40 +02:00
|
|
|
+ Viewport->dwY + Viewport->dwHeight / 2;
|
|
|
|
dst->u3.sz /= dst->u4.rhw;
|
|
|
|
dst->u4.rhw = 1 / dst->u4.rhw;
|
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
src++;
|
|
|
|
dst++;
|
2009-09-01 09:09:37 +02:00
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
|
|
|
} else if (ci->dwFlags == D3DPROCESSVERTICES_TRANSFORM) {
|
2004-09-08 03:23:57 +02:00
|
|
|
unsigned int nb;
|
2003-01-23 22:32:35 +01:00
|
|
|
D3DLVERTEX *src = ((LPD3DLVERTEX) ((char *)This->desc.lpData + vs)) + ci->wStart;
|
2003-05-20 19:49:40 +02:00
|
|
|
D3DTLVERTEX *dst = ((LPD3DTLVERTEX) (This->vertex_data)) + ci->wDest;
|
|
|
|
D3DMATRIX mat;
|
|
|
|
D3DVIEWPORT* Viewport = &lpViewport->viewports.vp1;
|
2002-11-21 22:04:16 +01:00
|
|
|
|
2010-08-19 18:57:50 +02:00
|
|
|
if (TRACE_ON(ddraw))
|
|
|
|
{
|
2006-06-09 19:36:12 +02:00
|
|
|
TRACE(" Projection Matrix : (%p)\n", &proj_mat);
|
|
|
|
dump_D3DMATRIX(&proj_mat);
|
|
|
|
TRACE(" View Matrix : (%p)\n",&view_mat);
|
|
|
|
dump_D3DMATRIX(&view_mat);
|
2008-03-23 16:18:44 +01:00
|
|
|
TRACE(" World Matrix : (%p)\n", &world_mat);
|
|
|
|
dump_D3DMATRIX(&world_mat);
|
2003-05-20 19:49:40 +02:00
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
multiply_matrix(&mat,&view_mat,&world_mat);
|
|
|
|
multiply_matrix(&mat,&proj_mat,&mat);
|
2003-05-20 19:49:40 +02:00
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
for (nb = 0; nb < ci->dwCount; nb++) {
|
2003-05-20 19:49:40 +02:00
|
|
|
dst->u5.color = src->u4.color;
|
|
|
|
dst->u6.specular = src->u5.specular;
|
|
|
|
dst->u7.tu = src->u6.tu;
|
|
|
|
dst->u8.tv = src->u7.tv;
|
2009-09-01 09:09:37 +02:00
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
/* Now, the matrix multiplication */
|
2003-05-20 19:49:40 +02:00
|
|
|
dst->u1.sx = (src->u1.x * mat._11) + (src->u2.y * mat._21) + (src->u3.z * mat._31) + (1.0 * mat._41);
|
|
|
|
dst->u2.sy = (src->u1.x * mat._12) + (src->u2.y * mat._22) + (src->u3.z * mat._32) + (1.0 * mat._42);
|
|
|
|
dst->u3.sz = (src->u1.x * mat._13) + (src->u2.y * mat._23) + (src->u3.z * mat._33) + (1.0 * mat._43);
|
|
|
|
dst->u4.rhw = (src->u1.x * mat._14) + (src->u2.y * mat._24) + (src->u3.z * mat._34) + (1.0 * mat._44);
|
|
|
|
|
2008-03-23 16:18:44 +01:00
|
|
|
dst->u1.sx = dst->u1.sx / dst->u4.rhw * Viewport->dvScaleX
|
|
|
|
+ Viewport->dwX + Viewport->dwWidth / 2;
|
|
|
|
dst->u2.sy = (-dst->u2.sy) / dst->u4.rhw * Viewport->dvScaleY
|
|
|
|
+ Viewport->dwY + Viewport->dwHeight / 2;
|
|
|
|
|
2003-05-20 19:49:40 +02:00
|
|
|
dst->u3.sz /= dst->u4.rhw;
|
|
|
|
dst->u4.rhw = 1 / dst->u4.rhw;
|
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
src++;
|
|
|
|
dst++;
|
|
|
|
}
|
|
|
|
} else if (ci->dwFlags == D3DPROCESSVERTICES_COPY) {
|
2003-01-23 22:32:35 +01:00
|
|
|
D3DTLVERTEX *src = ((LPD3DTLVERTEX) ((char *)This->desc.lpData + vs)) + ci->wStart;
|
2002-11-24 23:14:40 +01:00
|
|
|
D3DTLVERTEX *dst = ((LPD3DTLVERTEX) (This->vertex_data)) + ci->wDest;
|
2002-11-21 22:04:16 +01:00
|
|
|
|
|
|
|
memcpy(dst, src, ci->dwCount * sizeof(D3DTLVERTEX));
|
|
|
|
} else {
|
2010-03-14 21:53:20 +01:00
|
|
|
ERR("Unhandled vertex processing flag %#x.\n", ci->dwFlags);
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
instr += size;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case D3DOP_TEXTURELOAD: {
|
2003-01-02 20:59:49 +01:00
|
|
|
WARN("TEXTURELOAD-s (%d)\n", count);
|
2002-11-21 22:04:16 +01:00
|
|
|
|
|
|
|
instr += count * size;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case D3DOP_EXIT: {
|
|
|
|
TRACE("EXIT (%d)\n", count);
|
|
|
|
/* We did this instruction */
|
|
|
|
instr += size;
|
|
|
|
/* Exit this loop */
|
|
|
|
goto end_of_buffer;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case D3DOP_BRANCHFORWARD: {
|
|
|
|
int i;
|
|
|
|
TRACE("BRANCHFORWARD (%d)\n", count);
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
LPD3DBRANCH ci = (LPD3DBRANCH) instr;
|
|
|
|
|
2002-11-24 23:14:40 +01:00
|
|
|
if ((This->data.dsStatus.dwStatus & ci->dwMask) == ci->dwValue) {
|
2002-11-21 22:04:16 +01:00
|
|
|
if (!ci->bNegate) {
|
2006-10-10 19:23:27 +02:00
|
|
|
TRACE(" Branch to %d\n", ci->dwOffset);
|
2008-02-18 02:36:35 +01:00
|
|
|
if (ci->dwOffset) {
|
|
|
|
instr = (char*)current + ci->dwOffset;
|
|
|
|
break;
|
|
|
|
}
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (ci->bNegate) {
|
2006-10-10 19:23:27 +02:00
|
|
|
TRACE(" Branch to %d\n", ci->dwOffset);
|
2008-02-18 02:36:35 +01:00
|
|
|
if (ci->dwOffset) {
|
|
|
|
instr = (char*)current + ci->dwOffset;
|
|
|
|
break;
|
|
|
|
}
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
instr += size;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case D3DOP_SPAN: {
|
2003-01-02 20:59:49 +01:00
|
|
|
WARN("SPAN-s (%d)\n", count);
|
2002-11-21 22:04:16 +01:00
|
|
|
|
|
|
|
instr += count * size;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case D3DOP_SETSTATUS: {
|
|
|
|
int i;
|
|
|
|
TRACE("SETSTATUS (%d)\n", count);
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
LPD3DSTATUS ci = (LPD3DSTATUS) instr;
|
2009-09-01 09:09:37 +02:00
|
|
|
|
2002-11-24 23:14:40 +01:00
|
|
|
This->data.dsStatus = *ci;
|
2002-11-21 22:04:16 +01:00
|
|
|
|
|
|
|
instr += size;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
default:
|
2003-05-11 05:28:53 +02:00
|
|
|
ERR("Unhandled OpCode %d !!!\n",current->bOpcode);
|
2002-11-21 22:04:16 +01:00
|
|
|
/* Try to save ... */
|
|
|
|
instr += count * size;
|
|
|
|
break;
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-24 23:14:40 +01:00
|
|
|
end_of_buffer:
|
2011-04-19 00:08:00 +02:00
|
|
|
return D3D_OK;
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2011-07-08 12:26:57 +02:00
|
|
|
static inline IDirect3DExecuteBufferImpl *impl_from_IDirect3DExecuteBuffer(IDirect3DExecuteBuffer *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer_iface);
|
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DExecuteBuffer::QueryInterface
|
|
|
|
*
|
|
|
|
* Well, a usual QueryInterface function. Don't know fur sure which
|
|
|
|
* interfaces it can Query.
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* riid: The interface ID queried for
|
|
|
|
* obj: Address to return the interface pointer at
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* D3D_OK in case of a success (S_OK? Think it's the same)
|
|
|
|
* OLE_E_ENUM_NOMORE if the interface wasn't found.
|
|
|
|
* (E_NOINTERFACE?? Don't know what I really need)
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
static HRESULT WINAPI
|
|
|
|
IDirect3DExecuteBufferImpl_QueryInterface(IDirect3DExecuteBuffer *iface,
|
|
|
|
REFIID riid,
|
|
|
|
void **obj)
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
2010-08-19 18:57:50 +02:00
|
|
|
TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), obj);
|
1999-01-03 18:00:19 +01:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
*obj = NULL;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
if ( IsEqualGUID( &IID_IUnknown, riid ) ) {
|
2009-01-21 09:56:13 +01:00
|
|
|
IDirect3DExecuteBuffer_AddRef(iface);
|
2006-06-09 19:36:12 +02:00
|
|
|
*obj = iface;
|
|
|
|
TRACE(" Creating IUnknown interface at %p.\n", *obj);
|
2002-11-21 22:04:16 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
2009-01-20 10:00:20 +01:00
|
|
|
if ( IsEqualGUID( &IID_IDirect3DExecuteBuffer, riid ) ) {
|
2009-01-21 09:56:13 +01:00
|
|
|
IDirect3DExecuteBuffer_AddRef(iface);
|
|
|
|
*obj = iface;
|
2006-06-09 19:36:12 +02:00
|
|
|
TRACE(" Creating IDirect3DExecuteBuffer interface %p\n", *obj);
|
2002-11-21 22:04:16 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
2009-01-21 09:56:13 +01:00
|
|
|
FIXME("(%p): interface for IID %s NOT found!\n", iface, debugstr_guid(riid));
|
2006-06-09 19:36:12 +02:00
|
|
|
return E_NOINTERFACE;
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DExecuteBuffer::AddRef
|
|
|
|
*
|
|
|
|
* A normal AddRef method, nothing special
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* The new refcount
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2011-07-08 12:26:57 +02:00
|
|
|
static ULONG WINAPI IDirect3DExecuteBufferImpl_AddRef(IDirect3DExecuteBuffer *iface)
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
2011-07-08 12:26:57 +02:00
|
|
|
IDirect3DExecuteBufferImpl *This = impl_from_IDirect3DExecuteBuffer(iface);
|
2005-01-09 18:29:21 +01:00
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
2010-08-19 18:57:50 +02:00
|
|
|
TRACE("%p increasing refcount to %u.\n", This, ref);
|
2005-01-09 18:29:21 +01:00
|
|
|
|
|
|
|
return ref;
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DExecuteBuffer::Release
|
|
|
|
*
|
|
|
|
* A normal Release method, nothing special
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* The new refcount
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2011-07-08 12:26:57 +02:00
|
|
|
static ULONG WINAPI IDirect3DExecuteBufferImpl_Release(IDirect3DExecuteBuffer *iface)
|
2002-11-21 22:04:16 +01:00
|
|
|
{
|
2011-07-08 12:26:57 +02:00
|
|
|
IDirect3DExecuteBufferImpl *This = impl_from_IDirect3DExecuteBuffer(iface);
|
2005-01-09 18:29:21 +01:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
2010-08-19 18:57:50 +02:00
|
|
|
TRACE("%p decreasing refcount to %u.\n", This, ref);
|
2005-01-09 18:29:21 +01:00
|
|
|
|
|
|
|
if (!ref) {
|
2006-06-12 00:11:36 +02:00
|
|
|
if (This->need_free)
|
2002-11-21 22:04:16 +01:00
|
|
|
HeapFree(GetProcessHeap(),0,This->desc.lpData);
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree(GetProcessHeap(),0,This->vertex_data);
|
|
|
|
HeapFree(GetProcessHeap(),0,This->indices);
|
2002-11-21 22:04:16 +01:00
|
|
|
HeapFree(GetProcessHeap(),0,This);
|
|
|
|
return 0;
|
|
|
|
}
|
1999-01-03 18:00:19 +01:00
|
|
|
|
2005-01-09 18:29:21 +01:00
|
|
|
return ref;
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
1999-01-03 18:00:19 +01:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DExecuteBuffer::Initialize
|
|
|
|
*
|
|
|
|
* Initializes the Execute Buffer. This method exists for COM compliance
|
|
|
|
* Nothing to do here.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* D3D_OK
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2010-08-19 18:57:50 +02:00
|
|
|
static HRESULT WINAPI IDirect3DExecuteBufferImpl_Initialize(IDirect3DExecuteBuffer *iface,
|
|
|
|
IDirect3DDevice *device, D3DEXECUTEBUFFERDESC *desc)
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
2010-08-19 18:57:50 +02:00
|
|
|
TRACE("iface %p, device %p, desc %p.\n", iface, device, desc);
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
return D3D_OK;
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DExecuteBuffer::Lock
|
|
|
|
*
|
|
|
|
* Locks the buffer, so the app can write into it.
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* Desc: Pointer to return the buffer description. This Description contains
|
|
|
|
* a pointer to the buffer data.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* This implementation always returns D3D_OK
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2011-07-08 12:26:57 +02:00
|
|
|
static HRESULT WINAPI IDirect3DExecuteBufferImpl_Lock(IDirect3DExecuteBuffer *iface,
|
|
|
|
D3DEXECUTEBUFFERDESC *lpDesc)
|
2002-11-21 22:04:16 +01:00
|
|
|
{
|
2011-07-08 12:26:57 +02:00
|
|
|
IDirect3DExecuteBufferImpl *This = impl_from_IDirect3DExecuteBuffer(iface);
|
2002-11-21 22:04:16 +01:00
|
|
|
DWORD dwSize;
|
2010-08-19 18:57:50 +02:00
|
|
|
|
|
|
|
TRACE("iface %p, desc %p.\n", iface, lpDesc);
|
2002-11-21 22:04:16 +01:00
|
|
|
|
|
|
|
dwSize = lpDesc->dwSize;
|
|
|
|
memcpy(lpDesc, &This->desc, dwSize);
|
2009-09-01 09:09:37 +02:00
|
|
|
|
2010-08-19 18:57:50 +02:00
|
|
|
if (TRACE_ON(ddraw))
|
|
|
|
{
|
2005-11-10 13:14:56 +01:00
|
|
|
TRACE(" Returning description :\n");
|
2002-11-21 22:04:16 +01:00
|
|
|
_dump_D3DEXECUTEBUFFERDESC(lpDesc);
|
|
|
|
}
|
2006-06-09 19:36:12 +02:00
|
|
|
return D3D_OK;
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
1999-01-03 18:00:19 +01:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DExecuteBuffer::Unlock
|
|
|
|
*
|
|
|
|
* Unlocks the buffer. We don't have anything to do here
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* This implementation always returns D3D_OK
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2010-08-19 18:57:50 +02:00
|
|
|
static HRESULT WINAPI IDirect3DExecuteBufferImpl_Unlock(IDirect3DExecuteBuffer *iface)
|
2002-11-21 22:04:16 +01:00
|
|
|
{
|
2010-08-19 18:57:50 +02:00
|
|
|
TRACE("iface %p.\n", iface);
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
return D3D_OK;
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
1999-01-03 18:00:19 +01:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DExecuteBuffer::SetExecuteData
|
|
|
|
*
|
|
|
|
* Sets the execute data. This data is used to describe the buffer's content
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* Data: Pointer to a D3DEXECUTEDATA structure containing the data to
|
|
|
|
* assign
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* D3D_OK on success
|
|
|
|
* DDERR_OUTOFMEMORY if the vertex buffer allocation failed
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2011-07-08 12:26:57 +02:00
|
|
|
static HRESULT WINAPI IDirect3DExecuteBufferImpl_SetExecuteData(IDirect3DExecuteBuffer *iface,
|
|
|
|
D3DEXECUTEDATA *lpData)
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
2011-07-08 12:26:57 +02:00
|
|
|
IDirect3DExecuteBufferImpl *This = impl_from_IDirect3DExecuteBuffer(iface);
|
2002-11-21 22:04:16 +01:00
|
|
|
DWORD nbvert;
|
2010-08-19 18:57:50 +02:00
|
|
|
|
|
|
|
TRACE("iface %p, data %p.\n", iface, lpData);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
memcpy(&This->data, lpData, lpData->dwSize);
|
1999-01-03 18:00:19 +01:00
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
/* Get the number of vertices in the execute buffer */
|
|
|
|
nbvert = This->data.dwVertexCount;
|
2009-09-01 09:09:37 +02:00
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
/* Prepares the transformed vertex buffer */
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->vertex_data);
|
2003-05-20 19:49:40 +02:00
|
|
|
This->vertex_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nbvert * sizeof(D3DTLVERTEX));
|
1999-01-03 18:00:19 +01:00
|
|
|
|
2010-08-19 18:57:50 +02:00
|
|
|
if (TRACE_ON(ddraw))
|
2002-11-21 22:04:16 +01:00
|
|
|
_dump_executedata(lpData);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
return D3D_OK;
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DExecuteBuffer::GetExecuteData
|
|
|
|
*
|
|
|
|
* Returns the data in the execute buffer
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* Data: Pointer to a D3DEXECUTEDATA structure used to return data
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* D3D_OK on success
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2011-07-08 12:26:57 +02:00
|
|
|
static HRESULT WINAPI IDirect3DExecuteBufferImpl_GetExecuteData(IDirect3DExecuteBuffer *iface,
|
|
|
|
D3DEXECUTEDATA *lpData)
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
2011-07-08 12:26:57 +02:00
|
|
|
IDirect3DExecuteBufferImpl *This = impl_from_IDirect3DExecuteBuffer(iface);
|
2002-11-21 22:04:16 +01:00
|
|
|
DWORD dwSize;
|
2010-08-19 18:57:50 +02:00
|
|
|
|
|
|
|
TRACE("iface %p, data %p.\n", iface, lpData);
|
1999-01-03 18:00:19 +01:00
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
dwSize = lpData->dwSize;
|
|
|
|
memcpy(lpData, &This->data, dwSize);
|
1999-01-03 18:00:19 +01:00
|
|
|
|
2010-08-19 18:57:50 +02:00
|
|
|
if (TRACE_ON(ddraw))
|
|
|
|
{
|
2005-11-10 13:14:56 +01:00
|
|
|
TRACE("Returning data :\n");
|
2002-11-21 22:04:16 +01:00
|
|
|
_dump_executedata(lpData);
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
return DD_OK;
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DExecuteBuffer::Validate
|
|
|
|
*
|
|
|
|
* DirectX 5 SDK: "The IDirect3DExecuteBuffer::Validate method is not
|
|
|
|
* currently implemented"
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* ?
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* DDERR_UNSUPPORTED, because it's not implemented in Windows.
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2010-08-19 18:57:50 +02:00
|
|
|
static HRESULT WINAPI IDirect3DExecuteBufferImpl_Validate(IDirect3DExecuteBuffer *iface,
|
|
|
|
DWORD *offset, LPD3DVALIDATECALLBACK callback, void *context, DWORD reserved)
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
2010-08-19 18:57:50 +02:00
|
|
|
TRACE("iface %p, offset %p, callback %p, context %p, reserved %#x.\n",
|
|
|
|
iface, offset, callback, context, reserved);
|
|
|
|
|
|
|
|
WARN("Not implemented.\n");
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
return DDERR_UNSUPPORTED; /* Unchecked */
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DExecuteBuffer::Optimize
|
|
|
|
*
|
|
|
|
* DirectX5 SDK: "The IDirect3DExecuteBuffer::Optimize method is not
|
|
|
|
* currently supported"
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* Dummy: Seems to be an unused dummy ;)
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* DDERR_UNSUPPORTED, because it's not implemented in Windows.
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2010-08-19 18:57:50 +02:00
|
|
|
static HRESULT WINAPI IDirect3DExecuteBufferImpl_Optimize(IDirect3DExecuteBuffer *iface, DWORD reserved)
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
2010-08-19 18:57:50 +02:00
|
|
|
TRACE("iface %p, reserved %#x.\n", iface, reserved);
|
|
|
|
|
|
|
|
WARN("Not implemented.\n");
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
return DDERR_UNSUPPORTED; /* Unchecked */
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
1999-01-03 18:00:19 +01:00
|
|
|
|
2010-08-19 18:57:45 +02:00
|
|
|
static const struct IDirect3DExecuteBufferVtbl d3d_execute_buffer_vtbl =
|
2002-11-21 22:04:16 +01:00
|
|
|
{
|
2006-06-09 19:36:12 +02:00
|
|
|
IDirect3DExecuteBufferImpl_QueryInterface,
|
|
|
|
IDirect3DExecuteBufferImpl_AddRef,
|
|
|
|
IDirect3DExecuteBufferImpl_Release,
|
|
|
|
IDirect3DExecuteBufferImpl_Initialize,
|
|
|
|
IDirect3DExecuteBufferImpl_Lock,
|
|
|
|
IDirect3DExecuteBufferImpl_Unlock,
|
|
|
|
IDirect3DExecuteBufferImpl_SetExecuteData,
|
|
|
|
IDirect3DExecuteBufferImpl_GetExecuteData,
|
|
|
|
IDirect3DExecuteBufferImpl_Validate,
|
|
|
|
IDirect3DExecuteBufferImpl_Optimize,
|
2002-11-21 22:04:16 +01:00
|
|
|
};
|
2010-08-19 18:57:45 +02:00
|
|
|
|
|
|
|
HRESULT d3d_execute_buffer_init(IDirect3DExecuteBufferImpl *execute_buffer,
|
|
|
|
IDirect3DDeviceImpl *device, D3DEXECUTEBUFFERDESC *desc)
|
|
|
|
{
|
2011-07-08 12:26:57 +02:00
|
|
|
execute_buffer->IDirect3DExecuteBuffer_iface.lpVtbl = &d3d_execute_buffer_vtbl;
|
2010-08-19 18:57:45 +02:00
|
|
|
execute_buffer->ref = 1;
|
|
|
|
execute_buffer->d3ddev = device;
|
|
|
|
|
|
|
|
/* Initializes memory */
|
|
|
|
memcpy(&execute_buffer->desc, desc, desc->dwSize);
|
|
|
|
|
|
|
|
/* No buffer given */
|
|
|
|
if (!(execute_buffer->desc.dwFlags & D3DDEB_LPDATA))
|
|
|
|
execute_buffer->desc.lpData = NULL;
|
|
|
|
|
|
|
|
/* No buffer size given */
|
|
|
|
if (!(execute_buffer->desc.dwFlags & D3DDEB_BUFSIZE))
|
|
|
|
execute_buffer->desc.dwBufferSize = 0;
|
|
|
|
|
|
|
|
/* Create buffer if asked */
|
|
|
|
if (!execute_buffer->desc.lpData && execute_buffer->desc.dwBufferSize)
|
|
|
|
{
|
|
|
|
execute_buffer->need_free = TRUE;
|
|
|
|
execute_buffer->desc.lpData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, execute_buffer->desc.dwBufferSize);
|
|
|
|
if (!execute_buffer->desc.lpData)
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate execute buffer data.\n");
|
|
|
|
return DDERR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
execute_buffer->desc.dwFlags |= D3DDEB_LPDATA;
|
|
|
|
|
|
|
|
return D3D_OK;
|
|
|
|
}
|
2011-07-08 12:28:27 +02:00
|
|
|
|
|
|
|
IDirect3DExecuteBufferImpl *unsafe_impl_from_IDirect3DExecuteBuffer(IDirect3DExecuteBuffer *iface)
|
|
|
|
{
|
|
|
|
if (!iface)
|
|
|
|
return NULL;
|
|
|
|
assert(iface->lpVtbl == &d3d_execute_buffer_vtbl);
|
|
|
|
|
|
|
|
return impl_from_IDirect3DExecuteBuffer(iface);
|
|
|
|
}
|