kernel32: Add missing function entry.
[wine] / dlls / wined3d / directx.c
1 /*
2  * Copyright 2002-2004 Jason Edmeades
3  * Copyright 2003-2004 Raphael Junqueira
4  * Copyright 2004 Christian Costa
5  * Copyright 2005 Oliver Stieber
6  * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
7  * Copyright 2009-2011 Henri Verbeet for CodeWeavers
8  *
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.
13  *
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.
18  *
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23
24 #include "config.h"
25 #include <stdio.h>
26 #include "wined3d_private.h"
27
28 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
29 WINE_DECLARE_DEBUG_CHANNEL(d3d_caps);
30
31 #define WINE_DEFAULT_VIDMEM (64 * 1024 * 1024)
32
33 /* The driver names reflect the lowest GPU supported
34  * by a certain driver, so DRIVER_AMD_R300 supports
35  * R3xx, R4xx and R5xx GPUs. */
36 enum wined3d_display_driver
37 {
38     DRIVER_AMD_RAGE_128PRO,
39     DRIVER_AMD_R100,
40     DRIVER_AMD_R300,
41     DRIVER_AMD_R600,
42     DRIVER_INTEL_GMA800,
43     DRIVER_INTEL_GMA900,
44     DRIVER_INTEL_GMA950,
45     DRIVER_INTEL_GMA3000,
46     DRIVER_NVIDIA_TNT,
47     DRIVER_NVIDIA_GEFORCE2MX,
48     DRIVER_NVIDIA_GEFORCEFX,
49     DRIVER_NVIDIA_GEFORCE6,
50     DRIVER_UNKNOWN
51 };
52
53 enum wined3d_driver_model
54 {
55     DRIVER_MODEL_WIN9X,
56     DRIVER_MODEL_NT40,
57     DRIVER_MODEL_NT5X,
58     DRIVER_MODEL_NT6X
59 };
60
61 enum wined3d_gl_vendor
62 {
63     GL_VENDOR_UNKNOWN,
64     GL_VENDOR_APPLE,
65     GL_VENDOR_FGLRX,
66     GL_VENDOR_INTEL,
67     GL_VENDOR_MESA,
68     GL_VENDOR_NVIDIA,
69 };
70
71 /* The d3d device ID */
72 static const GUID IID_D3DDEVICE_D3DUID = { 0xaeb2cdd4, 0x6e41, 0x43ea, { 0x94,0x1c,0x83,0x61,0xcc,0x76,0x07,0x81 } };
73
74 /* Extension detection */
75 static const struct
76 {
77     const char *extension_string;
78     enum wined3d_gl_extension extension;
79     DWORD version;
80 }
81 EXTENSION_MAP[] =
82 {
83     /* APPLE */
84     {"GL_APPLE_client_storage",             APPLE_CLIENT_STORAGE,           0                           },
85     {"GL_APPLE_fence",                      APPLE_FENCE,                    0                           },
86     {"GL_APPLE_float_pixels",               APPLE_FLOAT_PIXELS,             0                           },
87     {"GL_APPLE_flush_buffer_range",         APPLE_FLUSH_BUFFER_RANGE,       0                           },
88     {"GL_APPLE_flush_render",               APPLE_FLUSH_RENDER,             0                           },
89     {"GL_APPLE_ycbcr_422",                  APPLE_YCBCR_422,                0                           },
90
91     /* ARB */
92     {"GL_ARB_color_buffer_float",           ARB_COLOR_BUFFER_FLOAT,         0                           },
93     {"GL_ARB_depth_buffer_float",           ARB_DEPTH_BUFFER_FLOAT,         0                           },
94     {"GL_ARB_depth_clamp",                  ARB_DEPTH_CLAMP,                0                           },
95     {"GL_ARB_depth_texture",                ARB_DEPTH_TEXTURE,              0                           },
96     {"GL_ARB_draw_buffers",                 ARB_DRAW_BUFFERS,               0                           },
97     {"GL_ARB_draw_elements_base_vertex",    ARB_DRAW_ELEMENTS_BASE_VERTEX,  0                           },
98     {"GL_ARB_fragment_program",             ARB_FRAGMENT_PROGRAM,           0                           },
99     {"GL_ARB_fragment_shader",              ARB_FRAGMENT_SHADER,            0                           },
100     {"GL_ARB_framebuffer_object",           ARB_FRAMEBUFFER_OBJECT,         0                           },
101     {"GL_ARB_geometry_shader4",             ARB_GEOMETRY_SHADER4,           0                           },
102     {"GL_ARB_half_float_pixel",             ARB_HALF_FLOAT_PIXEL,           0                           },
103     {"GL_ARB_half_float_vertex",            ARB_HALF_FLOAT_VERTEX,          0                           },
104     {"GL_ARB_map_buffer_alignment",         ARB_MAP_BUFFER_ALIGNMENT,       0                           },
105     {"GL_ARB_map_buffer_range",             ARB_MAP_BUFFER_RANGE,           0                           },
106     {"GL_ARB_multisample",                  ARB_MULTISAMPLE,                0                           }, /* needs GLX_ARB_MULTISAMPLE as well */
107     {"GL_ARB_multitexture",                 ARB_MULTITEXTURE,               0                           },
108     {"GL_ARB_occlusion_query",              ARB_OCCLUSION_QUERY,            0                           },
109     {"GL_ARB_pixel_buffer_object",          ARB_PIXEL_BUFFER_OBJECT,        0                           },
110     {"GL_ARB_point_parameters",             ARB_POINT_PARAMETERS,           0                           },
111     {"GL_ARB_point_sprite",                 ARB_POINT_SPRITE,               0                           },
112     {"GL_ARB_provoking_vertex",             ARB_PROVOKING_VERTEX,           0                           },
113     {"GL_ARB_shader_objects",               ARB_SHADER_OBJECTS,             0                           },
114     {"GL_ARB_shader_texture_lod",           ARB_SHADER_TEXTURE_LOD,         0                           },
115     {"GL_ARB_shading_language_100",         ARB_SHADING_LANGUAGE_100,       0                           },
116     {"GL_ARB_shadow",                       ARB_SHADOW,                     0                           },
117     {"GL_ARB_sync",                         ARB_SYNC,                       0                           },
118     {"GL_ARB_texture_border_clamp",         ARB_TEXTURE_BORDER_CLAMP,       0                           },
119     {"GL_ARB_texture_compression",          ARB_TEXTURE_COMPRESSION,        0                           },
120     {"GL_ARB_texture_compression_rgtc",     ARB_TEXTURE_COMPRESSION_RGTC,   0                           },
121     {"GL_ARB_texture_cube_map",             ARB_TEXTURE_CUBE_MAP,           0                           },
122     {"GL_ARB_texture_env_add",              ARB_TEXTURE_ENV_ADD,            0                           },
123     {"GL_ARB_texture_env_combine",          ARB_TEXTURE_ENV_COMBINE,        0                           },
124     {"GL_ARB_texture_env_dot3",             ARB_TEXTURE_ENV_DOT3,           0                           },
125     {"GL_ARB_texture_float",                ARB_TEXTURE_FLOAT,              0                           },
126     {"GL_ARB_texture_mirrored_repeat",      ARB_TEXTURE_MIRRORED_REPEAT,    0                           },
127     {"GL_ARB_texture_non_power_of_two",     ARB_TEXTURE_NON_POWER_OF_TWO,   MAKEDWORD_VERSION(2, 0)     },
128     {"GL_ARB_texture_rectangle",            ARB_TEXTURE_RECTANGLE,          0                           },
129     {"GL_ARB_texture_rg",                   ARB_TEXTURE_RG,                 0                           },
130     {"GL_ARB_vertex_array_bgra",            ARB_VERTEX_ARRAY_BGRA,          0                           },
131     {"GL_ARB_vertex_blend",                 ARB_VERTEX_BLEND,               0                           },
132     {"GL_ARB_vertex_buffer_object",         ARB_VERTEX_BUFFER_OBJECT,       0                           },
133     {"GL_ARB_vertex_program",               ARB_VERTEX_PROGRAM,             0                           },
134     {"GL_ARB_vertex_shader",                ARB_VERTEX_SHADER,              0                           },
135
136     /* ATI */
137     {"GL_ATI_fragment_shader",              ATI_FRAGMENT_SHADER,            0                           },
138     {"GL_ATI_separate_stencil",             ATI_SEPARATE_STENCIL,           0                           },
139     {"GL_ATI_texture_compression_3dc",      ATI_TEXTURE_COMPRESSION_3DC,    0                           },
140     {"GL_ATI_texture_env_combine3",         ATI_TEXTURE_ENV_COMBINE3,       0                           },
141     {"GL_ATI_texture_mirror_once",          ATI_TEXTURE_MIRROR_ONCE,        0                           },
142
143     /* EXT */
144     {"GL_EXT_blend_color",                  EXT_BLEND_COLOR,                0                           },
145     {"GL_EXT_blend_equation_separate",      EXT_BLEND_EQUATION_SEPARATE,    0                           },
146     {"GL_EXT_blend_func_separate",          EXT_BLEND_FUNC_SEPARATE,        0                           },
147     {"GL_EXT_blend_minmax",                 EXT_BLEND_MINMAX,               0                           },
148     {"GL_EXT_blend_subtract",               EXT_BLEND_SUBTRACT,             0                           },
149     {"GL_EXT_depth_bounds_test",            EXT_DEPTH_BOUNDS_TEST,          0                           },
150     {"GL_EXT_draw_buffers2",                EXT_DRAW_BUFFERS2,              0                           },
151     {"GL_EXT_fog_coord",                    EXT_FOG_COORD,                  0                           },
152     {"GL_EXT_framebuffer_blit",             EXT_FRAMEBUFFER_BLIT,           0                           },
153     {"GL_EXT_framebuffer_multisample",      EXT_FRAMEBUFFER_MULTISAMPLE,    0                           },
154     {"GL_EXT_framebuffer_object",           EXT_FRAMEBUFFER_OBJECT,         0                           },
155     {"GL_EXT_gpu_program_parameters",       EXT_GPU_PROGRAM_PARAMETERS,     0                           },
156     {"GL_EXT_gpu_shader4",                  EXT_GPU_SHADER4,                0                           },
157     {"GL_EXT_packed_depth_stencil",         EXT_PACKED_DEPTH_STENCIL,       0                           },
158     {"GL_EXT_paletted_texture",             EXT_PALETTED_TEXTURE,           0                           },
159     {"GL_EXT_point_parameters",             EXT_POINT_PARAMETERS,           0                           },
160     {"GL_EXT_provoking_vertex",             EXT_PROVOKING_VERTEX,           0                           },
161     {"GL_EXT_secondary_color",              EXT_SECONDARY_COLOR,            0                           },
162     {"GL_EXT_stencil_two_side",             EXT_STENCIL_TWO_SIDE,           0                           },
163     {"GL_EXT_stencil_wrap",                 EXT_STENCIL_WRAP,               0                           },
164     {"GL_EXT_texture3D",                    EXT_TEXTURE3D,                  MAKEDWORD_VERSION(1, 2)     },
165     {"GL_EXT_texture_compression_rgtc",     EXT_TEXTURE_COMPRESSION_RGTC,   0                           },
166     {"GL_EXT_texture_compression_s3tc",     EXT_TEXTURE_COMPRESSION_S3TC,   0                           },
167     {"GL_EXT_texture_env_add",              EXT_TEXTURE_ENV_ADD,            0                           },
168     {"GL_EXT_texture_env_combine",          EXT_TEXTURE_ENV_COMBINE,        0                           },
169     {"GL_EXT_texture_env_dot3",             EXT_TEXTURE_ENV_DOT3,           0                           },
170     {"GL_EXT_texture_filter_anisotropic",   EXT_TEXTURE_FILTER_ANISOTROPIC, 0                           },
171     {"GL_EXT_texture_lod_bias",             EXT_TEXTURE_LOD_BIAS,           0                           },
172     {"GL_EXT_texture_sRGB",                 EXT_TEXTURE_SRGB,               0                           },
173     {"GL_EXT_texture_sRGB_decode",          EXT_TEXTURE_SRGB_DECODE,        0                           },
174     {"GL_EXT_vertex_array_bgra",            EXT_VERTEX_ARRAY_BGRA,          0                           },
175
176     /* NV */
177     {"GL_NV_depth_clamp",                   NV_DEPTH_CLAMP,                 0                           },
178     {"GL_NV_fence",                         NV_FENCE,                       0                           },
179     {"GL_NV_fog_distance",                  NV_FOG_DISTANCE,                0                           },
180     {"GL_NV_fragment_program",              NV_FRAGMENT_PROGRAM,            0                           },
181     {"GL_NV_fragment_program2",             NV_FRAGMENT_PROGRAM2,           0                           },
182     {"GL_NV_fragment_program_option",       NV_FRAGMENT_PROGRAM_OPTION,     0                           },
183     {"GL_NV_half_float",                    NV_HALF_FLOAT,                  0                           },
184     {"GL_NV_light_max_exponent",            NV_LIGHT_MAX_EXPONENT,          0                           },
185     {"GL_NV_point_sprite",                  NV_POINT_SPRITE,                0                           },
186     {"GL_NV_register_combiners",            NV_REGISTER_COMBINERS,          0                           },
187     {"GL_NV_register_combiners2",           NV_REGISTER_COMBINERS2,         0                           },
188     {"GL_NV_texgen_reflection",             NV_TEXGEN_REFLECTION,           0                           },
189     {"GL_NV_texture_env_combine4",          NV_TEXTURE_ENV_COMBINE4,        0                           },
190     {"GL_NV_texture_shader",                NV_TEXTURE_SHADER,              0                           },
191     {"GL_NV_texture_shader2",               NV_TEXTURE_SHADER2,             0                           },
192     {"GL_NV_vertex_program",                NV_VERTEX_PROGRAM,              0                           },
193     {"GL_NV_vertex_program1_1",             NV_VERTEX_PROGRAM1_1,           0                           },
194     {"GL_NV_vertex_program2",               NV_VERTEX_PROGRAM2,             0                           },
195     {"GL_NV_vertex_program2_option",        NV_VERTEX_PROGRAM2_OPTION,      0                           },
196     {"GL_NV_vertex_program3",               NV_VERTEX_PROGRAM3,             0                           },
197
198     /* SGI */
199     {"GL_SGIS_generate_mipmap",             SGIS_GENERATE_MIPMAP,           0                           },
200 };
201
202 /**********************************************************
203  * Utility functions follow
204  **********************************************************/
205
206 const struct min_lookup minMipLookup[] =
207 {
208     /* NONE         POINT                       LINEAR */
209     {{GL_NEAREST,   GL_NEAREST,                 GL_NEAREST}},               /* NONE */
210     {{GL_NEAREST,   GL_NEAREST_MIPMAP_NEAREST,  GL_NEAREST_MIPMAP_LINEAR}}, /* POINT*/
211     {{GL_LINEAR,    GL_LINEAR_MIPMAP_NEAREST,   GL_LINEAR_MIPMAP_LINEAR}},  /* LINEAR */
212 };
213
214 const struct min_lookup minMipLookup_noFilter[] =
215 {
216     /* NONE         POINT                       LINEAR */
217     {{GL_NEAREST,   GL_NEAREST,                 GL_NEAREST}},               /* NONE */
218     {{GL_NEAREST,   GL_NEAREST,                 GL_NEAREST}},               /* POINT */
219     {{GL_NEAREST,   GL_NEAREST,                 GL_NEAREST}},               /* LINEAR */
220 };
221
222 const struct min_lookup minMipLookup_noMip[] =
223 {
224     /* NONE         POINT                       LINEAR */
225     {{GL_NEAREST,   GL_NEAREST,                 GL_NEAREST}},               /* NONE */
226     {{GL_NEAREST,   GL_NEAREST,                 GL_NEAREST}},               /* POINT */
227     {{GL_LINEAR,    GL_LINEAR,                  GL_LINEAR }},               /* LINEAR */
228 };
229
230 const GLenum magLookup[] =
231 {
232     /* NONE     POINT       LINEAR */
233     GL_NEAREST, GL_NEAREST, GL_LINEAR,
234 };
235
236 const GLenum magLookup_noFilter[] =
237 {
238     /* NONE     POINT       LINEAR */
239     GL_NEAREST, GL_NEAREST, GL_NEAREST,
240 };
241
242 /* drawStridedSlow attributes */
243 glAttribFunc position_funcs[WINED3D_FFP_EMIT_COUNT];
244 glAttribFunc diffuse_funcs[WINED3D_FFP_EMIT_COUNT];
245 glAttribFunc specular_func_3ubv;
246 glAttribFunc specular_funcs[WINED3D_FFP_EMIT_COUNT];
247 glAttribFunc normal_funcs[WINED3D_FFP_EMIT_COUNT];
248 glMultiTexCoordFunc multi_texcoord_funcs[WINED3D_FFP_EMIT_COUNT];
249
250 /**
251  * Note: GL seems to trap if GetDeviceCaps is called before any HWND's created,
252  * i.e., there is no GL Context - Get a default rendering context to enable the
253  * function query some info from GL.
254  */
255
256 struct wined3d_fake_gl_ctx
257 {
258     HDC dc;
259     HWND wnd;
260     HGLRC gl_ctx;
261     HDC restore_dc;
262     HGLRC restore_gl_ctx;
263 };
264
265 static void WineD3D_ReleaseFakeGLContext(const struct wined3d_fake_gl_ctx *ctx)
266 {
267     TRACE_(d3d_caps)("Destroying fake GL context.\n");
268
269     if (!pwglMakeCurrent(NULL, NULL))
270     {
271         ERR_(d3d_caps)("Failed to disable fake GL context.\n");
272     }
273
274     if (!pwglDeleteContext(ctx->gl_ctx))
275     {
276         DWORD err = GetLastError();
277         ERR("wglDeleteContext(%p) failed, last error %#x.\n", ctx->gl_ctx, err);
278     }
279
280     ReleaseDC(ctx->wnd, ctx->dc);
281     DestroyWindow(ctx->wnd);
282
283     if (ctx->restore_gl_ctx && !pwglMakeCurrent(ctx->restore_dc, ctx->restore_gl_ctx))
284     {
285         ERR_(d3d_caps)("Failed to restore previous GL context.\n");
286     }
287 }
288
289 /* Do not call while under the GL lock. */
290 static BOOL WineD3D_CreateFakeGLContext(struct wined3d_fake_gl_ctx *ctx)
291 {
292     PIXELFORMATDESCRIPTOR pfd;
293     int iPixelFormat;
294
295     TRACE("getting context...\n");
296
297     ctx->restore_dc = pwglGetCurrentDC();
298     ctx->restore_gl_ctx = pwglGetCurrentContext();
299
300     /* We need a fake window as a hdc retrieved using GetDC(0) can't be used for much GL purposes. */
301     ctx->wnd = CreateWindowA(WINED3D_OPENGL_WINDOW_CLASS_NAME, "WineD3D fake window",
302             WS_OVERLAPPEDWINDOW, 10, 10, 10, 10, NULL, NULL, NULL, NULL);
303     if (!ctx->wnd)
304     {
305         ERR_(d3d_caps)("Failed to create a window.\n");
306         goto fail;
307     }
308
309     ctx->dc = GetDC(ctx->wnd);
310     if (!ctx->dc)
311     {
312         ERR_(d3d_caps)("Failed to get a DC.\n");
313         goto fail;
314     }
315
316     /* PixelFormat selection */
317     ZeroMemory(&pfd, sizeof(pfd));
318     pfd.nSize = sizeof(pfd);
319     pfd.nVersion = 1;
320     pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW; /* PFD_GENERIC_ACCELERATED */
321     pfd.iPixelType = PFD_TYPE_RGBA;
322     pfd.cColorBits = 32;
323     pfd.iLayerType = PFD_MAIN_PLANE;
324
325     iPixelFormat = ChoosePixelFormat(ctx->dc, &pfd);
326     if (!iPixelFormat)
327     {
328         /* If this happens something is very wrong as ChoosePixelFormat barely fails. */
329         ERR_(d3d_caps)("Can't find a suitable iPixelFormat.\n");
330         goto fail;
331     }
332     DescribePixelFormat(ctx->dc, iPixelFormat, sizeof(pfd), &pfd);
333     SetPixelFormat(ctx->dc, iPixelFormat, &pfd);
334
335     /* Create a GL context. */
336     ctx->gl_ctx = pwglCreateContext(ctx->dc);
337     if (!ctx->gl_ctx)
338     {
339         WARN_(d3d_caps)("Error creating default context for capabilities initialization.\n");
340         goto fail;
341     }
342
343     /* Make it the current GL context. */
344     if (!pwglMakeCurrent(ctx->dc, ctx->gl_ctx))
345     {
346         ERR_(d3d_caps)("Failed to make fake GL context current.\n");
347         goto fail;
348     }
349
350     return TRUE;
351
352 fail:
353     if (ctx->gl_ctx) pwglDeleteContext(ctx->gl_ctx);
354     ctx->gl_ctx = NULL;
355     if (ctx->dc) ReleaseDC(ctx->wnd, ctx->dc);
356     ctx->dc = NULL;
357     if (ctx->wnd) DestroyWindow(ctx->wnd);
358     ctx->wnd = NULL;
359     if (ctx->restore_gl_ctx && !pwglMakeCurrent(ctx->restore_dc, ctx->restore_gl_ctx))
360     {
361         ERR_(d3d_caps)("Failed to restore previous GL context.\n");
362     }
363
364     return FALSE;
365 }
366
367 /* Adjust the amount of used texture memory */
368 unsigned int adapter_adjust_memory(struct wined3d_adapter *adapter, int amount)
369 {
370     adapter->UsedTextureRam += amount;
371     TRACE("Adjusted adapter memory by %d to %d.\n", amount, adapter->UsedTextureRam);
372     return adapter->UsedTextureRam;
373 }
374
375 static void wined3d_adapter_cleanup(struct wined3d_adapter *adapter)
376 {
377     HeapFree(GetProcessHeap(), 0, adapter->gl_info.formats);
378     HeapFree(GetProcessHeap(), 0, adapter->cfgs);
379 }
380
381 ULONG CDECL wined3d_incref(struct wined3d *wined3d)
382 {
383     ULONG refcount = InterlockedIncrement(&wined3d->ref);
384
385     TRACE("%p increasing refcount to %u.\n", wined3d, refcount);
386
387     return refcount;
388 }
389
390 ULONG CDECL wined3d_decref(struct wined3d *wined3d)
391 {
392     ULONG refcount = InterlockedDecrement(&wined3d->ref);
393
394     TRACE("%p decreasing refcount to %u.\n", wined3d, refcount);
395
396     if (!refcount)
397     {
398         unsigned int i;
399
400         for (i = 0; i < wined3d->adapter_count; ++i)
401         {
402             wined3d_adapter_cleanup(&wined3d->adapters[i]);
403         }
404         HeapFree(GetProcessHeap(), 0, wined3d);
405     }
406
407     return refcount;
408 }
409
410 /* GL locking is done by the caller */
411 static inline BOOL test_arb_vs_offset_limit(const struct wined3d_gl_info *gl_info)
412 {
413     GLuint prog;
414     BOOL ret = FALSE;
415     const char *testcode =
416         "!!ARBvp1.0\n"
417         "PARAM C[66] = { program.env[0..65] };\n"
418         "ADDRESS A0;"
419         "PARAM zero = {0.0, 0.0, 0.0, 0.0};\n"
420         "ARL A0.x, zero.x;\n"
421         "MOV result.position, C[A0.x + 65];\n"
422         "END\n";
423
424     while(glGetError());
425     GL_EXTCALL(glGenProgramsARB(1, &prog));
426     if(!prog) {
427         ERR("Failed to create an ARB offset limit test program\n");
428     }
429     GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prog));
430     GL_EXTCALL(glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
431                                   strlen(testcode), testcode));
432     if (glGetError())
433     {
434         TRACE("OpenGL implementation does not allow indirect addressing offsets > 63\n");
435         TRACE("error: %s\n", debugstr_a((const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
436         ret = TRUE;
437     } else TRACE("OpenGL implementation allows offsets > 63\n");
438
439     GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, 0));
440     GL_EXTCALL(glDeleteProgramsARB(1, &prog));
441     checkGLcall("ARB vp offset limit test cleanup");
442
443     return ret;
444 }
445
446 static DWORD ver_for_ext(enum wined3d_gl_extension ext)
447 {
448     unsigned int i;
449     for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i) {
450         if(EXTENSION_MAP[i].extension == ext) {
451             return EXTENSION_MAP[i].version;
452         }
453     }
454     return 0;
455 }
456
457 static BOOL match_amd_r300_to_500(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
458         enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
459 {
460     if (card_vendor != HW_VENDOR_AMD) return FALSE;
461     if (device == CARD_AMD_RADEON_9500) return TRUE;
462     if (device == CARD_AMD_RADEON_X700) return TRUE;
463     if (device == CARD_AMD_RADEON_X1600) return TRUE;
464     return FALSE;
465 }
466
467 static BOOL match_geforce5(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
468         enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
469 {
470     if (card_vendor == HW_VENDOR_NVIDIA)
471     {
472         if (device == CARD_NVIDIA_GEFORCEFX_5200 ||
473             device == CARD_NVIDIA_GEFORCEFX_5600 ||
474             device == CARD_NVIDIA_GEFORCEFX_5800)
475         {
476             return TRUE;
477         }
478     }
479     return FALSE;
480 }
481
482 static BOOL match_apple(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
483         enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
484 {
485     /* MacOS has various specialities in the extensions it advertises. Some have to be loaded from
486      * the opengl 1.2+ core, while other extensions are advertised, but software emulated. So try to
487      * detect the Apple OpenGL implementation to apply some extension fixups afterwards.
488      *
489      * Detecting this isn't really easy. The vendor string doesn't mention Apple. Compile-time checks
490      * aren't sufficient either because a Linux binary may display on a macos X server via remote X11.
491      * So try to detect the GL implementation by looking at certain Apple extensions. Some extensions
492      * like client storage might be supported on other implementations too, but GL_APPLE_flush_render
493      * is specific to the Mac OS X window management, and GL_APPLE_ycbcr_422 is QuickTime specific. So
494      * the chance that other implementations support them is rather small since Win32 QuickTime uses
495      * DirectDraw, not OpenGL.
496      *
497      * This test has been moved into wined3d_guess_gl_vendor()
498      */
499     if (gl_vendor == GL_VENDOR_APPLE)
500     {
501         return TRUE;
502     }
503     return FALSE;
504 }
505
506 /* Context activation is done by the caller. */
507 static void test_pbo_functionality(struct wined3d_gl_info *gl_info)
508 {
509     /* Some OpenGL implementations, namely Apple's Geforce 8 driver, advertises PBOs,
510      * but glTexSubImage from a PBO fails miserably, with the first line repeated over
511      * all the texture. This function detects this bug by its symptom and disables PBOs
512      * if the test fails.
513      *
514      * The test uploads a 4x4 texture via the PBO in the "native" format GL_BGRA,
515      * GL_UNSIGNED_INT_8_8_8_8_REV. This format triggers the bug, and it is what we use
516      * for D3DFMT_A8R8G8B8. Then the texture is read back without any PBO and the data
517      * read back is compared to the original. If they are equal PBOs are assumed to work,
518      * otherwise the PBO extension is disabled. */
519     GLuint texture, pbo;
520     static const unsigned int pattern[] =
521     {
522         0x00000000, 0x000000ff, 0x0000ff00, 0x40ff0000,
523         0x80ffffff, 0x40ffff00, 0x00ff00ff, 0x0000ffff,
524         0x00ffff00, 0x00ff00ff, 0x0000ffff, 0x000000ff,
525         0x80ff00ff, 0x0000ffff, 0x00ff00ff, 0x40ff00ff
526     };
527     unsigned int check[sizeof(pattern) / sizeof(pattern[0])];
528
529     /* No PBO -> No point in testing them. */
530     if (!gl_info->supported[ARB_PIXEL_BUFFER_OBJECT]) return;
531
532     ENTER_GL();
533
534     while (glGetError());
535     glGenTextures(1, &texture);
536     glBindTexture(GL_TEXTURE_2D, texture);
537
538     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
539     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
540     checkGLcall("Specifying the PBO test texture");
541
542     GL_EXTCALL(glGenBuffersARB(1, &pbo));
543     GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo));
544     GL_EXTCALL(glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, sizeof(pattern), pattern, GL_STREAM_DRAW_ARB));
545     checkGLcall("Specifying the PBO test pbo");
546
547     glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
548     checkGLcall("Loading the PBO test texture");
549
550     GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
551     LEAVE_GL();
552
553     wglFinish(); /* just to be sure */
554
555     memset(check, 0, sizeof(check));
556     ENTER_GL();
557     glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, check);
558     checkGLcall("Reading back the PBO test texture");
559
560     glDeleteTextures(1, &texture);
561     GL_EXTCALL(glDeleteBuffersARB(1, &pbo));
562     checkGLcall("PBO test cleanup");
563
564     LEAVE_GL();
565
566     if (memcmp(check, pattern, sizeof(check)))
567     {
568         WARN_(d3d_caps)("PBO test failed, read back data doesn't match original.\n");
569         WARN_(d3d_caps)("Disabling PBOs. This may result in slower performance.\n");
570         gl_info->supported[ARB_PIXEL_BUFFER_OBJECT] = FALSE;
571     }
572     else
573     {
574         TRACE_(d3d_caps)("PBO test successful.\n");
575     }
576 }
577
578 static BOOL match_apple_intel(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
579         enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
580 {
581     return (card_vendor == HW_VENDOR_INTEL) && (gl_vendor == GL_VENDOR_APPLE);
582 }
583
584 static BOOL match_apple_nonr500ati(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
585         enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
586 {
587     if (gl_vendor != GL_VENDOR_APPLE) return FALSE;
588     if (card_vendor != HW_VENDOR_AMD) return FALSE;
589     if (device == CARD_AMD_RADEON_X1600) return FALSE;
590     return TRUE;
591 }
592
593 static BOOL match_dx10_capable(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
594         enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
595 {
596     /* DX9 cards support 40 single float varyings in hardware, most drivers report 32. ATI misreports
597      * 44 varyings. So assume that if we have more than 44 varyings we have a dx10 card.
598      * This detection is for the gl_ClipPos varying quirk. If a d3d9 card really supports more than 44
599      * varyings and we subtract one in dx9 shaders its not going to hurt us because the dx9 limit is
600      * hardcoded
601      *
602      * dx10 cards usually have 64 varyings */
603     return gl_info->limits.glsl_varyings > 44;
604 }
605
606 static BOOL match_not_dx10_capable(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
607         enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
608 {
609     return !match_dx10_capable(gl_info, gl_renderer, gl_vendor, card_vendor, device);
610 }
611
612 /* A GL context is provided by the caller */
613 static BOOL match_allows_spec_alpha(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
614         enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
615 {
616     GLenum error;
617     DWORD data[16];
618
619     if (!gl_info->supported[EXT_SECONDARY_COLOR]) return FALSE;
620
621     ENTER_GL();
622     while(glGetError());
623     GL_EXTCALL(glSecondaryColorPointerEXT)(4, GL_UNSIGNED_BYTE, 4, data);
624     error = glGetError();
625     LEAVE_GL();
626
627     if(error == GL_NO_ERROR)
628     {
629         TRACE("GL Implementation accepts 4 component specular color pointers\n");
630         return TRUE;
631     }
632     else
633     {
634         TRACE("GL implementation does not accept 4 component specular colors, error %s\n",
635               debug_glerror(error));
636         return FALSE;
637     }
638 }
639
640 /* A GL context is provided by the caller */
641 static BOOL match_broken_nv_clip(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
642         enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
643 {
644     GLuint prog;
645     BOOL ret = FALSE;
646     GLint pos;
647     const char *testcode =
648         "!!ARBvp1.0\n"
649         "OPTION NV_vertex_program2;\n"
650         "MOV result.clip[0], 0.0;\n"
651         "MOV result.position, 0.0;\n"
652         "END\n";
653
654     if (!gl_info->supported[NV_VERTEX_PROGRAM2_OPTION]) return FALSE;
655
656     ENTER_GL();
657     while(glGetError());
658
659     GL_EXTCALL(glGenProgramsARB(1, &prog));
660     if(!prog)
661     {
662         ERR("Failed to create the NVvp clip test program\n");
663         LEAVE_GL();
664         return FALSE;
665     }
666     GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prog));
667     GL_EXTCALL(glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
668                                   strlen(testcode), testcode));
669     glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
670     if(pos != -1)
671     {
672         WARN("GL_NV_vertex_program2_option result.clip[] test failed\n");
673         TRACE("error: %s\n", debugstr_a((const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
674         ret = TRUE;
675         while(glGetError());
676     }
677     else TRACE("GL_NV_vertex_program2_option result.clip[] test passed\n");
678
679     GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, 0));
680     GL_EXTCALL(glDeleteProgramsARB(1, &prog));
681     checkGLcall("GL_NV_vertex_program2_option result.clip[] test cleanup");
682
683     LEAVE_GL();
684     return ret;
685 }
686
687 /* Context activation is done by the caller. */
688 static BOOL match_fbo_tex_update(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
689         enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
690 {
691     char data[4 * 4 * 4];
692     GLuint tex, fbo;
693     GLenum status;
694
695     if (wined3d_settings.offscreen_rendering_mode != ORM_FBO) return FALSE;
696
697     memset(data, 0xcc, sizeof(data));
698
699     ENTER_GL();
700
701     glGenTextures(1, &tex);
702     glBindTexture(GL_TEXTURE_2D, tex);
703     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
704     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
705     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
706     checkGLcall("glTexImage2D");
707
708     gl_info->fbo_ops.glGenFramebuffers(1, &fbo);
709     gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
710     gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
711     checkGLcall("glFramebufferTexture2D");
712
713     status = gl_info->fbo_ops.glCheckFramebufferStatus(GL_FRAMEBUFFER);
714     if (status != GL_FRAMEBUFFER_COMPLETE) ERR("FBO status %#x\n", status);
715     checkGLcall("glCheckFramebufferStatus");
716
717     memset(data, 0x11, sizeof(data));
718     glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, data);
719     checkGLcall("glTexSubImage2D");
720
721     glClearColor(0.996f, 0.729f, 0.745f, 0.792f);
722     glClear(GL_COLOR_BUFFER_BIT);
723     checkGLcall("glClear");
724
725     glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, data);
726     checkGLcall("glGetTexImage");
727
728     gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
729     gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, 0);
730     glBindTexture(GL_TEXTURE_2D, 0);
731     checkGLcall("glBindTexture");
732
733     gl_info->fbo_ops.glDeleteFramebuffers(1, &fbo);
734     glDeleteTextures(1, &tex);
735     checkGLcall("glDeleteTextures");
736
737     LEAVE_GL();
738
739     return *(DWORD *)data == 0x11111111;
740 }
741
742 /* Context activation is done by the caller. */
743 static BOOL match_broken_rgba16(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
744         enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
745 {
746     /* GL_RGBA16 uses GL_RGBA8 internally on Geforce 7 and older cards.
747      * This leads to graphical bugs in Half Life 2 and Unreal engine games. */
748     GLuint tex;
749     GLint size;
750
751     ENTER_GL();
752
753     glGenTextures(1, &tex);
754     glBindTexture(GL_TEXTURE_2D, tex);
755     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT, NULL);
756     checkGLcall("glTexImage2D");
757
758     glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_RED_SIZE, &size);
759     checkGLcall("glGetTexLevelParameteriv");
760     TRACE("Real color depth is %d\n", size);
761
762     glBindTexture(GL_TEXTURE_2D, 0);
763     checkGLcall("glBindTexture");
764     glDeleteTextures(1, &tex);
765     checkGLcall("glDeleteTextures");
766
767     LEAVE_GL();
768
769     return size < 16;
770 }
771
772 static BOOL match_fglrx(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
773         enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
774 {
775     return gl_vendor == GL_VENDOR_FGLRX;
776 }
777
778 static void quirk_arb_constants(struct wined3d_gl_info *gl_info)
779 {
780     TRACE_(d3d_caps)("Using ARB vs constant limit(=%u) for GLSL.\n", gl_info->limits.arb_vs_native_constants);
781     gl_info->limits.glsl_vs_float_constants = gl_info->limits.arb_vs_native_constants;
782     TRACE_(d3d_caps)("Using ARB ps constant limit(=%u) for GLSL.\n", gl_info->limits.arb_ps_native_constants);
783     gl_info->limits.glsl_ps_float_constants = gl_info->limits.arb_ps_native_constants;
784 }
785
786 static void quirk_apple_glsl_constants(struct wined3d_gl_info *gl_info)
787 {
788     quirk_arb_constants(gl_info);
789     /* MacOS needs uniforms for relative addressing offsets. This can accumulate to quite a few uniforms.
790      * Beyond that the general uniform isn't optimal, so reserve a number of uniforms. 12 vec4's should
791      * allow 48 different offsets or other helper immediate values. */
792     TRACE_(d3d_caps)("Reserving 12 GLSL constants for compiler private use.\n");
793     gl_info->reserved_glsl_constants = max(gl_info->reserved_glsl_constants, 12);
794 }
795
796 static void quirk_amd_dx9(struct wined3d_gl_info *gl_info)
797 {
798     /* MacOS advertises GL_ARB_texture_non_power_of_two on ATI r500 and earlier cards, although
799      * these cards only support GL_ARB_texture_rectangle(D3DPTEXTURECAPS_NONPOW2CONDITIONAL).
800      * If real NP2 textures are used, the driver falls back to software. We could just remove the
801      * extension and use GL_ARB_texture_rectangle instead, but texture_rectangle is inconvenient
802      * due to the non-normalized texture coordinates. Thus set an internal extension flag,
803      * GL_WINE_normalized_texrect, which signals the code that it can use non power of two textures
804      * as per GL_ARB_texture_non_power_of_two, but has to stick to the texture_rectangle limits.
805      *
806      * fglrx doesn't advertise GL_ARB_texture_non_power_of_two, but it advertises opengl 2.0 which
807      * has this extension promoted to core. The extension loading code sets this extension supported
808      * due to that, so this code works on fglrx as well. */
809     if(gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
810     {
811         TRACE("GL_ARB_texture_non_power_of_two advertised on R500 or earlier card, removing.\n");
812         gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] = FALSE;
813         gl_info->supported[WINED3D_GL_NORMALIZED_TEXRECT] = TRUE;
814     }
815 }
816
817 static void quirk_no_np2(struct wined3d_gl_info *gl_info)
818 {
819     /*  The nVidia GeForceFX series reports OpenGL 2.0 capabilities with the latest drivers versions, but
820      *  doesn't explicitly advertise the ARB_tex_npot extension in the GL extension string.
821      *  This usually means that ARB_tex_npot is supported in hardware as long as the application is staying
822      *  within the limits enforced by the ARB_texture_rectangle extension. This however is not true for the
823      *  FX series, which instantly falls back to a slower software path as soon as ARB_tex_npot is used.
824      *  We therefore completely remove ARB_tex_npot from the list of supported extensions.
825      *
826      *  Note that wine_normalized_texrect can't be used in this case because internally it uses ARB_tex_npot,
827      *  triggering the software fallback. There is not much we can do here apart from disabling the
828      *  software-emulated extension and reenable ARB_tex_rect (which was previously disabled
829      *  in wined3d_adapter_init_gl_caps).
830      *  This fixup removes performance problems on both the FX 5900 and FX 5700 (e.g. for framebuffer
831      *  post-processing effects in the game "Max Payne 2").
832      *  The behaviour can be verified through a simple test app attached in bugreport #14724. */
833     TRACE("GL_ARB_texture_non_power_of_two advertised through OpenGL 2.0 on NV FX card, removing.\n");
834     gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] = FALSE;
835     gl_info->supported[ARB_TEXTURE_RECTANGLE] = TRUE;
836 }
837
838 static void quirk_texcoord_w(struct wined3d_gl_info *gl_info)
839 {
840     /* The Intel GPUs on MacOS set the .w register of texcoords to 0.0 by default, which causes problems
841      * with fixed function fragment processing. Ideally this flag should be detected with a test shader
842      * and OpenGL feedback mode, but some GL implementations (MacOS ATI at least, probably all MacOS ones)
843      * do not like vertex shaders in feedback mode and return an error, even though it should be valid
844      * according to the spec.
845      *
846      * We don't want to enable this on all cards, as it adds an extra instruction per texcoord used. This
847      * makes the shader slower and eats instruction slots which should be available to the d3d app.
848      *
849      * ATI Radeon HD 2xxx cards on MacOS have the issue. Instead of checking for the buggy cards, blacklist
850      * all radeon cards on Macs and whitelist the good ones. That way we're prepared for the future. If
851      * this workaround is activated on cards that do not need it, it won't break things, just affect
852      * performance negatively. */
853     TRACE("Enabling vertex texture coord fixes in vertex shaders.\n");
854     gl_info->quirks |= WINED3D_QUIRK_SET_TEXCOORD_W;
855 }
856
857 static void quirk_clip_varying(struct wined3d_gl_info *gl_info)
858 {
859     gl_info->quirks |= WINED3D_QUIRK_GLSL_CLIP_VARYING;
860 }
861
862 static void quirk_allows_specular_alpha(struct wined3d_gl_info *gl_info)
863 {
864     gl_info->quirks |= WINED3D_QUIRK_ALLOWS_SPECULAR_ALPHA;
865 }
866
867 static void quirk_disable_nvvp_clip(struct wined3d_gl_info *gl_info)
868 {
869     gl_info->quirks |= WINED3D_QUIRK_NV_CLIP_BROKEN;
870 }
871
872 static void quirk_fbo_tex_update(struct wined3d_gl_info *gl_info)
873 {
874     gl_info->quirks |= WINED3D_QUIRK_FBO_TEX_UPDATE;
875 }
876
877 static void quirk_broken_rgba16(struct wined3d_gl_info *gl_info)
878 {
879     gl_info->quirks |= WINED3D_QUIRK_BROKEN_RGBA16;
880 }
881
882 static void quirk_infolog_spam(struct wined3d_gl_info *gl_info)
883 {
884     gl_info->quirks |= WINED3D_QUIRK_INFO_LOG_SPAM;
885 }
886
887 static void quirk_limited_tex_filtering(struct wined3d_gl_info *gl_info)
888 {
889     /* Nvidia GeForce 6xxx and 7xxx support accelerated VTF only on a few
890        selected texture formats. They are apparently the only DX9 class GPUs
891        supporting VTF.
892        Also, DX9-era GPUs are somewhat limited with float textures
893        filtering and blending. */
894     gl_info->quirks |= WINED3D_QUIRK_LIMITED_TEX_FILTERING;
895 }
896
897 struct driver_quirk
898 {
899     BOOL (*match)(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
900             enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device);
901     void (*apply)(struct wined3d_gl_info *gl_info);
902     const char *description;
903 };
904
905 static const struct driver_quirk quirk_table[] =
906 {
907     {
908         match_amd_r300_to_500,
909         quirk_amd_dx9,
910         "AMD normalized texrect quirk"
911     },
912     /* MacOS advertises more GLSL vertex shader uniforms than supported by the hardware, and if more are
913      * used it falls back to software. While the compiler can detect if the shader uses all declared
914      * uniforms, the optimization fails if the shader uses relative addressing. So any GLSL shader
915      * using relative addressing falls back to software.
916      *
917      * ARB vp gives the correct amount of uniforms, so use it instead of GLSL. */
918     {
919         match_apple,
920         quirk_apple_glsl_constants,
921         "Apple GLSL uniform override"
922     },
923     {
924         match_geforce5,
925         quirk_no_np2,
926         "Geforce 5 NP2 disable"
927     },
928     {
929         match_apple_intel,
930         quirk_texcoord_w,
931         "Init texcoord .w for Apple Intel GPU driver"
932     },
933     {
934         match_apple_nonr500ati,
935         quirk_texcoord_w,
936         "Init texcoord .w for Apple ATI >= r600 GPU driver"
937     },
938     {
939         match_dx10_capable,
940         quirk_clip_varying,
941         "Reserved varying for gl_ClipPos"
942     },
943     {
944         /* GL_EXT_secondary_color does not allow 4 component secondary colors, but most
945          * GL implementations accept it. The Mac GL is the only implementation known to
946          * reject it.
947          *
948          * If we can pass 4 component specular colors, do it, because (a) we don't have
949          * to screw around with the data, and (b) the D3D fixed function vertex pipeline
950          * passes specular alpha to the pixel shader if any is used. Otherwise the
951          * specular alpha is used to pass the fog coordinate, which we pass to opengl
952          * via GL_EXT_fog_coord.
953          */
954         match_allows_spec_alpha,
955         quirk_allows_specular_alpha,
956         "Allow specular alpha quirk"
957     },
958     {
959         match_broken_nv_clip,
960         quirk_disable_nvvp_clip,
961         "Apple NV_vertex_program clip bug quirk"
962     },
963     {
964         match_fbo_tex_update,
965         quirk_fbo_tex_update,
966         "FBO rebind for attachment updates"
967     },
968     {
969         match_broken_rgba16,
970         quirk_broken_rgba16,
971         "True RGBA16 is not available"
972     },
973     {
974         match_fglrx,
975         quirk_infolog_spam,
976         "Not printing GLSL infolog"
977     },
978     {
979         match_not_dx10_capable,
980         quirk_limited_tex_filtering,
981         "Texture filtering, blending and VTF support is limited"
982     },
983 };
984
985 /* Certain applications (Steam) complain if we report an outdated driver version. In general,
986  * reporting a driver version is moot because we are not the Windows driver, and we have different
987  * bugs, features, etc.
988  *
989  * The driver version has the form "x.y.z.w".
990  *
991  * "x" is the Windows version the driver is meant for:
992  * 4 -> 95/98/NT4
993  * 5 -> 2000
994  * 6 -> 2000/XP
995  * 7 -> Vista
996  * 8 -> Win 7
997  *
998  * "y" is the maximum Direct3D version the driver supports.
999  * y  -> d3d version mapping:
1000  * 11 -> d3d6
1001  * 12 -> d3d7
1002  * 13 -> d3d8
1003  * 14 -> d3d9
1004  * 15 -> d3d10
1005  * 16 -> d3d10.1
1006  * 17 -> d3d11
1007  *
1008  * "z" is the subversion number.
1009  *
1010  * "w" is the vendor specific driver build number.
1011  */
1012
1013 struct driver_version_information
1014 {
1015     enum wined3d_display_driver driver;
1016     enum wined3d_driver_model driver_model;
1017     const char *driver_name;            /* name of Windows driver */
1018     WORD version;                       /* version word ('y'), contained in low word of DriverVersion.HighPart */
1019     WORD subversion;                    /* subversion word ('z'), contained in high word of DriverVersion.LowPart */
1020     WORD build;                         /* build number ('w'), contained in low word of DriverVersion.LowPart */
1021 };
1022
1023 /* The driver version table contains driver information for different devices on several OS versions. */
1024 static const struct driver_version_information driver_version_table[] =
1025 {
1026     /* AMD
1027      * - Radeon HD2x00 (R600) and up supported by current drivers.
1028      * - Radeon 9500 (R300) - X1*00 (R5xx) supported up to Catalyst 9.3 (Linux) and 10.2 (XP/Vista/Win7)
1029      * - Radeon 7xxx (R100) - 9250 (RV250) supported up to Catalyst 6.11 (XP)
1030      * - Rage 128 supported up to XP, latest official build 6.13.3279 dated October 2001 */
1031     {DRIVER_AMD_RAGE_128PRO,    DRIVER_MODEL_NT5X,  "ati2dvaa.dll", 13, 3279,  0},
1032     {DRIVER_AMD_R100,           DRIVER_MODEL_NT5X,  "ati2dvag.dll", 14, 10, 6614},
1033     {DRIVER_AMD_R300,           DRIVER_MODEL_NT5X,  "ati2dvag.dll", 14, 10, 6764},
1034     {DRIVER_AMD_R600,           DRIVER_MODEL_NT5X,  "ati2dvag.dll", 14, 10, 8681},
1035     {DRIVER_AMD_R300,           DRIVER_MODEL_NT6X,  "atiumdag.dll", 14, 10, 741 },
1036     {DRIVER_AMD_R600,           DRIVER_MODEL_NT6X,  "atiumdag.dll", 14, 10, 741 },
1037
1038     /* Intel
1039      * The drivers are unified but not all versions support all GPUs. At some point the 2k/xp
1040      * drivers used ialmrnt5.dll for GMA800/GMA900 but at some point the file was renamed to
1041      * igxprd32.dll but the GMA800 driver was never updated. */
1042     {DRIVER_INTEL_GMA800,       DRIVER_MODEL_NT5X,  "ialmrnt5.dll", 14, 10, 3889},
1043     {DRIVER_INTEL_GMA900,       DRIVER_MODEL_NT5X,  "igxprd32.dll", 14, 10, 4764},
1044     {DRIVER_INTEL_GMA950,       DRIVER_MODEL_NT5X,  "igxprd32.dll", 14, 10, 4926},
1045     {DRIVER_INTEL_GMA3000,      DRIVER_MODEL_NT5X,  "igxprd32.dll", 14, 10, 5218},
1046     {DRIVER_INTEL_GMA950,       DRIVER_MODEL_NT6X,  "igdumd32.dll", 14, 10, 1504},
1047     {DRIVER_INTEL_GMA3000,      DRIVER_MODEL_NT6X,  "igdumd32.dll", 15, 10, 1666},
1048
1049     /* Nvidia
1050      * - Geforce6 and newer cards are supported by the current driver (197.x) on XP-Win7
1051      * - GeforceFX support is up to 173.x on <= XP
1052      * - Geforce2MX/3/4 up to 96.x on <= XP
1053      * - TNT/Geforce1/2 up to 71.x on <= XP
1054      * All version numbers used below are from the Linux nvidia drivers. */
1055     {DRIVER_NVIDIA_TNT,         DRIVER_MODEL_NT5X,  "nv4_disp.dll", 14, 10, 7186},
1056     {DRIVER_NVIDIA_GEFORCE2MX,  DRIVER_MODEL_NT5X,  "nv4_disp.dll", 14, 10, 9371},
1057     {DRIVER_NVIDIA_GEFORCEFX,   DRIVER_MODEL_NT5X,  "nv4_disp.dll", 14, 11, 7516},
1058     {DRIVER_NVIDIA_GEFORCE6,    DRIVER_MODEL_NT5X,  "nv4_disp.dll", 15, 12, 6658},
1059     {DRIVER_NVIDIA_GEFORCE6,    DRIVER_MODEL_NT6X,  "nvd3dum.dll",  15, 12, 6658},
1060 };
1061
1062 struct gpu_description
1063 {
1064     WORD vendor;                    /* reported PCI card vendor ID  */
1065     WORD card;                      /* reported PCI card device ID  */
1066     const char *description;        /* Description of the card e.g. NVIDIA RIVA TNT */
1067     enum wined3d_display_driver driver;
1068     unsigned int vidmem;
1069 };
1070
1071 /* The amount of video memory stored in the gpu description table is the minimum amount of video memory
1072  * found on a board containing a specific GPU. */
1073 static const struct gpu_description gpu_description_table[] =
1074 {
1075     /* Nvidia cards */
1076     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_RIVA_TNT,           "NVIDIA RIVA TNT",                  DRIVER_NVIDIA_TNT,       16  },
1077     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_RIVA_TNT2,          "NVIDIA RIVA TNT2/TNT2 Pro",        DRIVER_NVIDIA_TNT,       32  },
1078     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE,            "NVIDIA GeForce 256",               DRIVER_NVIDIA_TNT,       32  },
1079     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE2,           "NVIDIA GeForce2 GTS/GeForce2 Pro", DRIVER_NVIDIA_TNT,       32  },
1080     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE2_MX,        "NVIDIA GeForce2 MX/MX 400",        DRIVER_NVIDIA_GEFORCE2MX,32  },
1081     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE3,           "NVIDIA GeForce3",                  DRIVER_NVIDIA_GEFORCE2MX,64  },
1082     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE4_MX,        "NVIDIA GeForce4 MX 460",           DRIVER_NVIDIA_GEFORCE2MX,64  },
1083     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE4_TI4200,    "NVIDIA GeForce4 Ti 4200",          DRIVER_NVIDIA_GEFORCE2MX,64, },
1084     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCEFX_5200,     "NVIDIA GeForce FX 5200",           DRIVER_NVIDIA_GEFORCEFX, 64  },
1085     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCEFX_5600,     "NVIDIA GeForce FX 5600",           DRIVER_NVIDIA_GEFORCEFX, 128 },
1086     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCEFX_5800,     "NVIDIA GeForce FX 5800",           DRIVER_NVIDIA_GEFORCEFX, 256 },
1087     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_6200,       "NVIDIA GeForce 6200",              DRIVER_NVIDIA_GEFORCE6,  64  },
1088     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_6600GT,     "NVIDIA GeForce 6600 GT",           DRIVER_NVIDIA_GEFORCE6,  128 },
1089     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_6800,       "NVIDIA GeForce 6800",              DRIVER_NVIDIA_GEFORCE6,  128 },
1090     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_7300,       "NVIDIA GeForce Go 7300",           DRIVER_NVIDIA_GEFORCE6,  256 },
1091     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_7400,       "NVIDIA GeForce Go 7400",           DRIVER_NVIDIA_GEFORCE6,  256 },
1092     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_7600,       "NVIDIA GeForce 7600 GT",           DRIVER_NVIDIA_GEFORCE6,  256 },
1093     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_7800GT,     "NVIDIA GeForce 7800 GT",           DRIVER_NVIDIA_GEFORCE6,  256 },
1094     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_8300GS,     "NVIDIA GeForce 8300 GS",           DRIVER_NVIDIA_GEFORCE6,  128 },
1095     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_8400GS,     "NVIDIA GeForce 8400 GS",           DRIVER_NVIDIA_GEFORCE6,  128 },
1096     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_8600GT,     "NVIDIA GeForce 8600 GT",           DRIVER_NVIDIA_GEFORCE6,  256 },
1097     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_8600MGT,    "NVIDIA GeForce 8600M GT",          DRIVER_NVIDIA_GEFORCE6,  512 },
1098     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_8800GTS,    "NVIDIA GeForce 8800 GTS",          DRIVER_NVIDIA_GEFORCE6,  320 },
1099     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_8800GTX,    "NVIDIA GeForce 8800 GTX",          DRIVER_NVIDIA_GEFORCE6,  768 },
1100     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_9200,       "NVIDIA GeForce 9200",              DRIVER_NVIDIA_GEFORCE6,  256 },
1101     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_9400GT,     "NVIDIA GeForce 9400 GT",           DRIVER_NVIDIA_GEFORCE6,  256 },
1102     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_9500GT,     "NVIDIA GeForce 9500 GT",           DRIVER_NVIDIA_GEFORCE6,  256 },
1103     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_9600GT,     "NVIDIA GeForce 9600 GT",           DRIVER_NVIDIA_GEFORCE6,  384 },
1104     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_9800GT,     "NVIDIA GeForce 9800 GT",           DRIVER_NVIDIA_GEFORCE6,  512 },
1105     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_210,        "NVIDIA GeForce 210",               DRIVER_NVIDIA_GEFORCE6,  512 },
1106     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GT220,      "NVIDIA GeForce GT 220",            DRIVER_NVIDIA_GEFORCE6,  512 },
1107     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GT240,      "NVIDIA GeForce GT 240",            DRIVER_NVIDIA_GEFORCE6,  512 },
1108     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GTX260,     "NVIDIA GeForce GTX 260",           DRIVER_NVIDIA_GEFORCE6,  1024},
1109     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GTX275,     "NVIDIA GeForce GTX 275",           DRIVER_NVIDIA_GEFORCE6,  896 },
1110     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GTX280,     "NVIDIA GeForce GTX 280",           DRIVER_NVIDIA_GEFORCE6,  1024},
1111     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GT320M,     "NVIDIA GeForce GT 320M",           DRIVER_NVIDIA_GEFORCE6,  1024},
1112     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GT325M,     "NVIDIA GeForce GT 325M",           DRIVER_NVIDIA_GEFORCE6,  1024},
1113     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GT330,      "NVIDIA GeForce GT 330",            DRIVER_NVIDIA_GEFORCE6,  1024},
1114     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GTS350M,    "NVIDIA GeForce GTS 350M",          DRIVER_NVIDIA_GEFORCE6,  1024},
1115     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GT420,      "NVIDIA GeForce GT 420",            DRIVER_NVIDIA_GEFORCE6,  2048},
1116     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GT430,      "NVIDIA GeForce GT 430",            DRIVER_NVIDIA_GEFORCE6,  1024},
1117     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GT440,      "NVIDIA GeForce GT 440",            DRIVER_NVIDIA_GEFORCE6,  1024},
1118     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GTS450,     "NVIDIA GeForce GTS 450",           DRIVER_NVIDIA_GEFORCE6,  1024},
1119     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GTX460,     "NVIDIA GeForce GTX 460",           DRIVER_NVIDIA_GEFORCE6,  768 },
1120     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GTX460M,    "NVIDIA GeForce GTX 460M",          DRIVER_NVIDIA_GEFORCE6,  1536},
1121     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GTX465,     "NVIDIA GeForce GTX 465",           DRIVER_NVIDIA_GEFORCE6,  1024},
1122     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GTX470,     "NVIDIA GeForce GTX 470",           DRIVER_NVIDIA_GEFORCE6,  1280},
1123     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GTX480,     "NVIDIA GeForce GTX 480",           DRIVER_NVIDIA_GEFORCE6,  1536},
1124     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GT540M,     "NVIDIA GeForce GT 540M",           DRIVER_NVIDIA_GEFORCE6,  1024},
1125     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GTX550,     "NVIDIA GeForce GTX 550 Ti",        DRIVER_NVIDIA_GEFORCE6,  1024},
1126     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GT555M,     "NVIDIA GeForce GT 555M",           DRIVER_NVIDIA_GEFORCE6,  1024},
1127     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GTX560TI,   "NVIDIA GeForce GTX 560 Ti",        DRIVER_NVIDIA_GEFORCE6,  1024},
1128     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GTX560,     "NVIDIA GeForce GTX 560",           DRIVER_NVIDIA_GEFORCE6,  1024},
1129     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GTX570,     "NVIDIA GeForce GTX 570",           DRIVER_NVIDIA_GEFORCE6,  1280},
1130     {HW_VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GTX580,     "NVIDIA GeForce GTX 580",           DRIVER_NVIDIA_GEFORCE6,  1536},
1131
1132     /* AMD cards */
1133     {HW_VENDOR_AMD,        CARD_AMD_RAGE_128PRO,           "ATI Rage Fury",                    DRIVER_AMD_RAGE_128PRO,  16  },
1134     {HW_VENDOR_AMD,        CARD_AMD_RADEON_7200,           "ATI RADEON 7200 SERIES",           DRIVER_AMD_R100,         32  },
1135     {HW_VENDOR_AMD,        CARD_AMD_RADEON_8500,           "ATI RADEON 8500 SERIES",           DRIVER_AMD_R100,         64  },
1136     {HW_VENDOR_AMD,        CARD_AMD_RADEON_9500,           "ATI Radeon 9500",                  DRIVER_AMD_R300,         64  },
1137     {HW_VENDOR_AMD,        CARD_AMD_RADEON_XPRESS_200M,    "ATI RADEON XPRESS 200M Series",    DRIVER_AMD_R300,         64  },
1138     {HW_VENDOR_AMD,        CARD_AMD_RADEON_X700,           "ATI Radeon X700 SE",               DRIVER_AMD_R300,         128 },
1139     {HW_VENDOR_AMD,        CARD_AMD_RADEON_X1600,          "ATI Radeon X1600 Series",          DRIVER_AMD_R300,         128 },
1140     {HW_VENDOR_AMD,        CARD_AMD_RADEON_HD2350,         "ATI Mobility Radeon HD 2350",      DRIVER_AMD_R600,         256 },
1141     {HW_VENDOR_AMD,        CARD_AMD_RADEON_HD2600,         "ATI Mobility Radeon HD 2600",      DRIVER_AMD_R600,         256 },
1142     {HW_VENDOR_AMD,        CARD_AMD_RADEON_HD2900,         "ATI Radeon HD 2900 XT",            DRIVER_AMD_R600,         512 },
1143     {HW_VENDOR_AMD,        CARD_AMD_RADEON_HD3200,         "ATI Radeon HD 3200 Graphics",      DRIVER_AMD_R600,         128 },
1144     {HW_VENDOR_AMD,        CARD_AMD_RADEON_HD4350,         "ATI Radeon HD 4350",               DRIVER_AMD_R600,         256 },
1145     {HW_VENDOR_AMD,        CARD_AMD_RADEON_HD4600,         "ATI Radeon HD 4600 Series",        DRIVER_AMD_R600,         512 },
1146     {HW_VENDOR_AMD,        CARD_AMD_RADEON_HD4700,         "ATI Radeon HD 4700 Series",        DRIVER_AMD_R600,         512 },
1147     {HW_VENDOR_AMD,        CARD_AMD_RADEON_HD4800,         "ATI Radeon HD 4800 Series",        DRIVER_AMD_R600,         512 },
1148     {HW_VENDOR_AMD,        CARD_AMD_RADEON_HD5400,         "ATI Radeon HD 5400 Series",        DRIVER_AMD_R600,         512 },
1149     {HW_VENDOR_AMD,        CARD_AMD_RADEON_HD5600,         "ATI Radeon HD 5600 Series",        DRIVER_AMD_R600,         512 },
1150     {HW_VENDOR_AMD,        CARD_AMD_RADEON_HD5700,         "ATI Radeon HD 5700 Series",        DRIVER_AMD_R600,         512 },
1151     {HW_VENDOR_AMD,        CARD_AMD_RADEON_HD5800,         "ATI Radeon HD 5800 Series",        DRIVER_AMD_R600,         1024},
1152     {HW_VENDOR_AMD,        CARD_AMD_RADEON_HD5900,         "ATI Radeon HD 5900 Series",        DRIVER_AMD_R600,         1024},
1153     {HW_VENDOR_AMD,        CARD_AMD_RADEON_HD6300,         "AMD Radeon HD 6300 series Graphics", DRIVER_AMD_R600,       1024},
1154     {HW_VENDOR_AMD,        CARD_AMD_RADEON_HD6400,         "AMD Radeon HD 6400 Series",        DRIVER_AMD_R600,         1024},
1155     {HW_VENDOR_AMD,        CARD_AMD_RADEON_HD6410D,        "AMD Radeon HD 6410D",              DRIVER_AMD_R600,         1024},
1156     {HW_VENDOR_AMD,        CARD_AMD_RADEON_HD6550D,        "AMD Radeon HD 6550D",              DRIVER_AMD_R600,         1024},
1157     {HW_VENDOR_AMD,        CARD_AMD_RADEON_HD6600,         "AMD Radeon HD 6600 Series",        DRIVER_AMD_R600,         1024},
1158     {HW_VENDOR_AMD,        CARD_AMD_RADEON_HD6600M,        "AMD Radeon HD 6600M Series",       DRIVER_AMD_R600,         512 },
1159     {HW_VENDOR_AMD,        CARD_AMD_RADEON_HD6800,         "AMD Radeon HD 6800 Series",        DRIVER_AMD_R600,         1024},
1160     {HW_VENDOR_AMD,        CARD_AMD_RADEON_HD6900,         "AMD Radeon HD 6900 Series",        DRIVER_AMD_R600,         2048},
1161     /* Intel cards */
1162     {HW_VENDOR_INTEL,      CARD_INTEL_830M,                "Intel(R) 82830M Graphics Controller",                       DRIVER_INTEL_GMA800,  32 },
1163     {HW_VENDOR_INTEL,      CARD_INTEL_855GM,               "Intel(R) 82852/82855 GM/GME Graphics Controller",           DRIVER_INTEL_GMA800,  32 },
1164     {HW_VENDOR_INTEL,      CARD_INTEL_845G,                "Intel(R) 845G",                                             DRIVER_INTEL_GMA800,  32 },
1165     {HW_VENDOR_INTEL,      CARD_INTEL_865G,                "Intel(R) 82865G Graphics Controller",                       DRIVER_INTEL_GMA800,  32 },
1166     {HW_VENDOR_INTEL,      CARD_INTEL_915G,                "Intel(R) 82915G/GV/910GL Express Chipset Family",           DRIVER_INTEL_GMA900,  64 },
1167     {HW_VENDOR_INTEL,      CARD_INTEL_E7221G,              "Intel(R) E7221G",                                           DRIVER_INTEL_GMA900,  64 },
1168     {HW_VENDOR_INTEL,      CARD_INTEL_915GM,               "Mobile Intel(R) 915GM/GMS,910GML Express Chipset Family",   DRIVER_INTEL_GMA900,  64 },
1169     {HW_VENDOR_INTEL,      CARD_INTEL_945G,                "Intel(R) 945G",                                             DRIVER_INTEL_GMA950,  64 },
1170     {HW_VENDOR_INTEL,      CARD_INTEL_945GM,               "Mobile Intel(R) 945GM Express Chipset Family",              DRIVER_INTEL_GMA950,  64 },
1171     {HW_VENDOR_INTEL,      CARD_INTEL_945GME,              "Intel(R) 945GME",                                           DRIVER_INTEL_GMA950,  64 },
1172     {HW_VENDOR_INTEL,      CARD_INTEL_Q35,                 "Intel(R) Q35",                                              DRIVER_INTEL_GMA950,  64 },
1173     {HW_VENDOR_INTEL,      CARD_INTEL_G33,                 "Intel(R) G33",                                              DRIVER_INTEL_GMA950,  64 },
1174     {HW_VENDOR_INTEL,      CARD_INTEL_Q33,                 "Intel(R) Q33",                                              DRIVER_INTEL_GMA950,  64 },
1175     {HW_VENDOR_INTEL,      CARD_INTEL_PNVG,                "Intel(R) IGD",                                              DRIVER_INTEL_GMA950,  64 },
1176     {HW_VENDOR_INTEL,      CARD_INTEL_PNVM,                "Intel(R) IGD",                                              DRIVER_INTEL_GMA950,  64 },
1177     {HW_VENDOR_INTEL,      CARD_INTEL_965Q,                "Intel(R) 965Q",                                             DRIVER_INTEL_GMA3000, 128},
1178     {HW_VENDOR_INTEL,      CARD_INTEL_965G,                "Intel(R) 965G",                                             DRIVER_INTEL_GMA3000, 128},
1179     {HW_VENDOR_INTEL,      CARD_INTEL_946GZ,               "Intel(R) 946GZ",                                            DRIVER_INTEL_GMA3000, 128},
1180     {HW_VENDOR_INTEL,      CARD_INTEL_965GM,               "Mobile Intel(R) 965 Express Chipset Family",                DRIVER_INTEL_GMA3000, 128},
1181     {HW_VENDOR_INTEL,      CARD_INTEL_965GME,              "Intel(R) 965GME",                                           DRIVER_INTEL_GMA3000, 128},
1182     {HW_VENDOR_INTEL,      CARD_INTEL_GM45,                "Mobile Intel(R) GM45 Express Chipset Family",               DRIVER_INTEL_GMA3000, 512},
1183     {HW_VENDOR_INTEL,      CARD_INTEL_IGD,                 "Intel(R) Integrated Graphics Device",                       DRIVER_INTEL_GMA3000, 512},
1184     {HW_VENDOR_INTEL,      CARD_INTEL_G45,                 "Intel(R) G45/G43",                                          DRIVER_INTEL_GMA3000, 512},
1185     {HW_VENDOR_INTEL,      CARD_INTEL_Q45,                 "Intel(R) Q45/Q43",                                          DRIVER_INTEL_GMA3000, 512},
1186     {HW_VENDOR_INTEL,      CARD_INTEL_G41,                 "Intel(R) G41",                                              DRIVER_INTEL_GMA3000, 512},
1187     {HW_VENDOR_INTEL,      CARD_INTEL_B43,                 "Intel(R) B43",                                              DRIVER_INTEL_GMA3000, 512},
1188     {HW_VENDOR_INTEL,      CARD_INTEL_ILKD,                "Intel(R) Ironlake Desktop",                                 DRIVER_INTEL_GMA3000, 1024},
1189     {HW_VENDOR_INTEL,      CARD_INTEL_ILKM,                "Intel(R) Ironlake Mobile",                                  DRIVER_INTEL_GMA3000, 1024},
1190     {HW_VENDOR_INTEL,      CARD_INTEL_SNBD,                "Intel(R) Sandybridge Desktop",                              DRIVER_INTEL_GMA3000, 1024},
1191     {HW_VENDOR_INTEL,      CARD_INTEL_SNBM,                "Intel(R) Sandybridge Mobile",                               DRIVER_INTEL_GMA3000, 1024},
1192     {HW_VENDOR_INTEL,      CARD_INTEL_SNBS,                "Intel(R) Sandybridge Server",                               DRIVER_INTEL_GMA3000, 1024},
1193     {HW_VENDOR_INTEL,      CARD_INTEL_IVBD,                "Intel(R) Ivybridge Desktop",                                DRIVER_INTEL_GMA3000, 1024},
1194     {HW_VENDOR_INTEL,      CARD_INTEL_IVBM,                "Intel(R) Ivybridge Mobile",                                 DRIVER_INTEL_GMA3000, 1024},
1195     {HW_VENDOR_INTEL,      CARD_INTEL_IVBS,                "Intel(R) Ivybridge Server",                                 DRIVER_INTEL_GMA3000, 1024},
1196 };
1197
1198 static const struct driver_version_information *get_driver_version_info(enum wined3d_display_driver driver,
1199         enum wined3d_driver_model driver_model)
1200 {
1201     unsigned int i;
1202
1203     TRACE("Looking up version info for driver=%d driver_model=%d\n", driver, driver_model);
1204     for (i = 0; i < (sizeof(driver_version_table) / sizeof(driver_version_table[0])); i++)
1205     {
1206         const struct driver_version_information *entry = &driver_version_table[i];
1207
1208         if (entry->driver == driver && entry->driver_model == driver_model)
1209         {
1210             TRACE_(d3d_caps)("Found driver '%s' version=%d subversion=%d build=%d\n",
1211                 entry->driver_name, entry->version, entry->subversion, entry->build);
1212
1213             return entry;
1214         }
1215     }
1216     return NULL;
1217 }
1218
1219 static void init_driver_info(struct wined3d_driver_info *driver_info,
1220         enum wined3d_pci_vendor vendor, enum wined3d_pci_device device)
1221 {
1222     OSVERSIONINFOW os_version;
1223     WORD driver_os_version;
1224     unsigned int i;
1225     enum wined3d_display_driver driver = DRIVER_UNKNOWN;
1226     enum wined3d_driver_model driver_model;
1227     const struct driver_version_information *version_info;
1228
1229     if (wined3d_settings.pci_vendor_id != PCI_VENDOR_NONE)
1230     {
1231         TRACE_(d3d_caps)("Overriding PCI vendor ID with: %04x\n", wined3d_settings.pci_vendor_id);
1232         vendor = wined3d_settings.pci_vendor_id;
1233     }
1234     driver_info->vendor = vendor;
1235
1236     if (wined3d_settings.pci_device_id != PCI_DEVICE_NONE)
1237     {
1238         TRACE_(d3d_caps)("Overriding PCI device ID with: %04x\n", wined3d_settings.pci_device_id);
1239         device = wined3d_settings.pci_device_id;
1240     }
1241     driver_info->device = device;
1242
1243     /* Set a default amount of video memory (64MB). In general this code isn't used unless the user
1244      * overrides the pci ids to a card which is not in our database. */
1245     driver_info->vidmem = WINE_DEFAULT_VIDMEM;
1246
1247     memset(&os_version, 0, sizeof(os_version));
1248     os_version.dwOSVersionInfoSize = sizeof(os_version);
1249     if (!GetVersionExW(&os_version))
1250     {
1251         ERR("Failed to get OS version, reporting 2000/XP.\n");
1252         driver_os_version = 6;
1253         driver_model = DRIVER_MODEL_NT5X;
1254     }
1255     else
1256     {
1257         TRACE("OS version %u.%u.\n", os_version.dwMajorVersion, os_version.dwMinorVersion);
1258         switch (os_version.dwMajorVersion)
1259         {
1260             case 4:
1261                 /* If needed we could distinguish between 9x and NT4, but this code won't make
1262                  * sense for NT4 since it had no way to obtain this info through DirectDraw 3.0.
1263                  */
1264                 driver_os_version = 4;
1265                 driver_model = DRIVER_MODEL_WIN9X;
1266                 break;
1267
1268             case 5:
1269                 driver_os_version = 6;
1270                 driver_model = DRIVER_MODEL_NT5X;
1271                 break;
1272
1273             case 6:
1274                 if (os_version.dwMinorVersion == 0)
1275                 {
1276                     driver_os_version = 7;
1277                     driver_model = DRIVER_MODEL_NT6X;
1278                 }
1279                 else
1280                 {
1281                     if (os_version.dwMinorVersion > 1)
1282                     {
1283                         FIXME("Unhandled OS version %u.%u, reporting Win 7.\n",
1284                                 os_version.dwMajorVersion, os_version.dwMinorVersion);
1285                     }
1286                     driver_os_version = 8;
1287                     driver_model = DRIVER_MODEL_NT6X;
1288                 }
1289                 break;
1290
1291             default:
1292                 FIXME("Unhandled OS version %u.%u, reporting 2000/XP.\n",
1293                         os_version.dwMajorVersion, os_version.dwMinorVersion);
1294                 driver_os_version = 6;
1295                 driver_model = DRIVER_MODEL_NT5X;
1296                 break;
1297         }
1298     }
1299
1300     /* When we reach this stage we always have a vendor or device id (it can be a default one).
1301      * This means that unless the ids are overriden, we will always find a GPU description. */
1302     for (i = 0; i < (sizeof(gpu_description_table) / sizeof(gpu_description_table[0])); i++)
1303     {
1304         if (vendor == gpu_description_table[i].vendor && device == gpu_description_table[i].card)
1305         {
1306             TRACE_(d3d_caps)("Found card %04x:%04x in driver DB.\n", vendor, device);
1307
1308             driver_info->description = gpu_description_table[i].description;
1309             driver_info->vidmem = gpu_description_table[i].vidmem * 1024*1024;
1310             driver = gpu_description_table[i].driver;
1311             break;
1312         }
1313     }
1314
1315     if (wined3d_settings.emulated_textureram)
1316     {
1317         TRACE_(d3d_caps)("Overriding amount of video memory with: %d byte\n", wined3d_settings.emulated_textureram);
1318         driver_info->vidmem = wined3d_settings.emulated_textureram;
1319     }
1320
1321     /* Try to obtain driver version information for the current Windows version. This fails in
1322      * some cases:
1323      * - the gpu is not available on the currently selected OS version:
1324      *   - Geforce GTX480 on Win98. When running applications in compatibility mode on Windows,
1325      *     version information for the current Windows version is returned instead of faked info.
1326      *     We do the same and assume the default Windows version to emulate is WinXP.
1327      *
1328      *   - Videocard is a Riva TNT but winver is set to win7 (there are no drivers for this beast)
1329      *     For now return the XP driver info. Perhaps later on we should return VESA.
1330      *
1331      * - the gpu is not in our database (can happen when the user overrides the vendor_id / device_id)
1332      *   This could be an indication that our database is not up to date, so this should be fixed.
1333      */
1334     version_info = get_driver_version_info(driver, driver_model);
1335     if (version_info)
1336     {
1337         driver_info->name = version_info->driver_name;
1338         driver_info->version_high = MAKEDWORD_VERSION(driver_os_version, version_info->version);
1339         driver_info->version_low = MAKEDWORD_VERSION(version_info->subversion, version_info->build);
1340     }
1341     else
1342     {
1343         version_info = get_driver_version_info(driver, DRIVER_MODEL_NT5X);
1344         if (version_info)
1345         {
1346             driver_info->name = version_info->driver_name;
1347             driver_info->version_high = MAKEDWORD_VERSION(driver_os_version, version_info->version);
1348             driver_info->version_low = MAKEDWORD_VERSION(version_info->subversion, version_info->build);
1349         }
1350         else
1351         {
1352             driver_info->description = "Direct3D HAL";
1353             driver_info->name = "Display";
1354             driver_info->version_high = MAKEDWORD_VERSION(driver_os_version, 15);
1355             driver_info->version_low = MAKEDWORD_VERSION(8, 6); /* Nvidia RIVA TNT, arbitrary */
1356
1357             FIXME("Unable to find a driver/device info for vendor_id=%#x device_id=%#x for driver_model=%d\n",
1358                     vendor, device, driver_model);
1359         }
1360     }
1361
1362     TRACE_(d3d_caps)("Reporting (fake) driver version 0x%08x-0x%08x.\n",
1363             driver_info->version_high, driver_info->version_low);
1364 }
1365
1366 /* Context activation is done by the caller. */
1367 static void fixup_extensions(struct wined3d_gl_info *gl_info, const char *gl_renderer,
1368         enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
1369 {
1370     unsigned int i;
1371
1372     for (i = 0; i < (sizeof(quirk_table) / sizeof(*quirk_table)); ++i)
1373     {
1374         if (!quirk_table[i].match(gl_info, gl_renderer, gl_vendor, card_vendor, device)) continue;
1375         TRACE_(d3d_caps)("Applying driver quirk \"%s\".\n", quirk_table[i].description);
1376         quirk_table[i].apply(gl_info);
1377     }
1378
1379     /* Find out if PBOs work as they are supposed to. */
1380     test_pbo_functionality(gl_info);
1381 }
1382
1383 static DWORD wined3d_parse_gl_version(const char *gl_version)
1384 {
1385     const char *ptr = gl_version;
1386     int major, minor;
1387
1388     major = atoi(ptr);
1389     if (major <= 0) ERR_(d3d_caps)("Invalid opengl major version: %d.\n", major);
1390
1391     while (isdigit(*ptr)) ++ptr;
1392     if (*ptr++ != '.') ERR_(d3d_caps)("Invalid opengl version string: %s.\n", debugstr_a(gl_version));
1393
1394     minor = atoi(ptr);
1395
1396     TRACE_(d3d_caps)("Found OpenGL version: %d.%d.\n", major, minor);
1397
1398     return MAKEDWORD_VERSION(major, minor);
1399 }
1400
1401 static enum wined3d_gl_vendor wined3d_guess_gl_vendor(const struct wined3d_gl_info *gl_info,
1402         const char *gl_vendor_string, const char *gl_renderer)
1403 {
1404
1405     /* MacOS has various specialities in the extensions it advertises. Some have to be loaded from
1406      * the opengl 1.2+ core, while other extensions are advertised, but software emulated. So try to
1407      * detect the Apple OpenGL implementation to apply some extension fixups afterwards.
1408      *
1409      * Detecting this isn't really easy. The vendor string doesn't mention Apple. Compile-time checks
1410      * aren't sufficient either because a Linux binary may display on a macos X server via remote X11.
1411      * So try to detect the GL implementation by looking at certain Apple extensions. Some extensions
1412      * like client storage might be supported on other implementations too, but GL_APPLE_flush_render
1413      * is specific to the Mac OS X window management, and GL_APPLE_ycbcr_422 is QuickTime specific. So
1414      * the chance that other implementations support them is rather small since Win32 QuickTime uses
1415      * DirectDraw, not OpenGL. */
1416     if (gl_info->supported[APPLE_FENCE]
1417             && gl_info->supported[APPLE_CLIENT_STORAGE]
1418             && gl_info->supported[APPLE_FLUSH_RENDER]
1419             && gl_info->supported[APPLE_YCBCR_422])
1420         return GL_VENDOR_APPLE;
1421
1422     if (strstr(gl_vendor_string, "NVIDIA"))
1423         return GL_VENDOR_NVIDIA;
1424
1425     if (strstr(gl_vendor_string, "ATI"))
1426         return GL_VENDOR_FGLRX;
1427
1428     if (strstr(gl_vendor_string, "Intel(R)")
1429             /* Intel switched from Intel(R) to Intel® recently, so just match Intel. */
1430             || strstr(gl_renderer, "Intel")
1431             || strstr(gl_vendor_string, "Intel Inc."))
1432         return GL_VENDOR_INTEL;
1433
1434     if (strstr(gl_vendor_string, "Mesa")
1435             || strstr(gl_vendor_string, "Advanced Micro Devices, Inc.")
1436             || strstr(gl_vendor_string, "DRI R300 Project")
1437             || strstr(gl_vendor_string, "X.Org R300 Project")
1438             || strstr(gl_vendor_string, "Tungsten Graphics, Inc")
1439             || strstr(gl_vendor_string, "VMware, Inc.")
1440             || strstr(gl_renderer, "Mesa")
1441             || strstr(gl_renderer, "Gallium"))
1442         return GL_VENDOR_MESA;
1443
1444     FIXME_(d3d_caps)("Received unrecognized GL_VENDOR %s. Returning GL_VENDOR_UNKNOWN.\n",
1445             debugstr_a(gl_vendor_string));
1446
1447     return GL_VENDOR_UNKNOWN;
1448 }
1449
1450 static enum wined3d_pci_vendor wined3d_guess_card_vendor(const char *gl_vendor_string, const char *gl_renderer)
1451 {
1452     if (strstr(gl_vendor_string, "NVIDIA")
1453             || strstr(gl_vendor_string, "nouveau"))
1454         return HW_VENDOR_NVIDIA;
1455
1456     if (strstr(gl_vendor_string, "ATI")
1457             || strstr(gl_vendor_string, "Advanced Micro Devices, Inc.")
1458             || strstr(gl_vendor_string, "X.Org R300 Project")
1459             || strstr(gl_renderer, "AMD")
1460             || strstr(gl_renderer, "R100")
1461             || strstr(gl_renderer, "R200")
1462             || strstr(gl_renderer, "R300")
1463             || strstr(gl_renderer, "R600")
1464             || strstr(gl_renderer, "R700"))
1465         return HW_VENDOR_AMD;
1466
1467     if (strstr(gl_vendor_string, "Intel(R)")
1468             /* Intel switched from Intel(R) to Intel® recently, so just match Intel. */
1469             || strstr(gl_renderer, "Intel")
1470             || strstr(gl_renderer, "i915")
1471             || strstr(gl_vendor_string, "Intel Inc."))
1472         return HW_VENDOR_INTEL;
1473
1474     if (strstr(gl_vendor_string, "Mesa")
1475             || strstr(gl_vendor_string, "Brian Paul")
1476             || strstr(gl_vendor_string, "Tungsten Graphics, Inc")
1477             || strstr(gl_vendor_string, "VMware, Inc."))
1478         return HW_VENDOR_SOFTWARE;
1479
1480     FIXME_(d3d_caps)("Received unrecognized GL_VENDOR %s. Returning HW_VENDOR_NVIDIA.\n", debugstr_a(gl_vendor_string));
1481
1482     return HW_VENDOR_NVIDIA;
1483 }
1484
1485 static UINT d3d_level_from_gl_info(const struct wined3d_gl_info *gl_info)
1486 {
1487     UINT level = 0;
1488
1489     if (gl_info->supported[ARB_MULTITEXTURE])
1490         level = 6;
1491     if (gl_info->supported[ARB_TEXTURE_COMPRESSION]
1492             && gl_info->supported[ARB_TEXTURE_CUBE_MAP]
1493             && gl_info->supported[ARB_TEXTURE_ENV_DOT3])
1494         level = 7;
1495     if (level == 7 && gl_info->supported[ARB_MULTISAMPLE]
1496             && gl_info->supported[ARB_TEXTURE_BORDER_CLAMP])
1497         level = 8;
1498     if (level == 8 && gl_info->supported[ARB_FRAGMENT_PROGRAM]
1499             && gl_info->supported[ARB_VERTEX_SHADER])
1500         level = 9;
1501     if (level == 9 && gl_info->supported[EXT_GPU_SHADER4])
1502         level = 10;
1503
1504     return level;
1505 }
1506
1507 static enum wined3d_pci_device select_card_nvidia_binary(const struct wined3d_gl_info *gl_info,
1508         const char *gl_renderer)
1509 {
1510     UINT d3d_level = d3d_level_from_gl_info(gl_info);
1511     unsigned int i;
1512
1513     if (d3d_level >= 10)
1514     {
1515         static const struct
1516         {
1517             const char *renderer;
1518             enum wined3d_pci_device id;
1519         }
1520         cards[] =
1521         {
1522             {"GTX 580",     CARD_NVIDIA_GEFORCE_GTX580},    /* Geforce 500 - highend */
1523             {"GTX 570",     CARD_NVIDIA_GEFORCE_GTX570},    /* Geforce 500 - midend high */
1524             {"GTX 560 Ti",  CARD_NVIDIA_GEFORCE_GTX560TI},  /* Geforce 500 - midend */
1525             {"GTX 560",     CARD_NVIDIA_GEFORCE_GTX560},    /* Geforce 500 - midend */
1526             {"GT 555M",     CARD_NVIDIA_GEFORCE_GT555M},    /* Geforce 500 - midend mobile */
1527             {"GTX 550 Ti",  CARD_NVIDIA_GEFORCE_GTX550},    /* Geforce 500 - midend */
1528             {"GT 540M",     CARD_NVIDIA_GEFORCE_GT540M},    /* Geforce 500 - midend mobile */
1529             {"GTX 480",     CARD_NVIDIA_GEFORCE_GTX480},    /* Geforce 400 - highend */
1530             {"GTX 470",     CARD_NVIDIA_GEFORCE_GTX470},    /* Geforce 400 - midend high */
1531             {"GTX 465",     CARD_NVIDIA_GEFORCE_GTX465},    /* Geforce 400 - midend */
1532             {"GTX 460M",    CARD_NVIDIA_GEFORCE_GTX460M},   /* Geforce 400 - highend mobile */
1533             {"GTX 460",     CARD_NVIDIA_GEFORCE_GTX460},    /* Geforce 400 - midend */
1534             {"GTS 450",     CARD_NVIDIA_GEFORCE_GTS450},    /* Geforce 400 - midend low */
1535             {"GT 440",      CARD_NVIDIA_GEFORCE_GT440},     /* Geforce 400 - lowend */
1536             {"GT 430",      CARD_NVIDIA_GEFORCE_GT430},     /* Geforce 400 - lowend */
1537             {"GT 420",      CARD_NVIDIA_GEFORCE_GT420},     /* Geforce 400 - lowend */
1538             {"GT 330",      CARD_NVIDIA_GEFORCE_GT330},     /* Geforce 300 - highend */
1539             {"GTS 360M",    CARD_NVIDIA_GEFORCE_GTS350M},   /* Geforce 300 - highend mobile */
1540             {"GTS 350M",    CARD_NVIDIA_GEFORCE_GTS350M},   /* Geforce 300 - highend mobile */
1541             {"GT 330M",     CARD_NVIDIA_GEFORCE_GT325M},    /* Geforce 300 - midend mobile */
1542             {"GT 325M",     CARD_NVIDIA_GEFORCE_GT325M},    /* Geforce 300 - midend mobile */
1543             {"GT 320M",     CARD_NVIDIA_GEFORCE_GT320M},    /* Geforce 300 - midend mobile */
1544             {"GTX 295",     CARD_NVIDIA_GEFORCE_GTX280},    /* Geforce 200 - highend */
1545             {"GTX 285",     CARD_NVIDIA_GEFORCE_GTX280},    /* Geforce 200 - highend */
1546             {"GTX 280",     CARD_NVIDIA_GEFORCE_GTX280},    /* Geforce 200 - highend */
1547             {"GTX 275",     CARD_NVIDIA_GEFORCE_GTX275},    /* Geforce 200 - midend high */
1548             {"GTX 260",     CARD_NVIDIA_GEFORCE_GTX260},    /* Geforce 200 - midend */
1549             {"GT 240",      CARD_NVIDIA_GEFORCE_GT240},     /* Geforce 200 - midend */
1550             {"GT 220",      CARD_NVIDIA_GEFORCE_GT220},     /* Geforce 200 - lowend */
1551             {"Geforce 310", CARD_NVIDIA_GEFORCE_210},       /* Geforce 200 - lowend */
1552             {"Geforce 305", CARD_NVIDIA_GEFORCE_210},       /* Geforce 200 - lowend */
1553             {"Geforce 210", CARD_NVIDIA_GEFORCE_210},       /* Geforce 200 - lowend */
1554             {"G 210",       CARD_NVIDIA_GEFORCE_210},       /* Geforce 200 - lowend */
1555             {"GTS 250",     CARD_NVIDIA_GEFORCE_9800GT},    /* Geforce 9 - highend / Geforce 200 - midend */
1556             {"GTS 150",     CARD_NVIDIA_GEFORCE_9800GT},    /* Geforce 9 - highend / Geforce 200 - midend */
1557             {"9800",        CARD_NVIDIA_GEFORCE_9800GT},    /* Geforce 9 - highend / Geforce 200 - midend */
1558             {"GT 140",      CARD_NVIDIA_GEFORCE_9600GT},    /* Geforce 9 - midend */
1559             {"9600",        CARD_NVIDIA_GEFORCE_9600GT},    /* Geforce 9 - midend */
1560             {"GT 130",      CARD_NVIDIA_GEFORCE_9500GT},    /* Geforce 9 - midend low / Geforce 200 - low */
1561             {"GT 120",      CARD_NVIDIA_GEFORCE_9500GT},    /* Geforce 9 - midend low / Geforce 200 - low */
1562             {"9500",        CARD_NVIDIA_GEFORCE_9500GT},    /* Geforce 9 - midend low / Geforce 200 - low */
1563             {"9400",        CARD_NVIDIA_GEFORCE_9400GT},    /* Geforce 9 - lowend */
1564             {"9300",        CARD_NVIDIA_GEFORCE_9200},      /* Geforce 9 - lowend low */
1565             {"9200",        CARD_NVIDIA_GEFORCE_9200},      /* Geforce 9 - lowend low */
1566             {"9100",        CARD_NVIDIA_GEFORCE_9200},      /* Geforce 9 - lowend low */
1567             {"G 100",       CARD_NVIDIA_GEFORCE_9200},      /* Geforce 9 - lowend low */
1568             {"8800 GTX",    CARD_NVIDIA_GEFORCE_8800GTX},   /* Geforce 8 - highend high */
1569             {"8800",        CARD_NVIDIA_GEFORCE_8800GTS},   /* Geforce 8 - highend */
1570             {"8600 M",      CARD_NVIDIA_GEFORCE_8600MGT},   /* Geforce 8 - midend mobile */
1571             {"8700",        CARD_NVIDIA_GEFORCE_8600GT},    /* Geforce 8 - midend */
1572             {"8600",        CARD_NVIDIA_GEFORCE_8600GT},    /* Geforce 8 - midend */
1573             {"8500",        CARD_NVIDIA_GEFORCE_8400GS},    /* Geforce 8 - mid-lowend */
1574             {"8400",        CARD_NVIDIA_GEFORCE_8400GS},    /* Geforce 8 - mid-lowend */
1575             {"8300",        CARD_NVIDIA_GEFORCE_8300GS},    /* Geforce 8 - lowend */
1576             {"8200",        CARD_NVIDIA_GEFORCE_8300GS},    /* Geforce 8 - lowend */
1577             {"8100",        CARD_NVIDIA_GEFORCE_8300GS},    /* Geforce 8 - lowend */
1578         };
1579
1580         for (i = 0; i < sizeof(cards) / sizeof(*cards); ++i)
1581         {
1582             if (strstr(gl_renderer, cards[i].renderer))
1583                 return cards[i].id;
1584         }
1585
1586         /* Geforce8-compatible fall back if the GPU is not in the list yet */
1587         return CARD_NVIDIA_GEFORCE_8300GS;
1588     }
1589
1590     /* Both the GeforceFX, 6xxx and 7xxx series support D3D9. The last two types have more
1591      * shader capabilities, so we use the shader capabilities to distinguish between FX and 6xxx/7xxx.
1592      */
1593     if (d3d_level >= 9 && gl_info->supported[NV_VERTEX_PROGRAM3])
1594     {
1595         static const struct
1596         {
1597             const char *renderer;
1598             enum wined3d_pci_device id;
1599         }
1600         cards[] =
1601         {
1602             {"Quadro FX 5", CARD_NVIDIA_GEFORCE_7800GT},    /* Geforce 7 - highend */
1603             {"Quadro FX 4", CARD_NVIDIA_GEFORCE_7800GT},    /* Geforce 7 - highend */
1604             {"7950",        CARD_NVIDIA_GEFORCE_7800GT},    /* Geforce 7 - highend */
1605             {"7900",        CARD_NVIDIA_GEFORCE_7800GT},    /* Geforce 7 - highend */
1606             {"7800",        CARD_NVIDIA_GEFORCE_7800GT},    /* Geforce 7 - highend */
1607             {"7700",        CARD_NVIDIA_GEFORCE_7600},      /* Geforce 7 - midend */
1608             {"7600",        CARD_NVIDIA_GEFORCE_7600},      /* Geforce 7 - midend */
1609             {"7400",        CARD_NVIDIA_GEFORCE_7400},      /* Geforce 7 - lower medium */
1610             {"7300",        CARD_NVIDIA_GEFORCE_7300},      /* Geforce 7 - lowend */
1611             {"6800",        CARD_NVIDIA_GEFORCE_6800},      /* Geforce 6 - highend */
1612             {"6700",        CARD_NVIDIA_GEFORCE_6600GT},    /* Geforce 6 - midend */
1613             {"6610",        CARD_NVIDIA_GEFORCE_6600GT},    /* Geforce 6 - midend */
1614             {"6600",        CARD_NVIDIA_GEFORCE_6600GT},    /* Geforce 6 - midend */
1615         };
1616
1617         for (i = 0; i < sizeof(cards) / sizeof(*cards); ++i)
1618         {
1619             if (strstr(gl_renderer, cards[i].renderer))
1620                 return cards[i].id;
1621         }
1622
1623         /* Geforce 6/7 - lowend */
1624         return CARD_NVIDIA_GEFORCE_6200; /* Geforce 6100/6150/6200/7300/7400/7500 */
1625     }
1626
1627     if (d3d_level >= 9)
1628     {
1629         /* GeforceFX - highend */
1630         if (strstr(gl_renderer, "5800")
1631                 || strstr(gl_renderer, "5900")
1632                 || strstr(gl_renderer, "5950")
1633                 || strstr(gl_renderer, "Quadro FX"))
1634         {
1635             return CARD_NVIDIA_GEFORCEFX_5800;
1636         }
1637
1638         /* GeforceFX - midend */
1639         if (strstr(gl_renderer, "5600")
1640                 || strstr(gl_renderer, "5650")
1641                 || strstr(gl_renderer, "5700")
1642                 || strstr(gl_renderer, "5750"))
1643         {
1644             return CARD_NVIDIA_GEFORCEFX_5600;
1645         }
1646
1647         /* GeforceFX - lowend */
1648         return CARD_NVIDIA_GEFORCEFX_5200; /* GeforceFX 5100/5200/5250/5300/5500 */
1649     }
1650
1651     if (d3d_level >= 8)
1652     {
1653         if (strstr(gl_renderer, "GeForce4 Ti") || strstr(gl_renderer, "Quadro4"))
1654         {
1655             return CARD_NVIDIA_GEFORCE4_TI4200; /* Geforce4 Ti4200/Ti4400/Ti4600/Ti4800, Quadro4 */
1656         }
1657
1658         return CARD_NVIDIA_GEFORCE3; /* Geforce3 standard/Ti200/Ti500, Quadro DCC */
1659     }
1660
1661     if (d3d_level >= 7)
1662     {
1663         if (strstr(gl_renderer, "GeForce4 MX"))
1664         {
1665             return CARD_NVIDIA_GEFORCE4_MX; /* MX420/MX440/MX460/MX4000 */
1666         }
1667
1668         if (strstr(gl_renderer, "GeForce2 MX") || strstr(gl_renderer, "Quadro2 MXR"))
1669         {
1670             return CARD_NVIDIA_GEFORCE2_MX; /* Geforce2 standard/MX100/MX200/MX400, Quadro2 MXR */
1671         }
1672
1673         if (strstr(gl_renderer, "GeForce2") || strstr(gl_renderer, "Quadro2"))
1674         {
1675             return CARD_NVIDIA_GEFORCE2; /* Geforce2 GTS/Pro/Ti/Ultra, Quadro2 */
1676         }
1677
1678         return CARD_NVIDIA_GEFORCE; /* Geforce 256/DDR, Quadro */
1679     }
1680
1681     if (strstr(gl_renderer, "TNT2"))
1682     {
1683         return CARD_NVIDIA_RIVA_TNT2; /* Riva TNT2 standard/M64/Pro/Ultra */
1684     }
1685
1686     return CARD_NVIDIA_RIVA_TNT; /* Riva TNT, Vanta */
1687 }
1688
1689 static enum wined3d_pci_device select_card_amd_binary(const struct wined3d_gl_info *gl_info,
1690         const char *gl_renderer)
1691 {
1692     UINT d3d_level = d3d_level_from_gl_info(gl_info);
1693
1694     /* See http://developer.amd.com/drivers/pc_vendor_id/Pages/default.aspx
1695      *
1696      * Beware: renderer string do not match exact card model,
1697      * eg HD 4800 is returned for multiple cards, even for RV790 based ones. */
1698     if (d3d_level >= 10)
1699     {
1700         unsigned int i;
1701
1702         static const struct
1703         {
1704             const char *renderer;
1705             enum wined3d_pci_device id;
1706         }
1707         cards[] =
1708         {
1709             /* Northern Islands */
1710             {"HD 6900", CARD_AMD_RADEON_HD6900},
1711             {"HD 6800", CARD_AMD_RADEON_HD6800},
1712             {"HD 6630M",CARD_AMD_RADEON_HD6600M},
1713             {"HD 6600M",CARD_AMD_RADEON_HD6600M},
1714             {"HD 6600", CARD_AMD_RADEON_HD6600},
1715             {"HD 6500M",CARD_AMD_RADEON_HD6600M},
1716             {"HD 6500", CARD_AMD_RADEON_HD6600},
1717             {"HD 6400", CARD_AMD_RADEON_HD6400},
1718             {"HD 6300", CARD_AMD_RADEON_HD6300},
1719             {"HD 6200", CARD_AMD_RADEON_HD6300},
1720             /* Evergreen */
1721             {"HD 5870", CARD_AMD_RADEON_HD5800},    /* Radeon EG CYPRESS PRO */
1722             {"HD 5850", CARD_AMD_RADEON_HD5800},    /* Radeon EG CYPRESS XT */
1723             {"HD 5800", CARD_AMD_RADEON_HD5800},    /* Radeon EG CYPRESS HD58xx generic renderer string */
1724             {"HD 5770", CARD_AMD_RADEON_HD5700},    /* Radeon EG JUNIPER XT */
1725             {"HD 5750", CARD_AMD_RADEON_HD5700},    /* Radeon EG JUNIPER LE */
1726             {"HD 5700", CARD_AMD_RADEON_HD5700},    /* Radeon EG JUNIPER HD57xx generic renderer string */
1727             {"HD 5670", CARD_AMD_RADEON_HD5600},    /* Radeon EG REDWOOD XT */
1728             {"HD 5570", CARD_AMD_RADEON_HD5600},    /* Radeon EG REDWOOD PRO mapped to HD5600 series */
1729             {"HD 5550", CARD_AMD_RADEON_HD5600},    /* Radeon EG REDWOOD LE mapped to HD5600 series */
1730             {"HD 5450", CARD_AMD_RADEON_HD5400},    /* Radeon EG CEDAR PRO */
1731             /* R700 */
1732             {"HD 4890", CARD_AMD_RADEON_HD4800},    /* Radeon RV790 */
1733             {"HD 4870", CARD_AMD_RADEON_HD4800},    /* Radeon RV770 */
1734             {"HD 4850", CARD_AMD_RADEON_HD4800},    /* Radeon RV770 */
1735             {"HD 4830", CARD_AMD_RADEON_HD4800},    /* Radeon RV770 */
1736             {"HD 4800", CARD_AMD_RADEON_HD4800},    /* Radeon RV7xx HD48xx generic renderer string */
1737             {"HD 4770", CARD_AMD_RADEON_HD4700},    /* Radeon RV740 */
1738             {"HD 4700", CARD_AMD_RADEON_HD4700},    /* Radeon RV7xx HD47xx generic renderer string */
1739             {"HD 4670", CARD_AMD_RADEON_HD4600},    /* Radeon RV730 */
1740             {"HD 4650", CARD_AMD_RADEON_HD4600},    /* Radeon RV730 */
1741             {"HD 4600", CARD_AMD_RADEON_HD4600},    /* Radeon RV730 */
1742             {"HD 4550", CARD_AMD_RADEON_HD4350},    /* Radeon RV710 */
1743             {"HD 4350", CARD_AMD_RADEON_HD4350},    /* Radeon RV710 */
1744             /* R600/R700 integrated */
1745             {"HD 3300", CARD_AMD_RADEON_HD3200},
1746             {"HD 3200", CARD_AMD_RADEON_HD3200},
1747             {"HD 3100", CARD_AMD_RADEON_HD3200},
1748             /* R600 */
1749             {"HD 3870", CARD_AMD_RADEON_HD2900},    /* HD2900/HD3800 - highend */
1750             {"HD 3850", CARD_AMD_RADEON_HD2900},    /* HD2900/HD3800 - highend */
1751             {"HD 2900", CARD_AMD_RADEON_HD2900},    /* HD2900/HD3800 - highend */
1752             {"HD 3830", CARD_AMD_RADEON_HD2600},    /* China-only midend */
1753             {"HD 3690", CARD_AMD_RADEON_HD2600},    /* HD2600/HD3600 - midend */
1754             {"HD 3650", CARD_AMD_RADEON_HD2600},    /* HD2600/HD3600 - midend */
1755             {"HD 2600", CARD_AMD_RADEON_HD2600},    /* HD2600/HD3600 - midend */
1756             {"HD 3470", CARD_AMD_RADEON_HD2350},    /* HD2350/HD2400/HD3400 - lowend */
1757             {"HD 3450", CARD_AMD_RADEON_HD2350},    /* HD2350/HD2400/HD3400 - lowend */
1758             {"HD 3430", CARD_AMD_RADEON_HD2350},    /* HD2350/HD2400/HD3400 - lowend */
1759             {"HD 3400", CARD_AMD_RADEON_HD2350},    /* HD2350/HD2400/HD3400 - lowend */
1760             {"HD 2400", CARD_AMD_RADEON_HD2350},    /* HD2350/HD2400/HD3400 - lowend */
1761             {"HD 2350", CARD_AMD_RADEON_HD2350},    /* HD2350/HD2400/HD3400 - lowend */
1762         };
1763
1764         for (i = 0; i < sizeof(cards) / sizeof(*cards); ++i)
1765         {
1766             if (strstr(gl_renderer, cards[i].renderer))
1767                 return cards[i].id;
1768         }
1769
1770         /* Default for when no GPU has been found */
1771         return CARD_AMD_RADEON_HD3200;
1772     }
1773
1774     if (d3d_level >= 9)
1775     {
1776         /* Radeon R5xx */
1777         if (strstr(gl_renderer, "X1600")
1778                 || strstr(gl_renderer, "X1650")
1779                 || strstr(gl_renderer, "X1800")
1780                 || strstr(gl_renderer, "X1900")
1781                 || strstr(gl_renderer, "X1950"))
1782         {
1783             return CARD_AMD_RADEON_X1600;
1784         }
1785
1786         /* Radeon R4xx + X1300/X1400/X1450/X1550/X2300/X2500/HD2300 (lowend R5xx)
1787          * Note X2300/X2500/HD2300 are R5xx GPUs with a 2xxx naming but they are still DX9-only */
1788         if (strstr(gl_renderer, "X700")
1789                 || strstr(gl_renderer, "X800")
1790                 || strstr(gl_renderer, "X850")
1791                 || strstr(gl_renderer, "X1300")
1792                 || strstr(gl_renderer, "X1400")
1793                 || strstr(gl_renderer, "X1450")
1794                 || strstr(gl_renderer, "X1550")
1795                 || strstr(gl_renderer, "X2300")
1796                 || strstr(gl_renderer, "X2500")
1797                 || strstr(gl_renderer, "HD 2300")
1798                 )
1799         {
1800             return CARD_AMD_RADEON_X700;
1801         }
1802
1803         /* Radeon Xpress Series - onboard, DX9b, Shader 2.0, 300-400MHz */
1804         if (strstr(gl_renderer, "Radeon Xpress"))
1805         {
1806             return CARD_AMD_RADEON_XPRESS_200M;
1807         }
1808
1809         /* Radeon R3xx */
1810         return CARD_AMD_RADEON_9500; /* Radeon 9500/9550/9600/9700/9800/X300/X550/X600 */
1811     }
1812
1813     if (d3d_level >= 8)
1814         return CARD_AMD_RADEON_8500; /* Radeon 8500/9000/9100/9200/9300 */
1815
1816     if (d3d_level >= 7)
1817         return CARD_AMD_RADEON_7200; /* Radeon 7000/7100/7200/7500 */
1818
1819     return CARD_AMD_RAGE_128PRO;
1820 }
1821
1822 static enum wined3d_pci_device select_card_intel(const struct wined3d_gl_info *gl_info,
1823         const char *gl_renderer)
1824 {
1825     unsigned int i;
1826
1827     static const struct
1828     {
1829         const char *renderer;
1830         enum wined3d_pci_device id;
1831     }
1832     cards[] =
1833     {
1834         /* Ivybridge */
1835         {"Ivybridge Server",            CARD_INTEL_IVBS},
1836         {"Ivybridge Mobile",            CARD_INTEL_IVBM},
1837         {"Ivybridge Desktop",           CARD_INTEL_IVBD},
1838         /* Sandybridge */
1839         {"Sandybridge Server",          CARD_INTEL_SNBS},
1840         {"Sandybridge Mobile",          CARD_INTEL_SNBM},
1841         {"Sandybridge Desktop",         CARD_INTEL_SNBD},
1842         /* Ironlake */
1843         {"Ironlake Mobile",             CARD_INTEL_ILKM},
1844         {"Ironlake Desktop",            CARD_INTEL_ILKD},
1845         /* G4x */
1846         {"B43",                         CARD_INTEL_B43},
1847         {"G41",                         CARD_INTEL_G41},
1848         {"G45",                         CARD_INTEL_G45},
1849         {"Q45",                         CARD_INTEL_Q45},
1850         {"Integrated Graphics Device",  CARD_INTEL_IGD},
1851         {"GM45",                        CARD_INTEL_GM45},
1852         /* i965 */
1853         {"965GME",                      CARD_INTEL_965GME},
1854         {"965GM",                       CARD_INTEL_965GM},
1855         {"X3100",                       CARD_INTEL_965GM},  /* MacOS */
1856         {"946GZ",                       CARD_INTEL_946GZ},
1857         {"965G",                        CARD_INTEL_965G},
1858         {"965Q",                        CARD_INTEL_965Q},
1859         /* i945 */
1860         {"Pineview M",                  CARD_INTEL_PNVM},
1861         {"Pineview G",                  CARD_INTEL_PNVG},
1862         {"IGD",                         CARD_INTEL_PNVG},
1863         {"Q33",                         CARD_INTEL_Q33},
1864         {"G33",                         CARD_INTEL_G33},
1865         {"Q35",                         CARD_INTEL_Q35},
1866         {"945GME",                      CARD_INTEL_945GME},
1867         {"945GM",                       CARD_INTEL_945GM},
1868         {"GMA 950",                     CARD_INTEL_945GM},  /* MacOS */
1869         {"945G",                        CARD_INTEL_945G},
1870         /* i915 */
1871         {"915GM",                       CARD_INTEL_915GM},
1872         {"E7221G",                      CARD_INTEL_E7221G},
1873         {"915G",                        CARD_INTEL_915G},
1874         /* i8xx */
1875         {"865G",                        CARD_INTEL_865G},
1876         {"845G",                        CARD_INTEL_845G},
1877         {"855GM",                       CARD_INTEL_855GM},
1878         {"830M",                        CARD_INTEL_830M},
1879     };
1880
1881     for (i = 0; i < sizeof(cards) / sizeof(*cards); ++i)
1882     {
1883         if (strstr(gl_renderer, cards[i].renderer))
1884             return cards[i].id;
1885     }
1886
1887     return CARD_INTEL_915G;
1888 }
1889
1890 static enum wined3d_pci_device select_card_amd_mesa(const struct wined3d_gl_info *gl_info,
1891         const char *gl_renderer)
1892 {
1893     UINT d3d_level;
1894     unsigned int i;
1895
1896     /* See http://developer.amd.com/drivers/pc_vendor_id/Pages/default.aspx
1897      *
1898      * Beware: renderer string do not match exact card model,
1899      * eg HD 4800 is returned for multiple cards, even for RV790 based ones. */
1900     if (strstr(gl_renderer, "Gallium"))
1901     {
1902         /* 20101109 - These are never returned by current Gallium radeon
1903          * drivers: R700, RV790, R680, RV535, RV516, R410, RS485, RV360, RV351.
1904          *
1905          * These are returned but not handled: RC410, RV380. */
1906         static const struct
1907         {
1908             const char *renderer;
1909             enum wined3d_pci_device id;
1910         }
1911         cards[] =
1912         {
1913             /* Northern Islands */
1914             {"CAYMAN",  CARD_AMD_RADEON_HD6900},
1915             {"BARTS",   CARD_AMD_RADEON_HD6800},
1916             {"TURKS",   CARD_AMD_RADEON_HD6600},
1917             {"SUMO2",   CARD_AMD_RADEON_HD6410D},   /* SUMO2 first, because we do a strstr(). */
1918             {"SUMO",    CARD_AMD_RADEON_HD6550D},
1919             {"CAICOS",  CARD_AMD_RADEON_HD6400},
1920             {"PALM",    CARD_AMD_RADEON_HD6300},
1921             /* Evergreen */
1922             {"HEMLOCK", CARD_AMD_RADEON_HD5900},
1923             {"CYPRESS", CARD_AMD_RADEON_HD5800},
1924             {"JUNIPER", CARD_AMD_RADEON_HD5700},
1925             {"REDWOOD", CARD_AMD_RADEON_HD5600},
1926             {"CEDAR",   CARD_AMD_RADEON_HD5400},
1927             /* R700 */
1928             {"R700",    CARD_AMD_RADEON_HD4800},    /* HD4800 - highend */
1929             {"RV790",   CARD_AMD_RADEON_HD4800},
1930             {"RV770",   CARD_AMD_RADEON_HD4800},
1931             {"RV740",   CARD_AMD_RADEON_HD4700},    /* HD4700 - midend */
1932             {"RV730",   CARD_AMD_RADEON_HD4600},    /* HD4600 - midend */
1933             {"RV710",   CARD_AMD_RADEON_HD4350},    /* HD4500/HD4350 - lowend */
1934             /* R600/R700 integrated */
1935             {"RS880",   CARD_AMD_RADEON_HD3200},
1936             {"RS780",   CARD_AMD_RADEON_HD3200},
1937             /* R600 */
1938             {"R680",    CARD_AMD_RADEON_HD2900},    /* HD2900/HD3800 - highend */
1939             {"R600",    CARD_AMD_RADEON_HD2900},
1940             {"RV670",   CARD_AMD_RADEON_HD2900},
1941             {"RV635",   CARD_AMD_RADEON_HD2600},    /* HD2600/HD3600 - midend; HD3830 is China-only midend */
1942             {"RV630",   CARD_AMD_RADEON_HD2600},
1943             {"RV620",   CARD_AMD_RADEON_HD2350},    /* HD2350/HD2400/HD3400 - lowend */
1944             {"RV610",   CARD_AMD_RADEON_HD2350},
1945             /* R500 */
1946             {"R580",    CARD_AMD_RADEON_X1600},
1947             {"R520",    CARD_AMD_RADEON_X1600},
1948             {"RV570",   CARD_AMD_RADEON_X1600},
1949             {"RV560",   CARD_AMD_RADEON_X1600},
1950             {"RV535",   CARD_AMD_RADEON_X1600},
1951             {"RV530",   CARD_AMD_RADEON_X1600},
1952             {"RV516",   CARD_AMD_RADEON_X700},      /* X700 is actually R400. */
1953             {"RV515",   CARD_AMD_RADEON_X700},
1954             /* R400 */
1955             {"R481",    CARD_AMD_RADEON_X700},
1956             {"R480",    CARD_AMD_RADEON_X700},
1957             {"R430",    CARD_AMD_RADEON_X700},
1958             {"R423",    CARD_AMD_RADEON_X700},
1959             {"R420",    CARD_AMD_RADEON_X700},
1960             {"R410",    CARD_AMD_RADEON_X700},
1961             {"RV410",   CARD_AMD_RADEON_X700},
1962             /* Radeon Xpress - onboard, DX9b, Shader 2.0, 300-400MHz */
1963             {"RS740",   CARD_AMD_RADEON_XPRESS_200M},
1964             {"RS690",   CARD_AMD_RADEON_XPRESS_200M},
1965             {"RS600",   CARD_AMD_RADEON_XPRESS_200M},
1966             {"RS485",   CARD_AMD_RADEON_XPRESS_200M},
1967             {"RS482",   CARD_AMD_RADEON_XPRESS_200M},
1968             {"RS480",   CARD_AMD_RADEON_XPRESS_200M},
1969             {"RS400",   CARD_AMD_RADEON_XPRESS_200M},
1970             /* R300 */
1971             {"R360",    CARD_AMD_RADEON_9500},
1972             {"R350",    CARD_AMD_RADEON_9500},
1973             {"R300",    CARD_AMD_RADEON_9500},
1974             {"RV370",   CARD_AMD_RADEON_9500},
1975             {"RV360",   CARD_AMD_RADEON_9500},
1976             {"RV351",   CARD_AMD_RADEON_9500},
1977             {"RV350",   CARD_AMD_RADEON_9500},
1978         };
1979
1980         for (i = 0; i < sizeof(cards) / sizeof(*cards); ++i)
1981         {
1982             if (strstr(gl_renderer, cards[i].renderer))
1983                 return cards[i].id;
1984         }
1985     }
1986
1987     d3d_level = d3d_level_from_gl_info(gl_info);
1988     if (d3d_level >= 10)
1989         return CARD_AMD_RADEON_HD2600;
1990
1991     if (d3d_level >= 9)
1992     {
1993         static const struct
1994         {
1995             const char *renderer;
1996             enum wined3d_pci_device id;
1997         }
1998         cards[] =
1999         {
2000             /* R700 */
2001             {"(R700",   CARD_AMD_RADEON_HD4800},    /* HD4800 - highend */
2002             {"(RV790",  CARD_AMD_RADEON_HD4800},
2003             {"(RV770",  CARD_AMD_RADEON_HD4800},
2004             {"(RV740",  CARD_AMD_RADEON_HD4700},    /* HD4700 - midend */
2005             {"(RV730",  CARD_AMD_RADEON_HD4600},    /* HD4600 - midend */
2006             {"(RV710",  CARD_AMD_RADEON_HD4350},    /* HD4500/HD4350 - lowend */
2007             /* R600/R700 integrated */
2008             {"RS880",   CARD_AMD_RADEON_HD3200},
2009             {"RS780",   CARD_AMD_RADEON_HD3200},
2010             /* R600 */
2011             {"(R680",   CARD_AMD_RADEON_HD2900},    /* HD2900/HD3800 - highend */
2012             {"(R600",   CARD_AMD_RADEON_HD2900},
2013             {"(RV670",  CARD_AMD_RADEON_HD2900},
2014             {"(RV635",  CARD_AMD_RADEON_HD2600},    /* HD2600/HD3600 - midend; HD3830 is China-only midend */
2015             {"(RV630",  CARD_AMD_RADEON_HD2600},
2016             {"(RV620",  CARD_AMD_RADEON_HD2350},    /* HD2300/HD2400/HD3400 - lowend */
2017             {"(RV610",  CARD_AMD_RADEON_HD2350},
2018         };
2019
2020         for (i = 0; i < sizeof(cards) / sizeof(*cards); ++i)
2021         {
2022             if (strstr(gl_renderer, cards[i].renderer))
2023                 return cards[i].id;
2024         }
2025
2026         return CARD_AMD_RADEON_9500;
2027     }
2028
2029     if (d3d_level >= 8)
2030         return CARD_AMD_RADEON_8500; /* Radeon 8500/9000/9100/9200/9300 */
2031
2032     if (d3d_level >= 7)
2033         return CARD_AMD_RADEON_7200; /* Radeon 7000/7100/7200/7500 */
2034
2035     return CARD_AMD_RAGE_128PRO;
2036 }
2037
2038 static enum wined3d_pci_device select_card_nvidia_mesa(const struct wined3d_gl_info *gl_info,
2039         const char *gl_renderer)
2040 {
2041     UINT d3d_level;
2042
2043     if (strstr(gl_renderer, "Gallium"))
2044     {
2045         unsigned int i;
2046
2047         static const struct
2048         {
2049             const char *renderer;
2050             enum wined3d_pci_device id;
2051         }
2052         cards[] =
2053         {
2054             {"NVC8",    CARD_NVIDIA_GEFORCE_GTX570},
2055             {"NVC4",    CARD_NVIDIA_GEFORCE_GTX460},
2056             {"NVC3",    CARD_NVIDIA_GEFORCE_GT440},
2057             {"NVC0",    CARD_NVIDIA_GEFORCE_GTX480},
2058             {"NVAF",    CARD_NVIDIA_GEFORCE_GT320M},
2059             {"NVAC",    CARD_NVIDIA_GEFORCE_8200},
2060             {"NVAA",    CARD_NVIDIA_GEFORCE_8200},
2061             {"NVA8",    CARD_NVIDIA_GEFORCE_210},
2062             {"NVA5",    CARD_NVIDIA_GEFORCE_GT220},
2063             {"NVA3",    CARD_NVIDIA_GEFORCE_GT240},
2064             {"NVA0",    CARD_NVIDIA_GEFORCE_GTX280},
2065             {"NV98",    CARD_NVIDIA_GEFORCE_9200},
2066             {"NV96",    CARD_NVIDIA_GEFORCE_9400GT},
2067             {"NV94",    CARD_NVIDIA_GEFORCE_9600GT},
2068             {"NV92",    CARD_NVIDIA_GEFORCE_9800GT},
2069             {"NV86",    CARD_NVIDIA_GEFORCE_8500GT},
2070             {"NV84",    CARD_NVIDIA_GEFORCE_8600GT},
2071             {"NV68",    CARD_NVIDIA_GEFORCE_6200},      /* 7050 */
2072             {"NV67",    CARD_NVIDIA_GEFORCE_6200},      /* 7000M */
2073             {"NV63",    CARD_NVIDIA_GEFORCE_6200},      /* 7100 */
2074             {"NV50",    CARD_NVIDIA_GEFORCE_8800GTX},
2075             {"NV4E",    CARD_NVIDIA_GEFORCE_6200},      /* 6100 Go / 6150 Go */
2076             {"NV4C",    CARD_NVIDIA_GEFORCE_6200},      /* 6150SE */
2077             {"NV4B",    CARD_NVIDIA_GEFORCE_7600},
2078             {"NV4A",    CARD_NVIDIA_GEFORCE_6200},
2079             {"NV49",    CARD_NVIDIA_GEFORCE_7800GT},    /* 7900 */
2080             {"NV47",    CARD_NVIDIA_GEFORCE_7800GT},
2081             {"NV46",    CARD_NVIDIA_GEFORCE_7400},
2082             {"NV45",    CARD_NVIDIA_GEFORCE_6800},
2083             {"NV44",    CARD_NVIDIA_GEFORCE_6200},
2084             {"NV43",    CARD_NVIDIA_GEFORCE_6600GT},
2085             {"NV42",    CARD_NVIDIA_GEFORCE_6800},
2086             {"NV41",    CARD_NVIDIA_GEFORCE_6800},
2087             {"NV40",    CARD_NVIDIA_GEFORCE_6800},
2088             {"NV38",    CARD_NVIDIA_GEFORCEFX_5800},    /* FX 5950 Ultra */
2089             {"NV36",    CARD_NVIDIA_GEFORCEFX_5800},    /* FX 5700/5750 */
2090             {"NV35",    CARD_NVIDIA_GEFORCEFX_5800},    /* FX 5900 */
2091             {"NV34",    CARD_NVIDIA_GEFORCEFX_5200},
2092             {"NV31",    CARD_NVIDIA_GEFORCEFX_5600},
2093             {"NV30",    CARD_NVIDIA_GEFORCEFX_5800},
2094             {"NV28",    CARD_NVIDIA_GEFORCE4_TI4200},
2095             {"NV25",    CARD_NVIDIA_GEFORCE4_TI4200},
2096             {"NV20",    CARD_NVIDIA_GEFORCE3},
2097             {"NV1F",    CARD_NVIDIA_GEFORCE4_MX},       /* GF4 MX IGP */
2098             {"NV1A",    CARD_NVIDIA_GEFORCE2},          /* GF2 IGP */
2099             {"NV18",    CARD_NVIDIA_GEFORCE4_MX},
2100             {"NV17",    CARD_NVIDIA_GEFORCE4_MX},
2101             {"NV16",    CARD_NVIDIA_GEFORCE2},
2102             {"NV15",    CARD_NVIDIA_GEFORCE2},
2103             {"NV11",    CARD_NVIDIA_GEFORCE2_MX},
2104             {"NV10",    CARD_NVIDIA_GEFORCE},
2105             {"NV05",    CARD_NVIDIA_RIVA_TNT2},
2106             {"NV04",    CARD_NVIDIA_RIVA_TNT},
2107             {"NV03",    CARD_NVIDIA_RIVA_128},
2108         };
2109
2110         for (i = 0; i < sizeof(cards) / sizeof(*cards); ++i)
2111         {
2112             if (strstr(gl_renderer, cards[i].renderer))
2113                 return cards[i].id;
2114         }
2115     }
2116
2117     FIXME_(d3d_caps)("Unknown renderer %s.\n", debugstr_a(gl_renderer));
2118
2119     d3d_level = d3d_level_from_gl_info(gl_info);
2120     if (d3d_level >= 9)
2121         return CARD_NVIDIA_GEFORCEFX_5600;
2122     if (d3d_level >= 8)
2123         return CARD_NVIDIA_GEFORCE3;
2124     if (d3d_level >= 7)
2125         return CARD_NVIDIA_GEFORCE;
2126     if (d3d_level >= 6)
2127         return CARD_NVIDIA_RIVA_TNT;
2128     return CARD_NVIDIA_RIVA_128;
2129 }
2130
2131
2132 struct vendor_card_selection
2133 {
2134     enum wined3d_gl_vendor gl_vendor;
2135     enum wined3d_pci_vendor card_vendor;
2136     const char *description;        /* Description of the card selector i.e. Apple OS/X Intel */
2137     enum wined3d_pci_device (*select_card)(const struct wined3d_gl_info *gl_info, const char *gl_renderer);
2138 };
2139
2140 static const struct vendor_card_selection vendor_card_select_table[] =
2141 {
2142     {GL_VENDOR_NVIDIA, HW_VENDOR_NVIDIA,  "Nvidia binary driver",     select_card_nvidia_binary},
2143     {GL_VENDOR_APPLE,  HW_VENDOR_NVIDIA,  "Apple OSX NVidia binary driver",   select_card_nvidia_binary},
2144     {GL_VENDOR_APPLE,  HW_VENDOR_AMD,     "Apple OSX AMD/ATI binary driver",  select_card_amd_binary},
2145     {GL_VENDOR_APPLE,  HW_VENDOR_INTEL,   "Apple OSX Intel binary driver",    select_card_intel},
2146     {GL_VENDOR_FGLRX,  HW_VENDOR_AMD,     "AMD/ATI binary driver",    select_card_amd_binary},
2147     {GL_VENDOR_MESA,   HW_VENDOR_AMD,     "Mesa AMD/ATI driver",      select_card_amd_mesa},
2148     {GL_VENDOR_MESA,   HW_VENDOR_NVIDIA,  "Mesa Nouveau driver",      select_card_nvidia_mesa},
2149     {GL_VENDOR_MESA,   HW_VENDOR_INTEL,   "Mesa Intel driver",        select_card_intel},
2150     {GL_VENDOR_INTEL,  HW_VENDOR_INTEL,   "Mesa Intel driver",        select_card_intel}
2151 };
2152
2153
2154 static enum wined3d_pci_device wined3d_guess_card(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
2155         enum wined3d_gl_vendor *gl_vendor, enum wined3d_pci_vendor *card_vendor)
2156 {
2157     UINT d3d_level;
2158
2159     /* Above is a list of Nvidia and ATI GPUs. Both vendors have dozens of
2160      * different GPUs with roughly the same features. In most cases GPUs from a
2161      * certain family differ in clockspeeds, the amount of video memory and the
2162      * number of shader pipelines.
2163      *
2164      * A Direct3D device object contains the PCI id (vendor + device) of the
2165      * videocard which is used for rendering. Various applications use this
2166      * information to get a rough estimation of the features of the card and
2167      * some might use it for enabling 3d effects only on certain types of
2168      * videocards. In some cases games might even use it to work around bugs
2169      * which happen on certain videocards/driver combinations. The problem is
2170      * that OpenGL only exposes a rendering string containing the name of the
2171      * videocard and not the PCI id.
2172      *
2173      * Various games depend on the PCI id, so somehow we need to provide one.
2174      * A simple option is to parse the renderer string and translate this to
2175      * the right PCI id. This is a lot of work because there are more than 200
2176      * GPUs just for Nvidia. Various cards share the same renderer string, so
2177      * the amount of code might be 'small' but there are quite a number of
2178      * exceptions which would make this a pain to maintain. Another way would
2179      * be to query the PCI id from the operating system (assuming this is the
2180      * videocard which is used for rendering which is not always the case).
2181      * This would work but it is not very portable. Second it would not work
2182      * well in, let's say, a remote X situation in which the amount of 3d
2183      * features which can be used is limited.
2184      *
2185      * As said most games only use the PCI id to get an indication of the
2186      * capabilities of the card. It doesn't really matter if the given id is
2187      * the correct one if we return the id of a card with similar 3d features.
2188      *
2189      * The code below checks the OpenGL capabilities of a videocard and matches
2190      * that to a certain level of Direct3D functionality. Once a card passes
2191      * the Direct3D9 check, we know that the card (in case of Nvidia) is at
2192      * least a GeforceFX. To give a better estimate we do a basic check on the
2193      * renderer string but if that won't pass we return a default card. This
2194      * way is better than maintaining a full card database as even without a
2195      * full database we can return a card with similar features. Second the
2196      * size of the database can be made quite small because when you know what
2197      * type of 3d functionality a card has, you know to which GPU family the
2198      * GPU must belong. Because of this you only have to check a small part of
2199      * the renderer string to distinguishes between different models from that
2200      * family.
2201      *
2202      * The code also selects a default amount of video memory which we will
2203      * use for an estimation of the amount of free texture memory. In case of
2204      * real D3D the amount of texture memory includes video memory and system
2205      * memory (to be specific AGP memory or in case of PCIE TurboCache /
2206      * HyperMemory). We don't know how much system memory can be addressed by
2207      * the system but we can make a reasonable estimation about the amount of
2208      * video memory. If the value is slightly wrong it doesn't matter as we
2209      * didn't include AGP-like memory which makes the amount of addressable
2210      * memory higher and second OpenGL isn't that critical it moves to system
2211      * memory behind our backs if really needed. Note that the amount of video
2212      * memory can be overruled using a registry setting. */
2213
2214     int i;
2215
2216     for (i = 0; i < (sizeof(vendor_card_select_table) / sizeof(*vendor_card_select_table)); ++i)
2217     {
2218         if ((vendor_card_select_table[i].gl_vendor != *gl_vendor)
2219             || (vendor_card_select_table[i].card_vendor != *card_vendor))
2220                 continue;
2221         TRACE_(d3d_caps)("Applying card_selector \"%s\".\n", vendor_card_select_table[i].description);
2222         return vendor_card_select_table[i].select_card(gl_info, gl_renderer);
2223     }
2224
2225     FIXME_(d3d_caps)("No card selector available for GL vendor %#x and card vendor %04x (using GL_RENDERER %s).\n",
2226             *gl_vendor, *card_vendor, debugstr_a(gl_renderer));
2227
2228     /* Default to generic Nvidia hardware based on the supported OpenGL extensions. The choice
2229      * for Nvidia was because the hardware and drivers they make are of good quality. This makes
2230      * them a good generic choice. */
2231     *card_vendor = HW_VENDOR_NVIDIA;
2232     d3d_level = d3d_level_from_gl_info(gl_info);
2233     if (d3d_level >= 9)
2234         return CARD_NVIDIA_GEFORCEFX_5600;
2235     if (d3d_level >= 8)
2236         return CARD_NVIDIA_GEFORCE3;
2237     if (d3d_level >= 7)
2238         return CARD_NVIDIA_GEFORCE;
2239     if (d3d_level >= 6)
2240         return CARD_NVIDIA_RIVA_TNT;
2241     return CARD_NVIDIA_RIVA_128;
2242 }
2243
2244 static const struct fragment_pipeline *select_fragment_implementation(const struct wined3d_gl_info *gl_info)
2245 {
2246     int vs_selected_mode, ps_selected_mode;
2247
2248     select_shader_mode(gl_info, &ps_selected_mode, &vs_selected_mode);
2249     if ((ps_selected_mode == SHADER_ARB || ps_selected_mode == SHADER_GLSL)
2250             && gl_info->supported[ARB_FRAGMENT_PROGRAM]) return &arbfp_fragment_pipeline;
2251     else if (ps_selected_mode == SHADER_ATI) return &atifs_fragment_pipeline;
2252     else if (gl_info->supported[NV_REGISTER_COMBINERS]
2253             && gl_info->supported[NV_TEXTURE_SHADER2]) return &nvts_fragment_pipeline;
2254     else if (gl_info->supported[NV_REGISTER_COMBINERS]) return &nvrc_fragment_pipeline;
2255     else return &ffp_fragment_pipeline;
2256 }
2257
2258 static const struct wined3d_shader_backend_ops *select_shader_backend(const struct wined3d_gl_info *gl_info)
2259 {
2260     int vs_selected_mode, ps_selected_mode;
2261
2262     select_shader_mode(gl_info, &ps_selected_mode, &vs_selected_mode);
2263     if (vs_selected_mode == SHADER_GLSL || ps_selected_mode == SHADER_GLSL) return &glsl_shader_backend;
2264     if (vs_selected_mode == SHADER_ARB || ps_selected_mode == SHADER_ARB) return &arb_program_shader_backend;
2265     return &none_shader_backend;
2266 }
2267
2268 static const struct blit_shader *select_blit_implementation(const struct wined3d_gl_info *gl_info)
2269 {
2270     int vs_selected_mode, ps_selected_mode;
2271
2272     select_shader_mode(gl_info, &ps_selected_mode, &vs_selected_mode);
2273     if ((ps_selected_mode == SHADER_ARB || ps_selected_mode == SHADER_GLSL)
2274             && gl_info->supported[ARB_FRAGMENT_PROGRAM]) return &arbfp_blit;
2275     else return &ffp_blit;
2276 }
2277
2278 static void load_gl_funcs(struct wined3d_gl_info *gl_info, DWORD gl_version)
2279 {
2280     DWORD ver;
2281
2282 #define USE_GL_FUNC(type, pfn, ext, replace) \
2283     if (gl_info->supported[ext]) gl_info->pfn = (type)pwglGetProcAddress(#pfn); \
2284     else if ((ver = ver_for_ext(ext)) && ver <= gl_version) gl_info->pfn = (type)pwglGetProcAddress(#replace); \
2285     else gl_info->pfn = NULL;
2286
2287     GL_EXT_FUNCS_GEN;
2288 #undef USE_GL_FUNC
2289
2290 #define USE_GL_FUNC(type, pfn, ext, replace) gl_info->pfn = (type)pwglGetProcAddress(#pfn);
2291     WGL_EXT_FUNCS_GEN;
2292 #undef USE_GL_FUNC
2293 }
2294
2295 /* Context activation is done by the caller. */
2296 static BOOL wined3d_adapter_init_gl_caps(struct wined3d_adapter *adapter)
2297 {
2298     struct wined3d_driver_info *driver_info = &adapter->driver_info;
2299     struct wined3d_gl_info *gl_info = &adapter->gl_info;
2300     const char *GL_Extensions    = NULL;
2301     const char *WGL_Extensions   = NULL;
2302     const char *gl_vendor_str, *gl_renderer_str, *gl_version_str;
2303     struct fragment_caps fragment_caps;
2304     enum wined3d_gl_vendor gl_vendor;
2305     enum wined3d_pci_vendor card_vendor;
2306     enum wined3d_pci_device device;
2307     GLint       gl_max;
2308     GLfloat     gl_floatv[2];
2309     unsigned    i;
2310     HDC         hdc;
2311     DWORD gl_version;
2312     size_t len;
2313
2314     TRACE_(d3d_caps)("(%p)\n", gl_info);
2315
2316     ENTER_GL();
2317
2318     gl_renderer_str = (const char *)glGetString(GL_RENDERER);
2319     TRACE_(d3d_caps)("GL_RENDERER: %s.\n", debugstr_a(gl_renderer_str));
2320     if (!gl_renderer_str)
2321     {
2322         LEAVE_GL();
2323         ERR_(d3d_caps)("Received a NULL GL_RENDERER.\n");
2324         return FALSE;
2325     }
2326
2327     gl_vendor_str = (const char *)glGetString(GL_VENDOR);
2328     TRACE_(d3d_caps)("GL_VENDOR: %s.\n", debugstr_a(gl_vendor_str));
2329     if (!gl_vendor_str)
2330     {
2331         LEAVE_GL();
2332         ERR_(d3d_caps)("Received a NULL GL_VENDOR.\n");
2333         return FALSE;
2334     }
2335
2336     /* Parse the GL_VERSION field into major and minor information */
2337     gl_version_str = (const char *)glGetString(GL_VERSION);
2338     TRACE_(d3d_caps)("GL_VERSION: %s.\n", debugstr_a(gl_version_str));
2339     if (!gl_version_str)
2340     {
2341         LEAVE_GL();
2342         ERR_(d3d_caps)("Received a NULL GL_VERSION.\n");
2343         return FALSE;
2344     }
2345     gl_version = wined3d_parse_gl_version(gl_version_str);
2346
2347     /*
2348      * Initialize openGL extension related variables
2349      *  with Default values
2350      */
2351     memset(gl_info->supported, 0, sizeof(gl_info->supported));
2352     gl_info->limits.blends = 1;
2353     gl_info->limits.buffers = 1;
2354     gl_info->limits.textures = 1;
2355     gl_info->limits.texture_coords = 1;
2356     gl_info->limits.fragment_samplers = 1;
2357     gl_info->limits.vertex_samplers = 0;
2358     gl_info->limits.combined_samplers = gl_info->limits.fragment_samplers + gl_info->limits.vertex_samplers;
2359     gl_info->limits.sampler_stages = 1;
2360     gl_info->limits.vertex_attribs = 16;
2361     gl_info->limits.glsl_vs_float_constants = 0;
2362     gl_info->limits.glsl_ps_float_constants = 0;
2363     gl_info->limits.arb_vs_float_constants = 0;
2364     gl_info->limits.arb_vs_native_constants = 0;
2365     gl_info->limits.arb_vs_instructions = 0;
2366     gl_info->limits.arb_vs_temps = 0;
2367     gl_info->limits.arb_ps_float_constants = 0;
2368     gl_info->limits.arb_ps_local_constants = 0;
2369     gl_info->limits.arb_ps_instructions = 0;
2370     gl_info->limits.arb_ps_temps = 0;
2371
2372     /* Retrieve opengl defaults */
2373     glGetIntegerv(GL_MAX_CLIP_PLANES, &gl_max);
2374     gl_info->limits.clipplanes = min(WINED3DMAXUSERCLIPPLANES, gl_max);
2375     TRACE_(d3d_caps)("ClipPlanes support - num Planes=%d\n", gl_max);
2376
2377     glGetIntegerv(GL_MAX_LIGHTS, &gl_max);
2378     gl_info->limits.lights = gl_max;
2379     TRACE_(d3d_caps)("Lights support - max lights=%d\n", gl_max);
2380
2381     glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gl_max);
2382     gl_info->limits.texture_size = gl_max;
2383     TRACE_(d3d_caps)("Maximum texture size support - max texture size=%d\n", gl_max);
2384
2385     glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, gl_floatv);
2386     gl_info->limits.pointsize_min = gl_floatv[0];
2387     gl_info->limits.pointsize_max = gl_floatv[1];
2388     TRACE_(d3d_caps)("Maximum point size support - max point size=%f\n", gl_floatv[1]);
2389
2390     /* Parse the gl supported features, in theory enabling parts of our code appropriately. */
2391     GL_Extensions = (const char *)glGetString(GL_EXTENSIONS);
2392     if (!GL_Extensions)
2393     {
2394         LEAVE_GL();
2395         ERR_(d3d_caps)("Received a NULL GL_EXTENSIONS.\n");
2396         return FALSE;
2397     }
2398
2399     LEAVE_GL();
2400
2401     TRACE_(d3d_caps)("GL_Extensions reported:\n");
2402
2403     gl_info->supported[WINED3D_GL_EXT_NONE] = TRUE;
2404
2405     while (*GL_Extensions)
2406     {
2407         const char *start;
2408
2409         while (isspace(*GL_Extensions)) ++GL_Extensions;
2410         start = GL_Extensions;
2411         while (!isspace(*GL_Extensions) && *GL_Extensions) ++GL_Extensions;
2412
2413         len = GL_Extensions - start;
2414         if (!len) continue;
2415
2416         TRACE_(d3d_caps)("- %s\n", debugstr_an(start, len));
2417
2418         for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i)
2419         {
2420             if (len == strlen(EXTENSION_MAP[i].extension_string)
2421                     && !memcmp(start, EXTENSION_MAP[i].extension_string, len))
2422             {
2423                 TRACE_(d3d_caps)(" FOUND: %s support.\n", EXTENSION_MAP[i].extension_string);
2424                 gl_info->supported[EXTENSION_MAP[i].extension] = TRUE;
2425                 break;
2426             }
2427         }
2428     }
2429
2430     /* Now work out what GL support this card really has */
2431     load_gl_funcs( gl_info, gl_version );
2432
2433     ENTER_GL();
2434
2435     /* Now mark all the extensions supported which are included in the opengl core version. Do this *after*
2436      * loading the functions, otherwise the code above will load the extension entry points instead of the
2437      * core functions, which may not work. */
2438     for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i)
2439     {
2440         if (!gl_info->supported[EXTENSION_MAP[i].extension]
2441                 && EXTENSION_MAP[i].version <= gl_version && EXTENSION_MAP[i].version)
2442         {
2443             TRACE_(d3d_caps)(" GL CORE: %s support.\n", EXTENSION_MAP[i].extension_string);
2444             gl_info->supported[EXTENSION_MAP[i].extension] = TRUE;
2445         }
2446     }
2447
2448     if (gl_version >= MAKEDWORD_VERSION(2, 0)) gl_info->supported[WINED3D_GL_VERSION_2_0] = TRUE;
2449
2450     if (gl_info->supported[APPLE_FENCE])
2451     {
2452         /* GL_NV_fence and GL_APPLE_fence provide the same functionality basically.
2453          * The apple extension interacts with some other apple exts. Disable the NV
2454          * extension if the apple one is support to prevent confusion in other parts
2455          * of the code. */
2456         gl_info->supported[NV_FENCE] = FALSE;
2457     }
2458     if (gl_info->supported[APPLE_FLOAT_PIXELS])
2459     {
2460         /* GL_APPLE_float_pixels == GL_ARB_texture_float + GL_ARB_half_float_pixel
2461          *
2462          * The enums are the same:
2463          * GL_RGBA16F_ARB     = GL_RGBA_FLOAT16_APPLE = 0x881A
2464          * GL_RGB16F_ARB      = GL_RGB_FLOAT16_APPLE  = 0x881B
2465          * GL_RGBA32F_ARB     = GL_RGBA_FLOAT32_APPLE = 0x8814
2466          * GL_RGB32F_ARB      = GL_RGB_FLOAT32_APPLE  = 0x8815
2467          * GL_HALF_FLOAT_ARB  = GL_HALF_APPLE         = 0x140B
2468          */
2469         if (!gl_info->supported[ARB_TEXTURE_FLOAT])
2470         {
2471             TRACE_(d3d_caps)(" IMPLIED: GL_ARB_texture_float support(from GL_APPLE_float_pixels.\n");
2472             gl_info->supported[ARB_TEXTURE_FLOAT] = TRUE;
2473         }
2474         if (!gl_info->supported[ARB_HALF_FLOAT_PIXEL])
2475         {
2476             TRACE_(d3d_caps)(" IMPLIED: GL_ARB_half_float_pixel support(from GL_APPLE_float_pixels.\n");
2477             gl_info->supported[ARB_HALF_FLOAT_PIXEL] = TRUE;
2478         }
2479     }
2480     if (gl_info->supported[ARB_MAP_BUFFER_RANGE])
2481     {
2482         /* GL_ARB_map_buffer_range and GL_APPLE_flush_buffer_range provide the same
2483          * functionality. Prefer the ARB extension */
2484         gl_info->supported[APPLE_FLUSH_BUFFER_RANGE] = FALSE;
2485     }
2486     if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
2487     {
2488         TRACE_(d3d_caps)(" IMPLIED: NVIDIA (NV) Texture Gen Reflection support.\n");
2489         gl_info->supported[NV_TEXGEN_REFLECTION] = TRUE;
2490     }
2491     if (!gl_info->supported[ARB_DEPTH_CLAMP] && gl_info->supported[NV_DEPTH_CLAMP])
2492     {
2493         TRACE_(d3d_caps)(" IMPLIED: ARB_depth_clamp support (by NV_depth_clamp).\n");
2494         gl_info->supported[ARB_DEPTH_CLAMP] = TRUE;
2495     }
2496     if (!gl_info->supported[ARB_VERTEX_ARRAY_BGRA] && gl_info->supported[EXT_VERTEX_ARRAY_BGRA])
2497     {
2498         TRACE_(d3d_caps)(" IMPLIED: ARB_vertex_array_bgra support (by EXT_vertex_array_bgra).\n");
2499         gl_info->supported[ARB_VERTEX_ARRAY_BGRA] = TRUE;
2500     }
2501     if (!gl_info->supported[ARB_TEXTURE_COMPRESSION_RGTC] && gl_info->supported[EXT_TEXTURE_COMPRESSION_RGTC])
2502     {
2503         TRACE_(d3d_caps)(" IMPLIED: ARB_texture_compression_rgtc support (by EXT_texture_compression_rgtc).\n");
2504         gl_info->supported[ARB_TEXTURE_COMPRESSION_RGTC] = TRUE;
2505     }
2506     if (gl_info->supported[NV_TEXTURE_SHADER2])
2507     {
2508         if (gl_info->supported[NV_REGISTER_COMBINERS])
2509         {
2510             /* Also disable ATI_FRAGMENT_SHADER if register combiners and texture_shader2
2511              * are supported. The nv extensions provide the same functionality as the
2512              * ATI one, and a bit more(signed pixelformats). */
2513             gl_info->supported[ATI_FRAGMENT_SHADER] = FALSE;
2514         }
2515     }
2516
2517     if (gl_info->supported[ARB_MAP_BUFFER_ALIGNMENT])
2518     {
2519         glGetIntegerv(GL_MIN_MAP_BUFFER_ALIGNMENT, &gl_max);
2520         TRACE_(d3d_caps)("Minimum buffer map alignment: %d.\n", gl_max);
2521     }
2522     else
2523     {
2524         WARN_(d3d_caps)("Driver doesn't guarantee a minimum buffer map alignment.\n");
2525     }
2526     if (gl_info->supported[NV_REGISTER_COMBINERS])
2527     {
2528         glGetIntegerv(GL_MAX_GENERAL_COMBINERS_NV, &gl_max);
2529         gl_info->limits.general_combiners = gl_max;
2530         TRACE_(d3d_caps)("Max general combiners: %d.\n", gl_max);
2531     }
2532     if (gl_info->supported[ARB_DRAW_BUFFERS])
2533     {
2534         glGetIntegerv(GL_MAX_DRAW_BUFFERS_ARB, &gl_max);
2535         gl_info->limits.buffers = gl_max;
2536         TRACE_(d3d_caps)("Max draw buffers: %u.\n", gl_max);
2537     }
2538     if (gl_info->supported[ARB_MULTITEXTURE])
2539     {
2540         glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_max);
2541         gl_info->limits.textures = min(MAX_TEXTURES, gl_max);
2542         TRACE_(d3d_caps)("Max textures: %d.\n", gl_info->limits.textures);
2543         glGetIntegerv(GL_MAX_TEXTURE_COORDS_ARB, &gl_max);
2544         gl_info->limits.texture_coords = min(MAX_TEXTURES, gl_max);
2545         TRACE_(d3d_caps)("Max texture coords: %d.\n", gl_info->limits.texture_coords);
2546
2547         if (gl_info->supported[ARB_FRAGMENT_PROGRAM])
2548         {
2549             GLint tmp;
2550             glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &tmp);
2551             gl_info->limits.fragment_samplers = min(MAX_FRAGMENT_SAMPLERS, tmp);
2552         }
2553         else
2554         {
2555             gl_info->limits.fragment_samplers = max(gl_info->limits.fragment_samplers, gl_max);
2556         }
2557         TRACE_(d3d_caps)("Max fragment samplers: %d.\n", gl_info->limits.fragment_samplers);
2558
2559         if (gl_info->supported[ARB_VERTEX_SHADER])
2560         {
2561             GLint tmp;
2562             glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, &tmp);
2563             gl_info->limits.vertex_samplers = tmp;
2564             glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, &tmp);
2565             gl_info->limits.combined_samplers = tmp;
2566             glGetIntegerv(GL_MAX_VERTEX_ATTRIBS_ARB, &tmp);
2567             gl_info->limits.vertex_attribs = tmp;
2568
2569             /* Loading GLSL sampler uniforms is much simpler if we can assume that the sampler setup
2570              * is known at shader link time. In a vertex shader + pixel shader combination this isn't
2571              * an issue because then the sampler setup only depends on the two shaders. If a pixel
2572              * shader is used with fixed function vertex processing we're fine too because fixed function
2573              * vertex processing doesn't use any samplers. If fixed function fragment processing is
2574              * used we have to make sure that all vertex sampler setups are valid together with all
2575              * possible fixed function fragment processing setups. This is true if vsamplers + MAX_TEXTURES
2576              * <= max_samplers. This is true on all d3d9 cards that support vtf(gf 6 and gf7 cards).
2577              * dx9 radeon cards do not support vertex texture fetch. DX10 cards have 128 samplers, and
2578              * dx9 is limited to 8 fixed function texture stages and 4 vertex samplers. DX10 does not have
2579              * a fixed function pipeline anymore.
2580              *
2581              * So this is just a check to check that our assumption holds true. If not, write a warning
2582              * and reduce the number of vertex samplers or probably disable vertex texture fetch. */
2583             if (gl_info->limits.vertex_samplers && gl_info->limits.combined_samplers < 12
2584                     && MAX_TEXTURES + gl_info->limits.vertex_samplers > gl_info->limits.combined_samplers)
2585             {
2586                 FIXME("OpenGL implementation supports %u vertex samplers and %u total samplers.\n",
2587                         gl_info->limits.vertex_samplers, gl_info->limits.combined_samplers);
2588                 FIXME("Expected vertex samplers + MAX_TEXTURES(=8) > combined_samplers.\n");
2589                 if (gl_info->limits.combined_samplers > MAX_TEXTURES)
2590                     gl_info->limits.vertex_samplers = gl_info->limits.combined_samplers - MAX_TEXTURES;
2591                 else
2592                     gl_info->limits.vertex_samplers = 0;
2593             }
2594         }
2595         else
2596         {
2597             gl_info->limits.combined_samplers = gl_info->limits.fragment_samplers;
2598         }
2599         TRACE_(d3d_caps)("Max vertex samplers: %u.\n", gl_info->limits.vertex_samplers);
2600         TRACE_(d3d_caps)("Max combined samplers: %u.\n", gl_info->limits.combined_samplers);
2601     }
2602     if (gl_info->supported[ARB_VERTEX_BLEND])
2603     {
2604         glGetIntegerv(GL_MAX_VERTEX_UNITS_ARB, &gl_max);
2605         gl_info->limits.blends = gl_max;
2606         TRACE_(d3d_caps)("Max blends: %u.\n", gl_info->limits.blends);
2607     }
2608     if (gl_info->supported[EXT_TEXTURE3D])
2609     {
2610         glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE_EXT, &gl_max);
2611         gl_info->limits.texture3d_size = gl_max;
2612         TRACE_(d3d_caps)("Max texture3D size: %d.\n", gl_info->limits.texture3d_size);
2613     }
2614     if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
2615     {
2616         glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &gl_max);
2617         gl_info->limits.anisotropy = gl_max;
2618         TRACE_(d3d_caps)("Max anisotropy: %d.\n", gl_info->limits.anisotropy);
2619     }
2620     if (gl_info->supported[ARB_FRAGMENT_PROGRAM])
2621     {
2622         GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, &gl_max));
2623         gl_info->limits.arb_ps_float_constants = gl_max;
2624         TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM float constants: %d.\n", gl_info->limits.arb_ps_float_constants);
2625         GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB, &gl_max));
2626         gl_info->limits.arb_ps_native_constants = gl_max;
2627         TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM native float constants: %d.\n",
2628                 gl_info->limits.arb_ps_native_constants);
2629         GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl_max));
2630         gl_info->limits.arb_ps_temps = gl_max;
2631         TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM native temporaries: %d.\n", gl_info->limits.arb_ps_temps);
2632         GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl_max));
2633         gl_info->limits.arb_ps_instructions = gl_max;
2634         TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM native instructions: %d.\n", gl_info->limits.arb_ps_instructions);
2635         GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB, &gl_max));
2636         gl_info->limits.arb_ps_local_constants = gl_max;
2637         TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM local parameters: %d.\n", gl_info->limits.arb_ps_instructions);
2638     }
2639     if (gl_info->supported[ARB_VERTEX_PROGRAM])
2640     {
2641         GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, &gl_max));
2642         gl_info->limits.arb_vs_float_constants = gl_max;
2643         TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM float constants: %d.\n", gl_info->limits.arb_vs_float_constants);
2644         GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB, &gl_max));
2645         gl_info->limits.arb_vs_native_constants = gl_max;
2646         TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM native float constants: %d.\n",
2647                 gl_info->limits.arb_vs_native_constants);
2648         GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl_max));
2649         gl_info->limits.arb_vs_temps = gl_max;
2650         TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM native temporaries: %d.\n", gl_info->limits.arb_vs_temps);
2651         GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl_max));
2652         gl_info->limits.arb_vs_instructions = gl_max;
2653         TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM native instructions: %d.\n", gl_info->limits.arb_vs_instructions);
2654
2655         if (test_arb_vs_offset_limit(gl_info)) gl_info->quirks |= WINED3D_QUIRK_ARB_VS_OFFSET_LIMIT;
2656     }
2657     if (gl_info->supported[ARB_VERTEX_SHADER])
2658     {
2659         glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, &gl_max);
2660         gl_info->limits.glsl_vs_float_constants = gl_max / 4;
2661         TRACE_(d3d_caps)("Max ARB_VERTEX_SHADER float constants: %u.\n", gl_info->limits.glsl_vs_float_constants);
2662     }
2663     if (gl_info->supported[ARB_FRAGMENT_SHADER])
2664     {
2665         glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB, &gl_max);
2666         gl_info->limits.glsl_ps_float_constants = gl_max / 4;
2667         TRACE_(d3d_caps)("Max ARB_FRAGMENT_SHADER float constants: %u.\n", gl_info->limits.glsl_ps_float_constants);
2668         glGetIntegerv(GL_MAX_VARYING_FLOATS_ARB, &gl_max);
2669         gl_info->limits.glsl_varyings = gl_max;
2670         TRACE_(d3d_caps)("Max GLSL varyings: %u (%u 4 component varyings).\n", gl_max, gl_max / 4);
2671     }
2672     if (gl_info->supported[ARB_SHADING_LANGUAGE_100])
2673     {
2674         const char *str = (const char *)glGetString(GL_SHADING_LANGUAGE_VERSION_ARB);
2675         unsigned int major, minor;
2676
2677         TRACE_(d3d_caps)("GLSL version string: %s.\n", debugstr_a(str));
2678
2679         /* The format of the GLSL version string is "major.minor[.release] [vendor info]". */
2680         sscanf(str, "%u.%u", &major, &minor);
2681         gl_info->glsl_version = MAKEDWORD_VERSION(major, minor);
2682     }
2683     if (gl_info->supported[NV_LIGHT_MAX_EXPONENT])
2684     {
2685         glGetFloatv(GL_MAX_SHININESS_NV, &gl_info->limits.shininess);
2686     }
2687     else
2688     {
2689         gl_info->limits.shininess = 128.0f;
2690     }
2691     if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
2692     {
2693         /* If we have full NP2 texture support, disable
2694          * GL_ARB_texture_rectangle because we will never use it.
2695          * This saves a few redundant glDisable calls. */
2696         gl_info->supported[ARB_TEXTURE_RECTANGLE] = FALSE;
2697     }
2698     if (gl_info->supported[ATI_FRAGMENT_SHADER])
2699     {
2700         /* Disable NV_register_combiners and fragment shader if this is supported.
2701          * generally the NV extensions are preferred over the ATI ones, and this
2702          * extension is disabled if register_combiners and texture_shader2 are both
2703          * supported. So we reach this place only if we have incomplete NV dxlevel 8
2704          * fragment processing support. */
2705         gl_info->supported[NV_REGISTER_COMBINERS] = FALSE;
2706         gl_info->supported[NV_REGISTER_COMBINERS2] = FALSE;
2707         gl_info->supported[NV_TEXTURE_SHADER] = FALSE;
2708         gl_info->supported[NV_TEXTURE_SHADER2] = FALSE;
2709     }
2710     if (gl_info->supported[NV_HALF_FLOAT])
2711     {
2712         /* GL_ARB_half_float_vertex is a subset of GL_NV_half_float. */
2713         gl_info->supported[ARB_HALF_FLOAT_VERTEX] = TRUE;
2714     }
2715     checkGLcall("extension detection");
2716
2717     LEAVE_GL();
2718
2719     adapter->fragment_pipe = select_fragment_implementation(gl_info);
2720     adapter->shader_backend = select_shader_backend(gl_info);
2721     adapter->blitter = select_blit_implementation(gl_info);
2722
2723     adapter->fragment_pipe->get_caps(gl_info, &fragment_caps);
2724     gl_info->limits.texture_stages = fragment_caps.MaxTextureBlendStages;
2725     TRACE_(d3d_caps)("Max texture stages: %u.\n", gl_info->limits.texture_stages);
2726
2727     /* In some cases the number of texture stages can be larger than the number
2728      * of samplers. The GF4 for example can use only 2 samplers (no fragment
2729      * shaders), but 8 texture stages (register combiners). */
2730     gl_info->limits.sampler_stages = max(gl_info->limits.fragment_samplers, gl_info->limits.texture_stages);
2731
2732     if (gl_info->supported[ARB_FRAMEBUFFER_OBJECT])
2733     {
2734         gl_info->fbo_ops.glIsRenderbuffer = gl_info->glIsRenderbuffer;
2735         gl_info->fbo_ops.glBindRenderbuffer = gl_info->glBindRenderbuffer;
2736         gl_info->fbo_ops.glDeleteRenderbuffers = gl_info->glDeleteRenderbuffers;
2737         gl_info->fbo_ops.glGenRenderbuffers = gl_info->glGenRenderbuffers;
2738         gl_info->fbo_ops.glRenderbufferStorage = gl_info->glRenderbufferStorage;
2739         gl_info->fbo_ops.glRenderbufferStorageMultisample = gl_info->glRenderbufferStorageMultisample;
2740         gl_info->fbo_ops.glGetRenderbufferParameteriv = gl_info->glGetRenderbufferParameteriv;
2741         gl_info->fbo_ops.glIsFramebuffer = gl_info->glIsFramebuffer;
2742         gl_info->fbo_ops.glBindFramebuffer = gl_info->glBindFramebuffer;
2743         gl_info->fbo_ops.glDeleteFramebuffers = gl_info->glDeleteFramebuffers;
2744         gl_info->fbo_ops.glGenFramebuffers = gl_info->glGenFramebuffers;
2745         gl_info->fbo_ops.glCheckFramebufferStatus = gl_info->glCheckFramebufferStatus;
2746         gl_info->fbo_ops.glFramebufferTexture1D = gl_info->glFramebufferTexture1D;
2747         gl_info->fbo_ops.glFramebufferTexture2D = gl_info->glFramebufferTexture2D;
2748         gl_info->fbo_ops.glFramebufferTexture3D = gl_info->glFramebufferTexture3D;
2749         gl_info->fbo_ops.glFramebufferRenderbuffer = gl_info->glFramebufferRenderbuffer;
2750         gl_info->fbo_ops.glGetFramebufferAttachmentParameteriv = gl_info->glGetFramebufferAttachmentParameteriv;
2751         gl_info->fbo_ops.glBlitFramebuffer = gl_info->glBlitFramebuffer;
2752         gl_info->fbo_ops.glGenerateMipmap = gl_info->glGenerateMipmap;
2753         if (wined3d_settings.allow_multisampling)
2754         {
2755             glGetIntegerv(GL_MAX_SAMPLES, &gl_max);
2756             gl_info->limits.samples = gl_max;
2757         }
2758     }
2759     else
2760     {
2761         if (gl_info->supported[EXT_FRAMEBUFFER_OBJECT])
2762         {
2763             gl_info->fbo_ops.glIsRenderbuffer = gl_info->glIsRenderbufferEXT;
2764             gl_info->fbo_ops.glBindRenderbuffer = gl_info->glBindRenderbufferEXT;
2765             gl_info->fbo_ops.glDeleteRenderbuffers = gl_info->glDeleteRenderbuffersEXT;
2766             gl_info->fbo_ops.glGenRenderbuffers = gl_info->glGenRenderbuffersEXT;
2767             gl_info->fbo_ops.glRenderbufferStorage = gl_info->glRenderbufferStorageEXT;
2768             gl_info->fbo_ops.glGetRenderbufferParameteriv = gl_info->glGetRenderbufferParameterivEXT;
2769             gl_info->fbo_ops.glIsFramebuffer = gl_info->glIsFramebufferEXT;
2770             gl_info->fbo_ops.glBindFramebuffer = gl_info->glBindFramebufferEXT;
2771             gl_info->fbo_ops.glDeleteFramebuffers = gl_info->glDeleteFramebuffersEXT;
2772             gl_info->fbo_ops.glGenFramebuffers = gl_info->glGenFramebuffersEXT;
2773             gl_info->fbo_ops.glCheckFramebufferStatus = gl_info->glCheckFramebufferStatusEXT;
2774             gl_info->fbo_ops.glFramebufferTexture1D = gl_info->glFramebufferTexture1DEXT;
2775             gl_info->fbo_ops.glFramebufferTexture2D = gl_info->glFramebufferTexture2DEXT;
2776             gl_info->fbo_ops.glFramebufferTexture3D = gl_info->glFramebufferTexture3DEXT;
2777             gl_info->fbo_ops.glFramebufferRenderbuffer = gl_info->glFramebufferRenderbufferEXT;
2778             gl_info->fbo_ops.glGetFramebufferAttachmentParameteriv = gl_info->glGetFramebufferAttachmentParameterivEXT;
2779             gl_info->fbo_ops.glGenerateMipmap = gl_info->glGenerateMipmapEXT;
2780         }
2781         else if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
2782         {
2783             WARN_(d3d_caps)("Framebuffer objects not supported, falling back to backbuffer offscreen rendering mode.\n");
2784             wined3d_settings.offscreen_rendering_mode = ORM_BACKBUFFER;
2785         }
2786         if (gl_info->supported[EXT_FRAMEBUFFER_BLIT])
2787         {
2788             gl_info->fbo_ops.glBlitFramebuffer = gl_info->glBlitFramebufferEXT;
2789         }
2790         if (gl_info->supported[EXT_FRAMEBUFFER_MULTISAMPLE])
2791         {
2792             gl_info->fbo_ops.glRenderbufferStorageMultisample = gl_info->glRenderbufferStorageMultisampleEXT;
2793             if (wined3d_settings.allow_multisampling)
2794             {
2795                 glGetIntegerv(GL_MAX_SAMPLES, &gl_max);
2796                 gl_info->limits.samples = gl_max;
2797             }
2798         }
2799     }
2800
2801     /* MRTs are currently only supported when FBOs are used. */
2802     if (wined3d_settings.offscreen_rendering_mode != ORM_FBO)
2803     {
2804         gl_info->limits.buffers = 1;
2805     }
2806
2807     gl_vendor = wined3d_guess_gl_vendor(gl_info, gl_vendor_str, gl_renderer_str);
2808     card_vendor = wined3d_guess_card_vendor(gl_vendor_str, gl_renderer_str);
2809     TRACE_(d3d_caps)("found GL_VENDOR (%s)->(0x%04x/0x%04x)\n", debugstr_a(gl_vendor_str), gl_vendor, card_vendor);
2810
2811     device = wined3d_guess_card(gl_info, gl_renderer_str, &gl_vendor, &card_vendor);
2812     TRACE_(d3d_caps)("FOUND (fake) card: 0x%x (vendor id), 0x%x (device id)\n", card_vendor, device);
2813
2814     gl_info->wrap_lookup[WINED3D_TADDRESS_WRAP - WINED3D_TADDRESS_WRAP] = GL_REPEAT;
2815     gl_info->wrap_lookup[WINED3D_TADDRESS_MIRROR - WINED3D_TADDRESS_WRAP] =
2816             gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT] ? GL_MIRRORED_REPEAT_ARB : GL_REPEAT;
2817     gl_info->wrap_lookup[WINED3D_TADDRESS_CLAMP - WINED3D_TADDRESS_WRAP] = GL_CLAMP_TO_EDGE;
2818     gl_info->wrap_lookup[WINED3D_TADDRESS_BORDER - WINED3D_TADDRESS_WRAP] =
2819             gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] ? GL_CLAMP_TO_BORDER_ARB : GL_REPEAT;
2820     gl_info->wrap_lookup[WINED3D_TADDRESS_MIRROR_ONCE - WINED3D_TADDRESS_WRAP] =
2821             gl_info->supported[ATI_TEXTURE_MIRROR_ONCE] ? GL_MIRROR_CLAMP_TO_EDGE_ATI : GL_REPEAT;
2822
2823     /* Make sure there's an active HDC else the WGL extensions will fail */
2824     hdc = pwglGetCurrentDC();
2825     if (hdc) {
2826         /* Not all GL drivers might offer WGL extensions e.g. VirtualBox */
2827         if(GL_EXTCALL(wglGetExtensionsStringARB))
2828             WGL_Extensions = GL_EXTCALL(wglGetExtensionsStringARB(hdc));
2829
2830         if (!WGL_Extensions)
2831         {
2832             ERR("   WGL_Extensions returns NULL\n");
2833         }
2834         else
2835         {
2836             TRACE_(d3d_caps)("WGL_Extensions reported:\n");
2837             while (*WGL_Extensions)
2838             {
2839                 const char *Start;
2840                 char ThisExtn[256];
2841
2842                 while (isspace(*WGL_Extensions)) WGL_Extensions++;
2843                 Start = WGL_Extensions;
2844                 while (!isspace(*WGL_Extensions) && *WGL_Extensions) ++WGL_Extensions;
2845
2846                 len = WGL_Extensions - Start;
2847                 if (!len || len >= sizeof(ThisExtn))
2848                     continue;
2849
2850                 memcpy(ThisExtn, Start, len);
2851                 ThisExtn[len] = '\0';
2852                 TRACE_(d3d_caps)("- %s\n", debugstr_a(ThisExtn));
2853
2854                 if (!strcmp(ThisExtn, "WGL_ARB_pixel_format")) {
2855                     gl_info->supported[WGL_ARB_PIXEL_FORMAT] = TRUE;
2856                     TRACE_(d3d_caps)("FOUND: WGL_ARB_pixel_format support\n");
2857                 }
2858                 if (!strcmp(ThisExtn, "WGL_EXT_swap_control")) {
2859                     gl_info->supported[WGL_EXT_SWAP_CONTROL] = TRUE;
2860                     TRACE_(d3d_caps)("FOUND: WGL_EXT_swap_control support\n");
2861                 }
2862                 if (!strcmp(ThisExtn, "WGL_WINE_pixel_format_passthrough")) {
2863                     gl_info->supported[WGL_WINE_PIXEL_FORMAT_PASSTHROUGH] = TRUE;
2864                     TRACE_(d3d_caps)("FOUND: WGL_WINE_pixel_format_passthrough support\n");
2865                 }
2866             }
2867         }
2868     }
2869
2870     fixup_extensions(gl_info, gl_renderer_str, gl_vendor, card_vendor, device);
2871     init_driver_info(driver_info, card_vendor, device);
2872     add_gl_compat_wrappers(gl_info);
2873
2874     return TRUE;
2875 }
2876
2877 UINT CDECL wined3d_get_adapter_count(const struct wined3d *wined3d)
2878 {
2879     TRACE_(d3d_caps)("wined3d %p, reporting %u adapters.\n",
2880             wined3d, wined3d->adapter_count);
2881
2882     return wined3d->adapter_count;
2883 }
2884
2885 HRESULT CDECL wined3d_register_software_device(struct wined3d *wined3d, void *init_function)
2886 {
2887     FIXME("wined3d %p, init_function %p stub!\n", wined3d, init_function);
2888
2889     return WINED3D_OK;
2890 }
2891
2892 HMONITOR CDECL wined3d_get_adapter_monitor(const struct wined3d *wined3d, UINT adapter_idx)
2893 {
2894     TRACE_(d3d_caps)("wined3d %p, adapter_idx %u.\n", wined3d, adapter_idx);
2895
2896     if (adapter_idx >= wined3d->adapter_count)
2897         return NULL;
2898
2899     return MonitorFromPoint(wined3d->adapters[adapter_idx].monitorPoint, MONITOR_DEFAULTTOPRIMARY);
2900 }
2901
2902 /* FIXME: GetAdapterModeCount and EnumAdapterModes currently only returns modes
2903      of the same bpp but different resolutions                                  */
2904
2905 /* Note: dx9 supplies a format. Calls from d3d8 supply WINED3DFMT_UNKNOWN */
2906 UINT CDECL wined3d_get_adapter_mode_count(const struct wined3d *wined3d, UINT adapter_idx,
2907         enum wined3d_format_id format_id)
2908 {
2909     TRACE_(d3d_caps)("wined3d %p, adapter_idx %u, format %s.\n", wined3d, adapter_idx, debug_d3dformat(format_id));
2910
2911     if (adapter_idx >= wined3d->adapter_count)
2912         return 0;
2913
2914     /* TODO: Store modes per adapter and read it from the adapter structure */
2915     if (!adapter_idx)
2916     {
2917         const struct wined3d_format *format = wined3d_get_format(&wined3d->adapters[adapter_idx].gl_info, format_id);
2918         UINT format_bits = format->byte_count * CHAR_BIT;
2919         unsigned int i = 0;
2920         unsigned int j = 0;
2921         DEVMODEW mode;
2922
2923         memset(&mode, 0, sizeof(mode));
2924         mode.dmSize = sizeof(mode);
2925
2926         while (EnumDisplaySettingsExW(NULL, j, &mode, 0))
2927         {
2928             ++j;
2929
2930             if (format_id == WINED3DFMT_UNKNOWN)
2931             {
2932                 /* This is for D3D8, do not enumerate P8 here */
2933                 if (mode.dmBitsPerPel == 32 || mode.dmBitsPerPel == 16) ++i;
2934             }
2935             else if (mode.dmBitsPerPel == format_bits)
2936             {
2937                 ++i;
2938             }
2939         }
2940
2941         TRACE_(d3d_caps)("Returning %u matching modes (out of %u total) for adapter %u.\n", i, j, adapter_idx);
2942
2943         return i;
2944     }
2945     else
2946     {
2947         FIXME_(d3d_caps)("Adapter not primary display.\n");
2948     }
2949
2950     return 0;
2951 }
2952
2953 /* Note: dx9 supplies a format. Calls from d3d8 supply WINED3DFMT_UNKNOWN */
2954 HRESULT CDECL wined3d_enum_adapter_modes(const struct wined3d *wined3d, UINT adapter_idx,
2955         enum wined3d_format_id format_id, UINT mode_idx, struct wined3d_display_mode *mode)
2956 {
2957     TRACE_(d3d_caps)("wined3d %p, adapter_idx %u, format %s, mode_idx %u, mode %p.\n",
2958             wined3d, adapter_idx, debug_d3dformat(format_id), mode_idx, mode);
2959
2960     /* Validate the parameters as much as possible */
2961     if (!mode || adapter_idx >= wined3d->adapter_count
2962             || mode_idx >= wined3d_get_adapter_mode_count(wined3d, adapter_idx, format_id))
2963     {
2964         return WINED3DERR_INVALIDCALL;
2965     }
2966
2967     /* TODO: Store modes per adapter and read it from the adapter structure */
2968     if (!adapter_idx)
2969     {
2970         const struct wined3d_format *format = wined3d_get_format(&wined3d->adapters[adapter_idx].gl_info, format_id);
2971         UINT format_bits = format->byte_count * CHAR_BIT;
2972         DEVMODEW DevModeW;
2973         int ModeIdx = 0;
2974         UINT i = 0;
2975         int j = 0;
2976
2977         ZeroMemory(&DevModeW, sizeof(DevModeW));
2978         DevModeW.dmSize = sizeof(DevModeW);
2979
2980         /* If we are filtering to a specific format (D3D9), then need to skip
2981            all unrelated modes, but if mode is irrelevant (D3D8), then we can
2982            just count through the ones with valid bit depths */
2983         while (i <= mode_idx && EnumDisplaySettingsExW(NULL, j++, &DevModeW, 0))
2984         {
2985             if (format_id == WINED3DFMT_UNKNOWN)
2986             {
2987                 /* This is for D3D8, do not enumerate P8 here */
2988                 if (DevModeW.dmBitsPerPel == 32 || DevModeW.dmBitsPerPel == 16) ++i;
2989             }
2990             else if (DevModeW.dmBitsPerPel == format_bits)
2991             {
2992                 ++i;
2993             }
2994         }
2995
2996         if (!i)
2997         {
2998             TRACE_(d3d_caps)("No modes found for format (%x - %s)\n", format_id, debug_d3dformat(format_id));
2999             return WINED3DERR_INVALIDCALL;
3000         }
3001         ModeIdx = j - 1;
3002
3003         /* Now get the display mode via the calculated index */
3004         if (EnumDisplaySettingsExW(NULL, ModeIdx, &DevModeW, 0))
3005         {
3006             mode->width = DevModeW.dmPelsWidth;
3007             mode->height = DevModeW.dmPelsHeight;
3008             mode->refresh_rate = DEFAULT_REFRESH_RATE;
3009             if (DevModeW.dmFields & DM_DISPLAYFREQUENCY)
3010                 mode->refresh_rate = DevModeW.dmDisplayFrequency;
3011
3012             if (format_id == WINED3DFMT_UNKNOWN)
3013                 mode->format_id = pixelformat_for_depth(DevModeW.dmBitsPerPel);
3014             else
3015                 mode->format_id = format_id;
3016         }
3017         else
3018         {
3019             TRACE_(d3d_caps)("Requested mode %u out of range.\n", mode_idx);
3020             return WINED3DERR_INVALIDCALL;
3021         }
3022
3023         TRACE_(d3d_caps)("W %d H %d rr %d fmt (%x - %s) bpp %u\n",
3024                 mode->width, mode->height, mode->refresh_rate, mode->format_id,
3025                 debug_d3dformat(mode->format_id), DevModeW.dmBitsPerPel);
3026     }
3027     else
3028     {
3029         FIXME_(d3d_caps)("Adapter not primary display\n");
3030     }
3031
3032     return WINED3D_OK;
3033 }
3034
3035 HRESULT CDECL wined3d_get_adapter_display_mode(const struct wined3d *wined3d, UINT adapter_idx,
3036         struct wined3d_display_mode *mode)
3037 {
3038     TRACE("wined3d %p, adapter_idx %u, display_mode %p.\n", wined3d, adapter_idx, mode);
3039
3040     if (!mode || adapter_idx >= wined3d->adapter_count)
3041         return WINED3DERR_INVALIDCALL;
3042
3043     if (!adapter_idx)
3044     {
3045         DEVMODEW DevModeW;
3046         unsigned int bpp;
3047
3048         ZeroMemory(&DevModeW, sizeof(DevModeW));
3049         DevModeW.dmSize = sizeof(DevModeW);
3050
3051         EnumDisplaySettingsExW(NULL, ENUM_CURRENT_SETTINGS, &DevModeW, 0);
3052         mode->width = DevModeW.dmPelsWidth;
3053         mode->height = DevModeW.dmPelsHeight;
3054         bpp = DevModeW.dmBitsPerPel;
3055         mode->refresh_rate = DEFAULT_REFRESH_RATE;
3056         if (DevModeW.dmFields & DM_DISPLAYFREQUENCY)
3057             mode->refresh_rate = DevModeW.dmDisplayFrequency;
3058         mode->format_id = pixelformat_for_depth(bpp);
3059     }
3060     else
3061     {
3062         FIXME_(d3d_caps)("Adapter not primary display\n");
3063     }
3064
3065     TRACE_(d3d_caps)("returning w:%d, h:%d, ref:%d, fmt:%s\n", mode->width,
3066           mode->height, mode->refresh_rate, debug_d3dformat(mode->format_id));
3067     return WINED3D_OK;
3068 }
3069
3070 /* NOTE: due to structure differences between dx8 and dx9 D3DADAPTER_IDENTIFIER,
3071    and fields being inserted in the middle, a new structure is used in place    */
3072 HRESULT CDECL wined3d_get_adapter_identifier(const struct wined3d *wined3d,
3073         UINT adapter_idx, DWORD flags, struct wined3d_adapter_identifier *identifier)
3074 {
3075     const struct wined3d_adapter *adapter;
3076     size_t len;
3077
3078     TRACE_(d3d_caps)("wined3d %p, adapter_idx %u, flags %#x, indentifier %p.\n",
3079             wined3d, adapter_idx, flags, identifier);
3080
3081     if (adapter_idx >= wined3d->adapter_count)
3082         return WINED3DERR_INVALIDCALL;
3083
3084     adapter = &wined3d->adapters[adapter_idx];
3085
3086     /* Return the information requested */
3087     TRACE_(d3d_caps)("device/Vendor Name and Version detection using FillGLCaps\n");
3088
3089     if (identifier->driver_size)
3090     {
3091         const char *name = adapter->driver_info.name;
3092         len = min(strlen(name), identifier->driver_size - 1);
3093         memcpy(identifier->driver, name, len);
3094         identifier->driver[len] = '\0';
3095     }
3096
3097     if (identifier->description_size)
3098     {
3099         const char *description = adapter->driver_info.description;
3100         len = min(strlen(description), identifier->description_size - 1);
3101         memcpy(identifier->description, description, len);
3102         identifier->description[len] = '\0';
3103     }
3104
3105     /* Note that d3d8 doesn't supply a device name. */
3106     if (identifier->device_name_size)
3107     {
3108         static const char *device_name = "\\\\.\\DISPLAY1"; /* FIXME: May depend on desktop? */
3109
3110         len = strlen(device_name);
3111         if (len >= identifier->device_name_size)
3112         {
3113             ERR("Device name size too small.\n");
3114             return WINED3DERR_INVALIDCALL;
3115         }
3116
3117         memcpy(identifier->device_name, device_name, len);
3118         identifier->device_name[len] = '\0';
3119     }
3120
3121     identifier->driver_version.u.HighPart = adapter->driver_info.version_high;
3122     identifier->driver_version.u.LowPart = adapter->driver_info.version_low;
3123     identifier->vendor_id = adapter->driver_info.vendor;
3124     identifier->device_id = adapter->driver_info.device;
3125     identifier->subsystem_id = 0;
3126     identifier->revision = 0;
3127     memcpy(&identifier->device_identifier, &IID_D3DDEVICE_D3DUID, sizeof(identifier->device_identifier));
3128     identifier->whql_level = (flags & WINED3DENUM_NO_WHQL_LEVEL) ? 0 : 1;
3129     memcpy(&identifier->adapter_luid, &adapter->luid, sizeof(identifier->adapter_luid));
3130     identifier->video_memory = adapter->TextureRam;
3131
3132     return WINED3D_OK;
3133 }
3134
3135 static BOOL wined3d_check_pixel_format_color(const struct wined3d_gl_info *gl_info,
3136         const struct wined3d_pixel_format *cfg, const struct wined3d_format *format)
3137 {
3138     BYTE redSize, greenSize, blueSize, alphaSize, colorBits;
3139
3140     /* Float formats need FBOs. If FBOs are used this function isn't called */
3141     if (format->flags & WINED3DFMT_FLAG_FLOAT) return FALSE;
3142
3143     if(cfg->iPixelType == WGL_TYPE_RGBA_ARB) { /* Integer RGBA formats */
3144         if (!getColorBits(format, &redSize, &greenSize, &blueSize, &alphaSize, &colorBits))
3145         {
3146             ERR("Unable to check compatibility for format %s.\n", debug_d3dformat(format->id));
3147             return FALSE;
3148         }
3149
3150         if(cfg->redSize < redSize)
3151             return FALSE;
3152
3153         if(cfg->greenSize < greenSize)
3154             return FALSE;
3155
3156         if(cfg->blueSize < blueSize)
3157             return FALSE;
3158
3159         if(cfg->alphaSize < alphaSize)
3160             return FALSE;
3161
3162         return TRUE;
3163     }
3164
3165     /* Probably a RGBA_float or color index mode */
3166     return FALSE;
3167 }
3168
3169 static BOOL wined3d_check_pixel_format_depth(const struct wined3d_gl_info *gl_info,
3170         const struct wined3d_pixel_format *cfg, const struct wined3d_format *format)
3171 {
3172     BYTE depthSize, stencilSize;
3173     BOOL lockable = FALSE;
3174
3175     if (!getDepthStencilBits(format, &depthSize, &stencilSize))
3176     {
3177         ERR("Unable to check compatibility for format %s.\n", debug_d3dformat(format->id));
3178         return FALSE;
3179     }
3180
3181     /* Float formats need FBOs. If FBOs are used this function isn't called */
3182     if (format->flags & WINED3DFMT_FLAG_FLOAT) return FALSE;
3183
3184     if ((format->id == WINED3DFMT_D16_LOCKABLE) || (format->id == WINED3DFMT_D32_FLOAT))
3185         lockable = TRUE;
3186
3187     /* On some modern cards like the Geforce8/9 GLX doesn't offer some dephthstencil formats which D3D9 reports.
3188      * We can safely report 'compatible' formats (e.g. D24 can be used for D16) as long as we aren't dealing with
3189      * a lockable format. This also helps D3D <= 7 as they expect D16 which isn't offered without this on Geforce8 cards. */
3190     if(!(cfg->depthSize == depthSize || (!lockable && cfg->depthSize > depthSize)))
3191         return FALSE;
3192
3193     /* Some cards like Intel i915 ones only offer D24S8 but lots of games also need a format without stencil, so
3194      * allow more stencil bits than requested. */
3195     if(cfg->stencilSize < stencilSize)
3196         return FALSE;
3197
3198     return TRUE;
3199 }
3200
3201 HRESULT CDECL wined3d_check_depth_stencil_match(const struct wined3d *wined3d,
3202         UINT adapter_idx, enum wined3d_device_type device_type, enum wined3d_format_id adapter_format_id,
3203         enum wined3d_format_id render_target_format_id, enum wined3d_format_id depth_stencil_format_id)
3204 {
3205     const struct wined3d_format *rt_format;
3206     const struct wined3d_format *ds_format;
3207     const struct wined3d_adapter *adapter;
3208
3209     TRACE_(d3d_caps)("wined3d %p, adapter_idx %u, device_type %s,\n"
3210             "adapter_format %s, render_target_format %s, depth_stencil_format %s.\n",
3211             wined3d, adapter_idx, debug_d3ddevicetype(device_type), debug_d3dformat(adapter_format_id),
3212             debug_d3dformat(render_target_format_id), debug_d3dformat(depth_stencil_format_id));
3213
3214     if (adapter_idx >= wined3d->adapter_count)
3215         return WINED3DERR_INVALIDCALL;
3216
3217     adapter = &wined3d->adapters[adapter_idx];
3218     rt_format = wined3d_get_format(&adapter->gl_info, render_target_format_id);
3219     ds_format = wined3d_get_format(&adapter->gl_info, depth_stencil_format_id);
3220     if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
3221     {
3222         if ((rt_format->flags & WINED3DFMT_FLAG_RENDERTARGET)
3223                 && (ds_format->flags & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL)))
3224         {
3225             TRACE_(d3d_caps)("Formats match.\n");
3226             return WINED3D_OK;
3227         }
3228     }
3229     else
3230     {
3231         const struct wined3d_pixel_format *cfgs;
3232         unsigned int cfg_count;
3233         unsigned int i;
3234
3235         cfgs = adapter->cfgs;
3236         cfg_count = adapter->cfg_count;
3237         for (i = 0; i < cfg_count; ++i)
3238         {
3239             if (wined3d_check_pixel_format_color(&adapter->gl_info, &cfgs[i], rt_format)
3240                     && wined3d_check_pixel_format_depth(&adapter->gl_info, &cfgs[i], ds_format))
3241             {
3242                 TRACE_(d3d_caps)("Formats match.\n");
3243                 return WINED3D_OK;
3244             }
3245         }
3246     }
3247
3248     TRACE_(d3d_caps)("Unsupported format pair: %s and %s.\n",
3249             debug_d3dformat(render_target_format_id),
3250             debug_d3dformat(depth_stencil_format_id));
3251
3252     return WINED3DERR_NOTAVAILABLE;
3253 }
3254
3255 HRESULT CDECL wined3d_check_device_multisample_type(const struct wined3d *wined3d, UINT adapter_idx,
3256         enum wined3d_device_type device_type, enum wined3d_format_id surface_format_id, BOOL windowed,
3257         enum wined3d_multisample_type multisample_type, DWORD *quality_levels)
3258 {
3259     const struct wined3d_gl_info *gl_info;
3260
3261     TRACE_(d3d_caps)("wined3d %p, adapter_idx %u, device_type %s, surface_format %s,\n"
3262             "windowed %#x, multisample_type %#x, quality_levels %p.\n",
3263             wined3d, adapter_idx, debug_d3ddevicetype(device_type), debug_d3dformat(surface_format_id),
3264             windowed, multisample_type, quality_levels);
3265
3266     if (adapter_idx >= wined3d->adapter_count)
3267         return WINED3DERR_INVALIDCALL;
3268
3269     gl_info = &wined3d->adapters[adapter_idx].gl_info;
3270
3271     if (multisample_type > gl_info->limits.samples)
3272     {
3273         TRACE("Returning not supported.\n");
3274         if (quality_levels)
3275             *quality_levels = 0;
3276
3277         return WINED3DERR_NOTAVAILABLE;
3278     }
3279
3280     if (quality_levels)
3281     {
3282         if (multisample_type == WINED3D_MULTISAMPLE_NON_MASKABLE)
3283             /* FIXME: This is probably wrong. */
3284             *quality_levels = gl_info->limits.samples;
3285         else
3286             *quality_levels = 1;
3287     }
3288
3289     return WINED3D_OK;
3290 }
3291
3292 /* Check if we support bumpmapping for a format */
3293 static BOOL CheckBumpMapCapability(const struct wined3d_adapter *adapter, const struct wined3d_format *format)
3294 {
3295     /* Ask the fixed function pipeline implementation if it can deal
3296      * with the conversion. If we've got a GL extension giving native
3297      * support this will be an identity conversion. */
3298     return (format->flags & WINED3DFMT_FLAG_BUMPMAP)
3299             && adapter->fragment_pipe->color_fixup_supported(format->color_fixup);
3300 }
3301
3302 /* Check if the given DisplayFormat + DepthStencilFormat combination is valid for the Adapter */
3303 static BOOL CheckDepthStencilCapability(const struct wined3d_adapter *adapter,
3304         const struct wined3d_format *display_format, const struct wined3d_format *ds_format)
3305 {
3306     /* Only allow depth/stencil formats */
3307     if (!(ds_format->depth_size || ds_format->stencil_size)) return FALSE;
3308
3309     /* Blacklist formats not supported on Windows */
3310     switch (ds_format->id)
3311     {
3312         case WINED3DFMT_S1_UINT_D15_UNORM: /* Breaks the shadowvol2 dx7 sdk sample */
3313         case WINED3DFMT_S4X4_UINT_D24_UNORM:
3314             TRACE_(d3d_caps)("[FAILED] - not supported on windows\n");
3315             return FALSE;
3316
3317         default:
3318             break;
3319     }
3320
3321     if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
3322     {
3323         /* With FBOs WGL limitations do not apply, but the format needs to be FBO attachable */
3324         if (ds_format->flags & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL)) return TRUE;
3325     }
3326     else
3327     {
3328         unsigned int i;
3329
3330         /* Walk through all WGL pixel formats to find a match */
3331         for (i = 0; i < adapter->cfg_count; ++i)
3332         {
3333             const struct wined3d_pixel_format *cfg = &adapter->cfgs[i];
3334             if (wined3d_check_pixel_format_color(&adapter->gl_info, cfg, display_format)
3335                     && wined3d_check_pixel_format_depth(&adapter->gl_info, cfg, ds_format))
3336                 return TRUE;
3337         }
3338     }
3339
3340     return FALSE;
3341 }
3342
3343 static BOOL CheckFilterCapability(const struct wined3d_adapter *adapter, const struct wined3d_format *format)
3344 {
3345     /* The flags entry of a format contains the filtering capability */
3346     if ((format->flags & WINED3DFMT_FLAG_FILTERING)
3347             || !(adapter->gl_info.quirks & WINED3D_QUIRK_LIMITED_TEX_FILTERING))
3348         return TRUE;
3349
3350     return FALSE;
3351 }
3352
3353 /* Check the render target capabilities of a format */
3354 static BOOL CheckRenderTargetCapability(const struct wined3d_adapter *adapter,
3355         const struct wined3d_format *adapter_format, const struct wined3d_format *check_format)
3356 {
3357     /* Filter out non-RT formats */
3358     if (!(check_format->flags & WINED3DFMT_FLAG_RENDERTARGET)) return FALSE;
3359     if (wined3d_settings.offscreen_rendering_mode == ORM_BACKBUFFER)
3360     {
3361         BYTE AdapterRed, AdapterGreen, AdapterBlue, AdapterAlpha, AdapterTotalSize;
3362         BYTE CheckRed, CheckGreen, CheckBlue, CheckAlpha, CheckTotalSize;
3363         const struct wined3d_pixel_format *cfgs = adapter->cfgs;
3364         unsigned int i;
3365
3366         getColorBits(adapter_format, &AdapterRed, &AdapterGreen, &AdapterBlue, &AdapterAlpha, &AdapterTotalSize);
3367         getColorBits(check_format, &CheckRed, &CheckGreen, &CheckBlue, &CheckAlpha, &CheckTotalSize);
3368
3369         /* In backbuffer mode the front and backbuffer share the same WGL pixelformat.
3370          * The format must match in RGB, alpha is allowed to be different. (Only the backbuffer can have alpha) */
3371         if(!((AdapterRed == CheckRed) && (AdapterGreen == CheckGreen) && (AdapterBlue == CheckBlue))) {
3372             TRACE_(d3d_caps)("[FAILED]\n");
3373             return FALSE;
3374         }
3375
3376         /* Check if there is a WGL pixel format matching the requirements, the format should also be window
3377          * drawable (not offscreen; e.g. Nvidia offers R5G6B5 for pbuffers even when X is running at 24bit) */
3378         for (i = 0; i < adapter->cfg_count; ++i)
3379         {
3380             if (cfgs[i].windowDrawable
3381                     && wined3d_check_pixel_format_color(&adapter->gl_info, &cfgs[i], check_format))
3382             {
3383                 TRACE_(d3d_caps)("Pixel format %d is compatible with format %s.\n",
3384                         cfgs[i].iPixelFormat, debug_d3dformat(check_format->id));
3385                 return TRUE;
3386             }
3387         }
3388     }
3389     else if(wined3d_settings.offscreen_rendering_mode == ORM_FBO)
3390     {
3391         /* For now return TRUE for FBOs until we have some proper checks.
3392          * Note that this function will only be called when the format is around for texturing. */
3393         return TRUE;
3394     }
3395     return FALSE;
3396 }
3397
3398 static BOOL CheckSrgbReadCapability(const struct wined3d_adapter *adapter, const struct wined3d_format *format)
3399 {
3400     return format->flags & WINED3DFMT_FLAG_SRGB_READ;
3401 }
3402
3403 static BOOL CheckSrgbWriteCapability(const struct wined3d_adapter *adapter, const struct wined3d_format *format)
3404 {
3405     /* Only offer SRGB writing on X8R8G8B8/A8R8G8B8 when we use ARB or GLSL shaders as we are
3406      * doing the color fixup in shaders.
3407      * Note Windows drivers (at least on the Geforce 8800) also offer this on R5G6B5. */
3408     if (format->flags & WINED3DFMT_FLAG_SRGB_WRITE)
3409     {
3410         int vs_selected_mode;
3411         int ps_selected_mode;
3412         select_shader_mode(&adapter->gl_info, &ps_selected_mode, &vs_selected_mode);
3413
3414         if((ps_selected_mode == SHADER_ARB) || (ps_selected_mode == SHADER_GLSL)) {
3415             TRACE_(d3d_caps)("[OK]\n");
3416             return TRUE;
3417         }
3418     }
3419
3420     TRACE_(d3d_caps)("[FAILED] - sRGB writes not supported by format %s.\n", debug_d3dformat(format->id));
3421     return FALSE;
3422 }
3423
3424 /* Check if a format support blending in combination with pixel shaders */
3425 static BOOL CheckPostPixelShaderBlendingCapability(const struct wined3d_adapter *adapter,
3426         const struct wined3d_format *format)
3427 {
3428     /* The flags entry of a format contains the post pixel shader blending capability */
3429     if (format->flags & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING) return TRUE;
3430
3431     return FALSE;
3432 }
3433
3434 static BOOL CheckWrapAndMipCapability(const struct wined3d_adapter *adapter, const struct wined3d_format *format)
3435 {
3436     /* OpenGL supports mipmapping on all formats basically. Wrapping is unsupported,
3437      * but we have to report mipmapping so we cannot reject this flag. Tests show that
3438      * windows reports WRAPANDMIP on unfilterable surfaces as well, apparently to show
3439      * that wrapping is supported. The lack of filtering will sort out the mipmapping
3440      * capability anyway.
3441      *
3442      * For now lets report this on all formats, but in the future we may want to
3443      * restrict it to some should games need that
3444      */
3445     return TRUE;
3446 }
3447
3448 /* Check if a texture format is supported on the given adapter */
3449 static BOOL CheckTextureCapability(const struct wined3d_adapter *adapter, const struct wined3d_format *format)
3450 {
3451     const struct wined3d_gl_info *gl_info = &adapter->gl_info;
3452
3453     switch (format->id)
3454     {
3455         /*****
3456          *  supported: RGB(A) formats
3457          */
3458         case WINED3DFMT_B8G8R8_UNORM:
3459             TRACE_(d3d_caps)("[FAILED] - Not enumerated on Windows\n");
3460             return FALSE;
3461         case WINED3DFMT_B8G8R8A8_UNORM:
3462         case WINED3DFMT_B8G8R8X8_UNORM:
3463         case WINED3DFMT_B5G6R5_UNORM:
3464         case WINED3DFMT_B5G5R5X1_UNORM:
3465         case WINED3DFMT_B5G5R5A1_UNORM:
3466         case WINED3DFMT_B4G4R4A4_UNORM:
3467         case WINED3DFMT_A8_UNORM:
3468         case WINED3DFMT_B4G4R4X4_UNORM:
3469         case WINED3DFMT_R8G8B8A8_UNORM:
3470         case WINED3DFMT_R8G8B8X8_UNORM:
3471         case WINED3DFMT_B10G10R10A2_UNORM:
3472         case WINED3DFMT_R10G10B10A2_UNORM:
3473         case WINED3DFMT_R16G16_UNORM:
3474             TRACE_(d3d_caps)("[OK]\n");
3475             return TRUE;
3476
3477         case WINED3DFMT_B2G3R3_UNORM:
3478             TRACE_(d3d_caps)("[FAILED] - Not supported on Windows\n");
3479             return FALSE;
3480
3481         /*****
3482          *  Not supported: Palettized
3483          *  Only some Geforce/Voodoo3/G400 cards offer 8-bit textures in case of <=Direct3D7.
3484          *  Since it is not widely available, don't offer it. Further no Windows driver offers
3485          *  WINED3DFMT_P8_UINT_A8_NORM, so don't offer it either.
3486          */
3487         case WINED3DFMT_P8_UINT:
3488         case WINED3DFMT_P8_UINT_A8_UNORM:
3489             return FALSE;
3490
3491         /*****
3492          *  Supported: (Alpha)-Luminance
3493          */
3494         case WINED3DFMT_L8_UNORM:
3495         case WINED3DFMT_L8A8_UNORM:
3496         case WINED3DFMT_L16_UNORM:
3497             TRACE_(d3d_caps)("[OK]\n");
3498             return TRUE;
3499
3500         /* Not supported on Windows, thus disabled */
3501         case WINED3DFMT_L4A4_UNORM:
3502             TRACE_(d3d_caps)("[FAILED] - not supported on windows\n");
3503             return FALSE;
3504
3505         /*****
3506          *  Supported: Depth/Stencil formats
3507          */
3508         case WINED3DFMT_D16_LOCKABLE:
3509         case WINED3DFMT_D16_UNORM:
3510         case WINED3DFMT_X8D24_UNORM:
3511         case WINED3DFMT_D24_UNORM_S8_UINT:
3512         case WINED3DFMT_S8_UINT_D24_FLOAT:
3513         case WINED3DFMT_D32_UNORM:
3514         case WINED3DFMT_D32_FLOAT:
3515             return TRUE;
3516
3517         case WINED3DFMT_INTZ:
3518             if (gl_info->supported[EXT_PACKED_DEPTH_STENCIL]
3519                     || gl_info->supported[ARB_FRAMEBUFFER_OBJECT])
3520                 return TRUE;
3521             return FALSE;
3522
3523         /* Not supported on Windows */
3524         case WINED3DFMT_S1_UINT_D15_UNORM:
3525         case WINED3DFMT_S4X4_UINT_D24_UNORM:
3526             TRACE_(d3d_caps)("[FAILED] - not supported on windows\n");
3527             return FALSE;
3528
3529         /*****
3530          *  Not supported everywhere(depends on GL_ATI_envmap_bumpmap or
3531          *  GL_NV_texture_shader). Emulated by shaders
3532          */
3533         case WINED3DFMT_R8G8_SNORM:
3534         case WINED3DFMT_R8G8_SNORM_L8X8_UNORM:
3535         case WINED3DFMT_R5G5_SNORM_L6_UNORM:
3536         case WINED3DFMT_R8G8B8A8_SNORM:
3537         case WINED3DFMT_R16G16_SNORM:
3538             /* Ask the shader backend if it can deal with the conversion. If
3539              * we've got a GL extension giving native support this will be an
3540              * identity conversion. */
3541             if (adapter->shader_backend->shader_color_fixup_supported(format->color_fixup))
3542             {
3543                 TRACE_(d3d_caps)("[OK]\n");
3544                 return TRUE;
3545             }
3546             TRACE_(d3d_caps)("[FAILED]\n");
3547             return FALSE;
3548
3549         case WINED3DFMT_DXT1:
3550         case WINED3DFMT_DXT2:
3551         case WINED3DFMT_DXT3:
3552         case WINED3DFMT_DXT4:
3553         case WINED3DFMT_DXT5:
3554             if (gl_info->supported[EXT_TEXTURE_COMPRESSION_S3TC])
3555             {
3556                 TRACE_(d3d_caps)("[OK]\n");
3557                 return TRUE;
3558             }
3559             TRACE_(d3d_caps)("[FAILED]\n");
3560             return FALSE;
3561
3562
3563         /*****
3564          *  Odd formats - not supported
3565          */
3566         case WINED3DFMT_VERTEXDATA:
3567         case WINED3DFMT_R16_UINT:
3568         case WINED3DFMT_R32_UINT:
3569         case WINED3DFMT_R16G16B16A16_SNORM:
3570         case WINED3DFMT_R10G10B10_SNORM_A2_UNORM:
3571         case WINED3DFMT_R10G11B11_SNORM:
3572         case WINED3DFMT_R16:
3573         case WINED3DFMT_AL16:
3574             TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
3575             return FALSE;
3576
3577         /*****
3578          *  WINED3DFMT_R8G8_SNORM_Cx: Not supported right now
3579          */
3580         case WINED3DFMT_R8G8_SNORM_Cx:
3581             TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
3582             return FALSE;
3583
3584         /* YUV formats */
3585         case WINED3DFMT_UYVY:
3586         case WINED3DFMT_YUY2:
3587             if (gl_info->supported[APPLE_YCBCR_422])
3588             {
3589                 TRACE_(d3d_caps)("[OK]\n");
3590                 return TRUE;
3591             }
3592             TRACE_(d3d_caps)("[FAILED]\n");
3593             return FALSE;
3594         case WINED3DFMT_YV12:
3595             TRACE_(d3d_caps)("[FAILED]\n");
3596             return FALSE;
3597
3598         case WINED3DFMT_R16G16B16A16_UNORM:
3599             if (gl_info->quirks & WINED3D_QUIRK_BROKEN_RGBA16)
3600             {
3601                 TRACE_(d3d_caps)("[FAILED]\n");
3602                 return FALSE;
3603             }
3604             TRACE_(d3d_caps)("[OK]\n");
3605             return TRUE;
3606
3607             /* Not supported */
3608         case WINED3DFMT_B2G3R3A8_UNORM:
3609             TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
3610             return FALSE;
3611
3612             /* Floating point formats */
3613         case WINED3DFMT_R16_FLOAT:
3614         case WINED3DFMT_R16G16_FLOAT:
3615         case WINED3DFMT_R16G16B16A16_FLOAT:
3616             if (gl_info->supported[ARB_TEXTURE_FLOAT] && gl_info->supported[ARB_HALF_FLOAT_PIXEL])
3617             {
3618                 TRACE_(d3d_caps)("[OK]\n");
3619                 return TRUE;
3620             }
3621             TRACE_(d3d_caps)("[FAILED]\n");
3622             return FALSE;
3623
3624         case WINED3DFMT_R32_FLOAT:
3625         case WINED3DFMT_R32G32_FLOAT:
3626         case WINED3DFMT_R32G32B32A32_FLOAT:
3627             if (gl_info->supported[ARB_TEXTURE_FLOAT])
3628             {
3629                 TRACE_(d3d_caps)("[OK]\n");
3630                 return TRUE;
3631             }
3632             TRACE_(d3d_caps)("[FAILED]\n");
3633             return FALSE;
3634
3635         /* ATI instancing hack: Although ATI cards do not support Shader Model 3.0, they support
3636          * instancing. To query if the card supports instancing CheckDeviceFormat with the special format
3637          * MAKEFOURCC('I','N','S','T') is used. Should a (broken) app check for this provide a proper return value.
3638          * We can do instancing with all shader versions, but we need vertex shaders.
3639          *
3640          * Additionally applications have to set the D3DRS_POINTSIZE render state to MAKEFOURCC('I','N','S','T') once
3641          * to enable instancing. WineD3D doesn't need that and just ignores it.
3642          *
3643          * With Shader Model 3.0 capable cards Instancing 'just works' in Windows.
3644          */
3645         case WINED3DFMT_INST:
3646             TRACE("ATI Instancing check hack\n");
3647             if (gl_info->supported[ARB_VERTEX_PROGRAM] || gl_info->supported[ARB_VERTEX_SHADER])
3648             {
3649                 TRACE_(d3d_caps)("[OK]\n");
3650                 return TRUE;
3651             }
3652             TRACE_(d3d_caps)("[FAILED]\n");
3653             return FALSE;
3654
3655         /* Some weird FOURCC formats */
3656         case WINED3DFMT_R8G8_B8G8:
3657         case WINED3DFMT_G8R8_G8B8:
3658         case WINED3DFMT_MULTI2_ARGB8:
3659             TRACE_(d3d_caps)("[FAILED]\n");
3660             return FALSE;
3661
3662         /* Vendor specific formats */
3663         case WINED3DFMT_ATI2N:
3664             if (gl_info->supported[ATI_TEXTURE_COMPRESSION_3DC]
3665                     || gl_info->supported[ARB_TEXTURE_COMPRESSION_RGTC])
3666             {
3667                 if (adapter->shader_backend->shader_color_fixup_supported(format->color_fixup)
3668                         && adapter->fragment_pipe->color_fixup_supported(format->color_fixup))
3669                 {
3670                     TRACE_(d3d_caps)("[OK]\n");
3671                     return TRUE;
3672                 }
3673
3674                 TRACE_(d3d_caps)("[OK]\n");
3675                 return TRUE;
3676             }
3677             TRACE_(d3d_caps)("[FAILED]\n");
3678             return FALSE;
3679
3680         /* Depth bound test. To query if the card supports it CheckDeviceFormat with the special
3681          * format MAKEFOURCC('N','V','D','B') is used.
3682          * It is enabled by setting D3DRS_ADAPTIVETESS_X render state to MAKEFOURCC('N','V','D','B') and
3683          * then controlled by setting D3DRS_ADAPTIVETESS_Z (zMin) and D3DRS_ADAPTIVETESS_W (zMax)
3684          * to test value.
3685          */
3686         case WINED3DFMT_NVDB:
3687             if (gl_info->supported[EXT_DEPTH_BOUNDS_TEST])
3688             {
3689                 TRACE_(d3d_caps)("[OK]\n");
3690                 return TRUE;
3691             }
3692             TRACE_(d3d_caps)("[FAILED]\n");
3693             return FALSE;
3694
3695         case WINED3DFMT_NVHU:
3696         case WINED3DFMT_NVHS:
3697             /* These formats seem to be similar to the HILO formats in GL_NV_texture_shader. NVHU
3698              * is said to be GL_UNSIGNED_HILO16, NVHS GL_SIGNED_HILO16. Rumours say that d3d computes
3699              * a 3rd channel similarly to D3DFMT_CxV8U8(So NVHS could be called D3DFMT_CxV16U16).
3700              * ATI refused to support formats which can easily be emulated with pixel shaders, so
3701              * Applications have to deal with not having NVHS and NVHU.
3702              */
3703             TRACE_(d3d_caps)("[FAILED]\n");
3704             return FALSE;
3705
3706         case WINED3DFMT_NULL:
3707             if (gl_info->supported[ARB_FRAMEBUFFER_OBJECT])
3708                 return TRUE;
3709             return FALSE;
3710
3711         case WINED3DFMT_UNKNOWN:
3712             return FALSE;
3713
3714         default:
3715             ERR("Unhandled format %s.\n", debug_d3dformat(format->id));
3716             break;
3717     }
3718     return FALSE;
3719 }
3720
3721 static BOOL CheckSurfaceCapability(const struct wined3d_adapter *adapter,
3722         const struct wined3d_format *adapter_format,
3723         const struct wined3d_format *check_format,
3724         enum wined3d_surface_type surface_type)
3725 {
3726     if (surface_type == WINED3D_SURFACE_TYPE_GDI)
3727     {
3728         switch (check_format->id)
3729         {
3730             case WINED3DFMT_B8G8R8_UNORM:
3731                 TRACE_(d3d_caps)("[FAILED] - Not enumerated on Windows\n");
3732                 return FALSE;
3733             case WINED3DFMT_B8G8R8A8_UNORM:
3734             case WINED3DFMT_B8G8R8X8_UNORM:
3735             case WINED3DFMT_B5G6R5_UNORM:
3736             case WINED3DFMT_B5G5R5X1_UNORM:
3737             case WINED3DFMT_B5G5R5A1_UNORM:
3738             case WINED3DFMT_B4G4R4A4_UNORM:
3739             case WINED3DFMT_B2G3R3_UNORM:
3740             case WINED3DFMT_A8_UNORM:
3741             case WINED3DFMT_B2G3R3A8_UNORM:
3742             case WINED3DFMT_B4G4R4X4_UNORM:
3743             case WINED3DFMT_R10G10B10A2_UNORM:
3744             case WINED3DFMT_R8G8B8A8_UNORM:
3745             case WINED3DFMT_R8G8B8X8_UNORM:
3746             case WINED3DFMT_R16G16_UNORM:
3747             case WINED3DFMT_B10G10R10A2_UNORM:
3748             case WINED3DFMT_R16G16B16A16_UNORM:
3749             case WINED3DFMT_P8_UINT:
3750                 TRACE_(d3d_caps)("[OK]\n");
3751                 return TRUE;
3752             default:
3753                 TRACE_(d3d_caps)("[FAILED] - not available on GDI surfaces\n");
3754                 return FALSE;
3755         }
3756     }
3757
3758     /* All format that are supported for textures are supported for surfaces as well */
3759     if (CheckTextureCapability(adapter, check_format)) return TRUE;
3760     /* All depth stencil formats are supported on surfaces */
3761     if (CheckDepthStencilCapability(adapter, adapter_format, check_format)) return TRUE;
3762
3763     /* If opengl can't process the format natively, the blitter may be able to convert it */
3764     if (adapter->blitter->blit_supported(&adapter->gl_info, WINED3D_BLIT_OP_COLOR_BLIT,
3765             NULL, WINED3D_POOL_DEFAULT, 0, check_format,
3766             NULL, WINED3D_POOL_DEFAULT, 0, adapter_format))
3767     {
3768         TRACE_(d3d_caps)("[OK]\n");
3769         return TRUE;
3770     }
3771
3772     /* Reject other formats */
3773     TRACE_(d3d_caps)("[FAILED]\n");
3774     return FALSE;
3775 }
3776
3777 static BOOL CheckVertexTextureCapability(const struct wined3d_adapter *adapter,
3778         const struct wined3d_format *format)
3779 {
3780     const struct wined3d_gl_info *gl_info = &adapter->gl_info;
3781
3782     if (!gl_info->limits.vertex_samplers || !(format->flags & WINED3DFMT_FLAG_VTF))
3783         return FALSE;
3784
3785     switch (format->id)
3786     {
3787         case WINED3DFMT_R32G32B32A32_FLOAT:
3788         case WINED3DFMT_R32_FLOAT:
3789             return TRUE;
3790         default:
3791             return !(gl_info->quirks & WINED3D_QUIRK_LIMITED_TEX_FILTERING);
3792     }
3793 }
3794
3795 HRESULT CDECL wined3d_check_device_format(const struct wined3d *wined3d, UINT adapter_idx,
3796         enum wined3d_device_type device_type, enum wined3d_format_id adapter_format_id, DWORD usage,
3797         enum wined3d_resource_type resource_type, enum wined3d_format_id check_format_id,
3798         enum wined3d_surface_type surface_type)
3799 {
3800     const struct wined3d_adapter *adapter = &wined3d->adapters[adapter_idx];
3801     const struct wined3d_gl_info *gl_info = &adapter->gl_info;
3802     const struct wined3d_format *adapter_format = wined3d_get_format(gl_info, adapter_format_id);
3803     const struct wined3d_format *format = wined3d_get_format(gl_info, check_format_id);
3804     DWORD usage_caps = 0;
3805
3806     TRACE_(d3d_caps)("wined3d %p, adapter_idx %u, device_type %s, adapter_format %s, usage %s, %s,\n"
3807             "resource_type %s, check_format %s, surface_type %#x.\n",
3808             wined3d, adapter_idx, debug_d3ddevicetype(device_type), debug_d3dformat(adapter_format_id),
3809             debug_d3dusage(usage), debug_d3dusagequery(usage), debug_d3dresourcetype(resource_type),
3810             debug_d3dformat(check_format_id), surface_type);
3811
3812     if (adapter_idx >= wined3d->adapter_count)
3813         return WINED3DERR_INVALIDCALL;
3814
3815     switch (resource_type)
3816     {
3817         case WINED3D_RTYPE_CUBE_TEXTURE:
3818             /* Cubetexture allows:
3819              *      - WINED3DUSAGE_AUTOGENMIPMAP
3820              *      - WINED3DUSAGE_DEPTHSTENCIL
3821              *      - WINED3DUSAGE_DYNAMIC
3822              *      - WINED3DUSAGE_NONSECURE (d3d9ex)
3823              *      - WINED3DUSAGE_RENDERTARGET
3824              *      - WINED3DUSAGE_SOFTWAREPROCESSING
3825              *      - WINED3DUSAGE_QUERY_WRAPANDMIP
3826              */
3827             if (surface_type != WINED3D_SURFACE_TYPE_OPENGL)
3828             {
3829                 TRACE_(d3d_caps)("[FAILED]\n");
3830                 return WINED3DERR_NOTAVAILABLE;
3831             }
3832
3833             if (!gl_info->supported[ARB_TEXTURE_CUBE_MAP])
3834             {
3835                 TRACE_(d3d_caps)("[FAILED] - No cube texture support\n");
3836                 return WINED3DERR_NOTAVAILABLE;
3837             }
3838
3839             if (!CheckTextureCapability(adapter, format))
3840             {
3841                 TRACE_(d3d_caps)("[FAILED] - Cube texture format not supported\n");
3842                 return WINED3DERR_NOTAVAILABLE;
3843             }
3844
3845             if (usage & WINED3DUSAGE_AUTOGENMIPMAP)
3846             {
3847                 if (!gl_info->supported[SGIS_GENERATE_MIPMAP])
3848                     /* When autogenmipmap isn't around continue and return
3849                      * WINED3DOK_NOAUTOGEN instead of D3D_OK. */
3850                     TRACE_(d3d_caps)("[FAILED] - No autogenmipmap support, but continuing\n");
3851                 else
3852                     usage_caps |= WINED3DUSAGE_AUTOGENMIPMAP;
3853             }
3854
3855             /* Always report dynamic locking. */
3856             if (usage & WINED3DUSAGE_DYNAMIC)
3857                 usage_caps |= WINED3DUSAGE_DYNAMIC;
3858
3859             if (usage & WINED3DUSAGE_RENDERTARGET)
3860             {
3861                 if (!CheckRenderTargetCapability(adapter, adapter_format, format))
3862                 {
3863                     TRACE_(d3d_caps)("[FAILED] - No rendertarget support\n");
3864                     return WINED3DERR_NOTAVAILABLE;
3865                 }
3866                 usage_caps |= WINED3DUSAGE_RENDERTARGET;
3867             }
3868
3869             /* Always report software processing. */
3870             if (usage & WINED3DUSAGE_SOFTWAREPROCESSING)
3871                 usage_caps |= WINED3DUSAGE_SOFTWAREPROCESSING;
3872
3873             if (usage & WINED3DUSAGE_QUERY_FILTER)
3874             {
3875                 if (!CheckFilterCapability(adapter, format))
3876                 {
3877                     TRACE_(d3d_caps)("[FAILED] - No query filter support\n");
3878                     return WINED3DERR_NOTAVAILABLE;
3879                 }
3880                 usage_caps |= WINED3DUSAGE_QUERY_FILTER;
3881             }
3882
3883             if (usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING)
3884             {
3885                 if (!CheckPostPixelShaderBlendingCapability(adapter, format))
3886                 {
3887                     TRACE_(d3d_caps)("[FAILED] - No query post pixelshader blending support\n");
3888                     return WINED3DERR_NOTAVAILABLE;
3889                 }
3890                 usage_caps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
3891             }
3892
3893             if (usage & WINED3DUSAGE_QUERY_SRGBREAD)
3894             {
3895                 if (!CheckSrgbReadCapability(adapter, format))
3896                 {
3897                     TRACE_(d3d_caps)("[FAILED] - No query srgbread support\n");
3898                     return WINED3DERR_NOTAVAILABLE;
3899                 }
3900                 usage_caps |= WINED3DUSAGE_QUERY_SRGBREAD;
3901             }
3902
3903             if (usage & WINED3DUSAGE_QUERY_SRGBWRITE)
3904             {
3905                 if (!CheckSrgbWriteCapability(adapter, format))
3906                 {
3907                     TRACE_(d3d_caps)("[FAILED] - No query srgbwrite support\n");
3908                     return WINED3DERR_NOTAVAILABLE;
3909                 }
3910                 usage_caps |= WINED3DUSAGE_QUERY_SRGBWRITE;
3911             }
3912
3913             if (usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE)
3914             {
3915                 if (!CheckVertexTextureCapability(adapter, format))
3916                 {
3917                     TRACE_(d3d_caps)("[FAILED] - No query vertextexture support\n");
3918                     return WINED3DERR_NOTAVAILABLE;
3919                 }
3920                 usage_caps |= WINED3DUSAGE_QUERY_VERTEXTEXTURE;
3921             }
3922
3923             if (usage & WINED3DUSAGE_QUERY_WRAPANDMIP)
3924             {
3925                 if (!CheckWrapAndMipCapability(adapter, format))
3926                 {
3927                     TRACE_(d3d_caps)("[FAILED] - No wrapping and mipmapping support\n");
3928                     return WINED3DERR_NOTAVAILABLE;
3929                 }
3930                 usage_caps |= WINED3DUSAGE_QUERY_WRAPANDMIP;
3931             }
3932             break;
3933
3934         case WINED3D_RTYPE_SURFACE:
3935             /* Surface allows:
3936              *      - WINED3DUSAGE_DEPTHSTENCIL
3937              *      - WINED3DUSAGE_NONSECURE (d3d9ex)
3938              *      - WINED3DUSAGE_RENDERTARGET
3939              */
3940             if (!CheckSurfaceCapability(adapter, adapter_format, format, surface_type))
3941             {
3942                 TRACE_(d3d_caps)("[FAILED] - Not supported for plain surfaces\n");
3943                 return WINED3DERR_NOTAVAILABLE;
3944             }
3945
3946             if (usage & WINED3DUSAGE_DEPTHSTENCIL)
3947             {
3948                 if (!CheckDepthStencilCapability(adapter, adapter_format, format))
3949                 {
3950                     TRACE_(d3d_caps)("[FAILED] - No depthstencil support\n");
3951                     return WINED3DERR_NOTAVAILABLE;
3952                 }
3953                 usage_caps |= WINED3DUSAGE_DEPTHSTENCIL;
3954             }
3955
3956             if (usage & WINED3DUSAGE_RENDERTARGET)
3957             {
3958                 if (!CheckRenderTargetCapability(adapter, adapter_format, format))
3959                 {
3960                     TRACE_(d3d_caps)("[FAILED] - No rendertarget support\n");
3961                     return WINED3DERR_NOTAVAILABLE;
3962                 }
3963                 usage_caps |= WINED3DUSAGE_RENDERTARGET;
3964             }
3965
3966             if (usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING)
3967             {
3968                 if (!CheckPostPixelShaderBlendingCapability(adapter, format))
3969                 {
3970                     TRACE_(d3d_caps)("[FAILED] - No query post pixelshader blending support\n");
3971                     return WINED3DERR_NOTAVAILABLE;
3972                 }
3973                 usage_caps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
3974             }
3975             break;
3976
3977         case WINED3D_RTYPE_TEXTURE:
3978             /* Texture allows:
3979              *      - WINED3DUSAGE_AUTOGENMIPMAP
3980              *      - WINED3DUSAGE_DEPTHSTENCIL
3981              *      - WINED3DUSAGE_DMAP
3982              *      - WINED3DUSAGE_DYNAMIC
3983              *      - WINED3DUSAGE_NONSECURE (d3d9ex)
3984              *      - WINED3DUSAGE_RENDERTARGET
3985              *      - WINED3DUSAGE_SOFTWAREPROCESSING
3986              *      - WINED3DUSAGE_TEXTAPI (d3d9ex)
3987              *      - WINED3DUSAGE_QUERY_WRAPANDMIP
3988              */
3989             if (surface_type != WINED3D_SURFACE_TYPE_OPENGL)
3990             {
3991                 TRACE_(d3d_caps)("[FAILED]\n");
3992                 return WINED3DERR_NOTAVAILABLE;
3993             }
3994
3995             if (!CheckTextureCapability(adapter, format))
3996             {
3997                 TRACE_(d3d_caps)("[FAILED] - Texture format not supported\n");
3998                 return WINED3DERR_NOTAVAILABLE;
3999             }
4000
4001             if (usage & WINED3DUSAGE_AUTOGENMIPMAP)
4002             {
4003                 if (!gl_info->supported[SGIS_GENERATE_MIPMAP])
4004                     /* When autogenmipmap isn't around continue and return
4005                      * WINED3DOK_NOAUTOGEN instead of D3D_OK. */
4006                     TRACE_(d3d_caps)("[FAILED] - No autogenmipmap support, but continuing\n");
4007                 else
4008                     usage_caps |= WINED3DUSAGE_AUTOGENMIPMAP;
4009             }
4010
4011             /* Always report dynamic locking. */
4012             if (usage & WINED3DUSAGE_DYNAMIC)
4013                 usage_caps |= WINED3DUSAGE_DYNAMIC;
4014
4015             if (usage & WINED3DUSAGE_RENDERTARGET)
4016             {
4017                 if (!CheckRenderTargetCapability(adapter, adapter_format, format))
4018                 {
4019                     TRACE_(d3d_caps)("[FAILED] - No rendertarget support\n");
4020                     return WINED3DERR_NOTAVAILABLE;
4021                 }
4022                 usage_caps |= WINED3DUSAGE_RENDERTARGET;
4023             }
4024
4025             /* Always report software processing. */
4026             if (usage & WINED3DUSAGE_SOFTWAREPROCESSING)
4027                 usage_caps |= WINED3DUSAGE_SOFTWAREPROCESSING;
4028
4029             if (usage & WINED3DUSAGE_QUERY_FILTER)
4030             {
4031                 if (!CheckFilterCapability(adapter, format))
4032                 {
4033                     TRACE_(d3d_caps)("[FAILED] - No query filter support\n");
4034                     return WINED3DERR_NOTAVAILABLE;
4035                 }
4036                 usage_caps |= WINED3DUSAGE_QUERY_FILTER;
4037             }
4038
4039             if (usage & WINED3DUSAGE_QUERY_LEGACYBUMPMAP)
4040             {
4041                 if (!CheckBumpMapCapability(adapter, format))
4042                 {
4043                     TRACE_(d3d_caps)("[FAILED] - No legacy bumpmap support\n");
4044                     return WINED3DERR_NOTAVAILABLE;
4045                 }
4046                 usage_caps |= WINED3DUSAGE_QUERY_LEGACYBUMPMAP;
4047             }
4048
4049             if (usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING)
4050             {
4051                 if (!CheckPostPixelShaderBlendingCapability(adapter, format))
4052                 {
4053                     TRACE_(d3d_caps)("[FAILED] - No query post pixelshader blending support\n");
4054                     return WINED3DERR_NOTAVAILABLE;
4055                 }
4056                 usage_caps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
4057             }
4058
4059             if (usage & WINED3DUSAGE_QUERY_SRGBREAD)
4060             {
4061                 if (!CheckSrgbReadCapability(adapter, format))
4062                 {
4063                     TRACE_(d3d_caps)("[FAILED] - No query srgbread support\n");
4064                     return WINED3DERR_NOTAVAILABLE;
4065                 }
4066                 usage_caps |= WINED3DUSAGE_QUERY_SRGBREAD;
4067             }
4068
4069             if (usage & WINED3DUSAGE_QUERY_SRGBWRITE)
4070             {
4071                 if (!CheckSrgbWriteCapability(adapter, format))
4072                 {
4073                     TRACE_(d3d_caps)("[FAILED] - No query srgbwrite support\n");
4074                     return WINED3DERR_NOTAVAILABLE;
4075                 }
4076                 usage_caps |= WINED3DUSAGE_QUERY_SRGBWRITE;
4077             }
4078
4079             if (usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE)
4080             {
4081                 if (!CheckVertexTextureCapability(adapter, format))
4082                 {
4083                     TRACE_(d3d_caps)("[FAILED] - No query vertextexture support\n");
4084                     return WINED3DERR_NOTAVAILABLE;
4085                 }
4086                 usage_caps |= WINED3DUSAGE_QUERY_VERTEXTEXTURE;
4087             }
4088
4089             if (usage & WINED3DUSAGE_QUERY_WRAPANDMIP)
4090             {
4091                 if (!CheckWrapAndMipCapability(adapter, format))
4092                 {
4093                     TRACE_(d3d_caps)("[FAILED] - No wrapping and mipmapping support\n");
4094                     return WINED3DERR_NOTAVAILABLE;
4095                 }
4096                 usage_caps |= WINED3DUSAGE_QUERY_WRAPANDMIP;
4097             }
4098
4099             if (usage & WINED3DUSAGE_DEPTHSTENCIL)
4100             {
4101                 if (!CheckDepthStencilCapability(adapter, adapter_format, format))
4102                 {
4103                     TRACE_(d3d_caps)("[FAILED] - No depth stencil support\n");
4104                     return WINED3DERR_NOTAVAILABLE;
4105                 }
4106                 if ((format->flags & WINED3DFMT_FLAG_SHADOW) && !gl_info->supported[ARB_SHADOW])
4107                 {
4108                     TRACE_(d3d_caps)("[FAILED] - No shadow sampler support.\n");
4109                     return WINED3DERR_NOTAVAILABLE;
4110                 }
4111                 usage_caps |= WINED3DUSAGE_DEPTHSTENCIL;
4112             }
4113             break;
4114
4115         case WINED3D_RTYPE_VOLUME_TEXTURE:
4116         case WINED3D_RTYPE_VOLUME:
4117             /* Volume is to VolumeTexture what Surface is to Texture, but its
4118              * usage caps are not documented. Most driver seem to offer
4119              * (nearly) the same on Volume and VolumeTexture, so do that too.
4120              *
4121              * Volumetexture allows:
4122              *      - D3DUSAGE_DYNAMIC
4123              *      - D3DUSAGE_NONSECURE (d3d9ex)
4124              *      - D3DUSAGE_SOFTWAREPROCESSING
4125              *      - D3DUSAGE_QUERY_WRAPANDMIP
4126              */
4127             if (surface_type != WINED3D_SURFACE_TYPE_OPENGL)
4128             {
4129                 TRACE_(d3d_caps)("[FAILED]\n");
4130                 return WINED3DERR_NOTAVAILABLE;
4131             }
4132
4133             if (!gl_info->supported[EXT_TEXTURE3D])
4134             {
4135                 TRACE_(d3d_caps)("[FAILED] - No volume texture support\n");
4136                 return WINED3DERR_NOTAVAILABLE;
4137             }
4138
4139             if (!CheckTextureCapability(adapter, format))
4140             {
4141                 TRACE_(d3d_caps)("[FAILED] - Format not supported\n");
4142                 return WINED3DERR_NOTAVAILABLE;
4143             }
4144
4145             /* Filter formats that need conversion; For one part, this
4146              * conversion is unimplemented, and volume textures are huge, so
4147              * it would be a big performance hit. Unless we hit an application
4148              * needing one of those formats, don't advertize them to avoid
4149              * leading applications into temptation. The windows drivers don't
4150              * support most of those formats on volumes anyway, except for
4151              * WINED3DFMT_R32_FLOAT. */
4152             switch (check_format_id)
4153             {
4154                 case WINED3DFMT_P8_UINT:
4155                 case WINED3DFMT_L4A4_UNORM:
4156                 case WINED3DFMT_R32_FLOAT:
4157                 case WINED3DFMT_R16_FLOAT:
4158                 case WINED3DFMT_R8G8_SNORM_L8X8_UNORM:
4159                 case WINED3DFMT_R5G5_SNORM_L6_UNORM:
4160                 case WINED3DFMT_R16G16_UNORM:
4161                     TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
4162                     return WINED3DERR_NOTAVAILABLE;
4163
4164                 case WINED3DFMT_R8G8B8A8_SNORM:
4165                 case WINED3DFMT_R16G16_SNORM:
4166                     if (!gl_info->supported[NV_TEXTURE_SHADER])
4167                     {
4168                         TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
4169                         return WINED3DERR_NOTAVAILABLE;
4170                     }
4171                     break;
4172
4173                 case WINED3DFMT_R8G8_SNORM:
4174                     if (!gl_info->supported[NV_TEXTURE_SHADER])
4175                     {
4176                         TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
4177                         return WINED3DERR_NOTAVAILABLE;
4178                     }
4179                     break;
4180
4181                 case WINED3DFMT_DXT1:
4182                 case WINED3DFMT_DXT2:
4183                 case WINED3DFMT_DXT3:
4184                 case WINED3DFMT_DXT4:
4185                 case WINED3DFMT_DXT5:
4186                     /* The GL_EXT_texture_compression_s3tc spec requires that
4187                      * loading an s3tc compressed texture results in an error.
4188                      * While the D3D refrast does support s3tc volumes, at
4189                      * least the nvidia windows driver does not, so we're free
4190                      * not to support this format. */
4191                     TRACE_(d3d_caps)("[FAILED] - DXTn does not support 3D textures\n");
4192                     return WINED3DERR_NOTAVAILABLE;
4193
4194                 default:
4195                     /* Do nothing, continue with checking the format below */
4196                     break;
4197             }
4198
4199             /* Always report dynamic locking. */
4200             if (usage & WINED3DUSAGE_DYNAMIC)
4201                 usage_caps |= WINED3DUSAGE_DYNAMIC;
4202
4203             /* Always report software processing. */
4204             if (usage & WINED3DUSAGE_SOFTWAREPROCESSING)
4205                 usage_caps |= WINED3DUSAGE_SOFTWAREPROCESSING;
4206
4207             if (usage & WINED3DUSAGE_QUERY_FILTER)
4208             {
4209                 if (!CheckFilterCapability(adapter, format))
4210                 {
4211                     TRACE_(d3d_caps)("[FAILED] - No query filter support\n");
4212                     return WINED3DERR_NOTAVAILABLE;
4213                 }
4214                 usage_caps |= WINED3DUSAGE_QUERY_FILTER;
4215             }
4216
4217             if (usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING)
4218             {
4219                 if (!CheckPostPixelShaderBlendingCapability(adapter, format))
4220                 {
4221                     TRACE_(d3d_caps)("[FAILED] - No query post pixelshader blending support\n");
4222                     return WINED3DERR_NOTAVAILABLE;
4223                 }
4224                 usage_caps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
4225             }
4226
4227             if (usage & WINED3DUSAGE_QUERY_SRGBREAD)
4228             {
4229                 if (!CheckSrgbReadCapability(adapter, format))
4230                 {
4231                     TRACE_(d3d_caps)("[FAILED] - No query srgbread support\n");
4232                     return WINED3DERR_NOTAVAILABLE;
4233                 }
4234                 usage_caps |= WINED3DUSAGE_QUERY_SRGBREAD;
4235             }
4236
4237             if (usage & WINED3DUSAGE_QUERY_SRGBWRITE)
4238             {
4239                 if (!CheckSrgbWriteCapability(adapter, format))
4240                 {
4241                     TRACE_(d3d_caps)("[FAILED] - No query srgbwrite support\n");
4242                     return WINED3DERR_NOTAVAILABLE;
4243                 }
4244                 usage_caps |= WINED3DUSAGE_QUERY_SRGBWRITE;
4245             }
4246
4247             if (usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE)
4248             {
4249                 if (!CheckVertexTextureCapability(adapter, format))
4250                 {
4251                     TRACE_(d3d_caps)("[FAILED] - No query vertextexture support\n");
4252                     return WINED3DERR_NOTAVAILABLE;
4253                 }
4254                 usage_caps |= WINED3DUSAGE_QUERY_VERTEXTEXTURE;
4255             }
4256
4257             if (usage & WINED3DUSAGE_QUERY_WRAPANDMIP)
4258             {
4259                 if (!CheckWrapAndMipCapability(adapter, format))
4260                 {
4261                     TRACE_(d3d_caps)("[FAILED] - No wrapping and mipmapping support\n");
4262                     return WINED3DERR_NOTAVAILABLE;
4263                 }
4264                 usage_caps |= WINED3DUSAGE_QUERY_WRAPANDMIP;
4265             }
4266             break;
4267
4268         default:
4269             FIXME_(d3d_caps)("Unhandled resource type %s.\n", debug_d3dresourcetype(resource_type));
4270             return WINED3DERR_NOTAVAILABLE;
4271     }
4272
4273     /* When the usage_caps exactly matches usage return WINED3D_OK except for
4274      * the situation in which WINED3DUSAGE_AUTOGENMIPMAP isn't around, then
4275      * WINED3DOK_NOAUTOGEN is returned if all the other usage flags match. */
4276     if (usage_caps == usage)
4277         return WINED3D_OK;
4278     if (usage_caps == (usage & ~WINED3DUSAGE_AUTOGENMIPMAP))
4279         return WINED3DOK_NOAUTOGEN;
4280
4281     TRACE_(d3d_caps)("[FAILED] - Usage %#x requested for format %s and resource_type %s but only %#x is available.\n",
4282             usage, debug_d3dformat(check_format_id), debug_d3dresourcetype(resource_type), usage_caps);
4283
4284     return WINED3DERR_NOTAVAILABLE;
4285 }
4286
4287 HRESULT CDECL wined3d_check_device_format_conversion(const struct wined3d *wined3d, UINT adapter_idx,
4288         enum wined3d_device_type device_type, enum wined3d_format_id src_format, enum wined3d_format_id dst_format)
4289 {
4290     FIXME("wined3d %p, adapter_idx %u, device_type %s, src_format %s, dst_format %s stub!\n",
4291             wined3d, adapter_idx, debug_d3ddevicetype(device_type), debug_d3dformat(src_format),
4292             debug_d3dformat(dst_format));
4293
4294     return WINED3D_OK;
4295 }
4296
4297 HRESULT CDECL wined3d_check_device_type(const struct wined3d *wined3d, UINT adapter_idx,
4298         enum wined3d_device_type device_type, enum wined3d_format_id display_format,
4299         enum wined3d_format_id backbuffer_format, BOOL windowed)
4300 {
4301     UINT mode_count;
4302     HRESULT hr;
4303
4304     TRACE("wined3d %p, adapter_idx %u, device_type %s, display_format %s, backbuffer_format %s, windowed %#x.\n",
4305             wined3d, adapter_idx, debug_d3ddevicetype(device_type), debug_d3dformat(display_format),
4306             debug_d3dformat(backbuffer_format), windowed);
4307
4308     if (adapter_idx >= wined3d->adapter_count)
4309         return WINED3DERR_INVALIDCALL;
4310
4311     /* The task of this function is to check whether a certain display / backbuffer format
4312      * combination is available on the given adapter. In fullscreen mode microsoft specified
4313      * that the display format shouldn't provide alpha and that ignoring alpha the backbuffer
4314      * and display format should match exactly.
4315      * In windowed mode format conversion can occur and this depends on the driver. When format
4316      * conversion is done, this function should nevertheless fail and applications need to use
4317      * CheckDeviceFormatConversion.
4318      * At the moment we assume that fullscreen and windowed have the same capabilities. */
4319
4320     /* There are only 4 display formats. */
4321     if (!(display_format == WINED3DFMT_B5G6R5_UNORM
4322             || display_format == WINED3DFMT_B5G5R5X1_UNORM
4323             || display_format == WINED3DFMT_B8G8R8X8_UNORM
4324             || display_format == WINED3DFMT_B10G10R10A2_UNORM))
4325     {
4326         TRACE_(d3d_caps)("Format %s is not supported as display format.\n", debug_d3dformat(display_format));
4327         return WINED3DERR_NOTAVAILABLE;
4328     }
4329
4330     /* If the requested display format is not available, don't continue. */
4331     mode_count = wined3d_get_adapter_mode_count(wined3d, adapter_idx, display_format);
4332     if (!mode_count)
4333     {
4334         TRACE_(d3d_caps)("No available modes for display format %s.\n", debug_d3dformat(display_format));
4335         return WINED3DERR_NOTAVAILABLE;
4336     }
4337
4338     /* Windowed mode allows you to specify WINED3DFMT_UNKNOWN for the backbuffer format,
4339      * it means 'reuse' the display format for the backbuffer. */
4340     if (!windowed && backbuffer_format == WINED3DFMT_UNKNOWN)
4341     {
4342         TRACE_(d3d_caps)("backbuffer_format WINED3FMT_UNKNOWN only available in windowed mode.\n");
4343         return WINED3DERR_NOTAVAILABLE;
4344     }
4345
4346     /* In FULLSCREEN mode WINED3DFMT_B5G6R5_UNORM can only be mixed with
4347      * backbuffer format WINED3DFMT_B5G6R5_UNORM. */
4348     if (display_format == WINED3DFMT_B5G6R5_UNORM && backbuffer_format != WINED3DFMT_B5G6R5_UNORM)
4349     {
4350         TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s / %s.\n",
4351                 debug_d3dformat(display_format), debug_d3dformat(backbuffer_format));
4352         return WINED3DERR_NOTAVAILABLE;
4353     }
4354
4355     /* In FULLSCREEN mode WINED3DFMT_B5G5R5X1_UNORM can only be mixed with
4356      * backbuffer formats WINED3DFMT_B5G5R5X1_UNORM and
4357      * WINED3DFMT_B5G5R5A1_UNORM. */
4358     if (display_format == WINED3DFMT_B5G5R5X1_UNORM
4359             && !(backbuffer_format == WINED3DFMT_B5G5R5X1_UNORM || backbuffer_format == WINED3DFMT_B5G5R5A1_UNORM))
4360     {
4361         TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s / %s.\n",
4362                 debug_d3dformat(display_format), debug_d3dformat(backbuffer_format));
4363         return WINED3DERR_NOTAVAILABLE;
4364     }
4365
4366     /* In FULLSCREEN mode WINED3DFMT_B8G8R8X8_UNORM can only be mixed with
4367      * backbuffer formats WINED3DFMT_B8G8R8X8_UNORM and
4368      * WINED3DFMT_B8G8R8A8_UNORM. */
4369     if (display_format == WINED3DFMT_B8G8R8X8_UNORM
4370             && !(backbuffer_format == WINED3DFMT_B8G8R8X8_UNORM || backbuffer_format == WINED3DFMT_B8G8R8A8_UNORM))
4371     {
4372         TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s / %s.\n",
4373                 debug_d3dformat(display_format), debug_d3dformat(backbuffer_format));
4374         return WINED3DERR_NOTAVAILABLE;
4375     }
4376
4377     /* WINED3DFMT_B10G10R10A2_UNORM is only allowed in fullscreen mode and it
4378      * can only be mixed with backbuffer format WINED3DFMT_B10G10R10A2_UNORM. */
4379     if (display_format == WINED3DFMT_B10G10R10A2_UNORM
4380             && (backbuffer_format != WINED3DFMT_B10G10R10A2_UNORM || windowed))
4381     {
4382         TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s / %s.\n",
4383                 debug_d3dformat(display_format), debug_d3dformat(backbuffer_format));
4384         return WINED3DERR_NOTAVAILABLE;
4385     }
4386
4387     /* Use CheckDeviceFormat to see if the backbuffer_format is usable with the given display_format */
4388     hr = wined3d_check_device_format(wined3d, adapter_idx, device_type, display_format,
4389             WINED3DUSAGE_RENDERTARGET, WINED3D_RTYPE_SURFACE, backbuffer_format, WINED3D_SURFACE_TYPE_OPENGL);
4390     if (FAILED(hr))
4391         TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s / %s.\n",
4392                 debug_d3dformat(display_format), debug_d3dformat(backbuffer_format));
4393
4394     return hr;
4395 }
4396
4397 HRESULT CDECL wined3d_get_device_caps(const struct wined3d *wined3d, UINT adapter_idx,
4398         enum wined3d_device_type device_type, WINED3DCAPS *caps)
4399 {
4400     const struct wined3d_adapter *adapter = &wined3d->adapters[adapter_idx];
4401     const struct wined3d_gl_info *gl_info = &adapter->gl_info;
4402     int vs_selected_mode;
4403     int ps_selected_mode;
4404     struct shader_caps shader_caps;
4405     struct fragment_caps fragment_caps;
4406     DWORD ckey_caps, blit_caps, fx_caps, pal_caps;
4407
4408     TRACE_(d3d_caps)("wined3d %p, adapter_idx %u, device_type %s, caps %p.\n",
4409             wined3d, adapter_idx, debug_d3ddevicetype(device_type), caps);
4410
4411     if (adapter_idx >= wined3d->adapter_count)
4412         return WINED3DERR_INVALIDCALL;
4413
4414     select_shader_mode(&adapter->gl_info, &ps_selected_mode, &vs_selected_mode);
4415
4416     /* ------------------------------------------------
4417        The following fields apply to both d3d8 and d3d9
4418        ------------------------------------------------ */
4419     /* Not quite true, but use h/w supported by opengl I suppose */
4420     caps->DeviceType = (device_type == WINED3D_DEVICE_TYPE_HAL) ? WINED3D_DEVICE_TYPE_HAL : WINED3D_DEVICE_TYPE_REF;
4421     caps->AdapterOrdinal           = adapter_idx;
4422
4423     caps->Caps                     = 0;
4424     caps->Caps2                    = WINED3DCAPS2_CANRENDERWINDOWED |
4425                                      WINED3DCAPS2_FULLSCREENGAMMA |
4426                                      WINED3DCAPS2_DYNAMICTEXTURES;
4427     if (gl_info->supported[SGIS_GENERATE_MIPMAP])
4428         caps->Caps2 |= WINED3DCAPS2_CANAUTOGENMIPMAP;
4429
4430     caps->Caps3                    = WINED3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD |
4431                                      WINED3DCAPS3_COPY_TO_VIDMEM                   |
4432                                      WINED3DCAPS3_COPY_TO_SYSTEMMEM;
4433
4434     caps->PresentationIntervals    = WINED3DPRESENT_INTERVAL_IMMEDIATE  |
4435                                      WINED3DPRESENT_INTERVAL_ONE;
4436
4437     caps->CursorCaps               = WINED3DCURSORCAPS_COLOR            |
4438                                      WINED3DCURSORCAPS_LOWRES;
4439
4440     caps->DevCaps                  = WINED3DDEVCAPS_FLOATTLVERTEX       |
4441                                      WINED3DDEVCAPS_EXECUTESYSTEMMEMORY |
4442                                      WINED3DDEVCAPS_TLVERTEXSYSTEMMEMORY|
4443                                      WINED3DDEVCAPS_TLVERTEXVIDEOMEMORY |
4444                                      WINED3DDEVCAPS_DRAWPRIMTLVERTEX    |
4445                                      WINED3DDEVCAPS_HWTRANSFORMANDLIGHT |
4446                                      WINED3DDEVCAPS_EXECUTEVIDEOMEMORY  |
4447                                      WINED3DDEVCAPS_PUREDEVICE          |
4448                                      WINED3DDEVCAPS_HWRASTERIZATION     |
4449                                      WINED3DDEVCAPS_TEXTUREVIDEOMEMORY  |
4450                                      WINED3DDEVCAPS_TEXTURESYSTEMMEMORY |
4451                                      WINED3DDEVCAPS_CANRENDERAFTERFLIP  |
4452                                      WINED3DDEVCAPS_DRAWPRIMITIVES2     |
4453                                      WINED3DDEVCAPS_DRAWPRIMITIVES2EX   |
4454                                      WINED3DDEVCAPS_RTPATCHES;
4455
4456     caps->PrimitiveMiscCaps        = WINED3DPMISCCAPS_CULLNONE              |
4457                                      WINED3DPMISCCAPS_CULLCCW               |
4458                                      WINED3DPMISCCAPS_CULLCW                |
4459                                      WINED3DPMISCCAPS_COLORWRITEENABLE      |
4460                                      WINED3DPMISCCAPS_CLIPTLVERTS           |
4461                                      WINED3DPMISCCAPS_CLIPPLANESCALEDPOINTS |
4462                                      WINED3DPMISCCAPS_MASKZ                 |
4463                                      WINED3DPMISCCAPS_BLENDOP               |
4464                                      WINED3DPMISCCAPS_MRTPOSTPIXELSHADERBLENDING;
4465                                     /* TODO:
4466                                         WINED3DPMISCCAPS_NULLREFERENCE
4467                                         WINED3DPMISCCAPS_FOGANDSPECULARALPHA
4468                                         WINED3DPMISCCAPS_MRTINDEPENDENTBITDEPTHS
4469                                         WINED3DPMISCCAPS_FOGVERTEXCLAMPED */
4470
4471     if (gl_info->supported[EXT_BLEND_EQUATION_SEPARATE] && gl_info->supported[EXT_BLEND_FUNC_SEPARATE])
4472         caps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_SEPARATEALPHABLEND;
4473     if (gl_info->supported[EXT_DRAW_BUFFERS2])
4474         caps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_INDEPENDENTWRITEMASKS;
4475
4476     caps->RasterCaps               = WINED3DPRASTERCAPS_DITHER    |
4477                                      WINED3DPRASTERCAPS_PAT       |
4478                                      WINED3DPRASTERCAPS_WFOG      |
4479                                      WINED3DPRASTERCAPS_ZFOG      |
4480                                      WINED3DPRASTERCAPS_FOGVERTEX |
4481                                      WINED3DPRASTERCAPS_FOGTABLE  |
4482                                      WINED3DPRASTERCAPS_STIPPLE   |
4483                                      WINED3DPRASTERCAPS_SUBPIXEL  |
4484                                      WINED3DPRASTERCAPS_ZTEST     |
4485                                      WINED3DPRASTERCAPS_SCISSORTEST   |
4486                                      WINED3DPRASTERCAPS_SLOPESCALEDEPTHBIAS |
4487                                      WINED3DPRASTERCAPS_DEPTHBIAS;
4488
4489     if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
4490     {
4491         caps->RasterCaps  |= WINED3DPRASTERCAPS_ANISOTROPY    |
4492                              WINED3DPRASTERCAPS_ZBIAS         |
4493                              WINED3DPRASTERCAPS_MIPMAPLODBIAS;
4494     }
4495     if (gl_info->supported[NV_FOG_DISTANCE])
4496     {
4497         caps->RasterCaps          |= WINED3DPRASTERCAPS_FOGRANGE;
4498     }
4499                         /* FIXME Add:
4500                            WINED3DPRASTERCAPS_COLORPERSPECTIVE
4501                            WINED3DPRASTERCAPS_STRETCHBLTMULTISAMPLE
4502                            WINED3DPRASTERCAPS_ANTIALIASEDGES
4503                            WINED3DPRASTERCAPS_ZBUFFERLESSHSR
4504                            WINED3DPRASTERCAPS_WBUFFER */
4505
4506     caps->ZCmpCaps =  WINED3DPCMPCAPS_ALWAYS       |
4507                       WINED3DPCMPCAPS_EQUAL        |
4508                       WINED3DPCMPCAPS_GREATER      |
4509                       WINED3DPCMPCAPS_GREATEREQUAL |
4510                       WINED3DPCMPCAPS_LESS         |
4511                       WINED3DPCMPCAPS_LESSEQUAL    |
4512                       WINED3DPCMPCAPS_NEVER        |
4513                       WINED3DPCMPCAPS_NOTEQUAL;
4514
4515     caps->SrcBlendCaps  =  WINED3DPBLENDCAPS_BOTHINVSRCALPHA |
4516                            WINED3DPBLENDCAPS_BOTHSRCALPHA    |
4517                            WINED3DPBLENDCAPS_DESTALPHA       |
4518                            WINED3DPBLENDCAPS_DESTCOLOR       |
4519                            WINED3DPBLENDCAPS_INVDESTALPHA    |
4520                            WINED3DPBLENDCAPS_INVDESTCOLOR    |
4521                            WINED3DPBLENDCAPS_INVSRCALPHA     |
4522                            WINED3DPBLENDCAPS_INVSRCCOLOR     |
4523                            WINED3DPBLENDCAPS_ONE             |
4524                            WINED3DPBLENDCAPS_SRCALPHA        |
4525                            WINED3DPBLENDCAPS_SRCALPHASAT     |
4526                            WINED3DPBLENDCAPS_SRCCOLOR        |
4527                            WINED3DPBLENDCAPS_ZERO;
4528
4529     caps->DestBlendCaps =  WINED3DPBLENDCAPS_DESTALPHA       |
4530                            WINED3DPBLENDCAPS_DESTCOLOR       |
4531                            WINED3DPBLENDCAPS_INVDESTALPHA    |
4532                            WINED3DPBLENDCAPS_INVDESTCOLOR    |
4533                            WINED3DPBLENDCAPS_INVSRCALPHA     |
4534                            WINED3DPBLENDCAPS_INVSRCCOLOR     |
4535                            WINED3DPBLENDCAPS_ONE             |
4536                            WINED3DPBLENDCAPS_SRCALPHA        |
4537                            WINED3DPBLENDCAPS_SRCCOLOR        |
4538                            WINED3DPBLENDCAPS_ZERO;
4539     /* NOTE: WINED3DPBLENDCAPS_SRCALPHASAT is not supported as dest blend factor,
4540      * according to the glBlendFunc manpage
4541      *
4542      * WINED3DPBLENDCAPS_BOTHINVSRCALPHA and WINED3DPBLENDCAPS_BOTHSRCALPHA are
4543      * legacy settings for srcblend only
4544      */
4545
4546     if (gl_info->supported[EXT_BLEND_COLOR])
4547     {
4548         caps->SrcBlendCaps |= WINED3DPBLENDCAPS_BLENDFACTOR;
4549         caps->DestBlendCaps |= WINED3DPBLENDCAPS_BLENDFACTOR;
4550     }
4551
4552
4553     caps->AlphaCmpCaps  = WINED3DPCMPCAPS_ALWAYS       |
4554                           WINED3DPCMPCAPS_EQUAL        |
4555                           WINED3DPCMPCAPS_GREATER      |
4556                           WINED3DPCMPCAPS_GREATEREQUAL |
4557                           WINED3DPCMPCAPS_LESS         |
4558                           WINED3DPCMPCAPS_LESSEQUAL    |
4559                           WINED3DPCMPCAPS_NEVER        |
4560                           WINED3DPCMPCAPS_NOTEQUAL;
4561
4562     caps->ShadeCaps      = WINED3DPSHADECAPS_SPECULARGOURAUDRGB |
4563                            WINED3DPSHADECAPS_COLORGOURAUDRGB    |
4564                            WINED3DPSHADECAPS_ALPHAFLATBLEND     |
4565                            WINED3DPSHADECAPS_ALPHAGOURAUDBLEND  |
4566                            WINED3DPSHADECAPS_COLORFLATRGB       |
4567                            WINED3DPSHADECAPS_FOGFLAT            |
4568                            WINED3DPSHADECAPS_FOGGOURAUD         |
4569                            WINED3DPSHADECAPS_SPECULARFLATRGB;
4570
4571     caps->TextureCaps   = WINED3DPTEXTURECAPS_ALPHA              |
4572                           WINED3DPTEXTURECAPS_ALPHAPALETTE       |
4573                           WINED3DPTEXTURECAPS_TRANSPARENCY       |
4574                           WINED3DPTEXTURECAPS_BORDER             |
4575                           WINED3DPTEXTURECAPS_MIPMAP             |
4576                           WINED3DPTEXTURECAPS_PROJECTED          |
4577                           WINED3DPTEXTURECAPS_PERSPECTIVE;
4578
4579     if (!gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
4580     {
4581         caps->TextureCaps  |= WINED3DPTEXTURECAPS_POW2 |
4582                               WINED3DPTEXTURECAPS_NONPOW2CONDITIONAL;
4583     }
4584
4585     if (gl_info->supported[EXT_TEXTURE3D])
4586     {
4587         caps->TextureCaps  |=  WINED3DPTEXTURECAPS_VOLUMEMAP      |
4588                                WINED3DPTEXTURECAPS_MIPVOLUMEMAP;
4589         if (!gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
4590         {
4591             caps->TextureCaps |= WINED3DPTEXTURECAPS_VOLUMEMAP_POW2;
4592         }
4593     }
4594
4595     if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
4596     {
4597         caps->TextureCaps  |= WINED3DPTEXTURECAPS_CUBEMAP     |
4598                               WINED3DPTEXTURECAPS_MIPCUBEMAP;
4599         if (!gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
4600         {
4601             caps->TextureCaps |= WINED3DPTEXTURECAPS_CUBEMAP_POW2;
4602         }
4603     }
4604
4605     caps->TextureFilterCaps =  WINED3DPTFILTERCAPS_MAGFLINEAR       |
4606                                WINED3DPTFILTERCAPS_MAGFPOINT        |
4607                                WINED3DPTFILTERCAPS_MINFLINEAR       |
4608                                WINED3DPTFILTERCAPS_MINFPOINT        |
4609                                WINED3DPTFILTERCAPS_MIPFLINEAR       |
4610                                WINED3DPTFILTERCAPS_MIPFPOINT        |
4611                                WINED3DPTFILTERCAPS_LINEAR           |
4612                                WINED3DPTFILTERCAPS_LINEARMIPLINEAR  |
4613                                WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
4614                                WINED3DPTFILTERCAPS_MIPLINEAR        |
4615                                WINED3DPTFILTERCAPS_MIPNEAREST       |
4616                                WINED3DPTFILTERCAPS_NEAREST;
4617
4618     if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
4619     {
4620         caps->TextureFilterCaps  |= WINED3DPTFILTERCAPS_MAGFANISOTROPIC |
4621                                     WINED3DPTFILTERCAPS_MINFANISOTROPIC;
4622     }
4623
4624     if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
4625     {
4626         caps->CubeTextureFilterCaps =  WINED3DPTFILTERCAPS_MAGFLINEAR       |
4627                                        WINED3DPTFILTERCAPS_MAGFPOINT        |
4628                                        WINED3DPTFILTERCAPS_MINFLINEAR       |
4629                                        WINED3DPTFILTERCAPS_MINFPOINT        |
4630                                        WINED3DPTFILTERCAPS_MIPFLINEAR       |
4631                                        WINED3DPTFILTERCAPS_MIPFPOINT        |
4632                                        WINED3DPTFILTERCAPS_LINEAR           |
4633                                        WINED3DPTFILTERCAPS_LINEARMIPLINEAR  |
4634                                        WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
4635                                        WINED3DPTFILTERCAPS_MIPLINEAR        |
4636                                        WINED3DPTFILTERCAPS_MIPNEAREST       |
4637                                        WINED3DPTFILTERCAPS_NEAREST;
4638
4639         if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
4640         {
4641             caps->CubeTextureFilterCaps  |= WINED3DPTFILTERCAPS_MAGFANISOTROPIC |
4642                                             WINED3DPTFILTERCAPS_MINFANISOTROPIC;
4643         }
4644     }
4645     else
4646     {
4647         caps->CubeTextureFilterCaps = 0;
4648     }
4649
4650     if (gl_info->supported[EXT_TEXTURE3D])
4651     {
4652         caps->VolumeTextureFilterCaps  = WINED3DPTFILTERCAPS_MAGFLINEAR       |
4653                                          WINED3DPTFILTERCAPS_MAGFPOINT        |
4654                                          WINED3DPTFILTERCAPS_MINFLINEAR       |
4655                                          WINED3DPTFILTERCAPS_MINFPOINT        |
4656                                          WINED3DPTFILTERCAPS_MIPFLINEAR       |
4657                                          WINED3DPTFILTERCAPS_MIPFPOINT        |
4658                                          WINED3DPTFILTERCAPS_LINEAR           |
4659                                          WINED3DPTFILTERCAPS_LINEARMIPLINEAR  |
4660                                          WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
4661                                          WINED3DPTFILTERCAPS_MIPLINEAR        |
4662                                          WINED3DPTFILTERCAPS_MIPNEAREST       |
4663                                          WINED3DPTFILTERCAPS_NEAREST;
4664     }
4665     else
4666     {
4667         caps->VolumeTextureFilterCaps = 0;
4668     }
4669
4670     caps->TextureAddressCaps  =  WINED3DPTADDRESSCAPS_INDEPENDENTUV |
4671                                  WINED3DPTADDRESSCAPS_CLAMP  |
4672                                  WINED3DPTADDRESSCAPS_WRAP;
4673
4674     if (gl_info->supported[ARB_TEXTURE_BORDER_CLAMP])
4675     {
4676         caps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_BORDER;
4677     }
4678     if (gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT])
4679     {
4680         caps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRROR;
4681     }
4682     if (gl_info->supported[ATI_TEXTURE_MIRROR_ONCE])
4683     {
4684         caps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRRORONCE;
4685     }
4686
4687     if (gl_info->supported[EXT_TEXTURE3D])
4688     {
4689         caps->VolumeTextureAddressCaps =   WINED3DPTADDRESSCAPS_INDEPENDENTUV |
4690                                            WINED3DPTADDRESSCAPS_CLAMP  |
4691                                            WINED3DPTADDRESSCAPS_WRAP;
4692         if (gl_info->supported[ARB_TEXTURE_BORDER_CLAMP])
4693         {
4694             caps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_BORDER;
4695         }
4696         if (gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT])
4697         {
4698             caps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRROR;
4699         }
4700         if (gl_info->supported[ATI_TEXTURE_MIRROR_ONCE])
4701         {
4702             caps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRRORONCE;
4703         }
4704     }
4705     else
4706     {
4707         caps->VolumeTextureAddressCaps = 0;
4708     }
4709
4710     caps->LineCaps  = WINED3DLINECAPS_TEXTURE       |
4711                       WINED3DLINECAPS_ZTEST         |
4712                       WINED3DLINECAPS_BLEND         |
4713                       WINED3DLINECAPS_ALPHACMP      |
4714                       WINED3DLINECAPS_FOG;
4715     /* WINED3DLINECAPS_ANTIALIAS is not supported on Windows, and dx and gl seem to have a different
4716      * idea how generating the smoothing alpha values works; the result is different
4717      */
4718
4719     caps->MaxTextureWidth = gl_info->limits.texture_size;
4720     caps->MaxTextureHeight = gl_info->limits.texture_size;
4721
4722     if (gl_info->supported[EXT_TEXTURE3D])
4723         caps->MaxVolumeExtent = gl_info->limits.texture3d_size;
4724     else
4725         caps->MaxVolumeExtent = 0;
4726
4727     caps->MaxTextureRepeat = 32768;
4728     caps->MaxTextureAspectRatio = gl_info->limits.texture_size;
4729     caps->MaxVertexW = 1.0f;
4730
4731     caps->GuardBandLeft = 0.0f;
4732     caps->GuardBandTop = 0.0f;
4733     caps->GuardBandRight = 0.0f;
4734     caps->GuardBandBottom = 0.0f;
4735
4736     caps->ExtentsAdjust = 0.0f;
4737
4738     caps->StencilCaps   = WINED3DSTENCILCAPS_DECRSAT |
4739                           WINED3DSTENCILCAPS_INCRSAT |
4740                           WINED3DSTENCILCAPS_INVERT  |
4741                           WINED3DSTENCILCAPS_KEEP    |
4742                           WINED3DSTENCILCAPS_REPLACE |
4743                           WINED3DSTENCILCAPS_ZERO;
4744     if (gl_info->supported[EXT_STENCIL_WRAP])
4745     {
4746         caps->StencilCaps |= WINED3DSTENCILCAPS_DECR  |
4747                               WINED3DSTENCILCAPS_INCR;
4748     }
4749     if (gl_info->supported[EXT_STENCIL_TWO_SIDE] || gl_info->supported[ATI_SEPARATE_STENCIL])
4750     {
4751         caps->StencilCaps |= WINED3DSTENCILCAPS_TWOSIDED;
4752     }
4753
4754     caps->FVFCaps = WINED3DFVFCAPS_PSIZE | 0x0008; /* 8 texture coords */
4755
4756     caps->MaxUserClipPlanes = gl_info->limits.clipplanes;
4757     caps->MaxActiveLights = gl_info->limits.lights;
4758
4759     caps->MaxVertexBlendMatrices = gl_info->limits.blends;
4760     caps->MaxVertexBlendMatrixIndex   = 0;
4761
4762     caps->MaxAnisotropy = gl_info->limits.anisotropy;
4763     caps->MaxPointSize = gl_info->limits.pointsize_max;
4764
4765
4766     /* FIXME: Add D3DVTXPCAPS_TWEENING, D3DVTXPCAPS_TEXGEN_SPHEREMAP */
4767     caps->VertexProcessingCaps  = WINED3DVTXPCAPS_DIRECTIONALLIGHTS |
4768                                   WINED3DVTXPCAPS_MATERIALSOURCE7   |
4769                                   WINED3DVTXPCAPS_POSITIONALLIGHTS  |
4770                                   WINED3DVTXPCAPS_LOCALVIEWER       |
4771                                   WINED3DVTXPCAPS_VERTEXFOG         |
4772                                   WINED3DVTXPCAPS_TEXGEN;
4773
4774     caps->MaxPrimitiveCount   = 0xFFFFF; /* For now set 2^20-1 which is used by most >=Geforce3/Radeon8500 cards */
4775     caps->MaxVertexIndex      = 0xFFFFF;
4776     caps->MaxStreams          = MAX_STREAMS;
4777     caps->MaxStreamStride     = 1024;
4778
4779     /* d3d9.dll sets D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES here because StretchRects is implemented in d3d9 */
4780     caps->DevCaps2                          = WINED3DDEVCAPS2_STREAMOFFSET |
4781                                               WINED3DDEVCAPS2_VERTEXELEMENTSCANSHARESTREAMOFFSET;
4782     caps->MaxNpatchTessellationLevel        = 0;
4783     caps->MasterAdapterOrdinal              = 0;
4784     caps->AdapterOrdinalInGroup             = 0;
4785     caps->NumberOfAdaptersInGroup           = 1;
4786
4787     caps->NumSimultaneousRTs = gl_info->limits.buffers;
4788
4789     caps->StretchRectFilterCaps               = WINED3DPTFILTERCAPS_MINFPOINT  |
4790                                                 WINED3DPTFILTERCAPS_MAGFPOINT  |
4791                                                 WINED3DPTFILTERCAPS_MINFLINEAR |
4792                                                 WINED3DPTFILTERCAPS_MAGFLINEAR;
4793     caps->VertexTextureFilterCaps             = 0;
4794
4795     adapter->shader_backend->shader_get_caps(&adapter->gl_info, &shader_caps);
4796     adapter->fragment_pipe->get_caps(&adapter->gl_info, &fragment_caps);
4797
4798     /* Add shader misc caps. Only some of them belong to the shader parts of the pipeline */
4799     caps->PrimitiveMiscCaps |= fragment_caps.PrimitiveMiscCaps;
4800
4801     /* This takes care for disabling vertex shader or pixel shader caps while leaving the other one enabled.
4802      * Ignore shader model capabilities if disabled in config
4803      */
4804     if (vs_selected_mode == SHADER_NONE)
4805     {
4806         TRACE_(d3d_caps)("Vertex shader disabled in config, reporting version 0.0\n");
4807         caps->VertexShaderVersion          = 0;
4808         caps->MaxVertexShaderConst         = 0;
4809     }
4810     else
4811     {
4812         caps->VertexShaderVersion          = shader_caps.VertexShaderVersion;
4813         caps->MaxVertexShaderConst         = shader_caps.MaxVertexShaderConst;
4814     }
4815
4816     if (ps_selected_mode == SHADER_NONE)
4817     {
4818         TRACE_(d3d_caps)("Pixel shader disabled in config, reporting version 0.0\n");
4819         caps->PixelShaderVersion           = 0;
4820         caps->PixelShader1xMaxValue        = 0.0f;
4821     } else {
4822         caps->PixelShaderVersion           = shader_caps.PixelShaderVersion;
4823         caps->PixelShader1xMaxValue        = shader_caps.PixelShader1xMaxValue;
4824     }
4825
4826     caps->TextureOpCaps                    = fragment_caps.TextureOpCaps;
4827     caps->MaxTextureBlendStages            = fragment_caps.MaxTextureBlendStages;
4828     caps->MaxSimultaneousTextures          = fragment_caps.MaxSimultaneousTextures;
4829
4830     /* The following caps are shader specific, but they are things we cannot detect, or which
4831      * are the same among all shader models. So to avoid code duplication set the shader version
4832      * specific, but otherwise constant caps here
4833      */
4834     if (caps->VertexShaderVersion >= 3)
4835     {
4836         /* Where possible set the caps based on OpenGL extensions and if they
4837          * aren't set (in case of software rendering) use the VS 3.0 from
4838          * MSDN or else if there's OpenGL spec use a hardcoded value minimum
4839          * VS3.0 value. */
4840         caps->VS20Caps.caps = WINED3DVS20CAPS_PREDICATION;
4841         /* VS 3.0 requires MAX_DYNAMICFLOWCONTROLDEPTH (24) */
4842         caps->VS20Caps.dynamic_flow_control_depth = WINED3DVS20_MAX_DYNAMICFLOWCONTROLDEPTH;
4843         caps->VS20Caps.temp_count = max(32, adapter->gl_info.limits.arb_vs_temps);
4844         /* level of nesting in loops / if-statements; VS 3.0 requires MAX (4) */
4845         caps->VS20Caps.static_flow_control_depth = WINED3DVS20_MAX_STATICFLOWCONTROLDEPTH;
4846
4847         caps->MaxVShaderInstructionsExecuted    = 65535; /* VS 3.0 needs at least 65535, some cards even use 2^32-1 */
4848         caps->MaxVertexShader30InstructionSlots = max(512, adapter->gl_info.limits.arb_vs_instructions);
4849     }
4850     else if (caps->VertexShaderVersion == 2)
4851     {
4852         caps->VS20Caps.caps = 0;
4853         caps->VS20Caps.dynamic_flow_control_depth = WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH;
4854         caps->VS20Caps.temp_count = max(12, adapter->gl_info.limits.arb_vs_temps);
4855         caps->VS20Caps.static_flow_control_depth = 1;
4856
4857         caps->MaxVShaderInstructionsExecuted    = 65535;
4858         caps->MaxVertexShader30InstructionSlots = 0;
4859     }
4860     else
4861     { /* VS 1.x */
4862         caps->VS20Caps.caps = 0;
4863         caps->VS20Caps.dynamic_flow_control_depth = 0;
4864         caps->VS20Caps.temp_count = 0;
4865         caps->VS20Caps.static_flow_control_depth = 0;
4866
4867         caps->MaxVShaderInstructionsExecuted    = 0;
4868         caps->MaxVertexShader30InstructionSlots = 0;
4869     }
4870
4871     if (caps->PixelShaderVersion >= 3)
4872     {
4873         /* Where possible set the caps based on OpenGL extensions and if they
4874          * aren't set (in case of software rendering) use the PS 3.0 from
4875          * MSDN or else if there's OpenGL spec use a hardcoded value minimum
4876          * PS 3.0 value. */
4877
4878         /* Caps is more or less undocumented on MSDN but it appears to be
4879          * used for PS20Caps based on results from R9600/FX5900/Geforce6800
4880          * cards from Windows */
4881         caps->PS20Caps.caps = WINED3DPS20CAPS_ARBITRARYSWIZZLE |
4882                 WINED3DPS20CAPS_GRADIENTINSTRUCTIONS |
4883                 WINED3DPS20CAPS_PREDICATION          |
4884                 WINED3DPS20CAPS_NODEPENDENTREADLIMIT |
4885                 WINED3DPS20CAPS_NOTEXINSTRUCTIONLIMIT;
4886         /* PS 3.0 requires MAX_DYNAMICFLOWCONTROLDEPTH (24) */
4887         caps->PS20Caps.dynamic_flow_control_depth = WINED3DPS20_MAX_DYNAMICFLOWCONTROLDEPTH;
4888         caps->PS20Caps.temp_count = max(32, adapter->gl_info.limits.arb_ps_temps);
4889         /* PS 3.0 requires MAX_STATICFLOWCONTROLDEPTH (4) */
4890         caps->PS20Caps.static_flow_control_depth = WINED3DPS20_MAX_STATICFLOWCONTROLDEPTH;
4891         /* PS 3.0 requires MAX_NUMINSTRUCTIONSLOTS (512) */
4892         caps->PS20Caps.instruction_slot_count = WINED3DPS20_MAX_NUMINSTRUCTIONSLOTS;
4893
4894         caps->MaxPShaderInstructionsExecuted = 65535;
4895         caps->MaxPixelShader30InstructionSlots = max(WINED3DMIN30SHADERINSTRUCTIONS,
4896                 adapter->gl_info.limits.arb_ps_instructions);
4897     }
4898     else if(caps->PixelShaderVersion == 2)
4899     {
4900         /* Below we assume PS2.0 specs, not extended 2.0a(GeforceFX)/2.0b(Radeon R3xx) ones */
4901         caps->PS20Caps.caps = 0;
4902         caps->PS20Caps.dynamic_flow_control_depth = 0; /* WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH = 0 */
4903         caps->PS20Caps.temp_count = max(12, adapter->gl_info.limits.arb_ps_temps);
4904         caps->PS20Caps.static_flow_control_depth = WINED3DPS20_MIN_STATICFLOWCONTROLDEPTH; /* Minimum: 1 */
4905         /* Minimum number (64 ALU + 32 Texture), a GeforceFX uses 512 */
4906         caps->PS20Caps.instruction_slot_count = WINED3DPS20_MIN_NUMINSTRUCTIONSLOTS;
4907
4908         caps->MaxPShaderInstructionsExecuted    = 512; /* Minimum value, a GeforceFX uses 1024 */
4909         caps->MaxPixelShader30InstructionSlots  = 0;
4910     }
4911     else /* PS 1.x */
4912     {
4913         caps->PS20Caps.caps = 0;
4914         caps->PS20Caps.dynamic_flow_control_depth = 0;
4915         caps->PS20Caps.temp_count = 0;
4916         caps->PS20Caps.static_flow_control_depth = 0;
4917         caps->PS20Caps.instruction_slot_count = 0;
4918
4919         caps->MaxPShaderInstructionsExecuted    = 0;
4920         caps->MaxPixelShader30InstructionSlots  = 0;
4921     }
4922
4923     if (caps->VertexShaderVersion >= 2)
4924     {
4925         /* OpenGL supports all the formats below, perhaps not always
4926          * without conversion, but it supports them.
4927          * Further GLSL doesn't seem to have an official unsigned type so
4928          * don't advertise it yet as I'm not sure how we handle it.
4929          * We might need to add some clamping in the shader engine to
4930          * support it.
4931          * TODO: WINED3DDTCAPS_USHORT2N, WINED3DDTCAPS_USHORT4N, WINED3DDTCAPS_UDEC3, WINED3DDTCAPS_DEC3N */
4932         caps->DeclTypes = WINED3DDTCAPS_UBYTE4    |
4933                           WINED3DDTCAPS_UBYTE4N   |
4934                           WINED3DDTCAPS_SHORT2N   |
4935                           WINED3DDTCAPS_SHORT4N;
4936         if (gl_info->supported[ARB_HALF_FLOAT_VERTEX])
4937         {
4938             caps->DeclTypes |= WINED3DDTCAPS_FLOAT16_2 |
4939                                WINED3DDTCAPS_FLOAT16_4;
4940         }
4941     }
4942     else
4943     {
4944         caps->DeclTypes = 0;
4945     }
4946
4947     /* Set DirectDraw helper Caps */
4948     ckey_caps =                         WINEDDCKEYCAPS_DESTBLT              |
4949                                         WINEDDCKEYCAPS_SRCBLT;
4950     fx_caps =                           WINEDDFXCAPS_BLTALPHA               |
4951                                         WINEDDFXCAPS_BLTMIRRORLEFTRIGHT     |
4952                                         WINEDDFXCAPS_BLTMIRRORUPDOWN        |
4953                                         WINEDDFXCAPS_BLTROTATION90          |
4954                                         WINEDDFXCAPS_BLTSHRINKX             |
4955                                         WINEDDFXCAPS_BLTSHRINKXN            |
4956                                         WINEDDFXCAPS_BLTSHRINKY             |
4957                                         WINEDDFXCAPS_BLTSHRINKXN            |
4958                                         WINEDDFXCAPS_BLTSTRETCHX            |
4959                                         WINEDDFXCAPS_BLTSTRETCHXN           |
4960                                         WINEDDFXCAPS_BLTSTRETCHY            |
4961                                         WINEDDFXCAPS_BLTSTRETCHYN;
4962     blit_caps =                         WINEDDCAPS_BLT                      |
4963                                         WINEDDCAPS_BLTCOLORFILL             |
4964                                         WINEDDCAPS_BLTDEPTHFILL             |
4965                                         WINEDDCAPS_BLTSTRETCH               |
4966                                         WINEDDCAPS_CANBLTSYSMEM             |
4967                                         WINEDDCAPS_CANCLIP                  |
4968                                         WINEDDCAPS_CANCLIPSTRETCHED         |
4969                                         WINEDDCAPS_COLORKEY                 |
4970                                         WINEDDCAPS_COLORKEYHWASSIST         |
4971                                         WINEDDCAPS_ALIGNBOUNDARYSRC;
4972     pal_caps =                          WINEDDPCAPS_8BIT                    |
4973                                         WINEDDPCAPS_PRIMARYSURFACE;
4974
4975     /* Fill the ddraw caps structure */
4976     caps->ddraw_caps.caps =             WINEDDCAPS_GDI                      |
4977                                         WINEDDCAPS_PALETTE                  |
4978                                         blit_caps;
4979     caps->ddraw_caps.caps2 =            WINEDDCAPS2_CERTIFIED               |
4980                                         WINEDDCAPS2_NOPAGELOCKREQUIRED      |
4981                                         WINEDDCAPS2_PRIMARYGAMMA            |
4982                                         WINEDDCAPS2_WIDESURFACES            |
4983                                         WINEDDCAPS2_CANRENDERWINDOWED;
4984     caps->ddraw_caps.color_key_caps = ckey_caps;
4985     caps->ddraw_caps.fx_caps = fx_caps;
4986     caps->ddraw_caps.pal_caps = pal_caps;
4987     caps->ddraw_caps.svb_caps = blit_caps;
4988     caps->ddraw_caps.svb_color_key_caps = ckey_caps;
4989     caps->ddraw_caps.svb_fx_caps = fx_caps;
4990     caps->ddraw_caps.vsb_caps = blit_caps;
4991     caps->ddraw_caps.vsb_color_key_caps = ckey_caps;
4992     caps->ddraw_caps.vsb_fx_caps = fx_caps;
4993     caps->ddraw_caps.ssb_caps = blit_caps;
4994     caps->ddraw_caps.ssb_color_key_caps = ckey_caps;
4995     caps->ddraw_caps.ssb_fx_caps = fx_caps;
4996
4997     caps->ddraw_caps.dds_caps =         WINEDDSCAPS_ALPHA                   |
4998                                         WINEDDSCAPS_BACKBUFFER              |
4999                                         WINEDDSCAPS_FLIP                    |
5000                                         WINEDDSCAPS_FRONTBUFFER             |
5001                                         WINEDDSCAPS_OFFSCREENPLAIN          |
5002                                         WINEDDSCAPS_PALETTE                 |
5003                                         WINEDDSCAPS_PRIMARYSURFACE          |
5004                                         WINEDDSCAPS_SYSTEMMEMORY            |
5005                                         WINEDDSCAPS_VIDEOMEMORY             |
5006                                         WINEDDSCAPS_VISIBLE;
5007     caps->ddraw_caps.stride_align = DDRAW_PITCH_ALIGNMENT;
5008
5009     /* Set D3D caps if OpenGL is available. */
5010     if (adapter->opengl)
5011     {
5012         caps->ddraw_caps.dds_caps |=    WINEDDSCAPS_3DDEVICE                |
5013                                         WINEDDSCAPS_MIPMAP                  |
5014                                         WINEDDSCAPS_TEXTURE                 |
5015                                         WINEDDSCAPS_ZBUFFER;
5016         caps->ddraw_caps.caps |=        WINEDDCAPS_3D;
5017     }
5018
5019     return WINED3D_OK;
5020 }
5021
5022 HRESULT CDECL wined3d_device_create(struct wined3d *wined3d, UINT adapter_idx, enum wined3d_device_type device_type,
5023         HWND focus_window, DWORD flags, BYTE surface_alignment, struct wined3d_device_parent *device_parent,
5024         struct wined3d_device **device)
5025 {
5026     struct wined3d_device *object;
5027     HRESULT hr;
5028
5029     TRACE("wined3d %p, adapter_idx %u, device_type %#x, focus_window %p, flags %#x, device_parent %p, device %p.\n",
5030             wined3d, adapter_idx, device_type, focus_window, flags, device_parent, device);
5031
5032     /* Validate the adapter number. If no adapters are available(no GL), ignore the adapter
5033      * number and create a device without a 3D adapter for 2D only operation. */
5034     if (wined3d->adapter_count && adapter_idx >= wined3d->adapter_count)
5035         return WINED3DERR_INVALIDCALL;
5036
5037     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
5038     if (!object)
5039     {
5040         ERR("Failed to allocate device memory.\n");
5041         return E_OUTOFMEMORY;
5042     }
5043
5044     hr = device_init(object, wined3d, adapter_idx, device_type,
5045             focus_window, flags, surface_alignment, device_parent);
5046     if (FAILED(hr))
5047     {
5048         WARN("Failed to initialize device, hr %#x.\n", hr);
5049         HeapFree(GetProcessHeap(), 0, object);
5050         return hr;
5051     }
5052
5053     TRACE("Created device %p.\n", object);
5054     *device = object;
5055
5056     device_parent->ops->wined3d_device_created(device_parent, *device);
5057
5058     return WINED3D_OK;
5059 }
5060
5061 void * CDECL wined3d_get_parent(const struct wined3d *wined3d)
5062 {
5063     TRACE("wined3d %p.\n", wined3d);
5064
5065     return wined3d->parent;
5066 }
5067
5068 static void WINE_GLAPI invalid_func(const void *data)
5069 {
5070     ERR("Invalid vertex attribute function called\n");
5071     DebugBreak();
5072 }
5073
5074 static void WINE_GLAPI invalid_texcoord_func(GLenum unit, const void *data)
5075 {
5076     ERR("Invalid texcoord function called\n");
5077     DebugBreak();
5078 }
5079
5080 /* Helper functions for providing vertex data to opengl. The arrays are initialized based on
5081  * the extension detection and are used in drawStridedSlow
5082  */
5083 static void WINE_GLAPI position_d3dcolor(const void *data)
5084 {
5085     DWORD pos = *((const DWORD *)data);
5086
5087     FIXME("Add a test for fixed function position from d3dcolor type\n");
5088     glVertex4s(D3DCOLOR_B_R(pos),
5089                D3DCOLOR_B_G(pos),
5090                D3DCOLOR_B_B(pos),
5091                D3DCOLOR_B_A(pos));
5092 }
5093
5094 static void WINE_GLAPI position_float4(const void *data)
5095 {
5096     const GLfloat *pos = data;
5097
5098     if (pos[3] != 0.0f && pos[3] != 1.0f)
5099     {
5100         float w = 1.0f / pos[3];
5101
5102         glVertex4f(pos[0] * w, pos[1] * w, pos[2] * w, w);
5103     }
5104     else
5105     {
5106         glVertex3fv(pos);
5107     }
5108 }
5109
5110 static void WINE_GLAPI diffuse_d3dcolor(const void *data)
5111 {
5112     DWORD diffuseColor = *((const DWORD *)data);
5113
5114     glColor4ub(D3DCOLOR_B_R(diffuseColor),
5115                D3DCOLOR_B_G(diffuseColor),
5116                D3DCOLOR_B_B(diffuseColor),
5117                D3DCOLOR_B_A(diffuseColor));
5118 }
5119
5120 static void WINE_GLAPI specular_d3dcolor(const void *data)
5121 {
5122     DWORD specularColor = *((const DWORD *)data);
5123     GLbyte d[] = {D3DCOLOR_B_R(specularColor),
5124             D3DCOLOR_B_G(specularColor),
5125             D3DCOLOR_B_B(specularColor)};
5126
5127     specular_func_3ubv(d);
5128 }
5129
5130 static void WINE_GLAPI warn_no_specular_func(const void *data)
5131 {
5132     WARN("GL_EXT_secondary_color not supported\n");
5133 }
5134
5135 static void fillGLAttribFuncs(const struct wined3d_gl_info *gl_info)
5136 {
5137     position_funcs[WINED3D_FFP_EMIT_FLOAT1]      = invalid_func;
5138     position_funcs[WINED3D_FFP_EMIT_FLOAT2]      = invalid_func;
5139     position_funcs[WINED3D_FFP_EMIT_FLOAT3]      = (glAttribFunc)glVertex3fv;
5140     position_funcs[WINED3D_FFP_EMIT_FLOAT4]      = position_float4;
5141     position_funcs[WINED3D_FFP_EMIT_D3DCOLOR]    = position_d3dcolor;
5142     position_funcs[WINED3D_FFP_EMIT_UBYTE4]      = invalid_func;
5143     position_funcs[WINED3D_FFP_EMIT_SHORT2]      = invalid_func;
5144     position_funcs[WINED3D_FFP_EMIT_SHORT4]      = (glAttribFunc)glVertex2sv;
5145     position_funcs[WINED3D_FFP_EMIT_UBYTE4N]     = invalid_func;
5146     position_funcs[WINED3D_FFP_EMIT_SHORT2N]     = invalid_func;
5147     position_funcs[WINED3D_FFP_EMIT_SHORT4N]     = invalid_func;
5148     position_funcs[WINED3D_FFP_EMIT_USHORT2N]    = invalid_func;
5149     position_funcs[WINED3D_FFP_EMIT_USHORT4N]    = invalid_func;
5150     position_funcs[WINED3D_FFP_EMIT_UDEC3]       = invalid_func;
5151     position_funcs[WINED3D_FFP_EMIT_DEC3N]       = invalid_func;
5152     position_funcs[WINED3D_FFP_EMIT_FLOAT16_2]   = invalid_func;
5153     position_funcs[WINED3D_FFP_EMIT_FLOAT16_4]   = invalid_func;
5154
5155     diffuse_funcs[WINED3D_FFP_EMIT_FLOAT1]       = invalid_func;
5156     diffuse_funcs[WINED3D_FFP_EMIT_FLOAT2]       = invalid_func;
5157     diffuse_funcs[WINED3D_FFP_EMIT_FLOAT3]       = (glAttribFunc)glColor3fv;
5158     diffuse_funcs[WINED3D_FFP_EMIT_FLOAT4]       = (glAttribFunc)glColor4fv;
5159     diffuse_funcs[WINED3D_FFP_EMIT_D3DCOLOR]     = diffuse_d3dcolor;
5160     diffuse_funcs[WINED3D_FFP_EMIT_UBYTE4]       = invalid_func;
5161     diffuse_funcs[WINED3D_FFP_EMIT_SHORT2]       = invalid_func;
5162     diffuse_funcs[WINED3D_FFP_EMIT_SHORT4]       = invalid_func;
5163     diffuse_funcs[WINED3D_FFP_EMIT_UBYTE4N]      = (glAttribFunc)glColor4ubv;
5164     diffuse_funcs[WINED3D_FFP_EMIT_SHORT2N]      = invalid_func;
5165     diffuse_funcs[WINED3D_FFP_EMIT_SHORT4N]      = (glAttribFunc)glColor4sv;
5166     diffuse_funcs[WINED3D_FFP_EMIT_USHORT2N]     = invalid_func;
5167     diffuse_funcs[WINED3D_FFP_EMIT_USHORT4N]     = (glAttribFunc)glColor4usv;
5168     diffuse_funcs[WINED3D_FFP_EMIT_UDEC3]        = invalid_func;
5169     diffuse_funcs[WINED3D_FFP_EMIT_DEC3N]        = invalid_func;
5170     diffuse_funcs[WINED3D_FFP_EMIT_FLOAT16_2]    = invalid_func;
5171     diffuse_funcs[WINED3D_FFP_EMIT_FLOAT16_4]    = invalid_func;
5172
5173     /* No 4 component entry points here */
5174     specular_funcs[WINED3D_FFP_EMIT_FLOAT1]      = invalid_func;
5175     specular_funcs[WINED3D_FFP_EMIT_FLOAT2]      = invalid_func;
5176     if (gl_info->supported[EXT_SECONDARY_COLOR])
5177     {
5178         specular_funcs[WINED3D_FFP_EMIT_FLOAT3]  = (glAttribFunc)GL_EXTCALL(glSecondaryColor3fvEXT);
5179     }
5180     else
5181     {
5182         specular_funcs[WINED3D_FFP_EMIT_FLOAT3]  = warn_no_specular_func;
5183     }
5184     specular_funcs[WINED3D_FFP_EMIT_FLOAT4]      = invalid_func;
5185     if (gl_info->supported[EXT_SECONDARY_COLOR])
5186     {
5187         specular_func_3ubv = (glAttribFunc)GL_EXTCALL(glSecondaryColor3ubvEXT);
5188         specular_funcs[WINED3D_FFP_EMIT_D3DCOLOR] = specular_d3dcolor;
5189     }
5190     else
5191     {
5192         specular_funcs[WINED3D_FFP_EMIT_D3DCOLOR] = warn_no_specular_func;
5193     }
5194     specular_funcs[WINED3D_FFP_EMIT_UBYTE4]      = invalid_func;
5195     specular_funcs[WINED3D_FFP_EMIT_SHORT2]      = invalid_func;
5196     specular_funcs[WINED3D_FFP_EMIT_SHORT4]      = invalid_func;
5197     specular_funcs[WINED3D_FFP_EMIT_UBYTE4N]     = invalid_func;
5198     specular_funcs[WINED3D_FFP_EMIT_SHORT2N]     = invalid_func;
5199     specular_funcs[WINED3D_FFP_EMIT_SHORT4N]     = invalid_func;
5200     specular_funcs[WINED3D_FFP_EMIT_USHORT2N]    = invalid_func;
5201     specular_funcs[WINED3D_FFP_EMIT_USHORT4N]    = invalid_func;
5202     specular_funcs[WINED3D_FFP_EMIT_UDEC3]       = invalid_func;
5203     specular_funcs[WINED3D_FFP_EMIT_DEC3N]       = invalid_func;
5204     specular_funcs[WINED3D_FFP_EMIT_FLOAT16_2]   = invalid_func;
5205     specular_funcs[WINED3D_FFP_EMIT_FLOAT16_4]   = invalid_func;
5206
5207     /* Only 3 component entry points here. Test how others behave. Float4 normals are used
5208      * by one of our tests, trying to pass it to the pixel shader, which fails on Windows.
5209      */
5210     normal_funcs[WINED3D_FFP_EMIT_FLOAT1]         = invalid_func;
5211     normal_funcs[WINED3D_FFP_EMIT_FLOAT2]         = invalid_func;
5212     normal_funcs[WINED3D_FFP_EMIT_FLOAT3]         = (glAttribFunc)glNormal3fv;
5213     normal_funcs[WINED3D_FFP_EMIT_FLOAT4]         = (glAttribFunc)glNormal3fv; /* Just ignore the 4th value */
5214     normal_funcs[WINED3D_FFP_EMIT_D3DCOLOR]       = invalid_func;
5215     normal_funcs[WINED3D_FFP_EMIT_UBYTE4]         = invalid_func;
5216     normal_funcs[WINED3D_FFP_EMIT_SHORT2]         = invalid_func;
5217     normal_funcs[WINED3D_FFP_EMIT_SHORT4]         = invalid_func;
5218     normal_funcs[WINED3D_FFP_EMIT_UBYTE4N]        = invalid_func;
5219     normal_funcs[WINED3D_FFP_EMIT_SHORT2N]        = invalid_func;
5220     normal_funcs[WINED3D_FFP_EMIT_SHORT4N]        = invalid_func;
5221     normal_funcs[WINED3D_FFP_EMIT_USHORT2N]       = invalid_func;
5222     normal_funcs[WINED3D_FFP_EMIT_USHORT4N]       = invalid_func;
5223     normal_funcs[WINED3D_FFP_EMIT_UDEC3]          = invalid_func;
5224     normal_funcs[WINED3D_FFP_EMIT_DEC3N]          = invalid_func;
5225     normal_funcs[WINED3D_FFP_EMIT_FLOAT16_2]      = invalid_func;
5226     normal_funcs[WINED3D_FFP_EMIT_FLOAT16_4]      = invalid_func;
5227
5228     multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT1]    = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord1fvARB);
5229     multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT2]    = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord2fvARB);
5230     multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT3]    = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord3fvARB);
5231     multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT4]    = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord4fvARB);
5232     multi_texcoord_funcs[WINED3D_FFP_EMIT_D3DCOLOR]  = invalid_texcoord_func;
5233     multi_texcoord_funcs[WINED3D_FFP_EMIT_UBYTE4]    = invalid_texcoord_func;
5234     multi_texcoord_funcs[WINED3D_FFP_EMIT_SHORT2]    = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord2svARB);
5235     multi_texcoord_funcs[WINED3D_FFP_EMIT_SHORT4]    = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord4svARB);
5236     multi_texcoord_funcs[WINED3D_FFP_EMIT_UBYTE4N]   = invalid_texcoord_func;
5237     multi_texcoord_funcs[WINED3D_FFP_EMIT_SHORT2N]   = invalid_texcoord_func;
5238     multi_texcoord_funcs[WINED3D_FFP_EMIT_SHORT4N]   = invalid_texcoord_func;
5239     multi_texcoord_funcs[WINED3D_FFP_EMIT_USHORT2N]  = invalid_texcoord_func;
5240     multi_texcoord_funcs[WINED3D_FFP_EMIT_USHORT4N]  = invalid_texcoord_func;
5241     multi_texcoord_funcs[WINED3D_FFP_EMIT_UDEC3]     = invalid_texcoord_func;
5242     multi_texcoord_funcs[WINED3D_FFP_EMIT_DEC3N]     = invalid_texcoord_func;
5243     if (gl_info->supported[NV_HALF_FLOAT])
5244     {
5245         /* Not supported by ARB_HALF_FLOAT_VERTEX, so check for NV_HALF_FLOAT */
5246         multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT16_2] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord2hvNV);
5247         multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT16_4] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord4hvNV);
5248     } else {
5249         multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT16_2] = invalid_texcoord_func;
5250         multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT16_4] = invalid_texcoord_func;
5251     }
5252 }
5253
5254 /* Do not call while under the GL lock. */
5255 static BOOL InitAdapters(struct wined3d *wined3d)
5256 {
5257     static HMODULE mod_gl;
5258     BOOL ret;
5259     int ps_selected_mode, vs_selected_mode;
5260
5261     /* No need to hold any lock. The calling library makes sure only one thread calls
5262      * wined3d simultaneously
5263      */
5264
5265     TRACE("Initializing adapters\n");
5266
5267     if(!mod_gl) {
5268 #ifdef USE_WIN32_OPENGL
5269 #define USE_GL_FUNC(pfn) pfn = (void*)GetProcAddress(mod_gl, #pfn);
5270         mod_gl = LoadLibraryA("opengl32.dll");
5271         if(!mod_gl) {
5272             ERR("Can't load opengl32.dll!\n");
5273             goto nogl_adapter;
5274         }
5275 #else
5276 #define USE_GL_FUNC(pfn) pfn = (void*)pwglGetProcAddress(#pfn);
5277         /* To bypass the opengl32 thunks load wglGetProcAddress from gdi32 (glXGetProcAddress wrapper) instead of opengl32's */
5278         mod_gl = GetModuleHandleA("gdi32.dll");
5279 #endif
5280     }
5281
5282 /* Load WGL core functions from opengl32.dll */
5283 #define USE_WGL_FUNC(pfn) p##pfn = (void*)GetProcAddress(mod_gl, #pfn);
5284     WGL_FUNCS_GEN;
5285 #undef USE_WGL_FUNC
5286
5287     if(!pwglGetProcAddress) {
5288         ERR("Unable to load wglGetProcAddress!\n");
5289         goto nogl_adapter;
5290     }
5291
5292 /* Dynamically load all GL core functions */
5293     GL_FUNCS_GEN;
5294 #undef USE_GL_FUNC
5295
5296     /* Load glFinish and glFlush from opengl32.dll even if we're not using WIN32 opengl
5297      * otherwise because we have to use winex11.drv's override
5298      */
5299 #ifdef USE_WIN32_OPENGL
5300     wglFinish = (void*)GetProcAddress(mod_gl, "glFinish");
5301     wglFlush = (void*)GetProcAddress(mod_gl, "glFlush");
5302 #else
5303     wglFinish = (void*)pwglGetProcAddress("wglFinish");
5304     wglFlush = (void*)pwglGetProcAddress("wglFlush");
5305 #endif
5306
5307     glEnableWINE = glEnable;
5308     glDisableWINE = glDisable;
5309
5310     /* For now only one default adapter */
5311     {
5312         struct wined3d_adapter *adapter = &wined3d->adapters[0];
5313         const struct wined3d_gl_info *gl_info = &adapter->gl_info;
5314         struct wined3d_fake_gl_ctx fake_gl_ctx = {0};
5315         struct wined3d_pixel_format *cfgs;
5316         int iPixelFormat;
5317         int res;
5318         DISPLAY_DEVICEW DisplayDevice;
5319         HDC hdc;
5320
5321         TRACE("Initializing default adapter\n");
5322         adapter->ordinal = 0;
5323         adapter->monitorPoint.x = -1;
5324         adapter->monitorPoint.y = -1;
5325
5326         if (!AllocateLocallyUniqueId(&adapter->luid))
5327         {
5328             DWORD err = GetLastError();
5329             ERR("Failed to set adapter LUID (%#x).\n", err);
5330             goto nogl_adapter;
5331         }
5332         TRACE("Allocated LUID %08x:%08x for adapter.\n",
5333                 adapter->luid.HighPart, adapter->luid.LowPart);
5334
5335         if (!WineD3D_CreateFakeGLContext(&fake_gl_ctx))
5336         {
5337             ERR("Failed to get a gl context for default adapter\n");
5338             goto nogl_adapter;
5339         }
5340
5341         ret = wined3d_adapter_init_gl_caps(adapter);
5342         if(!ret) {
5343             ERR("Failed to initialize gl caps for default adapter\n");
5344             WineD3D_ReleaseFakeGLContext(&fake_gl_ctx);
5345             goto nogl_adapter;
5346         }
5347         ret = initPixelFormats(&adapter->gl_info, adapter->driver_info.vendor);
5348         if(!ret) {
5349             ERR("Failed to init gl formats\n");
5350             WineD3D_ReleaseFakeGLContext(&fake_gl_ctx);
5351             goto nogl_adapter;
5352         }
5353
5354         hdc = fake_gl_ctx.dc;
5355
5356         adapter->TextureRam = adapter->driver_info.vidmem;
5357         adapter->UsedTextureRam = 0;
5358         TRACE("Emulating %dMB of texture ram\n", adapter->TextureRam/(1024*1024));
5359
5360         /* Initialize the Adapter's DeviceName which is required for ChangeDisplaySettings and friends */
5361         DisplayDevice.cb = sizeof(DisplayDevice);
5362         EnumDisplayDevicesW(NULL, 0 /* Adapter 0 = iDevNum 0 */, &DisplayDevice, 0);
5363         TRACE("DeviceName: %s\n", debugstr_w(DisplayDevice.DeviceName));
5364         strcpyW(adapter->DeviceName, DisplayDevice.DeviceName);
5365
5366         if (gl_info->supported[WGL_ARB_PIXEL_FORMAT])
5367         {
5368             GLint cfg_count;
5369             int attribute;
5370             int attribs[11];
5371             int values[11];
5372             int nAttribs = 0;
5373
5374             attribute = WGL_NUMBER_PIXEL_FORMATS_ARB;
5375             GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, 0, 0, 1, &attribute, &cfg_count));
5376             adapter->cfg_count = cfg_count;
5377
5378             adapter->cfgs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, adapter->cfg_count * sizeof(*adapter->cfgs));
5379             cfgs = adapter->cfgs;
5380             attribs[nAttribs++] = WGL_RED_BITS_ARB;
5381             attribs[nAttribs++] = WGL_GREEN_BITS_ARB;
5382             attribs[nAttribs++] = WGL_BLUE_BITS_ARB;
5383             attribs[nAttribs++] = WGL_ALPHA_BITS_ARB;
5384             attribs[nAttribs++] = WGL_COLOR_BITS_ARB;
5385             attribs[nAttribs++] = WGL_DEPTH_BITS_ARB;
5386             attribs[nAttribs++] = WGL_STENCIL_BITS_ARB;
5387             attribs[nAttribs++] = WGL_DRAW_TO_WINDOW_ARB;
5388             attribs[nAttribs++] = WGL_PIXEL_TYPE_ARB;
5389             attribs[nAttribs++] = WGL_DOUBLE_BUFFER_ARB;
5390             attribs[nAttribs++] = WGL_AUX_BUFFERS_ARB;
5391
5392             for (iPixelFormat=1; iPixelFormat <= adapter->cfg_count; ++iPixelFormat)
5393             {
5394                 res = GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0, nAttribs, attribs, values));
5395
5396                 if(!res)
5397                     continue;
5398
5399                 /* Cache the pixel format */
5400                 cfgs->iPixelFormat = iPixelFormat;
5401                 cfgs->redSize = values[0];
5402                 cfgs->greenSize = values[1];
5403                 cfgs->blueSize = values[2];
5404                 cfgs->alphaSize = values[3];
5405                 cfgs->colorSize = values[4];
5406                 cfgs->depthSize = values[5];
5407                 cfgs->stencilSize = values[6];
5408                 cfgs->windowDrawable = values[7];
5409                 cfgs->iPixelType = values[8];
5410                 cfgs->doubleBuffer = values[9];
5411                 cfgs->auxBuffers = values[10];
5412
5413                 cfgs->numSamples = 0;
5414                 /* Check multisample support */
5415                 if (gl_info->supported[ARB_MULTISAMPLE])
5416                 {
5417                     int attrib[2] = {WGL_SAMPLE_BUFFERS_ARB, WGL_SAMPLES_ARB};
5418                     int value[2];
5419                     if(GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0, 2, attrib, value))) {
5420                         /* value[0] = WGL_SAMPLE_BUFFERS_ARB which tells whether multisampling is supported.
5421                         * value[1] = number of multi sample buffers*/
5422                         if(value[0])
5423                             cfgs->numSamples = value[1];
5424                     }
5425                 }
5426
5427                 TRACE("iPixelFormat=%d, iPixelType=%#x, doubleBuffer=%d, RGBA=%d/%d/%d/%d, "
5428                         "depth=%d, stencil=%d, samples=%d, windowDrawable=%d\n",
5429                         cfgs->iPixelFormat, cfgs->iPixelType, cfgs->doubleBuffer,
5430                         cfgs->redSize, cfgs->greenSize, cfgs->blueSize, cfgs->alphaSize,
5431                         cfgs->depthSize, cfgs->stencilSize, cfgs->numSamples, cfgs->windowDrawable);
5432                 cfgs++;
5433             }
5434         }
5435         else
5436         {
5437             int nCfgs = DescribePixelFormat(hdc, 0, 0, 0);
5438             adapter->cfgs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nCfgs * sizeof(*adapter->cfgs));
5439             adapter->cfg_count = 0; /* We won't accept all formats e.g. software accelerated ones will be skipped */
5440
5441             cfgs = adapter->cfgs;
5442             for(iPixelFormat=1; iPixelFormat<=nCfgs; iPixelFormat++)
5443             {
5444                 PIXELFORMATDESCRIPTOR ppfd;
5445
5446                 res = DescribePixelFormat(hdc, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &ppfd);
5447                 if(!res)
5448                     continue;
5449
5450                 /* We only want HW acceleration using an OpenGL ICD driver.
5451                  * PFD_GENERIC_FORMAT = slow opengl 1.1 gdi software rendering
5452                  * PFD_GENERIC_ACCELERATED = partial hw acceleration using a MCD driver (e.g. 3dfx minigl)
5453                  */
5454                 if(ppfd.dwFlags & (PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED))
5455                 {
5456                     TRACE("Skipping iPixelFormat=%d because it isn't ICD accelerated\n", iPixelFormat);
5457                     continue;
5458                 }
5459
5460                 cfgs->iPixelFormat = iPixelFormat;
5461                 cfgs->redSize = ppfd.cRedBits;
5462                 cfgs->greenSize = ppfd.cGreenBits;
5463                 cfgs->blueSize = ppfd.cBlueBits;
5464                 cfgs->alphaSize = ppfd.cAlphaBits;
5465                 cfgs->colorSize = ppfd.cColorBits;
5466                 cfgs->depthSize = ppfd.cDepthBits;
5467                 cfgs->stencilSize = ppfd.cStencilBits;
5468                 cfgs->windowDrawable = (ppfd.dwFlags & PFD_DRAW_TO_WINDOW) ? 1 : 0;
5469                 cfgs->iPixelType = (ppfd.iPixelType == PFD_TYPE_RGBA) ? WGL_TYPE_RGBA_ARB : WGL_TYPE_COLORINDEX_ARB;
5470                 cfgs->doubleBuffer = (ppfd.dwFlags & PFD_DOUBLEBUFFER) ? 1 : 0;
5471                 cfgs->auxBuffers = ppfd.cAuxBuffers;
5472                 cfgs->numSamples = 0;
5473
5474                 TRACE("iPixelFormat=%d, iPixelType=%#x, doubleBuffer=%d, RGBA=%d/%d/%d/%d, "
5475                         "depth=%d, stencil=%d, windowDrawable=%d\n",
5476                         cfgs->iPixelFormat, cfgs->iPixelType, cfgs->doubleBuffer,
5477                         cfgs->redSize, cfgs->greenSize, cfgs->blueSize, cfgs->alphaSize,
5478                         cfgs->depthSize, cfgs->stencilSize, cfgs->windowDrawable);
5479                 cfgs++;
5480                 adapter->cfg_count++;
5481             }
5482
5483             /* We haven't found any suitable formats. This should only happen
5484              * in case of GDI software rendering, which is pretty useless
5485              * anyway. */
5486             if (!adapter->cfg_count)
5487             {
5488                 ERR("Disabling Direct3D because no hardware accelerated pixel formats have been found!\n");
5489
5490                 WineD3D_ReleaseFakeGLContext(&fake_gl_ctx);
5491                 HeapFree(GetProcessHeap(), 0, adapter->cfgs);
5492                 goto nogl_adapter;
5493             }
5494         }
5495
5496         WineD3D_ReleaseFakeGLContext(&fake_gl_ctx);
5497
5498         select_shader_mode(&adapter->gl_info, &ps_selected_mode, &vs_selected_mode);
5499         fillGLAttribFuncs(&adapter->gl_info);
5500         adapter->opengl = TRUE;
5501     }
5502     wined3d->adapter_count = 1;
5503     TRACE("%u adapters successfully initialized.\n", wined3d->adapter_count);
5504
5505     return TRUE;
5506
5507 nogl_adapter:
5508     /* Initialize an adapter for ddraw-only memory counting */
5509     memset(wined3d->adapters, 0, sizeof(wined3d->adapters));
5510     wined3d->adapters[0].ordinal = 0;
5511     wined3d->adapters[0].opengl = FALSE;
5512     wined3d->adapters[0].monitorPoint.x = -1;
5513     wined3d->adapters[0].monitorPoint.y = -1;
5514
5515     wined3d->adapters[0].driver_info.name = "Display";
5516     wined3d->adapters[0].driver_info.description = "WineD3D DirectDraw Emulation";
5517     if (wined3d_settings.emulated_textureram)
5518         wined3d->adapters[0].TextureRam = wined3d_settings.emulated_textureram;
5519     else
5520         wined3d->adapters[0].TextureRam = 8 * 1024 * 1024; /* This is plenty for a DDraw-only card */
5521
5522     initPixelFormatsNoGL(&wined3d->adapters[0].gl_info);
5523
5524     wined3d->adapter_count = 1;
5525     return FALSE;
5526 }
5527
5528 static void STDMETHODCALLTYPE wined3d_null_wined3d_object_destroyed(void *parent) {}
5529
5530 const struct wined3d_parent_ops wined3d_null_parent_ops =
5531 {
5532     wined3d_null_wined3d_object_destroyed,
5533 };
5534
5535 /* Do not call while under the GL lock. */
5536 HRESULT wined3d_init(struct wined3d *wined3d, UINT version, DWORD flags, void *parent)
5537 {
5538     wined3d->dxVersion = version;
5539     wined3d->ref = 1;
5540     wined3d->parent = parent;
5541     wined3d->flags = flags;
5542
5543     if (!InitAdapters(wined3d))
5544     {
5545         WARN("Failed to initialize adapters.\n");
5546         if (version > 7)
5547         {
5548             MESSAGE("Direct3D%u is not available without OpenGL.\n", version);
5549             return E_FAIL;
5550         }
5551     }
5552
5553     return WINED3D_OK;
5554 }