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