wined3d: Pass the vertex count rather than the primitive count to wined3d draw methods.

This commit is contained in:
Henri Verbeet 2009-03-05 12:30:42 +01:00 committed by Alexandre Julliard
parent 6eccf2a3fa
commit 602bb1f551
7 changed files with 149 additions and 307 deletions

View File

@ -136,6 +136,32 @@ WINED3DFORMAT wined3dformat_from_d3dformat(D3DFORMAT format)
}
}
static UINT vertex_count_from_primitive_count(D3DPRIMITIVETYPE primitive_type, UINT primitive_count)
{
switch(primitive_type)
{
case D3DPT_POINTLIST:
return primitive_count;
case D3DPT_LINELIST:
return primitive_count * 2;
case D3DPT_LINESTRIP:
return primitive_count + 1;
case D3DPT_TRIANGLELIST:
return primitive_count * 3;
case D3DPT_TRIANGLESTRIP:
case D3DPT_TRIANGLEFAN:
return primitive_count + 2;
default:
FIXME("Unhandled primitive type %#x\n", primitive_type);
return 0;
}
}
/* Shader handle functions */
static shader_handle *alloc_shader_handle(IDirect3DDevice8Impl *This) {
if (This->free_shader_handles) {
@ -1512,7 +1538,8 @@ static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitive(LPDIRECT3DDEVICE8 iface
TRACE("(%p) Relay\n" , This);
EnterCriticalSection(&d3d8_cs);
hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, PrimitiveType, StartVertex, PrimitiveCount);
hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, PrimitiveType, StartVertex,
vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount));
LeaveCriticalSection(&d3d8_cs);
return hr;
}
@ -1524,7 +1551,8 @@ static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE
TRACE("(%p) Relay\n" , This);
EnterCriticalSection(&d3d8_cs);
hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, PrimitiveType, MinVertexIndex, NumVertices, startIndex, primCount);
hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, PrimitiveType, MinVertexIndex, NumVertices,
startIndex, vertex_count_from_primitive_count(PrimitiveType, primCount));
LeaveCriticalSection(&d3d8_cs);
return hr;
}
@ -1535,7 +1563,9 @@ static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitiveUP(LPDIRECT3DDEVICE8 ifa
TRACE("(%p) Relay\n" , This);
EnterCriticalSection(&d3d8_cs);
hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice, PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride);
hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice, PrimitiveType,
vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount),
pVertexStreamZeroData, VertexStreamZeroStride);
LeaveCriticalSection(&d3d8_cs);
return hr;
}
@ -1550,8 +1580,8 @@ static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVI
EnterCriticalSection(&d3d8_cs);
hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice, PrimitiveType, MinVertexIndex,
NumVertexIndices, PrimitiveCount, pIndexData, wined3dformat_from_d3dformat(IndexDataFormat),
pVertexStreamZeroData, VertexStreamZeroStride);
NumVertexIndices, vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount), pIndexData,
wined3dformat_from_d3dformat(IndexDataFormat), pVertexStreamZeroData, VertexStreamZeroStride);
LeaveCriticalSection(&d3d8_cs);
return hr;
}

View File

