2002-11-21 22:04:16 +01:00
|
|
|
/* Direct3D Viewport
|
|
|
|
* Copyright (c) 2002 Lionel ULMER
|
|
|
|
*
|
|
|
|
* This file contains the implementation of Direct3DVertexBuffer COM object
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
#include "windef.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "winbase.h"
|
2002-11-21 22:04:16 +01:00
|
|
|
#include "winerror.h"
|
2002-12-05 21:33:07 +01:00
|
|
|
#include "objbase.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "wingdi.h"
|
2002-11-21 22:04:16 +01:00
|
|
|
#include "ddraw.h"
|
|
|
|
#include "d3d.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
#include "d3d_private.h"
|
2005-06-06 17:51:50 +02:00
|
|
|
#include "opengl_private.h"
|
2002-11-21 22:04:16 +01:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
|
2003-05-20 06:27:04 +02:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(ddraw_geom);
|
2002-11-21 22:04:16 +01:00
|
|
|
|
|
|
|
HRESULT WINAPI
|
|
|
|
Main_IDirect3DVertexBufferImpl_7_1T_QueryInterface(LPDIRECT3DVERTEXBUFFER7 iface,
|
|
|
|
REFIID riid,
|
|
|
|
LPVOID* obp)
|
|
|
|
{
|
|
|
|
ICOM_THIS_FROM(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, iface);
|
|
|
|
TRACE("(%p/%p)->(%s,%p)\n", This, iface, debugstr_guid(riid), obp);
|
|
|
|
|
|
|
|
/* By default, set the object pointer to NULL */
|
|
|
|
*obp = NULL;
|
|
|
|
|
|
|
|
if ( IsEqualGUID( &IID_IUnknown, riid ) ) {
|
|
|
|
IDirect3DVertexBuffer7_AddRef(ICOM_INTERFACE(This,IDirect3DVertexBuffer7));
|
|
|
|
*obp = iface;
|
|
|
|
TRACE(" Creating IUnknown interface at %p.\n", *obp);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
if ( IsEqualGUID( &IID_IDirect3DVertexBuffer, riid ) ) {
|
|
|
|
IDirect3DVertexBuffer7_AddRef(ICOM_INTERFACE(This,IDirect3DVertexBuffer7));
|
|
|
|
*obp = ICOM_INTERFACE(This, IDirect3DVertexBuffer);
|
|
|
|
TRACE(" Creating IDirect3DVertexBuffer interface %p\n", *obp);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
if ( IsEqualGUID( &IID_IDirect3DVertexBuffer7, riid ) ) {
|
|
|
|
IDirect3DVertexBuffer7_AddRef(ICOM_INTERFACE(This,IDirect3DVertexBuffer7));
|
|
|
|
*obp = ICOM_INTERFACE(This, IDirect3DVertexBuffer7);
|
|
|
|
TRACE(" Creating IDirect3DVertexBuffer7 interface %p\n", *obp);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
FIXME("(%p): interface for IID %s NOT found!\n", This, debugstr_guid(riid));
|
|
|
|
return OLE_E_ENUM_NOMORE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG WINAPI
|
|
|
|
Main_IDirect3DVertexBufferImpl_7_1T_AddRef(LPDIRECT3DVERTEXBUFFER7 iface)
|
|
|
|
{
|
|
|
|
ICOM_THIS_FROM(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, iface);
|
2005-01-09 18:29:21 +01:00
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p/%p)->() incrementing from %lu.\n", This, iface, ref - 1);
|
|
|
|
|
|
|
|
return ref;
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ULONG WINAPI
|
|
|
|
Main_IDirect3DVertexBufferImpl_7_1T_Release(LPDIRECT3DVERTEXBUFFER7 iface)
|
|
|
|
{
|
|
|
|
ICOM_THIS_FROM(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, iface);
|
2005-01-09 18:29:21 +01:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, ref + 1);
|
|
|
|
|
|
|
|
if (ref == 0) {
|
2003-01-02 20:54:09 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->vertices);
|
2002-11-21 22:04:16 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
return 0;
|
|
|
|
}
|
2005-01-09 18:29:21 +01:00
|
|
|
return ref;
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI
|
|
|
|
Main_IDirect3DVertexBufferImpl_7_1T_Lock(LPDIRECT3DVERTEXBUFFER7 iface,
|
|
|
|
DWORD dwFlags,
|
|
|
|
LPVOID* lplpData,
|
|
|
|
LPDWORD lpdwSize)
|
|
|
|
{
|
|
|
|
ICOM_THIS_FROM(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, iface);
|
2002-11-30 20:27:19 +01:00
|
|
|
TRACE("(%p/%p)->(%08lx,%p,%p)\n", This, iface, dwFlags, lplpData, lpdwSize);
|
|
|
|
|
|
|
|
if (TRACE_ON(ddraw)) {
|
|
|
|
TRACE(" lock flags : ");
|
|
|
|
DDRAW_dump_lockflag(dwFlags);
|
|
|
|
}
|
|
|
|
|
2004-12-09 15:07:59 +01:00
|
|
|
if (This->processed) {
|
2003-01-03 22:07:22 +01:00
|
|
|
WARN(" application does a Lock on a vertex buffer resulting from a ProcessVertices call. Expect problems !\n");
|
|
|
|
}
|
|
|
|
|
2003-01-03 20:10:48 +01:00
|
|
|
if (This->desc.dwCaps & D3DVBCAPS_OPTIMIZED) return D3DERR_VERTEXBUFFEROPTIMIZED;
|
|
|
|
|
2002-11-30 20:27:19 +01:00
|
|
|
if (lpdwSize != NULL) *lpdwSize = This->vertex_buffer_size;
|
|
|
|
*lplpData = This->vertices;
|
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
return DD_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI
|
|
|
|
Main_IDirect3DVertexBufferImpl_7_1T_Unlock(LPDIRECT3DVERTEXBUFFER7 iface)
|
|
|
|
{
|
|
|
|
ICOM_THIS_FROM(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, iface);
|
2003-01-02 21:02:49 +01:00
|
|
|
TRACE("(%p/%p)->()\n", This, iface);
|
2003-01-02 21:05:48 +01:00
|
|
|
/* Nothing to do here for now. Maybe some optimizations if ever we want to do some :-) */
|
2002-11-21 22:04:16 +01:00
|
|
|
return DD_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI
|
2003-01-03 22:04:12 +01:00
|
|
|
Main_IDirect3DVertexBufferImpl_7_1T_ProcessVertices(LPDIRECT3DVERTEXBUFFER7 iface,
|
|
|
|
DWORD dwVertexOp,
|
|
|
|
DWORD dwDestIndex,
|
|
|
|
DWORD dwCount,
|
|
|
|
LPDIRECT3DVERTEXBUFFER7 lpSrcBuffer,
|
|
|
|
DWORD dwSrcIndex,
|
|
|
|
LPDIRECT3DDEVICE7 lpD3DDevice,
|
|
|
|
DWORD dwFlags)
|
2002-11-21 22:04:16 +01:00
|
|
|
{
|
|
|
|
ICOM_THIS_FROM(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, iface);
|
2003-01-02 21:02:49 +01:00
|
|
|
FIXME("(%p/%p)->(%08lx,%08lx,%08lx,%p,%08lx,%p,%08lx): stub!\n", This, iface, dwVertexOp, dwDestIndex, dwCount, lpSrcBuffer, dwSrcIndex, lpD3DDevice, dwFlags);
|
2002-11-21 22:04:16 +01:00
|
|
|
return DD_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI
|
|
|
|
Main_IDirect3DVertexBufferImpl_7_1T_GetVertexBufferDesc(LPDIRECT3DVERTEXBUFFER7 iface,
|
|
|
|
LPD3DVERTEXBUFFERDESC lpD3DVertexBufferDesc)
|
|
|
|
{
|
2003-01-02 21:02:49 +01:00
|
|
|
DWORD size;
|
2002-11-21 22:04:16 +01:00
|
|
|
ICOM_THIS_FROM(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, iface);
|
2003-01-03 20:10:48 +01:00
|
|
|
|
2003-01-02 21:02:49 +01:00
|
|
|
TRACE("(%p/%p)->(%p)\n", This, iface, lpD3DVertexBufferDesc);
|
2003-01-03 20:10:48 +01:00
|
|
|
|
|
|
|
size = lpD3DVertexBufferDesc->dwSize;
|
|
|
|
memset(lpD3DVertexBufferDesc, 0, size);
|
|
|
|
memcpy(lpD3DVertexBufferDesc, &This->desc,
|
|
|
|
(size < This->desc.dwSize) ? size : This->desc.dwSize);
|
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
return DD_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI
|
2003-01-03 22:04:12 +01:00
|
|
|
Main_IDirect3DVertexBufferImpl_7_1T_Optimize(LPDIRECT3DVERTEXBUFFER7 iface,
|
|
|
|
LPDIRECT3DDEVICE7 lpD3DDevice,
|
|
|
|
DWORD dwFlags)
|
2002-11-21 22:04:16 +01:00
|
|
|
{
|
|
|
|
ICOM_THIS_FROM(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, iface);
|
|
|
|
FIXME("(%p/%p)->(%p,%08lx): stub!\n", This, iface, lpD3DDevice, dwFlags);
|
2003-01-03 20:10:48 +01:00
|
|
|
|
|
|
|
This->desc.dwCaps |= D3DVBCAPS_OPTIMIZED;
|
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
return DD_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI
|
|
|
|
Main_IDirect3DVertexBufferImpl_7_ProcessVerticesStrided(LPDIRECT3DVERTEXBUFFER7 iface,
|
|
|
|
DWORD dwVertexOp,
|
|
|
|
DWORD dwDestIndex,
|
|
|
|
DWORD dwCount,
|
|
|
|
LPD3DDRAWPRIMITIVESTRIDEDDATA lpStrideData,
|
|
|
|
DWORD dwVertexTypeDesc,
|
|
|
|
LPDIRECT3DDEVICE7 lpD3DDevice,
|
|
|
|
DWORD dwFlags)
|
|
|
|
{
|
|
|
|
ICOM_THIS_FROM(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, iface);
|
|
|
|
FIXME("(%p/%p)->(%08lx,%08lx,%08lx,%p,%08lx,%p,%08lx): stub!\n", This, iface, dwVertexOp, dwDestIndex, dwCount, lpStrideData, dwVertexTypeDesc, lpD3DDevice, dwFlags);
|
|
|
|
return DD_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI
|
2003-01-03 22:04:12 +01:00
|
|
|
Thunk_IDirect3DVertexBufferImpl_1_ProcessVertices(LPDIRECT3DVERTEXBUFFER iface,
|
|
|
|
DWORD dwVertexOp,
|
|
|
|
DWORD dwDestIndex,
|
|
|
|
DWORD dwCount,
|
|
|
|
LPDIRECT3DVERTEXBUFFER lpSrcBuffer,
|
|
|
|
DWORD dwSrcIndex,
|
|
|
|
LPDIRECT3DDEVICE3 lpD3DDevice,
|
|
|
|
DWORD dwFlags)
|
2002-11-21 22:04:16 +01:00
|
|
|
{
|
2003-01-03 22:04:12 +01:00
|
|
|
TRACE("(%p)->(%08lx,%08lx,%08lx,%p,%08lx,%p,%08lx) thunking to IDirect3DVertexBuffer7 interface.\n", iface,
|
|
|
|
dwVertexOp, dwDestIndex, dwCount, lpSrcBuffer, dwSrcIndex, lpD3DDevice, dwFlags);
|
|
|
|
return IDirect3DVertexBuffer7_ProcessVertices(COM_INTERFACE_CAST(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer, IDirect3DVertexBuffer7, iface),
|
|
|
|
dwVertexOp,
|
|
|
|
dwDestIndex,
|
|
|
|
dwCount,
|
|
|
|
COM_INTERFACE_CAST(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer, IDirect3DVertexBuffer7, lpSrcBuffer),
|
|
|
|
dwSrcIndex,
|
|
|
|
COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice3, IDirect3DDevice7, lpD3DDevice),
|
|
|
|
dwFlags);
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI
|
2003-01-03 22:04:12 +01:00
|
|
|
Thunk_IDirect3DVertexBufferImpl_1_Optimize(LPDIRECT3DVERTEXBUFFER iface,
|
|
|
|
LPDIRECT3DDEVICE3 lpD3DDevice,
|
|
|
|
DWORD dwFlags)
|
2002-11-21 22:04:16 +01:00
|
|
|
{
|
2003-01-03 22:04:12 +01:00
|
|
|
TRACE("(%p)->(%p,%08lx) thunking to IDirect3DVertexBuffer7 interface.\n", iface, lpD3DDevice, dwFlags);
|
|
|
|
return IDirect3DVertexBuffer7_Optimize(COM_INTERFACE_CAST(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer, IDirect3DVertexBuffer7, iface),
|
|
|
|
COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice3, IDirect3DDevice7, lpD3DDevice),
|
|
|
|
dwFlags);
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI
|
|
|
|
Thunk_IDirect3DVertexBufferImpl_1_QueryInterface(LPDIRECT3DVERTEXBUFFER iface,
|
|
|
|
REFIID riid,
|
|
|
|
LPVOID* obp)
|
|
|
|
{
|
|
|
|
TRACE("(%p)->(%s,%p) thunking to IDirect3DVertexBuffer7 interface.\n", iface, debugstr_guid(riid), obp);
|
|
|
|
return IDirect3DVertexBuffer7_QueryInterface(COM_INTERFACE_CAST(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer, IDirect3DVertexBuffer7, iface),
|
|
|
|
riid,
|
|
|
|
obp);
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG WINAPI
|
|
|
|
Thunk_IDirect3DVertexBufferImpl_1_AddRef(LPDIRECT3DVERTEXBUFFER iface)
|
|
|
|
{
|
|
|
|
TRACE("(%p)->() thunking to IDirect3DVertexBuffer7 interface.\n", iface);
|
|
|
|
return IDirect3DVertexBuffer7_AddRef(COM_INTERFACE_CAST(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer, IDirect3DVertexBuffer7, iface));
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG WINAPI
|
|
|
|
Thunk_IDirect3DVertexBufferImpl_1_Release(LPDIRECT3DVERTEXBUFFER iface)
|
|
|
|
{
|
|
|
|
TRACE("(%p)->() thunking to IDirect3DVertexBuffer7 interface.\n", iface);
|
|
|
|
return IDirect3DVertexBuffer7_Release(COM_INTERFACE_CAST(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer, IDirect3DVertexBuffer7, iface));
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI
|
|
|
|
Thunk_IDirect3DVertexBufferImpl_1_Lock(LPDIRECT3DVERTEXBUFFER iface,
|
|
|
|
DWORD dwFlags,
|
|
|
|
LPVOID* lplpData,
|
|
|
|
LPDWORD lpdwSize)
|
|
|
|
{
|
|
|
|
TRACE("(%p)->(%08lx,%p,%p) thunking to IDirect3DVertexBuffer7 interface.\n", iface, dwFlags, lplpData, lpdwSize);
|
|
|
|
return IDirect3DVertexBuffer7_Lock(COM_INTERFACE_CAST(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer, IDirect3DVertexBuffer7, iface),
|
|
|
|
dwFlags,
|
|
|
|
lplpData,
|
|
|
|
lpdwSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI
|
|
|
|
Thunk_IDirect3DVertexBufferImpl_1_Unlock(LPDIRECT3DVERTEXBUFFER iface)
|
|
|
|
{
|
|
|
|
TRACE("(%p)->() thunking to IDirect3DVertexBuffer7 interface.\n", iface);
|
|
|
|
return IDirect3DVertexBuffer7_Unlock(COM_INTERFACE_CAST(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer, IDirect3DVertexBuffer7, iface));
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI
|
|
|
|
Thunk_IDirect3DVertexBufferImpl_1_GetVertexBufferDesc(LPDIRECT3DVERTEXBUFFER iface,
|
|
|
|
LPD3DVERTEXBUFFERDESC lpD3DVertexBufferDesc)
|
|
|
|
{
|
|
|
|
TRACE("(%p)->(%p) thunking to IDirect3DVertexBuffer7 interface.\n", iface, lpD3DVertexBufferDesc);
|
|
|
|
return IDirect3DVertexBuffer7_GetVertexBufferDesc(COM_INTERFACE_CAST(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer, IDirect3DVertexBuffer7, iface),
|
|
|
|
lpD3DVertexBufferDesc);
|
|
|
|
}
|
|
|
|
|
2003-01-03 22:07:22 +01:00
|
|
|
#define copy_and_next(dest, src, size) memcpy(dest, src, size); dest += (size)
|
|
|
|
|
|
|
|
static HRESULT
|
|
|
|
process_vertices_strided(IDirect3DVertexBufferImpl *This,
|
|
|
|
DWORD dwVertexOp,
|
|
|
|
DWORD dwDestIndex,
|
|
|
|
DWORD dwCount,
|
|
|
|
LPD3DDRAWPRIMITIVESTRIDEDDATA lpStrideData,
|
|
|
|
DWORD dwVertexTypeDesc,
|
|
|
|
IDirect3DDeviceImpl *device_impl,
|
|
|
|
DWORD dwFlags)
|
|
|
|
{
|
|
|
|
IDirect3DVertexBufferGLImpl *glThis = (IDirect3DVertexBufferGLImpl *) This;
|
|
|
|
DWORD size = get_flexible_vertex_size(dwVertexTypeDesc);
|
|
|
|
char *dest_ptr;
|
2004-09-08 03:23:57 +02:00
|
|
|
unsigned int i;
|
2003-01-03 22:07:22 +01:00
|
|
|
|
|
|
|
This->processed = TRUE;
|
|
|
|
|
|
|
|
/* For the moment, the trick is to save the transform and lighting state at process
|
|
|
|
time to restore them at drawing time.
|
|
|
|
|
|
|
|
The BIG problem with this method is nothing prevents D3D to do dirty tricks like
|
|
|
|
processing two different sets of vertices with two different rendering parameters
|
|
|
|
and then to display them using the same DrawPrimitive call.
|
|
|
|
|
|
|
|
It would be nice to check for such code here (but well, even this is not trivial
|
|
|
|
to do).
|
|
|
|
|
|
|
|
This is exactly what the TWIST.EXE demo does but using the same kind of ugly stuff
|
|
|
|
in the D3DExecuteBuffer code. I really wonder why Microsoft went back in time when
|
|
|
|
implementing this mostly useless (IMHO) API.
|
|
|
|
*/
|
|
|
|
glThis->dwVertexTypeDesc = dwVertexTypeDesc;
|
|
|
|
|
|
|
|
if (dwVertexTypeDesc & D3DFVF_NORMAL) {
|
|
|
|
WARN(" lighting state not saved yet... Some strange stuff may happen !\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (glThis->vertices == NULL) {
|
|
|
|
glThis->vertices = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size * This->desc.dwNumVertices);
|
|
|
|
}
|
|
|
|
dest_ptr = ((char *) glThis->vertices) + dwDestIndex * size;
|
|
|
|
|
|
|
|
memcpy(&(glThis->world_mat), device_impl->world_mat, sizeof(D3DMATRIX));
|
|
|
|
memcpy(&(glThis->view_mat), device_impl->view_mat, sizeof(D3DMATRIX));
|
|
|
|
memcpy(&(glThis->proj_mat), device_impl->proj_mat, sizeof(D3DMATRIX));
|
|
|
|
|
|
|
|
for (i = 0; i < dwCount; i++) {
|
2004-09-08 03:23:57 +02:00
|
|
|
unsigned int tex_index;
|
2003-01-03 22:07:22 +01:00
|
|
|
|
|
|
|
if ((dwVertexTypeDesc & D3DFVF_POSITION_MASK) == D3DFVF_XYZ) {
|
|
|
|
D3DVALUE *position =
|
|
|
|
(D3DVALUE *) (((char *) lpStrideData->position.lpvData) + i * lpStrideData->position.dwStride);
|
|
|
|
copy_and_next(dest_ptr, position, 3 * sizeof(D3DVALUE));
|
|
|
|
} else if ((dwVertexTypeDesc & D3DFVF_POSITION_MASK) == D3DFVF_XYZRHW) {
|
|
|
|
D3DVALUE *position =
|
|
|
|
(D3DVALUE *) (((char *) lpStrideData->position.lpvData) + i * lpStrideData->position.dwStride);
|
|
|
|
copy_and_next(dest_ptr, position, 4 * sizeof(D3DVALUE));
|
|
|
|
}
|
|
|
|
if (dwVertexTypeDesc & D3DFVF_RESERVED1) {
|
|
|
|
dest_ptr += sizeof(DWORD);
|
|
|
|
}
|
|
|
|
if (dwVertexTypeDesc & D3DFVF_NORMAL) {
|
|
|
|
D3DVALUE *normal =
|
|
|
|
(D3DVALUE *) (((char *) lpStrideData->normal.lpvData) + i * lpStrideData->normal.dwStride);
|
|
|
|
copy_and_next(dest_ptr, normal, 3 * sizeof(D3DVALUE));
|
|
|
|
}
|
|
|
|
if (dwVertexTypeDesc & D3DFVF_DIFFUSE) {
|
|
|
|
DWORD *color_d =
|
|
|
|
(DWORD *) (((char *) lpStrideData->diffuse.lpvData) + i * lpStrideData->diffuse.dwStride);
|
|
|
|
copy_and_next(dest_ptr, color_d, sizeof(DWORD));
|
|
|
|
}
|
|
|
|
if (dwVertexTypeDesc & D3DFVF_SPECULAR) {
|
|
|
|
DWORD *color_s =
|
|
|
|
(DWORD *) (((char *) lpStrideData->specular.lpvData) + i * lpStrideData->specular.dwStride);
|
|
|
|
copy_and_next(dest_ptr, color_s, sizeof(DWORD));
|
|
|
|
}
|
2005-06-12 12:43:11 +02:00
|
|
|
for (tex_index = 0; tex_index < GET_TEXCOUNT_FROM_FVF(dwVertexTypeDesc); tex_index++) {
|
2003-01-03 22:07:22 +01:00
|
|
|
D3DVALUE *tex_coord =
|
|
|
|
(D3DVALUE *) (((char *) lpStrideData->textureCoords[tex_index].lpvData) +
|
|
|
|
i * lpStrideData->textureCoords[tex_index].dwStride);
|
2005-06-12 12:43:11 +02:00
|
|
|
copy_and_next(dest_ptr, tex_coord, GET_TEXCOORD_SIZE_FROM_FVF(dwVertexTypeDesc, i) * sizeof(D3DVALUE));
|
2003-01-03 22:07:22 +01:00
|
|
|
}
|
|
|
|
|
2003-05-20 06:27:04 +02:00
|
|
|
if (TRACE_ON(ddraw_geom)) {
|
2003-01-03 22:07:22 +01:00
|
|
|
if ((dwVertexTypeDesc & D3DFVF_POSITION_MASK) == D3DFVF_XYZ) {
|
|
|
|
D3DVALUE *position =
|
|
|
|
(D3DVALUE *) (((char *) lpStrideData->position.lpvData) + i * lpStrideData->position.dwStride);
|
2003-05-20 06:27:04 +02:00
|
|
|
TRACE_(ddraw_geom)(" %f %f %f", position[0], position[1], position[2]);
|
2003-01-03 22:07:22 +01:00
|
|
|
} else if ((dwVertexTypeDesc & D3DFVF_POSITION_MASK) == D3DFVF_XYZRHW) {
|
|
|
|
D3DVALUE *position =
|
|
|
|
(D3DVALUE *) (((char *) lpStrideData->position.lpvData) + i * lpStrideData->position.dwStride);
|
2003-05-20 06:27:04 +02:00
|
|
|
TRACE_(ddraw_geom)(" %f %f %f %f", position[0], position[1], position[2], position[3]);
|
2003-01-03 22:07:22 +01:00
|
|
|
}
|
|
|
|
if (dwVertexTypeDesc & D3DFVF_NORMAL) {
|
|
|
|
D3DVALUE *normal =
|
|
|
|
(D3DVALUE *) (((char *) lpStrideData->normal.lpvData) + i * lpStrideData->normal.dwStride);
|
2003-05-20 06:27:04 +02:00
|
|
|
TRACE_(ddraw_geom)(" / %f %f %f", normal[0], normal[1], normal[2]);
|
2003-01-03 22:07:22 +01:00
|
|
|
}
|
|
|
|
if (dwVertexTypeDesc & D3DFVF_DIFFUSE) {
|
|
|
|
DWORD *color_d =
|
|
|
|
(DWORD *) (((char *) lpStrideData->diffuse.lpvData) + i * lpStrideData->diffuse.dwStride);
|
2003-05-20 06:27:04 +02:00
|
|
|
TRACE_(ddraw_geom)(" / %02lx %02lx %02lx %02lx",
|
|
|
|
(*color_d >> 16) & 0xFF,
|
|
|
|
(*color_d >> 8) & 0xFF,
|
|
|
|
(*color_d >> 0) & 0xFF,
|
|
|
|
(*color_d >> 24) & 0xFF);
|
2003-01-03 22:07:22 +01:00
|
|
|
}
|
|
|
|
if (dwVertexTypeDesc & D3DFVF_SPECULAR) {
|
|
|
|
DWORD *color_s =
|
|
|
|
(DWORD *) (((char *) lpStrideData->specular.lpvData) + i * lpStrideData->specular.dwStride);
|
2003-05-20 06:27:04 +02:00
|
|
|
TRACE_(ddraw_geom)(" / %02lx %02lx %02lx %02lx",
|
|
|
|
(*color_s >> 16) & 0xFF,
|
|
|
|
(*color_s >> 8) & 0xFF,
|
|
|
|
(*color_s >> 0) & 0xFF,
|
|
|
|
(*color_s >> 24) & 0xFF);
|
2003-01-03 22:07:22 +01:00
|
|
|
}
|
2005-06-12 12:43:11 +02:00
|
|
|
for (tex_index = 0; tex_index < GET_TEXCOUNT_FROM_FVF(dwVertexTypeDesc); tex_index++) {
|
2003-01-03 22:07:22 +01:00
|
|
|
D3DVALUE *tex_coord =
|
|
|
|
(D3DVALUE *) (((char *) lpStrideData->textureCoords[tex_index].lpvData) +
|
|
|
|
i * lpStrideData->textureCoords[tex_index].dwStride);
|
2005-06-12 12:43:11 +02:00
|
|
|
switch (GET_TEXCOORD_SIZE_FROM_FVF(dwVertexTypeDesc, tex_index)) {
|
|
|
|
case 1: TRACE_(ddraw_geom)(" / %f", tex_coord[0]); break;
|
|
|
|
case 2: TRACE_(ddraw_geom)(" / %f %f", tex_coord[0], tex_coord[1]); break;
|
|
|
|
case 3: TRACE_(ddraw_geom)(" / %f %f %f", tex_coord[0], tex_coord[1], tex_coord[2]); break;
|
|
|
|
case 4: TRACE_(ddraw_geom)(" / %f %f %f %f", tex_coord[0], tex_coord[1], tex_coord[2], tex_coord[3]); break;
|
|
|
|
default: TRACE_(ddraw_geom)("Invalid texture size (%ld) !!!", GET_TEXCOORD_SIZE_FROM_FVF(dwVertexTypeDesc, tex_index)); break;
|
|
|
|
}
|
2003-01-03 22:07:22 +01:00
|
|
|
}
|
2003-05-20 06:27:04 +02:00
|
|
|
TRACE_(ddraw_geom)("\n");
|
2003-01-03 22:07:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return DD_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef copy_and_next
|
|
|
|
|
|
|
|
HRESULT WINAPI
|
|
|
|
GL_IDirect3DVertexBufferImpl_7_1T_ProcessVertices(LPDIRECT3DVERTEXBUFFER7 iface,
|
|
|
|
DWORD dwVertexOp,
|
|
|
|
DWORD dwDestIndex,
|
|
|
|
DWORD dwCount,
|
|
|
|
LPDIRECT3DVERTEXBUFFER7 lpSrcBuffer,
|
|
|
|
DWORD dwSrcIndex,
|
|
|
|
LPDIRECT3DDEVICE7 lpD3DDevice,
|
|
|
|
DWORD dwFlags)
|
|
|
|
{
|
|
|
|
ICOM_THIS_FROM(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, iface);
|
|
|
|
IDirect3DVertexBufferImpl *src_impl = ICOM_OBJECT(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, lpSrcBuffer);
|
|
|
|
IDirect3DDeviceImpl *device_impl = ICOM_OBJECT(IDirect3DDeviceImpl, IDirect3DDevice7, lpD3DDevice);
|
|
|
|
D3DDRAWPRIMITIVESTRIDEDDATA strided;
|
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
TRACE("(%p/%p)->(%08lx,%08lx,%08lx,%p,%08lx,%p,%08lx)\n", This, iface, dwVertexOp, dwDestIndex, dwCount, lpSrcBuffer, dwSrcIndex, lpD3DDevice, dwFlags);
|
|
|
|
|
|
|
|
if (TRACE_ON(ddraw)) {
|
2003-03-15 01:12:42 +01:00
|
|
|
TRACE(" - vertex operations : "); dump_D3DVOP(dwVertexOp);
|
|
|
|
TRACE(" - flags : "); dump_D3DPV(dwFlags);
|
2003-01-03 22:07:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((dwVertexOp & D3DVOP_TRANSFORM) == 0) return DDERR_INVALIDPARAMS;
|
|
|
|
|
|
|
|
size = get_flexible_vertex_size(src_impl->desc.dwFVF);
|
2003-02-12 22:40:25 +01:00
|
|
|
convert_FVF_to_strided_data(src_impl->desc.dwFVF, ((char *) src_impl->vertices) + dwSrcIndex * size, &strided, 0);
|
2003-01-03 22:07:22 +01:00
|
|
|
|
|
|
|
return process_vertices_strided(This, dwVertexOp, dwDestIndex, dwCount, &strided, src_impl->desc.dwFVF, device_impl, dwFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI
|
|
|
|
GL_IDirect3DVertexBufferImpl_7_ProcessVerticesStrided(LPDIRECT3DVERTEXBUFFER7 iface,
|
|
|
|
DWORD dwVertexOp,
|
|
|
|
DWORD dwDestIndex,
|
|
|
|
DWORD dwCount,
|
|
|
|
LPD3DDRAWPRIMITIVESTRIDEDDATA lpStrideData,
|
|
|
|
DWORD dwVertexTypeDesc,
|
|
|
|
LPDIRECT3DDEVICE7 lpD3DDevice,
|
|
|
|
DWORD dwFlags)
|
|
|
|
{
|
|
|
|
ICOM_THIS_FROM(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, iface);
|
|
|
|
IDirect3DDeviceImpl *device_impl = ICOM_OBJECT(IDirect3DDeviceImpl, IDirect3DDevice7, lpD3DDevice);
|
|
|
|
|
|
|
|
TRACE("(%p/%p)->(%08lx,%08lx,%08lx,%p,%08lx,%p,%08lx)\n", This, iface, dwVertexOp, dwDestIndex, dwCount, lpStrideData, dwVertexTypeDesc, lpD3DDevice, dwFlags);
|
|
|
|
if (TRACE_ON(ddraw)) {
|
2003-03-15 01:12:42 +01:00
|
|
|
TRACE(" - vertex operations : "); dump_D3DVOP(dwVertexOp);
|
|
|
|
TRACE(" - flags : "); dump_D3DPV(dwFlags);
|
|
|
|
TRACE(" - vertex format : "); dump_flexible_vertex(dwVertexTypeDesc);
|
2003-01-03 22:07:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((dwVertexOp & D3DVOP_TRANSFORM) == 0) return DDERR_INVALIDPARAMS;
|
|
|
|
|
|
|
|
return process_vertices_strided(This, dwVertexOp, dwDestIndex, dwCount, lpStrideData, dwVertexTypeDesc, device_impl, dwFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
#if !defined(__STRICT_ANSI__) && defined(__GNUC__)
|
|
|
|
# define XCAST(fun) (typeof(VTABLE_IDirect3DVertexBuffer7.fun))
|
|
|
|
#else
|
|
|
|
# define XCAST(fun) (void*)
|
|
|
|
#endif
|
|
|
|
|
2005-05-27 22:17:35 +02:00
|
|
|
static const IDirect3DVertexBuffer7Vtbl VTABLE_IDirect3DVertexBuffer7 =
|
2002-11-21 22:04:16 +01:00
|
|
|
{
|
|
|
|
XCAST(QueryInterface) Main_IDirect3DVertexBufferImpl_7_1T_QueryInterface,
|
|
|
|
XCAST(AddRef) Main_IDirect3DVertexBufferImpl_7_1T_AddRef,
|
|
|
|
XCAST(Release) Main_IDirect3DVertexBufferImpl_7_1T_Release,
|
|
|
|
XCAST(Lock) Main_IDirect3DVertexBufferImpl_7_1T_Lock,
|
|
|
|
XCAST(Unlock) Main_IDirect3DVertexBufferImpl_7_1T_Unlock,
|
2003-01-03 22:07:22 +01:00
|
|
|
XCAST(ProcessVertices) GL_IDirect3DVertexBufferImpl_7_1T_ProcessVertices,
|
2002-11-21 22:04:16 +01:00
|
|
|
XCAST(GetVertexBufferDesc) Main_IDirect3DVertexBufferImpl_7_1T_GetVertexBufferDesc,
|
2003-01-03 22:04:12 +01:00
|
|
|
XCAST(Optimize) Main_IDirect3DVertexBufferImpl_7_1T_Optimize,
|
2003-01-03 22:07:22 +01:00
|
|
|
XCAST(ProcessVerticesStrided) GL_IDirect3DVertexBufferImpl_7_ProcessVerticesStrided
|
2002-11-21 22:04:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#if !defined(__STRICT_ANSI__) && defined(__GNUC__)
|
|
|
|
#undef XCAST
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if !defined(__STRICT_ANSI__) && defined(__GNUC__)
|
|
|
|
# define XCAST(fun) (typeof(VTABLE_IDirect3DVertexBuffer.fun))
|
|
|
|
#else
|
|
|
|
# define XCAST(fun) (void*)
|
|
|
|
#endif
|
|
|
|
|
2005-05-27 22:17:35 +02:00
|
|
|
static const IDirect3DVertexBufferVtbl VTABLE_IDirect3DVertexBuffer =
|
2002-11-21 22:04:16 +01:00
|
|
|
{
|
2003-01-02 21:02:49 +01:00
|
|
|
XCAST(QueryInterface) Thunk_IDirect3DVertexBufferImpl_1_QueryInterface,
|
|
|
|
XCAST(AddRef) Thunk_IDirect3DVertexBufferImpl_1_AddRef,
|
|
|
|
XCAST(Release) Thunk_IDirect3DVertexBufferImpl_1_Release,
|
|
|
|
XCAST(Lock) Thunk_IDirect3DVertexBufferImpl_1_Lock,
|
|
|
|
XCAST(Unlock) Thunk_IDirect3DVertexBufferImpl_1_Unlock,
|
2003-01-03 22:04:12 +01:00
|
|
|
XCAST(ProcessVertices) Thunk_IDirect3DVertexBufferImpl_1_ProcessVertices,
|
2002-11-21 22:04:16 +01:00
|
|
|
XCAST(GetVertexBufferDesc) Thunk_IDirect3DVertexBufferImpl_1_GetVertexBufferDesc,
|
2003-01-03 22:04:12 +01:00
|
|
|
XCAST(Optimize) Thunk_IDirect3DVertexBufferImpl_1_Optimize
|
2002-11-21 22:04:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#if !defined(__STRICT_ANSI__) && defined(__GNUC__)
|
|
|
|
#undef XCAST
|
|
|
|
#endif
|
|
|
|
|
2003-06-05 01:31:39 +02:00
|
|
|
HRESULT d3dvertexbuffer_create(IDirect3DVertexBufferImpl **obj, IDirectDrawImpl *d3d, LPD3DVERTEXBUFFERDESC lpD3DVertBufDesc, DWORD dwFlags)
|
2002-11-21 22:04:16 +01:00
|
|
|
{
|
|
|
|
IDirect3DVertexBufferImpl *object;
|
2002-11-30 20:27:19 +01:00
|
|
|
static const flag_info flags[] = {
|
2003-01-03 20:10:48 +01:00
|
|
|
FE(D3DVBCAPS_DONOTCLIP),
|
2002-11-30 20:27:19 +01:00
|
|
|
FE(D3DVBCAPS_OPTIMIZED),
|
|
|
|
FE(D3DVBCAPS_SYSTEMMEMORY),
|
|
|
|
FE(D3DVBCAPS_WRITEONLY)
|
|
|
|
};
|
2002-11-21 22:04:16 +01:00
|
|
|
|
2003-01-03 22:07:22 +01:00
|
|
|
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVertexBufferGLImpl));
|
2002-11-21 22:04:16 +01:00
|
|
|
if (object == NULL) return DDERR_OUTOFMEMORY;
|
|
|
|
|
|
|
|
object->ref = 1;
|
|
|
|
object->d3d = d3d;
|
2002-11-30 20:27:19 +01:00
|
|
|
object->desc = *lpD3DVertBufDesc;
|
2003-01-03 22:07:22 +01:00
|
|
|
object->vertex_buffer_size = get_flexible_vertex_size(lpD3DVertBufDesc->dwFVF) * lpD3DVertBufDesc->dwNumVertices;
|
2002-11-30 20:27:19 +01:00
|
|
|
object->vertices = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, object->vertex_buffer_size);
|
2002-11-21 22:04:16 +01:00
|
|
|
|
|
|
|
ICOM_INIT_INTERFACE(object, IDirect3DVertexBuffer, VTABLE_IDirect3DVertexBuffer);
|
|
|
|
ICOM_INIT_INTERFACE(object, IDirect3DVertexBuffer7, VTABLE_IDirect3DVertexBuffer7);
|
|
|
|
|
|
|
|
*obj = object;
|
|
|
|
|
2002-11-30 20:27:19 +01:00
|
|
|
if (TRACE_ON(ddraw)) {
|
|
|
|
TRACE(" creating implementation at %p with description : \n", *obj);
|
2003-01-02 20:54:09 +01:00
|
|
|
TRACE(" flags : "); DDRAW_dump_flags_(lpD3DVertBufDesc->dwCaps, flags, sizeof(flags)/sizeof(flags[0]), TRUE);
|
|
|
|
TRACE(" vertex type : "); dump_flexible_vertex(lpD3DVertBufDesc->dwFVF);
|
|
|
|
TRACE(" num vertices : %ld\n", lpD3DVertBufDesc->dwNumVertices);
|
2002-11-30 20:27:19 +01:00
|
|
|
}
|
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
|
|
|
|
return D3D_OK;
|
|
|
|
}
|