2 * IDirect3D8 implementation
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2003-2004 Raphael Junqueira
6 * Copyright 2004 Christian Costa
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
33 #include "wine/debug.h"
34 #include "wine/unicode.h"
36 #include "d3d8_private.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
39 WINE_DECLARE_DEBUG_CHANNEL(d3d_caps);
41 /* x11drv GDI escapes */
42 #define X11DRV_ESCAPE 6789
43 enum x11drv_escape_codes
45 X11DRV_GET_DISPLAY, /* get X11 display for a DC */
46 X11DRV_GET_DRAWABLE, /* get current drawable for a DC */
47 X11DRV_GET_FONT, /* get current X font for a DC */
51 static const D3DFORMAT device_formats[NUM_FORMATS] = {
61 static void IDirect3D8Impl_FillGLCaps(LPDIRECT3D8 iface, Display* display);
64 /* retrieve the X display to use on a given DC */
65 inline static Display *get_display( HDC hdc )
68 enum x11drv_escape_codes escape = X11DRV_GET_DISPLAY;
70 if (!ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPCSTR)&escape,
71 sizeof(display), (LPSTR)&display )) display = NULL;
76 * Note: GL seems to trap if GetDeviceCaps is called before any HWND's created
77 * ie there is no GL Context - Get a default rendering context to enable the
78 * function query some info from GL
81 WineD3D_Context* WineD3DCreateFakeGLContext(void) {
82 static WineD3D_Context ctx = { NULL, NULL, NULL, 0, 0 };
83 WineD3D_Context* ret = NULL;
85 if (glXGetCurrentContext() == NULL) {
86 BOOL gotContext = FALSE;
93 XWindowAttributes win_attr;
95 TRACE_(d3d_caps)("Creating Fake GL Context\n");
97 ctx.drawable = (Drawable) GetPropA(GetDesktopWindow(), "__wine_x11_whole_window");
100 device_context = GetDC(0);
101 ctx.display = get_display(device_context);
102 ReleaseDC(0, device_context);
104 /* Get the X visual */
106 if (XGetWindowAttributes(ctx.display, ctx.drawable, &win_attr)) {
107 visual = win_attr.visual;
109 visual = DefaultVisual(ctx.display, DefaultScreen(ctx.display));
111 template.visualid = XVisualIDFromVisual(visual);
112 ctx.visInfo = XGetVisualInfo(ctx.display, VisualIDMask, &template, &num);
113 if (ctx.visInfo == NULL) {
115 WARN_(d3d_caps)("Error creating visual info for capabilities initialization\n");
119 /* Create a GL context */
121 ctx.glCtx = glXCreateContext(ctx.display, ctx.visInfo, NULL, GL_TRUE);
123 if (ctx.glCtx == NULL) {
125 WARN_(d3d_caps)("Error creating default context for capabilities initialization\n");
130 /* Make it the current GL context */
131 if (!failed && glXMakeCurrent(ctx.display, ctx.drawable, ctx.glCtx) == False) {
132 glXDestroyContext(ctx.display, ctx.glCtx);
134 WARN_(d3d_caps)("Error setting default context as current for capabilities initialization\n");
138 /* It worked! Wow... */
147 if (ctx.ref > 0) ret = &ctx;
150 if (NULL != ret) ++ret->ref;
156 void WineD3DReleaseFakeGLContext(WineD3D_Context* ctx) {
157 /* If we created a dummy context, throw it away */
161 glXMakeCurrent(ctx->display, None, NULL);
162 glXDestroyContext(ctx->display, ctx->glCtx);
171 /* IDirect3D IUnknown parts follow: */
172 HRESULT WINAPI IDirect3D8Impl_QueryInterface(LPDIRECT3D8 iface,REFIID riid,LPVOID *ppobj)
174 ICOM_THIS(IDirect3D8Impl,iface);
176 if (IsEqualGUID(riid, &IID_IUnknown)
177 || IsEqualGUID(riid, &IID_IDirect3D8)) {
178 IDirect3D8Impl_AddRef(iface);
183 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
184 return E_NOINTERFACE;
187 ULONG WINAPI IDirect3D8Impl_AddRef(LPDIRECT3D8 iface) {
188 ICOM_THIS(IDirect3D8Impl,iface);
189 TRACE("(%p) : AddRef from %ld\n", This, This->ref);
190 return ++(This->ref);
193 ULONG WINAPI IDirect3D8Impl_Release(LPDIRECT3D8 iface) {
194 ICOM_THIS(IDirect3D8Impl,iface);
195 ULONG ref = --This->ref;
196 TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
198 HeapFree(GetProcessHeap(), 0, This);
202 /* IDirect3D Interface follow: */
203 HRESULT WINAPI IDirect3D8Impl_RegisterSoftwareDevice (LPDIRECT3D8 iface, void* pInitializeFunction) {
204 ICOM_THIS(IDirect3D8Impl,iface);
205 FIXME_(d3d_caps)("(%p)->(%p): stub\n", This, pInitializeFunction);
209 UINT WINAPI IDirect3D8Impl_GetAdapterCount (LPDIRECT3D8 iface) {
210 ICOM_THIS(IDirect3D8Impl,iface);
211 /* FIXME: Set to one for now to imply the display */
212 TRACE_(d3d_caps)("(%p): Mostly stub, only returns primary display\n", This);
216 HRESULT WINAPI IDirect3D8Impl_GetAdapterIdentifier (LPDIRECT3D8 iface,
217 UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER8* pIdentifier) {
218 ICOM_THIS(IDirect3D8Impl,iface);
220 TRACE_(d3d_caps)("(%p}->(Adapter: %d, Flags: %lx, pId=%p)\n", This, Adapter, Flags, pIdentifier);
222 if (Adapter >= IDirect3D8Impl_GetAdapterCount(iface)) {
223 return D3DERR_INVALIDCALL;
226 if (Adapter == 0) { /* Display */
227 /* If we don't know the device settings, go query them now */
228 if (This->isGLInfoValid == FALSE) {
229 WineD3D_Context* ctx = WineD3DCreateFakeGLContext();
230 if (NULL != ctx) IDirect3D8Impl_FillGLCaps(iface, NULL);
231 WineD3DReleaseFakeGLContext(ctx);
233 if (This->isGLInfoValid == TRUE) {
234 TRACE_(d3d_caps)("device/Vendor Name and Version detection using FillGLCaps\n");
235 strcpy(pIdentifier->Driver, "Display");
236 strcpy(pIdentifier->Description, "Direct3D HAL");
237 pIdentifier->DriverVersion.u.HighPart = 0xa;
238 pIdentifier->DriverVersion.u.LowPart = This->gl_info.gl_driver_version;
239 pIdentifier->VendorId = This->gl_info.gl_vendor;
240 pIdentifier->DeviceId = This->gl_info.gl_card;
241 pIdentifier->SubSysId = 0;
242 pIdentifier->Revision = 0;
244 WARN_(d3d_caps)("Cannot get GLCaps for device/Vendor Name and Version detection using FillGLCaps, currently using NVIDIA identifiers\n");
245 strcpy(pIdentifier->Driver, "Display");
246 strcpy(pIdentifier->Description, "Direct3D HAL");
247 pIdentifier->DriverVersion.u.HighPart = 0xa;
248 pIdentifier->DriverVersion.u.LowPart = MAKEDWORD_VERSION(53, 96); /* last Linux Nvidia drivers */
249 pIdentifier->VendorId = VENDOR_NVIDIA;
250 pIdentifier->DeviceId = CARD_NVIDIA_GEFORCE4_TI4600;
251 pIdentifier->SubSysId = 0;
252 pIdentifier->Revision = 0;
254 /*FIXME: memcpy(&pIdentifier->DeviceIdentifier, ??, sizeof(??GUID)); */
255 if (Flags & D3DENUM_NO_WHQL_LEVEL) {
256 pIdentifier->WHQLLevel = 0;
258 pIdentifier->WHQLLevel = 1;
261 FIXME_(d3d_caps)("Adapter not primary display\n");
267 UINT WINAPI IDirect3D8Impl_GetAdapterModeCount (LPDIRECT3D8 iface,
269 ICOM_THIS(IDirect3D8Impl,iface);
271 TRACE_(d3d_caps)("(%p}->(Adapter: %d)\n", This, Adapter);
273 if (Adapter >= IDirect3D8Impl_GetAdapterCount(iface)) {
274 return D3DERR_INVALIDCALL;
277 if (Adapter == 0) { /* Display */
281 while (EnumDisplaySettingsExW(NULL, i, &DevModeW, 0)) {
284 TRACE_(d3d_caps)("(%p}->(Adapter: %d) => %d\n", This, Adapter, i);
287 FIXME_(d3d_caps)("Adapter not primary display\n");
293 HRESULT WINAPI IDirect3D8Impl_EnumAdapterModes (LPDIRECT3D8 iface,
294 UINT Adapter, UINT Mode, D3DDISPLAYMODE* pMode) {
295 ICOM_THIS(IDirect3D8Impl,iface);
297 TRACE_(d3d_caps)("(%p}->(Adapter:%d, mode:%d, pMode:%p)\n", This, Adapter, Mode, pMode);
299 if (Adapter >= IDirect3D8Impl_GetAdapterCount(iface)) {
300 return D3DERR_INVALIDCALL;
303 if (Adapter == 0) { /* Display */
308 if (EnumDisplaySettingsExW(NULL, Mode, &DevModeW, 0))
310 pMode->Width = DevModeW.dmPelsWidth;
311 pMode->Height = DevModeW.dmPelsHeight;
312 bpp = DevModeW.dmBitsPerPel;
313 pMode->RefreshRate = D3DADAPTER_DEFAULT;
314 if (DevModeW.dmFields&DM_DISPLAYFREQUENCY)
316 pMode->RefreshRate = DevModeW.dmDisplayFrequency;
321 TRACE_(d3d_caps)("Requested mode out of range %d\n", Mode);
322 return D3DERR_INVALIDCALL;
325 hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
326 bpp = min(GetDeviceCaps(hdc, BITSPIXEL), bpp);
330 case 8: pMode->Format = D3DFMT_R3G3B2; break;
331 case 16: pMode->Format = D3DFMT_R5G6B5; break;
332 case 24: /* pMode->Format = D3DFMT_R5G6B5; break;*/ /* Make 24bit appear as 32 bit */
333 case 32: pMode->Format = D3DFMT_A8R8G8B8; break;
334 default: pMode->Format = D3DFMT_UNKNOWN;
336 TRACE_(d3d_caps)("W %d H %d rr %d fmt (%x,%s) bpp %u\n", pMode->Width, pMode->Height, pMode->RefreshRate, pMode->Format, debug_d3dformat(pMode->Format), bpp);
339 FIXME_(d3d_caps)("Adapter not primary display\n");
345 HRESULT WINAPI IDirect3D8Impl_GetAdapterDisplayMode (LPDIRECT3D8 iface,
346 UINT Adapter, D3DDISPLAYMODE* pMode) {
347 ICOM_THIS(IDirect3D8Impl,iface);
348 TRACE_(d3d_caps)("(%p}->(Adapter: %d, pMode: %p)\n", This, Adapter, pMode);
350 if (Adapter >= IDirect3D8Impl_GetAdapterCount(iface)) {
351 return D3DERR_INVALIDCALL;
354 if (Adapter == 0) { /* Display */
358 EnumDisplaySettingsExW(NULL, (DWORD)-1, &DevModeW, 0);
359 pMode->Width = DevModeW.dmPelsWidth;
360 pMode->Height = DevModeW.dmPelsHeight;
361 bpp = DevModeW.dmBitsPerPel;
362 pMode->RefreshRate = D3DADAPTER_DEFAULT;
363 if (DevModeW.dmFields&DM_DISPLAYFREQUENCY)
365 pMode->RefreshRate = DevModeW.dmDisplayFrequency;
369 case 8: pMode->Format = D3DFMT_R3G3B2; break;
370 case 16: pMode->Format = D3DFMT_R5G6B5; break;
371 case 24: /*pMode->Format = D3DFMT_R5G6B5; break;*/ /* Make 24bit appear as 32 bit */
372 case 32: pMode->Format = D3DFMT_A8R8G8B8; break;
373 default: pMode->Format = D3DFMT_UNKNOWN;
377 FIXME_(d3d_caps)("Adapter not primary display\n");
380 TRACE_(d3d_caps)("returning w:%d, h:%d, ref:%d, fmt:%x\n", pMode->Width,
381 pMode->Height, pMode->RefreshRate, pMode->Format);
385 HRESULT WINAPI IDirect3D8Impl_CheckDeviceType (LPDIRECT3D8 iface,
386 UINT Adapter, D3DDEVTYPE CheckType, D3DFORMAT DisplayFormat,
387 D3DFORMAT BackBufferFormat, BOOL Windowed) {
388 ICOM_THIS(IDirect3D8Impl,iface);
389 TRACE_(d3d_caps)("(%p)->(Adptr:%d, CheckType:(%x,%s), DispFmt:(%x,%s), BackBuf:(%x,%s), Win?%d): stub\n",
392 CheckType, debug_d3ddevicetype(CheckType),
393 DisplayFormat, debug_d3dformat(DisplayFormat),
394 BackBufferFormat, debug_d3dformat(BackBufferFormat),
397 switch (DisplayFormat) {
398 case D3DFMT_A8R8G8B8:
399 return D3DERR_NOTAVAILABLE;
408 HRESULT WINAPI IDirect3D8Impl_CheckDeviceFormat (LPDIRECT3D8 iface,
409 UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat,
410 DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat) {
411 ICOM_THIS(IDirect3D8Impl,iface);
412 TRACE_(d3d_caps)("(%p)->(Adptr:%d, DevType:(%u,%s), AdptFmt:(%u,%s), Use:(%lu,%s), ResTyp:(%x,%s), CheckFmt:(%u,%s))\n",
415 DeviceType, debug_d3ddevicetype(DeviceType),
416 AdapterFormat, debug_d3dformat(AdapterFormat),
417 Usage, debug_d3dusage(Usage),
418 RType, debug_d3dressourcetype(RType),
419 CheckFormat, debug_d3dformat(CheckFormat));
421 if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
422 switch (CheckFormat) {
428 break; /* Avoid compiler warnings */
432 switch (CheckFormat) {
440 case D3DFMT_X8L8V8U8:
444 /* Since we do not support these formats right now, don't pretend to. */
445 return D3DERR_NOTAVAILABLE;
453 HRESULT WINAPI IDirect3D8Impl_CheckDeviceMultiSampleType(LPDIRECT3D8 iface,
454 UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat,
455 BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType) {
456 ICOM_THIS(IDirect3D8Impl,iface);
457 TRACE_(d3d_caps)("(%p)->(Adptr:%d, DevType:(%x,%s), SurfFmt:(%x,%s), Win?%d, MultiSamp:%x)\n",
460 DeviceType, debug_d3ddevicetype(DeviceType),
461 SurfaceFormat, debug_d3dformat(SurfaceFormat),
465 if (D3DMULTISAMPLE_NONE == MultiSampleType)
467 return D3DERR_NOTAVAILABLE;
470 HRESULT WINAPI IDirect3D8Impl_CheckDepthStencilMatch(LPDIRECT3D8 iface,
471 UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat,
472 D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat) {
473 ICOM_THIS(IDirect3D8Impl,iface);
474 TRACE_(d3d_caps)("(%p)->(Adptr:%d, DevType:(%x,%s), AdptFmt:(%x,%s), RendrTgtFmt:(%x,%s), DepthStencilFmt:(%x,%s))\n",
477 DeviceType, debug_d3ddevicetype(DeviceType),
478 AdapterFormat, debug_d3dformat(AdapterFormat),
479 RenderTargetFormat, debug_d3dformat(RenderTargetFormat),
480 DepthStencilFormat, debug_d3dformat(DepthStencilFormat));
483 switch (DepthStencilFormat) {
489 * as i don't know how to really check hard caps of graphics cards
490 * i prefer to not permit 32bit zbuffers enumeration (as few cards can do it)
492 return D3DERR_NOTAVAILABLE;
500 HRESULT WINAPI IDirect3D8Impl_GetDeviceCaps(LPDIRECT3D8 iface, UINT Adapter, D3DDEVTYPE DeviceType, D3DCAPS8* pCaps) {
502 BOOL gotContext = FALSE;
503 GLint gl_tex_size = 0;
504 WineD3D_Context* fake_ctx = NULL;
505 ICOM_THIS(IDirect3D8Impl,iface);
507 TRACE_(d3d_caps)("(%p)->(Adptr:%d, DevType: %x, pCaps: %p)\n", This, Adapter, DeviceType, pCaps);
509 /* Note: GL seems to trap if GetDeviceCaps is called before any HWND's created
510 ie there is no GL Context - Get a default rendering context to enable the
511 function query some info from GL */
512 if (glXGetCurrentContext() == NULL) {
513 fake_ctx = WineD3DCreateFakeGLContext();
514 if (NULL != fake_ctx) gotContext = TRUE;
519 if (gotContext == FALSE) {
521 FIXME_(d3d_caps)("GetDeviceCaps called but no GL Context - Returning dummy values\n");
523 pCaps->MaxTextureBlendStages = 2;
524 pCaps->MaxSimultaneousTextures = 2;
525 pCaps->MaxUserClipPlanes = 8;
526 pCaps->MaxActiveLights = 8;
527 pCaps->MaxVertexBlendMatrices = 0;
528 pCaps->MaxVertexBlendMatrixIndex = 1;
529 pCaps->MaxAnisotropy = 0;
530 pCaps->MaxPointSize = 255.0;
532 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gl_tex_size);
535 /* If we don't know the device settings, go query them now */
536 if (This->isGLInfoValid == FALSE) IDirect3D8Impl_FillGLCaps(iface, NULL);
538 pCaps->DeviceType = (DeviceType == D3DDEVTYPE_HAL) ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF; /* Not quite true, but use h/w supported by opengl I suppose */
539 pCaps->AdapterOrdinal = Adapter;
542 pCaps->Caps2 = D3DCAPS2_CANRENDERWINDOWED;
543 pCaps->Caps3 = D3DDEVCAPS_HWTRANSFORMANDLIGHT;
544 pCaps->PresentationIntervals = D3DPRESENT_INTERVAL_IMMEDIATE;
546 pCaps->CursorCaps = 0;
548 pCaps->DevCaps = D3DDEVCAPS_DRAWPRIMTLVERTEX |
549 D3DDEVCAPS_HWTRANSFORMANDLIGHT |
550 D3DDEVCAPS_PUREDEVICE;
552 pCaps->PrimitiveMiscCaps = D3DPMISCCAPS_CULLCCW |
553 D3DPMISCCAPS_CULLCW |
554 D3DPMISCCAPS_COLORWRITEENABLE |
555 D3DPMISCCAPS_CLIPTLVERTS |
556 D3DPMISCCAPS_CLIPPLANESCALEDPOINTS |
558 /*NOT: D3DPMISCCAPS_TSSARGTEMP*/
560 pCaps->RasterCaps = D3DPRASTERCAPS_DITHER |
562 D3DPRASTERCAPS_WFOG |
563 D3DPRASTERCAPS_ZFOG |
564 D3DPRASTERCAPS_FOGVERTEX |
565 D3DPRASTERCAPS_FOGTABLE |
566 D3DPRASTERCAPS_FOGRANGE;
568 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC)) {
569 pCaps->RasterCaps |= D3DPRASTERCAPS_ANISOTROPY;
572 D3DPRASTERCAPS_MIPMAPLODBIAS
574 D3DPRASTERCAPS_COLORPERSPECTIVE
575 D3DPRASTERCAPS_STRETCHBLTMULTISAMPLE
576 D3DPRASTERCAPS_ANTIALIASEDGES
577 D3DPRASTERCAPS_ZBUFFERLESSHSR
578 D3DPRASTERCAPS_WBUFFER */
580 pCaps->ZCmpCaps = D3DPCMPCAPS_ALWAYS |
582 D3DPCMPCAPS_GREATER |
583 D3DPCMPCAPS_GREATEREQUAL |
585 D3DPCMPCAPS_LESSEQUAL |
587 D3DPCMPCAPS_NOTEQUAL;
589 pCaps->SrcBlendCaps = 0xFFFFFFFF; /*FIXME: Tidy up later */
590 pCaps->DestBlendCaps = 0xFFFFFFFF; /*FIXME: Tidy up later */
591 pCaps->AlphaCmpCaps = 0xFFFFFFFF; /*FIXME: Tidy up later */
593 pCaps->ShadeCaps = D3DPSHADECAPS_SPECULARGOURAUDRGB |
594 D3DPSHADECAPS_COLORGOURAUDRGB;
596 pCaps->TextureCaps = D3DPTEXTURECAPS_ALPHA |
597 D3DPTEXTURECAPS_ALPHAPALETTE |
598 D3DPTEXTURECAPS_POW2 |
599 D3DPTEXTURECAPS_VOLUMEMAP |
600 D3DPTEXTURECAPS_MIPMAP;
602 if (GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
603 pCaps->TextureCaps |= D3DPTEXTURECAPS_CUBEMAP |
604 D3DPTEXTURECAPS_MIPCUBEMAP |
605 D3DPTEXTURECAPS_CUBEMAP_POW2;
608 pCaps->TextureFilterCaps = D3DPTFILTERCAPS_MAGFLINEAR |
609 D3DPTFILTERCAPS_MAGFPOINT |
610 D3DPTFILTERCAPS_MINFLINEAR |
611 D3DPTFILTERCAPS_MINFPOINT |
612 D3DPTFILTERCAPS_MIPFLINEAR |
613 D3DPTFILTERCAPS_MIPFPOINT;
615 pCaps->CubeTextureFilterCaps = 0;
616 pCaps->VolumeTextureFilterCaps = 0;
618 pCaps->TextureAddressCaps = D3DPTADDRESSCAPS_BORDER |
619 D3DPTADDRESSCAPS_CLAMP |
620 D3DPTADDRESSCAPS_WRAP;
622 if (GL_SUPPORT(ARB_TEXTURE_BORDER_CLAMP)) {
623 pCaps->TextureAddressCaps |= D3DPTADDRESSCAPS_BORDER;
625 if (GL_SUPPORT(ARB_TEXTURE_MIRRORED_REPEAT)) {
626 pCaps->TextureAddressCaps |= D3DPTADDRESSCAPS_MIRROR;
628 if (GL_SUPPORT(ATI_TEXTURE_MIRROR_ONCE)) {
629 pCaps->TextureAddressCaps |= D3DPTADDRESSCAPS_MIRRORONCE;
632 pCaps->VolumeTextureAddressCaps = 0;
634 pCaps->LineCaps = D3DLINECAPS_TEXTURE |
641 pCaps->MaxTextureWidth = gl_tex_size;
642 pCaps->MaxTextureHeight = gl_tex_size;
644 pCaps->MaxVolumeExtent = 0;
646 pCaps->MaxTextureRepeat = 32768;
647 pCaps->MaxTextureAspectRatio = 32768;
648 pCaps->MaxVertexW = 1.0;
650 pCaps->GuardBandLeft = 0;
651 pCaps->GuardBandTop = 0;
652 pCaps->GuardBandRight = 0;
653 pCaps->GuardBandBottom = 0;
655 pCaps->ExtentsAdjust = 0;
657 pCaps->StencilCaps = D3DSTENCILCAPS_DECRSAT |
658 D3DSTENCILCAPS_INCRSAT |
659 D3DSTENCILCAPS_INVERT |
660 D3DSTENCILCAPS_KEEP |
661 D3DSTENCILCAPS_REPLACE |
663 #if defined(GL_VERSION_1_4) || defined(GL_EXT_stencil_wrap)
664 pCaps->StencilCaps |= D3DSTENCILCAPS_DECR |
668 pCaps->FVFCaps = D3DFVFCAPS_PSIZE | 0x80000;
670 pCaps->TextureOpCaps = D3DTEXOPCAPS_ADD |
671 D3DTEXOPCAPS_ADDSIGNED |
672 D3DTEXOPCAPS_ADDSIGNED2X |
673 D3DTEXOPCAPS_MODULATE |
674 D3DTEXOPCAPS_MODULATE2X |
675 D3DTEXOPCAPS_MODULATE4X |
676 D3DTEXOPCAPS_SELECTARG1 |
677 D3DTEXOPCAPS_SELECTARG2 |
678 D3DTEXOPCAPS_DISABLE;
679 #if defined(GL_VERSION_1_3)
680 pCaps->TextureOpCaps |= D3DTEXOPCAPS_DOTPRODUCT3 |
681 D3DTEXOPCAPS_SUBTRACT;
683 if (GL_SUPPORT(ARB_TEXTURE_ENV_COMBINE) ||
684 GL_SUPPORT(EXT_TEXTURE_ENV_COMBINE) ||
685 GL_SUPPORT(NV_TEXTURE_ENV_COMBINE4)) {
686 pCaps->TextureOpCaps |= D3DTEXOPCAPS_BLENDDIFFUSEALPHA |
687 D3DTEXOPCAPS_BLENDTEXTUREALPHA |
688 D3DTEXOPCAPS_BLENDFACTORALPHA |
689 D3DTEXOPCAPS_BLENDCURRENTALPHA |
692 if (GL_SUPPORT(NV_TEXTURE_ENV_COMBINE4)) {
693 pCaps->TextureOpCaps |= D3DTEXOPCAPS_ADDSMOOTH |
694 D3DTEXOPCAPS_MULTIPLYADD |
695 D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR |
696 D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA |
697 D3DTEXOPCAPS_BLENDTEXTUREALPHAPM;
700 D3DTEXOPCAPS_BUMPENVMAP
701 D3DTEXOPCAPS_BUMPENVMAPLUMINANCE
702 D3DTEXOPCAPS_PREMODULATE */
707 #if defined(GL_VERSION_1_3)
708 glGetIntegerv(GL_MAX_TEXTURE_UNITS, &gl_max);
710 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_max);
712 TRACE_(d3d_caps)("GLCaps: GL_MAX_TEXTURE_UNITS_ARB=%d\n", gl_max);
713 pCaps->MaxTextureBlendStages = min(8, gl_max);
714 pCaps->MaxSimultaneousTextures = min(8, gl_max);
716 glGetIntegerv(GL_MAX_CLIP_PLANES, &gl_max);
717 pCaps->MaxUserClipPlanes = min(MAX_CLIPPLANES, gl_max);
718 TRACE_(d3d_caps)("GLCaps: GL_MAX_CLIP_PLANES=%ld\n", pCaps->MaxUserClipPlanes);
720 glGetIntegerv(GL_MAX_LIGHTS, &gl_max);
721 pCaps->MaxActiveLights = gl_max;
722 TRACE_(d3d_caps)("GLCaps: GL_MAX_LIGHTS=%ld\n", pCaps->MaxActiveLights);
724 if (GL_SUPPORT(ARB_VERTEX_BLEND)) {
725 glGetIntegerv(GL_MAX_VERTEX_UNITS_ARB, &gl_max);
726 pCaps->MaxVertexBlendMatrices = gl_max;
727 pCaps->MaxVertexBlendMatrixIndex = 1;
729 pCaps->MaxVertexBlendMatrices = 0;
730 pCaps->MaxVertexBlendMatrixIndex = 1;
733 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC)) {
734 glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &gl_max);
735 checkGLcall("glGetInterv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT)");
736 pCaps->MaxAnisotropy = gl_max;
738 pCaps->MaxAnisotropy = 0;
741 glGetFloatv(GL_POINT_SIZE_RANGE, &gl_float);
742 pCaps->MaxPointSize = gl_float;
745 pCaps->VertexProcessingCaps = D3DVTXPCAPS_DIRECTIONALLIGHTS |
746 D3DVTXPCAPS_MATERIALSOURCE7 |
747 D3DVTXPCAPS_POSITIONALLIGHTS |
750 D3DVTXPCAPS_LOCALVIEWER
751 D3DVTXPCAPS_TWEENING */
753 pCaps->MaxPrimitiveCount = 0xFFFFFFFF;
754 pCaps->MaxVertexIndex = 0xFFFFFFFF;
755 pCaps->MaxStreams = MAX_STREAMS;
756 pCaps->MaxStreamStride = 1024;
758 if (((vs_mode == VS_HW) && GL_SUPPORT(ARB_VERTEX_PROGRAM)) || (vs_mode == VS_SW) || (DeviceType == D3DDEVTYPE_REF))
759 pCaps->VertexShaderVersion = D3DVS_VERSION(1,1);
761 pCaps->VertexShaderVersion = 0;
762 pCaps->MaxVertexShaderConst = D3D8_VSHADER_MAX_CONSTANTS;
765 pCaps->PixelShaderVersion = D3DPS_VERSION(1,1);
766 pCaps->MaxPixelShaderValue = 1.0;
768 pCaps->PixelShaderVersion = 0;
769 pCaps->MaxPixelShaderValue = 0.0;
772 /* If we created a dummy context, throw it away */
773 WineD3DReleaseFakeGLContext(fake_ctx);
777 HMONITOR WINAPI IDirect3D8Impl_GetAdapterMonitor(LPDIRECT3D8 iface, UINT Adapter) {
778 ICOM_THIS(IDirect3D8Impl,iface);
779 FIXME_(d3d_caps)("(%p)->(Adptr:%d)\n", This, Adapter);
784 static void IDirect3D8Impl_FillGLCaps(LPDIRECT3D8 iface, Display* display) {
785 const char *GL_Extensions = NULL;
786 const char *GLX_Extensions = NULL;
788 const char* gl_string = NULL;
789 const char* gl_string_cursor = NULL;
792 ICOM_THIS(IDirect3D8Impl,iface);
794 if (This->gl_info.bIsFilled) return ;
795 This->gl_info.bIsFilled = 1;
797 TRACE_(d3d_caps)("(%p, %p)\n", This, display);
799 if (NULL != display) {
800 test = glXQueryVersion(NULL, &major, &minor);
801 This->gl_info.glx_version = ((major & 0x0000FFFF) << 16) | (minor & 0x0000FFFF);
802 gl_string = glXGetClientString(NULL, GLX_VENDOR);
804 gl_string = glGetString(GL_VENDOR);
807 if (strstr(gl_string, "NVIDIA")) {
808 This->gl_info.gl_vendor = VENDOR_NVIDIA;
809 } else if (strstr(gl_string, "ATI")) {
810 This->gl_info.gl_vendor = VENDOR_ATI;
812 This->gl_info.gl_vendor = VENDOR_WINE;
815 TRACE_(d3d_caps)("found GL_VENDOR (%s)->(0x%04x)\n", debugstr_a(gl_string), This->gl_info.gl_vendor);
817 gl_string = glGetString(GL_VERSION);
818 switch (This->gl_info.gl_vendor) {
820 gl_string_cursor = strstr(gl_string, "NVIDIA");
821 gl_string_cursor = strstr(gl_string_cursor, " ");
822 while (*gl_string_cursor && ' ' == *gl_string_cursor) ++gl_string_cursor;
823 if (*gl_string_cursor) {
827 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
828 tmp[cursor++] = *gl_string_cursor;
834 if (*gl_string_cursor != '.') WARN_(d3d_caps)("malformed GL_VERSION (%s)\n", debugstr_a(gl_string));
837 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
838 tmp[cursor++] = *gl_string_cursor;
850 This->gl_info.gl_driver_version = MAKEDWORD_VERSION(major, minor);
852 gl_string = glGetString(GL_RENDERER);
853 strcpy(This->gl_info.gl_renderer, gl_string);
855 switch (This->gl_info.gl_vendor) {
857 if (strstr(This->gl_info.gl_renderer, "GeForce4 Ti")) {
858 This->gl_info.gl_card = CARD_NVIDIA_GEFORCE4_TI4600;
859 } else if (strstr(This->gl_info.gl_renderer, "GeForceFX")) {
860 This->gl_info.gl_card = CARD_NVIDIA_GEFORCEFX_5900ULTRA;
862 This->gl_info.gl_card = CARD_NVIDIA_GEFORCE4_TI4600;
866 This->gl_info.gl_card = CARD_ATI_RADEON_8500;
869 This->gl_info.gl_card = CARD_WINE;
873 FIXME_(d3d_caps)("found GL_VERSION (0x%08lx)\n", This->gl_info.gl_driver_version);
874 FIXME_(d3d_caps)("found GL_RENDERER (%s)->(0x%04x)\n", debugstr_a(This->gl_info.gl_renderer), This->gl_info.gl_card);
876 * Initialize openGL extension related variables
877 * with Default values
879 memset(&This->gl_info.supported, 0, sizeof(This->gl_info.supported));
880 This->gl_info.max_textures = 1;
881 This->gl_info.ps_arb_version = PS_VERSION_NOT_SUPPORTED;
882 This->gl_info.vs_arb_version = VS_VERSION_NOT_SUPPORTED;
883 This->gl_info.vs_nv_version = VS_VERSION_NOT_SUPPORTED;
884 This->gl_info.vs_ati_version = VS_VERSION_NOT_SUPPORTED;
886 #define USE_GL_FUNC(type, pfn) This->gl_info.pfn = NULL;
890 /* Retrieve opengl defaults */
891 glGetIntegerv(GL_MAX_CLIP_PLANES, &gl_max);
892 This->gl_info.max_clipplanes = min(MAX_CLIPPLANES, gl_max);
893 TRACE_(d3d_caps)("ClipPlanes support - num Planes=%d\n", gl_max);
895 glGetIntegerv(GL_MAX_LIGHTS, &gl_max);
896 This->gl_info.max_lights = gl_max;
897 TRACE_(d3d_caps)("Lights support - max lights=%d\n", gl_max);
899 /* Parse the gl supported features, in theory enabling parts of our code appropriately */
900 GL_Extensions = glGetString(GL_EXTENSIONS);
901 TRACE_(d3d_caps)("GL_Extensions reported:\n");
903 if (NULL == GL_Extensions) {
904 ERR(" GL_Extensions returns NULL\n");
906 while (*GL_Extensions != 0x00) {
907 const char *Start = GL_Extensions;
910 memset(ThisExtn, 0x00, sizeof(ThisExtn));
911 while (*GL_Extensions != ' ' && *GL_Extensions != 0x00) {
914 memcpy(ThisExtn, Start, (GL_Extensions - Start));
915 TRACE_(d3d_caps)("- %s\n", ThisExtn);
920 if (strcmp(ThisExtn, "GL_ARB_fragment_program") == 0) {
921 This->gl_info.ps_arb_version = PS_VERSION_11;
922 TRACE_(d3d_caps)(" FOUND: ARB Pixel Shader support - version=%02x\n", This->gl_info.ps_arb_version);
923 This->gl_info.supported[ARB_FRAGMENT_PROGRAM] = TRUE;
924 } else if (strcmp(ThisExtn, "GL_ARB_multisample") == 0) {
925 TRACE_(d3d_caps)(" FOUND: ARB Multisample support\n");
926 This->gl_info.supported[ARB_MULTISAMPLE] = TRUE;
927 } else if (strcmp(ThisExtn, "GL_ARB_multitexture") == 0) {
928 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_max);
929 TRACE_(d3d_caps)(" FOUND: ARB Multitexture support - GL_MAX_TEXTURE_UNITS_ARB=%u\n", gl_max);
930 This->gl_info.supported[ARB_MULTITEXTURE] = TRUE;
931 This->gl_info.max_textures = min(8, gl_max);
932 } else if (strcmp(ThisExtn, "GL_ARB_texture_cube_map") == 0) {
933 TRACE_(d3d_caps)(" FOUND: ARB Texture Cube Map support\n");
934 This->gl_info.supported[ARB_TEXTURE_CUBE_MAP] = TRUE;
935 } else if (strcmp(ThisExtn, "GL_ARB_texture_compression") == 0) {
936 TRACE_(d3d_caps)(" FOUND: ARB Texture Compression support\n");
937 This->gl_info.supported[ARB_TEXTURE_COMPRESSION] = TRUE;
938 } else if (strcmp(ThisExtn, "GL_ARB_texture_env_add") == 0) {
939 TRACE_(d3d_caps)(" FOUND: ARB Texture Env Add support\n");
940 This->gl_info.supported[ARB_TEXTURE_ENV_ADD] = TRUE;
941 } else if (strcmp(ThisExtn, "GL_ARB_texture_env_combine") == 0) {
942 TRACE_(d3d_caps)(" FOUND: ARB Texture Env combine support\n");
943 This->gl_info.supported[ARB_TEXTURE_ENV_COMBINE] = TRUE;
944 } else if (strcmp(ThisExtn, "GL_ARB_texture_env_dot3") == 0) {
945 TRACE_(d3d_caps)(" FOUND: ARB Dot3 support\n");
946 This->gl_info.supported[ARB_TEXTURE_ENV_DOT3] = TRUE;
947 } else if (strcmp(ThisExtn, "GL_ARB_texture_border_clamp") == 0) {
948 TRACE_(d3d_caps)(" FOUND: ARB Texture border clamp support\n");
949 This->gl_info.supported[ARB_TEXTURE_BORDER_CLAMP] = TRUE;
950 } else if (strcmp(ThisExtn, "GL_ARB_texture_mirrored_repeat") == 0) {
951 TRACE_(d3d_caps)(" FOUND: ARB Texture mirrored repeat support\n");
952 This->gl_info.supported[ARB_TEXTURE_MIRRORED_REPEAT] = TRUE;
953 } else if (strstr(ThisExtn, "GL_ARB_vertex_program")) {
954 This->gl_info.vs_arb_version = VS_VERSION_11;
955 TRACE_(d3d_caps)(" FOUND: ARB Vertex Shader support - version=%02x\n", This->gl_info.vs_arb_version);
956 This->gl_info.supported[ARB_VERTEX_PROGRAM] = TRUE;
961 } else if (strcmp(ThisExtn, "GL_EXT_fog_coord") == 0) {
962 TRACE_(d3d_caps)(" FOUND: EXT Fog coord support\n");
963 This->gl_info.supported[EXT_FOG_COORD] = TRUE;
964 } else if (strcmp(ThisExtn, "GL_EXT_paletted_texture") == 0) { /* handle paletted texture extensions */
965 TRACE_(d3d_caps)(" FOUND: EXT Paletted texture support\n");
966 This->gl_info.supported[EXT_PALETTED_TEXTURE] = TRUE;
967 } else if (strcmp(ThisExtn, "GL_EXT_point_parameters") == 0) {
968 TRACE_(d3d_caps)(" FOUND: EXT Point parameters support\n");
969 This->gl_info.supported[EXT_POINT_PARAMETERS] = TRUE;
970 } else if (strcmp(ThisExtn, "GL_EXT_secondary_color") == 0) {
971 TRACE_(d3d_caps)(" FOUND: EXT Secondary coord support\n");
972 This->gl_info.supported[EXT_SECONDARY_COLOR] = TRUE;
973 } else if (strcmp(ThisExtn, "GL_EXT_texture_compression_s3tc") == 0) {
974 TRACE_(d3d_caps)(" FOUND: EXT Texture S3TC compression support\n");
975 This->gl_info.supported[EXT_TEXTURE_COMPRESSION_S3TC] = TRUE;
976 } else if (strcmp(ThisExtn, "GL_EXT_texture_env_add") == 0) {
977 TRACE_(d3d_caps)(" FOUND: EXT Texture Env Add support\n");
978 This->gl_info.supported[EXT_TEXTURE_ENV_ADD] = TRUE;
979 } else if (strcmp(ThisExtn, "GL_EXT_texture_env_combine") == 0) {
980 TRACE_(d3d_caps)(" FOUND: EXT Texture Env combine support\n");
981 This->gl_info.supported[EXT_TEXTURE_ENV_COMBINE] = TRUE;
982 } else if (strcmp(ThisExtn, "GL_EXT_texture_env_dot3") == 0) {
983 TRACE_(d3d_caps)(" FOUND: EXT Dot3 support\n");
984 This->gl_info.supported[EXT_TEXTURE_ENV_DOT3] = TRUE;
985 } else if (strcmp(ThisExtn, "GL_EXT_texture_filter_anisotropic") == 0) {
986 TRACE_(d3d_caps)(" FOUND: EXT Texture Anisotropic filter support\n");
987 This->gl_info.supported[EXT_TEXTURE_FILTER_ANISOTROPIC] = TRUE;
988 } else if (strcmp(ThisExtn, "GL_EXT_texture_lod") == 0) {
989 TRACE_(d3d_caps)(" FOUND: EXT Texture LOD support\n");
990 This->gl_info.supported[EXT_TEXTURE_LOD] = TRUE;
991 } else if (strcmp(ThisExtn, "GL_EXT_texture_lod_bias") == 0) {
992 TRACE_(d3d_caps)(" FOUND: EXT Texture LOD bias support\n");
993 This->gl_info.supported[EXT_TEXTURE_LOD_BIAS] = TRUE;
994 } else if (strcmp(ThisExtn, "GL_EXT_vertex_weighting") == 0) {
995 TRACE_(d3d_caps)(" FOUND: EXT Vertex weighting support\n");
996 This->gl_info.supported[EXT_VERTEX_WEIGHTING] = TRUE;
1001 } else if (strcmp(ThisExtn, "GL_NV_texture_env_combine4") == 0) {
1002 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Texture Env combine (4) support\n");
1003 This->gl_info.supported[NV_TEXTURE_ENV_COMBINE4] = TRUE;
1004 } else if (strstr(ThisExtn, "GL_NV_fragment_program")) {
1005 This->gl_info.ps_nv_version = PS_VERSION_11;
1006 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Pixel Shader support - version=%02x\n", This->gl_info.ps_nv_version);
1007 } else if (strstr(ThisExtn, "GL_NV_fog_distance")) {
1008 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Fog Distance support\n");
1009 This->gl_info.supported[NV_FOG_DISTANCE] = TRUE;
1010 } else if (strstr(ThisExtn, "GL_NV_vertex_program")) {
1011 This->gl_info.vs_nv_version = max(This->gl_info.vs_nv_version, (0 == strcmp(ThisExtn, "GL_NV_vertex_program1_1")) ? VS_VERSION_11 : VS_VERSION_10);
1012 This->gl_info.vs_nv_version = max(This->gl_info.vs_nv_version, (0 == strcmp(ThisExtn, "GL_NV_vertex_program2")) ? VS_VERSION_20 : VS_VERSION_10);
1013 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Vertex Shader support - version=%02x\n", This->gl_info.vs_nv_version);
1014 This->gl_info.supported[NV_VERTEX_PROGRAM] = TRUE;
1020 } else if (strcmp(ThisExtn, "GL_ATI_texture_env_combine3") == 0) {
1021 TRACE_(d3d_caps)(" FOUND: ATI Texture Env combine (3) support\n");
1022 This->gl_info.supported[ATI_TEXTURE_ENV_COMBINE3] = TRUE;
1023 } else if (strcmp(ThisExtn, "GL_ATI_texture_mirror_once") == 0) {
1024 TRACE_(d3d_caps)(" FOUND: ATI Texture Mirror Once support\n");
1025 This->gl_info.supported[ATI_TEXTURE_MIRROR_ONCE] = TRUE;
1026 } else if (strcmp(ThisExtn, "GL_EXT_vertex_shader") == 0) {
1027 This->gl_info.vs_ati_version = VS_VERSION_11;
1028 TRACE_(d3d_caps)(" FOUND: ATI (EXT) Vertex Shader support - version=%02x\n", This->gl_info.vs_ati_version);
1029 This->gl_info.supported[EXT_VERTEX_SHADER] = TRUE;
1033 if (*GL_Extensions == ' ') GL_Extensions++;
1037 #define USE_GL_FUNC(type, pfn) This->gl_info.pfn = (type) glXGetProcAddressARB(#pfn);
1041 if (display != NULL) {
1042 GLX_Extensions = glXQueryExtensionsString(display, DefaultScreen(display));
1043 TRACE_(d3d_caps)("GLX_Extensions reported:\n");
1045 if (NULL == GLX_Extensions) {
1046 ERR(" GLX_Extensions returns NULL\n");
1048 while (*GLX_Extensions != 0x00) {
1049 const char *Start = GLX_Extensions;
1052 memset(ThisExtn, 0x00, sizeof(ThisExtn));
1053 while (*GLX_Extensions != ' ' && *GLX_Extensions != 0x00) {
1056 memcpy(ThisExtn, Start, (GLX_Extensions - Start));
1057 TRACE_(d3d_caps)("- %s\n", ThisExtn);
1058 if (*GLX_Extensions == ' ') GLX_Extensions++;
1063 #define USE_GL_FUNC(type, pfn) This->gl_info.pfn = (type) glXGetProcAddressARB(#pfn);
1067 /* Only save the values obtained when a display is provided */
1068 if (display != NULL) This->isGLInfoValid = TRUE;
1072 HRESULT WINAPI IDirect3D8Impl_CreateDevice (LPDIRECT3D8 iface,
1073 UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow,
1074 DWORD BehaviourFlags, D3DPRESENT_PARAMETERS* pPresentationParameters,
1075 IDirect3DDevice8** ppReturnedDeviceInterface) {
1076 IDirect3DDevice8Impl *object;
1079 XVisualInfo template;
1082 ICOM_THIS(IDirect3D8Impl,iface);
1083 TRACE("(%p)->(Adptr:%d, DevType: %x, FocusHwnd: %p, BehFlags: %lx, PresParms: %p, RetDevInt: %p)\n", This, Adapter, DeviceType,
1084 hFocusWindow, BehaviourFlags, pPresentationParameters, ppReturnedDeviceInterface);
1086 /* Allocate the storage for the device */
1087 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DDevice8Impl));
1088 if (NULL == object) {
1089 return D3DERR_OUTOFVIDEOMEMORY;
1091 object->lpVtbl = &Direct3DDevice8_Vtbl;
1093 object->direct3d8 = This;
1094 /** The device AddRef the direct3d8 Interface else crash in propers clients codes */
1095 IDirect3D8_AddRef((LPDIRECT3D8) object->direct3d8);
1097 /** use StateBlock Factory here, for creating the startup stateBlock */
1098 object->StateBlock = NULL;
1099 IDirect3DDeviceImpl_CreateStateBlock(object, D3DSBT_ALL, NULL);
1100 object->UpdateStateBlock = object->StateBlock;
1102 /* Save the creation parameters */
1103 object->CreateParms.AdapterOrdinal = Adapter;
1104 object->CreateParms.DeviceType = DeviceType;
1105 object->CreateParms.hFocusWindow = hFocusWindow;
1106 object->CreateParms.BehaviorFlags = BehaviourFlags;
1108 *ppReturnedDeviceInterface = (LPDIRECT3DDEVICE8) object;
1110 /* Initialize settings */
1111 object->PresentParms.BackBufferCount = 1; /* Opengl only supports one? */
1112 object->adapterNo = Adapter;
1113 object->devType = DeviceType;
1115 /* Initialize openGl - Note the visual is chosen as the window is created and the glcontext cannot
1116 use different properties after that point in time. FIXME: How to handle when requested format
1117 doesn't match actual visual? Cannot choose one here - code removed as it ONLY works if the one
1118 it chooses is identical to the one already being used! */
1119 /* FIXME: Handle stencil appropriately via EnableAutoDepthStencil / AutoDepthStencilFormat */
1121 /* Which hwnd are we using? */
1122 whichHWND = pPresentationParameters->hDeviceWindow;
1124 whichHWND = hFocusWindow;
1126 object->win_handle = whichHWND;
1127 object->win = (Window)GetPropA( whichHWND, "__wine_x11_client_window" );
1129 hDc = GetDC(whichHWND);
1130 object->display = get_display(hDc);
1132 TRACE("(%p)->(DepthStencil:(%u,%s), BackBufferFormat:(%u,%s))\n", This,
1133 pPresentationParameters->AutoDepthStencilFormat, debug_d3dformat(pPresentationParameters->AutoDepthStencilFormat),
1134 pPresentationParameters->BackBufferFormat, debug_d3dformat(pPresentationParameters->BackBufferFormat));
1138 /* Create a context based off the properties of the existing visual */
1139 template.visualid = (VisualID)GetPropA(GetDesktopWindow(), "__wine_x11_visual_id");
1140 object->visInfo = XGetVisualInfo(object->display, VisualIDMask, &template, &num);
1141 if (NULL == object->visInfo) {
1142 ERR("cannot really get XVisual\n");
1144 return D3DERR_NOTAVAILABLE;
1146 object->glCtx = glXCreateContext(object->display, object->visInfo, NULL, GL_TRUE);
1147 if (NULL == object->glCtx) {
1148 ERR("cannot create glxContext\n");
1150 return D3DERR_NOTAVAILABLE;
1154 ReleaseDC(whichHWND, hDc);
1156 if (object->glCtx == NULL) {
1157 ERR("Error in context creation !\n");
1158 return D3DERR_INVALIDCALL;
1160 TRACE("Context created (HWND=%p, glContext=%p, Window=%ld, VisInfo=%p)\n",
1161 whichHWND, object->glCtx, object->win, object->visInfo);
1164 /* If not windowed, need to go fullscreen, and resize the HWND to the appropriate */
1166 if (!pPresentationParameters->Windowed) {
1171 memset(&devmode, 0, sizeof(DEVMODEW));
1172 devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
1173 MultiByteToWideChar(CP_ACP, 0, "Gamers CG", -1, devmode.dmDeviceName, CCHDEVICENAME);
1174 hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
1175 bpp = GetDeviceCaps(hdc, BITSPIXEL);
1177 devmode.dmBitsPerPel = (bpp >= 24) ? 32 : bpp;/*Stupid XVidMode cannot change bpp D3DFmtGetBpp(object, pPresentationParameters->BackBufferFormat);*/
1178 devmode.dmPelsWidth = pPresentationParameters->BackBufferWidth;
1179 devmode.dmPelsHeight = pPresentationParameters->BackBufferHeight;
1180 ChangeDisplaySettingsExW(devmode.dmDeviceName, &devmode, object->win_handle, CDS_FULLSCREEN, NULL);
1182 FIXME("Requested full screen support not implemented, expect windowed operation\n");
1185 /* Make popup window */
1186 ShowWindow(whichHWND, SW_HIDE);
1187 SetWindowLongA(whichHWND, GWL_STYLE, WS_POPUP);
1188 SetWindowPos(object->win_handle, HWND_TOP, 0, 0,
1189 pPresentationParameters->BackBufferWidth,
1190 pPresentationParameters->BackBufferHeight, SWP_SHOWWINDOW | SWP_FRAMECHANGED);
1191 ShowWindow(whichHWND, SW_SHOW);
1194 TRACE("Creating back buffer\n");
1195 /* MSDN: If Windowed is TRUE and either of the BackBufferWidth/Height values is zero,
1196 then the corresponding dimension of the client area of the hDeviceWindow
1197 (or the focus window, if hDeviceWindow is NULL) is taken. */
1198 if (pPresentationParameters->Windowed && ((pPresentationParameters->BackBufferWidth == 0) ||
1199 (pPresentationParameters->BackBufferHeight == 0))) {
1202 GetClientRect(whichHWND, &Rect);
1204 if (pPresentationParameters->BackBufferWidth == 0) {
1205 pPresentationParameters->BackBufferWidth = Rect.right;
1206 TRACE("Updating width to %d\n", pPresentationParameters->BackBufferWidth);
1208 if (pPresentationParameters->BackBufferHeight == 0) {
1209 pPresentationParameters->BackBufferHeight = Rect.bottom;
1210 TRACE("Updating height to %d\n", pPresentationParameters->BackBufferHeight);
1214 /* Save the presentation parms now filled in correctly */
1215 memcpy(&object->PresentParms, pPresentationParameters, sizeof(D3DPRESENT_PARAMETERS));
1218 IDirect3DDevice8Impl_CreateRenderTarget((LPDIRECT3DDEVICE8) object,
1219 pPresentationParameters->BackBufferWidth,
1220 pPresentationParameters->BackBufferHeight,
1221 pPresentationParameters->BackBufferFormat,
1222 pPresentationParameters->MultiSampleType,
1224 (LPDIRECT3DSURFACE8*) &object->frontBuffer);
1226 IDirect3DDevice8Impl_CreateRenderTarget((LPDIRECT3DDEVICE8) object,
1227 pPresentationParameters->BackBufferWidth,
1228 pPresentationParameters->BackBufferHeight,
1229 pPresentationParameters->BackBufferFormat,
1230 pPresentationParameters->MultiSampleType,
1232 (LPDIRECT3DSURFACE8*) &object->backBuffer);
1234 if (pPresentationParameters->EnableAutoDepthStencil) {
1235 IDirect3DDevice8Impl_CreateDepthStencilSurface((LPDIRECT3DDEVICE8) object,
1236 pPresentationParameters->BackBufferWidth,
1237 pPresentationParameters->BackBufferHeight,
1238 pPresentationParameters->AutoDepthStencilFormat,
1239 D3DMULTISAMPLE_NONE,
1240 (LPDIRECT3DSURFACE8*) &object->depthStencilBuffer);
1242 object->depthStencilBuffer = NULL;
1244 TRACE("FrontBuf @ %p, BackBuf @ %p, DepthStencil @ %p\n",object->frontBuffer, object->backBuffer, object->depthStencilBuffer);
1246 /* init the default renderTarget management */
1247 object->drawable = object->win;
1248 object->render_ctx = object->glCtx;
1249 object->renderTarget = object->frontBuffer;
1250 IDirect3DSurface8Impl_AddRef((LPDIRECT3DSURFACE8) object->renderTarget);
1251 object->stencilBufferTarget = object->depthStencilBuffer;
1252 if (NULL != object->stencilBufferTarget) {
1253 IDirect3DSurface8Impl_AddRef((LPDIRECT3DSURFACE8) object->stencilBufferTarget);
1258 if (glXMakeCurrent(object->display, object->win, object->glCtx) == False) {
1259 ERR("Error in setting current context (context %p drawable %ld)!\n", object->glCtx, object->win);
1261 checkGLcall("glXMakeCurrent");
1263 /* Clear the screen */
1264 glClearColor(1.0, 0.0, 0.0, 0.0);
1265 checkGLcall("glClearColor");
1266 glColor3f(1.0, 1.0, 1.0);
1267 checkGLcall("glColor3f");
1269 glEnable(GL_LIGHTING);
1270 checkGLcall("glEnable");
1272 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
1273 checkGLcall("glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);");
1275 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
1276 checkGLcall("glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);");
1278 glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
1279 checkGLcall("glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);");
1282 * Initialize openGL extension related variables
1283 * with Default values
1285 IDirect3D8Impl_FillGLCaps(iface, object->display);
1287 /* Setup all the devices defaults */
1288 IDirect3DDeviceImpl_InitStartupStateBlock(object);
1292 { /* Set a default viewport */
1296 vp.Width = pPresentationParameters->BackBufferWidth;
1297 vp.Height = pPresentationParameters->BackBufferHeight;
1300 IDirect3DDevice8Impl_SetViewport((LPDIRECT3DDEVICE8) object, &vp);
1303 /* Initialize the current view state */
1304 object->modelview_valid = 1;
1305 object->proj_valid = 0;
1306 object->view_ident = 1;
1307 object->last_was_rhw = 0;
1308 glGetIntegerv(GL_MAX_LIGHTS, &object->maxConcurrentLights);
1309 TRACE("(%p,%d) All defaults now set up, leaving CreateDevice with %p\n", This, Adapter, object);
1313 ICOM_VTABLE(IDirect3D8) Direct3D8_Vtbl =
1315 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1316 IDirect3D8Impl_QueryInterface,
1317 IDirect3D8Impl_AddRef,
1318 IDirect3D8Impl_Release,
1319 IDirect3D8Impl_RegisterSoftwareDevice,
1320 IDirect3D8Impl_GetAdapterCount,
1321 IDirect3D8Impl_GetAdapterIdentifier,
1322 IDirect3D8Impl_GetAdapterModeCount,
1323 IDirect3D8Impl_EnumAdapterModes,
1324 IDirect3D8Impl_GetAdapterDisplayMode,
1325 IDirect3D8Impl_CheckDeviceType,
1326 IDirect3D8Impl_CheckDeviceFormat,
1327 IDirect3D8Impl_CheckDeviceMultiSampleType,
1328 IDirect3D8Impl_CheckDepthStencilMatch,
1329 IDirect3D8Impl_GetDeviceCaps,
1330 IDirect3D8Impl_GetAdapterMonitor,
1331 IDirect3D8Impl_CreateDevice