Moved x11drv.h to dlls/x11drv.
[wine/wine-kai.git] / dlls / d3d8 / directx.c
blob947686889ab443a33224174e02219f32c803b332
1 /*
2 * IDirect3D8 implementation
4 * Copyright 2002 Jason Edmeades
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
21 #include "config.h"
23 #define NONAMELESSUNION
24 #define NONAMELESSSTRUCT
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "wingdi.h"
29 #include "wine/debug.h"
31 #include "d3d8_private.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
35 /* x11drv GDI escapes */
36 #define X11DRV_ESCAPE 6789
37 enum x11drv_escape_codes
39 X11DRV_GET_DISPLAY, /* get X11 display for a DC */
40 X11DRV_GET_DRAWABLE, /* get current drawable for a DC */
41 X11DRV_GET_FONT, /* get current X font for a DC */
44 #define NUM_MODES 10
45 static const int modes[NUM_MODES][3] = {
46 {640, 480, 85},
47 {800, 600, 85},
48 {1024, 768, 85},
49 {1152, 864, 85},
50 {1280, 768, 85},
51 {1280, 960, 85},
52 {1280, 1024, 85},
53 {1600, 900, 85},
54 {1600, 1024, 85},
55 {1600, 1200, 85}
58 /* retrieve the X display to use on a given DC */
59 inline static Display *get_display( HDC hdc )
61 Display *display;
62 enum x11drv_escape_codes escape = X11DRV_GET_DISPLAY;
64 if (!ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPCSTR)&escape,
65 sizeof(display), (LPSTR)&display )) display = NULL;
66 return display;
70 /* IDirect3D IUnknown parts follow: */
71 HRESULT WINAPI IDirect3D8Impl_QueryInterface(LPDIRECT3D8 iface,REFIID riid,LPVOID *ppobj)
73 ICOM_THIS(IDirect3D8Impl,iface);
75 if (IsEqualGUID(riid, &IID_IUnknown)
76 || IsEqualGUID(riid, &IID_IDirect3D8)) {
77 IDirect3D8Impl_AddRef(iface);
78 *ppobj = This;
79 return D3D_OK;
82 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
83 return E_NOINTERFACE;
86 ULONG WINAPI IDirect3D8Impl_AddRef(LPDIRECT3D8 iface) {
87 ICOM_THIS(IDirect3D8Impl,iface);
88 TRACE("(%p) : AddRef from %ld\n", This, This->ref);
89 return ++(This->ref);
92 ULONG WINAPI IDirect3D8Impl_Release(LPDIRECT3D8 iface) {
93 ICOM_THIS(IDirect3D8Impl,iface);
94 ULONG ref = --This->ref;
95 TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
96 if (ref == 0)
97 HeapFree(GetProcessHeap(), 0, This);
98 return ref;
101 /* IDirect3D Interface follow: */
102 HRESULT WINAPI IDirect3D8Impl_RegisterSoftwareDevice (LPDIRECT3D8 iface, void* pInitializeFunction) {
103 ICOM_THIS(IDirect3D8Impl,iface);
104 FIXME("(%p)->(%p): stub\n", This, pInitializeFunction);
105 return D3D_OK;
108 UINT WINAPI IDirect3D8Impl_GetAdapterCount (LPDIRECT3D8 iface) {
109 ICOM_THIS(IDirect3D8Impl,iface);
110 /* FIXME: Set to one for now to imply the display */
111 TRACE("(%p): Mostly stub, only returns primary display\n", This);
112 return 1;
115 HRESULT WINAPI IDirect3D8Impl_GetAdapterIdentifier (LPDIRECT3D8 iface,
116 UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER8* pIdentifier) {
117 ICOM_THIS(IDirect3D8Impl,iface);
119 TRACE("(%p}->(Adapter: %d, Flags: %lx, pId=%p)\n", This, Adapter, Flags, pIdentifier);
121 if (Adapter >= IDirect3D8Impl_GetAdapterCount(iface)) {
122 return D3DERR_INVALIDCALL;
125 if (Adapter == 0) { /* Display */
126 strcpy(pIdentifier->Driver, "Display");
127 strcpy(pIdentifier->Description, "Direct3D Display");
128 pIdentifier->DriverVersion.s.HighPart = 1;
129 pIdentifier->DriverVersion.s.LowPart = 0;
130 pIdentifier->VendorId = 0;
131 pIdentifier->DeviceId = 0;
132 pIdentifier->SubSysId = 0;
133 pIdentifier->Revision = 0;
134 /*FIXME: memcpy(&pIdentifier->DeviceIdentifier, ??, sizeof(??GUID)); */
135 if (Flags & D3DENUM_NO_WHQL_LEVEL ) {
136 pIdentifier->WHQLLevel = 0;
137 } else {
138 pIdentifier->WHQLLevel = 1;
140 } else {
141 FIXME("Adapter not primary display\n");
144 return D3D_OK;
147 UINT WINAPI IDirect3D8Impl_GetAdapterModeCount (LPDIRECT3D8 iface,
148 UINT Adapter) {
149 ICOM_THIS(IDirect3D8Impl,iface);
151 TRACE("(%p}->(Adapter: %d)\n", This, Adapter);
153 if (Adapter >= IDirect3D8Impl_GetAdapterCount(iface)) {
154 return D3DERR_INVALIDCALL;
157 if (Adapter == 0) { /* Display */
158 int maxWidth = GetSystemMetrics(SM_CXSCREEN);
159 int maxHeight = GetSystemMetrics(SM_CYSCREEN);
160 int i;
162 for (i=0; i<NUM_MODES; i++) {
163 if (modes[i][0] > maxWidth || modes[i][1] > maxHeight) {
164 return i+1;
167 return NUM_MODES+1;
168 } else {
169 FIXME("Adapter not primary display\n");
172 return 0;
175 HRESULT WINAPI IDirect3D8Impl_EnumAdapterModes (LPDIRECT3D8 iface,
176 UINT Adapter, UINT Mode, D3DDISPLAYMODE* pMode) {
177 ICOM_THIS(IDirect3D8Impl,iface);
179 TRACE("(%p}->(Adapter: %d, mode: %d, pMode=%p)\n", This, Adapter, Mode, pMode);
181 if (Adapter >= IDirect3D8Impl_GetAdapterCount(iface)) {
182 return D3DERR_INVALIDCALL;
185 if (Adapter == 0) { /* Display */
186 HDC hdc;
187 int bpp = 0;
189 if (Mode == 0) {
190 pMode->Width = GetSystemMetrics(SM_CXSCREEN);
191 pMode->Height = GetSystemMetrics(SM_CYSCREEN);
192 pMode->RefreshRate = 85; /*FIXME: How to identify? */
193 } else if (Mode < (NUM_MODES+1)) {
194 pMode->Width = modes[Mode-1][0];
195 pMode->Height = modes[Mode-1][1];
196 pMode->RefreshRate = modes[Mode-1][2];
197 } else {
198 TRACE("Requested mode out of range %d\n", Mode);
199 return D3DERR_INVALIDCALL;
202 hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
203 bpp = GetDeviceCaps(hdc, BITSPIXEL);
204 DeleteDC(hdc);
206 switch (bpp) {
207 case 8: pMode->Format = D3DFMT_R3G3B2; break;
208 case 16: pMode->Format = D3DFMT_R5G6B5; break;
209 case 24: pMode->Format = D3DFMT_R5G6B5; break; /* Make 24bit appear as 16 bit */
210 case 32: pMode->Format = D3DFMT_A8R8G8B8; break;
211 default: pMode->Format = D3DFMT_UNKNOWN;
213 TRACE("W %d H %d rr %d fmt %x\n", pMode->Width, pMode->Height, pMode->RefreshRate, pMode->Format);
215 } else {
216 FIXME("Adapter not primary display\n");
219 return D3D_OK;
222 HRESULT WINAPI IDirect3D8Impl_GetAdapterDisplayMode (LPDIRECT3D8 iface,
223 UINT Adapter, D3DDISPLAYMODE* pMode) {
224 ICOM_THIS(IDirect3D8Impl,iface);
225 TRACE("(%p}->(Adapter: %d, pMode: %p)\n", This, Adapter, pMode);
227 if (Adapter >= IDirect3D8Impl_GetAdapterCount(iface)) {
228 return D3DERR_INVALIDCALL;
231 if (Adapter == 0) { /* Display */
232 HDC hdc;
233 int bpp = 0;
235 pMode->Width = GetSystemMetrics(SM_CXSCREEN);
236 pMode->Height = GetSystemMetrics(SM_CYSCREEN);
237 pMode->RefreshRate = 85; /*FIXME: How to identify? */
239 hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
240 bpp = GetDeviceCaps(hdc, BITSPIXEL);
241 DeleteDC(hdc);
243 switch (bpp) {
244 case 8: pMode->Format = D3DFMT_R3G3B2; break;
245 case 16: pMode->Format = D3DFMT_R5G6B5; break;
246 case 24: pMode->Format = D3DFMT_R5G6B5; break; /* Make 24bit appear as 16 bit */
247 case 32: pMode->Format = D3DFMT_A8R8G8B8; break;
248 default: pMode->Format = D3DFMT_UNKNOWN;
251 } else {
252 FIXME("Adapter not primary display\n");
255 TRACE("returning w:%d, h:%d, ref:%d, fmt:%x\n", pMode->Width,
256 pMode->Height, pMode->RefreshRate, pMode->Format);
257 return D3D_OK;
260 HRESULT WINAPI IDirect3D8Impl_CheckDeviceType (LPDIRECT3D8 iface,
261 UINT Adapter, D3DDEVTYPE CheckType, D3DFORMAT DisplayFormat,
262 D3DFORMAT BackBufferFormat, BOOL Windowed) {
263 ICOM_THIS(IDirect3D8Impl,iface);
264 FIXME("(%p)->(Adptr:%d, CheckType:%x, DispFmt:%x, BackBuf:%x, Win? %d): stub\n", This, Adapter, CheckType,
265 DisplayFormat, BackBufferFormat, Windowed);
266 return D3D_OK;
269 HRESULT WINAPI IDirect3D8Impl_CheckDeviceFormat (LPDIRECT3D8 iface,
270 UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat,
271 DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat) {
272 ICOM_THIS(IDirect3D8Impl,iface);
273 FIXME("(%p)->(Adptr:%d, DevType: %x, AdptFmt: %d, Use: %ld, ResTyp: %x, CheckFmt: %d)\n", This, Adapter, DeviceType,
274 AdapterFormat, Usage, RType, CheckFormat);
275 return D3D_OK;
278 HRESULT WINAPI IDirect3D8Impl_CheckDeviceMultiSampleType (LPDIRECT3D8 iface,
279 UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat,
280 BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType) {
281 ICOM_THIS(IDirect3D8Impl,iface);
282 FIXME("(%p)->(Adptr:%d, DevType: %x, SurfFmt: %x, Win? %d, MultiSamp: %x)\n", This, Adapter, DeviceType,
283 SurfaceFormat, Windowed, MultiSampleType);
284 return D3D_OK;
287 HRESULT WINAPI IDirect3D8Impl_CheckDepthStencilMatch (LPDIRECT3D8 iface,
288 UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat,
289 D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat) {
290 ICOM_THIS(IDirect3D8Impl,iface);
291 FIXME("(%p)->(Adptr:%d, DevType: %x, AdptFmt: %x, RendrTgtFmt: %x, DepthStencilFmt: %x)\n", This, Adapter, DeviceType,
292 AdapterFormat, RenderTargetFormat, DepthStencilFormat);
293 return D3D_OK;
296 HRESULT WINAPI IDirect3D8Impl_GetDeviceCaps (LPDIRECT3D8 iface,
297 UINT Adapter, D3DDEVTYPE DeviceType, D3DCAPS8* pCaps) {
298 ICOM_THIS(IDirect3D8Impl,iface);
299 TRACE("(%p)->(Adptr:%d, DevType: %x, pCaps: %p)\n", This, Adapter, DeviceType, pCaps);
302 /* NOTE: Most of the values here are complete garbage for now */
303 pCaps->DeviceType = (DeviceType == D3DDEVTYPE_HAL) ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF; /* Not quite true, but use h/w supported by opengl I suppose */
304 pCaps->AdapterOrdinal = Adapter;
306 pCaps->Caps = 0;
307 pCaps->Caps2 = D3DCAPS2_CANRENDERWINDOWED;
308 pCaps->Caps3 = D3DDEVCAPS_HWTRANSFORMANDLIGHT;
309 pCaps->PresentationIntervals = D3DPRESENT_INTERVAL_IMMEDIATE;
311 pCaps->CursorCaps = 0;
313 pCaps->DevCaps = D3DDEVCAPS_DRAWPRIMTLVERTEX | D3DDEVCAPS_HWTRANSFORMANDLIGHT | D3DDEVCAPS_PUREDEVICE;
315 pCaps->PrimitiveMiscCaps = D3DPMISCCAPS_CULLCCW | D3DPMISCCAPS_CULLCW | D3DPMISCCAPS_COLORWRITEENABLE | D3DPMISCCAPS_CLIPTLVERTS |
316 D3DPMISCCAPS_CLIPPLANESCALEDPOINTS | D3DPMISCCAPS_MASKZ; /*NOT: D3DPMISCCAPS_TSSARGTEMP*/
317 pCaps->RasterCaps = D3DPRASTERCAPS_DITHER | D3DPRASTERCAPS_PAT;
318 pCaps->ZCmpCaps = D3DPCMPCAPS_ALWAYS | D3DPCMPCAPS_EQUAL | D3DPCMPCAPS_GREATER | D3DPCMPCAPS_GREATEREQUAL |
319 D3DPCMPCAPS_LESS | D3DPCMPCAPS_LESSEQUAL | D3DPCMPCAPS_NEVER | D3DPCMPCAPS_NOTEQUAL;
321 pCaps->SrcBlendCaps = 0xFFFFFFFF; /*FIXME: Tidy up later */
322 pCaps->DestBlendCaps = 0xFFFFFFFF; /*FIXME: Tidy up later */
323 pCaps->AlphaCmpCaps = 0xFFFFFFFF; /*FIXME: Tidy up later */
324 pCaps->ShadeCaps = D3DPSHADECAPS_SPECULARGOURAUDRGB | D3DPSHADECAPS_COLORGOURAUDRGB ;
325 pCaps->TextureCaps = D3DPTEXTURECAPS_ALPHA | D3DPTEXTURECAPS_ALPHAPALETTE | D3DPTEXTURECAPS_CUBEMAP | D3DPTEXTURECAPS_POW2 | D3DPTEXTURECAPS_VOLUMEMAP | D3DPTEXTURECAPS_MIPMAP;
326 pCaps->TextureFilterCaps = D3DPTFILTERCAPS_MAGFLINEAR | D3DPTFILTERCAPS_MAGFPOINT | D3DPTFILTERCAPS_MINFLINEAR | D3DPTFILTERCAPS_MINFPOINT |
327 D3DPTFILTERCAPS_MIPFLINEAR | D3DPTFILTERCAPS_MIPFPOINT ;
328 pCaps->CubeTextureFilterCaps = 0;
329 pCaps->VolumeTextureFilterCaps = 0;
330 pCaps->TextureAddressCaps = D3DPTADDRESSCAPS_BORDER | D3DPTADDRESSCAPS_CLAMP | D3DPTADDRESSCAPS_WRAP;
331 #if defined(GL_VERSION_1_3)
332 pCaps->TextureAddressCaps |= D3DPTADDRESSCAPS_MIRROR;
333 #endif
334 pCaps->VolumeTextureAddressCaps = 0;
336 pCaps->LineCaps = D3DLINECAPS_TEXTURE | D3DLINECAPS_ZTEST;
338 pCaps->MaxTextureWidth = 16384;
339 pCaps->MaxTextureHeight = 16384;
340 pCaps->MaxVolumeExtent = 0;
342 pCaps->MaxTextureRepeat = 32768;
343 pCaps->MaxTextureAspectRatio = 32768;
344 pCaps->MaxAnisotropy = 0;
345 pCaps->MaxVertexW = 1.0;
347 pCaps->GuardBandLeft = 0;
348 pCaps->GuardBandTop = 0;
349 pCaps->GuardBandRight = 0;
350 pCaps->GuardBandBottom = 0;
352 pCaps->ExtentsAdjust = 0;
354 pCaps->StencilCaps = D3DSTENCILCAPS_DECRSAT | D3DSTENCILCAPS_INCRSAT |
355 D3DSTENCILCAPS_INVERT | D3DSTENCILCAPS_KEEP |
356 D3DSTENCILCAPS_REPLACE | D3DSTENCILCAPS_ZERO /* | D3DSTENCILCAPS_DECR | D3DSTENCILCAPS_INCR */;
358 pCaps->FVFCaps = D3DFVFCAPS_PSIZE | 0x80000;
360 pCaps->TextureOpCaps = D3DTEXOPCAPS_ADD | D3DTEXOPCAPS_ADDSIGNED | D3DTEXOPCAPS_ADDSIGNED2X |
361 D3DTEXOPCAPS_MODULATE | D3DTEXOPCAPS_MODULATE2X | D3DTEXOPCAPS_MODULATE4X |
362 D3DTEXOPCAPS_SELECTARG1 | D3DTEXOPCAPS_DISABLE;
363 #if defined(GL_VERSION_1_3)
364 pCaps->TextureOpCaps |= D3DTEXOPCAPS_DOTPRODUCT3;
365 #endif
366 /* FIXME: Add D3DTEXOPCAPS_ADDSMOOTH D3DTEXOPCAPS_BLENDCURRENTALPHA D3DTEXOPCAPS_BLENDDIFFUSEALPHA D3DTEXOPCAPS_BLENDFACTORALPHA
367 D3DTEXOPCAPS_BLENDTEXTUREALPHA D3DTEXOPCAPS_BLENDTEXTUREALPHAPM D3DTEXOPCAPS_BUMPENVMAP D3DTEXOPCAPS_BUMPENVMAPLUMINANCE
368 D3DTEXOPCAPS_LERP D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
369 D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA D3DTEXOPCAPS_MULTIPLYADD
370 D3DTEXOPCAPS_PREMODULATE D3DTEXOPCAPS_SELECTARG2 D3DTEXOPCAPS_SUBTRACT */
373 GLint gl_max;
375 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_max);
376 TRACE("GLCaps: GL_MAX_TEXTURE_UNITS_ARB=%d\n", gl_max);
377 pCaps->MaxTextureBlendStages = min(8, gl_max);
378 pCaps->MaxSimultaneousTextures = min(8, gl_max);
380 glGetIntegerv(GL_MAX_CLIP_PLANES, &gl_max);
381 pCaps->MaxUserClipPlanes = min(MAX_CLIPPLANES, gl_max);
382 TRACE("GLCaps: GL_MAX_CLIP_PLANES=%d\n", gl_max);
384 glGetIntegerv(GL_MAX_LIGHTS, &gl_max);
385 pCaps->MaxActiveLights = min(MAX_ACTIVE_LIGHTS, gl_max);
386 TRACE("GLCaps: GL_MAX_LIGHTS=%d\n", gl_max);
389 pCaps->VertexProcessingCaps = D3DVTXPCAPS_DIRECTIONALLIGHTS | D3DVTXPCAPS_MATERIALSOURCE7 | D3DVTXPCAPS_POSITIONALLIGHTS | D3DVTXPCAPS_TEXGEN;
391 pCaps->MaxVertexBlendMatrices = 1;
392 pCaps->MaxVertexBlendMatrixIndex = 1;
394 pCaps->MaxPointSize = 128.0;
396 pCaps->MaxPrimitiveCount = 0xFFFFFFFF;
397 pCaps->MaxVertexIndex = 0xFFFFFFFF;
398 pCaps->MaxStreams = 2; /* HACK: Some games want at least 2 */
399 pCaps->MaxStreamStride = 1024;
401 pCaps->VertexShaderVersion = D3DVS_VERSION(1,1);
402 pCaps->MaxVertexShaderConst = D3D8_VSHADER_MAX_CONSTANTS;
404 pCaps->PixelShaderVersion = D3DPS_VERSION(1,1);
405 pCaps->MaxPixelShaderValue = 1.0;
407 return D3D_OK;
410 HMONITOR WINAPI IDirect3D8Impl_GetAdapterMonitor (LPDIRECT3D8 iface,
411 UINT Adapter) {
412 ICOM_THIS(IDirect3D8Impl,iface);
413 FIXME("(%p)->(Adptr:%d)\n", This, Adapter);
414 return D3D_OK;
417 HRESULT WINAPI IDirect3D8Impl_CreateDevice (LPDIRECT3D8 iface,
418 UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow,
419 DWORD BehaviourFlags, D3DPRESENT_PARAMETERS* pPresentationParameters,
420 IDirect3DDevice8** ppReturnedDeviceInterface) {
421 IDirect3DDevice8Impl *object;
422 HWND whichHWND;
423 int num;
424 XVisualInfo template;
425 const char *GL_Extensions = NULL;
426 const char *GLX_Extensions = NULL;
427 GLint gl_max;
429 ICOM_THIS(IDirect3D8Impl,iface);
430 TRACE("(%p)->(Adptr:%d, DevType: %x, FocusHwnd: %p, BehFlags: %lx, PresParms: %p, RetDevInt: %p)\n", This, Adapter, DeviceType,
431 hFocusWindow, BehaviourFlags, pPresentationParameters, ppReturnedDeviceInterface);
433 /* Allocate the storage for the device */
434 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DDevice8Impl));
435 if (NULL == object) {
436 return D3DERR_OUTOFVIDEOMEMORY;
438 object->lpVtbl = &Direct3DDevice8_Vtbl;
439 object->ref = 1;
440 object->direct3d8 = This;
441 /** The device AddRef the direct3d8 Interface else crash in propers clients codes */
442 IDirect3D8_AddRef((LPDIRECT3D8) object->direct3d8);
444 /** use StateBlock Factory here, for creating the startup stateBlock */
445 object->StateBlock = NULL;
446 IDirect3DDeviceImpl_CreateStateBlock(object, D3DSBT_ALL, NULL);
447 object->UpdateStateBlock = object->StateBlock;
449 /* Save the creation parameters */
450 object->CreateParms.AdapterOrdinal = Adapter;
451 object->CreateParms.DeviceType = DeviceType;
452 object->CreateParms.hFocusWindow = hFocusWindow;
453 object->CreateParms.BehaviorFlags = BehaviourFlags;
455 *ppReturnedDeviceInterface = (LPDIRECT3DDEVICE8)object;
457 /* Initialize settings */
458 memcpy(&object->PresentParms, pPresentationParameters, sizeof(D3DPRESENT_PARAMETERS));
460 object->PresentParms.BackBufferCount = 1; /* Opengl only supports one? */
461 pPresentationParameters->BackBufferCount = 1;
463 object->adapterNo = Adapter;
464 object->devType = DeviceType;
466 /* Initialize openGl */
468 HDC hDc;
469 int dblBuf[]={GLX_STENCIL_SIZE,8,GLX_RGBA,GLX_DEPTH_SIZE,16,GLX_DOUBLEBUFFER,None};
470 /* FIXME: Handle stencil appropriately via EnableAutoDepthStencil / AutoDepthStencilFormat */
471 /*int dblBuf[]={GLX_RGBA,GLX_RED_SIZE,4,GLX_GREEN_SIZE,4,GLX_BLUE_SIZE,4,GLX_DOUBLEBUFFER,None}; */
473 /* Which hwnd are we using? */
474 /* if (pPresentationParameters->Windowed) { */
475 whichHWND = pPresentationParameters->hDeviceWindow;
476 if (!whichHWND) {
477 whichHWND = hFocusWindow;
479 object->win = (Window)GetPropA( whichHWND, "__wine_x11_client_window" );
481 * } else {
482 * whichHWND = (HWND) GetDesktopWindow();
483 * object->win = (Window)GetPropA(whichHWND, "__wine_x11_whole_window" );
484 * root_window
488 hDc = GetDC(whichHWND);
489 object->display = get_display(hDc);
491 ENTER_GL();
492 object->visInfo = glXChooseVisual(object->display, DefaultScreen(object->display), dblBuf);
493 if (NULL == object->visInfo) {
494 FIXME("cannot choose needed glxVisual with Stencil Buffer\n");
497 * second try using wine initialized visual ...
498 * must be fixed reworking wine-glx init
500 template.visualid = (VisualID)GetPropA( GetDesktopWindow(), "__wine_x11_visual_id" );
501 object->visInfo = XGetVisualInfo(object->display, VisualIDMask, &template, &num);
502 if (NULL == object->visInfo) {
503 ERR("cannot really get XVisual\n");
504 LEAVE_GL();
505 return D3DERR_NOTAVAILABLE;
508 object->glCtx = glXCreateContext(object->display, object->visInfo, NULL, GL_TRUE);
509 if (NULL == object->glCtx) {
510 ERR("cannot create glxContext\n");
511 LEAVE_GL();
512 return D3DERR_NOTAVAILABLE;
514 LEAVE_GL();
516 ReleaseDC(whichHWND, hDc);
519 if (object->glCtx == NULL) {
520 ERR("Error in context creation !\n");
521 return D3DERR_INVALIDCALL;
522 } else {
523 TRACE("Context created (HWND=%p, glContext=%p, Window=%ld, VisInfo=%p)\n",
524 whichHWND, object->glCtx, object->win, object->visInfo);
527 /* If not windowed, need to go fullscreen, and resize the HWND to the appropriate */
528 /* dimensions */
529 if (!pPresentationParameters->Windowed) {
530 FIXME("Requested full screen support not implemented, expect windowed operation\n");
531 SetWindowPos(whichHWND, HWND_TOP, 0, 0, pPresentationParameters->BackBufferWidth,
532 pPresentationParameters->BackBufferHeight, SWP_SHOWWINDOW);
535 TRACE("Creating back buffer\n");
536 /* MSDN: If Windowed is TRUE and either of the BackBufferWidth/Height values is zero,
537 then the corresponding dimension of the client area of the hDeviceWindow
538 (or the focus window, if hDeviceWindow is NULL) is taken. */
539 if (pPresentationParameters->Windowed && ((pPresentationParameters->BackBufferWidth == 0) ||
540 (pPresentationParameters->BackBufferHeight == 0))) {
541 RECT Rect;
543 GetClientRect(whichHWND, &Rect);
545 if (pPresentationParameters->BackBufferWidth == 0) {
546 pPresentationParameters->BackBufferWidth = Rect.right;
547 TRACE("Updating width to %d\n", pPresentationParameters->BackBufferWidth);
549 if (pPresentationParameters->BackBufferHeight == 0) {
550 pPresentationParameters->BackBufferHeight = Rect.bottom;
551 TRACE("Updating height to %d\n", pPresentationParameters->BackBufferHeight);
555 IDirect3DDevice8Impl_CreateImageSurface((LPDIRECT3DDEVICE8) object,
556 pPresentationParameters->BackBufferWidth,
557 pPresentationParameters->BackBufferHeight,
558 pPresentationParameters->BackBufferFormat,
559 (LPDIRECT3DSURFACE8*) &object->backBuffer);
561 if (pPresentationParameters->EnableAutoDepthStencil)
562 IDirect3DDevice8Impl_CreateImageSurface((LPDIRECT3DDEVICE8) object,
563 pPresentationParameters->BackBufferWidth,
564 pPresentationParameters->BackBufferHeight,
565 pPresentationParameters->AutoDepthStencilFormat,
566 (LPDIRECT3DSURFACE8*) &object->depthStencilBuffer);
568 /* Now override the surface's Flip method (if in double buffering) ?COPIED from DDRAW!?
569 ((x11_ds_private *) surface->private)->opengl_flip = TRUE;
571 int i;
572 struct _surface_chain *chain = surface->s.chain;
573 for (i=0;i<chain->nrofsurfaces;i++)
574 if (chain->surfaces[i]->s.surface_desc.ddsCaps.dwCaps & DDSCAPS_FLIP)
575 ((x11_ds_private *) chain->surfaces[i]->private)->opengl_flip = TRUE;
579 ENTER_GL();
581 /*TRACE("hereeee. %x %x %x\n", object->display, object->win, object->glCtx);*/
582 if (glXMakeCurrent(object->display, object->win, object->glCtx) == False) {
583 ERR("Error in setting current context (context %p drawable %ld)!\n", object->glCtx, object->win);
585 checkGLcall("glXMakeCurrent");
587 /* Clear the screen */
588 glClearColor(1.0, 0.0, 0.0, 0.0);
589 checkGLcall("glClearColor");
590 glColor3f(1.0, 1.0, 1.0);
591 checkGLcall("glColor3f");
593 glEnable(GL_LIGHTING);
594 checkGLcall("glEnable");
596 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
597 checkGLcall("glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);");
599 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
600 checkGLcall("glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);");
602 /* Initialize openGL extension related variables */
603 object->isMultiTexture = FALSE;
604 object->isDot3 = FALSE;
605 object->TextureUnits = 1;
607 /* Retrieve opengl defaults */
608 glGetIntegerv(GL_MAX_CLIP_PLANES, &gl_max);
609 object->clipPlanes = min(MAX_CLIPPLANES, gl_max);
610 TRACE("ClipPlanes support - num Planes=%d\n", gl_max);
612 glGetIntegerv(GL_MAX_LIGHTS, &gl_max);
613 object->maxLights = min(MAX_ACTIVE_LIGHTS, gl_max);
614 TRACE("Lights support - max lights=%d\n", gl_max);
616 /* Parse the gl supported features, in theory enabling parts of our code appropriately */
617 GL_Extensions = glGetString(GL_EXTENSIONS);
618 TRACE("GL_Extensions reported:\n");
620 if (NULL == GL_Extensions) {
621 ERR(" GL_Extensions returns NULL\n");
622 } else {
623 while (*GL_Extensions != 0x00) {
624 const char *Start = GL_Extensions;
625 char ThisExtn[256];
627 memset(ThisExtn, 0x00, sizeof(ThisExtn));
628 while (*GL_Extensions != ' ' && *GL_Extensions != 0x00) {
629 GL_Extensions++;
631 memcpy(ThisExtn, Start, (GL_Extensions - Start));
632 TRACE (" %s\n", ThisExtn);
634 if (strcmp(ThisExtn, "GL_ARB_multitexture") == 0) {
635 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_max);
636 object->isMultiTexture = TRUE;
637 object->TextureUnits = min(8, gl_max);
638 TRACE("FOUND: Multitexture support - GL_MAX_TEXTURE_UNITS_ARB=%d\n", gl_max);
639 } else if (strcmp(ThisExtn, "GL_EXT_texture_env_dot3") == 0) {
640 object->isDot3 = TRUE;
641 TRACE("FOUND: Dot3 support\n");
644 if (*GL_Extensions == ' ') GL_Extensions++;
648 GLX_Extensions = glXQueryExtensionsString(object->display, DefaultScreen(object->display));
649 TRACE("GLX_Extensions reported:\n");
651 if (NULL == GLX_Extensions) {
652 ERR(" GLX_Extensions returns NULL\n");
653 } else {
654 while (*GLX_Extensions != 0x00) {
655 const char *Start = GLX_Extensions;
656 char ThisExtn[256];
658 memset(ThisExtn, 0x00, sizeof(ThisExtn));
659 while (*GLX_Extensions != ' ' && *GLX_Extensions != 0x00) {
660 GLX_Extensions++;
662 memcpy(ThisExtn, Start, (GLX_Extensions - Start));
663 TRACE (" %s\n", ThisExtn);
664 if (*GLX_Extensions == ' ') GLX_Extensions++;
668 /* Setup all the devices defaults */
669 IDirect3DDeviceImpl_InitStartupStateBlock(object);
671 LEAVE_GL();
673 { /* Set a default viewport */
674 D3DVIEWPORT8 vp;
675 vp.X = 0;
676 vp.Y = 0;
677 vp.Width = pPresentationParameters->BackBufferWidth;
678 vp.Height = pPresentationParameters->BackBufferHeight;
679 vp.MinZ = 0.0f;
680 vp.MaxZ = 1.0f;
681 IDirect3DDevice8Impl_SetViewport((LPDIRECT3DDEVICE8) object, &vp);
684 TRACE("(%p,%d) All defaults now set up, leaving CreateDevice\n", This, Adapter);
685 return D3D_OK;
688 ICOM_VTABLE(IDirect3D8) Direct3D8_Vtbl =
690 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
691 IDirect3D8Impl_QueryInterface,
692 IDirect3D8Impl_AddRef,
693 IDirect3D8Impl_Release,
694 IDirect3D8Impl_RegisterSoftwareDevice,
695 IDirect3D8Impl_GetAdapterCount,
696 IDirect3D8Impl_GetAdapterIdentifier,
697 IDirect3D8Impl_GetAdapterModeCount,
698 IDirect3D8Impl_EnumAdapterModes,
699 IDirect3D8Impl_GetAdapterDisplayMode,
700 IDirect3D8Impl_CheckDeviceType,
701 IDirect3D8Impl_CheckDeviceFormat,
702 IDirect3D8Impl_CheckDeviceMultiSampleType,
703 IDirect3D8Impl_CheckDepthStencilMatch,
704 IDirect3D8Impl_GetDeviceCaps,
705 IDirect3D8Impl_GetAdapterMonitor,
706 IDirect3D8Impl_CreateDevice