VxDCall functions do not need to be 'register'.
[wine/multimedia.git] / graphics / d3dviewport.c
blobaabfccf1ff38acdb2c858f9a06ebc8b19aeb63ae
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"
17 DEFAULT_DEBUG_CHANNEL(ddraw)
20 #ifdef HAVE_MESAGL
22 static ICOM_VTABLE(IDirect3DViewport2) viewport2_vtable;
24 /*******************************************************************************
25 * Viewport1/2 static functions
27 static void activate(IDirect3DViewport2Impl* This) {
28 IDirect3DLightImpl* l;
30 /* Activate all the lights associated with this context */
31 l = This->lights;
33 while (l != NULL) {
34 l->activate(l);
35 l = l->next;
39 /*******************************************************************************
40 * Viewport1/2 Creation functions
42 LPDIRECT3DVIEWPORT2 d3dviewport2_create(IDirect3D2Impl* d3d2)
44 IDirect3DViewport2Impl* vp;
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;
52 vp->device.active_device2 = NULL;
53 vp->activate = activate;
55 vp->lights = NULL;
57 vp->nextlight = GL_LIGHT0;
59 return (LPDIRECT3DVIEWPORT2)vp;
62 LPDIRECT3DVIEWPORT d3dviewport_create(IDirect3DImpl* d3d1)
64 IDirect3DViewport2Impl* vp;
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;
72 vp->device.active_device1 = NULL;
73 vp->activate = activate;
75 vp->lights = NULL;
77 vp->nextlight = GL_LIGHT0;
79 return (LPDIRECT3DVIEWPORT) vp;
82 /*******************************************************************************
83 * IDirect3DViewport2 methods
86 static HRESULT WINAPI IDirect3DViewport2Impl_QueryInterface(LPDIRECT3DVIEWPORT2 iface,
87 REFIID riid,
88 LPVOID* ppvObj)
90 ICOM_THIS(IDirect3DViewport2Impl,iface);
91 char xrefiid[50];
93 WINE_StringFromCLSID((LPCLSID)riid,xrefiid);
94 FIXME(ddraw, "(%p)->(%s,%p): stub\n", This, xrefiid,ppvObj);
96 return S_OK;
101 static ULONG WINAPI IDirect3DViewport2Impl_AddRef(LPDIRECT3DVIEWPORT2 iface)
103 ICOM_THIS(IDirect3DViewport2Impl,iface);
104 TRACE(ddraw, "(%p)->()incrementing from %lu.\n", This, This->ref );
106 return ++(This->ref);
111 static ULONG WINAPI IDirect3DViewport2Impl_Release(LPDIRECT3DVIEWPORT2 iface)
113 ICOM_THIS(IDirect3DViewport2Impl,iface);
114 FIXME( ddraw, "(%p)->() decrementing from %lu.\n", This, This->ref );
116 if (!--(This->ref)) {
117 HeapFree(GetProcessHeap(),0,This);
118 return 0;
121 return This->ref;
124 /*** IDirect3DViewport methods ***/
125 static HRESULT WINAPI IDirect3DViewport2Impl_Initialize(LPDIRECT3DVIEWPORT2 iface,
126 LPDIRECT3D d3d)
128 ICOM_THIS(IDirect3DViewport2Impl,iface);
129 FIXME(ddraw, "(%p)->(%p): stub\n", This, d3d);
131 return DD_OK;
134 static HRESULT WINAPI IDirect3DViewport2Impl_GetViewport(LPDIRECT3DVIEWPORT2 iface,
135 LPD3DVIEWPORT lpvp)
137 ICOM_THIS(IDirect3DViewport2Impl,iface);
138 FIXME(ddraw, "(%p)->(%p): stub\n", This, lpvp);
140 if (This->use_vp2 != 0)
141 return DDERR_INVALIDPARAMS;
143 *lpvp = This->viewport.vp1;
145 return DD_OK;
148 static HRESULT WINAPI IDirect3DViewport2Impl_SetViewport(LPDIRECT3DVIEWPORT2 iface,
149 LPD3DVIEWPORT lpvp)
151 ICOM_THIS(IDirect3DViewport2Impl,iface);
152 FIXME(ddraw, "(%p)->(%p): stub\n", This, lpvp);
154 This->use_vp2 = 0;
155 This->viewport.vp1 = *lpvp;
157 TRACE(ddraw, "dwSize = %ld dwX = %ld dwY = %ld\n",
158 lpvp->dwSize, lpvp->dwX, lpvp->dwY);
159 TRACE(ddraw, "dwWidth = %ld dwHeight = %ld\n",
160 lpvp->dwWidth, lpvp->dwHeight);
161 TRACE(ddraw, "dvScaleX = %f dvScaleY = %f\n",
162 lpvp->dvScaleX, lpvp->dvScaleY);
163 TRACE(ddraw, "dvMaxX = %f dvMaxY = %f\n",
164 lpvp->dvMaxX, lpvp->dvMaxY);
165 TRACE(ddraw, "dvMinZ = %f dvMaxZ = %f\n",
166 lpvp->dvMinZ, lpvp->dvMaxZ);
169 return DD_OK;
172 static HRESULT WINAPI IDirect3DViewport2Impl_TransformVertices(LPDIRECT3DVIEWPORT2 iface,
173 DWORD dwVertexCount,
174 LPD3DTRANSFORMDATA lpData,
175 DWORD dwFlags,
176 LPDWORD lpOffScreen)
178 ICOM_THIS(IDirect3DViewport2Impl,iface);
179 FIXME(ddraw, "(%p)->(%8ld,%p,%08lx,%p): stub\n",
180 This, dwVertexCount, lpData, dwFlags, lpOffScreen);
182 return DD_OK;
185 static HRESULT WINAPI IDirect3DViewport2Impl_LightElements(LPDIRECT3DVIEWPORT2 iface,
186 DWORD dwElementCount,
187 LPD3DLIGHTDATA lpData)
189 ICOM_THIS(IDirect3DViewport2Impl,iface);
190 FIXME(ddraw, "(%p)->(%8ld,%p): stub\n", This, dwElementCount, lpData);
192 return DD_OK;
195 static HRESULT WINAPI IDirect3DViewport2Impl_SetBackground(LPDIRECT3DVIEWPORT2 iface,
196 D3DMATERIALHANDLE hMat)
198 ICOM_THIS(IDirect3DViewport2Impl,iface);
199 FIXME(ddraw, "(%p)->(%08lx): stub\n", This, (DWORD) hMat);
201 return DD_OK;
204 static HRESULT WINAPI IDirect3DViewport2Impl_GetBackground(LPDIRECT3DVIEWPORT2 iface,
205 LPD3DMATERIALHANDLE lphMat,
206 LPBOOL lpValid)
208 ICOM_THIS(IDirect3DViewport2Impl,iface);
209 FIXME(ddraw, "(%p)->(%p,%p): stub\n", This, lphMat, lpValid);
211 return DD_OK;
214 static HRESULT WINAPI IDirect3DViewport2Impl_SetBackgroundDepth(LPDIRECT3DVIEWPORT2 iface,
215 LPDIRECTDRAWSURFACE lpDDSurface)
217 ICOM_THIS(IDirect3DViewport2Impl,iface);
218 FIXME(ddraw, "(%p)->(%p): stub\n", This, lpDDSurface);
220 return DD_OK;
223 static HRESULT WINAPI IDirect3DViewport2Impl_GetBackgroundDepth(LPDIRECT3DVIEWPORT2 iface,
224 LPDIRECTDRAWSURFACE* lplpDDSurface,
225 LPBOOL lpValid)
227 ICOM_THIS(IDirect3DViewport2Impl,iface);
228 FIXME(ddraw, "(%p)->(%p,%p): stub\n", This, lplpDDSurface, lpValid);
230 return DD_OK;
233 static HRESULT WINAPI IDirect3DViewport2Impl_Clear(LPDIRECT3DVIEWPORT2 iface,
234 DWORD dwCount,
235 LPD3DRECT lpRects,
236 DWORD dwFlags)
238 ICOM_THIS(IDirect3DViewport2Impl,iface);
239 GLboolean ztest;
240 FIXME(ddraw, "(%p)->(%8ld,%p,%08lx): stub\n", This, dwCount, lpRects, dwFlags);
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);
251 /* Clears the screen */
252 glGetBooleanv(GL_DEPTH_TEST, &ztest);
253 glDepthMask(GL_TRUE); /* Enables Z writing to be sure to delete also the Z buffer */
254 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
255 glDepthMask(ztest);
257 return DD_OK;
260 static HRESULT WINAPI IDirect3DViewport2Impl_AddLight(LPDIRECT3DVIEWPORT2 iface,
261 LPDIRECT3DLIGHT lpLight)
263 ICOM_THIS(IDirect3DViewport2Impl,iface);
264 IDirect3DLightImpl* ilpLight=(IDirect3DLightImpl*)lpLight;
265 FIXME(ddraw, "(%p)->(%p): stub\n", This, ilpLight);
267 /* Add the light in the 'linked' chain */
268 ilpLight->next = This->lights;
269 This->lights = ilpLight;
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);
279 /* Activate the light */
280 ilpLight->light_num = This->nextlight++;
281 ilpLight->activate(ilpLight);
284 return DD_OK;
287 static HRESULT WINAPI IDirect3DViewport2Impl_DeleteLight(LPDIRECT3DVIEWPORT2 iface,
288 LPDIRECT3DLIGHT lpLight)
290 ICOM_THIS(IDirect3DViewport2Impl,iface);
291 FIXME(ddraw, "(%p)->(%p): stub\n", This, lpLight);
293 return DD_OK;
296 static HRESULT WINAPI IDirect3DViewport2Impl_NextLight(LPDIRECT3DVIEWPORT2 iface,
297 LPDIRECT3DLIGHT lpLight,
298 LPDIRECT3DLIGHT* lplpLight,
299 DWORD dwFlags)
301 ICOM_THIS(IDirect3DViewport2Impl,iface);
302 FIXME(ddraw, "(%p)->(%p,%p,%08lx): stub\n", This, lpLight, lplpLight, dwFlags);
304 return DD_OK;
307 /*** IDirect3DViewport2 methods ***/
308 static HRESULT WINAPI IDirect3DViewport2Impl_GetViewport2(LPDIRECT3DVIEWPORT2 iface,
309 LPD3DVIEWPORT2 lpViewport2)
311 ICOM_THIS(IDirect3DViewport2Impl,iface);
312 TRACE(ddraw, "(%p)->(%p)\n", This, lpViewport2);
314 if (This->use_vp2 != 1)
315 return DDERR_INVALIDPARAMS;
317 *lpViewport2 = This->viewport.vp2;
319 return DD_OK;
322 static HRESULT WINAPI IDirect3DViewport2Impl_SetViewport2(LPDIRECT3DVIEWPORT2 iface,
323 LPD3DVIEWPORT2 lpViewport2)
325 ICOM_THIS(IDirect3DViewport2Impl,iface);
326 TRACE(ddraw, "(%p)->(%p)\n", This, lpViewport2);
328 TRACE(ddraw, "dwSize = %ld dwX = %ld dwY = %ld\n",
329 lpViewport2->dwSize, lpViewport2->dwX, lpViewport2->dwY);
330 TRACE(ddraw, "dwWidth = %ld dwHeight = %ld\n",
331 lpViewport2->dwWidth, lpViewport2->dwHeight);
332 TRACE(ddraw, "dvClipX = %f dvClipY = %f\n",
333 lpViewport2->dvClipX, lpViewport2->dvClipY);
334 TRACE(ddraw, "dvClipWidth = %f dvClipHeight = %f\n",
335 lpViewport2->dvClipWidth, lpViewport2->dvClipHeight);
336 TRACE(ddraw, "dvMinZ = %f dvMaxZ = %f\n",
337 lpViewport2->dvMinZ, lpViewport2->dvMaxZ);
339 This->viewport.vp2 = *lpViewport2;
340 This->use_vp2 = 1;
342 return DD_OK;
346 /*******************************************************************************
347 * IDirect3DViewport1/2 VTable
349 static ICOM_VTABLE(IDirect3DViewport2) viewport2_vtable = {
350 /*** IUnknown methods ***/
351 IDirect3DViewport2Impl_QueryInterface,
352 IDirect3DViewport2Impl_AddRef,
353 IDirect3DViewport2Impl_Release,
354 /*** IDirect3DViewport methods ***/
355 IDirect3DViewport2Impl_Initialize,
356 IDirect3DViewport2Impl_GetViewport,
357 IDirect3DViewport2Impl_SetViewport,
358 IDirect3DViewport2Impl_TransformVertices,
359 IDirect3DViewport2Impl_LightElements,
360 IDirect3DViewport2Impl_SetBackground,
361 IDirect3DViewport2Impl_GetBackground,
362 IDirect3DViewport2Impl_SetBackgroundDepth,
363 IDirect3DViewport2Impl_GetBackgroundDepth,
364 IDirect3DViewport2Impl_Clear,
365 IDirect3DViewport2Impl_AddLight,
366 IDirect3DViewport2Impl_DeleteLight,
367 IDirect3DViewport2Impl_NextLight,
368 /*** IDirect3DViewport2 methods ***/
369 IDirect3DViewport2Impl_GetViewport2,
370 IDirect3DViewport2Impl_SetViewport2
373 #else /* HAVE_MESAGL */
375 LPDIRECT3DVIEWPORT d3dviewport_create(IDirect3DImpl* d3d1) {
376 ERR(ddraw, "Should not be called...\n");
377 return NULL;
380 LPDIRECT3DVIEWPORT2 d3dviewport2_create(IDirect3D2Impl* d3d2) {
381 ERR(ddraw, "Should not be called...\n");
382 return NULL;
385 #endif /* HAVE_MESAGL */