Make sure we advertize our capabilites correctly.
[wine/wine-gecko.git] / dlls / d3d8 / directx.c
blobce9d26f6e5309ad5fdaa93bec63a1f2d8557bece
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 switch(CheckFormat) {
276 case D3DFMT_UYVY:
277 case D3DFMT_YUY2:
278 case D3DFMT_DXT1:
279 case D3DFMT_DXT2:
280 case D3DFMT_DXT3:
281 case D3DFMT_DXT4:
282 case D3DFMT_DXT5:
283 /* Since we do not support these formats right now, don't pretend to. */
284 return D3DERR_NOTAVAILABLE;
285 default:
286 break;
288 return D3D_OK;
291 HRESULT WINAPI IDirect3D8Impl_CheckDeviceMultiSampleType (LPDIRECT3D8 iface,
292 UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat,
293 BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType) {
294 ICOM_THIS(IDirect3D8Impl,iface);
295 FIXME("(%p)->(Adptr:%d, DevType: %x, SurfFmt: %x, Win? %d, MultiSamp: %x)\n", This, Adapter, DeviceType,
296 SurfaceFormat, Windowed, MultiSampleType);
297 return D3D_OK;
300 HRESULT WINAPI IDirect3D8Impl_CheckDepthStencilMatch (LPDIRECT3D8 iface,
301 UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat,
302 D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat) {
303 ICOM_THIS(IDirect3D8Impl,iface);
304 FIXME("(%p)->(Adptr:%d, DevType: %x, AdptFmt: %x, RendrTgtFmt: %x, DepthStencilFmt: %x)\n", This, Adapter, DeviceType,
305 AdapterFormat, RenderTargetFormat, DepthStencilFormat);
306 return D3D_OK;
309 HRESULT WINAPI IDirect3D8Impl_GetDeviceCaps (LPDIRECT3D8 iface,
310 UINT Adapter, D3DDEVTYPE DeviceType, D3DCAPS8* pCaps) {
311 ICOM_THIS(IDirect3D8Impl,iface);
312 TRACE("(%p)->(Adptr:%d, DevType: %x, pCaps: %p)\n", This, Adapter, DeviceType, pCaps);
315 /* NOTE: Most of the values here are complete garbage for now */
316 pCaps->DeviceType = (DeviceType == D3DDEVTYPE_HAL) ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF; /* Not quite true, but use h/w supported by opengl I suppose */
317 pCaps->AdapterOrdinal = Adapter;
319 pCaps->Caps = 0;
320 pCaps->Caps2 = D3DCAPS2_CANRENDERWINDOWED;
321 pCaps->Caps3 = D3DDEVCAPS_HWTRANSFORMANDLIGHT;
322 pCaps->PresentationIntervals = D3DPRESENT_INTERVAL_IMMEDIATE;
324 pCaps->CursorCaps = 0;
326 pCaps->DevCaps = D3DDEVCAPS_DRAWPRIMTLVERTEX | D3DDEVCAPS_HWTRANSFORMANDLIGHT | D3DDEVCAPS_PUREDEVICE;
328 pCaps->PrimitiveMiscCaps = D3DPMISCCAPS_CULLCCW | D3DPMISCCAPS_CULLCW | D3DPMISCCAPS_COLORWRITEENABLE | D3DPMISCCAPS_CLIPTLVERTS |
329 D3DPMISCCAPS_CLIPPLANESCALEDPOINTS | D3DPMISCCAPS_MASKZ; /*NOT: D3DPMISCCAPS_TSSARGTEMP*/
330 pCaps->RasterCaps = D3DPRASTERCAPS_DITHER | D3DPRASTERCAPS_PAT;
331 pCaps->ZCmpCaps = D3DPCMPCAPS_ALWAYS | D3DPCMPCAPS_EQUAL | D3DPCMPCAPS_GREATER | D3DPCMPCAPS_GREATEREQUAL |
332 D3DPCMPCAPS_LESS | D3DPCMPCAPS_LESSEQUAL | D3DPCMPCAPS_NEVER | D3DPCMPCAPS_NOTEQUAL;
334 pCaps->SrcBlendCaps = 0xFFFFFFFF; /*FIXME: Tidy up later */
335 pCaps->DestBlendCaps = 0xFFFFFFFF; /*FIXME: Tidy up later */
336 pCaps->AlphaCmpCaps = 0xFFFFFFFF; /*FIXME: Tidy up later */
337 pCaps->ShadeCaps = D3DPSHADECAPS_SPECULARGOURAUDRGB | D3DPSHADECAPS_COLORGOURAUDRGB ;
338 pCaps->TextureCaps = D3DPTEXTURECAPS_ALPHA | D3DPTEXTURECAPS_ALPHAPALETTE | D3DPTEXTURECAPS_CUBEMAP | D3DPTEXTURECAPS_POW2 | D3DPTEXTURECAPS_VOLUMEMAP | D3DPTEXTURECAPS_MIPMAP;
339 pCaps->TextureFilterCaps = D3DPTFILTERCAPS_MAGFLINEAR | D3DPTFILTERCAPS_MAGFPOINT | D3DPTFILTERCAPS_MINFLINEAR | D3DPTFILTERCAPS_MINFPOINT |
340 D3DPTFILTERCAPS_MIPFLINEAR | D3DPTFILTERCAPS_MIPFPOINT ;
341 pCaps->CubeTextureFilterCaps = 0;
342 pCaps->VolumeTextureFilterCaps = 0;
343 pCaps->TextureAddressCaps = D3DPTADDRESSCAPS_BORDER | D3DPTADDRESSCAPS_CLAMP | D3DPTADDRESSCAPS_WRAP;
344 #if defined(GL_VERSION_1_3)
345 pCaps->TextureAddressCaps |= D3DPTADDRESSCAPS_MIRROR;
346 #endif
347 pCaps->VolumeTextureAddressCaps = 0;
349 pCaps->LineCaps = D3DLINECAPS_TEXTURE | D3DLINECAPS_ZTEST;
351 /*pCaps->MaxTextureWidth = 16384;
352 pCaps->MaxTextureHeight = 16384;*/
354 GLint gl_tex_size;
355 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gl_tex_size);
356 pCaps->MaxTextureWidth = gl_tex_size;
357 pCaps->MaxTextureHeight = gl_tex_size;
360 pCaps->MaxVolumeExtent = 0;
362 pCaps->MaxTextureRepeat = 32768;
363 pCaps->MaxTextureAspectRatio = 32768;
364 pCaps->MaxAnisotropy = 0;
365 pCaps->MaxVertexW = 1.0;
367 pCaps->GuardBandLeft = 0;
368 pCaps->GuardBandTop = 0;
369 pCaps->GuardBandRight = 0;
370 pCaps->GuardBandBottom = 0;
372 pCaps->ExtentsAdjust = 0;
374 pCaps->StencilCaps = D3DSTENCILCAPS_DECRSAT | D3DSTENCILCAPS_INCRSAT |
375 D3DSTENCILCAPS_INVERT | D3DSTENCILCAPS_KEEP |
376 D3DSTENCILCAPS_REPLACE | D3DSTENCILCAPS_ZERO /* | D3DSTENCILCAPS_DECR | D3DSTENCILCAPS_INCR */;
378 pCaps->FVFCaps = D3DFVFCAPS_PSIZE | 0x80000;
380 pCaps->TextureOpCaps = D3DTEXOPCAPS_ADD | D3DTEXOPCAPS_ADDSIGNED | D3DTEXOPCAPS_ADDSIGNED2X |
381 D3DTEXOPCAPS_MODULATE | D3DTEXOPCAPS_MODULATE2X | D3DTEXOPCAPS_MODULATE4X |
382 D3DTEXOPCAPS_SELECTARG1 | D3DTEXOPCAPS_SELECTARG2 | D3DTEXOPCAPS_DISABLE;
383 #if defined(GL_VERSION_1_3)
384 pCaps->TextureOpCaps |= D3DTEXOPCAPS_DOTPRODUCT3;
385 #endif
386 /* FIXME: Add D3DTEXOPCAPS_ADDSMOOTH D3DTEXOPCAPS_BLENDCURRENTALPHA D3DTEXOPCAPS_BLENDDIFFUSEALPHA D3DTEXOPCAPS_BLENDFACTORALPHA
387 D3DTEXOPCAPS_BLENDTEXTUREALPHA D3DTEXOPCAPS_BLENDTEXTUREALPHAPM D3DTEXOPCAPS_BUMPENVMAP D3DTEXOPCAPS_BUMPENVMAPLUMINANCE
388 D3DTEXOPCAPS_LERP D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
389 D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA D3DTEXOPCAPS_MULTIPLYADD
390 D3DTEXOPCAPS_PREMODULATE D3DTEXOPCAPS_SUBTRACT */
393 GLint gl_max;
394 #if defined(GL_VERSION_1_3)
395 glGetIntegerv(GL_MAX_TEXTURE_UNITS, &gl_max);
396 #else
397 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_max);
398 #endif
399 TRACE("GLCaps: GL_MAX_TEXTURE_UNITS_ARB=%d\n", gl_max);
400 pCaps->MaxTextureBlendStages = min(8, gl_max);
401 pCaps->MaxSimultaneousTextures = min(8, gl_max);
403 glGetIntegerv(GL_MAX_CLIP_PLANES, &gl_max);
404 pCaps->MaxUserClipPlanes = min(MAX_CLIPPLANES, gl_max);
405 TRACE("GLCaps: GL_MAX_CLIP_PLANES=%ld\n", pCaps->MaxUserClipPlanes);
407 glGetIntegerv(GL_MAX_LIGHTS, &gl_max);
408 pCaps->MaxActiveLights = min(MAX_ACTIVE_LIGHTS, gl_max);
409 TRACE("GLCaps: GL_MAX_LIGHTS=%ld\n", pCaps->MaxActiveLights);
412 pCaps->VertexProcessingCaps = D3DVTXPCAPS_DIRECTIONALLIGHTS | D3DVTXPCAPS_MATERIALSOURCE7 | D3DVTXPCAPS_POSITIONALLIGHTS | D3DVTXPCAPS_TEXGEN;
414 pCaps->MaxVertexBlendMatrices = 1;
415 pCaps->MaxVertexBlendMatrixIndex = 1;
417 pCaps->MaxPointSize = 128.0;
419 pCaps->MaxPrimitiveCount = 0xFFFFFFFF;
420 pCaps->MaxVertexIndex = 0xFFFFFFFF;
421 pCaps->MaxStreams = 2; /* HACK: Some games want at least 2 */
422 pCaps->MaxStreamStride = 1024;
424 pCaps->VertexShaderVersion = D3DVS_VERSION(1,1);
425 pCaps->MaxVertexShaderConst = D3D8_VSHADER_MAX_CONSTANTS;
427 pCaps->PixelShaderVersion = D3DPS_VERSION(1,1);
428 pCaps->MaxPixelShaderValue = 1.0;
430 return D3D_OK;
433 HMONITOR WINAPI IDirect3D8Impl_GetAdapterMonitor (LPDIRECT3D8 iface,
434 UINT Adapter) {
435 ICOM_THIS(IDirect3D8Impl,iface);
436 FIXME("(%p)->(Adptr:%d)\n", This, Adapter);
437 return D3D_OK;
440 HRESULT WINAPI IDirect3D8Impl_CreateDevice (LPDIRECT3D8 iface,
441 UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow,
442 DWORD BehaviourFlags, D3DPRESENT_PARAMETERS* pPresentationParameters,
443 IDirect3DDevice8** ppReturnedDeviceInterface) {
444 IDirect3DDevice8Impl *object;
445 HWND whichHWND;
446 int num;
447 XVisualInfo template;
448 const char *GL_Extensions = NULL;
449 const char *GLX_Extensions = NULL;
450 GLint gl_max;
452 ICOM_THIS(IDirect3D8Impl,iface);
453 TRACE("(%p)->(Adptr:%d, DevType: %x, FocusHwnd: %p, BehFlags: %lx, PresParms: %p, RetDevInt: %p)\n", This, Adapter, DeviceType,
454 hFocusWindow, BehaviourFlags, pPresentationParameters, ppReturnedDeviceInterface);
456 /* Allocate the storage for the device */
457 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DDevice8Impl));
458 if (NULL == object) {
459 return D3DERR_OUTOFVIDEOMEMORY;
461 object->lpVtbl = &Direct3DDevice8_Vtbl;
462 object->ref = 1;
463 object->direct3d8 = This;
464 /** The device AddRef the direct3d8 Interface else crash in propers clients codes */
465 IDirect3D8_AddRef((LPDIRECT3D8) object->direct3d8);
467 /** use StateBlock Factory here, for creating the startup stateBlock */
468 object->StateBlock = NULL;
469 IDirect3DDeviceImpl_CreateStateBlock(object, D3DSBT_ALL, NULL);
470 object->UpdateStateBlock = object->StateBlock;
472 /* Save the creation parameters */
473 object->CreateParms.AdapterOrdinal = Adapter;
474 object->CreateParms.DeviceType = DeviceType;
475 object->CreateParms.hFocusWindow = hFocusWindow;
476 object->CreateParms.BehaviorFlags = BehaviourFlags;
478 *ppReturnedDeviceInterface = (LPDIRECT3DDEVICE8)object;
480 /* Initialize settings */
481 memcpy(&object->PresentParms, pPresentationParameters, sizeof(D3DPRESENT_PARAMETERS));
483 object->PresentParms.BackBufferCount = 1; /* Opengl only supports one? */
484 pPresentationParameters->BackBufferCount = 1;
486 object->adapterNo = Adapter;
487 object->devType = DeviceType;
489 /* Initialize openGl */
491 HDC hDc;
492 int dblBuf[]={GLX_STENCIL_SIZE,8,GLX_RGBA,GLX_DEPTH_SIZE,16,GLX_DOUBLEBUFFER,None};
493 /* FIXME: Handle stencil appropriately via EnableAutoDepthStencil / AutoDepthStencilFormat */
494 /*int dblBuf[]={GLX_RGBA,GLX_RED_SIZE,4,GLX_GREEN_SIZE,4,GLX_BLUE_SIZE,4,GLX_DOUBLEBUFFER,None}; */
496 /* Which hwnd are we using? */
497 /* if (pPresentationParameters->Windowed) { */
498 whichHWND = pPresentationParameters->hDeviceWindow;
499 if (!whichHWND) {
500 whichHWND = hFocusWindow;
502 object->win = (Window)GetPropA( whichHWND, "__wine_x11_client_window" );
504 * } else {
505 * whichHWND = (HWND) GetDesktopWindow();
506 * object->win = (Window)GetPropA(whichHWND, "__wine_x11_whole_window" );
507 * root_window
511 hDc = GetDC(whichHWND);
512 object->display = get_display(hDc);
514 ENTER_GL();
515 object->visInfo = glXChooseVisual(object->display, DefaultScreen(object->display), dblBuf);
516 if (NULL == object->visInfo) {
517 FIXME("cannot choose needed glxVisual with Stencil Buffer\n");
520 * second try using wine initialized visual ...
521 * must be fixed reworking wine-glx init
523 template.visualid = (VisualID)GetPropA( GetDesktopWindow(), "__wine_x11_visual_id" );
524 object->visInfo = XGetVisualInfo(object->display, VisualIDMask, &template, &num);
525 if (NULL == object->visInfo) {
526 ERR("cannot really get XVisual\n");
527 LEAVE_GL();
528 return D3DERR_NOTAVAILABLE;
531 object->glCtx = glXCreateContext(object->display, object->visInfo, NULL, GL_TRUE);
532 if (NULL == object->glCtx) {
533 ERR("cannot create glxContext\n");
534 LEAVE_GL();
535 return D3DERR_NOTAVAILABLE;
537 LEAVE_GL();
539 ReleaseDC(whichHWND, hDc);
542 if (object->glCtx == NULL) {
543 ERR("Error in context creation !\n");
544 return D3DERR_INVALIDCALL;
545 } else {
546 TRACE("Context created (HWND=%p, glContext=%p, Window=%ld, VisInfo=%p)\n",
547 whichHWND, object->glCtx, object->win, object->visInfo);
550 /* If not windowed, need to go fullscreen, and resize the HWND to the appropriate */
551 /* dimensions */
552 if (!pPresentationParameters->Windowed) {
553 FIXME("Requested full screen support not implemented, expect windowed operation\n");
554 SetWindowPos(whichHWND, HWND_TOP, 0, 0, pPresentationParameters->BackBufferWidth,
555 pPresentationParameters->BackBufferHeight, SWP_SHOWWINDOW);
558 TRACE("Creating back buffer\n");
559 /* MSDN: If Windowed is TRUE and either of the BackBufferWidth/Height values is zero,
560 then the corresponding dimension of the client area of the hDeviceWindow
561 (or the focus window, if hDeviceWindow is NULL) is taken. */
562 if (pPresentationParameters->Windowed && ((pPresentationParameters->BackBufferWidth == 0) ||
563 (pPresentationParameters->BackBufferHeight == 0))) {
564 RECT Rect;
566 GetClientRect(whichHWND, &Rect);
568 if (pPresentationParameters->BackBufferWidth == 0) {
569 pPresentationParameters->BackBufferWidth = Rect.right;
570 TRACE("Updating width to %d\n", pPresentationParameters->BackBufferWidth);
572 if (pPresentationParameters->BackBufferHeight == 0) {
573 pPresentationParameters->BackBufferHeight = Rect.bottom;
574 TRACE("Updating height to %d\n", pPresentationParameters->BackBufferHeight);
578 IDirect3DDevice8Impl_CreateRenderTarget((LPDIRECT3DDEVICE8) object,
579 pPresentationParameters->BackBufferWidth,
580 pPresentationParameters->BackBufferHeight,
581 pPresentationParameters->BackBufferFormat,
582 D3DMULTISAMPLE_NONE, TRUE,
583 (LPDIRECT3DSURFACE8*) &object->frontBuffer);
585 IDirect3DDevice8Impl_CreateRenderTarget((LPDIRECT3DDEVICE8) object,
586 pPresentationParameters->BackBufferWidth,
587 pPresentationParameters->BackBufferHeight,
588 pPresentationParameters->BackBufferFormat,
589 D3DMULTISAMPLE_NONE, TRUE,
590 (LPDIRECT3DSURFACE8*) &object->backBuffer);
592 if (pPresentationParameters->EnableAutoDepthStencil)
593 IDirect3DDevice8Impl_CreateDepthStencilSurface((LPDIRECT3DDEVICE8) object,
594 pPresentationParameters->BackBufferWidth,
595 pPresentationParameters->BackBufferHeight,
596 pPresentationParameters->AutoDepthStencilFormat,
597 D3DMULTISAMPLE_NONE,
598 (LPDIRECT3DSURFACE8*) &object->depthStencilBuffer);
600 /* Now override the surface's Flip method (if in double buffering) ?COPIED from DDRAW!?
601 ((x11_ds_private *) surface->private)->opengl_flip = TRUE;
603 int i;
604 struct _surface_chain *chain = surface->s.chain;
605 for (i=0;i<chain->nrofsurfaces;i++)
606 if (chain->surfaces[i]->s.surface_desc.ddsCaps.dwCaps & DDSCAPS_FLIP)
607 ((x11_ds_private *) chain->surfaces[i]->private)->opengl_flip = TRUE;
611 ENTER_GL();
613 /*TRACE("hereeee. %x %x %x\n", object->display, object->win, object->glCtx);*/
614 if (glXMakeCurrent(object->display, object->win, object->glCtx) == False) {
615 ERR("Error in setting current context (context %p drawable %ld)!\n", object->glCtx, object->win);
617 checkGLcall("glXMakeCurrent");
619 /* Clear the screen */
620 glClearColor(1.0, 0.0, 0.0, 0.0);
621 checkGLcall("glClearColor");
622 glColor3f(1.0, 1.0, 1.0);
623 checkGLcall("glColor3f");
625 glEnable(GL_LIGHTING);
626 checkGLcall("glEnable");
628 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
629 checkGLcall("glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);");
631 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
632 checkGLcall("glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);");
634 /* Initialize openGL extension related variables */
635 object->isMultiTexture = FALSE;
636 object->isDot3 = FALSE;
637 object->TextureUnits = 1;
639 /* Retrieve opengl defaults */
640 glGetIntegerv(GL_MAX_CLIP_PLANES, &gl_max);
641 object->clipPlanes = min(MAX_CLIPPLANES, gl_max);
642 TRACE("ClipPlanes support - num Planes=%d\n", gl_max);
644 glGetIntegerv(GL_MAX_LIGHTS, &gl_max);
645 object->maxLights = min(MAX_ACTIVE_LIGHTS, gl_max);
646 TRACE("Lights support - max lights=%d\n", gl_max);
648 /* Parse the gl supported features, in theory enabling parts of our code appropriately */
649 GL_Extensions = glGetString(GL_EXTENSIONS);
650 TRACE("GL_Extensions reported:\n");
652 if (NULL == GL_Extensions) {
653 ERR(" GL_Extensions returns NULL\n");
654 } else {
655 while (*GL_Extensions != 0x00) {
656 const char *Start = GL_Extensions;
657 char ThisExtn[256];
659 memset(ThisExtn, 0x00, sizeof(ThisExtn));
660 while (*GL_Extensions != ' ' && *GL_Extensions != 0x00) {
661 GL_Extensions++;
663 memcpy(ThisExtn, Start, (GL_Extensions - Start));
664 TRACE (" %s\n", ThisExtn);
666 if (strcmp(ThisExtn, "GL_ARB_multitexture") == 0) {
667 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_max);
668 object->isMultiTexture = TRUE;
669 object->TextureUnits = min(8, gl_max);
670 TRACE("FOUND: Multitexture support - GL_MAX_TEXTURE_UNITS_ARB=%d\n", gl_max);
671 } else if (strcmp(ThisExtn, "GL_EXT_texture_env_dot3") == 0) {
672 object->isDot3 = TRUE;
673 TRACE("FOUND: Dot3 support\n");
676 if (*GL_Extensions == ' ') GL_Extensions++;
680 GLX_Extensions = glXQueryExtensionsString(object->display, DefaultScreen(object->display));
681 TRACE("GLX_Extensions reported:\n");
683 if (NULL == GLX_Extensions) {
684 ERR(" GLX_Extensions returns NULL\n");
685 } else {
686 while (*GLX_Extensions != 0x00) {
687 const char *Start = GLX_Extensions;
688 char ThisExtn[256];
690 memset(ThisExtn, 0x00, sizeof(ThisExtn));
691 while (*GLX_Extensions != ' ' && *GLX_Extensions != 0x00) {
692 GLX_Extensions++;
694 memcpy(ThisExtn, Start, (GLX_Extensions - Start));
695 TRACE (" %s\n", ThisExtn);
696 if (*GLX_Extensions == ' ') GLX_Extensions++;
700 /* Setup all the devices defaults */
701 IDirect3DDeviceImpl_InitStartupStateBlock(object);
703 LEAVE_GL();
705 { /* Set a default viewport */
706 D3DVIEWPORT8 vp;
707 vp.X = 0;
708 vp.Y = 0;
709 vp.Width = pPresentationParameters->BackBufferWidth;
710 vp.Height = pPresentationParameters->BackBufferHeight;
711 vp.MinZ = 0.0f;
712 vp.MaxZ = 1.0f;
713 IDirect3DDevice8Impl_SetViewport((LPDIRECT3DDEVICE8) object, &vp);
716 TRACE("(%p,%d) All defaults now set up, leaving CreateDevice\n", This, Adapter);
717 return D3D_OK;
720 ICOM_VTABLE(IDirect3D8) Direct3D8_Vtbl =
722 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
723 IDirect3D8Impl_QueryInterface,
724 IDirect3D8Impl_AddRef,
725 IDirect3D8Impl_Release,
726 IDirect3D8Impl_RegisterSoftwareDevice,
727 IDirect3D8Impl_GetAdapterCount,
728 IDirect3D8Impl_GetAdapterIdentifier,
729 IDirect3D8Impl_GetAdapterModeCount,
730 IDirect3D8Impl_EnumAdapterModes,
731 IDirect3D8Impl_GetAdapterDisplayMode,
732 IDirect3D8Impl_CheckDeviceType,
733 IDirect3D8Impl_CheckDeviceFormat,
734 IDirect3D8Impl_CheckDeviceMultiSampleType,
735 IDirect3D8Impl_CheckDepthStencilMatch,
736 IDirect3D8Impl_GetDeviceCaps,
737 IDirect3D8Impl_GetAdapterMonitor,
738 IDirect3D8Impl_CreateDevice