Group commit for recovery after disk crash.
[wine] / graphics / d3dviewport.c
1 /* Direct3D Viewport
2    (c) 1998 Lionel ULMER
3    
4    This files contains the implementation of Direct3DViewport2. */
5
6 #include "config.h"
7 #include "windows.h"
8 #include "wintypes.h"
9 #include "winerror.h"
10 #include "interfaces.h"
11 #include "heap.h"
12 #include "ddraw.h"
13 #include "d3d.h"
14 #include "debug.h"
15
16 #include "d3d_private.h"
17
18
19 #ifdef HAVE_MESAGL
20
21 static IDirect3DViewport2_VTable viewport2_vtable;
22
23 /*******************************************************************************
24  *                              Viewport1/2 static functions
25  */
26 static void activate(LPDIRECT3DVIEWPORT2 this) {
27   LPDIRECT3DLIGHT l;
28   
29   /* Activate all the lights associated with this context */
30   l = this->lights;
31
32   while (l != NULL) {
33     l->activate(l);
34     l = l->next;
35   }
36 }
37
38 /*******************************************************************************
39  *                              Viewport1/2 Creation functions
40  */
41 LPDIRECT3DVIEWPORT2 d3dviewport2_create(LPDIRECT3D2 d3d)
42 {
43   LPDIRECT3DVIEWPORT2 vp;
44   
45   vp = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DViewport2));
46   vp->ref = 1;
47   vp->lpvtbl = &viewport2_vtable;
48   vp->d3d.d3d2 = d3d;
49   vp->use_d3d2 = 1;
50
51   vp->device.active_device2 = NULL;
52   vp->activate = activate;
53
54   vp->lights = NULL;
55
56   vp->nextlight = GL_LIGHT0;
57   
58   return vp;
59 }
60
61 LPDIRECT3DVIEWPORT d3dviewport_create(LPDIRECT3D d3d)
62 {
63   LPDIRECT3DVIEWPORT2 vp;
64   
65   vp = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DViewport2));
66   vp->ref = 1;
67   vp->lpvtbl = &viewport2_vtable;
68   vp->d3d.d3d1 = d3d;
69   vp->use_d3d2 = 0;
70
71   vp->device.active_device1 = NULL;
72   vp->activate = activate;
73
74   vp->lights = NULL;
75
76   vp->nextlight = GL_LIGHT0;
77   
78   return (LPDIRECT3DVIEWPORT) vp;
79 }
80
81 /*******************************************************************************
82  *                              IDirect3DViewport2 methods
83  */
84
85 static HRESULT WINAPI IDirect3DViewport2_QueryInterface(LPDIRECT3DVIEWPORT2 this,
86                                                         REFIID riid,
87                                                         LPVOID* ppvObj)
88 {
89   char xrefiid[50];
90   
91   WINE_StringFromCLSID((LPCLSID)riid,xrefiid);
92   FIXME(ddraw, "(%p)->(%s,%p): stub\n", this, xrefiid,ppvObj);
93   
94   return S_OK;
95 }
96
97
98
99 static ULONG WINAPI IDirect3DViewport2_AddRef(LPDIRECT3DVIEWPORT2 this)
100 {
101   TRACE(ddraw, "(%p)->()incrementing from %lu.\n", this, this->ref );
102   
103   return ++(this->ref);
104 }
105
106
107
108 static ULONG WINAPI IDirect3DViewport2_Release(LPDIRECT3DVIEWPORT2 this)
109 {
110   FIXME( ddraw, "(%p)->() decrementing from %lu.\n", this, this->ref );
111   
112   if (!--(this->ref)) {
113     HeapFree(GetProcessHeap(),0,this);
114     return 0;
115   }
116   
117   return this->ref;
118 }
119
120 /*** IDirect3DViewport methods ***/
121 static HRESULT WINAPI IDirect3DViewport2_Initialize(LPDIRECT3DVIEWPORT2 this,
122                                                     LPDIRECT3D d3d)
123 {
124   FIXME(ddraw, "(%p)->(%p): stub\n", this, d3d);
125   
126   return DD_OK;
127 }
128
129 static HRESULT WINAPI IDirect3DViewport2_GetViewport(LPDIRECT3DVIEWPORT2 this,
130                                                      LPD3DVIEWPORT lpvp)
131 {
132   FIXME(ddraw, "(%p)->(%p): stub\n", this, lpvp);
133   
134   if (this->use_vp2 != 0)
135     return DDERR_INVALIDPARAMS;
136
137   *lpvp = this->viewport.vp1;
138   
139   return DD_OK;
140 }
141
142 static HRESULT WINAPI IDirect3DViewport2_SetViewport(LPDIRECT3DVIEWPORT2 this,
143                                                      LPD3DVIEWPORT lpvp)
144 {
145   FIXME(ddraw, "(%p)->(%p): stub\n", this, lpvp);
146
147   this->use_vp2 = 0;
148   this->viewport.vp1 = *lpvp;
149   
150   return DD_OK;
151 }
152
153 static HRESULT WINAPI IDirect3DViewport2_TransformVertices(LPDIRECT3DVIEWPORT2 this,
154                                                            DWORD dwVertexCount,
155                                                            LPD3DTRANSFORMDATA lpData,
156                                                            DWORD dwFlags,
157                                                            LPDWORD lpOffScreen)
158 {
159   FIXME(ddraw, "(%p)->(%8ld,%p,%08lx,%p): stub\n",
160         this, dwVertexCount, lpData, dwFlags, lpOffScreen);
161   
162   return DD_OK;
163 }
164
165 static HRESULT WINAPI IDirect3DViewport2_LightElements(LPDIRECT3DVIEWPORT2 this,
166                                                        DWORD dwElementCount,
167                                                        LPD3DLIGHTDATA lpData)
168 {
169   FIXME(ddraw, "(%p)->(%8ld,%p): stub\n", this, dwElementCount, lpData);
170   
171   return DD_OK;
172 }
173
174 static HRESULT WINAPI IDirect3DViewport2_SetBackground(LPDIRECT3DVIEWPORT2 this,
175                                                        D3DMATERIALHANDLE hMat)
176 {
177   FIXME(ddraw, "(%p)->(%08x): stub\n", this, hMat);
178   
179   return DD_OK;
180 }
181
182 static HRESULT WINAPI IDirect3DViewport2_GetBackground(LPDIRECT3DVIEWPORT2 this,
183                                                        LPD3DMATERIALHANDLE lphMat,
184                                                        LPBOOL lpValid)
185 {
186   FIXME(ddraw, "(%p)->(%p,%p): stub\n", this, lphMat, lpValid);
187   
188   return DD_OK;
189 }
190
191 static HRESULT WINAPI IDirect3DViewport2_SetBackgroundDepth(LPDIRECT3DVIEWPORT2 this,
192                                                             LPDIRECTDRAWSURFACE lpDDSurface)
193 {
194   FIXME(ddraw, "(%p)->(%p): stub\n", this, lpDDSurface);
195   
196   return DD_OK;
197 }
198
199 static HRESULT WINAPI IDirect3DViewport2_GetBackgroundDepth(LPDIRECT3DVIEWPORT2 this,
200                                                             LPDIRECTDRAWSURFACE* lplpDDSurface,
201                                                             LPBOOL lpValid)
202 {
203   FIXME(ddraw, "(%p)->(%p,%p): stub\n", this, lplpDDSurface, lpValid);
204   
205   return DD_OK;
206 }
207
208 static HRESULT WINAPI IDirect3DViewport2_Clear(LPDIRECT3DVIEWPORT2 this,
209                                                DWORD dwCount,
210                                                LPD3DRECT lpRects,
211                                                DWORD dwFlags)
212 {
213   GLboolean ztest;
214   FIXME(ddraw, "(%p)->(%8ld,%p,%08lx): stub\n", this, dwCount, lpRects, dwFlags);
215
216   /* For the moment, ignore the rectangles */
217   if (this->device.active_device1 != NULL) {
218     /* Get the rendering context */
219     if (this->use_d3d2)
220       this->device.active_device2->set_context(this->device.active_device2);
221     else
222       this->device.active_device1->set_context(this->device.active_device1);
223
224     /* Clears the screen */
225     glGetBooleanv(GL_DEPTH_TEST, &ztest);
226     glDepthMask(GL_TRUE); /* Enables Z writing to be sure to delete also the Z buffer */
227     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
228     glDepthMask(ztest);
229   }
230   
231   return DD_OK;
232 }
233
234 static HRESULT WINAPI IDirect3DViewport2_AddLight(LPDIRECT3DVIEWPORT2 this,
235                                                   LPDIRECT3DLIGHT lpLight)
236 {
237   FIXME(ddraw, "(%p)->(%p): stub\n", this, lpLight);
238
239   /* Add the light in the 'linked' chain */
240   lpLight->next = this->lights;
241   this->lights = lpLight;
242
243   /* If active, activate the light */
244   if (this->device.active_device1 != NULL) {
245     /* Get the rendering context */
246     if (this->use_d3d2)
247       this->device.active_device2->set_context(this->device.active_device2);
248     else
249       this->device.active_device1->set_context(this->device.active_device1);
250     
251     /* Activate the light */
252     lpLight->light_num = this->nextlight++;
253     lpLight->activate(lpLight);
254   }
255   
256   return DD_OK;
257 }
258
259 static HRESULT WINAPI IDirect3DViewport2_DeleteLight(LPDIRECT3DVIEWPORT2 this,
260                                                      LPDIRECT3DLIGHT lpLight)
261 {
262   FIXME(ddraw, "(%p)->(%p): stub\n", this, lpLight);
263   
264   return DD_OK;
265 }
266
267 static HRESULT WINAPI IDirect3DViewport2_NextLight(LPDIRECT3DVIEWPORT2 this,
268                                                    LPDIRECT3DLIGHT lpLight,
269                                                    LPDIRECT3DLIGHT* lplpLight,
270                                                    DWORD dwFlags)
271 {
272   FIXME(ddraw, "(%p)->(%p,%p,%08lx): stub\n", this, lpLight, lplpLight, dwFlags);
273   
274   return DD_OK;
275 }
276
277 /*** IDirect3DViewport2 methods ***/
278 static HRESULT WINAPI IDirect3DViewport2_GetViewport2(LPDIRECT3DVIEWPORT2 this,
279                                                       LPD3DVIEWPORT2 lpViewport2)
280 {
281   TRACE(ddraw, "(%p)->(%p)\n", this, lpViewport2);
282
283   if (this->use_vp2 != 1)
284     return DDERR_INVALIDPARAMS;
285
286   *lpViewport2 = this->viewport.vp2;
287   
288   return DD_OK;
289 }
290
291 static HRESULT WINAPI IDirect3DViewport2_SetViewport2(LPDIRECT3DVIEWPORT2 this,
292                                                       LPD3DVIEWPORT2 lpViewport2)
293 {
294   TRACE(ddraw, "(%p)->(%p)\n", this, lpViewport2);
295
296   TRACE(ddraw, "dwSize = %ld   dwX = %ld   dwY = %ld\n",
297         lpViewport2->dwSize, lpViewport2->dwX, lpViewport2->dwY);
298   TRACE(ddraw, "dwWidth = %ld   dwHeight = %ld\n",
299         lpViewport2->dwWidth, lpViewport2->dwHeight);
300   TRACE(ddraw, "dvClipX = %f   dvClipY = %f\n",
301         lpViewport2->dvClipX, lpViewport2->dvClipY);
302   TRACE(ddraw, "dvClipWidth = %f   dvClipHeight = %f\n",
303         lpViewport2->dvClipWidth, lpViewport2->dvClipHeight);
304   TRACE(ddraw, "dvMinZ = %f   dvMaxZ = %f\n",
305         lpViewport2->dvMinZ, lpViewport2->dvMaxZ);
306
307   this->viewport.vp2 = *lpViewport2;
308   this->use_vp2 = 1;
309   
310   return DD_OK;
311 }
312
313
314 /*******************************************************************************
315  *                              IDirect3DViewport1/2 VTable
316  */
317 static IDirect3DViewport2_VTable viewport2_vtable = {
318   /*** IUnknown methods ***/
319   IDirect3DViewport2_QueryInterface,
320   IDirect3DViewport2_AddRef,
321   IDirect3DViewport2_Release,
322   /*** IDirect3DViewport methods ***/
323   IDirect3DViewport2_Initialize,
324   IDirect3DViewport2_GetViewport,
325   IDirect3DViewport2_SetViewport,
326   IDirect3DViewport2_TransformVertices,
327   IDirect3DViewport2_LightElements,
328   IDirect3DViewport2_SetBackground,
329   IDirect3DViewport2_GetBackground,
330   IDirect3DViewport2_SetBackgroundDepth,
331   IDirect3DViewport2_GetBackgroundDepth,
332   IDirect3DViewport2_Clear,
333   IDirect3DViewport2_AddLight,
334   IDirect3DViewport2_DeleteLight,
335   IDirect3DViewport2_NextLight,
336   /*** IDirect3DViewport2 methods ***/
337   IDirect3DViewport2_GetViewport2,
338   IDirect3DViewport2_SetViewport2
339 };
340
341 #else /* HAVE_MESAGL */
342
343 LPDIRECT3DVIEWPORT d3dviewport_create(LPDIRECT3D d3d) {
344   ERR(ddraw, "Should not be called...\n");
345   return NULL;
346 }
347
348 LPDIRECT3DVIEWPORT2 d3dviewport2_create(LPDIRECT3D2 d3d) {
349   ERR(ddraw, "Should not be called...\n");
350   return NULL;
351 }
352
353 #endif /* HAVE_MESAGL */