2 * IWineD3D implementation
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2003-2004 Raphael Junqueira
6 * Copyright 2004 Christian Costa
7 * Copyright 2005 Oliver Stieber
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 /* Compile time diagnostics: */
26 /* Uncomment this to force only a single display mode to be exposed: */
27 /*#define DEBUG_SINGLE_MODE*/
31 #include "wined3d_private.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
34 WINE_DECLARE_DEBUG_CHANNEL(d3d_caps);
35 #define GLINFO_LOCATION This->gl_info
37 /**********************************************************
38 * Utility functions follow
39 **********************************************************/
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 */
50 /* retrieve the X display to use on a given DC */
51 inline static Display *get_display( HDC hdc )
54 enum x11drv_escape_codes escape = X11DRV_GET_DISPLAY;
56 if (!ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPCSTR)&escape,
57 sizeof(display), (LPSTR)&display )) display = NULL;
62 int minLookup[MAX_LOOKUPS];
63 int maxLookup[MAX_LOOKUPS];
64 DWORD *stateLookup[MAX_LOOKUPS];
66 DWORD minMipLookup[D3DTEXF_ANISOTROPIC + 1][D3DTEXF_LINEAR + 1];
71 * Note: GL seems to trap if GetDeviceCaps is called before any HWND's created
72 * ie there is no GL Context - Get a default rendering context to enable the
73 * function query some info from GL
75 static WineD3D_Context* WineD3D_CreateFakeGLContext(void) {
76 static WineD3D_Context ctx = { NULL, NULL, NULL, 0, 0 };
77 WineD3D_Context* ret = NULL;
79 if (glXGetCurrentContext() == NULL) {
80 BOOL gotContext = FALSE;
87 XWindowAttributes win_attr;
89 TRACE_(d3d_caps)("Creating Fake GL Context\n");
91 ctx.drawable = (Drawable) GetPropA(GetDesktopWindow(), "__wine_x11_whole_window");
94 device_context = GetDC(0);
95 ctx.display = get_display(device_context);
96 ReleaseDC(0, device_context);
98 /* Get the X visual */
100 if (XGetWindowAttributes(ctx.display, ctx.drawable, &win_attr)) {
101 visual = win_attr.visual;
103 visual = DefaultVisual(ctx.display, DefaultScreen(ctx.display));
105 template.visualid = XVisualIDFromVisual(visual);
106 ctx.visInfo = XGetVisualInfo(ctx.display, VisualIDMask, &template, &num);
107 if (ctx.visInfo == NULL) {
109 WARN_(d3d_caps)("Error creating visual info for capabilities initialization\n");
113 /* Create a GL context */
115 ctx.glCtx = glXCreateContext(ctx.display, ctx.visInfo, NULL, GL_TRUE);
117 if (ctx.glCtx == NULL) {
119 WARN_(d3d_caps)("Error creating default context for capabilities initialization\n");
124 /* Make it the current GL context */
125 if (!failed && glXMakeCurrent(ctx.display, ctx.drawable, ctx.glCtx) == False) {
126 glXDestroyContext(ctx.display, ctx.glCtx);
128 WARN_(d3d_caps)("Error setting default context as current for capabilities initialization\n");
132 /* It worked! Wow... */
142 if (ctx.ref > 0) ret = &ctx;
145 if (NULL != ret) InterlockedIncrement(&ret->ref);
149 static void WineD3D_ReleaseFakeGLContext(WineD3D_Context* ctx) {
150 /* If we created a dummy context, throw it away */
152 if (0 == InterlockedDecrement(&ctx->ref)) {
153 glXMakeCurrent(ctx->display, None, NULL);
154 glXDestroyContext(ctx->display, ctx->glCtx);
162 /**********************************************************
163 * IUnknown parts follows
164 **********************************************************/
166 HRESULT WINAPI IWineD3DImpl_QueryInterface(IWineD3D *iface,REFIID riid,LPVOID *ppobj)
168 IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
170 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
171 if (IsEqualGUID(riid, &IID_IUnknown)
172 || IsEqualGUID(riid, &IID_IWineD3DBase)
173 || IsEqualGUID(riid, &IID_IWineD3DDevice)) {
174 IUnknown_AddRef(iface);
179 return E_NOINTERFACE;
182 ULONG WINAPI IWineD3DImpl_AddRef(IWineD3D *iface) {
183 IWineD3DImpl *This = (IWineD3DImpl *)iface;
184 ULONG refCount = InterlockedIncrement(&This->ref);
186 TRACE("(%p) : AddRef increasing from %ld\n", This, refCount - 1);
190 ULONG WINAPI IWineD3DImpl_Release(IWineD3D *iface) {
191 IWineD3DImpl *This = (IWineD3DImpl *)iface;
193 TRACE("(%p) : Releasing from %ld\n", This, This->ref);
194 ref = InterlockedDecrement(&This->ref);
196 HeapFree(GetProcessHeap(), 0, This);
202 /**********************************************************
203 * IWineD3D parts follows
204 **********************************************************/
206 static BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info, Display* display) {
207 const char *GL_Extensions = NULL;
208 const char *GLX_Extensions = NULL;
209 const char *gl_string = NULL;
210 const char *gl_string_cursor = NULL;
215 WineD3D_Context *fake_ctx = NULL;
216 BOOL gotContext = FALSE;
219 /* Make sure that we've got a context */
220 if (glXGetCurrentContext() == NULL) {
221 /* TODO: CreateFakeGLContext should really take a display as a parameter */
222 fake_ctx = WineD3D_CreateFakeGLContext();
223 if (NULL != fake_ctx) gotContext = TRUE;
228 TRACE_(d3d_caps)("(%p, %p)\n", gl_info, display);
230 gl_string = (const char *) glGetString(GL_RENDERER);
231 strcpy(gl_info->gl_renderer, gl_string);
233 /* Fill in the GL info retrievable depending on the display */
234 if (NULL != display) {
235 test = glXQueryVersion(display, &major, &minor);
236 gl_info->glx_version = ((major & 0x0000FFFF) << 16) | (minor & 0x0000FFFF);
238 FIXME("Display must not be NULL, use glXGetCurrentDisplay or getAdapterDisplay()\n");
240 gl_string = (const char *) glGetString(GL_VENDOR);
242 TRACE_(d3d_caps)("Filling vendor string %s\n", gl_string);
243 if (gl_string != NULL) {
244 /* Fill in the GL vendor */
245 if (strstr(gl_string, "NVIDIA")) {
246 gl_info->gl_vendor = VENDOR_NVIDIA;
247 } else if (strstr(gl_string, "ATI")) {
248 gl_info->gl_vendor = VENDOR_ATI;
249 } else if (strstr(gl_string, "Intel(R)") ||
250 strstr(gl_info->gl_renderer, "Intel(R)")) {
251 gl_info->gl_vendor = VENDOR_INTEL;
252 } else if (strstr(gl_string, "Mesa")) {
253 gl_info->gl_vendor = VENDOR_MESA;
255 gl_info->gl_vendor = VENDOR_WINE;
258 gl_info->gl_vendor = VENDOR_WINE;
262 TRACE_(d3d_caps)("found GL_VENDOR (%s)->(0x%04x)\n", debugstr_a(gl_string), gl_info->gl_vendor);
264 /* Parse the GL_VERSION field into major and minor information */
265 gl_string = (const char *) glGetString(GL_VERSION);
266 if (gl_string != NULL) {
268 switch (gl_info->gl_vendor) {
270 gl_string_cursor = strstr(gl_string, "NVIDIA");
271 if (!gl_string_cursor) {
272 ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
276 gl_string_cursor = strstr(gl_string_cursor, " ");
277 if (!gl_string_cursor) {
278 ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
282 while (*gl_string_cursor == ' ') {
286 if (!*gl_string_cursor) {
287 ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
291 major = atoi(gl_string_cursor);
292 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
296 if (*gl_string_cursor++ != '.') {
297 ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
301 minor = atoi(gl_string_cursor);
302 minor = major*100+minor;
309 gl_string_cursor = strchr(gl_string, '-');
310 if (gl_string_cursor) {
314 /* Check if version number is of the form x.y.z */
315 if (*gl_string_cursor > '9' && *gl_string_cursor < '0')
317 if (!error && *(gl_string_cursor+2) > '9' && *(gl_string_cursor+2) < '0')
319 if (!error && *(gl_string_cursor+4) > '9' && *(gl_string_cursor+4) < '0')
321 if (!error && *(gl_string_cursor+1) != '.' && *(gl_string_cursor+3) != '.')
324 /* Mark version number as malformed */
326 gl_string_cursor = 0;
329 if (!gl_string_cursor)
330 WARN_(d3d_caps)("malformed GL_VERSION (%s)\n", debugstr_a(gl_string));
332 major = *gl_string_cursor - '0';
333 minor = (*(gl_string_cursor+2) - '0') * 256 + (*(gl_string_cursor+4) - '0');
339 gl_string_cursor = strstr(gl_string, "Mesa");
340 gl_string_cursor = strstr(gl_string_cursor, " ");
341 while (*gl_string_cursor && ' ' == *gl_string_cursor) ++gl_string_cursor;
342 if (*gl_string_cursor) {
346 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
347 tmp[cursor++] = *gl_string_cursor;
353 if (*gl_string_cursor != '.') WARN_(d3d_caps)("malformed GL_VERSION (%s)\n", debugstr_a(gl_string));
357 while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
358 tmp[cursor++] = *gl_string_cursor;
370 gl_info->gl_driver_version = MAKEDWORD_VERSION(major, minor);
371 TRACE_(d3d_caps)("found GL_VERSION (%s)->%i.%i->(0x%08lx)\n", debugstr_a(gl_string), major, minor, gl_info->gl_driver_version);
373 /* Fill in the renderer information */
375 switch (gl_info->gl_vendor) {
377 if (strstr(gl_info->gl_renderer, "GeForce4 Ti")) {
378 gl_info->gl_card = CARD_NVIDIA_GEFORCE4_TI4600;
379 } else if (strstr(gl_info->gl_renderer, "GeForceFX")) {
380 gl_info->gl_card = CARD_NVIDIA_GEFORCEFX_5900ULTRA;
381 } else if (strstr(gl_info->gl_renderer, "Quadro FX 3000")) {
382 gl_info->gl_card = CARD_NVIDIA_QUADROFX_3000;
383 } else if (strstr(gl_info->gl_renderer, "GeForce 6800")) {
384 gl_info->gl_card = CARD_NVIDIA_GEFORCE_6800ULTRA;
385 } else if (strstr(gl_info->gl_renderer, "Quadro FX 4000")) {
386 gl_info->gl_card = CARD_NVIDIA_QUADROFX_4000;
387 } else if (strstr(gl_info->gl_renderer, "GeForce 7800")) {
388 gl_info->gl_card = CARD_NVIDIA_GEFORCE_7800ULTRA;
390 gl_info->gl_card = CARD_NVIDIA_GEFORCE4_TI4600;
395 if (strstr(gl_info->gl_renderer, "RADEON 9800 PRO")) {
396 gl_info->gl_card = CARD_ATI_RADEON_9800PRO;
397 } else if (strstr(gl_info->gl_renderer, "RADEON 9700 PRO")) {
398 gl_info->gl_card = CARD_ATI_RADEON_9700PRO;
400 gl_info->gl_card = CARD_ATI_RADEON_8500;
405 if (strstr(gl_info->gl_renderer, "915GM")) {
406 gl_info->gl_card = CARD_INTEL_I915GM;
407 } else if (strstr(gl_info->gl_renderer, "915G")) {
408 gl_info->gl_card = CARD_INTEL_I915G;
409 } else if (strstr(gl_info->gl_renderer, "865G")) {
410 gl_info->gl_card = CARD_INTEL_I865G;
411 } else if (strstr(gl_info->gl_renderer, "855G")) {
412 gl_info->gl_card = CARD_INTEL_I855G;
413 } else if (strstr(gl_info->gl_renderer, "830G")) {
414 gl_info->gl_card = CARD_INTEL_I830G;
416 gl_info->gl_card = CARD_INTEL_I915G;
421 gl_info->gl_card = CARD_WINE;
425 FIXME("get version string returned null\n");
428 TRACE_(d3d_caps)("found GL_RENDERER (%s)->(0x%04x)\n", debugstr_a(gl_info->gl_renderer), gl_info->gl_card);
431 * Initialize openGL extension related variables
432 * with Default values
434 memset(&gl_info->supported, 0, sizeof(gl_info->supported));
435 gl_info->max_textures = 1;
436 gl_info->max_samplers = 1;
437 gl_info->ps_arb_version = PS_VERSION_NOT_SUPPORTED;
438 gl_info->vs_arb_version = VS_VERSION_NOT_SUPPORTED;
439 gl_info->vs_nv_version = VS_VERSION_NOT_SUPPORTED;
440 gl_info->vs_ati_version = VS_VERSION_NOT_SUPPORTED;
442 /* Now work out what GL support this card really has */
443 #define USE_GL_FUNC(type, pfn) gl_info->pfn = NULL;
447 /* Retrieve opengl defaults */
448 glGetIntegerv(GL_MAX_CLIP_PLANES, &gl_max);
449 gl_info->max_clipplanes = min(D3DMAXUSERCLIPPLANES, gl_max);
450 TRACE_(d3d_caps)("ClipPlanes support - num Planes=%d\n", gl_max);
452 glGetIntegerv(GL_MAX_LIGHTS, &gl_max);
453 gl_info->max_lights = gl_max;
454 TRACE_(d3d_caps)("Lights support - max lights=%d\n", gl_max);
456 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gl_max);
457 gl_info->max_texture_size = gl_max;
458 TRACE_(d3d_caps)("Maximum texture size support - max texture size=%d\n", gl_max);
460 glGetFloatv(GL_POINT_SIZE_RANGE, &gl_float);
461 gl_info->max_pointsize = gl_float;
462 TRACE_(d3d_caps)("Maximum point size support - max texture size=%f\n", gl_float);
464 /* Parse the gl supported features, in theory enabling parts of our code appropriately */
465 GL_Extensions = (const char *) glGetString(GL_EXTENSIONS);
466 TRACE_(d3d_caps)("GL_Extensions reported:\n");
468 if (NULL == GL_Extensions) {
469 ERR(" GL_Extensions returns NULL\n");
471 while (*GL_Extensions != 0x00) {
472 const char *Start = GL_Extensions;
475 memset(ThisExtn, 0x00, sizeof(ThisExtn));
476 while (*GL_Extensions != ' ' && *GL_Extensions != 0x00) {
479 memcpy(ThisExtn, Start, (GL_Extensions - Start));
480 TRACE_(d3d_caps)("- %s\n", ThisExtn);
485 if (strcmp(ThisExtn, "GL_ARB_fragment_program") == 0) {
486 gl_info->ps_arb_version = PS_VERSION_11;
487 TRACE_(d3d_caps)(" FOUND: ARB Pixel Shader support - version=%02x\n", gl_info->ps_arb_version);
488 gl_info->supported[ARB_FRAGMENT_PROGRAM] = TRUE;
489 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &gl_max);
490 TRACE_(d3d_caps)(" FOUND: ARB Pixel Shader support - GL_MAX_TEXTURE_IMAGE_UNITS_ARB=%u\n", gl_max);
491 gl_info->max_samplers = min(MAX_SAMPLERS, gl_max);
492 } else if (strcmp(ThisExtn, "GL_ARB_multisample") == 0) {
493 TRACE_(d3d_caps)(" FOUND: ARB Multisample support\n");
494 gl_info->supported[ARB_MULTISAMPLE] = TRUE;
495 } else if (strcmp(ThisExtn, "GL_ARB_multitexture") == 0) {
496 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_max);
497 TRACE_(d3d_caps)(" FOUND: ARB Multitexture support - GL_MAX_TEXTURE_UNITS_ARB=%u\n", gl_max);
498 gl_info->supported[ARB_MULTITEXTURE] = TRUE;
499 gl_info->max_textures = min(MAX_TEXTURES, gl_max);
500 gl_info->max_samplers = max(gl_info->max_samplers, gl_max);
501 } else if (strcmp(ThisExtn, "GL_ARB_texture_cube_map") == 0) {
502 TRACE_(d3d_caps)(" FOUND: ARB Texture Cube Map support\n");
503 gl_info->supported[ARB_TEXTURE_CUBE_MAP] = TRUE;
504 TRACE_(d3d_caps)(" IMPLIED: NVIDIA (NV) Texture Gen Reflection support\n");
505 gl_info->supported[NV_TEXGEN_REFLECTION] = TRUE;
506 } else if (strcmp(ThisExtn, "GL_ARB_texture_compression") == 0) {
507 TRACE_(d3d_caps)(" FOUND: ARB Texture Compression support\n");
508 gl_info->supported[ARB_TEXTURE_COMPRESSION] = TRUE;
509 } else if (strcmp(ThisExtn, "GL_ARB_texture_env_add") == 0) {
510 TRACE_(d3d_caps)(" FOUND: ARB Texture Env Add support\n");
511 gl_info->supported[ARB_TEXTURE_ENV_ADD] = TRUE;
512 } else if (strcmp(ThisExtn, "GL_ARB_texture_env_combine") == 0) {
513 TRACE_(d3d_caps)(" FOUND: ARB Texture Env combine support\n");
514 gl_info->supported[ARB_TEXTURE_ENV_COMBINE] = TRUE;
515 } else if (strcmp(ThisExtn, "GL_ARB_texture_env_dot3") == 0) {
516 TRACE_(d3d_caps)(" FOUND: ARB Dot3 support\n");
517 gl_info->supported[ARB_TEXTURE_ENV_DOT3] = TRUE;
518 } else if (strcmp(ThisExtn, "GL_ARB_texture_border_clamp") == 0) {
519 TRACE_(d3d_caps)(" FOUND: ARB Texture border clamp support\n");
520 gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] = TRUE;
521 } else if (strcmp(ThisExtn, "GL_ARB_texture_mirrored_repeat") == 0) {
522 TRACE_(d3d_caps)(" FOUND: ARB Texture mirrored repeat support\n");
523 gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT] = TRUE;
524 } else if (strcmp(ThisExtn, "GLX_ARB_multisample") == 0) {
525 TRACE_(d3d_caps)(" FOUND: ARB multisample support\n");
526 gl_info->supported[ARB_MULTISAMPLE] = TRUE;
527 } else if (strcmp(ThisExtn, "GL_ARB_pixel_buffer_object") == 0) {
528 TRACE_(d3d_caps)(" FOUND: ARB Pixel Buffer support\n");
529 gl_info->supported[ARB_PIXEL_BUFFER_OBJECT] = TRUE;
530 } else if (strcmp(ThisExtn, "GL_ARB_point_sprite") == 0) {
531 TRACE_(d3d_caps)(" FOUND: ARB point sprite support\n");
532 gl_info->supported[ARB_POINT_SPRITE] = TRUE;
533 } else if (strstr(ThisExtn, "GL_ARB_vertex_program")) {
534 gl_info->vs_arb_version = VS_VERSION_11;
535 TRACE_(d3d_caps)(" FOUND: ARB Vertex Shader support - version=%02x\n", gl_info->vs_arb_version);
536 gl_info->supported[ARB_VERTEX_PROGRAM] = TRUE;
537 } else if (strcmp(ThisExtn, "GL_ARB_vertex_blend") == 0) {
538 glGetIntegerv(GL_MAX_VERTEX_UNITS_ARB, &gl_max);
539 TRACE_(d3d_caps)(" FOUND: ARB Vertex Blend support GL_MAX_VERTEX_UNITS_ARB %d\n", gl_max);
540 gl_info->max_blends = gl_max;
541 gl_info->supported[ARB_VERTEX_BLEND] = TRUE;
542 } else if (strcmp(ThisExtn, "GL_ARB_vertex_buffer_object") == 0) {
543 TRACE_(d3d_caps)(" FOUND: ARB Vertex Buffer support\n");
544 gl_info->supported[ARB_VERTEX_BUFFER_OBJECT] = TRUE;
545 } else if (strcmp(ThisExtn, "GL_ARB_occlusion_query") == 0) {
546 TRACE_(d3d_caps)(" FOUND: ARB Occlusion Query support\n");
547 gl_info->supported[ARB_OCCLUSION_QUERY] = TRUE;
548 } else if (strcmp(ThisExtn, "GL_ARB_point_parameters") == 0) {
549 TRACE_(d3d_caps)(" FOUND: ARB Point parameters support\n");
550 gl_info->supported[ARB_POINT_PARAMETERS] = TRUE;
554 } else if (strcmp(ThisExtn, "GL_EXT_fog_coord") == 0) {
555 TRACE_(d3d_caps)(" FOUND: EXT Fog coord support\n");
556 gl_info->supported[EXT_FOG_COORD] = TRUE;
557 } else if (strcmp(ThisExtn, "GL_EXT_framebuffer_object") == 0) {
558 TRACE_(d3d_caps)(" FOUND: EXT Frame Buffer Object support\n");
559 gl_info->supported[EXT_FRAMEBUFFER_OBJECT] = TRUE;
560 } else if (strcmp(ThisExtn, "GL_EXT_paletted_texture") == 0) { /* handle paletted texture extensions */
561 TRACE_(d3d_caps)(" FOUND: EXT Paletted texture support\n");
562 gl_info->supported[EXT_PALETTED_TEXTURE] = TRUE;
563 } else if (strcmp(ThisExtn, "GL_EXT_point_parameters") == 0) {
564 TRACE_(d3d_caps)(" FOUND: EXT Point parameters support\n");
565 gl_info->supported[EXT_POINT_PARAMETERS] = TRUE;
566 } else if (strcmp(ThisExtn, "GL_EXT_secondary_color") == 0) {
567 TRACE_(d3d_caps)(" FOUND: EXT Secondary coord support\n");
568 gl_info->supported[EXT_SECONDARY_COLOR] = TRUE;
569 } else if (strcmp(ThisExtn, "GL_EXT_stencil_wrap") == 0) {
570 TRACE_(d3d_caps)(" FOUND: EXT Stencil wrap support\n");
571 gl_info->supported[EXT_STENCIL_WRAP] = TRUE;
572 } else if (strcmp(ThisExtn, "GL_EXT_texture_compression_s3tc") == 0) {
573 TRACE_(d3d_caps)(" FOUND: EXT Texture S3TC compression support\n");
574 gl_info->supported[EXT_TEXTURE_COMPRESSION_S3TC] = TRUE;
575 } else if (strcmp(ThisExtn, "GL_EXT_texture_env_add") == 0) {
576 TRACE_(d3d_caps)(" FOUND: EXT Texture Env Add support\n");
577 gl_info->supported[EXT_TEXTURE_ENV_ADD] = TRUE;
578 } else if (strcmp(ThisExtn, "GL_EXT_texture_env_combine") == 0) {
579 TRACE_(d3d_caps)(" FOUND: EXT Texture Env combine support\n");
580 gl_info->supported[EXT_TEXTURE_ENV_COMBINE] = TRUE;
581 } else if (strcmp(ThisExtn, "GL_EXT_texture_env_dot3") == 0) {
582 TRACE_(d3d_caps)(" FOUND: EXT Dot3 support\n");
583 gl_info->supported[EXT_TEXTURE_ENV_DOT3] = TRUE;
584 } else if (strcmp(ThisExtn, "GL_EXT_texture_filter_anisotropic") == 0) {
585 gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] = TRUE;
586 glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &gl_max);
587 TRACE_(d3d_caps)(" FOUND: EXT Texture Anisotropic filter support. GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT %d\n", gl_max);
588 gl_info->max_anisotropy = gl_max;
589 } else if (strcmp(ThisExtn, "GL_EXT_texture_lod") == 0) {
590 TRACE_(d3d_caps)(" FOUND: EXT Texture LOD support\n");
591 gl_info->supported[EXT_TEXTURE_LOD] = TRUE;
592 } else if (strcmp(ThisExtn, "GL_EXT_texture_lod_bias") == 0) {
593 TRACE_(d3d_caps)(" FOUND: EXT Texture LOD bias support\n");
594 gl_info->supported[EXT_TEXTURE_LOD_BIAS] = TRUE;
595 } else if (strcmp(ThisExtn, "GL_EXT_vertex_weighting") == 0) {
596 TRACE_(d3d_caps)(" FOUND: EXT Vertex weighting support\n");
597 gl_info->supported[EXT_VERTEX_WEIGHTING] = TRUE;
602 } else if (strstr(ThisExtn, "GL_NV_fog_distance")) {
603 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Fog Distance support\n");
604 gl_info->supported[NV_FOG_DISTANCE] = TRUE;
605 } else if (strstr(ThisExtn, "GL_NV_fragment_program")) {
606 gl_info->ps_nv_version = PS_VERSION_11;
607 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Pixel Shader support - version=%02x\n", gl_info->ps_nv_version);
608 } else if (strcmp(ThisExtn, "GL_NV_register_combiners") == 0) {
609 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Register combiners (1) support\n");
610 gl_info->supported[NV_REGISTER_COMBINERS] = TRUE;
611 } else if (strcmp(ThisExtn, "GL_NV_register_combiners2") == 0) {
612 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Register combiners (2) support\n");
613 gl_info->supported[NV_REGISTER_COMBINERS2] = TRUE;
614 } else if (strcmp(ThisExtn, "GL_NV_texgen_reflection") == 0) {
615 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Texture Gen Reflection support\n");
616 gl_info->supported[NV_TEXGEN_REFLECTION] = TRUE;
617 } else if (strcmp(ThisExtn, "GL_NV_texture_env_combine4") == 0) {
618 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Texture Env combine (4) support\n");
619 gl_info->supported[NV_TEXTURE_ENV_COMBINE4] = TRUE;
620 } else if (strcmp(ThisExtn, "GL_NV_texture_shader") == 0) {
621 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Texture Shader (1) support\n");
622 gl_info->supported[NV_TEXTURE_SHADER] = TRUE;
623 } else if (strcmp(ThisExtn, "GL_NV_texture_shader2") == 0) {
624 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Texture Shader (2) support\n");
625 gl_info->supported[NV_TEXTURE_SHADER2] = TRUE;
626 } else if (strcmp(ThisExtn, "GL_NV_texture_shader3") == 0) {
627 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Texture Shader (3) support\n");
628 gl_info->supported[NV_TEXTURE_SHADER3] = TRUE;
629 } else if (strcmp(ThisExtn, "GL_NV_occlusion_query") == 0) {
630 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Occlusion Query (3) support\n");
631 gl_info->supported[NV_OCCLUSION_QUERY] = TRUE;
632 } else if (strstr(ThisExtn, "GL_NV_vertex_program")) {
633 gl_info->vs_nv_version = max(gl_info->vs_nv_version, (0 == strcmp(ThisExtn, "GL_NV_vertex_program1_1")) ? VS_VERSION_11 : VS_VERSION_10);
634 gl_info->vs_nv_version = max(gl_info->vs_nv_version, (0 == strcmp(ThisExtn, "GL_NV_vertex_program2")) ? VS_VERSION_20 : VS_VERSION_10);
635 TRACE_(d3d_caps)(" FOUND: NVIDIA (NV) Vertex Shader support - version=%02x\n", gl_info->vs_nv_version);
636 gl_info->supported[NV_VERTEX_PROGRAM] = TRUE;
642 } else if (strcmp(ThisExtn, "GL_ATI_texture_env_combine3") == 0) {
643 TRACE_(d3d_caps)(" FOUND: ATI Texture Env combine (3) support\n");
644 gl_info->supported[ATI_TEXTURE_ENV_COMBINE3] = TRUE;
645 } else if (strcmp(ThisExtn, "GL_ATI_texture_mirror_once") == 0) {
646 TRACE_(d3d_caps)(" FOUND: ATI Texture Mirror Once support\n");
647 gl_info->supported[ATI_TEXTURE_MIRROR_ONCE] = TRUE;
648 } else if (strcmp(ThisExtn, "GL_EXT_vertex_shader") == 0) {
649 gl_info->vs_ati_version = VS_VERSION_11;
650 TRACE_(d3d_caps)(" FOUND: ATI (EXT) Vertex Shader support - version=%02x\n", gl_info->vs_ati_version);
651 gl_info->supported[EXT_VERTEX_SHADER] = TRUE;
655 if (*GL_Extensions == ' ') GL_Extensions++;
659 /* Load all the lookup tables
660 TODO: It may be a good idea to make minLookup and maxLookup const and populate them in wined3d_private.h where they are declared */
661 minLookup[WINELOOKUP_WARPPARAM] = D3DTADDRESS_WRAP;
662 maxLookup[WINELOOKUP_WARPPARAM] = D3DTADDRESS_MIRRORONCE;
664 minLookup[WINELOOKUP_MAGFILTER] = D3DTEXF_NONE;
665 maxLookup[WINELOOKUP_MAGFILTER] = D3DTEXF_ANISOTROPIC;
668 for (i = 0; i < MAX_LOOKUPS; i++) {
669 stateLookup[i] = HeapAlloc(GetProcessHeap(), 0, sizeof(*stateLookup[i]) * (1 + maxLookup[i] - minLookup[i]) );
672 stateLookup[WINELOOKUP_WARPPARAM][D3DTADDRESS_WRAP - minLookup[WINELOOKUP_WARPPARAM]] = GL_REPEAT;
673 stateLookup[WINELOOKUP_WARPPARAM][D3DTADDRESS_CLAMP - minLookup[WINELOOKUP_WARPPARAM]] = GL_CLAMP_TO_EDGE;
674 stateLookup[WINELOOKUP_WARPPARAM][D3DTADDRESS_BORDER - minLookup[WINELOOKUP_WARPPARAM]] =
675 gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] ? GL_CLAMP_TO_BORDER_ARB : GL_REPEAT;
676 stateLookup[WINELOOKUP_WARPPARAM][D3DTADDRESS_BORDER - minLookup[WINELOOKUP_WARPPARAM]] =
677 gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] ? GL_CLAMP_TO_BORDER_ARB : GL_REPEAT;
678 stateLookup[WINELOOKUP_WARPPARAM][D3DTADDRESS_MIRROR - minLookup[WINELOOKUP_WARPPARAM]] =
679 gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT] ? GL_MIRRORED_REPEAT_ARB : GL_REPEAT;
680 stateLookup[WINELOOKUP_WARPPARAM][D3DTADDRESS_MIRRORONCE - minLookup[WINELOOKUP_WARPPARAM]] =
681 gl_info->supported[ATI_TEXTURE_MIRROR_ONCE] ? GL_MIRROR_CLAMP_TO_EDGE_ATI : GL_REPEAT;
683 stateLookup[WINELOOKUP_MAGFILTER][D3DTEXF_NONE - minLookup[WINELOOKUP_MAGFILTER]] = GL_NEAREST;
684 stateLookup[WINELOOKUP_MAGFILTER][D3DTEXF_POINT - minLookup[WINELOOKUP_MAGFILTER]] = GL_NEAREST;
685 stateLookup[WINELOOKUP_MAGFILTER][D3DTEXF_LINEAR - minLookup[WINELOOKUP_MAGFILTER]] = GL_LINEAR;
686 stateLookup[WINELOOKUP_MAGFILTER][D3DTEXF_ANISOTROPIC - minLookup[WINELOOKUP_MAGFILTER]] =
687 gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ? GL_LINEAR : GL_NEAREST;
690 minMipLookup[D3DTEXF_NONE][D3DTEXF_NONE] = GL_LINEAR;
691 minMipLookup[D3DTEXF_NONE][D3DTEXF_POINT] = GL_LINEAR;
692 minMipLookup[D3DTEXF_NONE][D3DTEXF_LINEAR] = GL_LINEAR;
693 minMipLookup[D3DTEXF_POINT][D3DTEXF_NONE] = GL_NEAREST;
694 minMipLookup[D3DTEXF_POINT][D3DTEXF_POINT] = GL_NEAREST_MIPMAP_NEAREST;
695 minMipLookup[D3DTEXF_POINT][D3DTEXF_LINEAR] = GL_NEAREST_MIPMAP_LINEAR;
696 minMipLookup[D3DTEXF_LINEAR][D3DTEXF_NONE] = GL_LINEAR;
697 minMipLookup[D3DTEXF_LINEAR][D3DTEXF_POINT] = GL_LINEAR_MIPMAP_NEAREST;
698 minMipLookup[D3DTEXF_LINEAR][D3DTEXF_LINEAR] = GL_LINEAR_MIPMAP_LINEAR;
699 minMipLookup[D3DTEXF_ANISOTROPIC][D3DTEXF_NONE] = gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ?
700 GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR;
701 minMipLookup[D3DTEXF_ANISOTROPIC][D3DTEXF_POINT] = gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR;
702 minMipLookup[D3DTEXF_ANISOTROPIC][D3DTEXF_LINEAR] = gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR;
704 /* TODO: config lookups */
707 #define USE_GL_FUNC(type, pfn) gl_info->pfn = (type) glXGetProcAddressARB( (const GLubyte *) #pfn);
711 if (display != NULL) {
712 GLX_Extensions = glXQueryExtensionsString(display, DefaultScreen(display));
713 TRACE_(d3d_caps)("GLX_Extensions reported:\n");
715 if (NULL == GLX_Extensions) {
716 ERR(" GLX_Extensions returns NULL\n");
718 while (*GLX_Extensions != 0x00) {
719 const char *Start = GLX_Extensions;
722 memset(ThisExtn, 0x00, sizeof(ThisExtn));
723 while (*GLX_Extensions != ' ' && *GLX_Extensions != 0x00) {
726 memcpy(ThisExtn, Start, (GLX_Extensions - Start));
727 TRACE_(d3d_caps)("- %s\n", ThisExtn);
728 if (*GLX_Extensions == ' ') GLX_Extensions++;
733 #define USE_GL_FUNC(type, pfn) gl_info->pfn = (type) glXGetProcAddressARB( (const GLubyte *) #pfn);
737 /* If we created a dummy context, throw it away */
738 if (NULL != fake_ctx) WineD3D_ReleaseFakeGLContext(fake_ctx);
740 /* Only save the values obtained when a display is provided */
741 if (fake_ctx == NULL) {
748 /**********************************************************
749 * IWineD3D implementation follows
750 **********************************************************/
752 UINT WINAPI IWineD3DImpl_GetAdapterCount (IWineD3D *iface) {
753 IWineD3DImpl *This = (IWineD3DImpl *)iface;
755 /* FIXME: Set to one for now to imply the display */
756 TRACE_(d3d_caps)("(%p): Mostly stub, only returns primary display\n", This);
760 HRESULT WINAPI IWineD3DImpl_RegisterSoftwareDevice(IWineD3D *iface, void* pInitializeFunction) {
761 IWineD3DImpl *This = (IWineD3DImpl *)iface;
762 FIXME("(%p)->(%p): stub\n", This, pInitializeFunction);
766 HMONITOR WINAPI IWineD3DImpl_GetAdapterMonitor(IWineD3D *iface, UINT Adapter) {
767 IWineD3DImpl *This = (IWineD3DImpl *)iface;
768 FIXME_(d3d_caps)("(%p)->(Adptr:%d)\n", This, Adapter);
769 if (Adapter >= IWineD3DImpl_GetAdapterCount(iface)) {
775 /* FIXME: GetAdapterModeCount and EnumAdapterModes currently only returns modes
776 of the same bpp but different resolutions */
778 /* Note: dx9 supplies a format. Calls from d3d8 supply D3DFMT_UNKNOWN */
779 UINT WINAPI IWineD3DImpl_GetAdapterModeCount(IWineD3D *iface, UINT Adapter, WINED3DFORMAT Format) {
780 IWineD3DImpl *This = (IWineD3DImpl *)iface;
781 TRACE_(d3d_caps)("(%p}->(Adapter: %d, Format: %s)\n", This, Adapter, debug_d3dformat(Format));
783 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
787 if (Adapter == 0) { /* Display */
790 #if !defined( DEBUG_SINGLE_MODE )
793 /* Work out the current screen bpp */
794 HDC hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
795 int bpp = GetDeviceCaps(hdc, BITSPIXEL);
798 while (EnumDisplaySettingsExW(NULL, j, &DevModeW, 0)) {
805 case D3DFMT_X8R8G8B8:
806 case D3DFMT_A8R8G8B8:
807 if (min(DevModeW.dmBitsPerPel, bpp) == 32) i++;
808 if (min(DevModeW.dmBitsPerPel, bpp) == 24) i++;
810 case D3DFMT_X1R5G5B5:
811 case D3DFMT_A1R5G5B5:
813 if (min(DevModeW.dmBitsPerPel, bpp) == 16) i++;
816 /* Skip other modes as they do not match requested format */
824 TRACE_(d3d_caps)("(%p}->(Adapter: %d) => %d (out of %d)\n", This, Adapter, i, j);
827 FIXME_(d3d_caps)("Adapter not primary display\n");
832 /* Note: dx9 supplies a format. Calls from d3d8 supply D3DFMT_UNKNOWN */
833 HRESULT WINAPI IWineD3DImpl_EnumAdapterModes(IWineD3D *iface, UINT Adapter, WINED3DFORMAT Format, UINT Mode, D3DDISPLAYMODE* pMode) {
834 IWineD3DImpl *This = (IWineD3DImpl *)iface;
835 TRACE_(d3d_caps)("(%p}->(Adapter:%d, mode:%d, pMode:%p, format:%s)\n", This, Adapter, Mode, pMode, debug_d3dformat(Format));
837 /* Validate the parameters as much as possible */
839 Adapter >= IWineD3DImpl_GetAdapterCount(iface) ||
840 Mode >= IWineD3DImpl_GetAdapterModeCount(iface, Adapter, Format)) {
841 return D3DERR_INVALIDCALL;
844 if (Adapter == 0) { /* Display */
845 #if !defined( DEBUG_SINGLE_MODE )
849 /* Work out the current screen bpp */
850 HDC hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
851 int bpp = GetDeviceCaps(hdc, BITSPIXEL);
854 /* If we are filtering to a specific format, then need to skip all unrelated
855 modes, but if mode is irrelevant, then we can use the index directly */
856 if (Format == D3DFMT_UNKNOWN)
862 DEVMODEW DevModeWtmp;
865 while (i<(Mode) && EnumDisplaySettingsExW(NULL, j, &DevModeWtmp, 0)) {
872 case D3DFMT_X8R8G8B8:
873 case D3DFMT_A8R8G8B8:
874 if (min(DevModeWtmp.dmBitsPerPel, bpp) == 32) i++;
875 if (min(DevModeWtmp.dmBitsPerPel, bpp) == 24) i++;
877 case D3DFMT_X1R5G5B5:
878 case D3DFMT_A1R5G5B5:
880 if (min(DevModeWtmp.dmBitsPerPel, bpp) == 16) i++;
883 /* Skip other modes as they do not match requested format */
890 /* Now get the display mode via the calculated index */
891 if (EnumDisplaySettingsExW(NULL, ModeIdx, &DevModeW, 0))
893 pMode->Width = DevModeW.dmPelsWidth;
894 pMode->Height = DevModeW.dmPelsHeight;
895 bpp = min(DevModeW.dmBitsPerPel, bpp);
896 pMode->RefreshRate = D3DADAPTER_DEFAULT;
897 if (DevModeW.dmFields & DM_DISPLAYFREQUENCY)
899 pMode->RefreshRate = DevModeW.dmDisplayFrequency;
902 if (Format == D3DFMT_UNKNOWN)
905 case 8: pMode->Format = D3DFMT_R3G3B2; break;
906 case 16: pMode->Format = D3DFMT_R5G6B5; break;
907 case 24: /* Robots and EVE Online need 24 and 32 bit as A8R8G8B8 to start */
908 case 32: pMode->Format = D3DFMT_A8R8G8B8; break;
909 default: pMode->Format = D3DFMT_UNKNOWN;
912 pMode->Format = Format;
917 TRACE_(d3d_caps)("Requested mode out of range %d\n", Mode);
918 return D3DERR_INVALIDCALL;
922 /* Return one setting of the format requested */
923 if (Mode > 0) return D3DERR_INVALIDCALL;
926 pMode->RefreshRate = D3DADAPTER_DEFAULT;
927 pMode->Format = (Format == D3DFMT_UNKNOWN) ? D3DFMT_A8R8G8B8 : Format;
930 TRACE_(d3d_caps)("W %d H %d rr %d fmt (%x - %s) bpp %u\n", pMode->Width, pMode->Height,
931 pMode->RefreshRate, pMode->Format, debug_d3dformat(pMode->Format), bpp);
934 FIXME_(d3d_caps)("Adapter not primary display\n");
940 HRESULT WINAPI IWineD3DImpl_GetAdapterDisplayMode(IWineD3D *iface, UINT Adapter, D3DDISPLAYMODE* pMode) {
941 IWineD3DImpl *This = (IWineD3DImpl *)iface;
942 TRACE_(d3d_caps)("(%p}->(Adapter: %d, pMode: %p)\n", This, Adapter, pMode);
945 Adapter >= IWineD3D_GetAdapterCount(iface)) {
946 return D3DERR_INVALIDCALL;
949 if (Adapter == 0) { /* Display */
953 EnumDisplaySettingsExW(NULL, (DWORD)-1, &DevModeW, 0);
954 pMode->Width = DevModeW.dmPelsWidth;
955 pMode->Height = DevModeW.dmPelsHeight;
956 bpp = DevModeW.dmBitsPerPel;
957 pMode->RefreshRate = D3DADAPTER_DEFAULT;
958 if (DevModeW.dmFields&DM_DISPLAYFREQUENCY)
960 pMode->RefreshRate = DevModeW.dmDisplayFrequency;
964 case 8: pMode->Format = D3DFMT_R3G3B2; break;
965 case 16: pMode->Format = D3DFMT_R5G6B5; break;
966 case 24: pMode->Format = D3DFMT_X8R8G8B8; break; /* Robots needs 24bit to be X8R8G8B8 */
967 case 32: pMode->Format = D3DFMT_X8R8G8B8; break; /* EVE online and the Fur demo need 32bit AdapterDisplatMode to return X8R8G8B8 */
968 default: pMode->Format = D3DFMT_UNKNOWN;
972 FIXME_(d3d_caps)("Adapter not primary display\n");
975 TRACE_(d3d_caps)("returning w:%d, h:%d, ref:%d, fmt:%s\n", pMode->Width,
976 pMode->Height, pMode->RefreshRate, debug_d3dformat(pMode->Format));
980 static Display * WINAPI IWineD3DImpl_GetAdapterDisplay(IWineD3D *iface, UINT Adapter) {
983 /* only works with one adapter at the moment... */
985 /* Get the display */
986 device_context = GetDC(0);
987 display = get_display(device_context);
988 ReleaseDC(0, device_context);
992 /* NOTE: due to structure differences between dx8 and dx9 D3DADAPTER_IDENTIFIER,
993 and fields being inserted in the middle, a new structure is used in place */
994 HRESULT WINAPI IWineD3DImpl_GetAdapterIdentifier(IWineD3D *iface, UINT Adapter, DWORD Flags,
995 WINED3DADAPTER_IDENTIFIER* pIdentifier) {
996 IWineD3DImpl *This = (IWineD3DImpl *)iface;
998 TRACE_(d3d_caps)("(%p}->(Adapter: %d, Flags: %lx, pId=%p)\n", This, Adapter, Flags, pIdentifier);
1000 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1001 return D3DERR_INVALIDCALL;
1004 if (Adapter == 0) { /* Display - only device supported for now */
1006 BOOL isGLInfoValid = This->isGLInfoValid;
1008 /* FillGLCaps updates gl_info, but we only want to store and
1009 reuse the values once we have a context which is valid. Values from
1010 a temporary context may differ from the final ones */
1011 if (isGLInfoValid == FALSE) {
1012 /* If we don't know the device settings, go query them now */
1013 isGLInfoValid = IWineD3DImpl_FillGLCaps(&This->gl_info, IWineD3DImpl_GetAdapterDisplay(iface, Adapter));
1016 /* If it worked, return the information requested */
1017 if (isGLInfoValid) {
1018 TRACE_(d3d_caps)("device/Vendor Name and Version detection using FillGLCaps\n");
1019 strcpy(pIdentifier->Driver, "Display");
1020 strcpy(pIdentifier->Description, "Direct3D HAL");
1022 /* Note dx8 doesn't supply a DeviceName */
1023 if (NULL != pIdentifier->DeviceName) strcpy(pIdentifier->DeviceName, "\\\\.\\DISPLAY"); /* FIXME: May depend on desktop? */
1024 /* Current Windows drivers have versions like 6.14.... (some older have an earlier version) */
1025 pIdentifier->DriverVersion->u.HighPart = MAKEDWORD_VERSION(6, 14);
1026 pIdentifier->DriverVersion->u.LowPart = This->gl_info.gl_driver_version;
1027 *(pIdentifier->VendorId) = This->gl_info.gl_vendor;
1028 *(pIdentifier->DeviceId) = This->gl_info.gl_card;
1029 *(pIdentifier->SubSysId) = 0;
1030 *(pIdentifier->Revision) = 0;
1034 /* If it failed, return dummy values from an NVidia driver */
1035 WARN_(d3d_caps)("Cannot get GLCaps for device/Vendor Name and Version detection using FillGLCaps, currently using NVIDIA identifiers\n");
1036 strcpy(pIdentifier->Driver, "Display");
1037 strcpy(pIdentifier->Description, "Direct3D HAL");
1038 if (NULL != pIdentifier->DeviceName) strcpy(pIdentifier->DeviceName, "\\\\.\\DISPLAY"); /* FIXME: May depend on desktop? */
1039 /* Current Windows Nvidia drivers have versions like e.g. 6.14.10.5672 */
1040 pIdentifier->DriverVersion->u.HighPart = MAKEDWORD_VERSION(6, 14);
1041 /* 71.74 is a current Linux Nvidia driver version */
1042 pIdentifier->DriverVersion->u.LowPart = MAKEDWORD_VERSION(10, (71*100+74));
1043 *(pIdentifier->VendorId) = VENDOR_NVIDIA;
1044 *(pIdentifier->DeviceId) = CARD_NVIDIA_GEFORCE4_TI4600;
1045 *(pIdentifier->SubSysId) = 0;
1046 *(pIdentifier->Revision) = 0;
1049 /*FIXME: memcpy(&pIdentifier->DeviceIdentifier, ??, sizeof(??GUID)); */
1050 if (Flags & D3DENUM_NO_WHQL_LEVEL) {
1051 *(pIdentifier->WHQLLevel) = 0;
1053 *(pIdentifier->WHQLLevel) = 1;
1057 FIXME_(d3d_caps)("Adapter not primary display\n");
1063 static BOOL IWineD3DImpl_IsGLXFBConfigCompatibleWithRenderFmt(WineD3D_Context* ctx, GLXFBConfig cfgs, WINED3DFORMAT Format) {
1064 #if 0 /* This code performs a strict test between the format and the current X11 buffer depth, which may give the best performance */
1066 int rb, gb, bb, ab, type, buf_sz;
1068 gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_RED_SIZE, &rb);
1069 gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_GREEN_SIZE, &gb);
1070 gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_BLUE_SIZE, &bb);
1071 gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_ALPHA_SIZE, &ab);
1072 gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_RENDER_TYPE, &type);
1073 gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_BUFFER_SIZE, &buf_sz);
1076 case WINED3DFMT_X8R8G8B8:
1077 case WINED3DFMT_R8G8B8:
1078 if (8 == rb && 8 == gb && 8 == bb) return TRUE;
1080 case WINED3DFMT_A8R8G8B8:
1081 if (8 == rb && 8 == gb && 8 == bb && 8 == ab) return TRUE;
1083 case WINED3DFMT_A2R10G10B10:
1084 if (10 == rb && 10 == gb && 10 == bb && 2 == ab) return TRUE;
1086 case WINED3DFMT_X1R5G5B5:
1087 if (5 == rb && 5 == gb && 5 == bb) return TRUE;
1089 case WINED3DFMT_A1R5G5B5:
1090 if (5 == rb && 5 == gb && 5 == bb && 1 == ab) return TRUE;
1092 case WINED3DFMT_X4R4G4B4:
1093 if (16 == buf_sz && 4 == rb && 4 == gb && 4 == bb) return TRUE;
1095 case WINED3DFMT_R5G6B5:
1096 if (5 == rb && 6 == gb && 5 == bb) return TRUE;
1098 case WINED3DFMT_R3G3B2:
1099 if (3 == rb && 3 == gb && 2 == bb) return TRUE;
1101 case WINED3DFMT_A8P8:
1102 if (type & GLX_COLOR_INDEX_BIT && 8 == buf_sz && 8 == ab) return TRUE;
1105 if (type & GLX_COLOR_INDEX_BIT && 8 == buf_sz) return TRUE;
1108 ERR("unsupported format %s\n", debug_d3dformat(Format));
1112 #else /* Most of the time performance is less of an issue than compatibility, this code allows for most common opengl/d3d formats */
1114 case WINED3DFMT_X8R8G8B8:
1115 case WINED3DFMT_R8G8B8:
1116 case WINED3DFMT_A8R8G8B8:
1117 case WINED3DFMT_A2R10G10B10:
1118 case WINED3DFMT_X1R5G5B5:
1119 case WINED3DFMT_A1R5G5B5:
1120 case WINED3DFMT_R5G6B5:
1121 case WINED3DFMT_R3G3B2:
1122 case WINED3DFMT_A8P8:
1126 ERR("unsupported format %s\n", debug_d3dformat(Format));
1133 static BOOL IWineD3DImpl_IsGLXFBConfigCompatibleWithDepthFmt(WineD3D_Context* ctx, GLXFBConfig cfgs, WINED3DFORMAT Format) {
1134 #if 0/* This code performs a strict test between the format and the current X11 buffer depth, which may give the best performance */
1138 gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_DEPTH_SIZE, &db);
1139 gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_STENCIL_SIZE, &sb);
1142 case WINED3DFMT_D16:
1143 case WINED3DFMT_D16_LOCKABLE:
1144 if (16 == db) return TRUE;
1146 case WINED3DFMT_D32:
1147 if (32 == db) return TRUE;
1149 case WINED3DFMT_D15S1:
1150 if (15 == db) return TRUE;
1152 case WINED3DFMT_D24S8:
1153 if (24 == db && 8 == sb) return TRUE;
1155 case WINED3DFMT_D24FS8:
1156 if (24 == db && 8 == sb) return TRUE;
1158 case WINED3DFMT_D24X8:
1159 if (24 == db) return TRUE;
1161 case WINED3DFMT_D24X4S4:
1162 if (24 == db && 4 == sb) return TRUE;
1164 case WINED3DFMT_D32F_LOCKABLE:
1165 if (32 == db) return TRUE;
1168 ERR("unsupported format %s\n", debug_d3dformat(Format));
1172 #else /* Most of the time performance is less of an issue than compatibility, this code allows for most common opengl/d3d formats */
1174 case WINED3DFMT_D16:
1175 case WINED3DFMT_D16_LOCKABLE:
1176 case WINED3DFMT_D32:
1177 case WINED3DFMT_D15S1:
1178 case WINED3DFMT_D24S8:
1179 case WINED3DFMT_D24FS8:
1180 case WINED3DFMT_D24X8:
1181 case WINED3DFMT_D24X4S4:
1182 case WINED3DFMT_D32F_LOCKABLE:
1185 ERR("unsupported format %s\n", debug_d3dformat(Format));
1192 HRESULT WINAPI IWineD3DImpl_CheckDepthStencilMatch(IWineD3D *iface, UINT Adapter, D3DDEVTYPE DeviceType,
1193 WINED3DFORMAT AdapterFormat,
1194 WINED3DFORMAT RenderTargetFormat,
1195 WINED3DFORMAT DepthStencilFormat) {
1196 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1197 HRESULT hr = D3DERR_NOTAVAILABLE;
1198 WineD3D_Context* ctx = NULL;
1199 GLXFBConfig* cfgs = NULL;
1203 WARN_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%x,%s), AdptFmt:(%x,%s), RendrTgtFmt:(%x,%s), DepthStencilFmt:(%x,%s))\n",
1205 DeviceType, debug_d3ddevicetype(DeviceType),
1206 AdapterFormat, debug_d3dformat(AdapterFormat),
1207 RenderTargetFormat, debug_d3dformat(RenderTargetFormat),
1208 DepthStencilFormat, debug_d3dformat(DepthStencilFormat));
1210 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1211 TRACE("(%p) Failed: Atapter (%u) higher than supported adapters (%u) returning D3DERR_INVALIDCALL\n", This, Adapter, IWineD3D_GetAdapterCount(iface));
1212 return D3DERR_INVALIDCALL;
1214 /* TODO: use the real context if it's available */
1215 ctx = WineD3D_CreateFakeGLContext();
1217 cfgs = glXGetFBConfigs(ctx->display, DefaultScreen(ctx->display), &nCfgs);
1219 TRACE_(d3d_caps)("(%p) : Unable to create a fake context at this time (there may already be an active context)\n", This);
1223 for (it = 0; it < nCfgs; ++it) {
1224 if (IWineD3DImpl_IsGLXFBConfigCompatibleWithRenderFmt(ctx, cfgs[it], RenderTargetFormat)) {
1225 if (IWineD3DImpl_IsGLXFBConfigCompatibleWithDepthFmt(ctx, cfgs[it], DepthStencilFormat)) {
1234 /* If there's a corrent context then we cannot create a fake one so pass everything */
1239 WineD3D_ReleaseFakeGLContext(ctx);
1242 TRACE_(d3d_caps)("Failed to match stencil format to device\b");
1244 TRACE_(d3d_caps)("(%p) : Returning %lx\n", This, hr);
1248 HRESULT WINAPI IWineD3DImpl_CheckDeviceMultiSampleType(IWineD3D *iface, UINT Adapter, D3DDEVTYPE DeviceType,
1249 WINED3DFORMAT SurfaceFormat,
1250 BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType, DWORD* pQualityLevels) {
1252 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1253 TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%x,%s), SurfFmt:(%x,%s), Win?%d, MultiSamp:%x, pQual:%p)\n",
1256 DeviceType, debug_d3ddevicetype(DeviceType),
1257 SurfaceFormat, debug_d3dformat(SurfaceFormat),
1262 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1263 return D3DERR_INVALIDCALL;
1266 if (pQualityLevels != NULL) {
1267 static int s_single_shot = 0;
1268 if (!s_single_shot) {
1269 FIXME("Quality levels unsupported at present\n");
1272 *pQualityLevels = 1; /* Guess at a value! */
1275 if (D3DMULTISAMPLE_NONE == MultiSampleType) return D3D_OK;
1276 return D3DERR_NOTAVAILABLE;
1279 HRESULT WINAPI IWineD3DImpl_CheckDeviceType(IWineD3D *iface, UINT Adapter, D3DDEVTYPE CheckType,
1280 WINED3DFORMAT DisplayFormat, WINED3DFORMAT BackBufferFormat, BOOL Windowed) {
1282 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1283 TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, CheckType:(%x,%s), DispFmt:(%x,%s), BackBuf:(%x,%s), Win?%d): stub\n",
1286 CheckType, debug_d3ddevicetype(CheckType),
1287 DisplayFormat, debug_d3dformat(DisplayFormat),
1288 BackBufferFormat, debug_d3dformat(BackBufferFormat),
1291 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1292 return D3DERR_INVALIDCALL;
1296 GLXFBConfig* cfgs = NULL;
1299 HRESULT hr = D3DERR_NOTAVAILABLE;
1301 WineD3D_Context* ctx = WineD3D_CreateFakeGLContext();
1303 cfgs = glXGetFBConfigs(ctx->display, DefaultScreen(ctx->display), &nCfgs);
1304 for (it = 0; it < nCfgs; ++it) {
1305 if (IWineD3DImpl_IsGLXFBConfigCompatibleWithRenderFmt(ctx, cfgs[it], DisplayFormat)) {
1312 WineD3D_ReleaseFakeGLContext(ctx);
1317 return D3DERR_NOTAVAILABLE;
1320 HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapter, D3DDEVTYPE DeviceType,
1321 WINED3DFORMAT AdapterFormat, DWORD Usage, D3DRESOURCETYPE RType, WINED3DFORMAT CheckFormat) {
1322 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1323 TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%u,%s), AdptFmt:(%u,%s), Use:(%lu,%s), ResTyp:(%x,%s), CheckFmt:(%u,%s)) ",
1326 DeviceType, debug_d3ddevicetype(DeviceType),
1327 AdapterFormat, debug_d3dformat(AdapterFormat),
1328 Usage, debug_d3dusage(Usage),
1329 RType, debug_d3dresourcetype(RType),
1330 CheckFormat, debug_d3dformat(CheckFormat));
1332 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1333 return D3DERR_INVALIDCALL;
1336 if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
1337 switch (CheckFormat) {
1343 TRACE_(d3d_caps)("[OK]\n");
1346 break; /* Avoid compiler warnings */
1350 switch (CheckFormat) {
1352 * check supported using GL_SUPPORT
1363 /*case D3DFMT_R5G6B5: */
1364 /*case D3DFMT_X1R5G5B5:*/
1365 /*case D3DFMT_A1R5G5B5: */
1366 /*case D3DFMT_A4R4G4B4:*/
1373 /*case D3DFMT_X8R8G8B8:*/
1374 case D3DFMT_A8R3G3B2:
1391 case D3DFMT_X8L8V8U8:
1392 case D3DFMT_Q8W8V8U8:
1393 case D3DFMT_W11V11U10:
1396 * currently hard to support
1401 /* Since we do not support these formats right now, don't pretend to. */
1402 TRACE_(d3d_caps)("[FAILED]\n");
1403 return D3DERR_NOTAVAILABLE;
1408 TRACE_(d3d_caps)("[OK]\n");
1412 HRESULT WINAPI IWineD3DImpl_CheckDeviceFormatConversion(IWineD3D *iface, UINT Adapter, D3DDEVTYPE DeviceType,
1413 WINED3DFORMAT SourceFormat, WINED3DFORMAT TargetFormat) {
1414 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1416 FIXME_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%u,%s), SrcFmt:(%u,%s), TgtFmt:(%u,%s))",
1419 DeviceType, debug_d3ddevicetype(DeviceType),
1420 SourceFormat, debug_d3dformat(SourceFormat),
1421 TargetFormat, debug_d3dformat(TargetFormat));
1425 /* Note: d3d8 passes in a pointer to a D3DCAPS8 structure, which is a true
1426 subset of a D3DCAPS9 structure. However, it has to come via a void *
1427 as the d3d8 interface cannot import the d3d9 header */
1428 HRESULT WINAPI IWineD3DImpl_GetDeviceCaps(IWineD3D *iface, UINT Adapter, D3DDEVTYPE DeviceType, WINED3DCAPS* pCaps) {
1430 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1432 TRACE_(d3d_caps)("(%p)->(Adptr:%d, DevType: %x, pCaps: %p)\n", This, Adapter, DeviceType, pCaps);
1434 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1435 return D3DERR_INVALIDCALL;
1438 /* If we don't know the device settings, go query them now */
1439 if (This->isGLInfoValid == FALSE) {
1440 /* use the desktop window to fill gl caps */
1441 BOOL rc = IWineD3DImpl_FillGLCaps(&This->gl_info, IWineD3DImpl_GetAdapterDisplay(iface, Adapter));
1443 /* We are running off a real context, save the values */
1444 if (rc) This->isGLInfoValid = TRUE;
1448 /* ------------------------------------------------
1449 The following fields apply to both d3d8 and d3d9
1450 ------------------------------------------------ */
1451 *pCaps->DeviceType = (DeviceType == D3DDEVTYPE_HAL) ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF; /* Not quite true, but use h/w supported by opengl I suppose */
1452 *pCaps->AdapterOrdinal = Adapter;
1455 *pCaps->Caps2 = D3DCAPS2_CANRENDERWINDOWED;
1456 *pCaps->Caps3 = D3DDEVCAPS_HWTRANSFORMANDLIGHT;
1457 *pCaps->PresentationIntervals = D3DPRESENT_INTERVAL_IMMEDIATE;
1459 *pCaps->CursorCaps = 0;
1462 *pCaps->DevCaps = D3DDEVCAPS_DRAWPRIMTLVERTEX |
1463 D3DDEVCAPS_HWTRANSFORMANDLIGHT |
1464 D3DDEVCAPS_EXECUTEVIDEOMEMORY |
1465 D3DDEVCAPS_PUREDEVICE |
1466 D3DDEVCAPS_HWRASTERIZATION |
1467 D3DDEVCAPS_TEXTUREVIDEOMEMORY;
1470 *pCaps->PrimitiveMiscCaps = D3DPMISCCAPS_CULLCCW |
1471 D3DPMISCCAPS_CULLCW |
1472 D3DPMISCCAPS_COLORWRITEENABLE |
1473 D3DPMISCCAPS_CLIPTLVERTS |
1474 D3DPMISCCAPS_CLIPPLANESCALEDPOINTS |
1476 /*NOT: D3DPMISCCAPS_TSSARGTEMP*/
1478 *pCaps->RasterCaps = D3DPRASTERCAPS_DITHER |
1479 D3DPRASTERCAPS_PAT |
1480 D3DPRASTERCAPS_WFOG |
1481 D3DPRASTERCAPS_ZFOG |
1482 D3DPRASTERCAPS_FOGVERTEX |
1483 D3DPRASTERCAPS_FOGTABLE |
1484 D3DPRASTERCAPS_FOGRANGE;
1486 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC)) {
1487 *pCaps->RasterCaps |= D3DPRASTERCAPS_ANISOTROPY |
1488 D3DPRASTERCAPS_ZBIAS |
1489 D3DPRASTERCAPS_MIPMAPLODBIAS;
1492 D3DPRASTERCAPS_COLORPERSPECTIVE
1493 D3DPRASTERCAPS_STRETCHBLTMULTISAMPLE
1494 D3DPRASTERCAPS_ANTIALIASEDGES
1495 D3DPRASTERCAPS_ZBUFFERLESSHSR
1496 D3DPRASTERCAPS_WBUFFER */
1498 *pCaps->ZCmpCaps = D3DPCMPCAPS_ALWAYS |
1500 D3DPCMPCAPS_GREATER |
1501 D3DPCMPCAPS_GREATEREQUAL |
1503 D3DPCMPCAPS_LESSEQUAL |
1505 D3DPCMPCAPS_NOTEQUAL;
1507 *pCaps->SrcBlendCaps = 0xFFFFFFFF; /*FIXME: Tidy up later */
1508 *pCaps->DestBlendCaps = 0xFFFFFFFF; /*FIXME: Tidy up later */
1509 *pCaps->AlphaCmpCaps = 0xFFFFFFFF; /*FIXME: Tidy up later */
1511 *pCaps->ShadeCaps = D3DPSHADECAPS_SPECULARGOURAUDRGB |
1512 D3DPSHADECAPS_COLORGOURAUDRGB;
1514 *pCaps->TextureCaps = D3DPTEXTURECAPS_ALPHA |
1515 D3DPTEXTURECAPS_ALPHAPALETTE |
1516 D3DPTEXTURECAPS_VOLUMEMAP |
1517 D3DPTEXTURECAPS_MIPMAP |
1518 D3DPTEXTURECAPS_PROJECTED |
1519 D3DPTEXTURECAPS_PERSPECTIVE |
1520 D3DPTEXTURECAPS_VOLUMEMAP_POW2 ;
1521 /* TODO: add support for NON-POW2 if avaialble
1524 if (This->dxVersion >= 8) {
1525 *pCaps->TextureCaps |= D3DPTEXTURECAPS_NONPOW2CONDITIONAL;
1527 } else { /* NONPOW2 isn't accessible by d3d8 yet */
1528 *pCaps->TextureCaps |= D3DPTEXTURECAPS_POW2;
1531 if (GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
1532 *pCaps->TextureCaps |= D3DPTEXTURECAPS_CUBEMAP |
1533 D3DPTEXTURECAPS_MIPCUBEMAP |
1534 D3DPTEXTURECAPS_CUBEMAP_POW2;
1538 *pCaps->TextureFilterCaps = D3DPTFILTERCAPS_MAGFLINEAR |
1539 D3DPTFILTERCAPS_MAGFPOINT |
1540 D3DPTFILTERCAPS_MINFLINEAR |
1541 D3DPTFILTERCAPS_MINFPOINT |
1542 D3DPTFILTERCAPS_MIPFLINEAR |
1543 D3DPTFILTERCAPS_MIPFPOINT;
1545 *pCaps->CubeTextureFilterCaps = 0;
1546 *pCaps->VolumeTextureFilterCaps = 0;
1548 *pCaps->TextureAddressCaps = D3DPTADDRESSCAPS_BORDER |
1549 D3DPTADDRESSCAPS_CLAMP |
1550 D3DPTADDRESSCAPS_WRAP;
1552 if (GL_SUPPORT(ARB_TEXTURE_BORDER_CLAMP)) {
1553 *pCaps->TextureAddressCaps |= D3DPTADDRESSCAPS_BORDER;
1555 if (GL_SUPPORT(ARB_TEXTURE_MIRRORED_REPEAT)) {
1556 *pCaps->TextureAddressCaps |= D3DPTADDRESSCAPS_MIRROR;
1558 if (GL_SUPPORT(ATI_TEXTURE_MIRROR_ONCE)) {
1559 *pCaps->TextureAddressCaps |= D3DPTADDRESSCAPS_MIRRORONCE;
1562 *pCaps->VolumeTextureAddressCaps = 0;
1564 *pCaps->LineCaps = D3DLINECAPS_TEXTURE |
1568 D3DLINECAPS_ALPHACMP
1571 *pCaps->MaxTextureWidth = GL_LIMITS(texture_size);
1572 *pCaps->MaxTextureHeight = GL_LIMITS(texture_size);
1574 *pCaps->MaxVolumeExtent = 0;
1576 *pCaps->MaxTextureRepeat = 32768;
1577 *pCaps->MaxTextureAspectRatio = 32768;
1578 *pCaps->MaxVertexW = 1.0;
1580 *pCaps->GuardBandLeft = 0;
1581 *pCaps->GuardBandTop = 0;
1582 *pCaps->GuardBandRight = 0;
1583 *pCaps->GuardBandBottom = 0;
1585 *pCaps->ExtentsAdjust = 0;
1587 *pCaps->StencilCaps = D3DSTENCILCAPS_DECRSAT |
1588 D3DSTENCILCAPS_INCRSAT |
1589 D3DSTENCILCAPS_INVERT |
1590 D3DSTENCILCAPS_KEEP |
1591 D3DSTENCILCAPS_REPLACE |
1592 D3DSTENCILCAPS_ZERO;
1593 if (GL_SUPPORT(EXT_STENCIL_WRAP)) {
1594 *pCaps->StencilCaps |= D3DSTENCILCAPS_DECR |
1595 D3DSTENCILCAPS_INCR;
1598 *pCaps->FVFCaps = D3DFVFCAPS_PSIZE | 0x0008; /* 8 texture coords */
1600 *pCaps->TextureOpCaps = D3DTEXOPCAPS_ADD |
1601 D3DTEXOPCAPS_ADDSIGNED |
1602 D3DTEXOPCAPS_ADDSIGNED2X |
1603 D3DTEXOPCAPS_MODULATE |
1604 D3DTEXOPCAPS_MODULATE2X |
1605 D3DTEXOPCAPS_MODULATE4X |
1606 D3DTEXOPCAPS_SELECTARG1 |
1607 D3DTEXOPCAPS_SELECTARG2 |
1608 D3DTEXOPCAPS_DISABLE;
1609 #if defined(GL_VERSION_1_3)
1610 *pCaps->TextureOpCaps |= D3DTEXOPCAPS_DOTPRODUCT3 |
1611 D3DTEXOPCAPS_SUBTRACT;
1613 if (GL_SUPPORT(ARB_TEXTURE_ENV_COMBINE) ||
1614 GL_SUPPORT(EXT_TEXTURE_ENV_COMBINE) ||
1615 GL_SUPPORT(NV_TEXTURE_ENV_COMBINE4)) {
1616 *pCaps->TextureOpCaps |= D3DTEXOPCAPS_BLENDDIFFUSEALPHA |
1617 D3DTEXOPCAPS_BLENDTEXTUREALPHA |
1618 D3DTEXOPCAPS_BLENDFACTORALPHA |
1619 D3DTEXOPCAPS_BLENDCURRENTALPHA |
1622 if (GL_SUPPORT(NV_TEXTURE_ENV_COMBINE4)) {
1623 *pCaps->TextureOpCaps |= D3DTEXOPCAPS_ADDSMOOTH |
1624 D3DTEXOPCAPS_MULTIPLYADD |
1625 D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR |
1626 D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA |
1627 D3DTEXOPCAPS_BLENDTEXTUREALPHAPM;
1631 *pCaps->TextureOpCaps |= D3DTEXOPCAPS_BUMPENVMAP;
1633 D3DTEXOPCAPS_BUMPENVMAPLUMINANCE
1634 D3DTEXOPCAPS_PREMODULATE */
1637 *pCaps->MaxTextureBlendStages = GL_LIMITS(textures);
1638 *pCaps->MaxSimultaneousTextures = GL_LIMITS(textures);
1639 *pCaps->MaxUserClipPlanes = GL_LIMITS(clipplanes);
1640 *pCaps->MaxActiveLights = GL_LIMITS(lights);
1644 #if 0 /* TODO: Blends support in drawprim */
1645 *pCaps->MaxVertexBlendMatrices = GL_LIMITS(blends);
1647 *pCaps->MaxVertexBlendMatrices = 0;
1649 *pCaps->MaxVertexBlendMatrixIndex = 1;
1651 *pCaps->MaxAnisotropy = GL_LIMITS(anisotropy);
1652 *pCaps->MaxPointSize = GL_LIMITS(pointsize);
1655 *pCaps->VertexProcessingCaps = D3DVTXPCAPS_DIRECTIONALLIGHTS |
1656 D3DVTXPCAPS_MATERIALSOURCE7 |
1657 D3DVTXPCAPS_POSITIONALLIGHTS |
1658 D3DVTXPCAPS_LOCALVIEWER |
1661 D3DVTXPCAPS_TWEENING */
1663 *pCaps->MaxPrimitiveCount = 0xFFFFFFFF;
1664 *pCaps->MaxVertexIndex = 0xFFFFFFFF;
1665 *pCaps->MaxStreams = MAX_STREAMS;
1666 *pCaps->MaxStreamStride = 1024;
1668 if (((wined3d_settings.vs_mode == VS_HW) && GL_SUPPORT(ARB_VERTEX_PROGRAM)) || (wined3d_settings.vs_mode == VS_SW) || (DeviceType == D3DDEVTYPE_REF)) {
1669 *pCaps->VertexShaderVersion = D3DVS_VERSION(1,1);
1671 if (This->gl_info.gl_vendor == VENDOR_MESA ||
1672 This->gl_info.gl_vendor == VENDOR_WINE) {
1673 *pCaps->MaxVertexShaderConst = 95;
1675 *pCaps->MaxVertexShaderConst = WINED3D_VSHADER_MAX_CONSTANTS;
1678 *pCaps->VertexShaderVersion = 0;
1679 *pCaps->MaxVertexShaderConst = 0;
1682 if ((wined3d_settings.ps_mode == PS_HW) && GL_SUPPORT(ARB_FRAGMENT_PROGRAM) && (DeviceType != D3DDEVTYPE_REF)) {
1683 *pCaps->PixelShaderVersion = D3DPS_VERSION(1,4);
1684 *pCaps->PixelShader1xMaxValue = 1.0;
1686 *pCaps->PixelShaderVersion = 0;
1687 *pCaps->PixelShader1xMaxValue = 0.0;
1689 /* TODO: ARB_FRAGMENT_PROGRAM_100 */
1691 /* ------------------------------------------------
1692 The following fields apply to d3d9 only
1693 ------------------------------------------------ */
1694 if (This->dxVersion > 8) {
1695 GLint max_buffers = 1;
1696 FIXME("Caps support for directx9 is nonexistent at the moment!\n");
1697 *pCaps->DevCaps2 = 0;
1698 /* TODO: D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES */
1699 *pCaps->MaxNpatchTessellationLevel = 0;
1700 *pCaps->MasterAdapterOrdinal = 0;
1701 *pCaps->AdapterOrdinalInGroup = 0;
1702 *pCaps->NumberOfAdaptersInGroup = 1;
1703 *pCaps->DeclTypes = 0;
1704 #if 0 /*FIXME: Simultaneous render targets*/
1705 GL_MAX_DRAW_BUFFERS_ATI 0x00008824
1706 if (GL_SUPPORT(GL_MAX_DRAW_BUFFERS_ATI)) {
1708 glEnable(GL_MAX_DRAW_BUFFERS_ATI);
1709 glGetIntegerv(GL_MAX_DRAW_BUFFERS_ATI, &max_buffers);
1710 glDisable(GL_MAX_DRAW_BUFFERS_ATI);
1714 *pCaps->NumSimultaneousRTs = max_buffers;
1715 *pCaps->StretchRectFilterCaps = 0;
1717 D3DPTFILTERCAPS_MINFPOINT
1718 D3DPTFILTERCAPS_MAGFPOINT
1719 D3DPTFILTERCAPS_MINFLINEAR
1720 D3DPTFILTERCAPS_MAGFLINEAR
1722 *pCaps->VS20Caps.Caps = 0;
1723 *pCaps->PS20Caps.Caps = 0;
1724 *pCaps->VertexTextureFilterCaps = 0;
1725 *pCaps->MaxVShaderInstructionsExecuted = 0;
1726 *pCaps->MaxPShaderInstructionsExecuted = 0;
1727 *pCaps->MaxVertexShader30InstructionSlots = 0;
1728 *pCaps->MaxPixelShader30InstructionSlots = 0;
1735 /* Note due to structure differences between dx8 and dx9 D3DPRESENT_PARAMETERS,
1736 and fields being inserted in the middle, a new structure is used in place */
1737 HRESULT WINAPI IWineD3DImpl_CreateDevice(IWineD3D *iface, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow,
1738 DWORD BehaviourFlags, WINED3DPRESENT_PARAMETERS* pPresentationParameters,
1739 IWineD3DDevice** ppReturnedDeviceInterface, IUnknown *parent,
1740 D3DCB_CREATEADDITIONALSWAPCHAIN D3DCB_CreateAdditionalSwapChain) {
1742 IWineD3DDeviceImpl *object = NULL;
1743 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1744 IWineD3DSwapChainImpl *swapchain;
1746 /* Validate the adapter number */
1747 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
1748 return D3DERR_INVALIDCALL;
1751 /* Create a WineD3DDevice object */
1752 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DDeviceImpl));
1753 *ppReturnedDeviceInterface = (IWineD3DDevice *)object;
1754 TRACE("Created WineD3DDevice object @ %p\n", object);
1755 if (NULL == object) {
1756 return D3DERR_OUTOFVIDEOMEMORY;
1759 /* Set up initial COM information */
1760 object->lpVtbl = &IWineD3DDevice_Vtbl;
1762 object->wineD3D = iface;
1763 IWineD3D_AddRef(object->wineD3D);
1764 object->parent = parent;
1766 /* Set the state up as invalid until the device is fully created */
1767 object->state = D3DERR_DRIVERINTERNALERROR;
1769 TRACE("(%p)->(Adptr:%d, DevType: %x, FocusHwnd: %p, BehFlags: %lx, PresParms: %p, RetDevInt: %p)\n", This, Adapter, DeviceType,
1770 hFocusWindow, BehaviourFlags, pPresentationParameters, ppReturnedDeviceInterface);
1771 TRACE("(%p)->(DepthStencil:(%u,%s), BackBufferFormat:(%u,%s))\n", This,
1772 *(pPresentationParameters->AutoDepthStencilFormat), debug_d3dformat(*(pPresentationParameters->AutoDepthStencilFormat)),
1773 *(pPresentationParameters->BackBufferFormat), debug_d3dformat(*(pPresentationParameters->BackBufferFormat)));
1775 /* Save the creation parameters */
1776 object->createParms.AdapterOrdinal = Adapter;
1777 object->createParms.DeviceType = DeviceType;
1778 object->createParms.hFocusWindow = hFocusWindow;
1779 object->createParms.BehaviorFlags = BehaviourFlags;
1781 /* Initialize other useful values */
1782 object->adapterNo = Adapter;
1783 object->devType = DeviceType;
1785 /* FIXME: Use for dx7 code eventually too! */
1786 /* Deliberately no indentation here, as this if will be removed when dx8 support merged in */
1787 if (This->dxVersion >= 8) {
1788 TRACE("(%p) : Creating stateblock\n", This);
1789 /* Creating the startup stateBlock - Note Special Case: 0 => Don't fill in yet! */
1790 if (D3D_OK != IWineD3DDevice_CreateStateBlock((IWineD3DDevice *)object,
1792 (IWineD3DStateBlock **)&object->stateBlock,
1793 NULL) || NULL == object->stateBlock) { /* Note: No parent needed for initial internal stateblock */
1794 WARN("Failed to create stateblock\n");
1795 goto create_device_error;
1797 TRACE("(%p) : Created stateblock (%p)\n", This, object->stateBlock);
1798 object->updateStateBlock = object->stateBlock;
1799 IWineD3DStateBlock_AddRef((IWineD3DStateBlock*)object->updateStateBlock);
1800 /* Setup surfaces for the backbuffer, frontbuffer and depthstencil buffer */
1802 /* Setup some defaults for creating the implicit swapchain */
1804 IWineD3DImpl_FillGLCaps(&This->gl_info, IWineD3DImpl_GetAdapterDisplay(iface, Adapter));
1807 /* Setup the implicit swapchain */
1808 TRACE("Creating implicit swapchain\n");
1809 if (D3D_OK != D3DCB_CreateAdditionalSwapChain((IUnknown *) object->parent, pPresentationParameters, (IWineD3DSwapChain **)&swapchain) || swapchain == NULL) {
1810 WARN("Failed to create implicit swapchain\n");
1811 goto create_device_error;
1814 object->renderTarget = swapchain->backBuffer;
1815 IWineD3DSurface_AddRef(object->renderTarget);
1816 /* Depth Stencil support */
1817 object->stencilBufferTarget = object->depthStencilBuffer;
1818 if (NULL != object->stencilBufferTarget) {
1819 IWineD3DSurface_AddRef(object->stencilBufferTarget);
1822 /* Set up some starting GL setup */
1825 * Initialize openGL extension related variables
1826 * with Default values
1829 This->isGLInfoValid = IWineD3DImpl_FillGLCaps(&This->gl_info, swapchain->display);
1830 /* Setup all the devices defaults */
1831 IWineD3DStateBlock_InitStartupStateBlock((IWineD3DStateBlock *)object->stateBlock);
1833 IWineD3DImpl_CheckGraphicsMemory();
1837 { /* Set a default viewport */
1841 vp.Width = *(pPresentationParameters->BackBufferWidth);
1842 vp.Height = *(pPresentationParameters->BackBufferHeight);
1845 IWineD3DDevice_SetViewport((IWineD3DDevice *)object, &vp);
1849 /* Initialize the current view state */
1850 object->modelview_valid = 1;
1851 object->proj_valid = 0;
1852 object->view_ident = 1;
1853 object->last_was_rhw = 0;
1854 glGetIntegerv(GL_MAX_LIGHTS, &object->maxConcurrentLights);
1855 TRACE("(%p,%d) All defaults now set up, leaving CreateDevice with %p\n", This, Adapter, object);
1857 /* Clear the screen */
1858 IWineD3DDevice_Clear((IWineD3DDevice *) object, 0, NULL, D3DCLEAR_STENCIL|D3DCLEAR_ZBUFFER|D3DCLEAR_TARGET, 0x00, 1.0, 0);
1860 } else { /* End of FIXME: remove when dx8 merged in */
1862 FIXME("(%p) Incomplete stub for d3d8\n", This);
1866 /* set the state of the device to valid */
1867 object->state = D3D_OK;
1870 create_device_error:
1872 /* Set the device state to error */
1873 object->state = D3DERR_DRIVERINTERNALERROR;
1875 if (object->updateStateBlock != NULL) {
1876 IWineD3DStateBlock_Release((IWineD3DStateBlock *)object->updateStateBlock);
1877 object->updateStateBlock = NULL;
1879 if (object->stateBlock != NULL) {
1880 IWineD3DStateBlock_Release((IWineD3DStateBlock *)object->stateBlock);
1881 object->stateBlock = NULL;
1883 if (object->renderTarget != NULL) {
1884 IWineD3DSurface_Release(object->renderTarget);
1885 object->renderTarget = NULL;
1887 if (object->stencilBufferTarget != NULL) {
1888 IWineD3DSurface_Release(object->stencilBufferTarget);
1889 object->stencilBufferTarget = NULL;
1891 if (object->stencilBufferTarget != NULL) {
1892 IWineD3DSurface_Release(object->stencilBufferTarget);
1893 object->stencilBufferTarget = NULL;
1895 if (swapchain != NULL) {
1896 IWineD3DSwapChain_Release((IWineD3DSwapChain *)swapchain);
1899 HeapFree(GetProcessHeap(), 0, object);
1900 *ppReturnedDeviceInterface = NULL;
1901 return D3DERR_INVALIDCALL;
1905 HRESULT WINAPI IWineD3DImpl_GetParent(IWineD3D *iface, IUnknown **pParent) {
1906 IWineD3DImpl *This = (IWineD3DImpl *)iface;
1907 IUnknown_AddRef(This->parent);
1908 *pParent = This->parent;
1912 /**********************************************************
1913 * IWineD3D VTbl follows
1914 **********************************************************/
1916 const IWineD3DVtbl IWineD3D_Vtbl =
1919 IWineD3DImpl_QueryInterface,
1920 IWineD3DImpl_AddRef,
1921 IWineD3DImpl_Release,
1923 IWineD3DImpl_GetParent,
1924 IWineD3DImpl_GetAdapterCount,
1925 IWineD3DImpl_RegisterSoftwareDevice,
1926 IWineD3DImpl_GetAdapterMonitor,
1927 IWineD3DImpl_GetAdapterModeCount,
1928 IWineD3DImpl_EnumAdapterModes,
1929 IWineD3DImpl_GetAdapterDisplayMode,
1930 IWineD3DImpl_GetAdapterIdentifier,
1931 IWineD3DImpl_CheckDeviceMultiSampleType,
1932 IWineD3DImpl_CheckDepthStencilMatch,
1933 IWineD3DImpl_CheckDeviceType,
1934 IWineD3DImpl_CheckDeviceFormat,
1935 IWineD3DImpl_CheckDeviceFormatConversion,
1936 IWineD3DImpl_GetDeviceCaps,
1937 IWineD3DImpl_CreateDevice