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