2001-01-04 23:44:55 +01:00
|
|
|
/* DirectDraw/Direct3D Z-Buffer stand in
|
|
|
|
*
|
|
|
|
* Copyright 2000 TransGaming Technologies Inc.
|
|
|
|
*
|
|
|
|
* This class provides a DirectDrawSurface implementation that represents
|
|
|
|
* a Z-Buffer surface. However it does not store an image and does not
|
|
|
|
* support Lock/Unlock or GetDC. It is merely a placeholder required by the
|
|
|
|
* Direct3D architecture.
|
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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2001-01-04 23:44:55 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2001-01-04 23:44:55 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
2003-01-07 21:36:20 +01:00
|
|
|
#define NONAMELESSUNION
|
|
|
|
#define NONAMELESSSTRUCT
|
2005-05-27 22:17:35 +02:00
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wingdi.h"
|
2001-01-25 23:23:08 +01:00
|
|
|
#include "ddraw.h"
|
|
|
|
#include "d3d.h"
|
2001-01-04 23:44:55 +01:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2001-01-04 23:44:55 +01:00
|
|
|
|
|
|
|
#include "ddcomimpl.h"
|
|
|
|
#include "ddraw_private.h"
|
2003-01-02 20:58:21 +01:00
|
|
|
#include "d3d_private.h"
|
2001-01-04 23:44:55 +01:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
|
2001-01-04 23:44:55 +01:00
|
|
|
|
2005-05-27 22:17:35 +02:00
|
|
|
static const IDirectDrawSurface7Vtbl FakeZBuffer_IDirectDrawSurface7_VTable;
|
2001-01-04 23:44:55 +01:00
|
|
|
|
2003-09-15 22:00:03 +02:00
|
|
|
#ifdef HAVE_OPENGL
|
|
|
|
static void zbuffer_lock_update(IDirectDrawSurfaceImpl* This, LPCRECT pRect, DWORD dwFlags)
|
|
|
|
{
|
|
|
|
/* Note that this does not do anything for now... At least it's not needed for Grim Fandango :-) */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void zbuffer_unlock_update(IDirectDrawSurfaceImpl* This, LPCRECT pRect)
|
|
|
|
{
|
|
|
|
((FakeZBuffer_DirectDrawSurfaceImpl *) This->private)->in_memory = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOLEAN zbuffer_get_dirty_status(IDirectDrawSurfaceImpl* This, LPCRECT pRect)
|
|
|
|
{
|
2004-12-09 15:07:59 +01:00
|
|
|
if (((FakeZBuffer_DirectDrawSurfaceImpl *) This->private)->in_memory) {
|
2003-09-15 22:00:03 +02:00
|
|
|
((FakeZBuffer_DirectDrawSurfaceImpl *) This->private)->in_memory = FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-01-04 23:44:55 +01:00
|
|
|
HRESULT FakeZBuffer_DirectDrawSurface_Construct(IDirectDrawSurfaceImpl *This,
|
|
|
|
IDirectDrawImpl *pDD,
|
|
|
|
const DDSURFACEDESC2 *pDDSD)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
2003-09-15 22:00:03 +02:00
|
|
|
BYTE zdepth = 16; /* Default value.. Should use the one from GL */
|
|
|
|
|
2001-01-04 23:44:55 +01:00
|
|
|
assert(pDDSD->ddsCaps.dwCaps & DDSCAPS_ZBUFFER);
|
|
|
|
|
|
|
|
hr = Main_DirectDrawSurface_Construct(This, pDD, pDDSD);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
ICOM_INIT_INTERFACE(This, IDirectDrawSurface7,
|
|
|
|
FakeZBuffer_IDirectDrawSurface7_VTable);
|
|
|
|
|
|
|
|
This->final_release = FakeZBuffer_DirectDrawSurface_final_release;
|
|
|
|
This->duplicate_surface = FakeZBuffer_DirectDrawSurface_duplicate_surface;
|
|
|
|
|
2003-09-15 22:00:03 +02:00
|
|
|
#ifdef HAVE_OPENGL
|
|
|
|
if (opengl_initialized) {
|
|
|
|
This->lock_update = zbuffer_lock_update;
|
|
|
|
This->unlock_update = zbuffer_unlock_update;
|
|
|
|
This->get_dirty_status = zbuffer_get_dirty_status;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* Beginning of some D3D hacks :-) */
|
|
|
|
if (This->surface_desc.dwFlags & DDSD_ZBUFFERBITDEPTH) {
|
|
|
|
zdepth = This->surface_desc.u2.dwMipMapCount; /* This is where the Z buffer depth is stored in 'old' versions */
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((This->surface_desc.dwFlags & DDSD_PIXELFORMAT) == 0) {
|
|
|
|
This->surface_desc.dwFlags |= DDSD_PIXELFORMAT;
|
|
|
|
This->surface_desc.u4.ddpfPixelFormat.dwSize = sizeof(This->surface_desc.u4.ddpfPixelFormat);
|
|
|
|
This->surface_desc.u4.ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
|
|
|
|
This->surface_desc.u4.ddpfPixelFormat.u1.dwZBufferBitDepth = zdepth;
|
|
|
|
}
|
|
|
|
if ((This->surface_desc.dwFlags & DDSD_PITCH) == 0) {
|
|
|
|
This->surface_desc.dwFlags |= DDSD_PITCH;
|
|
|
|
This->surface_desc.u1.lPitch = ((zdepth + 7) / 8) * This->surface_desc.dwWidth;
|
|
|
|
}
|
|
|
|
This->surface_desc.lpSurface = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
This->surface_desc.u1.lPitch * This->surface_desc.dwHeight);
|
|
|
|
|
2001-01-04 23:44:55 +01:00
|
|
|
return DD_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Not an API */
|
|
|
|
HRESULT FakeZBuffer_DirectDrawSurface_Create(IDirectDrawImpl* pDD,
|
|
|
|
const DDSURFACEDESC2* pDDSD,
|
|
|
|
LPDIRECTDRAWSURFACE7* ppSurf,
|
|
|
|
IUnknown* pUnkOuter)
|
|
|
|
{
|
|
|
|
IDirectDrawSurfaceImpl* This;
|
|
|
|
HRESULT hr;
|
|
|
|
assert(pUnkOuter == NULL);
|
|
|
|
|
|
|
|
This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
sizeof(*This)
|
|
|
|
+ sizeof(FakeZBuffer_DirectDrawSurfaceImpl));
|
|
|
|
if (This == NULL) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
This->private = (FakeZBuffer_DirectDrawSurfaceImpl*)(This+1);
|
|
|
|
|
|
|
|
hr = FakeZBuffer_DirectDrawSurface_Construct(This, pDD, pDDSD);
|
|
|
|
if (FAILED(hr))
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
else
|
|
|
|
*ppSurf = ICOM_INTERFACE(This, IDirectDrawSurface7);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FakeZBuffer_DirectDrawSurface_final_release(IDirectDrawSurfaceImpl* This)
|
|
|
|
{
|
2002-07-03 03:20:07 +02:00
|
|
|
Main_DirectDrawSurface_final_release(This);
|
2001-01-04 23:44:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT
|
|
|
|
FakeZBuffer_DirectDrawSurface_duplicate_surface(IDirectDrawSurfaceImpl* This,
|
|
|
|
LPDIRECTDRAWSURFACE7* ppDup)
|
|
|
|
{
|
|
|
|
return FakeZBuffer_DirectDrawSurface_Create(This->ddraw_owner,
|
|
|
|
&This->surface_desc, ppDup,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* put your breakpoint/abort call here */
|
|
|
|
static HRESULT cant_do_that(const char *s)
|
|
|
|
{
|
|
|
|
FIXME("attempt to %s fake z-buffer\n", s);
|
|
|
|
return DDERR_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI
|
|
|
|
FakeZBuffer_DirectDrawSurface_Blt(LPDIRECTDRAWSURFACE7 iface, LPRECT rdst,
|
|
|
|
LPDIRECTDRAWSURFACE7 src, LPRECT rsrc,
|
|
|
|
DWORD dwFlags, LPDDBLTFX lpbltfx)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
|
2003-01-02 20:58:21 +01:00
|
|
|
|
|
|
|
if (TRACE_ON(ddraw)) {
|
|
|
|
TRACE("(%p)->(%p,%p,%p,%08lx,%p)\n", This,rdst,src,rsrc,dwFlags,lpbltfx);
|
2003-01-08 22:09:25 +01:00
|
|
|
if (rdst) TRACE("\tdestrect :%ldx%ld-%ldx%ld\n",rdst->left,rdst->top,rdst->right,rdst->bottom);
|
|
|
|
if (rsrc) TRACE("\tsrcrect :%ldx%ld-%ldx%ld\n",rsrc->left,rsrc->top,rsrc->right,rsrc->bottom);
|
2003-01-02 20:58:21 +01:00
|
|
|
TRACE("\tflags: ");
|
|
|
|
DDRAW_dump_DDBLT(dwFlags);
|
|
|
|
if (dwFlags & DDBLT_DDFX) {
|
|
|
|
TRACE("\tblitfx: ");
|
|
|
|
DDRAW_dump_DDBLTFX(lpbltfx->dwDDFX);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We only support the BLT with DEPTH_FILL for now */
|
2003-06-05 01:31:39 +02:00
|
|
|
if ((dwFlags & DDBLT_DEPTHFILL) && (This->ddraw_owner->d3d_private != NULL)) {
|
|
|
|
if (This->ddraw_owner->current_device != NULL) {
|
2003-05-22 05:38:22 +02:00
|
|
|
D3DRECT rect;
|
|
|
|
if (rdst) {
|
|
|
|
rect.u1.x1 = rdst->left;
|
|
|
|
rect.u2.y1 = rdst->top;
|
|
|
|
rect.u3.x2 = rdst->right;
|
|
|
|
rect.u4.y2 = rdst->bottom;
|
|
|
|
}
|
2003-06-05 01:31:39 +02:00
|
|
|
This->ddraw_owner->current_device->clear(This->ddraw_owner->current_device,
|
|
|
|
(rdst == NULL ? 0 : 1), &rect,
|
|
|
|
D3DCLEAR_ZBUFFER,
|
|
|
|
0x00000000,
|
|
|
|
((double) lpbltfx->u5.dwFillDepth) / 4294967295.0,
|
|
|
|
0x00000000);
|
2003-01-02 20:58:21 +01:00
|
|
|
return DD_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-04 23:44:55 +01:00
|
|
|
return cant_do_that("blt to a");
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI
|
|
|
|
FakeZBuffer_DirectDrawSurface_BltFast(LPDIRECTDRAWSURFACE7 iface, DWORD dstx,
|
|
|
|
DWORD dsty, LPDIRECTDRAWSURFACE7 src,
|
|
|
|
LPRECT rsrc, DWORD trans)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
|
2003-01-02 20:58:21 +01:00
|
|
|
|
|
|
|
if (TRACE_ON(ddraw)) {
|
|
|
|
FIXME("(%p)->(%ld,%ld,%p,%p,%08lx)\n",
|
|
|
|
This,dstx,dsty,src,rsrc,trans
|
|
|
|
);
|
|
|
|
FIXME("\ttrans:");
|
|
|
|
if (FIXME_ON(ddraw))
|
|
|
|
DDRAW_dump_DDBLTFAST(trans);
|
|
|
|
if (rsrc)
|
2003-01-08 22:09:25 +01:00
|
|
|
FIXME("\tsrcrect: %ldx%ld-%ldx%ld\n",rsrc->left,rsrc->top,rsrc->right,rsrc->bottom);
|
2003-01-02 20:58:21 +01:00
|
|
|
else
|
|
|
|
FIXME(" srcrect: NULL\n");
|
|
|
|
}
|
|
|
|
|
2001-01-04 23:44:55 +01:00
|
|
|
return cant_do_that("bltfast to a");
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI
|
|
|
|
FakeZBuffer_DirectDrawSurface_GetDC(LPDIRECTDRAWSURFACE7 iface, HDC *phDC)
|
|
|
|
{
|
|
|
|
return cant_do_that("get a DC for a");
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI
|
|
|
|
FakeZBuffer_DirectDrawSurface_ReleaseDC(LPDIRECTDRAWSURFACE7 iface, HDC hDC)
|
|
|
|
{
|
|
|
|
return cant_do_that("release a DC for a");
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI
|
|
|
|
FakeZBuffer_DirectDrawSurface_Restore(LPDIRECTDRAWSURFACE7 iface)
|
|
|
|
{
|
|
|
|
return DD_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI
|
|
|
|
FakeZBuffer_DirectDrawSurface_SetSurfaceDesc(LPDIRECTDRAWSURFACE7 iface,
|
|
|
|
LPDDSURFACEDESC2 pDDSD,
|
|
|
|
DWORD dwFlags)
|
|
|
|
{
|
|
|
|
/* XXX */
|
|
|
|
abort();
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-27 22:17:35 +02:00
|
|
|
static const IDirectDrawSurface7Vtbl FakeZBuffer_IDirectDrawSurface7_VTable=
|
2001-01-04 23:44:55 +01:00
|
|
|
{
|
|
|
|
Main_DirectDrawSurface_QueryInterface,
|
|
|
|
Main_DirectDrawSurface_AddRef,
|
|
|
|
Main_DirectDrawSurface_Release,
|
|
|
|
Main_DirectDrawSurface_AddAttachedSurface,
|
|
|
|
Main_DirectDrawSurface_AddOverlayDirtyRect,
|
|
|
|
FakeZBuffer_DirectDrawSurface_Blt,
|
|
|
|
Main_DirectDrawSurface_BltBatch,
|
|
|
|
FakeZBuffer_DirectDrawSurface_BltFast,
|
|
|
|
Main_DirectDrawSurface_DeleteAttachedSurface,
|
|
|
|
Main_DirectDrawSurface_EnumAttachedSurfaces,
|
|
|
|
Main_DirectDrawSurface_EnumOverlayZOrders,
|
|
|
|
Main_DirectDrawSurface_Flip,
|
|
|
|
Main_DirectDrawSurface_GetAttachedSurface,
|
|
|
|
Main_DirectDrawSurface_GetBltStatus,
|
|
|
|
Main_DirectDrawSurface_GetCaps,
|
|
|
|
Main_DirectDrawSurface_GetClipper,
|
|
|
|
Main_DirectDrawSurface_GetColorKey,
|
|
|
|
FakeZBuffer_DirectDrawSurface_GetDC,
|
|
|
|
Main_DirectDrawSurface_GetFlipStatus,
|
|
|
|
Main_DirectDrawSurface_GetOverlayPosition,
|
|
|
|
Main_DirectDrawSurface_GetPalette,
|
|
|
|
Main_DirectDrawSurface_GetPixelFormat,
|
|
|
|
Main_DirectDrawSurface_GetSurfaceDesc,
|
|
|
|
Main_DirectDrawSurface_Initialize,
|
|
|
|
Main_DirectDrawSurface_IsLost,
|
|
|
|
Main_DirectDrawSurface_Lock,
|
|
|
|
FakeZBuffer_DirectDrawSurface_ReleaseDC,
|
|
|
|
FakeZBuffer_DirectDrawSurface_Restore,
|
|
|
|
Main_DirectDrawSurface_SetClipper,
|
|
|
|
Main_DirectDrawSurface_SetColorKey,
|
|
|
|
Main_DirectDrawSurface_SetOverlayPosition,
|
|
|
|
Main_DirectDrawSurface_SetPalette,
|
|
|
|
Main_DirectDrawSurface_Unlock,
|
|
|
|
Main_DirectDrawSurface_UpdateOverlay,
|
|
|
|
Main_DirectDrawSurface_UpdateOverlayDisplay,
|
|
|
|
Main_DirectDrawSurface_UpdateOverlayZOrder,
|
|
|
|
Main_DirectDrawSurface_GetDDInterface,
|
|
|
|
Main_DirectDrawSurface_PageLock,
|
|
|
|
Main_DirectDrawSurface_PageUnlock,
|
|
|
|
FakeZBuffer_DirectDrawSurface_SetSurfaceDesc,
|
|
|
|
Main_DirectDrawSurface_SetPrivateData,
|
|
|
|
Main_DirectDrawSurface_GetPrivateData,
|
|
|
|
Main_DirectDrawSurface_FreePrivateData,
|
|
|
|
Main_DirectDrawSurface_GetUniquenessValue,
|
|
|
|
Main_DirectDrawSurface_ChangeUniquenessValue,
|
|
|
|
Main_DirectDrawSurface_SetPriority,
|
|
|
|
Main_DirectDrawSurface_GetPriority,
|
|
|
|
Main_DirectDrawSurface_SetLOD,
|
|
|
|
Main_DirectDrawSurface_GetLOD
|
|
|
|
};
|