@ -155,6 +155,32 @@ WINED3DFORMAT wined3dformat_from_d3dformat(D3DFORMAT format)
}
}
static UINT vertex_count_from_primitive_count(D3DPRIMITIVETYPE primitive_type, UINT primitive_count)
{
switch(primitive_type)
{
case D3DPT_POINTLIST:
return primitive_count;
case D3DPT_LINELIST:
return primitive_count * 2;
case D3DPT_LINESTRIP:
return primitive_count + 1;
case D3DPT_TRIANGLELIST:
return primitive_count * 3;
case D3DPT_TRIANGLESTRIP:
case D3DPT_TRIANGLEFAN:
return primitive_count + 2;
default:
FIXME("Unhandled primitive type %#x\n", primitive_type);
return 0;
}
}
/* IDirect3D IUnknown parts follow: */
static HRESULT WINAPI IDirect3DDevice9Impl_QueryInterface(LPDIRECT3DDEVICE9EX iface, REFIID riid, LPVOID* ppobj) {
IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
@ -1357,7 +1383,8 @@ static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitive(LPDIRECT3DDEVICE9EX ifa
TRACE("(%p) Relay\n" , This);
EnterCriticalSection(&d3d9_cs);
hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, PrimitiveType, StartVertex, PrimitiveCount);
hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, PrimitiveType, StartVertex,
vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount));
LeaveCriticalSection(&d3d9_cs);
return hr;
}
@ -1371,7 +1398,8 @@ static HRESULT WINAPI IDirect3DDevice9Impl_DrawIndexedPrimitive(LPDIRECT3DDEVI
/* D3D8 passes the baseVertexIndex in SetIndices, and due to the stateblock functions wined3d has to work that way */
EnterCriticalSection(&d3d9_cs);
IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, BaseVertexIndex);
hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, PrimitiveType, MinVertexIndex, NumVertices, startIndex, primCount);
hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, PrimitiveType, MinVertexIndex, NumVertices,
startIndex, vertex_count_from_primitive_count(PrimitiveType, primCount));
LeaveCriticalSection(&d3d9_cs);
return hr;
}
@ -1382,7 +1410,9 @@ static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitiveUP(LPDIRECT3DDEVICE9EX
TRACE("(%p) Relay\n" , This);
EnterCriticalSection(&d3d9_cs);
hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice, PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride);
hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice, PrimitiveType,
vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount),
pVertexStreamZeroData, VertexStreamZeroStride);
LeaveCriticalSection(&d3d9_cs);
return hr;
}
@ -1396,8 +1426,8 @@ static HRESULT WINAPI IDirect3DDevice9Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDE
EnterCriticalSection(&d3d9_cs);
hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice, PrimitiveType, MinVertexIndex,
NumVertexIndices, PrimitiveCount, pIndexData, wined3dformat_from_d3dformat(IndexDataFormat),
pVertexStreamZeroData, VertexStreamZeroStride);
NumVertexIndices, vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount), pIndexData,
wined3dformat_from_d3dformat(IndexDataFormat), pVertexStreamZeroData, VertexStreamZeroStride);
LeaveCriticalSection(&d3d9_cs);
return hr;
}

View File

