Added handling of SIGUSR2 for the new event interruption handling,
[wine/wine-kai.git] / graphics / d3dviewport.c
blob393cdd7cd44e1abf4f2f9ab1282ac85abb6e92dd
1 /* Direct3D Viewport
2 (c) 1998 Lionel ULMER
4 This files contains the implementation of Direct3DViewport2. */
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 "debug.h"
15 #include "d3d_private.h"
18 #ifdef HAVE_MESAGL
20 static IDirect3DViewport2_VTable viewport2_vtable;
22 /*******************************************************************************
23 * Viewport1/2 static functions
25 static void activate(LPDIRECT3DVIEWPORT2 this) {
26 LPDIRECT3DLIGHT l;
28 /* Activate all the lights associated with this context */
29 l = this->lights;
31 while (l != NULL) {
32 l->activate(l);
33 l = l->next;
37 /*******************************************************************************
38 * Viewport1/2 Creation functions
40 LPDIRECT3DVIEWPORT2 d3dviewport2_create(LPDIRECT3D2 d3d)
42 LPDIRECT3DVIEWPORT2 vp;
44 vp = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DViewport2));
45 vp->ref = 1;
46 vp->lpvtbl = &viewport2_vtable;
47 vp->d3d.d3d2 = d3d;
48 vp->use_d3d2 = 1;
50 vp->device.active_device2 = NULL;
51 vp->activate = activate;
53 vp->lights = NULL;
55 vp->nextlight = GL_LIGHT0;
57 return vp;
60 LPDIRECT3DVIEWPORT d3dviewport_create(LPDIRECT3D d3d)
62 LPDIRECT3DVIEWPORT2 vp;
64 vp = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DViewport2));
65 vp->ref = 1;
66 vp->lpvtbl = &viewport2_vtable;
67 vp->d3d.d3d1 = d3d;
68 vp->use_d3d2 = 0;
70 vp->device.active_device1 = NULL;
71 vp->activate = activate;
73 vp->lights = NULL;
75 vp->nextlight = GL_LIGHT0;
77 return (LPDIRECT3DVIEWPORT) vp;
80 /*******************************************************************************
81 * IDirect3DViewport2 methods
84 static HRESULT WINAPI IDirect3DViewport2_QueryInterface(LPDIRECT3DVIEWPORT2 this,
85 REFIID riid,
86 LPVOID* ppvObj)
88 char xrefiid[50];
90 WINE_StringFromCLSID((LPCLSID)riid,xrefiid);
91 FIXME(ddraw, "(%p)->(%s,%p): stub\n", this, xrefiid,ppvObj);
93 return S_OK;
98 static ULONG WINAPI IDirect3DViewport2_AddRef(LPDIRECT3DVIEWPORT2 this)
100 TRACE(ddraw, "(%p)->()incrementing from %lu.\n", this, this->ref );
102 return ++(this->ref);
107 static ULONG WINAPI IDirect3DViewport2_Release(LPDIRECT3DVIEWPORT2 this)
109 FIXME( ddraw, "(%p)->() decrementing from %lu.\n", this, this->ref );
111 if (!--(this->ref)) {
112 HeapFree(GetProcessHeap(),0,this);
113 return 0;
116 return this->ref;
119 /*** IDirect3DViewport methods ***/
120 static HRESULT WINAPI IDirect3DViewport2_Initialize(LPDIRECT3DVIEWPORT2 this,
121 LPDIRECT3D d3d)
123 FIXME(ddraw, "(%p)->(%p): stub\n", this, d3d);
125 return DD_OK;
128 static HRESULT WINAPI IDirect3DViewport2_GetViewport(LPDIRECT3DVIEWPORT2 this,
129 LPD3DVIEWPORT lpvp)
131 FIXME(ddraw, "(%p)->(%p): stub\n", this, lpvp);
133 if (this->use_vp2 != 0)
134 return DDERR_INVALIDPARAMS;
136 *lpvp = this->viewport.vp1;
138 return DD_OK;
141 static HRESULT WINAPI IDirect3DViewport2_SetViewport(LPDIRECT3DVIEWPORT2 this,
142 LPD3DVIEWPORT lpvp)
144 FIXME(ddraw, "(%p)->(%p): stub\n", this, lpvp);
146 this->use_vp2 = 0;
147 this->viewport.vp1 = *lpvp;
149 TRACE(ddraw, "dwSize = %ld dwX = %ld dwY = %ld\n",
150 lpvp->dwSize, lpvp->dwX, lpvp->dwY);
151 TRACE(ddraw, "dwWidth = %ld dwHeight = %ld\n",
152 lpvp->dwWidth, lpvp->dwHeight);
153 TRACE(ddraw, "dvScaleX = %f dvScaleY = %f\n",
154 lpvp->dvScaleX, lpvp->dvScaleY);
155 TRACE(ddraw, "dvMaxX = %f dvMaxY = %f\n",
156 lpvp->dvMaxX, lpvp->dvMaxY);
157 TRACE(ddraw, "dvMinZ = %f dvMaxZ = %f\n",
158 lpvp->dvMinZ, lpvp->dvMaxZ);
161 return DD_OK;
164 static HRESULT WINAPI IDirect3DViewport2_TransformVertices(LPDIRECT3DVIEWPORT2 this,
165 DWORD dwVertexCount,
166 LPD3DTRANSFORMDATA lpData,
167 DWORD dwFlags,
168 LPDWORD lpOffScreen)
170 FIXME(ddraw, "(%p)->(%8ld,%p,%08lx,%p): stub\n",
171 this, dwVertexCount, lpData, dwFlags, lpOffScreen);
173 return DD_OK;
176 static HRESULT WINAPI IDirect3DViewport2_LightElements(LPDIRECT3DVIEWPORT2 this,
177 DWORD dwElementCount,
178 LPD3DLIGHTDATA lpData)
180 FIXME(ddraw, "(%p)->(%8ld,%p): stub\n", this, dwElementCount, lpData);
182 return DD_OK;
185 static HRESULT WINAPI IDirect3DViewport2_SetBackground(LPDIRECT3DVIEWPORT2 this,
186 D3DMATERIALHANDLE hMat)
188 FIXME(ddraw, "(%p)->(%08lx): stub\n", this, (DWORD) hMat);
190 return DD_OK;
193 static HRESULT WINAPI IDirect3DViewport2_GetBackground(LPDIRECT3DVIEWPORT2 this,
194 LPD3DMATERIALHANDLE lphMat,
195 LPBOOL lpValid)
197 FIXME(ddraw, "(%p)->(%p,%p): stub\n", this, lphMat, lpValid);
199 return DD_OK;
202 static HRESULT WINAPI IDirect3DViewport2_SetBackgroundDepth(LPDIRECT3DVIEWPORT2 this,
203 LPDIRECTDRAWSURFACE lpDDSurface)
205 FIXME(ddraw, "(%p)->(%p): stub\n", this, lpDDSurface);
207 return DD_OK;
210 static HRESULT WINAPI IDirect3DViewport2_GetBackgroundDepth(LPDIRECT3DVIEWPORT2 this,
211 LPDIRECTDRAWSURFACE* lplpDDSurface,
212 LPBOOL lpValid)
214 FIXME(ddraw, "(%p)->(%p,%p): stub\n", this, lplpDDSurface, lpValid);
216 return DD_OK;
219 static HRESULT WINAPI IDirect3DViewport2_Clear(LPDIRECT3DVIEWPORT2 this,
220 DWORD dwCount,
221 LPD3DRECT lpRects,
222 DWORD dwFlags)
224 GLboolean ztest;
225 FIXME(ddraw, "(%p)->(%8ld,%p,%08lx): stub\n", this, dwCount, lpRects, dwFlags);
227 /* For the moment, ignore the rectangles */
228 if (this->device.active_device1 != NULL) {
229 /* Get the rendering context */
230 if (this->use_d3d2)
231 this->device.active_device2->set_context(this->device.active_device2);
232 else
233 this->device.active_device1->set_context(this->device.active_device1);
236 /* Clears the screen */
237 glGetBooleanv(GL_DEPTH_TEST, &ztest);
238 glDepthMask(GL_TRUE); /* Enables Z writing to be sure to delete also the Z buffer */
239 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
240 glDepthMask(ztest);
242 return DD_OK;
245 static HRESULT WINAPI IDirect3DViewport2_AddLight(LPDIRECT3DVIEWPORT2 this,
246 LPDIRECT3DLIGHT lpLight)
248 FIXME(ddraw, "(%p)->(%p): stub\n", this, lpLight);
250 /* Add the light in the 'linked' chain */
251 lpLight->next = this->lights;
252 this->lights = lpLight;
254 /* If active, activate the light */
255 if (this->device.active_device1 != NULL) {
256 /* Get the rendering context */
257 if (this->use_d3d2)
258 this->device.active_device2->set_context(this->device.active_device2);
259 else
260 this->device.active_device1->set_context(this->device.active_device1);
262 /* Activate the light */
263 lpLight->light_num = this->nextlight++;
264 lpLight->activate(lpLight);
267 return DD_OK;
270 static HRESULT WINAPI IDirect3DViewport2_DeleteLight(LPDIRECT3DVIEWPORT2 this,
271 LPDIRECT3DLIGHT lpLight)
273 FIXME(ddraw, "(%p)->(%p): stub\n", this, lpLight);
275 return DD_OK;
278 static HRESULT WINAPI IDirect3DViewport2_NextLight(LPDIRECT3DVIEWPORT2 this,
279 LPDIRECT3DLIGHT lpLight,
280 LPDIRECT3DLIGHT* lplpLight,
281 DWORD dwFlags)
283 FIXME(ddraw, "(%p)->(%p,%p,%08lx): stub\n", this, lpLight, lplpLight, dwFlags);
285 return DD_OK;
288 /*** IDirect3DViewport2 methods ***/
289 static HRESULT WINAPI IDirect3DViewport2_GetViewport2(LPDIRECT3DVIEWPORT2 this,
290 LPD3DVIEWPORT2 lpViewport2)
292 TRACE(ddraw, "(%p)->(%p)\n", this, lpViewport2);
294 if (this->use_vp2 != 1)
295 return DDERR_INVALIDPARAMS;
297 *lpViewport2 = this->viewport.vp2;
299 return DD_OK;
302 static HRESULT WINAPI IDirect3DViewport2_SetViewport2(LPDIRECT3DVIEWPORT2 this,
303 LPD3DVIEWPORT2 lpViewport2)
305 TRACE(ddraw, "(%p)->(%p)\n", this, lpViewport2);
307 TRACE(ddraw, "dwSize = %ld dwX = %ld dwY = %ld\n",
308 lpViewport2->dwSize, lpViewport2->dwX, lpViewport2->dwY);
309 TRACE(ddraw, "dwWidth = %ld dwHeight = %ld\n",
310 lpViewport2->dwWidth, lpViewport2->dwHeight);
311 TRACE(ddraw, "dvClipX = %f dvClipY = %f\n",
312 lpViewport2->dvClipX, lpViewport2->dvClipY);
313 TRACE(ddraw, "dvClipWidth = %f dvClipHeight = %f\n",
314 lpViewport2->dvClipWidth, lpViewport2->dvClipHeight);
315 TRACE(ddraw, "dvMinZ = %f dvMaxZ = %f\n",
316 lpViewport2->dvMinZ, lpViewport2->dvMaxZ);
318 this->viewport.vp2 = *lpViewport2;
319 this->use_vp2 = 1;
321 return DD_OK;
325 /*******************************************************************************
326 * IDirect3DViewport1/2 VTable
328 static IDirect3DViewport2_VTable viewport2_vtable = {
329 /*** IUnknown methods ***/
330 IDirect3DViewport2_QueryInterface,
331 IDirect3DViewport2_AddRef,
332 IDirect3DViewport2_Release,
333 /*** IDirect3DViewport methods ***/
334 IDirect3DViewport2_Initialize,
335 IDirect3DViewport2_GetViewport,
336 IDirect3DViewport2_SetViewport,
337 IDirect3DViewport2_TransformVertices,
338 IDirect3DViewport2_LightElements,
339 IDirect3DViewport2_SetBackground,
340 IDirect3DViewport2_GetBackground,
341 IDirect3DViewport2_SetBackgroundDepth,
342 IDirect3DViewport2_GetBackgroundDepth,
343 IDirect3DViewport2_Clear,
344 IDirect3DViewport2_AddLight,
345 IDirect3DViewport2_DeleteLight,
346 IDirect3DViewport2_NextLight,
347 /*** IDirect3DViewport2 methods ***/
348 IDirect3DViewport2_GetViewport2,
349 IDirect3DViewport2_SetViewport2
352 #else /* HAVE_MESAGL */
354 LPDIRECT3DVIEWPORT d3dviewport_create(LPDIRECT3D d3d) {
355 ERR(ddraw, "Should not be called...\n");
356 return NULL;
359 LPDIRECT3DVIEWPORT2 d3dviewport2_create(LPDIRECT3D2 d3d) {
360 ERR(ddraw, "Should not be called...\n");
361 return NULL;
364 #endif /* HAVE_MESAGL */