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