@ -3463,44 +3463,13 @@ IDirect3DDeviceImpl_7_DrawPrimitive(IDirect3DDevice7 *iface,
DWORD Flags)
{
IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
UINT PrimitiveCount, stride;
UINT stride;
HRESULT hr;
TRACE("(%p)->(%08x,%08x,%p,%08x,%08x): Relay!\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Flags);
if(!Vertices)
return DDERR_INVALIDPARAMS;
/* Get the vertex count */
switch(PrimitiveType)
{
case D3DPT_POINTLIST:
PrimitiveCount = VertexCount;
break;
case D3DPT_LINELIST:
PrimitiveCount = VertexCount / 2;
break;
case D3DPT_LINESTRIP:
PrimitiveCount = VertexCount - 1;
break;
case D3DPT_TRIANGLELIST:
PrimitiveCount = VertexCount / 3;
break;
case D3DPT_TRIANGLESTRIP:
PrimitiveCount = VertexCount - 2;
break;
case D3DPT_TRIANGLEFAN:
PrimitiveCount = VertexCount - 2;
break;
default:
return DDERR_INVALIDPARAMS;
}
/* Get the stride */
stride = get_flexible_vertex_size(VertexType);
@ -3517,7 +3486,7 @@ IDirect3DDeviceImpl_7_DrawPrimitive(IDirect3DDevice7 *iface,
/* This method translates to the user pointer draw of WineD3D */
hr = IWineD3DDevice_DrawPrimitiveUP(This->wineD3DDevice,
PrimitiveType,
PrimitiveCount,
VertexCount,
Vertices,
stride);
LeaveCriticalSection(&ddraw_cs);
@ -3627,41 +3596,9 @@ IDirect3DDeviceImpl_7_DrawIndexedPrimitive(IDirect3DDevice7 *iface,
DWORD Flags)
{
IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
UINT PrimitiveCount = 0;
HRESULT hr;
TRACE("(%p)->(%08x,%08x,%p,%08x,%p,%08x,%08x): Relay!\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Indices, IndexCount, Flags);
/* Get the primitive number */
switch(PrimitiveType)
{
case D3DPT_POINTLIST:
PrimitiveCount = IndexCount;
break;
case D3DPT_LINELIST:
PrimitiveCount = IndexCount / 2;
break;
case D3DPT_LINESTRIP:
PrimitiveCount = IndexCount - 1;
break;
case D3DPT_TRIANGLELIST:
PrimitiveCount = IndexCount / 3;
break;
case D3DPT_TRIANGLESTRIP:
PrimitiveCount = IndexCount - 2;
break;
case D3DPT_TRIANGLEFAN:
PrimitiveCount = IndexCount - 2;
break;
default:
return DDERR_INVALIDPARAMS;
}
/* Set the D3DDevice's FVF */
EnterCriticalSection(&ddraw_cs);
hr = IWineD3DDevice_SetVertexDeclaration(This->wineD3DDevice,
@ -3674,7 +3611,7 @@ IDirect3DDeviceImpl_7_DrawIndexedPrimitive(IDirect3DDevice7 *iface,
}
hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->wineD3DDevice, PrimitiveType, 0 /* MinVertexIndex */,
VertexCount /* UINT NumVertexIndex */, PrimitiveCount, Indices, WINED3DFMT_R16_UINT, Vertices,
VertexCount /* UINT NumVertexIndex */, IndexCount, Indices, WINED3DFMT_R16_UINT, Vertices,
get_flexible_vertex_size(VertexType));
LeaveCriticalSection(&ddraw_cs);
return hr;
@ -3879,7 +3816,6 @@ IDirect3DDeviceImpl_7_DrawPrimitiveStrided(IDirect3DDevice7 *iface,
IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
WineDirect3DVertexStridedData WineD3DStrided;
DWORD i;
UINT PrimitiveCount;
HRESULT hr;
TRACE("(%p)->(%08x,%08x,%p,%08x,%08x): stub!\n", This, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Flags);
@ -3940,41 +3876,11 @@ IDirect3DDeviceImpl_7_DrawPrimitiveStrided(IDirect3DDevice7 *iface,
}
}
/* Get the primitive count */
switch(PrimitiveType)
{
case D3DPT_POINTLIST:
PrimitiveCount = VertexCount;
break;
case D3DPT_LINELIST:
PrimitiveCount = VertexCount / 2;
break;
case D3DPT_LINESTRIP:
PrimitiveCount = VertexCount - 1;
break;
case D3DPT_TRIANGLELIST:
PrimitiveCount = VertexCount / 3;
break;
case D3DPT_TRIANGLESTRIP:
PrimitiveCount = VertexCount - 2;
break;
case D3DPT_TRIANGLEFAN:
PrimitiveCount = VertexCount - 2;
break;
default: return DDERR_INVALIDPARAMS;
}
/* WineD3D doesn't need the FVF here */
EnterCriticalSection(&ddraw_cs);
hr = IWineD3DDevice_DrawPrimitiveStrided(This->wineD3DDevice,
PrimitiveType,
PrimitiveCount,
VertexCount,
&WineD3DStrided);
LeaveCriticalSection(&ddraw_cs);
return hr;
@ -4053,7 +3959,6 @@ IDirect3DDeviceImpl_7_DrawIndexedPrimitiveStrided(IDirect3DDevice7 *iface,
IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
WineDirect3DVertexStridedData WineD3DStrided;
DWORD i;
UINT PrimitiveCount;
HRESULT hr;
TRACE("(%p)->(%08x,%08x,%p,%08x,%p,%08x,%08x)\n", This, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Indices, IndexCount, Flags);
@ -4114,40 +4019,10 @@ IDirect3DDeviceImpl_7_DrawIndexedPrimitiveStrided(IDirect3DDevice7 *iface,
}
}
/* Get the primitive count */
switch(PrimitiveType)
{
case D3DPT_POINTLIST:
PrimitiveCount = IndexCount;
break;
case D3DPT_LINELIST:
PrimitiveCount = IndexCount / 2;
break;
case D3DPT_LINESTRIP:
PrimitiveCount = IndexCount - 1;
break;
case D3DPT_TRIANGLELIST:
PrimitiveCount = IndexCount / 3;
break;
case D3DPT_TRIANGLESTRIP:
PrimitiveCount = IndexCount - 2;
break;
case D3DPT_TRIANGLEFAN:
PrimitiveCount = IndexCount - 2;
break;
default: return DDERR_INVALIDPARAMS;
}
/* WineD3D doesn't need the FVF here */
EnterCriticalSection(&ddraw_cs);
hr = IWineD3DDevice_DrawIndexedPrimitiveStrided(This->wineD3DDevice, PrimitiveType,
PrimitiveCount, &WineD3DStrided, VertexCount, Indices, WINED3DFMT_R16_UINT);
IndexCount, &WineD3DStrided, VertexCount, Indices, WINED3DFMT_R16_UINT);
LeaveCriticalSection(&ddraw_cs);
return hr;
}
@ -4230,7 +4105,6 @@ IDirect3DDeviceImpl_7_DrawPrimitiveVB(IDirect3DDevice7 *iface,
{
IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
IDirect3DVertexBufferImpl *vb = (IDirect3DVertexBufferImpl *)D3DVertexBuf;
UINT PrimitiveCount;
HRESULT hr;
DWORD stride;
WINED3DVERTEXBUFFER_DESC Desc;
@ -4244,37 +4118,6 @@ IDirect3DDeviceImpl_7_DrawPrimitiveVB(IDirect3DDevice7 *iface,
return DDERR_INVALIDPARAMS;
}
/* Get the primitive count */
switch(PrimitiveType)
{
case D3DPT_POINTLIST:
PrimitiveCount = NumVertices;
break;
case D3DPT_LINELIST:
PrimitiveCount = NumVertices / 2;
break;
case D3DPT_LINESTRIP:
PrimitiveCount = NumVertices - 1;
break;
case D3DPT_TRIANGLELIST:
PrimitiveCount = NumVertices / 3;
break;
case D3DPT_TRIANGLESTRIP:
PrimitiveCount = NumVertices - 2;
break;
case D3DPT_TRIANGLEFAN:
PrimitiveCount = NumVertices - 2;
break;
default:
return DDERR_INVALIDPARAMS;
}
/* Get the FVF of the vertex buffer, and its stride */
EnterCriticalSection(&ddraw_cs);
hr = IWineD3DVertexBuffer_GetDesc(vb->wineD3DVertexBuffer,
@ -4313,7 +4156,7 @@ IDirect3DDeviceImpl_7_DrawPrimitiveVB(IDirect3DDevice7 *iface,
hr = IWineD3DDevice_DrawPrimitive(This->wineD3DDevice,
PrimitiveType,
StartVertex,
PrimitiveCount);
NumVertices);
LeaveCriticalSection(&ddraw_cs);
return hr;
}
@ -4393,7 +4236,6 @@ IDirect3DDeviceImpl_7_DrawIndexedPrimitiveVB(IDirect3DDevice7 *iface,
IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
IDirect3DVertexBufferImpl *vb = (IDirect3DVertexBufferImpl *)D3DVertexBuf;
DWORD stride;
UINT PrimitiveCount;
WORD *LockedIndices;
HRESULT hr;
WINED3DVERTEXBUFFER_DESC Desc;
@ -4401,43 +4243,13 @@ IDirect3DDeviceImpl_7_DrawIndexedPrimitiveVB(IDirect3DDevice7 *iface,
TRACE("(%p)->(%08x,%p,%d,%d,%p,%d,%08x)\n", This, PrimitiveType, vb, StartVertex, NumVertices, Indices, IndexCount, Flags);
/* Steps:
* 1) Calculate some things: Vertex count -> Primitive count, stride, ...
* 1) Calculate some things: stride, ...
* 2) Upload the Indices to the index buffer
* 3) Set the index source
* 4) Set the Vertex Buffer as the Stream source
* 5) Call IWineD3DDevice::DrawIndexedPrimitive
*/
/* Get the primitive count */
switch(PrimitiveType)
{
case D3DPT_POINTLIST:
PrimitiveCount = IndexCount;
break;
case D3DPT_LINELIST:
PrimitiveCount = IndexCount / 2;
break;
case D3DPT_LINESTRIP:
PrimitiveCount = IndexCount - 1;
break;
case D3DPT_TRIANGLELIST:
PrimitiveCount = IndexCount / 3;
break;
case D3DPT_TRIANGLESTRIP:
PrimitiveCount = IndexCount - 2;
break;
case D3DPT_TRIANGLEFAN:
PrimitiveCount = IndexCount - 2;
break;
default: return DDERR_INVALIDPARAMS;
}
EnterCriticalSection(&ddraw_cs);
/* Get the FVF of the vertex buffer, and its stride */
hr = IWineD3DVertexBuffer_GetDesc(vb->wineD3DVertexBuffer,
@ -4510,7 +4322,7 @@ IDirect3DDeviceImpl_7_DrawIndexedPrimitiveVB(IDirect3DDevice7 *iface,
0 /* minIndex */,
NumVertices,
0 /* StartIndex */,
PrimitiveCount);
IndexCount);
LeaveCriticalSection(&ddraw_cs);
return hr;

View File

@ -5301,14 +5301,13 @@ static HRESULT WINAPI IWineD3DDeviceImpl_Clear(IWineD3DDevice *iface, DWORD Coun
/*****
* Drawing functions
*****/
static HRESULT WINAPI IWineD3DDeviceImpl_DrawPrimitive(IWineD3DDevice *iface, WINED3DPRIMITIVETYPE PrimitiveType, UINT StartVertex,
UINT PrimitiveCount) {
static HRESULT WINAPI IWineD3DDeviceImpl_DrawPrimitive(IWineD3DDevice *iface,
WINED3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT vertex_count)
{
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
TRACE("(%p) : Type=(%d,%s), Start=%d, Count=%d\n", This, PrimitiveType,
debug_d3dprimitivetype(PrimitiveType),
StartVertex, PrimitiveCount);
TRACE("(%p) : type %u (%s), start %u, count %u\n", This, PrimitiveType,
debug_d3dprimitivetype(PrimitiveType), StartVertex, vertex_count);
if(!This->stateBlock->vertexDecl) {
WARN("(%p) : Called without a valid vertex declaration set\n", This);
@ -5326,16 +5325,14 @@ static HRESULT WINAPI IWineD3DDeviceImpl_DrawPrimitive(IWineD3DDevice *iface, WI
IWineD3DDeviceImpl_MarkStateDirty(This, STATE_STREAMSRC);
}
/* Account for the loading offset due to index buffers. Instead of reloading all sources correct it with the startvertex parameter */
drawPrimitive(iface, PrimitiveType, PrimitiveCount, 0/* NumVertices */, StartVertex /* start_idx */,
drawPrimitive(iface, PrimitiveType, vertex_count, 0/* NumVertices */, StartVertex /* start_idx */,
0 /* indxSize */, NULL /* indxData */, 0 /* minIndex */);
return WINED3D_OK;
}
/* TODO: baseVIndex needs to be provided from This->stateBlock->baseVertexIndex when called from d3d8 */
static HRESULT WINAPI IWineD3DDeviceImpl_DrawIndexedPrimitive(IWineD3DDevice *iface,
WINED3DPRIMITIVETYPE PrimitiveType,
UINT minIndex, UINT NumVertices, UINT startIndex, UINT primCount) {
static HRESULT WINAPI IWineD3DDeviceImpl_DrawIndexedPrimitive(IWineD3DDevice *iface,
WINED3DPRIMITIVETYPE PrimitiveType, UINT minIndex, UINT NumVertices, UINT startIndex, UINT index_count)
{
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
UINT idxStride = 2;
IWineD3DIndexBuffer *pIB;
@ -5363,9 +5360,8 @@ static HRESULT WINAPI IWineD3DDeviceImpl_DrawIndexedPrimitive(IWineD3DDevice *
}
vbo = ((IWineD3DIndexBufferImpl *) pIB)->vbo;
TRACE("(%p) : Type=(%d,%s), min=%d, CountV=%d, startIdx=%d, countP=%d\n", This,
PrimitiveType, debug_d3dprimitivetype(PrimitiveType),
minIndex, NumVertices, startIndex, primCount);
TRACE("(%p) : type %u (%s), min %u, vertex count %u, startIdx %u, index count %u\n", This,
PrimitiveType, debug_d3dprimitivetype(PrimitiveType), minIndex, NumVertices, startIndex, index_count);
IWineD3DIndexBuffer_GetDesc(pIB, &IdxBufDsc);
if (IdxBufDsc.Format == WINED3DFMT_R16_UINT) {
@ -5379,21 +5375,20 @@ static HRESULT WINAPI IWineD3DDeviceImpl_DrawIndexedPrimitive(IWineD3DDevice *
IWineD3DDeviceImpl_MarkStateDirty(This, STATE_STREAMSRC);
}
drawPrimitive(iface, PrimitiveType, primCount, NumVertices, startIndex,
drawPrimitive(iface, PrimitiveType, index_count, NumVertices, startIndex,
idxStride, vbo ? NULL : ((IWineD3DIndexBufferImpl *) pIB)->resource.allocatedMemory, minIndex);
return WINED3D_OK;
}
static HRESULT WINAPI IWineD3DDeviceImpl_DrawPrimitiveUP(IWineD3DDevice *iface, WINED3DPRIMITIVETYPE PrimitiveType,
UINT PrimitiveCount, CONST void* pVertexStreamZeroData,
UINT VertexStreamZeroStride) {
UINT vertex_count, const void *pVertexStreamZeroData, UINT VertexStreamZeroStride)
{
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
IWineD3DVertexBuffer *vb;
TRACE("(%p) : Type=(%d,%s), pCount=%d, pVtxData=%p, Stride=%d\n", This, PrimitiveType,
debug_d3dprimitivetype(PrimitiveType),
PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride);
TRACE("(%p) : type %u (%s), vertex count %u, pVtxData %p, stride %u\n", This, PrimitiveType,
debug_d3dprimitivetype(PrimitiveType), vertex_count, pVertexStreamZeroData, VertexStreamZeroStride);
if(!This->stateBlock->vertexDecl) {
WARN("(%p) : Called without a valid vertex declaration set\n", This);
@ -5412,8 +5407,8 @@ static HRESULT WINAPI IWineD3DDeviceImpl_DrawPrimitiveUP(IWineD3DDevice *iface,
/* TODO: Only mark dirty if drawing from a different UP address */
IWineD3DDeviceImpl_MarkStateDirty(This, STATE_STREAMSRC);
drawPrimitive(iface, PrimitiveType, PrimitiveCount, 0 /* NumVertices */,
0 /* start_idx */, 0 /* indxSize*/, NULL /* indxData */, 0 /* indxMin */);
drawPrimitive(iface, PrimitiveType, vertex_count, 0 /* NumVertices */,
0 /* start_idx */, 0 /* indxSize*/, NULL /* indxData */, 0 /* indxMin */);
/* MSDN specifies stream zero settings must be set to NULL */
This->stateBlock->streamStride[0] = 0;
@ -5425,20 +5420,19 @@ static HRESULT WINAPI IWineD3DDeviceImpl_DrawPrimitiveUP(IWineD3DDevice *iface,
return WINED3D_OK;
}
static HRESULT WINAPI IWineD3DDeviceImpl_DrawIndexedPrimitiveUP(IWineD3DDevice *iface, WINED3DPRIMITIVETYPE PrimitiveType,
UINT MinVertexIndex, UINT NumVertices,
UINT PrimitiveCount, CONST void* pIndexData,
WINED3DFORMAT IndexDataFormat,CONST void* pVertexStreamZeroData,
UINT VertexStreamZeroStride) {
static HRESULT WINAPI IWineD3DDeviceImpl_DrawIndexedPrimitiveUP(IWineD3DDevice *iface,
WINED3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertices,
UINT index_count, const void *pIndexData, WINED3DFORMAT IndexDataFormat,
const void *pVertexStreamZeroData, UINT VertexStreamZeroStride)
{
int idxStride;
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
IWineD3DVertexBuffer *vb;
IWineD3DIndexBuffer *ib;
TRACE("(%p) : Type=(%d,%s), MinVtxIdx=%d, NumVIdx=%d, PCount=%d, pidxdata=%p, IdxFmt=%d, pVtxdata=%p, stride=%d\n",
This, PrimitiveType, debug_d3dprimitivetype(PrimitiveType),
MinVertexIndex, NumVertices, PrimitiveCount, pIndexData,
IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride);
TRACE("(%p) : type %u (%s), MinVtxIdx %u, NumVIdx %u, index count %u, pidxdata %p, IdxFmt %u, pVtxdata %p, stride=%u\n",
This, PrimitiveType, debug_d3dprimitivetype(PrimitiveType), MinVertexIndex, NumVertices, index_count,
pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride);
if(!This->stateBlock->vertexDecl) {
WARN("(%p) : Called without a valid vertex declaration set\n", This);
@ -5466,7 +5460,8 @@ static HRESULT WINAPI IWineD3DDeviceImpl_DrawIndexedPrimitiveUP(IWineD3DDevice *
IWineD3DDeviceImpl_MarkStateDirty(This, STATE_VDECL);
IWineD3DDeviceImpl_MarkStateDirty(This, STATE_INDEXBUFFER);
drawPrimitive(iface, PrimitiveType, PrimitiveCount, NumVertices, 0 /* start_idx */, idxStride, pIndexData, MinVertexIndex);
drawPrimitive(iface, PrimitiveType, index_count, NumVertices,
0 /* start_idx */, idxStride, pIndexData, MinVertexIndex);
/* MSDN specifies stream zero settings and index buffer must be set to NULL */
This->stateBlock->streamSource[0] = NULL;
@ -5484,8 +5479,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_DrawIndexedPrimitiveUP(IWineD3DDevice *
}
static HRESULT WINAPI IWineD3DDeviceImpl_DrawPrimitiveStrided(IWineD3DDevice *iface,
WINED3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount,
const WineDirect3DVertexStridedData *DrawPrimStrideData)
WINED3DPRIMITIVETYPE PrimitiveType, UINT vertex_count, const WineDirect3DVertexStridedData *DrawPrimStrideData)
{
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
@ -5497,15 +5491,14 @@ static HRESULT WINAPI IWineD3DDeviceImpl_DrawPrimitiveStrided(IWineD3DDevice *if
IWineD3DDeviceImpl_MarkStateDirty(This, STATE_INDEXBUFFER);
This->stateBlock->baseVertexIndex = 0;
This->up_strided = DrawPrimStrideData;
drawPrimitive(iface, PrimitiveType, PrimitiveCount, 0, 0, 0, NULL, 0);
drawPrimitive(iface, PrimitiveType, vertex_count, 0, 0, 0, NULL, 0);
This->up_strided = NULL;
return WINED3D_OK;
}
static HRESULT WINAPI IWineD3DDeviceImpl_DrawIndexedPrimitiveStrided(IWineD3DDevice *iface,
WINED3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount,
const WineDirect3DVertexStridedData *DrawPrimStrideData, UINT NumVertices, const void *pIndexData,
WINED3DFORMAT IndexDataFormat)
WINED3DPRIMITIVETYPE PrimitiveType, UINT vertex_count, const WineDirect3DVertexStridedData *DrawPrimStrideData,
UINT NumVertices, const void *pIndexData, WINED3DFORMAT IndexDataFormat)
{
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
DWORD idxSize = (IndexDataFormat == WINED3DFMT_R32_UINT ? 4 : 2);
@ -5519,7 +5512,8 @@ static HRESULT WINAPI IWineD3DDeviceImpl_DrawIndexedPrimitiveStrided(IWineD3DDev
This->stateBlock->streamIsUP = TRUE;
This->stateBlock->baseVertexIndex = 0;
This->up_strided = DrawPrimStrideData;
drawPrimitive(iface, PrimitiveType, PrimitiveCount, 0 /* numindices */, 0 /* start_idx */, idxSize, pIndexData, 0 /* minindex */);
drawPrimitive(iface, PrimitiveType, vertex_count, 0 /* numindices */,
0 /* start_idx */, idxSize, pIndexData, 0 /* minindex */);
This->up_strided = NULL;
return WINED3D_OK;
}

View File

@ -32,56 +32,34 @@ WINE_DEFAULT_DEBUG_CHANNEL(d3d_draw);
#include <stdio.h>
#include <math.h>
/* Issues the glBegin call for gl given the primitive type and count */
static DWORD primitiveToGl(WINED3DPRIMITIVETYPE PrimitiveType,
DWORD NumPrimitives,
GLenum *primType)
/* Note that except for WINED3DPT_POINTLIST and WINED3DPT_LINELIST these
* actually have the same values in GL and D3D. */
static GLenum primitive_to_gl(WINED3DPRIMITIVETYPE primitive_type)
{
DWORD NumVertexes = NumPrimitives;
switch(primitive_type)
{
case WINED3DPT_POINTLIST:
return GL_POINTS;
switch (PrimitiveType) {
case WINED3DPT_POINTLIST:
TRACE("POINTS\n");
*primType = GL_POINTS;
NumVertexes = NumPrimitives;
break;
case WINED3DPT_LINELIST:
return GL_LINES;
case WINED3DPT_LINELIST:
TRACE("LINES\n");
*primType = GL_LINES;
NumVertexes = NumPrimitives * 2;
break;
case WINED3DPT_LINESTRIP:
return GL_LINE_STRIP;
case WINED3DPT_LINESTRIP:
TRACE("LINE_STRIP\n");
*primType = GL_LINE_STRIP;
NumVertexes = NumPrimitives + 1;
break;
case WINED3DPT_TRIANGLELIST:
return GL_TRIANGLES;
case WINED3DPT_TRIANGLELIST:
TRACE("TRIANGLES\n");
*primType = GL_TRIANGLES;
NumVertexes = NumPrimitives * 3;
break;
case WINED3DPT_TRIANGLESTRIP:
return GL_TRIANGLE_STRIP;
case WINED3DPT_TRIANGLESTRIP:
TRACE("TRIANGLE_STRIP\n");
*primType = GL_TRIANGLE_STRIP;
NumVertexes = NumPrimitives + 2;
break;
case WINED3DPT_TRIANGLEFAN:
return GL_TRIANGLE_FAN;
case WINED3DPT_TRIANGLEFAN:
TRACE("TRIANGLE_FAN\n");
*primType = GL_TRIANGLE_FAN;
NumVertexes = NumPrimitives + 2;
break;
default:
FIXME("Unhandled primitive\n");
*primType = GL_POINTS;
break;
default:
FIXME("Unhandled primitive type %s\n", debug_d3dprimitivetype(primitive_type));
return GL_NONE;
}
return NumVertexes;
}
static BOOL fixed_get_input(
@ -829,7 +807,7 @@ static inline void remove_vbos(IWineD3DDeviceImpl *This, WineDirect3DVertexStrid
}
/* Routine common to the draw primitive and draw indexed primitive routines */
void drawPrimitive(IWineD3DDevice *iface, int PrimitiveType, long NumPrimitives,
void drawPrimitive(IWineD3DDevice *iface, WINED3DPRIMITIVETYPE PrimitiveType, UINT index_count,
UINT numberOfVertices, long StartIdx, short idxSize, const void *idxData, int minIndex)
{
@ -837,7 +815,7 @@ void drawPrimitive(IWineD3DDevice *iface, int PrimitiveType, long NumPrimitives,
IWineD3DSurfaceImpl *target;
unsigned int i;
if (NumPrimitives == 0) return;
if (!index_count) return;
/* Invalidate the back buffer memory so LockRect will read it the next time */
for(i = 0; i < GL_LIMITS(buffers); i++) {
@ -870,9 +848,9 @@ void drawPrimitive(IWineD3DDevice *iface, int PrimitiveType, long NumPrimitives,
WineDirect3DVertexStridedData stridedlcl;
/* Ok, Work out which primitive is requested and how many vertexes that
will be */
UINT calculatedNumberOfindices = primitiveToGl(PrimitiveType, NumPrimitives, &glPrimType);
if (numberOfVertices == 0 )
numberOfVertices = calculatedNumberOfindices;
glPrimType = primitive_to_gl(PrimitiveType);
if (!numberOfVertices) numberOfVertices = index_count;
if (!use_vs(This->stateBlock))
{
@ -920,19 +898,17 @@ void drawPrimitive(IWineD3DDevice *iface, int PrimitiveType, long NumPrimitives,
} else {
TRACE("Using immediate mode with vertex shaders for half float emulation\n");
}
drawStridedSlowVs(iface, strided, calculatedNumberOfindices,
glPrimType, idxData, idxSize, minIndex, StartIdx);
drawStridedSlowVs(iface, strided, index_count, glPrimType, idxData, idxSize, minIndex, StartIdx);
} else {
drawStridedSlow(iface, strided, calculatedNumberOfindices,
glPrimType, idxData, idxSize, minIndex, StartIdx);
drawStridedSlow(iface, strided, index_count, glPrimType, idxData, idxSize, minIndex, StartIdx);
}
} else if(This->instancedDraw) {
/* Instancing emulation with mixing immediate mode and arrays */
drawStridedInstanced(iface, &This->strided_streams, calculatedNumberOfindices, glPrimType,
idxData, idxSize, minIndex, StartIdx);
drawStridedInstanced(iface, &This->strided_streams, index_count,
glPrimType, idxData, idxSize, minIndex, StartIdx);
} else {
drawStridedFast(iface, glPrimType, minIndex, minIndex + numberOfVertices - 1,
calculatedNumberOfindices, idxSize, idxData, StartIdx);
index_count, idxSize, idxData, StartIdx);
}
}

View File

@ -653,7 +653,7 @@ extern LONG primCounter;
*/
/* Routine common to the draw primitive and draw indexed primitive routines */
void drawPrimitive(IWineD3DDevice *iface, int PrimitiveType, long NumPrimitives,
void drawPrimitive(IWineD3DDevice *iface, WINED3DPRIMITIVETYPE PrimitiveType, UINT index_count,
UINT numberOfVertices, long start_idx, short idxBytes, const void *idxData, int minIndex);
void primitiveDeclarationConvertToStridedData(

View File

@ -3483,18 +3483,18 @@ interface IWineD3DDevice : IWineD3DBase
HRESULT DrawPrimitive(
[in] WINED3DPRIMITIVETYPE primitive_type,
[in] UINT start_vertex,
[in] UINT primitive_count
[in] UINT vertex_count
);
HRESULT DrawIndexedPrimitive(
[in] WINED3DPRIMITIVETYPE primitive_type,
[in] UINT min_vertex_idx,
[in] UINT vertex_count,
[in] UINT start_idx,
[in] UINT primitive_count
[in] UINT index_count
);
HRESULT DrawPrimitiveUP(
[in] WINED3DPRIMITIVETYPE primitive_type,
[in] UINT primitive_count,
[in] UINT vertex_count,
[in] const void *stream_data,
[in] UINT stream_stride
);
@ -3502,7 +3502,7 @@ interface IWineD3DDevice : IWineD3DBase
[in] WINED3DPRIMITIVETYPE primitive_type,
[in] UINT min_vertex_idx,
[in] UINT vertex_count,
[in] UINT primitive_count,
[in] UINT index_count,
[in] const void *index_data,
[in] WINED3DFORMAT index_data_format,
[in] const void *stream_data,
@ -3510,12 +3510,12 @@ interface IWineD3DDevice : IWineD3DBase
);
HRESULT DrawPrimitiveStrided(
[in] WINED3DPRIMITIVETYPE primitive_type,
[in] UINT primitive_count,
[in] UINT vertex_count,
[in] const WineDirect3DVertexStridedData *strided_data
);
HRESULT DrawIndexedPrimitiveStrided(
[in] WINED3DPRIMITIVETYPE primitive_type,
[in] UINT primitive_count,
[in] UINT index_count,
[in] const WineDirect3DVertexStridedData *strided_data,
[in] UINT vertex_count,
[in] const void *index_data,