2 * Copyright (c) 1998 Lionel ULMER
4 * This file contains the implementation of Direct3DViewport2.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "wine/obj_base.h"
27 #include "wine/debug.h"
29 #include "d3d_private.h"
30 #include "mesa_private.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
36 #define D3DVPRIVATE(x) mesa_d3dv_private*dvpriv=((mesa_d3dv_private*)x->private)
37 #define D3DLPRIVATE(x) mesa_d3dl_private*dlpriv=((mesa_d3dl_private*)x->private)
39 static ICOM_VTABLE(IDirect3DViewport2) viewport2_vtable;
41 /*******************************************************************************
42 * Viewport1/2 static functions
44 static void activate(IDirect3DViewport2Impl* This) {
45 IDirect3DLightImpl* l;
47 /* Activate all the lights associated with this context */
56 /*******************************************************************************
57 * Viewport1/2 Creation functions
59 LPDIRECT3DVIEWPORT2 d3dviewport2_create(IDirect3D2Impl* d3d2)
61 IDirect3DViewport2Impl* vp;
63 vp = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DViewport2Impl));
64 vp->private = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(mesa_d3dv_private));
66 ICOM_VTBL(vp) = &viewport2_vtable;
70 vp->device.active_device2 = NULL;
71 vp->activate = activate;
75 ((mesa_d3dv_private *) vp->private)->nextlight = GL_LIGHT0;
77 return (LPDIRECT3DVIEWPORT2)vp;
80 LPDIRECT3DVIEWPORT d3dviewport_create(IDirect3DImpl* d3d1)
82 IDirect3DViewport2Impl* vp;
84 vp = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DViewport2Impl));
85 vp->private = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(mesa_d3dv_private));
87 ICOM_VTBL(vp) = &viewport2_vtable;
91 vp->device.active_device1 = NULL;
92 vp->activate = activate;
96 ((mesa_d3dv_private *) vp->private)->nextlight = GL_LIGHT0;
98 return (LPDIRECT3DVIEWPORT) vp;
101 /*******************************************************************************
102 * IDirect3DViewport2 methods
105 HRESULT WINAPI IDirect3DViewport2Impl_QueryInterface(LPDIRECT3DVIEWPORT2 iface,
109 ICOM_THIS(IDirect3DViewport2Impl,iface);
111 FIXME("(%p)->(%s,%p): stub\n", This, debugstr_guid(riid),ppvObj);
118 ULONG WINAPI IDirect3DViewport2Impl_AddRef(LPDIRECT3DVIEWPORT2 iface)
120 ICOM_THIS(IDirect3DViewport2Impl,iface);
121 TRACE("(%p)->()incrementing from %lu.\n", This, This->ref );
123 return ++(This->ref);
128 ULONG WINAPI IDirect3DViewport2Impl_Release(LPDIRECT3DVIEWPORT2 iface)
130 ICOM_THIS(IDirect3DViewport2Impl,iface);
131 FIXME("(%p)->() decrementing from %lu.\n", This, This->ref );
133 if (!--(This->ref)) {
134 HeapFree(GetProcessHeap(),0,This->private);
135 HeapFree(GetProcessHeap(),0,This);
142 /*** IDirect3DViewport methods ***/
143 HRESULT WINAPI IDirect3DViewport2Impl_Initialize(LPDIRECT3DVIEWPORT2 iface,
146 ICOM_THIS(IDirect3DViewport2Impl,iface);
147 FIXME("(%p)->(%p): stub\n", This, d3d);
152 HRESULT WINAPI IDirect3DViewport2Impl_GetViewport(LPDIRECT3DVIEWPORT2 iface,
155 ICOM_THIS(IDirect3DViewport2Impl,iface);
156 FIXME("(%p)->(%p): stub\n", This, lpvp);
158 if (This->use_vp2 != 0)
159 return DDERR_INVALIDPARAMS;
161 *lpvp = This->viewport.vp1;
166 HRESULT WINAPI IDirect3DViewport2Impl_SetViewport(LPDIRECT3DVIEWPORT2 iface,
169 ICOM_THIS(IDirect3DViewport2Impl,iface);
170 FIXME("(%p)->(%p): stub\n", This, lpvp);
173 This->viewport.vp1 = *lpvp;
175 TRACE("dwSize = %ld dwX = %ld dwY = %ld\n",
176 lpvp->dwSize, lpvp->dwX, lpvp->dwY);
177 TRACE("dwWidth = %ld dwHeight = %ld\n",
178 lpvp->dwWidth, lpvp->dwHeight);
179 TRACE("dvScaleX = %f dvScaleY = %f\n",
180 lpvp->dvScaleX, lpvp->dvScaleY);
181 TRACE("dvMaxX = %f dvMaxY = %f\n",
182 lpvp->dvMaxX, lpvp->dvMaxY);
183 TRACE("dvMinZ = %f dvMaxZ = %f\n",
184 lpvp->dvMinZ, lpvp->dvMaxZ);
190 HRESULT WINAPI IDirect3DViewport2Impl_TransformVertices(LPDIRECT3DVIEWPORT2 iface,
192 LPD3DTRANSFORMDATA lpData,
196 ICOM_THIS(IDirect3DViewport2Impl,iface);
197 FIXME("(%p)->(%8ld,%p,%08lx,%p): stub\n",
198 This, dwVertexCount, lpData, dwFlags, lpOffScreen);
203 HRESULT WINAPI IDirect3DViewport2Impl_LightElements(LPDIRECT3DVIEWPORT2 iface,
204 DWORD dwElementCount,
205 LPD3DLIGHTDATA lpData)
207 ICOM_THIS(IDirect3DViewport2Impl,iface);
208 FIXME("(%p)->(%8ld,%p): stub\n", This, dwElementCount, lpData);
213 HRESULT WINAPI IDirect3DViewport2Impl_SetBackground(LPDIRECT3DVIEWPORT2 iface,
214 D3DMATERIALHANDLE hMat)
216 ICOM_THIS(IDirect3DViewport2Impl,iface);
217 FIXME("(%p)->(%08lx): stub\n", This, (DWORD) hMat);
222 HRESULT WINAPI IDirect3DViewport2Impl_GetBackground(LPDIRECT3DVIEWPORT2 iface,
223 LPD3DMATERIALHANDLE lphMat,
226 ICOM_THIS(IDirect3DViewport2Impl,iface);
227 FIXME("(%p)->(%p,%p): stub\n", This, lphMat, lpValid);
232 HRESULT WINAPI IDirect3DViewport2Impl_SetBackgroundDepth(LPDIRECT3DVIEWPORT2 iface,
233 LPDIRECTDRAWSURFACE lpDDSurface)
235 ICOM_THIS(IDirect3DViewport2Impl,iface);
236 FIXME("(%p)->(%p): stub\n", This, lpDDSurface);
241 HRESULT WINAPI IDirect3DViewport2Impl_GetBackgroundDepth(LPDIRECT3DVIEWPORT2 iface,
242 LPDIRECTDRAWSURFACE* lplpDDSurface,
245 ICOM_THIS(IDirect3DViewport2Impl,iface);
246 FIXME("(%p)->(%p,%p): stub\n", This, lplpDDSurface, lpValid);
251 HRESULT WINAPI IDirect3DViewport2Impl_Clear(LPDIRECT3DVIEWPORT2 iface,
256 ICOM_THIS(IDirect3DViewport2Impl,iface);
258 FIXME("(%p)->(%8ld,%p,%08lx): stub\n", This, dwCount, lpRects, dwFlags);
260 /* For the moment, ignore the rectangles */
261 if (This->device.active_device1 != NULL) {
262 /* Get the rendering context */
264 This->device.active_device2->set_context(This->device.active_device2);
266 This->device.active_device1->set_context(This->device.active_device1);
269 /* Clears the screen */
271 glGetBooleanv(GL_DEPTH_TEST, &ztest);
272 glDepthMask(GL_TRUE); /* Enables Z writing to be sure to delete also the Z buffer */
273 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
280 HRESULT WINAPI IDirect3DViewport2Impl_AddLight(LPDIRECT3DVIEWPORT2 iface,
281 LPDIRECT3DLIGHT lpLight)
283 ICOM_THIS(IDirect3DViewport2Impl,iface);
284 IDirect3DLightImpl* ilpLight=(IDirect3DLightImpl*)lpLight;
285 FIXME("(%p)->(%p): stub\n", This, ilpLight);
287 /* Add the light in the 'linked' chain */
288 ilpLight->next = This->lights;
289 This->lights = ilpLight;
291 /* If active, activate the light */
292 if (This->device.active_device1 != NULL) {
294 D3DLPRIVATE(ilpLight);
296 /* Get the rendering context */
298 This->device.active_device2->set_context(This->device.active_device2);
300 This->device.active_device1->set_context(This->device.active_device1);
302 /* Activate the light */
303 dlpriv->light_num = dvpriv->nextlight++;
304 ilpLight->activate(ilpLight);
310 HRESULT WINAPI IDirect3DViewport2Impl_DeleteLight(LPDIRECT3DVIEWPORT2 iface,
311 LPDIRECT3DLIGHT lpLight)
313 ICOM_THIS(IDirect3DViewport2Impl,iface);
314 IDirect3DLightImpl** currentlplpLight;
315 TRACE("(%p)->(%p): stub\n", This, lpLight);
317 currentlplpLight = &(This->lights);
318 while(*currentlplpLight) {
319 if (*currentlplpLight == (IDirect3DLightImpl*)lpLight) {
320 *currentlplpLight = (*currentlplpLight)->next;
323 currentlplpLight = &((*currentlplpLight)->next);
326 return DDERR_INVALIDOBJECT;
329 HRESULT WINAPI IDirect3DViewport2Impl_NextLight(LPDIRECT3DVIEWPORT2 iface,
330 LPDIRECT3DLIGHT lpLight,
331 LPDIRECT3DLIGHT* lplpLight,
334 ICOM_THIS(IDirect3DViewport2Impl,iface);
335 FIXME("(%p)->(%p,%p,%08lx): stub\n", This, lpLight, lplpLight, dwFlags);
340 /*** IDirect3DViewport2 methods ***/
341 HRESULT WINAPI IDirect3DViewport2Impl_GetViewport2(LPDIRECT3DVIEWPORT2 iface,
342 LPD3DVIEWPORT2 lpViewport2)
344 ICOM_THIS(IDirect3DViewport2Impl,iface);
345 TRACE("(%p)->(%p)\n", This, lpViewport2);
347 if (This->use_vp2 != 1)
348 return DDERR_INVALIDPARAMS;
350 *lpViewport2 = This->viewport.vp2;
355 HRESULT WINAPI IDirect3DViewport2Impl_SetViewport2(LPDIRECT3DVIEWPORT2 iface,
356 LPD3DVIEWPORT2 lpViewport2)
358 ICOM_THIS(IDirect3DViewport2Impl,iface);
359 TRACE("(%p)->(%p)\n", This, lpViewport2);
361 TRACE("dwSize = %ld dwX = %ld dwY = %ld\n",
362 lpViewport2->dwSize, lpViewport2->dwX, lpViewport2->dwY);
363 TRACE("dwWidth = %ld dwHeight = %ld\n",
364 lpViewport2->dwWidth, lpViewport2->dwHeight);
365 TRACE("dvClipX = %f dvClipY = %f\n",
366 lpViewport2->dvClipX, lpViewport2->dvClipY);
367 TRACE("dvClipWidth = %f dvClipHeight = %f\n",
368 lpViewport2->dvClipWidth, lpViewport2->dvClipHeight);
369 TRACE("dvMinZ = %f dvMaxZ = %f\n",
370 lpViewport2->dvMinZ, lpViewport2->dvMaxZ);
372 This->viewport.vp2 = *lpViewport2;
379 /*******************************************************************************
380 * IDirect3DViewport1/2 VTable
382 static ICOM_VTABLE(IDirect3DViewport2) viewport2_vtable =
384 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
385 /*** IUnknown methods ***/
386 IDirect3DViewport2Impl_QueryInterface,
387 IDirect3DViewport2Impl_AddRef,
388 IDirect3DViewport2Impl_Release,
389 /*** IDirect3DViewport methods ***/
390 IDirect3DViewport2Impl_Initialize,
391 IDirect3DViewport2Impl_GetViewport,
392 IDirect3DViewport2Impl_SetViewport,
393 IDirect3DViewport2Impl_TransformVertices,
394 IDirect3DViewport2Impl_LightElements,
395 IDirect3DViewport2Impl_SetBackground,
396 IDirect3DViewport2Impl_GetBackground,
397 IDirect3DViewport2Impl_SetBackgroundDepth,
398 IDirect3DViewport2Impl_GetBackgroundDepth,
399 IDirect3DViewport2Impl_Clear,
400 IDirect3DViewport2Impl_AddLight,
401 IDirect3DViewport2Impl_DeleteLight,
402 IDirect3DViewport2Impl_NextLight,
403 /*** IDirect3DViewport2 methods ***/
404 IDirect3DViewport2Impl_GetViewport2,
405 IDirect3DViewport2Impl_SetViewport2
408 #else /* HAVE_OPENGL */
410 LPDIRECT3DVIEWPORT d3dviewport_create(IDirect3DImpl* d3d1) {
411 ERR("Should not be called...\n");
415 LPDIRECT3DVIEWPORT2 d3dviewport2_create(IDirect3D2Impl* d3d2) {
416 ERR("Should not be called...\n");
420 #endif /* HAVE_OPENGL */