Remove all openGL calls in execute buffers and use the Direct3D7 APIs.
[wine] / dlls / ddraw / dsurface / fakezbuffer.c
1 /*              DirectDraw/Direct3D Z-Buffer stand in
2  *
3  * Copyright 2000 TransGaming Technologies Inc.
4  *
5  * This class provides a DirectDrawSurface implementation that represents
6  * a Z-Buffer surface. However it does not store an image and does not
7  * support Lock/Unlock or GetDC. It is merely a placeholder required by the
8  * Direct3D architecture.
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23  */
24
25 #include "config.h"
26
27 #include <stdlib.h>
28 #include <assert.h>
29
30 #define NONAMELESSUNION
31 #define NONAMELESSSTRUCT
32 #include "ddraw.h"
33 #include "d3d.h"
34
35 #include "wine/debug.h"
36
37 #include "ddcomimpl.h"
38 #include "ddraw_private.h"
39 #include "d3d_private.h"
40 #include "dsurface/main.h"
41 #include "dsurface/fakezbuffer.h"
42
43 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
44
45 static ICOM_VTABLE(IDirectDrawSurface7) FakeZBuffer_IDirectDrawSurface7_VTable;
46
47 HRESULT FakeZBuffer_DirectDrawSurface_Construct(IDirectDrawSurfaceImpl *This,
48                                                 IDirectDrawImpl *pDD,
49                                                 const DDSURFACEDESC2 *pDDSD)
50 {
51     HRESULT hr;
52
53     assert(pDDSD->ddsCaps.dwCaps & DDSCAPS_ZBUFFER);
54
55     hr = Main_DirectDrawSurface_Construct(This, pDD, pDDSD);
56     if (FAILED(hr)) return hr;
57
58     ICOM_INIT_INTERFACE(This, IDirectDrawSurface7,
59                         FakeZBuffer_IDirectDrawSurface7_VTable);
60
61     This->final_release = FakeZBuffer_DirectDrawSurface_final_release;
62     This->duplicate_surface = FakeZBuffer_DirectDrawSurface_duplicate_surface;
63
64     return DD_OK;
65 }
66
67 /* Not an API */
68 HRESULT FakeZBuffer_DirectDrawSurface_Create(IDirectDrawImpl* pDD,
69                                              const DDSURFACEDESC2* pDDSD,
70                                              LPDIRECTDRAWSURFACE7* ppSurf,
71                                              IUnknown* pUnkOuter)
72 {
73     IDirectDrawSurfaceImpl* This;
74     HRESULT hr;
75     assert(pUnkOuter == NULL);
76
77     This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
78                      sizeof(*This)
79                      + sizeof(FakeZBuffer_DirectDrawSurfaceImpl));
80     if (This == NULL) return E_OUTOFMEMORY;
81
82     This->private = (FakeZBuffer_DirectDrawSurfaceImpl*)(This+1);
83
84     hr = FakeZBuffer_DirectDrawSurface_Construct(This, pDD, pDDSD);
85     if (FAILED(hr))
86         HeapFree(GetProcessHeap(), 0, This);
87     else
88         *ppSurf = ICOM_INTERFACE(This, IDirectDrawSurface7);
89
90     return hr;
91 }
92
93 void
94 FakeZBuffer_DirectDrawSurface_final_release(IDirectDrawSurfaceImpl* This)
95 {
96     Main_DirectDrawSurface_final_release(This);
97 }
98
99 HRESULT
100 FakeZBuffer_DirectDrawSurface_duplicate_surface(IDirectDrawSurfaceImpl* This,
101                                                 LPDIRECTDRAWSURFACE7* ppDup)
102 {
103     return FakeZBuffer_DirectDrawSurface_Create(This->ddraw_owner,
104                                                 &This->surface_desc, ppDup,
105                                                 NULL);
106 }
107
108 /* put your breakpoint/abort call here */
109 static HRESULT cant_do_that(const char *s)
110 {
111     FIXME("attempt to %s fake z-buffer\n", s);
112     return DDERR_UNSUPPORTED;
113 }
114
115 HRESULT WINAPI
116 FakeZBuffer_DirectDrawSurface_Blt(LPDIRECTDRAWSURFACE7 iface, LPRECT rdst,
117                                   LPDIRECTDRAWSURFACE7 src, LPRECT rsrc,
118                                   DWORD dwFlags, LPDDBLTFX lpbltfx)
119 {
120     ICOM_THIS(IDirectDrawSurfaceImpl,iface);
121
122     if (TRACE_ON(ddraw)) {
123         TRACE("(%p)->(%p,%p,%p,%08lx,%p)\n", This,rdst,src,rsrc,dwFlags,lpbltfx);
124         if (rdst) TRACE("\tdestrect :%ldx%ld-%ldx%ld\n",rdst->left,rdst->top,rdst->right,rdst->bottom);
125         if (rsrc) TRACE("\tsrcrect  :%ldx%ld-%ldx%ld\n",rsrc->left,rsrc->top,rsrc->right,rsrc->bottom);
126         TRACE("\tflags: ");
127         DDRAW_dump_DDBLT(dwFlags);
128         if (dwFlags & DDBLT_DDFX) {
129             TRACE("\tblitfx: ");
130             DDRAW_dump_DDBLTFX(lpbltfx->dwDDFX);
131         }
132     }
133
134     /* We only support the BLT with DEPTH_FILL for now */
135     if ((dwFlags & DDBLT_DEPTHFILL) && This->ddraw_owner->d3d != NULL) {
136         if (This->ddraw_owner->d3d->current_device != NULL) {
137             This->ddraw_owner->d3d->current_device->clear(This->ddraw_owner->d3d->current_device,
138                                                           0, NULL, /* Clear the whole screen */
139                                                           D3DCLEAR_ZBUFFER,
140                                                           0x00000000,
141                                                           ((double) lpbltfx->u5.dwFillDepth) / 4294967295.0,
142                                                           0x00000000);
143             return DD_OK;
144         }
145     }
146
147     return cant_do_that("blt to a");
148 }
149
150 HRESULT WINAPI
151 FakeZBuffer_DirectDrawSurface_BltFast(LPDIRECTDRAWSURFACE7 iface, DWORD dstx,
152                                       DWORD dsty, LPDIRECTDRAWSURFACE7 src,
153                                       LPRECT rsrc, DWORD trans)
154 {
155     ICOM_THIS(IDirectDrawSurfaceImpl,iface);
156
157     if (TRACE_ON(ddraw)) {
158         FIXME("(%p)->(%ld,%ld,%p,%p,%08lx)\n",
159                 This,dstx,dsty,src,rsrc,trans
160         );
161         FIXME("\ttrans:");
162         if (FIXME_ON(ddraw))
163           DDRAW_dump_DDBLTFAST(trans);
164         if (rsrc)
165           FIXME("\tsrcrect: %ldx%ld-%ldx%ld\n",rsrc->left,rsrc->top,rsrc->right,rsrc->bottom);
166         else
167           FIXME(" srcrect: NULL\n");
168     }
169
170     return cant_do_that("bltfast to a");
171 }
172
173 HRESULT WINAPI
174 FakeZBuffer_DirectDrawSurface_GetDC(LPDIRECTDRAWSURFACE7 iface, HDC *phDC)
175 {
176     return cant_do_that("get a DC for a");
177 }
178
179 HRESULT WINAPI
180 FakeZBuffer_DirectDrawSurface_ReleaseDC(LPDIRECTDRAWSURFACE7 iface, HDC hDC)
181 {
182     return cant_do_that("release a DC for a");
183 }
184
185 HRESULT WINAPI
186 FakeZBuffer_DirectDrawSurface_Restore(LPDIRECTDRAWSURFACE7 iface)
187 {
188     return DD_OK;
189 }
190
191 HRESULT WINAPI
192 FakeZBuffer_DirectDrawSurface_SetSurfaceDesc(LPDIRECTDRAWSURFACE7 iface,
193                                              LPDDSURFACEDESC2 pDDSD,
194                                              DWORD dwFlags)
195 {
196     /* XXX */
197     abort();
198     return E_FAIL;
199 }
200
201
202 static ICOM_VTABLE(IDirectDrawSurface7) FakeZBuffer_IDirectDrawSurface7_VTable=
203 {
204     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
205     Main_DirectDrawSurface_QueryInterface,
206     Main_DirectDrawSurface_AddRef,
207     Main_DirectDrawSurface_Release,
208     Main_DirectDrawSurface_AddAttachedSurface,
209     Main_DirectDrawSurface_AddOverlayDirtyRect,
210     FakeZBuffer_DirectDrawSurface_Blt,
211     Main_DirectDrawSurface_BltBatch,
212     FakeZBuffer_DirectDrawSurface_BltFast,
213     Main_DirectDrawSurface_DeleteAttachedSurface,
214     Main_DirectDrawSurface_EnumAttachedSurfaces,
215     Main_DirectDrawSurface_EnumOverlayZOrders,
216     Main_DirectDrawSurface_Flip,
217     Main_DirectDrawSurface_GetAttachedSurface,
218     Main_DirectDrawSurface_GetBltStatus,
219     Main_DirectDrawSurface_GetCaps,
220     Main_DirectDrawSurface_GetClipper,
221     Main_DirectDrawSurface_GetColorKey,
222     FakeZBuffer_DirectDrawSurface_GetDC,
223     Main_DirectDrawSurface_GetFlipStatus,
224     Main_DirectDrawSurface_GetOverlayPosition,
225     Main_DirectDrawSurface_GetPalette,
226     Main_DirectDrawSurface_GetPixelFormat,
227     Main_DirectDrawSurface_GetSurfaceDesc,
228     Main_DirectDrawSurface_Initialize,
229     Main_DirectDrawSurface_IsLost,
230     Main_DirectDrawSurface_Lock,
231     FakeZBuffer_DirectDrawSurface_ReleaseDC,
232     FakeZBuffer_DirectDrawSurface_Restore,
233     Main_DirectDrawSurface_SetClipper,
234     Main_DirectDrawSurface_SetColorKey,
235     Main_DirectDrawSurface_SetOverlayPosition,
236     Main_DirectDrawSurface_SetPalette,
237     Main_DirectDrawSurface_Unlock,
238     Main_DirectDrawSurface_UpdateOverlay,
239     Main_DirectDrawSurface_UpdateOverlayDisplay,
240     Main_DirectDrawSurface_UpdateOverlayZOrder,
241     Main_DirectDrawSurface_GetDDInterface,
242     Main_DirectDrawSurface_PageLock,
243     Main_DirectDrawSurface_PageUnlock,
244     FakeZBuffer_DirectDrawSurface_SetSurfaceDesc,
245     Main_DirectDrawSurface_SetPrivateData,
246     Main_DirectDrawSurface_GetPrivateData,
247     Main_DirectDrawSurface_FreePrivateData,
248     Main_DirectDrawSurface_GetUniquenessValue,
249     Main_DirectDrawSurface_ChangeUniquenessValue,
250     Main_DirectDrawSurface_SetPriority,
251     Main_DirectDrawSurface_GetPriority,
252     Main_DirectDrawSurface_SetLOD,
253     Main_DirectDrawSurface_GetLOD
254 };