- updated documentation to be in sync with current code
[wine/wine-kai.git] / graphics / d3dviewport.c
blob77f4810e2d73f826c63e7426c278e38a8a0d8324
1 /* Direct3D Viewport
2 (c) 1998 Lionel ULMER
4 This files contains the implementation of Direct3DViewport2. */
6 #include "config.h"
7 #include "windows.h"
8 #include "wintypes.h"
9 #include "winerror.h"
10 #include "interfaces.h"
11 #include "heap.h"
12 #include "ddraw.h"
13 #include "d3d.h"
14 #include "debug.h"
16 #include "d3d_private.h"
19 #ifdef HAVE_MESAGL
21 static IDirect3DViewport2_VTable viewport2_vtable;
23 /*******************************************************************************
24 * Viewport1/2 static functions
26 static void activate(LPDIRECT3DVIEWPORT2 this) {
27 LPDIRECT3DLIGHT l;
29 /* Activate all the lights associated with this context */
30 l = this->lights;
32 while (l != NULL) {
33 l->activate(l);
34 l = l->next;
38 /*******************************************************************************
39 * Viewport1/2 Creation functions
41 LPDIRECT3DVIEWPORT2 d3dviewport2_create(LPDIRECT3D2 d3d)
43 LPDIRECT3DVIEWPORT2 vp;
45 vp = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DViewport2));
46 vp->ref = 1;
47 vp->lpvtbl = &viewport2_vtable;
48 vp->d3d.d3d2 = d3d;
49 vp->use_d3d2 = 1;
51 vp->device.active_device2 = NULL;
52 vp->activate = activate;
54 vp->lights = NULL;
56 vp->nextlight = GL_LIGHT0;
58 return vp;
61 LPDIRECT3DVIEWPORT d3dviewport_create(LPDIRECT3D d3d)
63 LPDIRECT3DVIEWPORT2 vp;
65 vp = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DViewport2));
66 vp->ref = 1;
67 vp->lpvtbl = &viewport2_vtable;
68 vp->d3d.d3d1 = d3d;
69 vp->use_d3d2 = 0;
71 vp->device.active_device1 = NULL;
72 vp->activate = activate;
74 vp->lights = NULL;
76 vp->nextlight = GL_LIGHT0;
78 return (LPDIRECT3DVIEWPORT) vp;
81 /*******************************************************************************
82 * IDirect3DViewport2 methods
85 static HRESULT WINAPI IDirect3DViewport2_QueryInterface(LPDIRECT3DVIEWPORT2 this,
86 REFIID riid,
87 LPVOID* ppvObj)
89 char xrefiid[50];
91 WINE_StringFromCLSID((LPCLSID)riid,xrefiid);
92 FIXME(ddraw, "(%p)->(%s,%p): stub\n", this, xrefiid,ppvObj);
94 return S_OK;
99 static ULONG WINAPI IDirect3DViewport2_AddRef(LPDIRECT3DVIEWPORT2 this)
101 TRACE(ddraw, "(%p)->()incrementing from %lu.\n", this, this->ref );
103 return ++(this->ref);
108 static ULONG WINAPI IDirect3DViewport2_Release(LPDIRECT3DVIEWPORT2 this)
110 FIXME( ddraw, "(%p)->() decrementing from %lu.\n", this, this->ref );
112 if (!--(this->ref)) {
113 HeapFree(GetProcessHeap(),0,this);
114 return 0;
117 return this->ref;
120 /*** IDirect3DViewport methods ***/
121 static HRESULT WINAPI IDirect3DViewport2_Initialize(LPDIRECT3DVIEWPORT2 this,
122 LPDIRECT3D d3d)
124 FIXME(ddraw, "(%p)->(%p): stub\n", this, d3d);
126 return DD_OK;
129 static HRESULT WINAPI IDirect3DViewport2_GetViewport(LPDIRECT3DVIEWPORT2 this,
130 LPD3DVIEWPORT lpvp)
132 FIXME(ddraw, "(%p)->(%p): stub\n", this, lpvp);
134 if (this->use_vp2 != 0)
135 return DDERR_INVALIDPARAMS;
137 *lpvp = this->viewport.vp1;
139 return DD_OK;
142 static HRESULT WINAPI IDirect3DViewport2_SetViewport(LPDIRECT3DVIEWPORT2 this,
143 LPD3DVIEWPORT lpvp)
145 FIXME(ddraw, "(%p)->(%p): stub\n", this, lpvp);
147 this->use_vp2 = 0;
148 this->viewport.vp1 = *lpvp;
150 TRACE(ddraw, "dwSize = %ld dwX = %ld dwY = %ld\n",
151 lpvp->dwSize, lpvp->dwX, lpvp->dwY);
152 TRACE(ddraw, "dwWidth = %ld dwHeight = %ld\n",
153 lpvp->dwWidth, lpvp->dwHeight);
154 TRACE(ddraw, "dvScaleX = %f dvScaleY = %f\n",
155 lpvp->dvScaleX, lpvp->dvScaleY);
156 TRACE(ddraw, "dvMaxX = %f dvMaxY = %f\n",
157 lpvp->dvMaxX, lpvp->dvMaxY);
158 TRACE(ddraw, "dvMinZ = %f dvMaxZ = %f\n",
159 lpvp->dvMinZ, lpvp->dvMaxZ);
162 return DD_OK;
165 static HRESULT WINAPI IDirect3DViewport2_TransformVertices(LPDIRECT3DVIEWPORT2 this,
166 DWORD dwVertexCount,
167 LPD3DTRANSFORMDATA lpData,
168 DWORD dwFlags,
169 LPDWORD lpOffScreen)
171 FIXME(ddraw, "(%p)->(%8ld,%p,%08lx,%p): stub\n",
172 this, dwVertexCount, lpData, dwFlags, lpOffScreen);
174 return DD_OK;
177 static HRESULT WINAPI IDirect3DViewport2_LightElements(LPDIRECT3DVIEWPORT2 this,
178 DWORD dwElementCount,
179 LPD3DLIGHTDATA lpData)
181 FIXME(ddraw, "(%p)->(%8ld,%p): stub\n", this, dwElementCount, lpData);
183 return DD_OK;
186 static HRESULT WINAPI IDirect3DViewport2_SetBackground(LPDIRECT3DVIEWPORT2 this,
187 D3DMATERIALHANDLE hMat)
189 FIXME(ddraw, "(%p)->(%08lx): stub\n", this, (DWORD) hMat);
191 return DD_OK;
194 static HRESULT WINAPI IDirect3DViewport2_GetBackground(LPDIRECT3DVIEWPORT2 this,
195 LPD3DMATERIALHANDLE lphMat,
196 LPBOOL lpValid)
198 FIXME(ddraw, "(%p)->(%p,%p): stub\n", this, lphMat, lpValid);
200 return DD_OK;
203 static HRESULT WINAPI IDirect3DViewport2_SetBackgroundDepth(LPDIRECT3DVIEWPORT2 this,
204 LPDIRECTDRAWSURFACE lpDDSurface)
206 FIXME(ddraw, "(%p)->(%p): stub\n", this, lpDDSurface);
208 return DD_OK;
211 static HRESULT WINAPI IDirect3DViewport2_GetBackgroundDepth(LPDIRECT3DVIEWPORT2 this,
212 LPDIRECTDRAWSURFACE* lplpDDSurface,
213 LPBOOL lpValid)
215 FIXME(ddraw, "(%p)->(%p,%p): stub\n", this, lplpDDSurface, lpValid);
217 return DD_OK;
220 static HRESULT WINAPI IDirect3DViewport2_Clear(LPDIRECT3DVIEWPORT2 this,
221 DWORD dwCount,
222 LPD3DRECT lpRects,
223 DWORD dwFlags)
225 GLboolean ztest;
226 FIXME(ddraw, "(%p)->(%8ld,%p,%08lx): stub\n", this, dwCount, lpRects, dwFlags);
228 /* For the moment, ignore the rectangles */
229 if (this->device.active_device1 != NULL) {
230 /* Get the rendering context */
231 if (this->use_d3d2)
232 this->device.active_device2->set_context(this->device.active_device2);
233 else
234 this->device.active_device1->set_context(this->device.active_device1);
237 /* Clears the screen */
238 glGetBooleanv(GL_DEPTH_TEST, &ztest);
239 glDepthMask(GL_TRUE); /* Enables Z writing to be sure to delete also the Z buffer */
240 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
241 glDepthMask(ztest);
243 return DD_OK;
246 static HRESULT WINAPI IDirect3DViewport2_AddLight(LPDIRECT3DVIEWPORT2 this,
247 LPDIRECT3DLIGHT lpLight)
249 FIXME(ddraw, "(%p)->(%p): stub\n", this, lpLight);
251 /* Add the light in the 'linked' chain */
252 lpLight->next = this->lights;
253 this->lights = lpLight;
255 /* If active, activate the light */
256 if (this->device.active_device1 != NULL) {
257 /* Get the rendering context */
258 if (this->use_d3d2)
259 this->device.active_device2->set_context(this->device.active_device2);
260 else
261 this->device.active_device1->set_context(this->device.active_device1);
263 /* Activate the light */
264 lpLight->light_num = this->nextlight++;
265 lpLight->activate(lpLight);
268 return DD_OK;
271 static HRESULT WINAPI IDirect3DViewport2_DeleteLight(LPDIRECT3DVIEWPORT2 this,
272 LPDIRECT3DLIGHT lpLight)
274 FIXME(ddraw, "(%p)->(%p): stub\n", this, lpLight);
276 return DD_OK;
279 static HRESULT WINAPI IDirect3DViewport2_NextLight(LPDIRECT3DVIEWPORT2 this,
280 LPDIRECT3DLIGHT lpLight,
281 LPDIRECT3DLIGHT* lplpLight,
282 DWORD dwFlags)
284 FIXME(ddraw, "(%p)->(%p,%p,%08lx): stub\n", this, lpLight, lplpLight, dwFlags);
286 return DD_OK;
289 /*** IDirect3DViewport2 methods ***/
290 static HRESULT WINAPI IDirect3DViewport2_GetViewport2(LPDIRECT3DVIEWPORT2 this,
291 LPD3DVIEWPORT2 lpViewport2)
293 TRACE(ddraw, "(%p)->(%p)\n", this, lpViewport2);
295 if (this->use_vp2 != 1)
296 return DDERR_INVALIDPARAMS;
298 *lpViewport2 = this->viewport.vp2;
300 return DD_OK;
303 static HRESULT WINAPI IDirect3DViewport2_SetViewport2(LPDIRECT3DVIEWPORT2 this,
304 LPD3DVIEWPORT2 lpViewport2)
306 TRACE(ddraw, "(%p)->(%p)\n", this, lpViewport2);
308 TRACE(ddraw, "dwSize = %ld dwX = %ld dwY = %ld\n",
309 lpViewport2->dwSize, lpViewport2->dwX, lpViewport2->dwY);
310 TRACE(ddraw, "dwWidth = %ld dwHeight = %ld\n",
311 lpViewport2->dwWidth, lpViewport2->dwHeight);
312 TRACE(ddraw, "dvClipX = %f dvClipY = %f\n",
313 lpViewport2->dvClipX, lpViewport2->dvClipY);
314 TRACE(ddraw, "dvClipWidth = %f dvClipHeight = %f\n",
315 lpViewport2->dvClipWidth, lpViewport2->dvClipHeight);
316 TRACE(ddraw, "dvMinZ = %f dvMaxZ = %f\n",
317 lpViewport2->dvMinZ, lpViewport2->dvMaxZ);
319 this->viewport.vp2 = *lpViewport2;
320 this->use_vp2 = 1;
322 return DD_OK;
326 /*******************************************************************************
327 * IDirect3DViewport1/2 VTable
329 static IDirect3DViewport2_VTable viewport2_vtable = {
330 /*** IUnknown methods ***/
331 IDirect3DViewport2_QueryInterface,
332 IDirect3DViewport2_AddRef,
333 IDirect3DViewport2_Release,
334 /*** IDirect3DViewport methods ***/
335 IDirect3DViewport2_Initialize,
336 IDirect3DViewport2_GetViewport,
337 IDirect3DViewport2_SetViewport,
338 IDirect3DViewport2_TransformVertices,
339 IDirect3DViewport2_LightElements,
340 IDirect3DViewport2_SetBackground,
341 IDirect3DViewport2_GetBackground,
342 IDirect3DViewport2_SetBackgroundDepth,
343 IDirect3DViewport2_GetBackgroundDepth,
344 IDirect3DViewport2_Clear,
345 IDirect3DViewport2_AddLight,
346 IDirect3DViewport2_DeleteLight,
347 IDirect3DViewport2_NextLight,
348 /*** IDirect3DViewport2 methods ***/
349 IDirect3DViewport2_GetViewport2,
350 IDirect3DViewport2_SetViewport2
353 #else /* HAVE_MESAGL */
355 LPDIRECT3DVIEWPORT d3dviewport_create(LPDIRECT3D d3d) {
356 ERR(ddraw, "Should not be called...\n");
357 return NULL;
360 LPDIRECT3DVIEWPORT2 d3dviewport2_create(LPDIRECT3D2 d3d) {
361 ERR(ddraw, "Should not be called...\n");
362 return NULL;
365 #endif /* HAVE_MESAGL */