Keep track of per-column information inside the listview.
[wine] / dlls / d3d8 / directx.c
1 /*
2  * IDirect3D8 implementation
3  *
4  * Copyright 2002 Jason Edmeades
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "windef.h"
22 #include "winbase.h"
23 #include "winuser.h"
24 #include "wingdi.h"
25 #include "wine/debug.h"
26
27 #include "config.h"
28 #include "x11drv.h"
29
30 #include "d3d8_private.h"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
33
34 static const float idmatrix[16] = {
35     1.0, 0.0, 0.0, 0.0,
36     0.0, 1.0, 0.0, 0.0,
37     0.0, 0.0, 1.0, 0.0,
38     0.0, 0.0, 0.0, 1.0
39 };
40
41 #define NUM_MODES 10
42 static const int modes[NUM_MODES][3] = {
43     {640, 480, 85},
44     {800, 600, 85},
45     {1024, 768, 85},
46     {1152, 864, 85},
47     {1280, 768, 85},
48     {1280, 960, 85},
49     {1280, 1024, 85},
50     {1600, 900, 85},
51     {1600, 1024, 85},
52     {1600, 1200, 85}
53 };
54
55 /* retrieve the X display to use on a given DC */
56 inline static Display *get_display( HDC hdc )
57 {
58     Display *display;
59     enum x11drv_escape_codes escape = X11DRV_GET_DISPLAY;
60
61     if (!ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPCSTR)&escape,
62                     sizeof(display), (LPSTR)&display )) display = NULL;
63     return display;
64 }
65
66
67 /* IDirect3D IUnknown parts follow: */
68 HRESULT WINAPI IDirect3D8Impl_QueryInterface(LPDIRECT3D8 iface,REFIID riid,LPVOID *ppobj)
69 {
70     ICOM_THIS(IDirect3D8Impl,iface);
71
72     if (IsEqualGUID(riid, &IID_IUnknown)
73         || IsEqualGUID(riid, &IID_IClassFactory)) {
74         IDirect3D8Impl_AddRef(iface);
75         *ppobj = This;
76         return D3D_OK;
77     }
78
79     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
80     return E_NOINTERFACE;
81 }
82
83 ULONG WINAPI IDirect3D8Impl_AddRef(LPDIRECT3D8 iface) {
84     ICOM_THIS(IDirect3D8Impl,iface);
85     TRACE("(%p) : AddRef from %ld\n", This, This->ref);
86     return ++(This->ref);
87 }
88
89 ULONG WINAPI IDirect3D8Impl_Release(LPDIRECT3D8 iface) {
90     ICOM_THIS(IDirect3D8Impl,iface);
91     ULONG ref = --This->ref;
92     TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
93     if (ref == 0)
94         HeapFree(GetProcessHeap(), 0, This);
95     return ref;
96 }
97
98 /* IDirect3D Interface follow: */
99 HRESULT  WINAPI  IDirect3D8Impl_RegisterSoftwareDevice     (LPDIRECT3D8 iface, void* pInitializeFunction) {
100     ICOM_THIS(IDirect3D8Impl,iface);
101     FIXME("(%p)->(%p): stub\n", This, pInitializeFunction);
102     return D3D_OK;
103 }
104
105 UINT     WINAPI  IDirect3D8Impl_GetAdapterCount            (LPDIRECT3D8 iface) {
106     ICOM_THIS(IDirect3D8Impl,iface);
107     /* FIXME: Set to one for now to imply the display */
108     TRACE("(%p): Mostly stub, only returns primary display\n", This);
109     return 1;
110 }
111
112 HRESULT  WINAPI  IDirect3D8Impl_GetAdapterIdentifier       (LPDIRECT3D8 iface,
113                                                             UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER8* pIdentifier) {
114     ICOM_THIS(IDirect3D8Impl,iface);
115
116     TRACE("(%p}->(Adapter: %d, Flags: %lx, pId=%p)\n", This, Adapter, Flags, pIdentifier);
117
118     if (Adapter >= IDirect3D8Impl_GetAdapterCount(iface)) {
119         return D3DERR_INVALIDCALL;
120     }
121
122     if (Adapter == 0) { /* Display */
123         strcpy(pIdentifier->Driver, "Display");
124         strcpy(pIdentifier->Description, "Direct3D Display");
125         pIdentifier->DriverVersion.s.HighPart = 1;
126         pIdentifier->DriverVersion.s.LowPart = 0;
127         pIdentifier->VendorId = 0;
128         pIdentifier->DeviceId = 0;
129         pIdentifier->SubSysId = 0;
130         pIdentifier->Revision = 0;
131         /*FIXME: memcpy(&pIdentifier->DeviceIdentifier, ??, sizeof(??GUID)); */
132         if (Flags & D3DENUM_NO_WHQL_LEVEL ) {
133             pIdentifier->WHQLLevel = 0;
134         } else {
135             pIdentifier->WHQLLevel = 1;
136         }
137     } else {
138         FIXME("Adapter not primary display\n");
139     }
140
141     return D3D_OK;
142 }
143
144 UINT     WINAPI  IDirect3D8Impl_GetAdapterModeCount        (LPDIRECT3D8 iface,
145                                                             UINT Adapter) {
146     ICOM_THIS(IDirect3D8Impl,iface);
147
148     TRACE("(%p}->(Adapter: %d)\n", This, Adapter);
149
150     if (Adapter >= IDirect3D8Impl_GetAdapterCount(iface)) {
151         return D3DERR_INVALIDCALL;
152     }
153
154     if (Adapter == 0) { /* Display */
155         int maxWidth        = GetSystemMetrics(SM_CXSCREEN);
156         int maxHeight       = GetSystemMetrics(SM_CYSCREEN);
157         int i;
158
159         for (i=0; i<NUM_MODES; i++) {
160             if (modes[i][0] > maxWidth || modes[i][1] > maxHeight) {
161                 return i+1;
162             }
163         }
164         return NUM_MODES+1;
165     } else {
166         FIXME("Adapter not primary display\n");
167     }
168
169     return D3D_OK;
170 }
171
172 HRESULT  WINAPI  IDirect3D8Impl_EnumAdapterModes           (LPDIRECT3D8 iface,
173                                                             UINT Adapter, UINT Mode, D3DDISPLAYMODE* pMode) {
174     ICOM_THIS(IDirect3D8Impl,iface);
175
176     TRACE("(%p}->(Adapter: %d, mode: %d, pMode=%p)\n", This, Adapter, Mode, pMode);
177
178     if (Adapter >= IDirect3D8Impl_GetAdapterCount(iface)) {
179         return D3DERR_INVALIDCALL;
180     }
181
182     if (Adapter == 0) { /* Display */
183         HDC hdc;
184         int bpp = 0;
185
186         if (Mode == 0) {
187             pMode->Width        = GetSystemMetrics(SM_CXSCREEN);
188             pMode->Height       = GetSystemMetrics(SM_CYSCREEN);
189             pMode->RefreshRate  = 85; /*FIXME: How to identify? */
190         } else if (Mode < (NUM_MODES+1)) {
191             pMode->Width        = modes[Mode-1][0];
192             pMode->Height       = modes[Mode-1][1];
193             pMode->RefreshRate  = modes[Mode-1][2];
194         } else {
195             TRACE("Requested mode out of range %d\n", Mode);
196             return D3DERR_INVALIDCALL;
197         }
198
199         hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
200         bpp = GetDeviceCaps(hdc, BITSPIXEL);
201         DeleteDC(hdc);
202
203         switch (bpp) {
204         case  8: pMode->Format       = D3DFMT_R3G3B2;   break;
205         case 16: pMode->Format       = D3DFMT_A4R4G4B4; break;
206         case 24: pMode->Format       = D3DFMT_R8G8B8;   break;
207         case 32: pMode->Format       = D3DFMT_A8R8G8B8; break;
208         default: pMode->Format       = D3DFMT_UNKNOWN;
209         }
210         TRACE("W %d H %d rr %d fmt %x\n", pMode->Width, pMode->Height, pMode->RefreshRate, pMode->Format);
211
212     } else {
213         FIXME("Adapter not primary display\n");
214     }
215
216     return D3D_OK;
217 }
218
219 HRESULT  WINAPI  IDirect3D8Impl_GetAdapterDisplayMode      (LPDIRECT3D8 iface,
220                                                             UINT Adapter, D3DDISPLAYMODE* pMode) {
221     ICOM_THIS(IDirect3D8Impl,iface);
222     TRACE("(%p}->(Adapter: %d, pMode: %p)\n", This, Adapter, pMode);
223
224     if (Adapter >= IDirect3D8Impl_GetAdapterCount(iface)) {
225         return D3DERR_INVALIDCALL;
226     }
227
228     if (Adapter == 0) { /* Display */
229         HDC hdc;
230         int bpp = 0;
231
232         pMode->Width        = GetSystemMetrics(SM_CXSCREEN);
233         pMode->Height       = GetSystemMetrics(SM_CYSCREEN);
234         pMode->RefreshRate  = 85; /*FIXME: How to identify? */
235
236         hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
237         bpp = GetDeviceCaps(hdc, BITSPIXEL);
238         DeleteDC(hdc);
239
240         switch (bpp) {
241         case  8: pMode->Format       = D3DFMT_R3G3B2;   break;
242         case 16: pMode->Format       = D3DFMT_A4R4G4B4; break;
243         case 24: pMode->Format       = D3DFMT_R8G8B8;   break;
244         case 32: pMode->Format       = D3DFMT_A8R8G8B8; break;
245         default: pMode->Format       = D3DFMT_UNKNOWN;
246         }
247
248     } else {
249         FIXME("Adapter not primary display\n");
250     }
251
252     TRACE("returning w:%d, h:%d, ref:%d, fmt:%d\n", pMode->Width,
253           pMode->Height, pMode->RefreshRate, pMode->Format);
254     return D3D_OK;
255 }
256
257 HRESULT  WINAPI  IDirect3D8Impl_CheckDeviceType            (LPDIRECT3D8 iface,
258                                                             UINT Adapter, D3DDEVTYPE CheckType, D3DFORMAT DisplayFormat,
259                                                             D3DFORMAT BackBufferFormat, BOOL Windowed) {
260     ICOM_THIS(IDirect3D8Impl,iface);
261     FIXME("(%p)->(Adptr:%d, CheckType:%x, DispFmt:%x, BackBuf:%x, Win? %d): stub\n", This, Adapter, CheckType,
262           DisplayFormat, BackBufferFormat, Windowed);
263     return D3D_OK;
264 }
265
266 HRESULT  WINAPI  IDirect3D8Impl_CheckDeviceFormat          (LPDIRECT3D8 iface,
267                                                             UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat,
268                                                             DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat) {
269     ICOM_THIS(IDirect3D8Impl,iface);
270     FIXME("(%p)->(Adptr:%d, DevType: %x, AdptFmt: %d, Use: %ld, ResTyp: %x, CheckFmt: %d)\n", This, Adapter, DeviceType,
271           AdapterFormat, Usage, RType, CheckFormat);
272     return D3D_OK;
273 }
274
275 HRESULT  WINAPI  IDirect3D8Impl_CheckDeviceMultiSampleType (LPDIRECT3D8 iface,
276                                                             UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat,
277                                                             BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType) {
278     ICOM_THIS(IDirect3D8Impl,iface);
279     FIXME("(%p)->(Adptr:%d, DevType: %x, SurfFmt: %x, Win? %d, MultiSamp: %x)\n", This, Adapter, DeviceType,
280           SurfaceFormat, Windowed, MultiSampleType);
281     return D3D_OK;
282 }
283
284 HRESULT  WINAPI  IDirect3D8Impl_CheckDepthStencilMatch     (LPDIRECT3D8 iface,
285                                                             UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat,
286                                                             D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat) {
287     ICOM_THIS(IDirect3D8Impl,iface);
288     FIXME("(%p)->(Adptr:%d, DevType: %x, AdptFmt: %x, RendrTgtFmt: %x, DepthStencilFmt: %x)\n", This, Adapter, DeviceType,
289           AdapterFormat, RenderTargetFormat, DepthStencilFormat);
290     return D3D_OK;
291 }
292
293 HRESULT  WINAPI  IDirect3D8Impl_GetDeviceCaps              (LPDIRECT3D8 iface,
294                                                             UINT Adapter, D3DDEVTYPE DeviceType, D3DCAPS8* pCaps) {
295     ICOM_THIS(IDirect3D8Impl,iface);
296     TRACE("(%p)->(Adptr:%d, DevType: %x, pCaps: %p)\n", This, Adapter, DeviceType, pCaps);
297
298
299     /* NOTE: Most of the values here are complete garbage for now */
300     pCaps->DeviceType = D3DDEVTYPE_HAL;  /* Not quite true, but use h/w supported by opengl I suppose */
301     pCaps->AdapterOrdinal = Adapter;
302
303     pCaps->Caps = 0;
304     pCaps->Caps2 = D3DCAPS2_CANRENDERWINDOWED;
305     pCaps->Caps3 = D3DDEVCAPS_HWTRANSFORMANDLIGHT;
306     pCaps->PresentationIntervals = D3DPRESENT_INTERVAL_IMMEDIATE;
307
308     pCaps->CursorCaps = 0;
309
310     pCaps->DevCaps = D3DDEVCAPS_DRAWPRIMTLVERTEX | D3DDEVCAPS_HWTRANSFORMANDLIGHT | D3DDEVCAPS_PUREDEVICE;
311
312     pCaps->PrimitiveMiscCaps = D3DPMISCCAPS_CULLCCW | D3DPMISCCAPS_CULLCW | D3DPMISCCAPS_COLORWRITEENABLE | D3DPMISCCAPS_CLIPTLVERTS  |
313                                D3DPMISCCAPS_CLIPPLANESCALEDPOINTS | D3DPMISCCAPS_MASKZ; /*NOT: D3DPMISCCAPS_TSSARGTEMP*/
314     pCaps->RasterCaps = D3DPRASTERCAPS_DITHER | D3DPRASTERCAPS_PAT;
315     pCaps->ZCmpCaps = D3DPCMPCAPS_ALWAYS | D3DPCMPCAPS_EQUAL | D3DPCMPCAPS_GREATER | D3DPCMPCAPS_GREATEREQUAL |
316                       D3DPCMPCAPS_LESS | D3DPCMPCAPS_LESSEQUAL | D3DPCMPCAPS_NEVER | D3DPCMPCAPS_NOTEQUAL;
317
318     pCaps->SrcBlendCaps = 0;
319     pCaps->DestBlendCaps = 0;
320     pCaps->AlphaCmpCaps = 0;
321     pCaps->ShadeCaps = D3DPSHADECAPS_SPECULARGOURAUDRGB | D3DPSHADECAPS_COLORGOURAUDRGB ;
322     pCaps->TextureCaps = D3DPTEXTURECAPS_ALPHA | D3DPTEXTURECAPS_ALPHAPALETTE | D3DPTEXTURECAPS_CUBEMAP | D3DPTEXTURECAPS_POW2;
323     pCaps->TextureFilterCaps = 0;
324     pCaps->CubeTextureFilterCaps = 0;
325     pCaps->VolumeTextureFilterCaps = 0;
326     pCaps->TextureAddressCaps = D3DPTADDRESSCAPS_BORDER | D3DPTADDRESSCAPS_CLAMP | D3DPTADDRESSCAPS_WRAP;
327     pCaps->VolumeTextureAddressCaps = 0;
328
329     pCaps->LineCaps = D3DLINECAPS_TEXTURE | D3DLINECAPS_ZTEST;
330
331     pCaps->MaxTextureWidth = 16384;
332     pCaps->MaxTextureHeight = 16384;
333     pCaps->MaxVolumeExtent = 0;
334
335     pCaps->MaxTextureRepeat = 32768;
336     pCaps->MaxTextureAspectRatio = 32768;
337     pCaps->MaxAnisotropy = 0;
338     pCaps->MaxVertexW = 1.0;
339
340     pCaps->GuardBandLeft = 0;
341     pCaps->GuardBandTop = 0;
342     pCaps->GuardBandRight = 0;
343     pCaps->GuardBandBottom = 0;
344
345     pCaps->ExtentsAdjust = 0;
346
347     pCaps->StencilCaps = 0;
348
349     pCaps->FVFCaps = D3DFVFCAPS_PSIZE | 0x80000;
350     pCaps->TextureOpCaps = 0xFFFFFFFF;
351     pCaps->MaxTextureBlendStages = 256;
352     pCaps->MaxSimultaneousTextures = 256;
353
354     pCaps->VertexProcessingCaps = D3DVTXPCAPS_DIRECTIONALLIGHTS | D3DVTXPCAPS_MATERIALSOURCE7 | D3DVTXPCAPS_POSITIONALLIGHTS | D3DVTXPCAPS_TEXGEN;
355
356     pCaps->MaxActiveLights = 8;
357     pCaps->MaxUserClipPlanes = 1;
358     pCaps->MaxVertexBlendMatrices = 1;
359     pCaps->MaxVertexBlendMatrixIndex = 1;
360
361     pCaps->MaxPointSize = 128.0;
362
363     pCaps->MaxPrimitiveCount = 0xFFFFFFFF;
364     pCaps->MaxVertexIndex = 0xFFFFFFFF;
365     pCaps->MaxStreams = 1;
366     pCaps->MaxStreamStride = 1024;
367
368     pCaps->VertexShaderVersion = 01;
369     pCaps->MaxVertexShaderConst = 1;
370
371     pCaps->PixelShaderVersion = 01;
372     pCaps->MaxPixelShaderValue = 1.0;
373
374     return D3D_OK;
375 }
376
377 HMONITOR WINAPI  IDirect3D8Impl_GetAdapterMonitor          (LPDIRECT3D8 iface,
378                                                             UINT Adapter) {
379     ICOM_THIS(IDirect3D8Impl,iface);
380     FIXME("(%p)->(Adptr:%d)\n", This, Adapter);
381     return D3D_OK;
382 }
383
384 HRESULT  WINAPI  IDirect3D8Impl_CreateDevice               (LPDIRECT3D8 iface,
385                                                             UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow,
386                                                             DWORD BehaviourFlags, D3DPRESENT_PARAMETERS* pPresentationParameters,
387                                                             IDirect3DDevice8** ppReturnedDeviceInterface) {
388     IDirect3DDevice8Impl *object;
389     HWND whichHWND;
390
391     ICOM_THIS(IDirect3D8Impl,iface);
392     TRACE("(%p)->(Adptr:%d, DevType: %x, FocusHwnd: %p, BehFlags: %lx, PresParms: %p, RetDevInt: %p)\n", This, Adapter, DeviceType,
393           hFocusWindow, BehaviourFlags, pPresentationParameters, ppReturnedDeviceInterface);
394
395     /* Allocate the storage for the device */
396     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DDevice8Impl));
397     object->lpVtbl = &Direct3DDevice8_Vtbl;
398     object->ref = 1;
399     object->direct3d8 = This;
400     object->UpdateStateBlock = &object->StateBlock;
401
402     /* Save the creation parameters */
403     object->CreateParms.AdapterOrdinal = Adapter;
404     object->CreateParms.DeviceType = DeviceType;
405     object->CreateParms.hFocusWindow = hFocusWindow;
406     object->CreateParms.BehaviorFlags = BehaviourFlags;
407
408     CreateStateBlock((LPDIRECT3DDEVICE8) object);
409
410     *ppReturnedDeviceInterface = (LPDIRECT3DDEVICE8)object;
411
412     /* Initialize settings */
413     memcpy(&object->PresentParms, pPresentationParameters, sizeof(D3DPRESENT_PARAMETERS));
414     memcpy(&object->StateBlock.transforms[D3DTS_WORLDMATRIX(0)], &idmatrix, sizeof(idmatrix));
415     memcpy(&object->StateBlock.transforms[D3DTS_PROJECTION], &idmatrix, sizeof(idmatrix));
416     memcpy(&object->StateBlock.transforms[D3DTS_VIEW], &idmatrix, sizeof(idmatrix));
417
418     object->PresentParms.BackBufferCount = 1; /* Opengl only supports one? */
419     pPresentationParameters->BackBufferCount = 1;
420
421     object->adapterNo = Adapter;
422     object->devType = DeviceType;
423
424     /* Initialize openGl */
425     {
426         HDC hDc;
427         int          dblBuf[]={GLX_RGBA,GLX_DEPTH_SIZE,16,GLX_DOUBLEBUFFER,None};
428         /*int          dblBuf[]={GLX_RGBA,GLX_DEPTH_SIZE,16, None};   // Useful for debugging */
429
430         /* Which hwnd are we using? */
431 /*      if (pPresentationParameters->Windowed) { */
432            whichHWND = pPresentationParameters->hDeviceWindow;
433            if (!whichHWND) {
434                whichHWND = hFocusWindow;
435            }
436            object->win     = (Window)GetPropA( whichHWND, "__wine_x11_client_window" );
437 /*
438  *      } else {
439  *           whichHWND       = (HWND) GetDesktopWindow();
440  *           object->win     = (Window)GetPropA(whichHWND, "__wine_x11_whole_window" );
441  *         root_window
442  *        }
443  */
444
445         hDc = GetDC(whichHWND);
446         object->display = get_display(hDc);
447
448         ENTER_GL();
449         object->visInfo = glXChooseVisual(object->display, DefaultScreen(object->display), dblBuf);
450         object->glCtx   = glXCreateContext(object->display, object->visInfo, NULL, GL_TRUE);
451         LEAVE_GL();
452         ReleaseDC(whichHWND, hDc);
453
454     }
455
456     if (object->glCtx == NULL) {
457         ERR("Error in context creation !\n");
458         return D3DERR_INVALIDCALL;
459     } else {
460         TRACE("Context created (HWND=%p, glContext=%p, Window=%ld, VisInfo=%p)\n",
461                         whichHWND, object->glCtx, object->win, object->visInfo);
462     }
463
464     TRACE("Creating back buffer\n");
465     /* MSDN: If Windowed is TRUE and either of the BackBufferWidth/Height values is zero,
466        then the corresponding dimension of the client area of the hDeviceWindow
467        (or the focus window, if hDeviceWindow is NULL) is taken. */
468     if (pPresentationParameters->Windowed && ((pPresentationParameters->BackBufferWidth  == 0) ||
469                                               (pPresentationParameters->BackBufferHeight  == 0))) {
470         RECT Rect;
471
472         GetClientRect(whichHWND, &Rect);
473
474         if (pPresentationParameters->BackBufferWidth  == 0) {
475            pPresentationParameters->BackBufferWidth = Rect.right;
476            TRACE("Updating width to %d\n", pPresentationParameters->BackBufferWidth);
477         }
478         if (pPresentationParameters->BackBufferHeight  == 0) {
479            pPresentationParameters->BackBufferHeight = Rect.bottom;
480            TRACE("Updating height to %d\n", pPresentationParameters->BackBufferHeight);
481         }
482     }
483
484     IDirect3DDevice8Impl_CreateImageSurface((LPDIRECT3DDEVICE8) object,
485                                             pPresentationParameters->BackBufferWidth,
486                                             pPresentationParameters->BackBufferHeight,
487                                             pPresentationParameters->BackBufferFormat,
488                                             (LPDIRECT3DSURFACE8*) &object->backBuffer);
489
490     /* Now override the surface's Flip method (if in double buffering) ?COPIED from DDRAW!?
491     ((x11_ds_private *) surface->private)->opengl_flip = TRUE;
492     {
493     int i;
494     struct _surface_chain *chain = surface->s.chain;
495     for (i=0;i<chain->nrofsurfaces;i++)
496       if (chain->surfaces[i]->s.surface_desc.ddsCaps.dwCaps & DDSCAPS_FLIP)
497           ((x11_ds_private *) chain->surfaces[i]->private)->opengl_flip = TRUE;
498     }
499     */
500
501     ENTER_GL();
502     if (glXMakeCurrent(object->display, object->win, object->glCtx) == False) {
503         ERR("Error in setting current context (context %p drawable %ld)!\n",
504             object->glCtx, object->win);
505     }
506     checkGLcall("glXMakeCurrent");
507
508     /* Clear the screen */
509     glClearColor(1.0, 0.0, 0.0, 0.0);
510     checkGLcall("glClearColor");
511     glColor3f(1.0, 1.0, 1.0);
512     checkGLcall("glColor3f");
513
514     glEnable(GL_LIGHTING);
515     checkGLcall("glEnable");
516
517     glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
518     checkGLcall("glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);");
519
520     LEAVE_GL();
521
522     { /* Set a default viewport */
523        D3DVIEWPORT8 vp;
524        vp.X      = 0;
525        vp.Y      = 0;
526        vp.Width  = pPresentationParameters->BackBufferWidth;
527        vp.Height = pPresentationParameters->BackBufferHeight;
528        vp.MinZ   = 0.0f;
529        vp.MaxZ   = 1.0f;
530        IDirect3DDevice8Impl_SetViewport((LPDIRECT3DDEVICE8) object, &vp);
531     }
532
533     TRACE("(%p,%d) incomplete\n", This, Adapter);
534     return D3D_OK;
535 }
536
537 ICOM_VTABLE(IDirect3D8) Direct3D8_Vtbl =
538 {
539     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
540     IDirect3D8Impl_QueryInterface,
541     IDirect3D8Impl_AddRef,
542     IDirect3D8Impl_Release,
543     IDirect3D8Impl_RegisterSoftwareDevice,
544     IDirect3D8Impl_GetAdapterCount,
545     IDirect3D8Impl_GetAdapterIdentifier,
546     IDirect3D8Impl_GetAdapterModeCount,
547     IDirect3D8Impl_EnumAdapterModes,
548     IDirect3D8Impl_GetAdapterDisplayMode,
549     IDirect3D8Impl_CheckDeviceType,
550     IDirect3D8Impl_CheckDeviceFormat,
551     IDirect3D8Impl_CheckDeviceMultiSampleType,
552     IDirect3D8Impl_CheckDepthStencilMatch,
553     IDirect3D8Impl_GetDeviceCaps,
554     IDirect3D8Impl_GetAdapterMonitor,
555     IDirect3D8Impl_CreateDevice
556 };