makedep: Use an unsigned constant in hash_filename.
[wine.git] / dlls / wined3d / directx.c
blob5f995ced018875559d6be211f13fd3eef23b7e96
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
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "config.h"
25 #include "wine/port.h"
27 #include <stdio.h>
29 #include "wined3d_private.h"
30 #include "winternl.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
33 WINE_DECLARE_DEBUG_CHANNEL(d3d_perf);
34 WINE_DECLARE_DEBUG_CHANNEL(winediag);
36 #define WINE_DEFAULT_VIDMEM (64 * 1024 * 1024)
37 #define DEFAULT_REFRESH_RATE 0
39 /* The driver names reflect the lowest GPU supported
40 * by a certain driver, so DRIVER_AMD_R300 supports
41 * R3xx, R4xx and R5xx GPUs. */
42 enum wined3d_display_driver
44 DRIVER_AMD_RAGE_128PRO,
45 DRIVER_AMD_R100,
46 DRIVER_AMD_R300,
47 DRIVER_AMD_R600,
48 DRIVER_INTEL_GMA800,
49 DRIVER_INTEL_GMA900,
50 DRIVER_INTEL_GMA950,
51 DRIVER_INTEL_GMA3000,
52 DRIVER_NVIDIA_TNT,
53 DRIVER_NVIDIA_GEFORCE2MX,
54 DRIVER_NVIDIA_GEFORCEFX,
55 DRIVER_NVIDIA_GEFORCE6,
56 DRIVER_NVIDIA_GEFORCE8,
57 DRIVER_VMWARE,
58 DRIVER_UNKNOWN
61 enum wined3d_driver_model
63 DRIVER_MODEL_WIN9X,
64 DRIVER_MODEL_NT40,
65 DRIVER_MODEL_NT5X,
66 DRIVER_MODEL_NT6X
69 enum wined3d_gl_vendor
71 GL_VENDOR_UNKNOWN,
72 GL_VENDOR_APPLE,
73 GL_VENDOR_FGLRX,
74 GL_VENDOR_MESA,
75 GL_VENDOR_NVIDIA,
78 enum wined3d_d3d_level
80 WINED3D_D3D_LEVEL_5,
81 WINED3D_D3D_LEVEL_6,
82 WINED3D_D3D_LEVEL_7,
83 WINED3D_D3D_LEVEL_8,
84 WINED3D_D3D_LEVEL_9_SM2,
85 WINED3D_D3D_LEVEL_9_SM3,
86 WINED3D_D3D_LEVEL_10,
87 WINED3D_D3D_LEVEL_11,
88 WINED3D_D3D_LEVEL_COUNT
91 /* The d3d device ID */
92 static const GUID IID_D3DDEVICE_D3DUID = { 0xaeb2cdd4, 0x6e41, 0x43ea, { 0x94,0x1c,0x83,0x61,0xcc,0x76,0x07,0x81 } };
94 /* Extension detection */
95 struct wined3d_extension_map
97 const char *extension_string;
98 enum wined3d_gl_extension extension;
101 static const struct wined3d_extension_map gl_extension_map[] =
103 /* APPLE */
104 {"GL_APPLE_fence", APPLE_FENCE },
105 {"GL_APPLE_float_pixels", APPLE_FLOAT_PIXELS },
106 {"GL_APPLE_flush_buffer_range", APPLE_FLUSH_BUFFER_RANGE },
107 {"GL_APPLE_ycbcr_422", APPLE_YCBCR_422 },
109 /* ARB */
110 {"GL_ARB_blend_func_extended", ARB_BLEND_FUNC_EXTENDED },
111 {"GL_ARB_color_buffer_float", ARB_COLOR_BUFFER_FLOAT },
112 {"GL_ARB_debug_output", ARB_DEBUG_OUTPUT },
113 {"GL_ARB_depth_buffer_float", ARB_DEPTH_BUFFER_FLOAT },
114 {"GL_ARB_depth_texture", ARB_DEPTH_TEXTURE },
115 {"GL_ARB_draw_buffers", ARB_DRAW_BUFFERS },
116 {"GL_ARB_draw_elements_base_vertex", ARB_DRAW_ELEMENTS_BASE_VERTEX },
117 {"GL_ARB_draw_instanced", ARB_DRAW_INSTANCED },
118 {"GL_ARB_ES2_compatibility", ARB_ES2_COMPATIBILITY },
119 {"GL_ARB_fragment_program", ARB_FRAGMENT_PROGRAM },
120 {"GL_ARB_fragment_shader", ARB_FRAGMENT_SHADER },
121 {"GL_ARB_framebuffer_object", ARB_FRAMEBUFFER_OBJECT },
122 {"GL_ARB_framebuffer_sRGB", ARB_FRAMEBUFFER_SRGB },
123 {"GL_ARB_geometry_shader4", ARB_GEOMETRY_SHADER4 },
124 {"GL_ARB_half_float_pixel", ARB_HALF_FLOAT_PIXEL },
125 {"GL_ARB_half_float_vertex", ARB_HALF_FLOAT_VERTEX },
126 {"GL_ARB_instanced_arrays", ARB_INSTANCED_ARRAYS },
127 {"GL_ARB_internalformat_query", ARB_INTERNALFORMAT_QUERY },
128 {"GL_ARB_internalformat_query2", ARB_INTERNALFORMAT_QUERY2 },
129 {"GL_ARB_map_buffer_alignment", ARB_MAP_BUFFER_ALIGNMENT },
130 {"GL_ARB_map_buffer_range", ARB_MAP_BUFFER_RANGE },
131 {"GL_ARB_multisample", ARB_MULTISAMPLE },
132 {"GL_ARB_multitexture", ARB_MULTITEXTURE },
133 {"GL_ARB_occlusion_query", ARB_OCCLUSION_QUERY },
134 {"GL_ARB_pixel_buffer_object", ARB_PIXEL_BUFFER_OBJECT },
135 {"GL_ARB_point_parameters", ARB_POINT_PARAMETERS },
136 {"GL_ARB_point_sprite", ARB_POINT_SPRITE },
137 {"GL_ARB_provoking_vertex", ARB_PROVOKING_VERTEX },
138 {"GL_ARB_sampler_objects", ARB_SAMPLER_OBJECTS },
139 {"GL_ARB_shader_bit_encoding", ARB_SHADER_BIT_ENCODING },
140 {"GL_ARB_shader_texture_lod", ARB_SHADER_TEXTURE_LOD },
141 {"GL_ARB_shading_language_100", ARB_SHADING_LANGUAGE_100 },
142 {"GL_ARB_shadow", ARB_SHADOW },
143 {"GL_ARB_sync", ARB_SYNC },
144 {"GL_ARB_texture_border_clamp", ARB_TEXTURE_BORDER_CLAMP },
145 {"GL_ARB_texture_compression", ARB_TEXTURE_COMPRESSION },
146 {"GL_ARB_texture_compression_rgtc", ARB_TEXTURE_COMPRESSION_RGTC },
147 {"GL_ARB_texture_cube_map", ARB_TEXTURE_CUBE_MAP },
148 {"GL_ARB_texture_env_combine", ARB_TEXTURE_ENV_COMBINE },
149 {"GL_ARB_texture_env_dot3", ARB_TEXTURE_ENV_DOT3 },
150 {"GL_ARB_texture_float", ARB_TEXTURE_FLOAT },
151 {"GL_ARB_texture_mirrored_repeat", ARB_TEXTURE_MIRRORED_REPEAT },
152 {"GL_ARB_texture_mirror_clamp_to_edge", ARB_TEXTURE_MIRROR_CLAMP_TO_EDGE},
153 {"GL_ARB_texture_non_power_of_two", ARB_TEXTURE_NON_POWER_OF_TWO },
154 {"GL_ARB_texture_query_levels", ARB_TEXTURE_QUERY_LEVELS },
155 {"GL_ARB_texture_rectangle", ARB_TEXTURE_RECTANGLE },
156 {"GL_ARB_texture_rg", ARB_TEXTURE_RG },
157 {"GL_ARB_texture_rgb10_a2ui", ARB_TEXTURE_RGB10_A2UI },
158 {"GL_ARB_timer_query", ARB_TIMER_QUERY },
159 {"GL_ARB_uniform_buffer_object", ARB_UNIFORM_BUFFER_OBJECT },
160 {"GL_ARB_vertex_array_bgra", ARB_VERTEX_ARRAY_BGRA },
161 {"GL_ARB_vertex_blend", ARB_VERTEX_BLEND },
162 {"GL_ARB_vertex_buffer_object", ARB_VERTEX_BUFFER_OBJECT },
163 {"GL_ARB_vertex_program", ARB_VERTEX_PROGRAM },
164 {"GL_ARB_vertex_shader", ARB_VERTEX_SHADER },
166 /* ATI */
167 {"GL_ATI_fragment_shader", ATI_FRAGMENT_SHADER },
168 {"GL_ATI_separate_stencil", ATI_SEPARATE_STENCIL },
169 {"GL_ATI_texture_compression_3dc", ATI_TEXTURE_COMPRESSION_3DC },
170 {"GL_ATI_texture_env_combine3", ATI_TEXTURE_ENV_COMBINE3 },
171 {"GL_ATI_texture_mirror_once", ATI_TEXTURE_MIRROR_ONCE },
173 /* EXT */
174 {"GL_EXT_blend_color", EXT_BLEND_COLOR },
175 {"GL_EXT_blend_equation_separate", EXT_BLEND_EQUATION_SEPARATE },
176 {"GL_EXT_blend_func_separate", EXT_BLEND_FUNC_SEPARATE },
177 {"GL_EXT_blend_minmax", EXT_BLEND_MINMAX },
178 {"GL_EXT_blend_subtract", EXT_BLEND_SUBTRACT },
179 {"GL_EXT_depth_bounds_test", EXT_DEPTH_BOUNDS_TEST },
180 {"GL_EXT_draw_buffers2", EXT_DRAW_BUFFERS2 },
181 {"GL_EXT_fog_coord", EXT_FOG_COORD },
182 {"GL_EXT_framebuffer_blit", EXT_FRAMEBUFFER_BLIT },
183 {"GL_EXT_framebuffer_multisample", EXT_FRAMEBUFFER_MULTISAMPLE },
184 {"GL_EXT_framebuffer_object", EXT_FRAMEBUFFER_OBJECT },
185 {"GL_EXT_gpu_program_parameters", EXT_GPU_PROGRAM_PARAMETERS },
186 {"GL_EXT_gpu_shader4", EXT_GPU_SHADER4 },
187 {"GL_EXT_packed_depth_stencil", EXT_PACKED_DEPTH_STENCIL },
188 {"GL_EXT_point_parameters", EXT_POINT_PARAMETERS },
189 {"GL_EXT_provoking_vertex", EXT_PROVOKING_VERTEX },
190 {"GL_EXT_secondary_color", EXT_SECONDARY_COLOR },
191 {"GL_EXT_stencil_two_side", EXT_STENCIL_TWO_SIDE },
192 {"GL_EXT_stencil_wrap", EXT_STENCIL_WRAP },
193 {"GL_EXT_texture3D", EXT_TEXTURE3D },
194 {"GL_EXT_texture_compression_rgtc", EXT_TEXTURE_COMPRESSION_RGTC },
195 {"GL_EXT_texture_compression_s3tc", EXT_TEXTURE_COMPRESSION_S3TC },
196 {"GL_EXT_texture_env_combine", EXT_TEXTURE_ENV_COMBINE },
197 {"GL_EXT_texture_env_dot3", EXT_TEXTURE_ENV_DOT3 },
198 {"GL_EXT_texture_filter_anisotropic", EXT_TEXTURE_FILTER_ANISOTROPIC},
199 {"GL_EXT_texture_integer", EXT_TEXTURE_INTEGER },
200 {"GL_EXT_texture_lod_bias", EXT_TEXTURE_LOD_BIAS },
201 {"GL_EXT_texture_mirror_clamp", EXT_TEXTURE_MIRROR_CLAMP },
202 {"GL_EXT_texture_snorm", EXT_TEXTURE_SNORM },
203 {"GL_EXT_texture_sRGB", EXT_TEXTURE_SRGB },
204 {"GL_EXT_texture_sRGB_decode", EXT_TEXTURE_SRGB_DECODE },
205 {"GL_EXT_vertex_array_bgra", EXT_VERTEX_ARRAY_BGRA },
207 /* NV */
208 {"GL_NV_fence", NV_FENCE },
209 {"GL_NV_fog_distance", NV_FOG_DISTANCE },
210 {"GL_NV_fragment_program", NV_FRAGMENT_PROGRAM },
211 {"GL_NV_fragment_program2", NV_FRAGMENT_PROGRAM2 },
212 {"GL_NV_fragment_program_option", NV_FRAGMENT_PROGRAM_OPTION },
213 {"GL_NV_half_float", NV_HALF_FLOAT },
214 {"GL_NV_light_max_exponent", NV_LIGHT_MAX_EXPONENT },
215 {"GL_NV_point_sprite", NV_POINT_SPRITE },
216 {"GL_NV_register_combiners", NV_REGISTER_COMBINERS },
217 {"GL_NV_register_combiners2", NV_REGISTER_COMBINERS2 },
218 {"GL_NV_texgen_reflection", NV_TEXGEN_REFLECTION },
219 {"GL_NV_texture_env_combine4", NV_TEXTURE_ENV_COMBINE4 },
220 {"GL_NV_texture_shader", NV_TEXTURE_SHADER },
221 {"GL_NV_texture_shader2", NV_TEXTURE_SHADER2 },
222 {"GL_NV_vertex_program", NV_VERTEX_PROGRAM },
223 {"GL_NV_vertex_program1_1", NV_VERTEX_PROGRAM1_1 },
224 {"GL_NV_vertex_program2", NV_VERTEX_PROGRAM2 },
225 {"GL_NV_vertex_program2_option", NV_VERTEX_PROGRAM2_OPTION },
226 {"GL_NV_vertex_program3", NV_VERTEX_PROGRAM3 },
228 /* SGI */
229 {"GL_SGIS_generate_mipmap", SGIS_GENERATE_MIPMAP },
232 static const struct wined3d_extension_map wgl_extension_map[] =
234 {"WGL_ARB_pixel_format", WGL_ARB_PIXEL_FORMAT },
235 {"WGL_EXT_swap_control", WGL_EXT_SWAP_CONTROL },
236 {"WGL_WINE_pixel_format_passthrough", WGL_WINE_PIXEL_FORMAT_PASSTHROUGH},
239 /**********************************************************
240 * Utility functions follow
241 **********************************************************/
243 const struct min_lookup minMipLookup[] =
245 /* NONE POINT LINEAR */
246 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}}, /* NONE */
247 {{GL_NEAREST, GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR}}, /* POINT*/
248 {{GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_LINEAR}}, /* LINEAR */
251 const GLenum magLookup[] =
253 /* NONE POINT LINEAR */
254 GL_NEAREST, GL_NEAREST, GL_LINEAR,
257 static void wined3d_caps_gl_ctx_destroy(const struct wined3d_caps_gl_ctx *ctx)
259 const struct wined3d_gl_info *gl_info = ctx->gl_info;
261 TRACE("Destroying caps GL context.\n");
263 /* Both glDeleteProgram and glDeleteBuffers silently ignore 0 IDs but
264 * this function might be called before the relevant function pointers
265 * in gl_info are initialized. */
266 if (ctx->test_program_id || ctx->test_vbo)
268 GL_EXTCALL(glDeleteProgram(ctx->test_program_id));
269 GL_EXTCALL(glDeleteBuffers(1, &ctx->test_vbo));
272 if (!wglMakeCurrent(NULL, NULL))
273 ERR("Failed to disable caps GL context.\n");
275 if (!wglDeleteContext(ctx->gl_ctx))
277 DWORD err = GetLastError();
278 ERR("wglDeleteContext(%p) failed, last error %#x.\n", ctx->gl_ctx, err);
281 wined3d_release_dc(ctx->wnd, ctx->dc);
282 DestroyWindow(ctx->wnd);
284 if (ctx->restore_gl_ctx && !wglMakeCurrent(ctx->restore_dc, ctx->restore_gl_ctx))
285 ERR("Failed to restore previous GL context.\n");
288 static BOOL wined3d_caps_gl_ctx_create_attribs(struct wined3d_caps_gl_ctx *caps_gl_ctx,
289 struct wined3d_gl_info *gl_info)
291 HGLRC new_ctx;
293 if (!(gl_info->p_wglCreateContextAttribsARB = (void *)wglGetProcAddress("wglCreateContextAttribsARB")))
294 return TRUE;
296 if (!(new_ctx = context_create_wgl_attribs(gl_info, caps_gl_ctx->dc, NULL)))
298 gl_info->p_wglCreateContextAttribsARB = NULL;
299 return FALSE;
302 if (!wglMakeCurrent(caps_gl_ctx->dc, new_ctx))
304 ERR("Failed to make new context current, last error %#x.\n", GetLastError());
305 if (!wglDeleteContext(new_ctx))
306 ERR("Failed to delete new context, last error %#x.\n", GetLastError());
307 gl_info->p_wglCreateContextAttribsARB = NULL;
308 return TRUE;
311 if (!wglDeleteContext(caps_gl_ctx->gl_ctx))
312 ERR("Failed to delete old context, last error %#x.\n", GetLastError());
313 caps_gl_ctx->gl_ctx = new_ctx;
315 return TRUE;
318 static BOOL wined3d_caps_gl_ctx_create(struct wined3d_adapter *adapter, struct wined3d_caps_gl_ctx *ctx)
320 PIXELFORMATDESCRIPTOR pfd;
321 int iPixelFormat;
323 TRACE("getting context...\n");
325 ctx->restore_dc = wglGetCurrentDC();
326 ctx->restore_gl_ctx = wglGetCurrentContext();
328 /* We need a fake window as a hdc retrieved using GetDC(0) can't be used for much GL purposes. */
329 ctx->wnd = CreateWindowA(WINED3D_OPENGL_WINDOW_CLASS_NAME, "WineD3D fake window",
330 WS_OVERLAPPEDWINDOW, 10, 10, 10, 10, NULL, NULL, NULL, NULL);
331 if (!ctx->wnd)
333 ERR("Failed to create a window.\n");
334 goto fail;
337 ctx->dc = GetDC(ctx->wnd);
338 if (!ctx->dc)
340 ERR("Failed to get a DC.\n");
341 goto fail;
344 /* PixelFormat selection */
345 ZeroMemory(&pfd, sizeof(pfd));
346 pfd.nSize = sizeof(pfd);
347 pfd.nVersion = 1;
348 pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW; /* PFD_GENERIC_ACCELERATED */
349 pfd.iPixelType = PFD_TYPE_RGBA;
350 pfd.cColorBits = 32;
351 pfd.iLayerType = PFD_MAIN_PLANE;
353 if (!(iPixelFormat = ChoosePixelFormat(ctx->dc, &pfd)))
355 /* If this happens something is very wrong as ChoosePixelFormat barely fails. */
356 ERR("Failed to find a suitable pixel format.\n");
357 goto fail;
359 DescribePixelFormat(ctx->dc, iPixelFormat, sizeof(pfd), &pfd);
360 SetPixelFormat(ctx->dc, iPixelFormat, &pfd);
362 /* Create a GL context. */
363 if (!(ctx->gl_ctx = wglCreateContext(ctx->dc)))
365 WARN("Failed to create default context for capabilities initialization.\n");
366 goto fail;
369 /* Make it the current GL context. */
370 if (!wglMakeCurrent(ctx->dc, ctx->gl_ctx))
372 ERR("Failed to make caps GL context current.\n");
373 goto fail;
376 ctx->gl_info = &adapter->gl_info;
377 return TRUE;
379 fail:
380 if (ctx->gl_ctx) wglDeleteContext(ctx->gl_ctx);
381 ctx->gl_ctx = NULL;
382 if (ctx->dc) ReleaseDC(ctx->wnd, ctx->dc);
383 ctx->dc = NULL;
384 if (ctx->wnd) DestroyWindow(ctx->wnd);
385 ctx->wnd = NULL;
386 if (ctx->restore_gl_ctx && !wglMakeCurrent(ctx->restore_dc, ctx->restore_gl_ctx))
387 ERR("Failed to restore previous GL context.\n");
389 return FALSE;
392 /* Adjust the amount of used texture memory */
393 UINT64 adapter_adjust_memory(struct wined3d_adapter *adapter, INT64 amount)
395 adapter->vram_bytes_used += amount;
396 TRACE("Adjusted used adapter memory by 0x%s to 0x%s.\n",
397 wine_dbgstr_longlong(amount),
398 wine_dbgstr_longlong(adapter->vram_bytes_used));
399 return adapter->vram_bytes_used;
402 static void wined3d_adapter_cleanup(struct wined3d_adapter *adapter)
404 HeapFree(GetProcessHeap(), 0, adapter->gl_info.formats);
405 HeapFree(GetProcessHeap(), 0, adapter->cfgs);
408 ULONG CDECL wined3d_incref(struct wined3d *wined3d)
410 ULONG refcount = InterlockedIncrement(&wined3d->ref);
412 TRACE("%p increasing refcount to %u.\n", wined3d, refcount);
414 return refcount;
417 ULONG CDECL wined3d_decref(struct wined3d *wined3d)
419 ULONG refcount = InterlockedDecrement(&wined3d->ref);
421 TRACE("%p decreasing refcount to %u.\n", wined3d, refcount);
423 if (!refcount)
425 unsigned int i;
427 for (i = 0; i < wined3d->adapter_count; ++i)
429 wined3d_adapter_cleanup(&wined3d->adapters[i]);
431 HeapFree(GetProcessHeap(), 0, wined3d);
434 return refcount;
437 /* Context activation is done by the caller. */
438 static BOOL test_arb_vs_offset_limit(const struct wined3d_gl_info *gl_info)
440 GLuint prog;
441 BOOL ret = FALSE;
442 static const char testcode[] =
443 "!!ARBvp1.0\n"
444 "PARAM C[66] = { program.env[0..65] };\n"
445 "ADDRESS A0;"
446 "PARAM zero = {0.0, 0.0, 0.0, 0.0};\n"
447 "ARL A0.x, zero.x;\n"
448 "MOV result.position, C[A0.x + 65];\n"
449 "END\n";
451 while (gl_info->gl_ops.gl.p_glGetError());
452 GL_EXTCALL(glGenProgramsARB(1, &prog));
453 if(!prog) {
454 ERR("Failed to create an ARB offset limit test program\n");
456 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prog));
457 GL_EXTCALL(glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
458 strlen(testcode), testcode));
459 if (gl_info->gl_ops.gl.p_glGetError())
461 TRACE("OpenGL implementation does not allow indirect addressing offsets > 63\n");
462 TRACE("error: %s\n", debugstr_a((const char *)gl_info->gl_ops.gl.p_glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
463 ret = TRUE;
464 } else TRACE("OpenGL implementation allows offsets > 63\n");
466 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, 0));
467 GL_EXTCALL(glDeleteProgramsARB(1, &prog));
468 checkGLcall("ARB vp offset limit test cleanup");
470 return ret;
473 static BOOL match_amd_r300_to_500(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
474 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
476 if (card_vendor != HW_VENDOR_AMD) return FALSE;
477 if (device == CARD_AMD_RADEON_9500) return TRUE;
478 if (device == CARD_AMD_RADEON_X700) return TRUE;
479 if (device == CARD_AMD_RADEON_X1600) return TRUE;
480 return FALSE;
483 static BOOL match_geforce5(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
484 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
486 if (card_vendor == HW_VENDOR_NVIDIA)
488 if (device == CARD_NVIDIA_GEFORCEFX_5200 ||
489 device == CARD_NVIDIA_GEFORCEFX_5600 ||
490 device == CARD_NVIDIA_GEFORCEFX_5800)
492 return TRUE;
495 return FALSE;
498 static BOOL match_apple(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
499 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
501 /* MacOS has various specialities in the extensions it advertises. Some have to be loaded from
502 * the opengl 1.2+ core, while other extensions are advertised, but software emulated. So try to
503 * detect the Apple OpenGL implementation to apply some extension fixups afterwards.
505 * Detecting this isn't really easy. The vendor string doesn't mention Apple. Compile-time checks
506 * aren't sufficient either because a Linux binary may display on a macos X server via remote X11.
507 * So try to detect the GL implementation by looking at certain Apple extensions. Some extensions
508 * like client storage might be supported on other implementations too, but GL_APPLE_flush_render
509 * is specific to the Mac OS X window management, and GL_APPLE_ycbcr_422 is QuickTime specific. So
510 * the chance that other implementations support them is rather small since Win32 QuickTime uses
511 * DirectDraw, not OpenGL.
513 * This test has been moved into wined3d_guess_gl_vendor()
515 if (gl_vendor == GL_VENDOR_APPLE)
517 return TRUE;
519 return FALSE;
522 /* Context activation is done by the caller. */
523 static void test_pbo_functionality(struct wined3d_gl_info *gl_info)
525 /* Some OpenGL implementations, namely Apple's Geforce 8 driver, advertises PBOs,
526 * but glTexSubImage from a PBO fails miserably, with the first line repeated over
527 * all the texture. This function detects this bug by its symptom and disables PBOs
528 * if the test fails.
530 * The test uploads a 4x4 texture via the PBO in the "native" format GL_BGRA,
531 * GL_UNSIGNED_INT_8_8_8_8_REV. This format triggers the bug, and it is what we use
532 * for D3DFMT_A8R8G8B8. Then the texture is read back without any PBO and the data
533 * read back is compared to the original. If they are equal PBOs are assumed to work,
534 * otherwise the PBO extension is disabled. */
535 GLuint texture, pbo;
536 static const unsigned int pattern[] =
538 0x00000000, 0x000000ff, 0x0000ff00, 0x40ff0000,
539 0x80ffffff, 0x40ffff00, 0x00ff00ff, 0x0000ffff,
540 0x00ffff00, 0x00ff00ff, 0x0000ffff, 0x000000ff,
541 0x80ff00ff, 0x0000ffff, 0x00ff00ff, 0x40ff00ff
543 unsigned int check[sizeof(pattern) / sizeof(pattern[0])];
545 /* No PBO -> No point in testing them. */
546 if (!gl_info->supported[ARB_PIXEL_BUFFER_OBJECT]) return;
548 while (gl_info->gl_ops.gl.p_glGetError());
549 gl_info->gl_ops.gl.p_glGenTextures(1, &texture);
550 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, texture);
552 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
553 gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
554 checkGLcall("Specifying the PBO test texture");
556 GL_EXTCALL(glGenBuffers(1, &pbo));
557 GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo));
558 GL_EXTCALL(glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(pattern), pattern, GL_STREAM_DRAW));
559 checkGLcall("Specifying the PBO test pbo");
561 gl_info->gl_ops.gl.p_glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
562 checkGLcall("Loading the PBO test texture");
564 GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0));
566 gl_info->gl_ops.gl.p_glFinish(); /* just to be sure */
568 memset(check, 0, sizeof(check));
569 gl_info->gl_ops.gl.p_glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, check);
570 checkGLcall("Reading back the PBO test texture");
572 gl_info->gl_ops.gl.p_glDeleteTextures(1, &texture);
573 GL_EXTCALL(glDeleteBuffers(1, &pbo));
574 checkGLcall("PBO test cleanup");
576 if (memcmp(check, pattern, sizeof(check)))
578 WARN_(d3d_perf)("PBO test failed, read back data doesn't match original.\n"
579 "Disabling PBOs. This may result in slower performance.\n");
580 gl_info->supported[ARB_PIXEL_BUFFER_OBJECT] = FALSE;
582 else
584 TRACE("PBO test successful.\n");
588 static BOOL match_apple_intel(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
589 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
591 return (card_vendor == HW_VENDOR_INTEL) && (gl_vendor == GL_VENDOR_APPLE);
594 static BOOL match_apple_nonr500ati(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
595 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
597 if (gl_vendor != GL_VENDOR_APPLE) return FALSE;
598 if (card_vendor != HW_VENDOR_AMD) return FALSE;
599 if (device == CARD_AMD_RADEON_X1600) return FALSE;
600 return TRUE;
603 static BOOL match_dx10_capable(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
604 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
606 /* DX9 cards support 40 single float varyings in hardware, most drivers report 32. ATI misreports
607 * 44 varyings. So assume that if we have more than 44 varyings we have a dx10 card.
608 * This detection is for the gl_ClipPos varying quirk. If a d3d9 card really supports more than 44
609 * varyings and we subtract one in dx9 shaders it's not going to hurt us because the dx9 limit is
610 * hardcoded
612 * dx10 cards usually have 64 varyings */
613 return gl_info->limits.glsl_varyings > 44;
616 static BOOL match_not_dx10_capable(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
617 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
619 return !match_dx10_capable(gl_info, gl_renderer, gl_vendor, card_vendor, device);
622 /* A GL context is provided by the caller */
623 static BOOL match_allows_spec_alpha(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
624 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
626 GLenum error;
627 DWORD data[16];
629 if (!gl_info->supported[EXT_SECONDARY_COLOR])
630 return FALSE;
632 while (gl_info->gl_ops.gl.p_glGetError());
633 GL_EXTCALL(glSecondaryColorPointerEXT)(4, GL_UNSIGNED_BYTE, 4, data);
634 error = gl_info->gl_ops.gl.p_glGetError();
636 if (error == GL_NO_ERROR)
638 TRACE("GL Implementation accepts 4 component specular color pointers\n");
639 return TRUE;
641 else
643 TRACE("GL implementation does not accept 4 component specular colors, error %s\n",
644 debug_glerror(error));
645 return FALSE;
649 /* A GL context is provided by the caller */
650 static BOOL match_broken_nv_clip(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
651 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
653 GLuint prog;
654 BOOL ret = FALSE;
655 GLint pos;
656 static const char testcode[] =
657 "!!ARBvp1.0\n"
658 "OPTION NV_vertex_program2;\n"
659 "MOV result.clip[0], 0.0;\n"
660 "MOV result.position, 0.0;\n"
661 "END\n";
663 if (!gl_info->supported[NV_VERTEX_PROGRAM2_OPTION]) return FALSE;
665 while (gl_info->gl_ops.gl.p_glGetError());
667 GL_EXTCALL(glGenProgramsARB(1, &prog));
668 if(!prog)
670 ERR("Failed to create the NVvp clip test program\n");
671 return FALSE;
673 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prog));
674 GL_EXTCALL(glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
675 strlen(testcode), testcode));
676 gl_info->gl_ops.gl.p_glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
677 if(pos != -1)
679 WARN("GL_NV_vertex_program2_option result.clip[] test failed\n");
680 TRACE("error: %s\n", debugstr_a((const char *)gl_info->gl_ops.gl.p_glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
681 ret = TRUE;
682 while (gl_info->gl_ops.gl.p_glGetError());
684 else TRACE("GL_NV_vertex_program2_option result.clip[] test passed\n");
686 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, 0));
687 GL_EXTCALL(glDeleteProgramsARB(1, &prog));
688 checkGLcall("GL_NV_vertex_program2_option result.clip[] test cleanup");
690 return ret;
693 /* Context activation is done by the caller. */
694 static BOOL match_fbo_tex_update(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
695 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
697 char data[4 * 4 * 4];
698 GLuint tex, fbo;
699 GLenum status;
701 if (wined3d_settings.offscreen_rendering_mode != ORM_FBO) return FALSE;
703 memset(data, 0xcc, sizeof(data));
705 gl_info->gl_ops.gl.p_glGenTextures(1, &tex);
706 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, tex);
707 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
708 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
709 gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
710 checkGLcall("glTexImage2D");
712 gl_info->fbo_ops.glGenFramebuffers(1, &fbo);
713 gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
714 gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
715 checkGLcall("glFramebufferTexture2D");
717 status = gl_info->fbo_ops.glCheckFramebufferStatus(GL_FRAMEBUFFER);
718 if (status != GL_FRAMEBUFFER_COMPLETE) ERR("FBO status %#x\n", status);
719 checkGLcall("glCheckFramebufferStatus");
721 memset(data, 0x11, sizeof(data));
722 gl_info->gl_ops.gl.p_glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, data);
723 checkGLcall("glTexSubImage2D");
725 gl_info->gl_ops.gl.p_glClearColor(0.996f, 0.729f, 0.745f, 0.792f);
726 gl_info->gl_ops.gl.p_glClear(GL_COLOR_BUFFER_BIT);
727 checkGLcall("glClear");
729 gl_info->gl_ops.gl.p_glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, data);
730 checkGLcall("glGetTexImage");
732 gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
733 gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, 0);
734 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, 0);
735 checkGLcall("glBindTexture");
737 gl_info->fbo_ops.glDeleteFramebuffers(1, &fbo);
738 gl_info->gl_ops.gl.p_glDeleteTextures(1, &tex);
739 checkGLcall("glDeleteTextures");
741 return *(DWORD *)data == 0x11111111;
744 /* Context activation is done by the caller. */
745 static BOOL match_broken_rgba16(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
746 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
748 /* GL_RGBA16 uses GL_RGBA8 internally on Geforce 7 and older cards.
749 * This leads to graphical bugs in Half Life 2 and Unreal engine games. */
750 GLuint tex;
751 GLint size;
753 gl_info->gl_ops.gl.p_glGenTextures(1, &tex);
754 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, tex);
755 gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT, NULL);
756 checkGLcall("glTexImage2D");
758 gl_info->gl_ops.gl.p_glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_RED_SIZE, &size);
759 checkGLcall("glGetTexLevelParameteriv");
760 TRACE("Real color depth is %d\n", size);
762 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, 0);
763 checkGLcall("glBindTexture");
764 gl_info->gl_ops.gl.p_glDeleteTextures(1, &tex);
765 checkGLcall("glDeleteTextures");
767 return size < 16;
770 static BOOL match_fglrx(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
771 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
773 return gl_vendor == GL_VENDOR_FGLRX;
776 static BOOL match_r200(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
777 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
779 if (card_vendor != HW_VENDOR_AMD) return FALSE;
780 if (device == CARD_AMD_RADEON_8500) return TRUE;
781 return FALSE;
784 static BOOL match_broken_arb_fog(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
785 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
787 DWORD data[4];
788 GLuint tex, fbo;
789 GLenum status;
790 float color[4] = {0.0f, 1.0f, 0.0f, 0.0f};
791 GLuint prog;
792 GLint err_pos;
793 static const char program_code[] =
794 "!!ARBfp1.0\n"
795 "OPTION ARB_fog_linear;\n"
796 "MOV result.color, {1.0, 0.0, 0.0, 0.0};\n"
797 "END\n";
799 if (wined3d_settings.offscreen_rendering_mode != ORM_FBO)
800 return FALSE;
801 if (!gl_info->supported[ARB_FRAGMENT_PROGRAM])
802 return FALSE;
804 gl_info->gl_ops.gl.p_glGenTextures(1, &tex);
805 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, tex);
806 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
807 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
808 gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 4, 1, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
809 checkGLcall("glTexImage2D");
811 gl_info->fbo_ops.glGenFramebuffers(1, &fbo);
812 gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
813 gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
814 checkGLcall("glFramebufferTexture2D");
816 status = gl_info->fbo_ops.glCheckFramebufferStatus(GL_FRAMEBUFFER);
817 if (status != GL_FRAMEBUFFER_COMPLETE) ERR("FBO status %#x\n", status);
818 checkGLcall("glCheckFramebufferStatus");
820 gl_info->gl_ops.gl.p_glClearColor(0.0f, 0.0f, 1.0f, 0.0f);
821 gl_info->gl_ops.gl.p_glClear(GL_COLOR_BUFFER_BIT);
822 checkGLcall("glClear");
823 gl_info->gl_ops.gl.p_glViewport(0, 0, 4, 1);
824 checkGLcall("glViewport");
826 gl_info->gl_ops.gl.p_glEnable(GL_FOG);
827 gl_info->gl_ops.gl.p_glFogf(GL_FOG_START, 0.5f);
828 gl_info->gl_ops.gl.p_glFogf(GL_FOG_END, 0.5f);
829 gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_LINEAR);
830 gl_info->gl_ops.gl.p_glHint(GL_FOG_HINT, GL_NICEST);
831 gl_info->gl_ops.gl.p_glFogfv(GL_FOG_COLOR, color);
832 checkGLcall("fog setup");
834 GL_EXTCALL(glGenProgramsARB(1, &prog));
835 GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, prog));
836 GL_EXTCALL(glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
837 strlen(program_code), program_code));
838 gl_info->gl_ops.gl.p_glEnable(GL_FRAGMENT_PROGRAM_ARB);
839 checkGLcall("Test fragment program setup");
841 gl_info->gl_ops.gl.p_glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &err_pos);
842 if (err_pos != -1)
844 const char *error_str;
845 error_str = (const char *)gl_info->gl_ops.gl.p_glGetString(GL_PROGRAM_ERROR_STRING_ARB);
846 FIXME("Fog test program error at position %d: %s\n\n", err_pos, debugstr_a(error_str));
849 gl_info->gl_ops.gl.p_glBegin(GL_TRIANGLE_STRIP);
850 gl_info->gl_ops.gl.p_glVertex3f(-1.0f, -1.0f, 0.0f);
851 gl_info->gl_ops.gl.p_glVertex3f( 1.0f, -1.0f, 1.0f);
852 gl_info->gl_ops.gl.p_glVertex3f(-1.0f, 1.0f, 0.0f);
853 gl_info->gl_ops.gl.p_glVertex3f( 1.0f, 1.0f, 1.0f);
854 gl_info->gl_ops.gl.p_glEnd();
855 checkGLcall("ARBfp fog test draw");
857 gl_info->gl_ops.gl.p_glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, data);
858 checkGLcall("glGetTexImage");
859 data[0] &= 0x00ffffff;
860 data[1] &= 0x00ffffff;
861 data[2] &= 0x00ffffff;
862 data[3] &= 0x00ffffff;
864 gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, 0);
865 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, 0);
867 gl_info->fbo_ops.glDeleteFramebuffers(1, &fbo);
868 gl_info->gl_ops.gl.p_glDeleteTextures(1, &tex);
869 gl_info->gl_ops.gl.p_glDisable(GL_FOG);
870 GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, 0));
871 gl_info->gl_ops.gl.p_glDisable(GL_FRAGMENT_PROGRAM_ARB);
872 GL_EXTCALL(glDeleteProgramsARB(1, &prog));
873 checkGLcall("ARBfp fog test teardown");
875 TRACE("Fog test data: %08x %08x %08x %08x\n", data[0], data[1], data[2], data[3]);
876 return data[0] != 0x00ff0000 || data[3] != 0x0000ff00;
879 static void quirk_apple_glsl_constants(struct wined3d_gl_info *gl_info)
881 /* MacOS needs uniforms for relative addressing offsets. This can accumulate to quite a few uniforms.
882 * Beyond that the general uniform isn't optimal, so reserve a number of uniforms. 12 vec4's should
883 * allow 48 different offsets or other helper immediate values. */
884 TRACE("Reserving 12 GLSL constants for compiler private use.\n");
885 gl_info->reserved_glsl_constants = max(gl_info->reserved_glsl_constants, 12);
888 static void quirk_amd_dx9(struct wined3d_gl_info *gl_info)
890 /* MacOS advertises GL_ARB_texture_non_power_of_two on ATI r500 and earlier cards, although
891 * these cards only support GL_ARB_texture_rectangle(D3DPTEXTURECAPS_NONPOW2CONDITIONAL).
892 * If real NP2 textures are used, the driver falls back to software. We could just remove the
893 * extension and use GL_ARB_texture_rectangle instead, but texture_rectangle is inconvenient
894 * due to the non-normalized texture coordinates. Thus set an internal extension flag,
895 * GL_WINE_normalized_texrect, which signals the code that it can use non power of two textures
896 * as per GL_ARB_texture_non_power_of_two, but has to stick to the texture_rectangle limits.
898 * fglrx doesn't advertise GL_ARB_texture_non_power_of_two, but it advertises opengl 2.0 which
899 * has this extension promoted to core. The extension loading code sets this extension supported
900 * due to that, so this code works on fglrx as well. */
901 if(gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
903 TRACE("GL_ARB_texture_non_power_of_two advertised on R500 or earlier card, removing.\n");
904 gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] = FALSE;
905 gl_info->supported[WINED3D_GL_NORMALIZED_TEXRECT] = TRUE;
909 static void quirk_no_np2(struct wined3d_gl_info *gl_info)
911 /* The nVidia GeForceFX series reports OpenGL 2.0 capabilities with the latest drivers versions, but
912 * doesn't explicitly advertise the ARB_tex_npot extension in the GL extension string.
913 * This usually means that ARB_tex_npot is supported in hardware as long as the application is staying
914 * within the limits enforced by the ARB_texture_rectangle extension. This however is not true for the
915 * FX series, which instantly falls back to a slower software path as soon as ARB_tex_npot is used.
916 * We therefore completely remove ARB_tex_npot from the list of supported extensions.
918 * Note that wine_normalized_texrect can't be used in this case because internally it uses ARB_tex_npot,
919 * triggering the software fallback. There is not much we can do here apart from disabling the
920 * software-emulated extension and re-enable ARB_tex_rect (which was previously disabled
921 * in wined3d_adapter_init_gl_caps).
922 * This fixup removes performance problems on both the FX 5900 and FX 5700 (e.g. for framebuffer
923 * post-processing effects in the game "Max Payne 2").
924 * The behaviour can be verified through a simple test app attached in bugreport #14724. */
925 TRACE("GL_ARB_texture_non_power_of_two advertised through OpenGL 2.0 on NV FX card, removing.\n");
926 gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] = FALSE;
927 gl_info->supported[ARB_TEXTURE_RECTANGLE] = TRUE;
930 static void quirk_texcoord_w(struct wined3d_gl_info *gl_info)
932 /* The Intel GPUs on MacOS set the .w register of texcoords to 0.0 by default, which causes problems
933 * with fixed function fragment processing. Ideally this flag should be detected with a test shader
934 * and OpenGL feedback mode, but some GL implementations (MacOS ATI at least, probably all MacOS ones)
935 * do not like vertex shaders in feedback mode and return an error, even though it should be valid
936 * according to the spec.
938 * We don't want to enable this on all cards, as it adds an extra instruction per texcoord used. This
939 * makes the shader slower and eats instruction slots which should be available to the d3d app.
941 * ATI Radeon HD 2xxx cards on MacOS have the issue. Instead of checking for the buggy cards, blacklist
942 * all radeon cards on Macs and whitelist the good ones. That way we're prepared for the future. If
943 * this workaround is activated on cards that do not need it, it won't break things, just affect
944 * performance negatively. */
945 TRACE("Enabling vertex texture coord fixes in vertex shaders.\n");
946 gl_info->quirks |= WINED3D_QUIRK_SET_TEXCOORD_W;
949 static void quirk_clip_varying(struct wined3d_gl_info *gl_info)
951 gl_info->quirks |= WINED3D_QUIRK_GLSL_CLIP_VARYING;
954 static void quirk_allows_specular_alpha(struct wined3d_gl_info *gl_info)
956 gl_info->quirks |= WINED3D_QUIRK_ALLOWS_SPECULAR_ALPHA;
959 static void quirk_disable_nvvp_clip(struct wined3d_gl_info *gl_info)
961 gl_info->quirks |= WINED3D_QUIRK_NV_CLIP_BROKEN;
964 static void quirk_fbo_tex_update(struct wined3d_gl_info *gl_info)
966 gl_info->quirks |= WINED3D_QUIRK_FBO_TEX_UPDATE;
969 static void quirk_broken_rgba16(struct wined3d_gl_info *gl_info)
971 gl_info->quirks |= WINED3D_QUIRK_BROKEN_RGBA16;
974 static void quirk_infolog_spam(struct wined3d_gl_info *gl_info)
976 gl_info->quirks |= WINED3D_QUIRK_INFO_LOG_SPAM;
979 static void quirk_limited_tex_filtering(struct wined3d_gl_info *gl_info)
981 /* Nvidia GeForce 6xxx and 7xxx support accelerated VTF only on a few
982 selected texture formats. They are apparently the only DX9 class GPUs
983 supporting VTF.
984 Also, DX9-era GPUs are somewhat limited with float textures
985 filtering and blending. */
986 gl_info->quirks |= WINED3D_QUIRK_LIMITED_TEX_FILTERING;
989 static void quirk_r200_constants(struct wined3d_gl_info *gl_info)
991 /* The Mesa r200 driver (and there is no other driver for this GPU Wine would run on)
992 * loads some fog parameters (start, end, exponent, but not the color) into the
993 * program.
995 * Apparently the fog hardware is only able to handle linear fog with a range of 0.0;1.0,
996 * and it is the responsibility of the vertex pipeline to handle non-linear fog and
997 * linear fog with start and end other than 0.0 and 1.0. */
998 TRACE("Reserving 1 ARB constant for compiler private use.\n");
999 gl_info->reserved_arb_constants = max(gl_info->reserved_arb_constants, 1);
1002 static void quirk_broken_arb_fog(struct wined3d_gl_info *gl_info)
1004 gl_info->quirks |= WINED3D_QUIRK_BROKEN_ARB_FOG;
1007 struct driver_quirk
1009 BOOL (*match)(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
1010 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device);
1011 void (*apply)(struct wined3d_gl_info *gl_info);
1012 const char *description;
1015 static const struct driver_quirk quirk_table[] =
1018 match_amd_r300_to_500,
1019 quirk_amd_dx9,
1020 "AMD normalized texrect quirk"
1023 match_apple,
1024 quirk_apple_glsl_constants,
1025 "Apple GLSL uniform override"
1028 match_geforce5,
1029 quirk_no_np2,
1030 "Geforce 5 NP2 disable"
1033 match_apple_intel,
1034 quirk_texcoord_w,
1035 "Init texcoord .w for Apple Intel GPU driver"
1038 match_apple_nonr500ati,
1039 quirk_texcoord_w,
1040 "Init texcoord .w for Apple ATI >= r600 GPU driver"
1043 match_dx10_capable,
1044 quirk_clip_varying,
1045 "Reserved varying for gl_ClipPos"
1048 /* GL_EXT_secondary_color does not allow 4 component secondary colors, but most
1049 * GL implementations accept it. The Mac GL is the only implementation known to
1050 * reject it.
1052 * If we can pass 4 component specular colors, do it, because (a) we don't have
1053 * to screw around with the data, and (b) the D3D fixed function vertex pipeline
1054 * passes specular alpha to the pixel shader if any is used. Otherwise the
1055 * specular alpha is used to pass the fog coordinate, which we pass to opengl
1056 * via GL_EXT_fog_coord.
1058 match_allows_spec_alpha,
1059 quirk_allows_specular_alpha,
1060 "Allow specular alpha quirk"
1063 match_broken_nv_clip,
1064 quirk_disable_nvvp_clip,
1065 "Apple NV_vertex_program clip bug quirk"
1068 match_fbo_tex_update,
1069 quirk_fbo_tex_update,
1070 "FBO rebind for attachment updates"
1073 match_broken_rgba16,
1074 quirk_broken_rgba16,
1075 "True RGBA16 is not available"
1078 match_fglrx,
1079 quirk_infolog_spam,
1080 "Not printing GLSL infolog"
1083 match_not_dx10_capable,
1084 quirk_limited_tex_filtering,
1085 "Texture filtering, blending and VTF support is limited"
1088 match_r200,
1089 quirk_r200_constants,
1090 "r200 vertex shader constants"
1093 match_broken_arb_fog,
1094 quirk_broken_arb_fog,
1095 "ARBfp fogstart == fogend workaround"
1099 /* Certain applications (Steam) complain if we report an outdated driver version. In general,
1100 * reporting a driver version is moot because we are not the Windows driver, and we have different
1101 * bugs, features, etc.
1103 * The driver version has the form "x.y.z.w".
1105 * "x" is the Windows version the driver is meant for:
1106 * 4 -> 95/98/NT4
1107 * 5 -> 2000
1108 * 6 -> 2000/XP
1109 * 7 -> Vista
1110 * 8 -> Win 7
1112 * "y" is the maximum Direct3D version the driver supports.
1113 * y -> d3d version mapping:
1114 * 11 -> d3d6
1115 * 12 -> d3d7
1116 * 13 -> d3d8
1117 * 14 -> d3d9
1118 * 15 -> d3d10
1119 * 16 -> d3d10.1
1120 * 17 -> d3d11
1122 * "z" is the subversion number.
1124 * "w" is the vendor specific driver build number.
1127 struct driver_version_information
1129 enum wined3d_display_driver driver;
1130 enum wined3d_driver_model driver_model;
1131 const char *driver_name; /* name of Windows driver */
1132 WORD version; /* version word ('y'), contained in low word of DriverVersion.HighPart */
1133 WORD subversion; /* subversion word ('z'), contained in high word of DriverVersion.LowPart */
1134 WORD build; /* build number ('w'), contained in low word of DriverVersion.LowPart */
1137 /* The driver version table contains driver information for different devices on several OS versions. */
1138 static const struct driver_version_information driver_version_table[] =
1140 /* AMD
1141 * - Radeon HD2x00 (R600) and up supported by current drivers.
1142 * - Radeon 9500 (R300) - X1*00 (R5xx) supported up to Catalyst 9.3 (Linux) and 10.2 (XP/Vista/Win7)
1143 * - Radeon 7xxx (R100) - 9250 (RV250) supported up to Catalyst 6.11 (XP)
1144 * - Rage 128 supported up to XP, latest official build 6.13.3279 dated October 2001 */
1145 {DRIVER_AMD_RAGE_128PRO, DRIVER_MODEL_NT5X, "ati2dvaa.dll", 13, 3279, 0},
1146 {DRIVER_AMD_R100, DRIVER_MODEL_NT5X, "ati2dvag.dll", 14, 10, 6614},
1147 {DRIVER_AMD_R300, DRIVER_MODEL_NT5X, "ati2dvag.dll", 14, 10, 6764},
1148 {DRIVER_AMD_R600, DRIVER_MODEL_NT5X, "ati2dvag.dll", 17, 10, 1280},
1149 {DRIVER_AMD_R300, DRIVER_MODEL_NT6X, "atiumdag.dll", 14, 10, 741 },
1150 {DRIVER_AMD_R600, DRIVER_MODEL_NT6X, "atiumdag.dll", 17, 10, 1280 },
1152 /* Intel
1153 * The drivers are unified but not all versions support all GPUs. At some point the 2k/xp
1154 * drivers used ialmrnt5.dll for GMA800/GMA900 but at some point the file was renamed to
1155 * igxprd32.dll but the GMA800 driver was never updated. */
1156 {DRIVER_INTEL_GMA800, DRIVER_MODEL_NT5X, "ialmrnt5.dll", 14, 10, 3889},
1157 {DRIVER_INTEL_GMA900, DRIVER_MODEL_NT5X, "igxprd32.dll", 14, 10, 4764},
1158 {DRIVER_INTEL_GMA950, DRIVER_MODEL_NT5X, "igxprd32.dll", 14, 10, 4926},
1159 {DRIVER_INTEL_GMA3000, DRIVER_MODEL_NT5X, "igxprd32.dll", 14, 10, 5218},
1160 {DRIVER_INTEL_GMA950, DRIVER_MODEL_NT6X, "igdumd32.dll", 14, 10, 1504},
1161 {DRIVER_INTEL_GMA3000, DRIVER_MODEL_NT6X, "igdumd32.dll", 15, 10, 1666},
1163 /* Nvidia
1164 * - Geforce8 and newer is supported by the current 340.52 driver on XP-Win8
1165 * - Geforce6 and 7 support is up to 307.83 on XP-Win8
1166 * - GeforceFX support is up to 173.x on <= XP
1167 * - Geforce2MX/3/4 up to 96.x on <= XP
1168 * - TNT/Geforce1/2 up to 71.x on <= XP
1169 * All version numbers used below are from the Linux nvidia drivers. */
1170 {DRIVER_NVIDIA_TNT, DRIVER_MODEL_NT5X, "nv4_disp.dll", 14, 10, 7186},
1171 {DRIVER_NVIDIA_GEFORCE2MX, DRIVER_MODEL_NT5X, "nv4_disp.dll", 14, 10, 9371},
1172 {DRIVER_NVIDIA_GEFORCEFX, DRIVER_MODEL_NT5X, "nv4_disp.dll", 14, 11, 7516},
1173 {DRIVER_NVIDIA_GEFORCE6, DRIVER_MODEL_NT5X, "nv4_disp.dll", 18, 13, 783},
1174 {DRIVER_NVIDIA_GEFORCE8, DRIVER_MODEL_NT5X, "nv4_disp.dll", 18, 13, 4052},
1175 {DRIVER_NVIDIA_GEFORCE6, DRIVER_MODEL_NT6X, "nvd3dum.dll", 18, 13, 783},
1176 {DRIVER_NVIDIA_GEFORCE8, DRIVER_MODEL_NT6X, "nvd3dum.dll", 18, 13, 4052},
1178 /* VMware */
1179 {DRIVER_VMWARE, DRIVER_MODEL_NT5X, "vm3dum.dll", 14, 1, 1134},
1182 struct gpu_description
1184 WORD vendor; /* reported PCI card vendor ID */
1185 WORD card; /* reported PCI card device ID */
1186 const char *description; /* Description of the card e.g. NVIDIA RIVA TNT */
1187 enum wined3d_display_driver driver;
1188 unsigned int vidmem;
1191 /* The amount of video memory stored in the gpu description table is the minimum amount of video memory
1192 * found on a board containing a specific GPU. */
1193 static const struct gpu_description gpu_description_table[] =
1195 /* Nvidia cards */
1196 {HW_VENDOR_NVIDIA, CARD_NVIDIA_RIVA_128, "NVIDIA RIVA 128", DRIVER_NVIDIA_TNT, 4 },
1197 {HW_VENDOR_NVIDIA, CARD_NVIDIA_RIVA_TNT, "NVIDIA RIVA TNT", DRIVER_NVIDIA_TNT, 16 },
1198 {HW_VENDOR_NVIDIA, CARD_NVIDIA_RIVA_TNT2, "NVIDIA RIVA TNT2/TNT2 Pro", DRIVER_NVIDIA_TNT, 32 },
1199 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE, "NVIDIA GeForce 256", DRIVER_NVIDIA_TNT, 32 },
1200 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE2, "NVIDIA GeForce2 GTS/GeForce2 Pro", DRIVER_NVIDIA_TNT, 32 },
1201 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE2_MX, "NVIDIA GeForce2 MX/MX 400", DRIVER_NVIDIA_GEFORCE2MX,32 },
1202 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE3, "NVIDIA GeForce3", DRIVER_NVIDIA_GEFORCE2MX,64 },
1203 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE4_MX, "NVIDIA GeForce4 MX 460", DRIVER_NVIDIA_GEFORCE2MX,64 },
1204 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE4_TI4200, "NVIDIA GeForce4 Ti 4200", DRIVER_NVIDIA_GEFORCE2MX,64, },
1205 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5200, "NVIDIA GeForce FX 5200", DRIVER_NVIDIA_GEFORCEFX, 64 },
1206 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5600, "NVIDIA GeForce FX 5600", DRIVER_NVIDIA_GEFORCEFX, 128 },
1207 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5800, "NVIDIA GeForce FX 5800", DRIVER_NVIDIA_GEFORCEFX, 256 },
1208 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6200, "NVIDIA GeForce 6200", DRIVER_NVIDIA_GEFORCE6, 64 },
1209 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6600GT, "NVIDIA GeForce 6600 GT", DRIVER_NVIDIA_GEFORCE6, 128 },
1210 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6800, "NVIDIA GeForce 6800", DRIVER_NVIDIA_GEFORCE6, 128 },
1211 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7300, "NVIDIA GeForce Go 7300", DRIVER_NVIDIA_GEFORCE6, 256 },
1212 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7400, "NVIDIA GeForce Go 7400", DRIVER_NVIDIA_GEFORCE6, 256 },
1213 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7600, "NVIDIA GeForce 7600 GT", DRIVER_NVIDIA_GEFORCE6, 256 },
1214 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7800GT, "NVIDIA GeForce 7800 GT", DRIVER_NVIDIA_GEFORCE6, 256 },
1215 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8200, "NVIDIA GeForce 8200", DRIVER_NVIDIA_GEFORCE8, 512 },
1216 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8300GS, "NVIDIA GeForce 8300 GS", DRIVER_NVIDIA_GEFORCE8, 128 },
1217 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8400GS, "NVIDIA GeForce 8400 GS", DRIVER_NVIDIA_GEFORCE8, 128 },
1218 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8500GT, "NVIDIA GeForce 8500 GT", DRIVER_NVIDIA_GEFORCE8, 256 },
1219 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8600GT, "NVIDIA GeForce 8600 GT", DRIVER_NVIDIA_GEFORCE8, 256 },
1220 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8600MGT, "NVIDIA GeForce 8600M GT", DRIVER_NVIDIA_GEFORCE8, 512 },
1221 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8800GTS, "NVIDIA GeForce 8800 GTS", DRIVER_NVIDIA_GEFORCE8, 320 },
1222 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8800GTX, "NVIDIA GeForce 8800 GTX", DRIVER_NVIDIA_GEFORCE8, 768 },
1223 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9200, "NVIDIA GeForce 9200", DRIVER_NVIDIA_GEFORCE8, 256 },
1224 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9300, "NVIDIA GeForce 9300", DRIVER_NVIDIA_GEFORCE8, 256 },
1225 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9400M, "NVIDIA GeForce 9400M", DRIVER_NVIDIA_GEFORCE8, 256 },
1226 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9400GT, "NVIDIA GeForce 9400 GT", DRIVER_NVIDIA_GEFORCE8, 256 },
1227 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9500GT, "NVIDIA GeForce 9500 GT", DRIVER_NVIDIA_GEFORCE8, 256 },
1228 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9600GT, "NVIDIA GeForce 9600 GT", DRIVER_NVIDIA_GEFORCE8, 384 },
1229 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9800GT, "NVIDIA GeForce 9800 GT", DRIVER_NVIDIA_GEFORCE8, 512 },
1230 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_210, "NVIDIA GeForce 210", DRIVER_NVIDIA_GEFORCE8, 512 },
1231 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT220, "NVIDIA GeForce GT 220", DRIVER_NVIDIA_GEFORCE8, 512 },
1232 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT240, "NVIDIA GeForce GT 240", DRIVER_NVIDIA_GEFORCE8, 512 },
1233 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX260, "NVIDIA GeForce GTX 260", DRIVER_NVIDIA_GEFORCE8, 1024},
1234 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX275, "NVIDIA GeForce GTX 275", DRIVER_NVIDIA_GEFORCE8, 896 },
1235 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX280, "NVIDIA GeForce GTX 280", DRIVER_NVIDIA_GEFORCE8, 1024},
1236 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_315M, "NVIDIA GeForce 315M", DRIVER_NVIDIA_GEFORCE8, 512 },
1237 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_320M, "NVIDIA GeForce 320M", DRIVER_NVIDIA_GEFORCE8, 256},
1238 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT320M, "NVIDIA GeForce GT 320M", DRIVER_NVIDIA_GEFORCE8, 1024},
1239 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT325M, "NVIDIA GeForce GT 325M", DRIVER_NVIDIA_GEFORCE8, 1024},
1240 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT330, "NVIDIA GeForce GT 330", DRIVER_NVIDIA_GEFORCE8, 1024},
1241 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTS350M, "NVIDIA GeForce GTS 350M", DRIVER_NVIDIA_GEFORCE8, 1024},
1242 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_410M, "NVIDIA GeForce 410M", DRIVER_NVIDIA_GEFORCE8, 512},
1243 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT420, "NVIDIA GeForce GT 420", DRIVER_NVIDIA_GEFORCE8, 2048},
1244 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT430, "NVIDIA GeForce GT 430", DRIVER_NVIDIA_GEFORCE8, 1024},
1245 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT440, "NVIDIA GeForce GT 440", DRIVER_NVIDIA_GEFORCE8, 1024},
1246 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTS450, "NVIDIA GeForce GTS 450", DRIVER_NVIDIA_GEFORCE8, 1024},
1247 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX460, "NVIDIA GeForce GTX 460", DRIVER_NVIDIA_GEFORCE8, 768 },
1248 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX460M, "NVIDIA GeForce GTX 460M", DRIVER_NVIDIA_GEFORCE8, 1536},
1249 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX465, "NVIDIA GeForce GTX 465", DRIVER_NVIDIA_GEFORCE8, 1024},
1250 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX470, "NVIDIA GeForce GTX 470", DRIVER_NVIDIA_GEFORCE8, 1280},
1251 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX480, "NVIDIA GeForce GTX 480", DRIVER_NVIDIA_GEFORCE8, 1536},
1252 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT520, "NVIDIA GeForce GT 520", DRIVER_NVIDIA_GEFORCE8, 1024},
1253 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT540M, "NVIDIA GeForce GT 540M", DRIVER_NVIDIA_GEFORCE8, 1024},
1254 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX550, "NVIDIA GeForce GTX 550 Ti", DRIVER_NVIDIA_GEFORCE8, 1024},
1255 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT555M, "NVIDIA GeForce GT 555M", DRIVER_NVIDIA_GEFORCE8, 1024},
1256 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX560TI, "NVIDIA GeForce GTX 560 Ti", DRIVER_NVIDIA_GEFORCE8, 1024},
1257 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX560, "NVIDIA GeForce GTX 560", DRIVER_NVIDIA_GEFORCE8, 1024},
1258 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX570, "NVIDIA GeForce GTX 570", DRIVER_NVIDIA_GEFORCE8, 1280},
1259 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX580, "NVIDIA GeForce GTX 580", DRIVER_NVIDIA_GEFORCE8, 1536},
1260 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT610, "NVIDIA GeForce GT 610", DRIVER_NVIDIA_GEFORCE8, 1024},
1261 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT630, "NVIDIA GeForce GT 630", DRIVER_NVIDIA_GEFORCE8, 1024},
1262 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT630M, "NVIDIA GeForce GT 630M", DRIVER_NVIDIA_GEFORCE8, 1024},
1263 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT640M, "NVIDIA GeForce GT 640M", DRIVER_NVIDIA_GEFORCE8, 1024},
1264 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT650M, "NVIDIA GeForce GT 650M", DRIVER_NVIDIA_GEFORCE8, 2048},
1265 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX650, "NVIDIA GeForce GTX 650", DRIVER_NVIDIA_GEFORCE8, 1024},
1266 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX650TI, "NVIDIA GeForce GTX 650 Ti", DRIVER_NVIDIA_GEFORCE8, 1024},
1267 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX660, "NVIDIA GeForce GTX 660", DRIVER_NVIDIA_GEFORCE8, 2048},
1268 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX660M, "NVIDIA GeForce GTX 660M", DRIVER_NVIDIA_GEFORCE8, 2048},
1269 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX660TI, "NVIDIA GeForce GTX 660 Ti", DRIVER_NVIDIA_GEFORCE8, 2048},
1270 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX670, "NVIDIA GeForce GTX 670", DRIVER_NVIDIA_GEFORCE8, 2048},
1271 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX670MX, "NVIDIA GeForce GTX 670MX", DRIVER_NVIDIA_GEFORCE8, 3072},
1272 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX680, "NVIDIA GeForce GTX 680", DRIVER_NVIDIA_GEFORCE8, 2048},
1273 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT750M, "NVIDIA GeForce GT 750M", DRIVER_NVIDIA_GEFORCE8, 1024},
1274 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX750, "NVIDIA GeForce GTX 750", DRIVER_NVIDIA_GEFORCE8, 1024},
1275 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX750TI, "NVIDIA GeForce GTX 750 Ti", DRIVER_NVIDIA_GEFORCE8, 2048},
1276 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX760, "NVIDIA Geforce GTX 760", DRIVER_NVIDIA_GEFORCE8, 2048},
1277 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX765M, "NVIDIA GeForce GTX 765M", DRIVER_NVIDIA_GEFORCE8, 2048},
1278 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX770M, "NVIDIA GeForce GTX 770M", DRIVER_NVIDIA_GEFORCE8, 3072},
1279 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX770, "NVIDIA GeForce GTX 770", DRIVER_NVIDIA_GEFORCE8, 2048},
1280 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX780, "NVIDIA GeForce GTX 780", DRIVER_NVIDIA_GEFORCE8, 3072},
1281 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX780TI, "NVIDIA GeForce GTX 780 Ti", DRIVER_NVIDIA_GEFORCE8, 3072},
1282 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX970, "NVIDIA GeForce GTX 970", DRIVER_NVIDIA_GEFORCE8, 4096},
1283 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX970M, "NVIDIA GeForce GTX 970M", DRIVER_NVIDIA_GEFORCE8, 3072},
1285 /* AMD cards */
1286 {HW_VENDOR_AMD, CARD_AMD_RAGE_128PRO, "ATI Rage Fury", DRIVER_AMD_RAGE_128PRO, 16 },
1287 {HW_VENDOR_AMD, CARD_AMD_RADEON_7200, "ATI RADEON 7200 SERIES", DRIVER_AMD_R100, 32 },
1288 {HW_VENDOR_AMD, CARD_AMD_RADEON_8500, "ATI RADEON 8500 SERIES", DRIVER_AMD_R100, 64 },
1289 {HW_VENDOR_AMD, CARD_AMD_RADEON_9500, "ATI Radeon 9500", DRIVER_AMD_R300, 64 },
1290 {HW_VENDOR_AMD, CARD_AMD_RADEON_XPRESS_200M, "ATI RADEON XPRESS 200M Series", DRIVER_AMD_R300, 64 },
1291 {HW_VENDOR_AMD, CARD_AMD_RADEON_X700, "ATI Radeon X700 SE", DRIVER_AMD_R300, 128 },
1292 {HW_VENDOR_AMD, CARD_AMD_RADEON_X1600, "ATI Radeon X1600 Series", DRIVER_AMD_R300, 128 },
1293 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD2350, "ATI Mobility Radeon HD 2350", DRIVER_AMD_R600, 256 },
1294 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD2600, "ATI Mobility Radeon HD 2600", DRIVER_AMD_R600, 256 },
1295 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD2900, "ATI Radeon HD 2900 XT", DRIVER_AMD_R600, 512 },
1296 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD3200, "ATI Radeon HD 3200 Graphics", DRIVER_AMD_R600, 128 },
1297 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD3850, "ATI Radeon HD 3850 AGP", DRIVER_AMD_R600, 512 },
1298 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD4200M, "ATI Mobility Radeon HD 4200", DRIVER_AMD_R600, 256 },
1299 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD4350, "ATI Radeon HD 4350", DRIVER_AMD_R600, 256 },
1300 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD4600, "ATI Radeon HD 4600 Series", DRIVER_AMD_R600, 512 },
1301 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD4700, "ATI Radeon HD 4700 Series", DRIVER_AMD_R600, 512 },
1302 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD4800, "ATI Radeon HD 4800 Series", DRIVER_AMD_R600, 512 },
1303 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD5400, "ATI Radeon HD 5400 Series", DRIVER_AMD_R600, 512 },
1304 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD5600, "ATI Radeon HD 5600 Series", DRIVER_AMD_R600, 512 },
1305 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD5700, "ATI Radeon HD 5700 Series", DRIVER_AMD_R600, 512 },
1306 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD5800, "ATI Radeon HD 5800 Series", DRIVER_AMD_R600, 1024},
1307 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD5900, "ATI Radeon HD 5900 Series", DRIVER_AMD_R600, 1024},
1308 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6300, "AMD Radeon HD 6300 series Graphics", DRIVER_AMD_R600, 1024},
1309 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6400, "AMD Radeon HD 6400 Series", DRIVER_AMD_R600, 1024},
1310 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6410D, "AMD Radeon HD 6410D", DRIVER_AMD_R600, 1024},
1311 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6550D, "AMD Radeon HD 6550D", DRIVER_AMD_R600, 1024},
1312 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6600, "AMD Radeon HD 6600 Series", DRIVER_AMD_R600, 1024},
1313 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6600M, "AMD Radeon HD 6600M Series", DRIVER_AMD_R600, 512 },
1314 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6700, "AMD Radeon HD 6700 Series", DRIVER_AMD_R600, 1024},
1315 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6800, "AMD Radeon HD 6800 Series", DRIVER_AMD_R600, 1024},
1316 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6900, "AMD Radeon HD 6900 Series", DRIVER_AMD_R600, 2048},
1317 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD7660D, "AMD Radeon HD 7660D", DRIVER_AMD_R600, 2048},
1318 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD7700, "AMD Radeon HD 7700 Series", DRIVER_AMD_R600, 1024},
1319 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD7800, "AMD Radeon HD 7800 Series", DRIVER_AMD_R600, 2048},
1320 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD7900, "AMD Radeon HD 7900 Series", DRIVER_AMD_R600, 2048},
1321 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD8600M, "AMD Radeon HD 8600M Series", DRIVER_AMD_R600, 1024},
1322 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD8670, "AMD Radeon HD 8670", DRIVER_AMD_R600, 2048},
1323 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD8770, "AMD Radeon HD 8770", DRIVER_AMD_R600, 2048},
1324 {HW_VENDOR_AMD, CARD_AMD_RADEON_R3, "AMD Radeon HD 8400 / R3 Series", DRIVER_AMD_R600, 2048},
1325 {HW_VENDOR_AMD, CARD_AMD_RADEON_R7, "AMD Radeon(TM) R7 Graphics", DRIVER_AMD_R600, 2048},
1326 {HW_VENDOR_AMD, CARD_AMD_RADEON_R9, "AMD Radeon R9 290", DRIVER_AMD_R600, 4096},
1328 /* VMware */
1329 {HW_VENDOR_VMWARE, CARD_VMWARE_SVGA3D, "VMware SVGA 3D (Microsoft Corporation - WDDM)", DRIVER_VMWARE, 1024},
1331 /* Intel cards */
1332 {HW_VENDOR_INTEL, CARD_INTEL_830M, "Intel(R) 82830M Graphics Controller", DRIVER_INTEL_GMA800, 32 },
1333 {HW_VENDOR_INTEL, CARD_INTEL_855GM, "Intel(R) 82852/82855 GM/GME Graphics Controller", DRIVER_INTEL_GMA800, 32 },
1334 {HW_VENDOR_INTEL, CARD_INTEL_845G, "Intel(R) 845G", DRIVER_INTEL_GMA800, 32 },
1335 {HW_VENDOR_INTEL, CARD_INTEL_865G, "Intel(R) 82865G Graphics Controller", DRIVER_INTEL_GMA800, 32 },
1336 {HW_VENDOR_INTEL, CARD_INTEL_915G, "Intel(R) 82915G/GV/910GL Express Chipset Family", DRIVER_INTEL_GMA900, 64 },
1337 {HW_VENDOR_INTEL, CARD_INTEL_E7221G, "Intel(R) E7221G", DRIVER_INTEL_GMA900, 64 },
1338 {HW_VENDOR_INTEL, CARD_INTEL_915GM, "Mobile Intel(R) 915GM/GMS,910GML Express Chipset Family", DRIVER_INTEL_GMA900, 64 },
1339 {HW_VENDOR_INTEL, CARD_INTEL_945G, "Intel(R) 945G", DRIVER_INTEL_GMA950, 64 },
1340 {HW_VENDOR_INTEL, CARD_INTEL_945GM, "Mobile Intel(R) 945GM Express Chipset Family", DRIVER_INTEL_GMA950, 64 },
1341 {HW_VENDOR_INTEL, CARD_INTEL_945GME, "Intel(R) 945GME", DRIVER_INTEL_GMA950, 64 },
1342 {HW_VENDOR_INTEL, CARD_INTEL_Q35, "Intel(R) Q35", DRIVER_INTEL_GMA950, 64 },
1343 {HW_VENDOR_INTEL, CARD_INTEL_G33, "Intel(R) G33", DRIVER_INTEL_GMA950, 64 },
1344 {HW_VENDOR_INTEL, CARD_INTEL_Q33, "Intel(R) Q33", DRIVER_INTEL_GMA950, 64 },
1345 {HW_VENDOR_INTEL, CARD_INTEL_PNVG, "Intel(R) IGD", DRIVER_INTEL_GMA950, 64 },
1346 {HW_VENDOR_INTEL, CARD_INTEL_PNVM, "Intel(R) IGD", DRIVER_INTEL_GMA950, 64 },
1347 {HW_VENDOR_INTEL, CARD_INTEL_965Q, "Intel(R) 965Q", DRIVER_INTEL_GMA3000, 128},
1348 {HW_VENDOR_INTEL, CARD_INTEL_965G, "Intel(R) 965G", DRIVER_INTEL_GMA3000, 128},
1349 {HW_VENDOR_INTEL, CARD_INTEL_946GZ, "Intel(R) 946GZ", DRIVER_INTEL_GMA3000, 128},
1350 {HW_VENDOR_INTEL, CARD_INTEL_965GM, "Mobile Intel(R) 965 Express Chipset Family", DRIVER_INTEL_GMA3000, 128},
1351 {HW_VENDOR_INTEL, CARD_INTEL_965GME, "Intel(R) 965GME", DRIVER_INTEL_GMA3000, 128},
1352 {HW_VENDOR_INTEL, CARD_INTEL_GM45, "Mobile Intel(R) GM45 Express Chipset Family", DRIVER_INTEL_GMA3000, 512},
1353 {HW_VENDOR_INTEL, CARD_INTEL_IGD, "Intel(R) Integrated Graphics Device", DRIVER_INTEL_GMA3000, 512},
1354 {HW_VENDOR_INTEL, CARD_INTEL_G45, "Intel(R) G45/G43", DRIVER_INTEL_GMA3000, 512},
1355 {HW_VENDOR_INTEL, CARD_INTEL_Q45, "Intel(R) Q45/Q43", DRIVER_INTEL_GMA3000, 512},
1356 {HW_VENDOR_INTEL, CARD_INTEL_G41, "Intel(R) G41", DRIVER_INTEL_GMA3000, 512},
1357 {HW_VENDOR_INTEL, CARD_INTEL_B43, "Intel(R) B43", DRIVER_INTEL_GMA3000, 512},
1358 {HW_VENDOR_INTEL, CARD_INTEL_ILKD, "Intel(R) Ironlake Desktop", DRIVER_INTEL_GMA3000, 1024},
1359 {HW_VENDOR_INTEL, CARD_INTEL_ILKM, "Intel(R) Ironlake Mobile", DRIVER_INTEL_GMA3000, 1024},
1360 {HW_VENDOR_INTEL, CARD_INTEL_SNBD, "Intel(R) Sandybridge Desktop", DRIVER_INTEL_GMA3000, 1024},
1361 {HW_VENDOR_INTEL, CARD_INTEL_SNBM, "Intel(R) Sandybridge Mobile", DRIVER_INTEL_GMA3000, 1024},
1362 {HW_VENDOR_INTEL, CARD_INTEL_SNBS, "Intel(R) Sandybridge Server", DRIVER_INTEL_GMA3000, 1024},
1363 {HW_VENDOR_INTEL, CARD_INTEL_IVBD, "Intel(R) Ivybridge Desktop", DRIVER_INTEL_GMA3000, 1024},
1364 {HW_VENDOR_INTEL, CARD_INTEL_IVBM, "Intel(R) Ivybridge Mobile", DRIVER_INTEL_GMA3000, 1024},
1365 {HW_VENDOR_INTEL, CARD_INTEL_IVBS, "Intel(R) Ivybridge Server", DRIVER_INTEL_GMA3000, 1024},
1366 {HW_VENDOR_INTEL, CARD_INTEL_HWM, "Intel(R) Haswell Mobile", DRIVER_INTEL_GMA3000, 1024},
1369 static const struct driver_version_information *get_driver_version_info(enum wined3d_display_driver driver,
1370 enum wined3d_driver_model driver_model)
1372 unsigned int i;
1374 TRACE("Looking up version info for driver=%d driver_model=%d\n", driver, driver_model);
1375 for (i = 0; i < (sizeof(driver_version_table) / sizeof(driver_version_table[0])); i++)
1377 const struct driver_version_information *entry = &driver_version_table[i];
1379 if (entry->driver == driver && entry->driver_model == driver_model)
1381 TRACE("Found driver \"%s\", version %u, subversion %u, build %u.\n",
1382 entry->driver_name, entry->version, entry->subversion, entry->build);
1383 return entry;
1386 return NULL;
1389 static const struct gpu_description *get_gpu_description(enum wined3d_pci_vendor vendor,
1390 enum wined3d_pci_device device)
1392 unsigned int i;
1394 for (i = 0; i < (sizeof(gpu_description_table) / sizeof(*gpu_description_table)); ++i)
1396 if (vendor == gpu_description_table[i].vendor && device == gpu_description_table[i].card)
1397 return &gpu_description_table[i];
1400 return NULL;
1403 static void init_driver_info(struct wined3d_driver_info *driver_info,
1404 enum wined3d_pci_vendor vendor, enum wined3d_pci_device device)
1406 OSVERSIONINFOW os_version;
1407 WORD driver_os_version;
1408 enum wined3d_display_driver driver;
1409 enum wined3d_driver_model driver_model;
1410 const struct driver_version_information *version_info;
1411 const struct gpu_description *gpu_desc;
1413 if (driver_info->vendor != PCI_VENDOR_NONE || driver_info->device != PCI_DEVICE_NONE)
1415 static unsigned int once;
1417 TRACE("GPU override %04x:%04x.\n", wined3d_settings.pci_vendor_id, wined3d_settings.pci_device_id);
1419 driver_info->vendor = wined3d_settings.pci_vendor_id;
1420 if (driver_info->vendor == PCI_VENDOR_NONE)
1421 driver_info->vendor = vendor;
1423 driver_info->device = wined3d_settings.pci_device_id;
1424 if (driver_info->device == PCI_DEVICE_NONE)
1425 driver_info->device = device;
1427 if (get_gpu_description(driver_info->vendor, driver_info->device))
1429 vendor = driver_info->vendor;
1430 device = driver_info->device;
1432 else if (!once++)
1433 ERR_(winediag)("Invalid GPU override %04x:%04x specified, ignoring.\n",
1434 driver_info->vendor, driver_info->device);
1437 driver_info->vendor = vendor;
1438 driver_info->device = device;
1440 memset(&os_version, 0, sizeof(os_version));
1441 os_version.dwOSVersionInfoSize = sizeof(os_version);
1442 if (!GetVersionExW(&os_version))
1444 ERR("Failed to get OS version, reporting 2000/XP.\n");
1445 driver_os_version = 6;
1446 driver_model = DRIVER_MODEL_NT5X;
1448 else
1450 TRACE("OS version %u.%u.\n", os_version.dwMajorVersion, os_version.dwMinorVersion);
1451 switch (os_version.dwMajorVersion)
1453 case 4:
1454 /* If needed we could distinguish between 9x and NT4, but this code won't make
1455 * sense for NT4 since it had no way to obtain this info through DirectDraw 3.0.
1457 driver_os_version = 4;
1458 driver_model = DRIVER_MODEL_WIN9X;
1459 break;
1461 case 5:
1462 driver_os_version = 6;
1463 driver_model = DRIVER_MODEL_NT5X;
1464 break;
1466 case 6:
1467 if (os_version.dwMinorVersion == 0)
1469 driver_os_version = 7;
1470 driver_model = DRIVER_MODEL_NT6X;
1472 else if (os_version.dwMinorVersion == 1)
1474 driver_os_version = 8;
1475 driver_model = DRIVER_MODEL_NT6X;
1477 else
1479 if (os_version.dwMinorVersion > 2)
1481 FIXME("Unhandled OS version %u.%u, reporting Win 8.\n",
1482 os_version.dwMajorVersion, os_version.dwMinorVersion);
1484 driver_os_version = 9;
1485 driver_model = DRIVER_MODEL_NT6X;
1487 break;
1489 default:
1490 FIXME("Unhandled OS version %u.%u, reporting 2000/XP.\n",
1491 os_version.dwMajorVersion, os_version.dwMinorVersion);
1492 driver_os_version = 6;
1493 driver_model = DRIVER_MODEL_NT5X;
1494 break;
1498 if ((gpu_desc = get_gpu_description(driver_info->vendor, driver_info->device)))
1500 driver_info->description = gpu_desc->description;
1501 driver_info->vram_bytes = (UINT64)gpu_desc->vidmem * 1024 * 1024;
1502 driver = gpu_desc->driver;
1504 else
1506 ERR("Card %04x:%04x not found in driver DB.\n", vendor, device);
1507 driver_info->description = "Direct3D HAL";
1508 driver_info->vram_bytes = WINE_DEFAULT_VIDMEM;
1509 driver = DRIVER_UNKNOWN;
1512 if (wined3d_settings.emulated_textureram)
1514 TRACE("Overriding amount of video memory with 0x%s bytes.\n",
1515 wine_dbgstr_longlong(wined3d_settings.emulated_textureram));
1516 driver_info->vram_bytes = wined3d_settings.emulated_textureram;
1519 /* Try to obtain driver version information for the current Windows version. This fails in
1520 * some cases:
1521 * - the gpu is not available on the currently selected OS version:
1522 * - Geforce GTX480 on Win98. When running applications in compatibility mode on Windows,
1523 * version information for the current Windows version is returned instead of faked info.
1524 * We do the same and assume the default Windows version to emulate is WinXP.
1526 * - Videocard is a Riva TNT but winver is set to win7 (there are no drivers for this beast)
1527 * For now return the XP driver info. Perhaps later on we should return VESA.
1529 * - the gpu is not in our database (can happen when the user overrides the vendor_id / device_id)
1530 * This could be an indication that our database is not up to date, so this should be fixed.
1532 if ((version_info = get_driver_version_info(driver, driver_model))
1533 || (version_info = get_driver_version_info(driver, DRIVER_MODEL_NT5X)))
1535 driver_info->name = version_info->driver_name;
1536 driver_info->version_high = MAKEDWORD_VERSION(driver_os_version, version_info->version);
1537 driver_info->version_low = MAKEDWORD_VERSION(version_info->subversion, version_info->build);
1539 else
1541 ERR("No driver version info found for device %04x:%04x, driver model %#x.\n",
1542 vendor, device, driver_model);
1543 driver_info->name = "Display";
1544 driver_info->version_high = MAKEDWORD_VERSION(driver_os_version, 15);
1545 driver_info->version_low = MAKEDWORD_VERSION(8, 6); /* Nvidia RIVA TNT, arbitrary */
1548 TRACE("Reporting (fake) driver version 0x%08x-0x%08x.\n",
1549 driver_info->version_high, driver_info->version_low);
1552 /* Context activation is done by the caller. */
1553 static void fixup_extensions(struct wined3d_gl_info *gl_info, const char *gl_renderer,
1554 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
1556 unsigned int i;
1558 for (i = 0; i < (sizeof(quirk_table) / sizeof(*quirk_table)); ++i)
1560 if (!quirk_table[i].match(gl_info, gl_renderer, gl_vendor, card_vendor, device)) continue;
1561 TRACE("Applying driver quirk \"%s\".\n", quirk_table[i].description);
1562 quirk_table[i].apply(gl_info);
1565 /* Find out if PBOs work as they are supposed to. */
1566 test_pbo_functionality(gl_info);
1569 static DWORD wined3d_parse_gl_version(const char *gl_version)
1571 const char *ptr = gl_version;
1572 int major, minor;
1574 major = atoi(ptr);
1575 if (major <= 0)
1576 ERR("Invalid OpenGL major version %d.\n", major);
1578 while (isdigit(*ptr)) ++ptr;
1579 if (*ptr++ != '.')
1580 ERR("Invalid OpenGL version string %s.\n", debugstr_a(gl_version));
1582 minor = atoi(ptr);
1584 TRACE("Found OpenGL version %d.%d.\n", major, minor);
1586 return MAKEDWORD_VERSION(major, minor);
1589 static enum wined3d_gl_vendor wined3d_guess_gl_vendor(const struct wined3d_gl_info *gl_info,
1590 const char *gl_vendor_string, const char *gl_renderer)
1593 /* MacOS has various specialities in the extensions it advertises. Some have to be loaded from
1594 * the opengl 1.2+ core, while other extensions are advertised, but software emulated. So try to
1595 * detect the Apple OpenGL implementation to apply some extension fixups afterwards.
1597 * Detecting this isn't really easy. The vendor string doesn't mention Apple. Compile-time checks
1598 * aren't sufficient either because a Linux binary may display on a macos X server via remote X11.
1599 * So try to detect the GL implementation by looking at certain Apple extensions. Some extensions
1600 * like client storage might be supported on other implementations too, but GL_APPLE_flush_render
1601 * is specific to the Mac OS X window management, and GL_APPLE_ycbcr_422 is QuickTime specific. So
1602 * the chance that other implementations support them is rather small since Win32 QuickTime uses
1603 * DirectDraw, not OpenGL. */
1604 if (gl_info->supported[APPLE_FENCE]
1605 && gl_info->supported[APPLE_YCBCR_422])
1606 return GL_VENDOR_APPLE;
1608 if (strstr(gl_vendor_string, "NVIDIA"))
1609 return GL_VENDOR_NVIDIA;
1611 if (strstr(gl_vendor_string, "ATI"))
1612 return GL_VENDOR_FGLRX;
1614 if (strstr(gl_vendor_string, "Mesa")
1615 || strstr(gl_vendor_string, "X.Org")
1616 || strstr(gl_vendor_string, "Advanced Micro Devices, Inc.")
1617 || strstr(gl_vendor_string, "DRI R300 Project")
1618 || strstr(gl_vendor_string, "Tungsten Graphics, Inc")
1619 || strstr(gl_vendor_string, "VMware, Inc.")
1620 || strstr(gl_vendor_string, "Intel")
1621 || strstr(gl_renderer, "Mesa")
1622 || strstr(gl_renderer, "Gallium")
1623 || strstr(gl_renderer, "Intel"))
1624 return GL_VENDOR_MESA;
1626 FIXME("Received unrecognized GL_VENDOR %s. Returning GL_VENDOR_UNKNOWN.\n",
1627 debugstr_a(gl_vendor_string));
1629 return GL_VENDOR_UNKNOWN;
1632 static enum wined3d_pci_vendor wined3d_guess_card_vendor(const char *gl_vendor_string, const char *gl_renderer)
1634 if (strstr(gl_vendor_string, "NVIDIA")
1635 || strstr(gl_vendor_string, "Nouveau")
1636 || strstr(gl_vendor_string, "nouveau"))
1637 return HW_VENDOR_NVIDIA;
1639 if (strstr(gl_vendor_string, "ATI")
1640 || strstr(gl_vendor_string, "Advanced Micro Devices, Inc.")
1641 || strstr(gl_vendor_string, "X.Org R300 Project")
1642 || strstr(gl_renderer, "AMD")
1643 || strstr(gl_renderer, "R100")
1644 || strstr(gl_renderer, "R200")
1645 || strstr(gl_renderer, "R300")
1646 || strstr(gl_renderer, "R600")
1647 || strstr(gl_renderer, "R700"))
1648 return HW_VENDOR_AMD;
1650 if (strstr(gl_vendor_string, "Intel(R)")
1651 /* Intel switched from Intel(R) to Intel® recently, so just match Intel. */
1652 || strstr(gl_renderer, "Intel")
1653 || strstr(gl_renderer, "i915")
1654 || strstr(gl_vendor_string, "Intel Inc."))
1655 return HW_VENDOR_INTEL;
1657 if (strstr(gl_renderer, "SVGA3D"))
1658 return HW_VENDOR_VMWARE;
1660 if (strstr(gl_vendor_string, "Mesa")
1661 || strstr(gl_vendor_string, "Brian Paul")
1662 || strstr(gl_vendor_string, "Tungsten Graphics, Inc")
1663 || strstr(gl_vendor_string, "VMware, Inc."))
1664 return HW_VENDOR_SOFTWARE;
1666 FIXME("Received unrecognized GL_VENDOR %s. Returning HW_VENDOR_NVIDIA.\n", debugstr_a(gl_vendor_string));
1668 return HW_VENDOR_NVIDIA;
1671 static enum wined3d_d3d_level d3d_level_from_caps(const struct shader_caps *shader_caps, const struct fragment_caps *fragment_caps, DWORD glsl_version)
1673 if (shader_caps->vs_version >= 5)
1674 return WINED3D_D3D_LEVEL_11;
1675 if (shader_caps->vs_version == 4)
1677 /* No backed supports SM 5 at the moment */
1678 if (glsl_version >= MAKEDWORD_VERSION(4, 00))
1679 return WINED3D_D3D_LEVEL_11;
1680 return WINED3D_D3D_LEVEL_10;
1682 if (shader_caps->vs_version == 3)
1684 /* Wine cannot use SM 4 on mesa drivers as the necessary functionality
1685 * is not exposed on compatibility contexts */
1686 if (glsl_version >= MAKEDWORD_VERSION(1, 30))
1687 return WINED3D_D3D_LEVEL_10;
1688 return WINED3D_D3D_LEVEL_9_SM3;
1690 if (shader_caps->vs_version == 2)
1691 return WINED3D_D3D_LEVEL_9_SM2;
1692 if (shader_caps->vs_version == 1)
1693 return WINED3D_D3D_LEVEL_8;
1695 if (fragment_caps->TextureOpCaps & WINED3DTEXOPCAPS_DOTPRODUCT3)
1696 return WINED3D_D3D_LEVEL_7;
1697 if (fragment_caps->MaxSimultaneousTextures > 1)
1698 return WINED3D_D3D_LEVEL_6;
1700 return WINED3D_D3D_LEVEL_5;
1703 static const struct wined3d_renderer_table
1705 const char *renderer;
1706 enum wined3d_pci_device id;
1708 cards_nvidia_binary[] =
1710 /* Direct 3D 11 */
1711 {"GTX 970M", CARD_NVIDIA_GEFORCE_GTX970M}, /* GeForce 900 - highend mobile*/
1712 {"GTX 970", CARD_NVIDIA_GEFORCE_GTX970}, /* GeForce 900 - highend */
1713 {"GTX 780 Ti", CARD_NVIDIA_GEFORCE_GTX780TI}, /* Geforce 700 - highend */
1714 {"GTX 780", CARD_NVIDIA_GEFORCE_GTX780}, /* Geforce 700 - highend */
1715 {"GTX 770M", CARD_NVIDIA_GEFORCE_GTX770M}, /* Geforce 700 - midend high mobile */
1716 {"GTX 770", CARD_NVIDIA_GEFORCE_GTX770}, /* Geforce 700 - highend */
1717 {"GTX 765M", CARD_NVIDIA_GEFORCE_GTX765M}, /* Geforce 700 - midend high mobile */
1718 {"GTX 760", CARD_NVIDIA_GEFORCE_GTX760}, /* Geforce 700 - midend high */
1719 {"GTX 750 Ti", CARD_NVIDIA_GEFORCE_GTX750TI}, /* Geforce 700 - midend */
1720 {"GTX 750", CARD_NVIDIA_GEFORCE_GTX750}, /* Geforce 700 - midend */
1721 {"GT 750M", CARD_NVIDIA_GEFORCE_GT750M}, /* Geforce 700 - midend mobile */
1722 {"GTX 680", CARD_NVIDIA_GEFORCE_GTX680}, /* Geforce 600 - highend */
1723 {"GTX 670MX", CARD_NVIDIA_GEFORCE_GTX670MX}, /* Geforce 600 - highend */
1724 {"GTX 670", CARD_NVIDIA_GEFORCE_GTX670}, /* Geforce 600 - midend high */
1725 {"GTX 660 Ti", CARD_NVIDIA_GEFORCE_GTX660TI}, /* Geforce 600 - midend high */
1726 {"GTX 660M", CARD_NVIDIA_GEFORCE_GTX660M}, /* Geforce 600 - midend high mobile */
1727 {"GTX 660", CARD_NVIDIA_GEFORCE_GTX660}, /* Geforce 600 - midend high */
1728 {"GTX 650 Ti", CARD_NVIDIA_GEFORCE_GTX650TI}, /* Geforce 600 - lowend */
1729 {"GTX 650", CARD_NVIDIA_GEFORCE_GTX650}, /* Geforce 600 - lowend */
1730 {"GT 650M", CARD_NVIDIA_GEFORCE_GT650M}, /* Geforce 600 - midend mobile */
1731 {"GT 640M", CARD_NVIDIA_GEFORCE_GT640M}, /* Geforce 600 - midend mobile */
1732 {"GT 630M", CARD_NVIDIA_GEFORCE_GT630M}, /* Geforce 600 - midend mobile */
1733 {"GT 630", CARD_NVIDIA_GEFORCE_GT630}, /* Geforce 600 - lowend */
1734 {"GT 610", CARD_NVIDIA_GEFORCE_GT610}, /* Geforce 600 - lowend */
1735 {"GTX 580", CARD_NVIDIA_GEFORCE_GTX580}, /* Geforce 500 - highend */
1736 {"GTX 570", CARD_NVIDIA_GEFORCE_GTX570}, /* Geforce 500 - midend high */
1737 {"GTX 560 Ti", CARD_NVIDIA_GEFORCE_GTX560TI}, /* Geforce 500 - midend */
1738 {"GTX 560", CARD_NVIDIA_GEFORCE_GTX560}, /* Geforce 500 - midend */
1739 {"GT 555M", CARD_NVIDIA_GEFORCE_GT555M}, /* Geforce 500 - midend mobile */
1740 {"GTX 550 Ti", CARD_NVIDIA_GEFORCE_GTX550}, /* Geforce 500 - midend */
1741 {"GT 540M", CARD_NVIDIA_GEFORCE_GT540M}, /* Geforce 500 - midend mobile */
1742 {"GT 520", CARD_NVIDIA_GEFORCE_GT520}, /* Geforce 500 - lowend */
1743 {"GTX 480", CARD_NVIDIA_GEFORCE_GTX480}, /* Geforce 400 - highend */
1744 {"GTX 470", CARD_NVIDIA_GEFORCE_GTX470}, /* Geforce 400 - midend high */
1745 /* Direct 3D 10 */
1746 {"GTX 465", CARD_NVIDIA_GEFORCE_GTX465}, /* Geforce 400 - midend */
1747 {"GTX 460M", CARD_NVIDIA_GEFORCE_GTX460M}, /* Geforce 400 - highend mobile */
1748 {"GTX 460", CARD_NVIDIA_GEFORCE_GTX460}, /* Geforce 400 - midend */
1749 {"GTS 450", CARD_NVIDIA_GEFORCE_GTS450}, /* Geforce 400 - midend low */
1750 {"GT 440", CARD_NVIDIA_GEFORCE_GT440}, /* Geforce 400 - lowend */
1751 {"GT 430", CARD_NVIDIA_GEFORCE_GT430}, /* Geforce 400 - lowend */
1752 {"GT 420", CARD_NVIDIA_GEFORCE_GT420}, /* Geforce 400 - lowend */
1753 {"410M", CARD_NVIDIA_GEFORCE_410M}, /* Geforce 400 - lowend mobile */
1754 {"GT 330", CARD_NVIDIA_GEFORCE_GT330}, /* Geforce 300 - highend */
1755 {"GTS 360M", CARD_NVIDIA_GEFORCE_GTS350M}, /* Geforce 300 - highend mobile */
1756 {"GTS 350M", CARD_NVIDIA_GEFORCE_GTS350M}, /* Geforce 300 - highend mobile */
1757 {"GT 330M", CARD_NVIDIA_GEFORCE_GT325M}, /* Geforce 300 - midend mobile */
1758 {"GT 325M", CARD_NVIDIA_GEFORCE_GT325M}, /* Geforce 300 - midend mobile */
1759 {"GT 320M", CARD_NVIDIA_GEFORCE_GT320M}, /* Geforce 300 - midend mobile */
1760 {"320M", CARD_NVIDIA_GEFORCE_320M}, /* Geforce 300 - midend mobile */
1761 {"315M", CARD_NVIDIA_GEFORCE_315M}, /* Geforce 300 - midend mobile */
1762 {"GTX 295", CARD_NVIDIA_GEFORCE_GTX280}, /* Geforce 200 - highend */
1763 {"GTX 285", CARD_NVIDIA_GEFORCE_GTX280}, /* Geforce 200 - highend */
1764 {"GTX 280", CARD_NVIDIA_GEFORCE_GTX280}, /* Geforce 200 - highend */
1765 {"GTX 275", CARD_NVIDIA_GEFORCE_GTX275}, /* Geforce 200 - midend high */
1766 {"GTX 260", CARD_NVIDIA_GEFORCE_GTX260}, /* Geforce 200 - midend */
1767 {"GT 240", CARD_NVIDIA_GEFORCE_GT240}, /* Geforce 200 - midend */
1768 {"GT 220", CARD_NVIDIA_GEFORCE_GT220}, /* Geforce 200 - lowend */
1769 {"GeForce 310", CARD_NVIDIA_GEFORCE_210}, /* Geforce 200 - lowend */
1770 {"GeForce 305", CARD_NVIDIA_GEFORCE_210}, /* Geforce 200 - lowend */
1771 {"GeForce 210", CARD_NVIDIA_GEFORCE_210}, /* Geforce 200 - lowend */
1772 {"G 210", CARD_NVIDIA_GEFORCE_210}, /* Geforce 200 - lowend */
1773 {"GTS 250", CARD_NVIDIA_GEFORCE_9800GT}, /* Geforce 9 - highend / Geforce 200 - midend */
1774 {"GTS 150", CARD_NVIDIA_GEFORCE_9800GT}, /* Geforce 9 - highend / Geforce 200 - midend */
1775 {"9800", CARD_NVIDIA_GEFORCE_9800GT}, /* Geforce 9 - highend / Geforce 200 - midend */
1776 {"GT 140", CARD_NVIDIA_GEFORCE_9600GT}, /* Geforce 9 - midend */
1777 {"9600", CARD_NVIDIA_GEFORCE_9600GT}, /* Geforce 9 - midend */
1778 {"GT 130", CARD_NVIDIA_GEFORCE_9500GT}, /* Geforce 9 - midend low / Geforce 200 - low */
1779 {"GT 120", CARD_NVIDIA_GEFORCE_9500GT}, /* Geforce 9 - midend low / Geforce 200 - low */
1780 {"9500", CARD_NVIDIA_GEFORCE_9500GT}, /* Geforce 9 - midend low / Geforce 200 - low */
1781 {"9400M", CARD_NVIDIA_GEFORCE_9400M}, /* Geforce 9 - lowend */
1782 {"9400", CARD_NVIDIA_GEFORCE_9400GT}, /* Geforce 9 - lowend */
1783 {"9300", CARD_NVIDIA_GEFORCE_9300}, /* Geforce 9 - lowend low */
1784 {"9200", CARD_NVIDIA_GEFORCE_9200}, /* Geforce 9 - lowend low */
1785 {"9100", CARD_NVIDIA_GEFORCE_9200}, /* Geforce 9 - lowend low */
1786 {"G 100", CARD_NVIDIA_GEFORCE_9200}, /* Geforce 9 - lowend low */
1787 {"8800 GTX", CARD_NVIDIA_GEFORCE_8800GTX}, /* Geforce 8 - highend high */
1788 {"8800", CARD_NVIDIA_GEFORCE_8800GTS}, /* Geforce 8 - highend */
1789 {"8600M", CARD_NVIDIA_GEFORCE_8600MGT}, /* Geforce 8 - midend mobile */
1790 {"8600 M", CARD_NVIDIA_GEFORCE_8600MGT}, /* Geforce 8 - midend mobile */
1791 {"8700", CARD_NVIDIA_GEFORCE_8600GT}, /* Geforce 8 - midend */
1792 {"8600", CARD_NVIDIA_GEFORCE_8600GT}, /* Geforce 8 - midend */
1793 {"8500", CARD_NVIDIA_GEFORCE_8500GT}, /* Geforce 8 - mid-lowend */
1794 {"8400", CARD_NVIDIA_GEFORCE_8400GS}, /* Geforce 8 - mid-lowend */
1795 {"8300", CARD_NVIDIA_GEFORCE_8300GS}, /* Geforce 8 - lowend */
1796 {"8200", CARD_NVIDIA_GEFORCE_8200}, /* Geforce 8 - lowend */
1797 {"8100", CARD_NVIDIA_GEFORCE_8200}, /* Geforce 8 - lowend */
1798 /* Direct 3D 9 SM3 */
1799 {"Quadro FX 5", CARD_NVIDIA_GEFORCE_7800GT}, /* Geforce 7 - highend */
1800 {"Quadro FX 4", CARD_NVIDIA_GEFORCE_7800GT}, /* Geforce 7 - highend */
1801 {"7950", CARD_NVIDIA_GEFORCE_7800GT}, /* Geforce 7 - highend */
1802 {"7900", CARD_NVIDIA_GEFORCE_7800GT}, /* Geforce 7 - highend */
1803 {"7800", CARD_NVIDIA_GEFORCE_7800GT}, /* Geforce 7 - highend */
1804 {"7700", CARD_NVIDIA_GEFORCE_7600}, /* Geforce 7 - midend */
1805 {"7600", CARD_NVIDIA_GEFORCE_7600}, /* Geforce 7 - midend */
1806 {"7400", CARD_NVIDIA_GEFORCE_7400}, /* Geforce 7 - lower medium */
1807 {"7300", CARD_NVIDIA_GEFORCE_7300}, /* Geforce 7 - lowend */
1808 {"6800", CARD_NVIDIA_GEFORCE_6800}, /* Geforce 6 - highend */
1809 {"6700", CARD_NVIDIA_GEFORCE_6600GT}, /* Geforce 6 - midend */
1810 {"6610", CARD_NVIDIA_GEFORCE_6600GT}, /* Geforce 6 - midend */
1811 {"6600", CARD_NVIDIA_GEFORCE_6600GT}, /* Geforce 6 - midend */
1812 /* Direct 3D 9 SM2 */
1813 {"Quadro FX", CARD_NVIDIA_GEFORCEFX_5800}, /* GeforceFX - highend */
1814 {"5950", CARD_NVIDIA_GEFORCEFX_5800}, /* GeforceFX - highend */
1815 {"5900", CARD_NVIDIA_GEFORCEFX_5800}, /* GeforceFX - highend */
1816 {"5800", CARD_NVIDIA_GEFORCEFX_5800}, /* GeforceFX - highend */
1817 {"5750", CARD_NVIDIA_GEFORCEFX_5600}, /* GeforceFX - midend */
1818 {"5700", CARD_NVIDIA_GEFORCEFX_5600}, /* GeforceFX - midend */
1819 {"5650", CARD_NVIDIA_GEFORCEFX_5600}, /* GeforceFX - midend */
1820 {"5600", CARD_NVIDIA_GEFORCEFX_5600}, /* GeforceFX - midend */
1821 {"5500", CARD_NVIDIA_GEFORCEFX_5200}, /* GeforceFX - lowend */
1822 {"5300", CARD_NVIDIA_GEFORCEFX_5200}, /* GeforceFX - lowend */
1823 {"5250", CARD_NVIDIA_GEFORCEFX_5200}, /* GeforceFX - lowend */
1824 {"5200", CARD_NVIDIA_GEFORCEFX_5200}, /* GeforceFX - lowend */
1825 {"5100", CARD_NVIDIA_GEFORCEFX_5200}, /* GeforceFX - lowend */
1826 /* Direct 3D 8 */
1827 {"Quadro4", CARD_NVIDIA_GEFORCE4_TI4200},
1828 {"GeForce4 Ti", CARD_NVIDIA_GEFORCE4_TI4200}, /* Geforce4 Ti4200/Ti4400/Ti4600/Ti4800 */
1829 /* Direct 3D 7 */
1830 {"GeForce4 MX", CARD_NVIDIA_GEFORCE4_MX}, /* MX420/MX440/MX460/MX4000 */
1831 {"Quadro2 MXR", CARD_NVIDIA_GEFORCE2_MX},
1832 {"GeForce2 MX", CARD_NVIDIA_GEFORCE2_MX}, /* Geforce2 standard/MX100/MX200/MX400 */
1833 {"Quadro2", CARD_NVIDIA_GEFORCE2},
1834 {"GeForce2", CARD_NVIDIA_GEFORCE2}, /* Geforce2 GTS/Pro/Ti/Ultra */
1835 /* Direct 3D 6 */
1836 {"TNT2", CARD_NVIDIA_RIVA_TNT2}, /* Riva TNT2 standard/M64/Pro/Ultra */
1838 /* See http://developer.amd.com/resources/hardware-drivers/ati-catalyst-pc-vendor-id-1002-li/
1840 * Beware: renderer string do not match exact card model,
1841 * eg HD 4800 is returned for multiple cards, even for RV790 based ones. */
1842 cards_amd_binary[] =
1844 /* Southern Islands */
1845 {"HD 7900", CARD_AMD_RADEON_HD7900},
1846 {"HD 7800", CARD_AMD_RADEON_HD7800},
1847 {"HD 7700", CARD_AMD_RADEON_HD7700},
1848 /* Northern Islands */
1849 {"HD 6970", CARD_AMD_RADEON_HD6900},
1850 {"HD 6900", CARD_AMD_RADEON_HD6900},
1851 {"HD 6800", CARD_AMD_RADEON_HD6800},
1852 {"HD 6770M", CARD_AMD_RADEON_HD6600M},
1853 {"HD 6750M", CARD_AMD_RADEON_HD6600M},
1854 {"HD 6700", CARD_AMD_RADEON_HD6700},
1855 {"HD 6670", CARD_AMD_RADEON_HD6600},
1856 {"HD 6630M", CARD_AMD_RADEON_HD6600M},
1857 {"HD 6600M", CARD_AMD_RADEON_HD6600M},
1858 {"HD 6600", CARD_AMD_RADEON_HD6600},
1859 {"HD 6570", CARD_AMD_RADEON_HD6600},
1860 {"HD 6500M", CARD_AMD_RADEON_HD6600M},
1861 {"HD 6500", CARD_AMD_RADEON_HD6600},
1862 {"HD 6400", CARD_AMD_RADEON_HD6400},
1863 {"HD 6300", CARD_AMD_RADEON_HD6300},
1864 {"HD 6200", CARD_AMD_RADEON_HD6300},
1865 /* Evergreen */
1866 {"HD 5870", CARD_AMD_RADEON_HD5800}, /* Radeon EG CYPRESS PRO */
1867 {"HD 5850", CARD_AMD_RADEON_HD5800}, /* Radeon EG CYPRESS XT */
1868 {"HD 5800", CARD_AMD_RADEON_HD5800}, /* Radeon EG CYPRESS HD58xx generic renderer string */
1869 {"HD 5770", CARD_AMD_RADEON_HD5700}, /* Radeon EG JUNIPER XT */
1870 {"HD 5750", CARD_AMD_RADEON_HD5700}, /* Radeon EG JUNIPER LE */
1871 {"HD 5700", CARD_AMD_RADEON_HD5700}, /* Radeon EG JUNIPER HD57xx generic renderer string */
1872 {"HD 5670", CARD_AMD_RADEON_HD5600}, /* Radeon EG REDWOOD XT */
1873 {"HD 5570", CARD_AMD_RADEON_HD5600}, /* Radeon EG REDWOOD PRO mapped to HD5600 series */
1874 {"HD 5550", CARD_AMD_RADEON_HD5600}, /* Radeon EG REDWOOD LE mapped to HD5600 series */
1875 {"HD 5450", CARD_AMD_RADEON_HD5400}, /* Radeon EG CEDAR PRO */
1876 {"HD 5000", CARD_AMD_RADEON_HD5600}, /* Defaulting to HD 5600 */
1877 /* R700 */
1878 {"HD 4890", CARD_AMD_RADEON_HD4800}, /* Radeon RV790 */
1879 {"HD 4870", CARD_AMD_RADEON_HD4800}, /* Radeon RV770 */
1880 {"HD 4850", CARD_AMD_RADEON_HD4800}, /* Radeon RV770 */
1881 {"HD 4830", CARD_AMD_RADEON_HD4800}, /* Radeon RV770 */
1882 {"HD 4800", CARD_AMD_RADEON_HD4800}, /* Radeon RV7xx HD48xx generic renderer string */
1883 {"HD 4770", CARD_AMD_RADEON_HD4700}, /* Radeon RV740 */
1884 {"HD 4700", CARD_AMD_RADEON_HD4700}, /* Radeon RV7xx HD47xx generic renderer string */
1885 {"HD 4670", CARD_AMD_RADEON_HD4600}, /* Radeon RV730 */
1886 {"HD 4650", CARD_AMD_RADEON_HD4600}, /* Radeon RV730 */
1887 {"HD 4600", CARD_AMD_RADEON_HD4600}, /* Radeon RV730 */
1888 {"HD 4550", CARD_AMD_RADEON_HD4350}, /* Radeon RV710 */
1889 {"HD 4350", CARD_AMD_RADEON_HD4350}, /* Radeon RV710 */
1890 /* R600/R700 integrated */
1891 {"HD 4200M", CARD_AMD_RADEON_HD4200M},
1892 {"HD 3300", CARD_AMD_RADEON_HD3200},
1893 {"HD 3200", CARD_AMD_RADEON_HD3200},
1894 {"HD 3100", CARD_AMD_RADEON_HD3200},
1895 /* R600 */
1896 {"HD 3870", CARD_AMD_RADEON_HD2900}, /* HD2900/HD3800 - highend */
1897 {"HD 3850", CARD_AMD_RADEON_HD2900}, /* HD2900/HD3800 - highend */
1898 {"HD 2900", CARD_AMD_RADEON_HD2900}, /* HD2900/HD3800 - highend */
1899 {"HD 3830", CARD_AMD_RADEON_HD2600}, /* China-only midend */
1900 {"HD 3690", CARD_AMD_RADEON_HD2600}, /* HD2600/HD3600 - midend */
1901 {"HD 3650", CARD_AMD_RADEON_HD2600}, /* HD2600/HD3600 - midend */
1902 {"HD 2600", CARD_AMD_RADEON_HD2600}, /* HD2600/HD3600 - midend */
1903 {"HD 3470", CARD_AMD_RADEON_HD2350}, /* HD2350/HD2400/HD3400 - lowend */
1904 {"HD 3450", CARD_AMD_RADEON_HD2350}, /* HD2350/HD2400/HD3400 - lowend */
1905 {"HD 3430", CARD_AMD_RADEON_HD2350}, /* HD2350/HD2400/HD3400 - lowend */
1906 {"HD 3400", CARD_AMD_RADEON_HD2350}, /* HD2350/HD2400/HD3400 - lowend */
1907 {"HD 2400", CARD_AMD_RADEON_HD2350}, /* HD2350/HD2400/HD3400 - lowend */
1908 {"HD 2350", CARD_AMD_RADEON_HD2350}, /* HD2350/HD2400/HD3400 - lowend */
1909 /* Radeon R5xx */
1910 {"X1950", CARD_AMD_RADEON_X1600},
1911 {"X1900", CARD_AMD_RADEON_X1600},
1912 {"X1800", CARD_AMD_RADEON_X1600},
1913 {"X1650", CARD_AMD_RADEON_X1600},
1914 {"X1600", CARD_AMD_RADEON_X1600},
1915 /* Radeon R4xx + X1300/X1400/X1450/X1550/X2300/X2500/HD2300 (lowend R5xx)
1916 * Note X2300/X2500/HD2300 are R5xx GPUs with a 2xxx naming but they are still DX9-only */
1917 {"HD 2300", CARD_AMD_RADEON_X700},
1918 {"X2500", CARD_AMD_RADEON_X700},
1919 {"X2300", CARD_AMD_RADEON_X700},
1920 {"X1550", CARD_AMD_RADEON_X700},
1921 {"X1450", CARD_AMD_RADEON_X700},
1922 {"X1400", CARD_AMD_RADEON_X700},
1923 {"X1300", CARD_AMD_RADEON_X700},
1924 {"X850", CARD_AMD_RADEON_X700},
1925 {"X800", CARD_AMD_RADEON_X700},
1926 {"X700", CARD_AMD_RADEON_X700},
1927 /* Radeon Xpress Series - onboard, DX9b, Shader 2.0, 300-400 MHz */
1928 {"Radeon Xpress", CARD_AMD_RADEON_XPRESS_200M},
1930 cards_intel[] =
1932 /* Haswell */
1933 {"Haswell Mobile", CARD_INTEL_HWM},
1934 /* Ivybridge */
1935 {"Ivybridge Server", CARD_INTEL_IVBS},
1936 {"Ivybridge Mobile", CARD_INTEL_IVBM},
1937 {"Ivybridge Desktop", CARD_INTEL_IVBD},
1938 /* Sandybridge */
1939 {"Sandybridge Server", CARD_INTEL_SNBS},
1940 {"Sandybridge Mobile", CARD_INTEL_SNBM},
1941 {"Sandybridge Desktop", CARD_INTEL_SNBD},
1942 /* Ironlake */
1943 {"Ironlake Mobile", CARD_INTEL_ILKM},
1944 {"Ironlake Desktop", CARD_INTEL_ILKD},
1945 /* G4x */
1946 {"B43", CARD_INTEL_B43},
1947 {"G41", CARD_INTEL_G41},
1948 {"G45", CARD_INTEL_G45},
1949 {"Q45", CARD_INTEL_Q45},
1950 {"Integrated Graphics Device", CARD_INTEL_IGD},
1951 {"GM45", CARD_INTEL_GM45},
1952 /* i965 */
1953 {"965GME", CARD_INTEL_965GME},
1954 {"965GM", CARD_INTEL_965GM},
1955 {"X3100", CARD_INTEL_965GM}, /* MacOS */
1956 {"946GZ", CARD_INTEL_946GZ},
1957 {"965G", CARD_INTEL_965G},
1958 {"965Q", CARD_INTEL_965Q},
1959 /* i945 */
1960 {"Pineview M", CARD_INTEL_PNVM},
1961 {"Pineview G", CARD_INTEL_PNVG},
1962 {"IGD", CARD_INTEL_PNVG},
1963 {"Q33", CARD_INTEL_Q33},
1964 {"G33", CARD_INTEL_G33},
1965 {"Q35", CARD_INTEL_Q35},
1966 {"945GME", CARD_INTEL_945GME},
1967 {"945GM", CARD_INTEL_945GM},
1968 {"GMA 950", CARD_INTEL_945GM}, /* MacOS */
1969 {"945G", CARD_INTEL_945G},
1970 /* i915 */
1971 {"915GM", CARD_INTEL_915GM},
1972 {"E7221G", CARD_INTEL_E7221G},
1973 {"915G", CARD_INTEL_915G},
1974 /* i8xx */
1975 {"865G", CARD_INTEL_865G},
1976 {"845G", CARD_INTEL_845G},
1977 {"855GM", CARD_INTEL_855GM},
1978 {"830M", CARD_INTEL_830M},
1980 /* 20101109 - These are never returned by current Gallium radeon
1981 * drivers: R700, RV790, R680, RV535, RV516, R410, RS485, RV360, RV351.
1983 * These are returned but not handled: RC410, RV380. */
1984 cards_amd_mesa[] =
1986 /* Sea Islands */
1987 {"HAWAII", CARD_AMD_RADEON_R9 },
1988 {"KAVERI", CARD_AMD_RADEON_R7 },
1989 {"KABINI", CARD_AMD_RADEON_R3 },
1990 {"BONAIRE", CARD_AMD_RADEON_HD8770},
1991 /* Southern Islands */
1992 {"OLAND", CARD_AMD_RADEON_HD8670},
1993 {"HAINAN", CARD_AMD_RADEON_HD8600M},
1994 {"TAHITI", CARD_AMD_RADEON_HD7900},
1995 {"PITCAIRN", CARD_AMD_RADEON_HD7800},
1996 {"CAPE VERDE", CARD_AMD_RADEON_HD7700},
1997 /* Northern Islands */
1998 {"ARUBA", CARD_AMD_RADEON_HD7660D},
1999 {"CAYMAN", CARD_AMD_RADEON_HD6900},
2000 {"BARTS", CARD_AMD_RADEON_HD6800},
2001 {"TURKS", CARD_AMD_RADEON_HD6600},
2002 {"SUMO2", CARD_AMD_RADEON_HD6410D}, /* SUMO2 first, because we do a strstr(). */
2003 {"SUMO", CARD_AMD_RADEON_HD6550D},
2004 {"CAICOS", CARD_AMD_RADEON_HD6400},
2005 {"PALM", CARD_AMD_RADEON_HD6300},
2006 /* Evergreen */
2007 {"HEMLOCK", CARD_AMD_RADEON_HD5900},
2008 {"CYPRESS", CARD_AMD_RADEON_HD5800},
2009 {"JUNIPER", CARD_AMD_RADEON_HD5700},
2010 {"REDWOOD", CARD_AMD_RADEON_HD5600},
2011 {"CEDAR", CARD_AMD_RADEON_HD5400},
2012 /* R700 */
2013 {"R700", CARD_AMD_RADEON_HD4800},
2014 {"RV790", CARD_AMD_RADEON_HD4800},
2015 {"RV770", CARD_AMD_RADEON_HD4800},
2016 {"RV740", CARD_AMD_RADEON_HD4700},
2017 {"RV730", CARD_AMD_RADEON_HD4600},
2018 {"RV710", CARD_AMD_RADEON_HD4350},
2019 /* R600/R700 integrated */
2020 {"RS880", CARD_AMD_RADEON_HD4200M},
2021 {"RS780", CARD_AMD_RADEON_HD3200},
2022 /* R600 */
2023 {"R680", CARD_AMD_RADEON_HD2900},
2024 {"R600", CARD_AMD_RADEON_HD2900},
2025 {"RV670", CARD_AMD_RADEON_HD3850},
2026 {"RV635", CARD_AMD_RADEON_HD2600},
2027 {"RV630", CARD_AMD_RADEON_HD2600},
2028 {"RV620", CARD_AMD_RADEON_HD2350},
2029 {"RV610", CARD_AMD_RADEON_HD2350},
2030 /* R500 */
2031 {"R580", CARD_AMD_RADEON_X1600},
2032 {"R520", CARD_AMD_RADEON_X1600},
2033 {"RV570", CARD_AMD_RADEON_X1600},
2034 {"RV560", CARD_AMD_RADEON_X1600},
2035 {"RV535", CARD_AMD_RADEON_X1600},
2036 {"RV530", CARD_AMD_RADEON_X1600},
2037 {"RV516", CARD_AMD_RADEON_X700},
2038 {"RV515", CARD_AMD_RADEON_X700},
2039 /* R400 */
2040 {"R481", CARD_AMD_RADEON_X700},
2041 {"R480", CARD_AMD_RADEON_X700},
2042 {"R430", CARD_AMD_RADEON_X700},
2043 {"R423", CARD_AMD_RADEON_X700},
2044 {"R420", CARD_AMD_RADEON_X700},
2045 {"R410", CARD_AMD_RADEON_X700},
2046 {"RV410", CARD_AMD_RADEON_X700},
2047 /* Radeon Xpress - onboard, DX9b, Shader 2.0, 300-400 MHz */
2048 {"RS740", CARD_AMD_RADEON_XPRESS_200M},
2049 {"RS690", CARD_AMD_RADEON_XPRESS_200M},
2050 {"RS600", CARD_AMD_RADEON_XPRESS_200M},
2051 {"RS485", CARD_AMD_RADEON_XPRESS_200M},
2052 {"RS482", CARD_AMD_RADEON_XPRESS_200M},
2053 {"RS480", CARD_AMD_RADEON_XPRESS_200M},
2054 {"RS400", CARD_AMD_RADEON_XPRESS_200M},
2055 /* R300 */
2056 {"R360", CARD_AMD_RADEON_9500},
2057 {"R350", CARD_AMD_RADEON_9500},
2058 {"R300", CARD_AMD_RADEON_9500},
2059 {"RV370", CARD_AMD_RADEON_9500},
2060 {"RV360", CARD_AMD_RADEON_9500},
2061 {"RV351", CARD_AMD_RADEON_9500},
2062 {"RV350", CARD_AMD_RADEON_9500},
2064 cards_nvidia_mesa[] =
2066 /* Maxwell */
2067 {"NV124", CARD_NVIDIA_GEFORCE_GTX970},
2068 {"NV117", CARD_NVIDIA_GEFORCE_GTX750},
2069 /* Kepler */
2070 {"NVF1", CARD_NVIDIA_GEFORCE_GTX780TI},
2071 {"NVF0", CARD_NVIDIA_GEFORCE_GTX780},
2072 {"NVE6", CARD_NVIDIA_GEFORCE_GTX770M},
2073 {"NVE4", CARD_NVIDIA_GEFORCE_GTX680},
2074 /* Fermi */
2075 {"NVD9", CARD_NVIDIA_GEFORCE_GT520},
2076 {"NVCF", CARD_NVIDIA_GEFORCE_GTX550},
2077 {"NVCE", CARD_NVIDIA_GEFORCE_GTX560},
2078 {"NVC8", CARD_NVIDIA_GEFORCE_GTX570},
2079 {"NVC4", CARD_NVIDIA_GEFORCE_GTX460},
2080 {"NVC3", CARD_NVIDIA_GEFORCE_GT440},
2081 {"NVC1", CARD_NVIDIA_GEFORCE_GT420},
2082 {"NVC0", CARD_NVIDIA_GEFORCE_GTX480},
2083 /* Tesla */
2084 {"NVAF", CARD_NVIDIA_GEFORCE_GT320M},
2085 {"NVAC", CARD_NVIDIA_GEFORCE_8200},
2086 {"NVAA", CARD_NVIDIA_GEFORCE_8200}, /* 8100 */
2087 {"NVA8", CARD_NVIDIA_GEFORCE_210},
2088 {"NVA5", CARD_NVIDIA_GEFORCE_GT220},
2089 {"NVA3", CARD_NVIDIA_GEFORCE_GT240},
2090 {"NVA0", CARD_NVIDIA_GEFORCE_GTX280},
2091 {"NV98", CARD_NVIDIA_GEFORCE_9200},
2092 {"NV96", CARD_NVIDIA_GEFORCE_9400GT},
2093 {"NV94", CARD_NVIDIA_GEFORCE_9600GT},
2094 {"NV92", CARD_NVIDIA_GEFORCE_9800GT},
2095 {"NV86", CARD_NVIDIA_GEFORCE_8500GT},
2096 {"NV84", CARD_NVIDIA_GEFORCE_8600GT},
2097 {"NV50", CARD_NVIDIA_GEFORCE_8800GTX},
2098 /* Curie */
2099 {"NV68", CARD_NVIDIA_GEFORCE_6200}, /* 7050 */
2100 {"NV67", CARD_NVIDIA_GEFORCE_6200}, /* 7000M */
2101 {"NV63", CARD_NVIDIA_GEFORCE_6200}, /* 7100 */
2102 {"NV4E", CARD_NVIDIA_GEFORCE_6200}, /* 6100 Go / 6150 Go */
2103 {"NV4C", CARD_NVIDIA_GEFORCE_6200}, /* 6150SE */
2104 {"NV4B", CARD_NVIDIA_GEFORCE_7600},
2105 {"NV4A", CARD_NVIDIA_GEFORCE_6200},
2106 {"NV49", CARD_NVIDIA_GEFORCE_7800GT}, /* 7900 */
2107 {"NV47", CARD_NVIDIA_GEFORCE_7800GT},
2108 {"NV46", CARD_NVIDIA_GEFORCE_7400},
2109 {"NV45", CARD_NVIDIA_GEFORCE_6800},
2110 {"NV44", CARD_NVIDIA_GEFORCE_6200},
2111 {"NV43", CARD_NVIDIA_GEFORCE_6600GT},
2112 {"NV42", CARD_NVIDIA_GEFORCE_6800},
2113 {"NV41", CARD_NVIDIA_GEFORCE_6800},
2114 {"NV40", CARD_NVIDIA_GEFORCE_6800},
2115 /* Rankine */
2116 {"NV38", CARD_NVIDIA_GEFORCEFX_5800}, /* FX 5950 Ultra */
2117 {"NV36", CARD_NVIDIA_GEFORCEFX_5800}, /* FX 5700/5750 */
2118 {"NV35", CARD_NVIDIA_GEFORCEFX_5800}, /* FX 5900 */
2119 {"NV34", CARD_NVIDIA_GEFORCEFX_5200},
2120 {"NV31", CARD_NVIDIA_GEFORCEFX_5600},
2121 {"NV30", CARD_NVIDIA_GEFORCEFX_5800},
2122 /* Kelvin */
2123 {"nv28", CARD_NVIDIA_GEFORCE4_TI4200},
2124 {"nv25", CARD_NVIDIA_GEFORCE4_TI4200},
2125 {"nv20", CARD_NVIDIA_GEFORCE3},
2126 /* Celsius */
2127 {"nv1F", CARD_NVIDIA_GEFORCE4_MX}, /* GF4 MX IGP */
2128 {"nv1A", CARD_NVIDIA_GEFORCE2}, /* GF2 IGP */
2129 {"nv18", CARD_NVIDIA_GEFORCE4_MX},
2130 {"nv17", CARD_NVIDIA_GEFORCE4_MX},
2131 {"nv16", CARD_NVIDIA_GEFORCE2},
2132 {"nv15", CARD_NVIDIA_GEFORCE2},
2133 {"nv11", CARD_NVIDIA_GEFORCE2_MX},
2134 {"nv10", CARD_NVIDIA_GEFORCE},
2135 /* Fahrenheit */
2136 {"nv05", CARD_NVIDIA_RIVA_TNT2},
2137 {"nv04", CARD_NVIDIA_RIVA_TNT},
2138 {"nv03", CARD_NVIDIA_RIVA_128},
2140 cards_vmware[] =
2142 {"SVGA3D", CARD_VMWARE_SVGA3D},
2145 static const struct gl_vendor_selection
2147 enum wined3d_gl_vendor gl_vendor;
2148 const char *description; /* Description of the card selector i.e. Apple OS/X Intel */
2149 const struct wined3d_renderer_table *cards; /* To be used as cards[], pointer to the first member in an array */
2150 size_t cards_size; /* Number of entries in the array above */
2152 amd_gl_vendor_table[] =
2154 {GL_VENDOR_APPLE, "Apple OSX AMD/ATI binary driver", cards_amd_binary, ARRAY_SIZE(cards_amd_binary)},
2155 {GL_VENDOR_FGLRX, "AMD/ATI binary driver", cards_amd_binary, ARRAY_SIZE(cards_amd_binary)},
2156 {GL_VENDOR_MESA, "Mesa AMD/ATI driver", cards_amd_mesa, ARRAY_SIZE(cards_amd_mesa)},
2158 nvidia_gl_vendor_table[] =
2160 {GL_VENDOR_APPLE, "Apple OSX NVidia binary driver", cards_nvidia_binary, ARRAY_SIZE(cards_nvidia_binary)},
2161 {GL_VENDOR_MESA, "Mesa Nouveau driver", cards_nvidia_mesa, ARRAY_SIZE(cards_nvidia_mesa)},
2162 {GL_VENDOR_NVIDIA, "Nvidia binary driver", cards_nvidia_binary, ARRAY_SIZE(cards_nvidia_binary)},
2164 vmware_gl_vendor_table[] =
2166 {GL_VENDOR_MESA, "VMware driver", cards_vmware, ARRAY_SIZE(cards_vmware)},
2168 intel_gl_vendor_table[] =
2170 {GL_VENDOR_APPLE, "Apple OSX Intel binary driver", cards_intel, ARRAY_SIZE(cards_intel)},
2171 {GL_VENDOR_MESA, "Mesa Intel driver", cards_intel, ARRAY_SIZE(cards_intel)},
2174 static const enum wined3d_pci_device
2175 card_fallback_nvidia[] =
2177 CARD_NVIDIA_RIVA_128, /* D3D5 */
2178 CARD_NVIDIA_RIVA_TNT, /* D3D6 */
2179 CARD_NVIDIA_GEFORCE, /* D3D7 */
2180 CARD_NVIDIA_GEFORCE3, /* D3D8 */
2181 CARD_NVIDIA_GEFORCEFX_5800, /* D3D9_SM2 */
2182 CARD_NVIDIA_GEFORCE_6800, /* D3D9_SM3 */
2183 CARD_NVIDIA_GEFORCE_8800GTX, /* D3D10 */
2184 CARD_NVIDIA_GEFORCE_GTX470, /* D3D11 */
2186 card_fallback_amd[] =
2188 CARD_AMD_RAGE_128PRO, /* D3D5 */
2189 CARD_AMD_RAGE_128PRO, /* D3D6 */
2190 CARD_AMD_RADEON_7200, /* D3D7 */
2191 CARD_AMD_RADEON_8500, /* D3D8 */
2192 CARD_AMD_RADEON_9500, /* D3D9_SM2 */
2193 CARD_AMD_RADEON_X1600, /* D3D9_SM3 */
2194 CARD_AMD_RADEON_HD2900, /* D3D10 */
2195 CARD_AMD_RADEON_HD5600, /* D3D11 */
2197 card_fallback_intel[] =
2199 CARD_INTEL_845G, /* D3D5 */
2200 CARD_INTEL_845G, /* D3D6 */
2201 CARD_INTEL_845G, /* D3D7 */
2202 CARD_INTEL_915G, /* D3D8 */
2203 CARD_INTEL_915G, /* D3D9_SM2 */
2204 CARD_INTEL_945G, /* D3D9_SM3 */
2205 CARD_INTEL_G45, /* D3D10 */
2206 CARD_INTEL_IVBD, /* D3D11 */
2208 C_ASSERT(ARRAY_SIZE(card_fallback_nvidia) == WINED3D_D3D_LEVEL_COUNT);
2209 C_ASSERT(ARRAY_SIZE(card_fallback_amd) == WINED3D_D3D_LEVEL_COUNT);
2210 C_ASSERT(ARRAY_SIZE(card_fallback_intel) == WINED3D_D3D_LEVEL_COUNT);
2212 static enum wined3d_pci_device select_card_handler(const struct gl_vendor_selection *table,
2213 unsigned int table_size, enum wined3d_gl_vendor gl_vendor, const char *gl_renderer)
2215 unsigned int i, j;
2217 for (i = 0; i < table_size; ++i)
2219 if (table[i].gl_vendor != gl_vendor)
2220 continue;
2222 TRACE("Applying card selector \"%s\".\n", table[i].description);
2224 for (j = 0; j < table[i].cards_size; ++j)
2226 if (strstr(gl_renderer, table[i].cards[j].renderer))
2227 return table[i].cards[j].id;
2229 return PCI_DEVICE_NONE;
2231 FIXME("Couldn't find a suitable card selector for GL vendor %04x (using GL_RENDERER %s)\n",
2232 gl_vendor, debugstr_a(gl_renderer));
2234 return PCI_DEVICE_NONE;
2237 static const struct
2239 enum wined3d_pci_vendor card_vendor;
2240 const char *description; /* Description of the card selector i.e. Apple OS/X Intel */
2241 const struct gl_vendor_selection *gl_vendor_selection;
2242 unsigned int gl_vendor_count;
2243 const enum wined3d_pci_device *card_fallback; /* An array with D3D_LEVEL_COUNT elements */
2245 card_vendor_table[] =
2247 {HW_VENDOR_AMD, "AMD", amd_gl_vendor_table,
2248 sizeof(amd_gl_vendor_table) / sizeof(*amd_gl_vendor_table),
2249 card_fallback_amd},
2250 {HW_VENDOR_NVIDIA, "Nvidia", nvidia_gl_vendor_table,
2251 sizeof(nvidia_gl_vendor_table) / sizeof(*nvidia_gl_vendor_table),
2252 card_fallback_nvidia},
2253 {HW_VENDOR_VMWARE, "VMware", vmware_gl_vendor_table,
2254 sizeof(vmware_gl_vendor_table) / sizeof(*vmware_gl_vendor_table),
2255 card_fallback_amd},
2256 {HW_VENDOR_INTEL, "Intel", intel_gl_vendor_table,
2257 sizeof(intel_gl_vendor_table) / sizeof(*intel_gl_vendor_table),
2258 card_fallback_intel},
2262 static enum wined3d_pci_device wined3d_guess_card(const struct shader_caps *shader_caps, const struct fragment_caps *fragment_caps,
2263 DWORD glsl_version, const char *gl_renderer, enum wined3d_gl_vendor *gl_vendor, enum wined3d_pci_vendor *card_vendor)
2265 /* A Direct3D device object contains the PCI id (vendor + device) of the
2266 * videocard which is used for rendering. Various applications use this
2267 * information to get a rough estimation of the features of the card and
2268 * some might use it for enabling 3d effects only on certain types of
2269 * videocards. In some cases games might even use it to work around bugs
2270 * which happen on certain videocards/driver combinations. The problem is
2271 * that OpenGL only exposes a rendering string containing the name of the
2272 * videocard and not the PCI id.
2274 * Various games depend on the PCI id, so somehow we need to provide one.
2275 * A simple option is to parse the renderer string and translate this to
2276 * the right PCI id. This is a lot of work because there are more than 200
2277 * GPUs just for Nvidia. Various cards share the same renderer string, so
2278 * the amount of code might be 'small' but there are quite a number of
2279 * exceptions which would make this a pain to maintain. Another way would
2280 * be to query the PCI id from the operating system (assuming this is the
2281 * videocard which is used for rendering which is not always the case).
2282 * This would work but it is not very portable. Second it would not work
2283 * well in, let's say, a remote X situation in which the amount of 3d
2284 * features which can be used is limited.
2286 * As said most games only use the PCI id to get an indication of the
2287 * capabilities of the card. It doesn't really matter if the given id is
2288 * the correct one if we return the id of a card with similar 3d features.
2290 * The code below checks the OpenGL capabilities of a videocard and matches
2291 * that to a certain level of Direct3D functionality. Once a card passes
2292 * the Direct3D9 check, we know that the card (in case of Nvidia) is at
2293 * least a GeforceFX. To give a better estimate we do a basic check on the
2294 * renderer string but if that won't pass we return a default card. This
2295 * way is better than maintaining a full card database as even without a
2296 * full database we can return a card with similar features. Second the
2297 * size of the database can be made quite small because when you know what
2298 * type of 3d functionality a card has, you know to which GPU family the
2299 * GPU must belong. Because of this you only have to check a small part of
2300 * the renderer string to distinguish between different models from that
2301 * family.
2303 * The code also selects a default amount of video memory which we will
2304 * use for an estimation of the amount of free texture memory. In case of
2305 * real D3D the amount of texture memory includes video memory and system
2306 * memory (to be specific AGP memory or in case of PCIE TurboCache /
2307 * HyperMemory). We don't know how much system memory can be addressed by
2308 * the system but we can make a reasonable estimation about the amount of
2309 * video memory. If the value is slightly wrong it doesn't matter as we
2310 * didn't include AGP-like memory which makes the amount of addressable
2311 * memory higher and second OpenGL isn't that critical it moves to system
2312 * memory behind our backs if really needed. Note that the amount of video
2313 * memory can be overruled using a registry setting. */
2315 unsigned int i;
2316 enum wined3d_d3d_level d3d_level = d3d_level_from_caps(shader_caps, fragment_caps, glsl_version);
2317 enum wined3d_pci_device device;
2319 for (i = 0; i < (sizeof(card_vendor_table) / sizeof(*card_vendor_table)); ++i)
2321 if (card_vendor_table[i].card_vendor != *card_vendor)
2322 continue;
2324 TRACE("Applying card selector \"%s\".\n", card_vendor_table[i].description);
2325 device = select_card_handler(card_vendor_table[i].gl_vendor_selection,
2326 card_vendor_table[i].gl_vendor_count, *gl_vendor, gl_renderer);
2327 if (device != PCI_DEVICE_NONE)
2328 return device;
2330 TRACE("Unrecognized renderer %s, falling back to default.\n", debugstr_a(gl_renderer));
2331 return card_vendor_table[i].card_fallback[d3d_level];
2334 FIXME("No card selector available for card vendor %04x (using GL_RENDERER %s).\n",
2335 *card_vendor, debugstr_a(gl_renderer));
2337 /* Default to generic Nvidia hardware based on the supported OpenGL extensions. */
2338 *card_vendor = HW_VENDOR_NVIDIA;
2339 return card_fallback_nvidia[d3d_level];
2342 static const struct wined3d_vertex_pipe_ops *select_vertex_implementation(const struct wined3d_gl_info *gl_info,
2343 const struct wined3d_shader_backend_ops *shader_backend_ops)
2345 if (shader_backend_ops == &glsl_shader_backend)
2346 return &glsl_vertex_pipe;
2347 return &ffp_vertex_pipe;
2350 static const struct fragment_pipeline *select_fragment_implementation(const struct wined3d_gl_info *gl_info,
2351 const struct wined3d_shader_backend_ops *shader_backend_ops)
2353 if (shader_backend_ops == &glsl_shader_backend)
2354 return &glsl_fragment_pipe;
2355 if (shader_backend_ops == &arb_program_shader_backend && gl_info->supported[ARB_FRAGMENT_PROGRAM])
2356 return &arbfp_fragment_pipeline;
2357 if (gl_info->supported[ATI_FRAGMENT_SHADER])
2358 return &atifs_fragment_pipeline;
2359 if (gl_info->supported[NV_REGISTER_COMBINERS] && gl_info->supported[NV_TEXTURE_SHADER2])
2360 return &nvts_fragment_pipeline;
2361 if (gl_info->supported[NV_REGISTER_COMBINERS])
2362 return &nvrc_fragment_pipeline;
2363 return &ffp_fragment_pipeline;
2366 static const struct wined3d_shader_backend_ops *select_shader_backend(const struct wined3d_gl_info *gl_info)
2368 BOOL glsl = wined3d_settings.glslRequested && gl_info->glsl_version >= MAKEDWORD_VERSION(1, 20);
2370 if (glsl && gl_info->supported[ARB_FRAGMENT_SHADER])
2371 return &glsl_shader_backend;
2372 if (glsl && gl_info->supported[ARB_VERTEX_SHADER])
2374 /* Geforce4 cards support GLSL but for vertex shaders only. Further
2375 * its reported GLSL caps are wrong. This combined with the fact that
2376 * GLSL won't offer more features or performance, use ARB shaders only
2377 * on this card. */
2378 if (gl_info->supported[NV_VERTEX_PROGRAM] && !gl_info->supported[NV_VERTEX_PROGRAM2])
2379 return &arb_program_shader_backend;
2380 return &glsl_shader_backend;
2382 if (gl_info->supported[ARB_VERTEX_PROGRAM] || gl_info->supported[ARB_FRAGMENT_PROGRAM])
2383 return &arb_program_shader_backend;
2384 return &none_shader_backend;
2387 static const struct blit_shader *select_blit_implementation(const struct wined3d_gl_info *gl_info,
2388 const struct wined3d_shader_backend_ops *shader_backend_ops)
2390 if ((shader_backend_ops == &glsl_shader_backend
2391 || shader_backend_ops == &arb_program_shader_backend)
2392 && gl_info->supported[ARB_FRAGMENT_PROGRAM])
2393 return &arbfp_blit;
2394 return &ffp_blit;
2397 static void parse_extension_string(struct wined3d_gl_info *gl_info, const char *extensions,
2398 const struct wined3d_extension_map *map, UINT entry_count)
2400 while (*extensions)
2402 const char *start;
2403 size_t len;
2404 UINT i;
2406 while (isspace(*extensions))
2407 ++extensions;
2408 start = extensions;
2409 while (!isspace(*extensions) && *extensions)
2410 ++extensions;
2412 len = extensions - start;
2413 if (!len)
2414 continue;
2416 TRACE("- %s.\n", debugstr_an(start, len));
2418 for (i = 0; i < entry_count; ++i)
2420 if (len == strlen(map[i].extension_string)
2421 && !memcmp(start, map[i].extension_string, len))
2423 TRACE(" FOUND: %s support.\n", map[i].extension_string);
2424 gl_info->supported[map[i].extension] = TRUE;
2425 break;
2431 static void enumerate_gl_extensions(struct wined3d_gl_info *gl_info,
2432 const struct wined3d_extension_map *map, unsigned int map_entries_count)
2434 const char *gl_extension_name;
2435 unsigned int i, j;
2436 GLint extensions_count;
2438 glGetIntegerv(GL_NUM_EXTENSIONS, &extensions_count);
2439 for (i = 0; i < extensions_count; ++i)
2441 gl_extension_name = (const char *)GL_EXTCALL(glGetStringi(GL_EXTENSIONS, i));
2442 TRACE("- %s.\n", debugstr_a(gl_extension_name));
2443 for (j = 0; j < map_entries_count; ++j)
2445 if (!strcmp(gl_extension_name, map[j].extension_string))
2447 TRACE("FOUND: %s support.\n", map[j].extension_string);
2448 gl_info->supported[map[j].extension] = TRUE;
2449 break;
2455 static void load_gl_funcs(struct wined3d_gl_info *gl_info)
2457 #define USE_GL_FUNC(pfn) gl_info->gl_ops.ext.p_##pfn = (void *)wglGetProcAddress(#pfn);
2458 /* GL_APPLE_fence */
2459 USE_GL_FUNC(glDeleteFencesAPPLE)
2460 USE_GL_FUNC(glFinishFenceAPPLE)
2461 USE_GL_FUNC(glFinishObjectAPPLE)
2462 USE_GL_FUNC(glGenFencesAPPLE)
2463 USE_GL_FUNC(glIsFenceAPPLE)
2464 USE_GL_FUNC(glSetFenceAPPLE)
2465 USE_GL_FUNC(glTestFenceAPPLE)
2466 USE_GL_FUNC(glTestObjectAPPLE)
2467 /* GL_APPLE_flush_buffer_range */
2468 USE_GL_FUNC(glBufferParameteriAPPLE)
2469 USE_GL_FUNC(glFlushMappedBufferRangeAPPLE)
2470 /* GL_ARB_blend_func_extended */
2471 USE_GL_FUNC(glBindFragDataLocationIndexed)
2472 USE_GL_FUNC(glGetFragDataIndex)
2473 /* GL_ARB_color_buffer_float */
2474 USE_GL_FUNC(glClampColorARB)
2475 /* GL_ARB_debug_output */
2476 USE_GL_FUNC(glDebugMessageCallbackARB)
2477 USE_GL_FUNC(glDebugMessageControlARB)
2478 USE_GL_FUNC(glDebugMessageInsertARB)
2479 USE_GL_FUNC(glGetDebugMessageLogARB)
2480 /* GL_ARB_draw_buffers */
2481 USE_GL_FUNC(glDrawBuffersARB)
2482 /* GL_ARB_draw_elements_base_vertex */
2483 USE_GL_FUNC(glDrawElementsBaseVertex)
2484 USE_GL_FUNC(glDrawElementsInstancedBaseVertex)
2485 USE_GL_FUNC(glDrawRangeElementsBaseVertex)
2486 USE_GL_FUNC(glMultiDrawElementsBaseVertex)
2487 /* GL_ARB_draw_instanced */
2488 USE_GL_FUNC(glDrawArraysInstancedARB)
2489 USE_GL_FUNC(glDrawElementsInstancedARB)
2490 /* GL_ARB_ES2_compatibility */
2491 USE_GL_FUNC(glReleaseShaderCompiler)
2492 USE_GL_FUNC(glShaderBinary)
2493 USE_GL_FUNC(glGetShaderPrecisionFormat)
2494 USE_GL_FUNC(glDepthRangef)
2495 USE_GL_FUNC(glClearDepthf)
2496 /* GL_ARB_framebuffer_object */
2497 USE_GL_FUNC(glBindFramebuffer)
2498 USE_GL_FUNC(glBindRenderbuffer)
2499 USE_GL_FUNC(glBlitFramebuffer)
2500 USE_GL_FUNC(glCheckFramebufferStatus)
2501 USE_GL_FUNC(glDeleteFramebuffers)
2502 USE_GL_FUNC(glDeleteRenderbuffers)
2503 USE_GL_FUNC(glFramebufferRenderbuffer)
2504 USE_GL_FUNC(glFramebufferTexture1D)
2505 USE_GL_FUNC(glFramebufferTexture2D)
2506 USE_GL_FUNC(glFramebufferTexture3D)
2507 USE_GL_FUNC(glFramebufferTextureLayer)
2508 USE_GL_FUNC(glGenFramebuffers)
2509 USE_GL_FUNC(glGenRenderbuffers)
2510 USE_GL_FUNC(glGenerateMipmap)
2511 USE_GL_FUNC(glGetFramebufferAttachmentParameteriv)
2512 USE_GL_FUNC(glGetRenderbufferParameteriv)
2513 USE_GL_FUNC(glIsFramebuffer)
2514 USE_GL_FUNC(glIsRenderbuffer)
2515 USE_GL_FUNC(glRenderbufferStorage)
2516 USE_GL_FUNC(glRenderbufferStorageMultisample)
2517 /* GL_ARB_geometry_shader4 */
2518 USE_GL_FUNC(glFramebufferTextureARB)
2519 USE_GL_FUNC(glFramebufferTextureFaceARB)
2520 USE_GL_FUNC(glFramebufferTextureLayerARB)
2521 USE_GL_FUNC(glProgramParameteriARB)
2522 /* GL_ARB_instanced_arrays */
2523 USE_GL_FUNC(glVertexAttribDivisorARB)
2524 /* GL_ARB_internalformat_query */
2525 USE_GL_FUNC(glGetInternalformativ)
2526 /* GL_ARB_internalformat_query2 */
2527 USE_GL_FUNC(glGetInternalformati64v)
2528 /* GL_ARB_map_buffer_range */
2529 USE_GL_FUNC(glFlushMappedBufferRange)
2530 USE_GL_FUNC(glMapBufferRange)
2531 /* GL_ARB_multisample */
2532 USE_GL_FUNC(glSampleCoverageARB)
2533 /* GL_ARB_multitexture */
2534 USE_GL_FUNC(glActiveTextureARB)
2535 USE_GL_FUNC(glClientActiveTextureARB)
2536 USE_GL_FUNC(glMultiTexCoord1fARB)
2537 USE_GL_FUNC(glMultiTexCoord1fvARB)
2538 USE_GL_FUNC(glMultiTexCoord2fARB)
2539 USE_GL_FUNC(glMultiTexCoord2fvARB)
2540 USE_GL_FUNC(glMultiTexCoord2svARB)
2541 USE_GL_FUNC(glMultiTexCoord3fARB)
2542 USE_GL_FUNC(glMultiTexCoord3fvARB)
2543 USE_GL_FUNC(glMultiTexCoord4fARB)
2544 USE_GL_FUNC(glMultiTexCoord4fvARB)
2545 USE_GL_FUNC(glMultiTexCoord4svARB)
2546 /* GL_ARB_occlusion_query */
2547 USE_GL_FUNC(glBeginQueryARB)
2548 USE_GL_FUNC(glDeleteQueriesARB)
2549 USE_GL_FUNC(glEndQueryARB)
2550 USE_GL_FUNC(glGenQueriesARB)
2551 USE_GL_FUNC(glGetQueryivARB)
2552 USE_GL_FUNC(glGetQueryObjectivARB)
2553 USE_GL_FUNC(glGetQueryObjectuivARB)
2554 USE_GL_FUNC(glIsQueryARB)
2555 /* GL_ARB_point_parameters */
2556 USE_GL_FUNC(glPointParameterfARB)
2557 USE_GL_FUNC(glPointParameterfvARB)
2558 /* GL_ARB_provoking_vertex */
2559 USE_GL_FUNC(glProvokingVertex)
2560 /* GL_ARB_sampler_objects */
2561 USE_GL_FUNC(glGenSamplers)
2562 USE_GL_FUNC(glDeleteSamplers)
2563 USE_GL_FUNC(glIsSampler)
2564 USE_GL_FUNC(glBindSampler)
2565 USE_GL_FUNC(glSamplerParameteri)
2566 USE_GL_FUNC(glSamplerParameterf)
2567 USE_GL_FUNC(glSamplerParameteriv)
2568 USE_GL_FUNC(glSamplerParameterfv)
2569 USE_GL_FUNC(glSamplerParameterIiv)
2570 USE_GL_FUNC(glSamplerParameterIuiv)
2571 USE_GL_FUNC(glGetSamplerParameteriv)
2572 USE_GL_FUNC(glGetSamplerParameterfv)
2573 USE_GL_FUNC(glGetSamplerParameterIiv)
2574 USE_GL_FUNC(glGetSamplerParameterIuiv)
2575 /* GL_ARB_shader_objects */
2576 USE_GL_FUNC(glAttachObjectARB)
2577 USE_GL_FUNC(glBindAttribLocationARB)
2578 USE_GL_FUNC(glCompileShaderARB)
2579 USE_GL_FUNC(glCreateProgramObjectARB)
2580 USE_GL_FUNC(glCreateShaderObjectARB)
2581 USE_GL_FUNC(glDeleteObjectARB)
2582 USE_GL_FUNC(glDetachObjectARB)
2583 USE_GL_FUNC(glGetActiveUniformARB)
2584 USE_GL_FUNC(glGetAttachedObjectsARB)
2585 USE_GL_FUNC(glGetAttribLocationARB)
2586 USE_GL_FUNC(glGetHandleARB)
2587 USE_GL_FUNC(glGetInfoLogARB)
2588 USE_GL_FUNC(glGetObjectParameterfvARB)
2589 USE_GL_FUNC(glGetObjectParameterivARB)
2590 USE_GL_FUNC(glGetShaderSourceARB)
2591 USE_GL_FUNC(glGetUniformLocationARB)
2592 USE_GL_FUNC(glGetUniformfvARB)
2593 USE_GL_FUNC(glGetUniformivARB)
2594 USE_GL_FUNC(glLinkProgramARB)
2595 USE_GL_FUNC(glShaderSourceARB)
2596 USE_GL_FUNC(glUniform1fARB)
2597 USE_GL_FUNC(glUniform1fvARB)
2598 USE_GL_FUNC(glUniform1iARB)
2599 USE_GL_FUNC(glUniform1ivARB)
2600 USE_GL_FUNC(glUniform2fARB)
2601 USE_GL_FUNC(glUniform2fvARB)
2602 USE_GL_FUNC(glUniform2iARB)
2603 USE_GL_FUNC(glUniform2ivARB)
2604 USE_GL_FUNC(glUniform3fARB)
2605 USE_GL_FUNC(glUniform3fvARB)
2606 USE_GL_FUNC(glUniform3iARB)
2607 USE_GL_FUNC(glUniform3ivARB)
2608 USE_GL_FUNC(glUniform4fARB)
2609 USE_GL_FUNC(glUniform4fvARB)
2610 USE_GL_FUNC(glUniform4iARB)
2611 USE_GL_FUNC(glUniform4ivARB)
2612 USE_GL_FUNC(glUniformMatrix2fvARB)
2613 USE_GL_FUNC(glUniformMatrix3fvARB)
2614 USE_GL_FUNC(glUniformMatrix4fvARB)
2615 USE_GL_FUNC(glUseProgramObjectARB)
2616 USE_GL_FUNC(glValidateProgramARB)
2617 /* GL_ARB_sync */
2618 USE_GL_FUNC(glClientWaitSync)
2619 USE_GL_FUNC(glDeleteSync)
2620 USE_GL_FUNC(glFenceSync)
2621 USE_GL_FUNC(glGetInteger64v)
2622 USE_GL_FUNC(glGetSynciv)
2623 USE_GL_FUNC(glIsSync)
2624 USE_GL_FUNC(glWaitSync)
2625 /* GL_ARB_texture_compression */
2626 USE_GL_FUNC(glCompressedTexImage2DARB)
2627 USE_GL_FUNC(glCompressedTexImage3DARB)
2628 USE_GL_FUNC(glCompressedTexSubImage2DARB)
2629 USE_GL_FUNC(glCompressedTexSubImage3DARB)
2630 USE_GL_FUNC(glGetCompressedTexImageARB)
2631 /* GL_ARB_timer_query */
2632 USE_GL_FUNC(glQueryCounter)
2633 USE_GL_FUNC(glGetQueryObjectui64v)
2634 /* GL_ARB_uniform_buffer_object */
2635 USE_GL_FUNC(glBindBufferBase)
2636 USE_GL_FUNC(glBindBufferRange)
2637 USE_GL_FUNC(glGetActiveUniformBlockName)
2638 USE_GL_FUNC(glGetActiveUniformBlockiv)
2639 USE_GL_FUNC(glGetActiveUniformName)
2640 USE_GL_FUNC(glGetActiveUniformsiv)
2641 USE_GL_FUNC(glGetIntegeri_v)
2642 USE_GL_FUNC(glGetUniformBlockIndex)
2643 USE_GL_FUNC(glGetUniformIndices)
2644 USE_GL_FUNC(glUniformBlockBinding)
2645 /* GL_ARB_vertex_blend */
2646 USE_GL_FUNC(glVertexBlendARB)
2647 USE_GL_FUNC(glWeightPointerARB)
2648 USE_GL_FUNC(glWeightbvARB)
2649 USE_GL_FUNC(glWeightdvARB)
2650 USE_GL_FUNC(glWeightfvARB)
2651 USE_GL_FUNC(glWeightivARB)
2652 USE_GL_FUNC(glWeightsvARB)
2653 USE_GL_FUNC(glWeightubvARB)
2654 USE_GL_FUNC(glWeightuivARB)
2655 USE_GL_FUNC(glWeightusvARB)
2656 /* GL_ARB_vertex_buffer_object */
2657 USE_GL_FUNC(glBindBufferARB)
2658 USE_GL_FUNC(glBufferDataARB)
2659 USE_GL_FUNC(glBufferSubDataARB)
2660 USE_GL_FUNC(glDeleteBuffersARB)
2661 USE_GL_FUNC(glGenBuffersARB)
2662 USE_GL_FUNC(glGetBufferParameterivARB)
2663 USE_GL_FUNC(glGetBufferPointervARB)
2664 USE_GL_FUNC(glGetBufferSubDataARB)
2665 USE_GL_FUNC(glIsBufferARB)
2666 USE_GL_FUNC(glMapBufferARB)
2667 USE_GL_FUNC(glUnmapBufferARB)
2668 /* GL_ARB_vertex_program */
2669 USE_GL_FUNC(glBindProgramARB)
2670 USE_GL_FUNC(glDeleteProgramsARB)
2671 USE_GL_FUNC(glDisableVertexAttribArrayARB)
2672 USE_GL_FUNC(glEnableVertexAttribArrayARB)
2673 USE_GL_FUNC(glGenProgramsARB)
2674 USE_GL_FUNC(glGetProgramivARB)
2675 USE_GL_FUNC(glProgramEnvParameter4fvARB)
2676 USE_GL_FUNC(glProgramLocalParameter4fvARB)
2677 USE_GL_FUNC(glProgramStringARB)
2678 USE_GL_FUNC(glVertexAttrib1dARB)
2679 USE_GL_FUNC(glVertexAttrib1dvARB)
2680 USE_GL_FUNC(glVertexAttrib1fARB)
2681 USE_GL_FUNC(glVertexAttrib1fvARB)
2682 USE_GL_FUNC(glVertexAttrib1sARB)
2683 USE_GL_FUNC(glVertexAttrib1svARB)
2684 USE_GL_FUNC(glVertexAttrib2dARB)
2685 USE_GL_FUNC(glVertexAttrib2dvARB)
2686 USE_GL_FUNC(glVertexAttrib2fARB)
2687 USE_GL_FUNC(glVertexAttrib2fvARB)
2688 USE_GL_FUNC(glVertexAttrib2sARB)
2689 USE_GL_FUNC(glVertexAttrib2svARB)
2690 USE_GL_FUNC(glVertexAttrib3dARB)
2691 USE_GL_FUNC(glVertexAttrib3dvARB)
2692 USE_GL_FUNC(glVertexAttrib3fARB)
2693 USE_GL_FUNC(glVertexAttrib3fvARB)
2694 USE_GL_FUNC(glVertexAttrib3sARB)
2695 USE_GL_FUNC(glVertexAttrib3svARB)
2696 USE_GL_FUNC(glVertexAttrib4NbvARB)
2697 USE_GL_FUNC(glVertexAttrib4NivARB)
2698 USE_GL_FUNC(glVertexAttrib4NsvARB)
2699 USE_GL_FUNC(glVertexAttrib4NubARB)
2700 USE_GL_FUNC(glVertexAttrib4NubvARB)
2701 USE_GL_FUNC(glVertexAttrib4NuivARB)
2702 USE_GL_FUNC(glVertexAttrib4NusvARB)
2703 USE_GL_FUNC(glVertexAttrib4bvARB)
2704 USE_GL_FUNC(glVertexAttrib4dARB)
2705 USE_GL_FUNC(glVertexAttrib4dvARB)
2706 USE_GL_FUNC(glVertexAttrib4fARB)
2707 USE_GL_FUNC(glVertexAttrib4fvARB)
2708 USE_GL_FUNC(glVertexAttrib4ivARB)
2709 USE_GL_FUNC(glVertexAttrib4sARB)
2710 USE_GL_FUNC(glVertexAttrib4svARB)
2711 USE_GL_FUNC(glVertexAttrib4ubvARB)
2712 USE_GL_FUNC(glVertexAttrib4uivARB)
2713 USE_GL_FUNC(glVertexAttrib4usvARB)
2714 USE_GL_FUNC(glVertexAttribPointerARB)
2715 /* GL_ATI_fragment_shader */
2716 USE_GL_FUNC(glAlphaFragmentOp1ATI)
2717 USE_GL_FUNC(glAlphaFragmentOp2ATI)
2718 USE_GL_FUNC(glAlphaFragmentOp3ATI)
2719 USE_GL_FUNC(glBeginFragmentShaderATI)
2720 USE_GL_FUNC(glBindFragmentShaderATI)
2721 USE_GL_FUNC(glColorFragmentOp1ATI)
2722 USE_GL_FUNC(glColorFragmentOp2ATI)
2723 USE_GL_FUNC(glColorFragmentOp3ATI)
2724 USE_GL_FUNC(glDeleteFragmentShaderATI)
2725 USE_GL_FUNC(glEndFragmentShaderATI)
2726 USE_GL_FUNC(glGenFragmentShadersATI)
2727 USE_GL_FUNC(glPassTexCoordATI)
2728 USE_GL_FUNC(glSampleMapATI)
2729 USE_GL_FUNC(glSetFragmentShaderConstantATI)
2730 /* GL_ATI_separate_stencil */
2731 USE_GL_FUNC(glStencilOpSeparateATI)
2732 USE_GL_FUNC(glStencilFuncSeparateATI)
2733 /* GL_EXT_blend_color */
2734 USE_GL_FUNC(glBlendColorEXT)
2735 /* GL_EXT_blend_equation_separate */
2736 USE_GL_FUNC(glBlendFuncSeparateEXT)
2737 /* GL_EXT_blend_func_separate */
2738 USE_GL_FUNC(glBlendEquationSeparateEXT)
2739 /* GL_EXT_blend_minmax */
2740 USE_GL_FUNC(glBlendEquationEXT)
2741 /* GL_EXT_depth_bounds_test */
2742 USE_GL_FUNC(glDepthBoundsEXT)
2743 /* GL_EXT_draw_buffers2 */
2744 USE_GL_FUNC(glColorMaskIndexedEXT)
2745 USE_GL_FUNC(glDisableIndexedEXT)
2746 USE_GL_FUNC(glEnableIndexedEXT)
2747 USE_GL_FUNC(glGetBooleanIndexedvEXT)
2748 USE_GL_FUNC(glGetIntegerIndexedvEXT)
2749 USE_GL_FUNC(glIsEnabledIndexedEXT)
2750 /* GL_EXT_fog_coord */
2751 USE_GL_FUNC(glFogCoordPointerEXT)
2752 USE_GL_FUNC(glFogCoorddEXT)
2753 USE_GL_FUNC(glFogCoorddvEXT)
2754 USE_GL_FUNC(glFogCoordfEXT)
2755 USE_GL_FUNC(glFogCoordfvEXT)
2756 /* GL_EXT_framebuffer_blit */
2757 USE_GL_FUNC(glBlitFramebufferEXT)
2758 /* GL_EXT_framebuffer_multisample */
2759 USE_GL_FUNC(glRenderbufferStorageMultisampleEXT)
2760 /* GL_EXT_framebuffer_object */
2761 USE_GL_FUNC(glBindFramebufferEXT)
2762 USE_GL_FUNC(glBindRenderbufferEXT)
2763 USE_GL_FUNC(glCheckFramebufferStatusEXT)
2764 USE_GL_FUNC(glDeleteFramebuffersEXT)
2765 USE_GL_FUNC(glDeleteRenderbuffersEXT)
2766 USE_GL_FUNC(glFramebufferRenderbufferEXT)
2767 USE_GL_FUNC(glFramebufferTexture1DEXT)
2768 USE_GL_FUNC(glFramebufferTexture2DEXT)
2769 USE_GL_FUNC(glFramebufferTexture3DEXT)
2770 USE_GL_FUNC(glGenFramebuffersEXT)
2771 USE_GL_FUNC(glGenRenderbuffersEXT)
2772 USE_GL_FUNC(glGenerateMipmapEXT)
2773 USE_GL_FUNC(glGetFramebufferAttachmentParameterivEXT)
2774 USE_GL_FUNC(glGetRenderbufferParameterivEXT)
2775 USE_GL_FUNC(glIsFramebufferEXT)
2776 USE_GL_FUNC(glIsRenderbufferEXT)
2777 USE_GL_FUNC(glRenderbufferStorageEXT)
2778 /* GL_EXT_gpu_program_parameters */
2779 USE_GL_FUNC(glProgramEnvParameters4fvEXT)
2780 USE_GL_FUNC(glProgramLocalParameters4fvEXT)
2781 /* GL_EXT_gpu_shader4 */
2782 USE_GL_FUNC(glBindFragDataLocationEXT)
2783 USE_GL_FUNC(glGetFragDataLocationEXT)
2784 USE_GL_FUNC(glGetUniformuivEXT)
2785 USE_GL_FUNC(glGetVertexAttribIivEXT)
2786 USE_GL_FUNC(glGetVertexAttribIuivEXT)
2787 USE_GL_FUNC(glUniform1uiEXT)
2788 USE_GL_FUNC(glUniform1uivEXT)
2789 USE_GL_FUNC(glUniform2uiEXT)
2790 USE_GL_FUNC(glUniform2uivEXT)
2791 USE_GL_FUNC(glUniform3uiEXT)
2792 USE_GL_FUNC(glUniform3uivEXT)
2793 USE_GL_FUNC(glUniform4uiEXT)
2794 USE_GL_FUNC(glUniform4uivEXT)
2795 USE_GL_FUNC(glVertexAttribI1iEXT)
2796 USE_GL_FUNC(glVertexAttribI1ivEXT)
2797 USE_GL_FUNC(glVertexAttribI1uiEXT)
2798 USE_GL_FUNC(glVertexAttribI1uivEXT)
2799 USE_GL_FUNC(glVertexAttribI2iEXT)
2800 USE_GL_FUNC(glVertexAttribI2ivEXT)
2801 USE_GL_FUNC(glVertexAttribI2uiEXT)
2802 USE_GL_FUNC(glVertexAttribI2uivEXT)
2803 USE_GL_FUNC(glVertexAttribI3iEXT)
2804 USE_GL_FUNC(glVertexAttribI3ivEXT)
2805 USE_GL_FUNC(glVertexAttribI3uiEXT)
2806 USE_GL_FUNC(glVertexAttribI3uivEXT)
2807 USE_GL_FUNC(glVertexAttribI4bvEXT)
2808 USE_GL_FUNC(glVertexAttribI4iEXT)
2809 USE_GL_FUNC(glVertexAttribI4ivEXT)
2810 USE_GL_FUNC(glVertexAttribI4svEXT)
2811 USE_GL_FUNC(glVertexAttribI4ubvEXT)
2812 USE_GL_FUNC(glVertexAttribI4uiEXT)
2813 USE_GL_FUNC(glVertexAttribI4uivEXT)
2814 USE_GL_FUNC(glVertexAttribI4usvEXT)
2815 USE_GL_FUNC(glVertexAttribIPointerEXT)
2816 /* GL_EXT_point_parameters */
2817 USE_GL_FUNC(glPointParameterfEXT)
2818 USE_GL_FUNC(glPointParameterfvEXT)
2819 /* GL_EXT_provoking_vertex */
2820 USE_GL_FUNC(glProvokingVertexEXT)
2821 /* GL_EXT_secondary_color */
2822 USE_GL_FUNC(glSecondaryColor3fEXT)
2823 USE_GL_FUNC(glSecondaryColor3fvEXT)
2824 USE_GL_FUNC(glSecondaryColor3ubEXT)
2825 USE_GL_FUNC(glSecondaryColor3ubvEXT)
2826 USE_GL_FUNC(glSecondaryColorPointerEXT)
2827 /* GL_EXT_stencil_two_side */
2828 USE_GL_FUNC(glActiveStencilFaceEXT)
2829 /* GL_EXT_texture3D */
2830 USE_GL_FUNC(glTexImage3D)
2831 USE_GL_FUNC(glTexImage3DEXT)
2832 USE_GL_FUNC(glTexSubImage3D)
2833 USE_GL_FUNC(glTexSubImage3DEXT)
2834 /* GL_NV_fence */
2835 USE_GL_FUNC(glDeleteFencesNV)
2836 USE_GL_FUNC(glFinishFenceNV)
2837 USE_GL_FUNC(glGenFencesNV)
2838 USE_GL_FUNC(glGetFenceivNV)
2839 USE_GL_FUNC(glIsFenceNV)
2840 USE_GL_FUNC(glSetFenceNV)
2841 USE_GL_FUNC(glTestFenceNV)
2842 /* GL_NV_half_float */
2843 USE_GL_FUNC(glColor3hNV)
2844 USE_GL_FUNC(glColor3hvNV)
2845 USE_GL_FUNC(glColor4hNV)
2846 USE_GL_FUNC(glColor4hvNV)
2847 USE_GL_FUNC(glFogCoordhNV)
2848 USE_GL_FUNC(glFogCoordhvNV)
2849 USE_GL_FUNC(glMultiTexCoord1hNV)
2850 USE_GL_FUNC(glMultiTexCoord1hvNV)
2851 USE_GL_FUNC(glMultiTexCoord2hNV)
2852 USE_GL_FUNC(glMultiTexCoord2hvNV)
2853 USE_GL_FUNC(glMultiTexCoord3hNV)
2854 USE_GL_FUNC(glMultiTexCoord3hvNV)
2855 USE_GL_FUNC(glMultiTexCoord4hNV)
2856 USE_GL_FUNC(glMultiTexCoord4hvNV)
2857 USE_GL_FUNC(glNormal3hNV)
2858 USE_GL_FUNC(glNormal3hvNV)
2859 USE_GL_FUNC(glSecondaryColor3hNV)
2860 USE_GL_FUNC(glSecondaryColor3hvNV)
2861 USE_GL_FUNC(glTexCoord1hNV)
2862 USE_GL_FUNC(glTexCoord1hvNV)
2863 USE_GL_FUNC(glTexCoord2hNV)
2864 USE_GL_FUNC(glTexCoord2hvNV)
2865 USE_GL_FUNC(glTexCoord3hNV)
2866 USE_GL_FUNC(glTexCoord3hvNV)
2867 USE_GL_FUNC(glTexCoord4hNV)
2868 USE_GL_FUNC(glTexCoord4hvNV)
2869 USE_GL_FUNC(glVertex2hNV)
2870 USE_GL_FUNC(glVertex2hvNV)
2871 USE_GL_FUNC(glVertex3hNV)
2872 USE_GL_FUNC(glVertex3hvNV)
2873 USE_GL_FUNC(glVertex4hNV)
2874 USE_GL_FUNC(glVertex4hvNV)
2875 USE_GL_FUNC(glVertexAttrib1hNV)
2876 USE_GL_FUNC(glVertexAttrib1hvNV)
2877 USE_GL_FUNC(glVertexAttrib2hNV)
2878 USE_GL_FUNC(glVertexAttrib2hvNV)
2879 USE_GL_FUNC(glVertexAttrib3hNV)
2880 USE_GL_FUNC(glVertexAttrib3hvNV)
2881 USE_GL_FUNC(glVertexAttrib4hNV)
2882 USE_GL_FUNC(glVertexAttrib4hvNV)
2883 USE_GL_FUNC(glVertexAttribs1hvNV)
2884 USE_GL_FUNC(glVertexAttribs2hvNV)
2885 USE_GL_FUNC(glVertexAttribs3hvNV)
2886 USE_GL_FUNC(glVertexAttribs4hvNV)
2887 USE_GL_FUNC(glVertexWeighthNV)
2888 USE_GL_FUNC(glVertexWeighthvNV)
2889 /* GL_NV_point_sprite */
2890 USE_GL_FUNC(glPointParameteriNV)
2891 USE_GL_FUNC(glPointParameterivNV)
2892 /* GL_NV_register_combiners */
2893 USE_GL_FUNC(glCombinerInputNV)
2894 USE_GL_FUNC(glCombinerOutputNV)
2895 USE_GL_FUNC(glCombinerParameterfNV)
2896 USE_GL_FUNC(glCombinerParameterfvNV)
2897 USE_GL_FUNC(glCombinerParameteriNV)
2898 USE_GL_FUNC(glCombinerParameterivNV)
2899 USE_GL_FUNC(glFinalCombinerInputNV)
2900 /* WGL extensions */
2901 USE_GL_FUNC(wglChoosePixelFormatARB)
2902 USE_GL_FUNC(wglGetExtensionsStringARB)
2903 USE_GL_FUNC(wglGetPixelFormatAttribfvARB)
2904 USE_GL_FUNC(wglGetPixelFormatAttribivARB)
2905 USE_GL_FUNC(wglSetPixelFormatWINE)
2906 USE_GL_FUNC(wglSwapIntervalEXT)
2908 /* Newer core functions */
2909 USE_GL_FUNC(glActiveTexture) /* OpenGL 1.3 */
2910 USE_GL_FUNC(glAttachShader) /* OpenGL 2.0 */
2911 USE_GL_FUNC(glBeginQuery) /* OpenGL 1.5 */
2912 USE_GL_FUNC(glBindAttribLocation) /* OpenGL 2.0 */
2913 USE_GL_FUNC(glBindBuffer) /* OpenGL 1.5 */
2914 USE_GL_FUNC(glBindVertexArray) /* OpenGL 3.0 */
2915 USE_GL_FUNC(glBlendColor) /* OpenGL 1.4 */
2916 USE_GL_FUNC(glBlendEquation) /* OpenGL 1.4 */
2917 USE_GL_FUNC(glBlendEquationSeparate) /* OpenGL 2.0 */
2918 USE_GL_FUNC(glBlendFuncSeparate) /* OpenGL 1.4 */
2919 USE_GL_FUNC(glBufferData) /* OpenGL 1.5 */
2920 USE_GL_FUNC(glBufferSubData) /* OpenGL 1.5 */
2921 USE_GL_FUNC(glColorMaski) /* OpenGL 3.0 */
2922 USE_GL_FUNC(glCompileShader) /* OpenGL 2.0 */
2923 USE_GL_FUNC(glCompressedTexImage2D) /* OpenGL 1.3 */
2924 USE_GL_FUNC(glCompressedTexImage3D) /* OpenGL 1.3 */
2925 USE_GL_FUNC(glCompressedTexSubImage2D) /* OpenGL 1.3 */
2926 USE_GL_FUNC(glCompressedTexSubImage3D) /* OpenGL 1.3 */
2927 USE_GL_FUNC(glCreateProgram) /* OpenGL 2.0 */
2928 USE_GL_FUNC(glCreateShader) /* OpenGL 2.0 */
2929 USE_GL_FUNC(glDebugMessageCallback) /* OpenGL 4.3 */
2930 USE_GL_FUNC(glDebugMessageControl) /* OpenGL 4.3 */
2931 USE_GL_FUNC(glDebugMessageInsert) /* OpenGL 4.3 */
2932 USE_GL_FUNC(glDeleteBuffers) /* OpenGL 1.5 */
2933 USE_GL_FUNC(glDeleteProgram) /* OpenGL 2.0 */
2934 USE_GL_FUNC(glDeleteQueries) /* OpenGL 1.5 */
2935 USE_GL_FUNC(glDeleteShader) /* OpenGL 2.0 */
2936 USE_GL_FUNC(glDeleteVertexArrays) /* OpenGL 3.0 */
2937 USE_GL_FUNC(glDetachShader) /* OpenGL 2.0 */
2938 USE_GL_FUNC(glDisableVertexAttribArray) /* OpenGL 2.0 */
2939 USE_GL_FUNC(glDrawArraysInstanced) /* OpenGL 3.1 */
2940 USE_GL_FUNC(glDrawBuffers) /* OpenGL 2.0 */
2941 USE_GL_FUNC(glDrawElementsInstanced) /* OpenGL 3.1 */
2942 USE_GL_FUNC(glEnableVertexAttribArray) /* OpenGL 2.0 */
2943 USE_GL_FUNC(glEndQuery) /* OpenGL 1.5 */
2944 USE_GL_FUNC(glGenBuffers) /* OpenGL 1.5 */
2945 USE_GL_FUNC(glGenQueries) /* OpenGL 1.5 */
2946 USE_GL_FUNC(glGenVertexArrays) /* OpenGL 3.0 */
2947 USE_GL_FUNC(glGetActiveUniform) /* OpenGL 2.0 */
2948 USE_GL_FUNC(glGetAttachedShaders) /* OpenGL 2.0 */
2949 USE_GL_FUNC(glGetAttribLocation) /* OpenGL 2.0 */
2950 USE_GL_FUNC(glGetBufferSubData) /* OpenGL 1.5 */
2951 USE_GL_FUNC(glGetCompressedTexImage) /* OpenGL 1.3 */
2952 USE_GL_FUNC(glGetDebugMessageLog) /* OpenGL 4.3 */
2953 USE_GL_FUNC(glGetProgramInfoLog) /* OpenGL 2.0 */
2954 USE_GL_FUNC(glGetProgramiv) /* OpenGL 2.0 */
2955 USE_GL_FUNC(glGetQueryiv) /* OpenGL 1.5 */
2956 USE_GL_FUNC(glGetQueryObjectuiv) /* OpenGL 1.5 */
2957 USE_GL_FUNC(glGetShaderInfoLog) /* OpenGL 2.0 */
2958 USE_GL_FUNC(glGetShaderiv) /* OpenGL 2.0 */
2959 USE_GL_FUNC(glGetShaderSource) /* OpenGL 2.0 */
2960 USE_GL_FUNC(glGetStringi) /* OpenGL 3.0 */
2961 USE_GL_FUNC(glGetUniformfv) /* OpenGL 2.0 */
2962 USE_GL_FUNC(glGetUniformiv) /* OpenGL 2.0 */
2963 USE_GL_FUNC(glGetUniformLocation) /* OpenGL 2.0 */
2964 USE_GL_FUNC(glLinkProgram) /* OpenGL 2.0 */
2965 USE_GL_FUNC(glMapBuffer) /* OpenGL 1.5 */
2966 USE_GL_FUNC(glPointParameteri) /* OpenGL 1.4 */
2967 USE_GL_FUNC(glPointParameteriv) /* OpenGL 1.4 */
2968 USE_GL_FUNC(glShaderSource) /* OpenGL 2.0 */
2969 USE_GL_FUNC(glStencilFuncSeparate) /* OpenGL 2.0 */
2970 USE_GL_FUNC(glStencilOpSeparate) /* OpenGL 2.0 */
2971 USE_GL_FUNC(glTexImage3D) /* OpenGL 1.2 */
2972 USE_GL_FUNC(glTexSubImage3D) /* OpenGL 1.2 */
2973 USE_GL_FUNC(glUniform1f) /* OpenGL 2.0 */
2974 USE_GL_FUNC(glUniform1fv) /* OpenGL 2.0 */
2975 USE_GL_FUNC(glUniform1i) /* OpenGL 2.0 */
2976 USE_GL_FUNC(glUniform1iv) /* OpenGL 2.0 */
2977 USE_GL_FUNC(glUniform2f) /* OpenGL 2.0 */
2978 USE_GL_FUNC(glUniform2fv) /* OpenGL 2.0 */
2979 USE_GL_FUNC(glUniform2i) /* OpenGL 2.0 */
2980 USE_GL_FUNC(glUniform2iv) /* OpenGL 2.0 */
2981 USE_GL_FUNC(glUniform3f) /* OpenGL 2.0 */
2982 USE_GL_FUNC(glUniform3fv) /* OpenGL 2.0 */
2983 USE_GL_FUNC(glUniform3i) /* OpenGL 2.0 */
2984 USE_GL_FUNC(glUniform3iv) /* OpenGL 2.0 */
2985 USE_GL_FUNC(glUniform4f) /* OpenGL 2.0 */
2986 USE_GL_FUNC(glUniform4fv) /* OpenGL 2.0 */
2987 USE_GL_FUNC(glUniform4i) /* OpenGL 2.0 */
2988 USE_GL_FUNC(glUniform4iv) /* OpenGL 2.0 */
2989 USE_GL_FUNC(glUniformMatrix2fv) /* OpenGL 2.0 */
2990 USE_GL_FUNC(glUniformMatrix3fv) /* OpenGL 2.0 */
2991 USE_GL_FUNC(glUniformMatrix4fv) /* OpenGL 2.0 */
2992 USE_GL_FUNC(glUnmapBuffer) /* OpenGL 1.5 */
2993 USE_GL_FUNC(glUseProgram) /* OpenGL 2.0 */
2994 USE_GL_FUNC(glValidateProgram) /* OpenGL 2.0 */
2995 USE_GL_FUNC(glVertexAttrib1f) /* OpenGL 2.0 */
2996 USE_GL_FUNC(glVertexAttrib1fv) /* OpenGL 2.0 */
2997 USE_GL_FUNC(glVertexAttrib2f) /* OpenGL 2.0 */
2998 USE_GL_FUNC(glVertexAttrib2fv) /* OpenGL 2.0 */
2999 USE_GL_FUNC(glVertexAttrib3f) /* OpenGL 2.0 */
3000 USE_GL_FUNC(glVertexAttrib3fv) /* OpenGL 2.0 */
3001 USE_GL_FUNC(glVertexAttrib4f) /* OpenGL 2.0 */
3002 USE_GL_FUNC(glVertexAttrib4fv) /* OpenGL 2.0 */
3003 USE_GL_FUNC(glVertexAttrib4Nsv) /* OpenGL 2.0 */
3004 USE_GL_FUNC(glVertexAttrib4Nubv) /* OpenGL 2.0 */
3005 USE_GL_FUNC(glVertexAttrib4Nusv) /* OpenGL 2.0 */
3006 USE_GL_FUNC(glVertexAttrib4sv) /* OpenGL 2.0 */
3007 USE_GL_FUNC(glVertexAttrib4ubv) /* OpenGL 2.0 */
3008 USE_GL_FUNC(glVertexAttribDivisor) /* OpenGL 3.3 */
3009 USE_GL_FUNC(glVertexAttribPointer) /* OpenGL 2.0 */
3010 #undef USE_GL_FUNC
3012 #ifndef USE_WIN32_OPENGL
3013 /* hack: use the functions directly from the TEB table to bypass the thunks */
3014 /* note that we still need the above wglGetProcAddress calls to initialize the table */
3015 gl_info->gl_ops.ext = ((struct opengl_funcs *)NtCurrentTeb()->glTable)->ext;
3016 #endif
3018 #define MAP_GL_FUNCTION(core_func, ext_func) \
3019 do \
3021 if (!gl_info->gl_ops.ext.p_##core_func) \
3022 gl_info->gl_ops.ext.p_##core_func = gl_info->gl_ops.ext.p_##ext_func; \
3023 } while (0)
3024 #define MAP_GL_FUNCTION_CAST(core_func, ext_func) \
3025 do \
3027 if (!gl_info->gl_ops.ext.p_##core_func) \
3028 gl_info->gl_ops.ext.p_##core_func = (void *)gl_info->gl_ops.ext.p_##ext_func; \
3029 } while (0)
3031 MAP_GL_FUNCTION(glActiveTexture, glActiveTextureARB);
3032 MAP_GL_FUNCTION(glAttachShader, glAttachObjectARB);
3033 MAP_GL_FUNCTION(glBeginQuery, glBeginQueryARB);
3034 MAP_GL_FUNCTION(glBindAttribLocation, glBindAttribLocationARB);
3035 MAP_GL_FUNCTION(glBindBuffer, glBindBufferARB);
3036 MAP_GL_FUNCTION(glBlendColor, glBlendColorEXT);
3037 MAP_GL_FUNCTION(glBlendEquation, glBlendEquationEXT);
3038 MAP_GL_FUNCTION(glBlendEquationSeparate, glBlendEquationSeparateEXT);
3039 MAP_GL_FUNCTION(glBlendFuncSeparate, glBlendFuncSeparateEXT);
3040 MAP_GL_FUNCTION(glBufferData, glBufferDataARB);
3041 MAP_GL_FUNCTION(glBufferSubData, glBufferSubDataARB);
3042 MAP_GL_FUNCTION(glColorMaski, glColorMaskIndexedEXT);
3043 MAP_GL_FUNCTION(glCompileShader, glCompileShaderARB);
3044 MAP_GL_FUNCTION(glCompressedTexImage2D, glCompressedTexImage2DARB);
3045 MAP_GL_FUNCTION(glCompressedTexImage3D, glCompressedTexImage3DARB);
3046 MAP_GL_FUNCTION(glCompressedTexSubImage2D, glCompressedTexSubImage2DARB);
3047 MAP_GL_FUNCTION(glCompressedTexSubImage3D, glCompressedTexSubImage3DARB);
3048 MAP_GL_FUNCTION(glCreateProgram, glCreateProgramObjectARB);
3049 MAP_GL_FUNCTION(glCreateShader, glCreateShaderObjectARB);
3050 MAP_GL_FUNCTION(glDebugMessageCallback, glDebugMessageCallbackARB);
3051 MAP_GL_FUNCTION(glDebugMessageControl, glDebugMessageControlARB);
3052 MAP_GL_FUNCTION(glDebugMessageInsert, glDebugMessageInsertARB);
3053 MAP_GL_FUNCTION(glDeleteBuffers, glDeleteBuffersARB);
3054 MAP_GL_FUNCTION(glDeleteProgram, glDeleteObjectARB);
3055 MAP_GL_FUNCTION(glDeleteQueries, glDeleteQueriesARB);
3056 MAP_GL_FUNCTION(glDeleteShader, glDeleteObjectARB);
3057 MAP_GL_FUNCTION(glDetachShader, glDetachObjectARB);
3058 MAP_GL_FUNCTION(glDisableVertexAttribArray, glDisableVertexAttribArrayARB);
3059 MAP_GL_FUNCTION(glDrawArraysInstanced, glDrawArraysInstancedARB);
3060 MAP_GL_FUNCTION(glDrawBuffers, glDrawBuffersARB);
3061 MAP_GL_FUNCTION(glDrawElementsInstanced, glDrawElementsInstancedARB);
3062 MAP_GL_FUNCTION(glEnableVertexAttribArray, glEnableVertexAttribArrayARB);
3063 MAP_GL_FUNCTION(glEndQuery, glEndQueryARB);
3064 MAP_GL_FUNCTION(glGenBuffers, glGenBuffersARB);
3065 MAP_GL_FUNCTION(glGenQueries, glGenQueriesARB);
3066 MAP_GL_FUNCTION(glGetActiveUniform, glGetActiveUniformARB);
3067 MAP_GL_FUNCTION(glGetAttachedShaders, glGetAttachedObjectsARB);
3068 MAP_GL_FUNCTION(glGetAttribLocation, glGetAttribLocationARB);
3069 MAP_GL_FUNCTION(glGetBufferSubData, glGetBufferSubDataARB);
3070 MAP_GL_FUNCTION(glGetCompressedTexImage, glGetCompressedTexImageARB);
3071 MAP_GL_FUNCTION(glGetDebugMessageLog, glGetDebugMessageLogARB);
3072 MAP_GL_FUNCTION(glGetProgramInfoLog, glGetInfoLogARB);
3073 MAP_GL_FUNCTION(glGetProgramiv, glGetObjectParameterivARB);
3074 MAP_GL_FUNCTION(glGetQueryiv, glGetQueryivARB);
3075 MAP_GL_FUNCTION(glGetQueryObjectuiv, glGetQueryObjectuivARB);
3076 MAP_GL_FUNCTION(glGetShaderInfoLog, glGetInfoLogARB);
3077 MAP_GL_FUNCTION(glGetShaderiv, glGetObjectParameterivARB);
3078 MAP_GL_FUNCTION(glGetShaderSource, glGetShaderSourceARB);
3079 MAP_GL_FUNCTION(glGetUniformfv, glGetUniformfvARB);
3080 MAP_GL_FUNCTION(glGetUniformiv, glGetUniformivARB);
3081 MAP_GL_FUNCTION(glGetUniformLocation, glGetUniformLocationARB);
3082 MAP_GL_FUNCTION(glLinkProgram, glLinkProgramARB);
3083 MAP_GL_FUNCTION(glMapBuffer, glMapBufferARB);
3084 MAP_GL_FUNCTION_CAST(glShaderSource, glShaderSourceARB);
3085 MAP_GL_FUNCTION_CAST(glTexImage3D, glTexImage3DEXT);
3086 MAP_GL_FUNCTION(glTexSubImage3D, glTexSubImage3DEXT);
3087 MAP_GL_FUNCTION(glUniform1f, glUniform1fARB);
3088 MAP_GL_FUNCTION(glUniform1fv, glUniform1fvARB);
3089 MAP_GL_FUNCTION(glUniform1i, glUniform1iARB);
3090 MAP_GL_FUNCTION(glUniform1iv, glUniform1ivARB);
3091 MAP_GL_FUNCTION(glUniform2f, glUniform2fARB);
3092 MAP_GL_FUNCTION(glUniform2fv, glUniform2fvARB);
3093 MAP_GL_FUNCTION(glUniform2i, glUniform2iARB);
3094 MAP_GL_FUNCTION(glUniform2iv, glUniform2ivARB);
3095 MAP_GL_FUNCTION(glUniform3f, glUniform3fARB);
3096 MAP_GL_FUNCTION(glUniform3fv, glUniform3fvARB);
3097 MAP_GL_FUNCTION(glUniform3i, glUniform3iARB);
3098 MAP_GL_FUNCTION(glUniform3iv, glUniform3ivARB);
3099 MAP_GL_FUNCTION(glUniform4f, glUniform4fARB);
3100 MAP_GL_FUNCTION(glUniform4fv, glUniform4fvARB);
3101 MAP_GL_FUNCTION(glUniform4i, glUniform4iARB);
3102 MAP_GL_FUNCTION(glUniform4iv, glUniform4ivARB);
3103 MAP_GL_FUNCTION(glUniformMatrix2fv, glUniformMatrix2fvARB);
3104 MAP_GL_FUNCTION(glUniformMatrix3fv, glUniformMatrix3fvARB);
3105 MAP_GL_FUNCTION(glUniformMatrix4fv, glUniformMatrix4fvARB);
3106 MAP_GL_FUNCTION(glUnmapBuffer, glUnmapBufferARB);
3107 MAP_GL_FUNCTION(glUseProgram, glUseProgramObjectARB);
3108 MAP_GL_FUNCTION(glValidateProgram, glValidateProgramARB);
3109 MAP_GL_FUNCTION(glVertexAttrib1f, glVertexAttrib1fARB);
3110 MAP_GL_FUNCTION(glVertexAttrib1fv, glVertexAttrib1fvARB);
3111 MAP_GL_FUNCTION(glVertexAttrib2f, glVertexAttrib2fARB);
3112 MAP_GL_FUNCTION(glVertexAttrib2fv, glVertexAttrib2fvARB);
3113 MAP_GL_FUNCTION(glVertexAttrib3f, glVertexAttrib3fARB);
3114 MAP_GL_FUNCTION(glVertexAttrib3fv, glVertexAttrib3fvARB);
3115 MAP_GL_FUNCTION(glVertexAttrib4f, glVertexAttrib4fARB);
3116 MAP_GL_FUNCTION(glVertexAttrib4fv, glVertexAttrib4fvARB);
3117 MAP_GL_FUNCTION(glVertexAttrib4Nsv, glVertexAttrib4NsvARB);
3118 MAP_GL_FUNCTION(glVertexAttrib4Nubv, glVertexAttrib4NubvARB);
3119 MAP_GL_FUNCTION(glVertexAttrib4Nusv, glVertexAttrib4NusvARB);
3120 MAP_GL_FUNCTION(glVertexAttrib4sv, glVertexAttrib4svARB);
3121 MAP_GL_FUNCTION(glVertexAttrib4ubv, glVertexAttrib4ubvARB);
3122 MAP_GL_FUNCTION(glVertexAttribDivisor, glVertexAttribDivisorARB);
3123 MAP_GL_FUNCTION(glVertexAttribPointer, glVertexAttribPointerARB);
3124 #undef MAP_GL_FUNCTION
3125 #undef MAP_GL_FUNCTION_CAST
3128 static void wined3d_adapter_init_limits(struct wined3d_gl_info *gl_info)
3130 GLfloat gl_floatv[2];
3131 GLint gl_max;
3133 gl_info->limits.blends = 1;
3134 gl_info->limits.buffers = 1;
3135 gl_info->limits.textures = 1;
3136 gl_info->limits.texture_coords = 1;
3137 gl_info->limits.vertex_uniform_blocks = 0;
3138 gl_info->limits.geometry_uniform_blocks = 0;
3139 gl_info->limits.fragment_uniform_blocks = 0;
3140 gl_info->limits.fragment_samplers = 1;
3141 gl_info->limits.vertex_samplers = 0;
3142 gl_info->limits.combined_samplers = gl_info->limits.fragment_samplers + gl_info->limits.vertex_samplers;
3143 gl_info->limits.vertex_attribs = 16;
3144 gl_info->limits.glsl_vs_float_constants = 0;
3145 gl_info->limits.glsl_ps_float_constants = 0;
3146 gl_info->limits.arb_vs_float_constants = 0;
3147 gl_info->limits.arb_vs_native_constants = 0;
3148 gl_info->limits.arb_vs_instructions = 0;
3149 gl_info->limits.arb_vs_temps = 0;
3150 gl_info->limits.arb_ps_float_constants = 0;
3151 gl_info->limits.arb_ps_local_constants = 0;
3152 gl_info->limits.arb_ps_instructions = 0;
3153 gl_info->limits.arb_ps_temps = 0;
3155 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_CLIP_PLANES, &gl_max);
3156 gl_info->limits.clipplanes = min(WINED3DMAXUSERCLIPPLANES, gl_max);
3157 TRACE("Clip plane support - max planes %d.\n", gl_max);
3159 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_LIGHTS, &gl_max);
3160 gl_info->limits.lights = gl_max;
3161 TRACE("Light support - max lights %d.\n", gl_max);
3163 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gl_max);
3164 gl_info->limits.texture_size = gl_max;
3165 TRACE("Maximum texture size support - max texture size %d.\n", gl_max);
3167 gl_info->gl_ops.gl.p_glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, gl_floatv);
3168 gl_info->limits.pointsize_min = gl_floatv[0];
3169 gl_info->limits.pointsize_max = gl_floatv[1];
3170 TRACE("Maximum point size support - max point size %f.\n", gl_floatv[1]);
3172 if (gl_info->supported[ARB_MAP_BUFFER_ALIGNMENT])
3174 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MIN_MAP_BUFFER_ALIGNMENT, &gl_max);
3175 TRACE("Minimum buffer map alignment: %d.\n", gl_max);
3177 else
3179 WARN_(d3d_perf)("Driver doesn't guarantee a minimum buffer map alignment.\n");
3181 if (gl_info->supported[NV_REGISTER_COMBINERS])
3183 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_GENERAL_COMBINERS_NV, &gl_max);
3184 gl_info->limits.general_combiners = gl_max;
3185 TRACE("Max general combiners: %d.\n", gl_max);
3187 if (gl_info->supported[ARB_DRAW_BUFFERS] && wined3d_settings.offscreen_rendering_mode == ORM_FBO)
3189 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_DRAW_BUFFERS_ARB, &gl_max);
3190 gl_info->limits.buffers = gl_max;
3191 TRACE("Max draw buffers: %u.\n", gl_max);
3193 if (gl_info->supported[ARB_MULTITEXTURE])
3195 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_max);
3196 gl_info->limits.textures = min(MAX_TEXTURES, gl_max);
3197 TRACE("Max textures: %d.\n", gl_info->limits.textures);
3199 if (gl_info->supported[ARB_FRAGMENT_PROGRAM])
3201 GLint tmp;
3202 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_TEXTURE_COORDS_ARB, &gl_max);
3203 gl_info->limits.texture_coords = min(MAX_TEXTURES, gl_max);
3204 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &tmp);
3205 gl_info->limits.fragment_samplers = min(MAX_FRAGMENT_SAMPLERS, tmp);
3207 else
3209 gl_info->limits.texture_coords = max(gl_info->limits.texture_coords, gl_max);
3210 gl_info->limits.fragment_samplers = max(gl_info->limits.fragment_samplers, gl_max);
3212 TRACE("Max texture coords: %d.\n", gl_info->limits.texture_coords);
3213 TRACE("Max fragment samplers: %d.\n", gl_info->limits.fragment_samplers);
3215 if (gl_info->supported[ARB_VERTEX_SHADER])
3217 GLint tmp;
3218 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, &tmp);
3219 gl_info->limits.vertex_samplers = tmp;
3220 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, &tmp);
3221 gl_info->limits.combined_samplers = tmp;
3222 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_VERTEX_ATTRIBS_ARB, &tmp);
3223 gl_info->limits.vertex_attribs = tmp;
3225 /* Loading GLSL sampler uniforms is much simpler if we can assume that the sampler setup
3226 * is known at shader link time. In a vertex shader + pixel shader combination this isn't
3227 * an issue because then the sampler setup only depends on the two shaders. If a pixel
3228 * shader is used with fixed function vertex processing we're fine too because fixed function
3229 * vertex processing doesn't use any samplers. If fixed function fragment processing is
3230 * used we have to make sure that all vertex sampler setups are valid together with all
3231 * possible fixed function fragment processing setups. This is true if vsamplers + MAX_TEXTURES
3232 * <= max_samplers. This is true on all d3d9 cards that support vtf(gf 6 and gf7 cards).
3233 * dx9 radeon cards do not support vertex texture fetch. DX10 cards have 128 samplers, and
3234 * dx9 is limited to 8 fixed function texture stages and 4 vertex samplers. DX10 does not have
3235 * a fixed function pipeline anymore.
3237 * So this is just a check to check that our assumption holds true. If not, write a warning
3238 * and reduce the number of vertex samplers or probably disable vertex texture fetch. */
3239 if (gl_info->limits.vertex_samplers && gl_info->limits.combined_samplers < 12
3240 && MAX_TEXTURES + gl_info->limits.vertex_samplers > gl_info->limits.combined_samplers)
3242 FIXME("OpenGL implementation supports %u vertex samplers and %u total samplers.\n",
3243 gl_info->limits.vertex_samplers, gl_info->limits.combined_samplers);
3244 FIXME("Expected vertex samplers + MAX_TEXTURES(=8) > combined_samplers.\n");
3245 if (gl_info->limits.combined_samplers > MAX_TEXTURES)
3246 gl_info->limits.vertex_samplers = gl_info->limits.combined_samplers - MAX_TEXTURES;
3247 else
3248 gl_info->limits.vertex_samplers = 0;
3251 else
3253 gl_info->limits.combined_samplers = gl_info->limits.fragment_samplers;
3255 TRACE("Max vertex samplers: %u.\n", gl_info->limits.vertex_samplers);
3256 TRACE("Max combined samplers: %u.\n", gl_info->limits.combined_samplers);
3258 if (gl_info->supported[ARB_VERTEX_BLEND])
3260 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_VERTEX_UNITS_ARB, &gl_max);
3261 gl_info->limits.blends = gl_max;
3262 TRACE("Max blends: %u.\n", gl_info->limits.blends);
3264 if (gl_info->supported[EXT_TEXTURE3D])
3266 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE_EXT, &gl_max);
3267 gl_info->limits.texture3d_size = gl_max;
3268 TRACE("Max texture3D size: %d.\n", gl_info->limits.texture3d_size);
3270 if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
3272 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &gl_max);
3273 gl_info->limits.anisotropy = gl_max;
3274 TRACE("Max anisotropy: %d.\n", gl_info->limits.anisotropy);
3276 if (gl_info->supported[ARB_FRAGMENT_PROGRAM])
3278 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, &gl_max));
3279 gl_info->limits.arb_ps_float_constants = gl_max;
3280 TRACE("Max ARB_FRAGMENT_PROGRAM float constants: %d.\n", gl_info->limits.arb_ps_float_constants);
3281 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB, &gl_max));
3282 gl_info->limits.arb_ps_native_constants = gl_max;
3283 TRACE("Max ARB_FRAGMENT_PROGRAM native float constants: %d.\n",
3284 gl_info->limits.arb_ps_native_constants);
3285 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl_max));
3286 gl_info->limits.arb_ps_temps = gl_max;
3287 TRACE("Max ARB_FRAGMENT_PROGRAM native temporaries: %d.\n", gl_info->limits.arb_ps_temps);
3288 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl_max));
3289 gl_info->limits.arb_ps_instructions = gl_max;
3290 TRACE("Max ARB_FRAGMENT_PROGRAM native instructions: %d.\n", gl_info->limits.arb_ps_instructions);
3291 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB, &gl_max));
3292 gl_info->limits.arb_ps_local_constants = gl_max;
3293 TRACE("Max ARB_FRAGMENT_PROGRAM local parameters: %d.\n", gl_info->limits.arb_ps_instructions);
3295 if (gl_info->supported[ARB_VERTEX_PROGRAM])
3297 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, &gl_max));
3298 gl_info->limits.arb_vs_float_constants = gl_max;
3299 TRACE("Max ARB_VERTEX_PROGRAM float constants: %d.\n", gl_info->limits.arb_vs_float_constants);
3300 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB, &gl_max));
3301 gl_info->limits.arb_vs_native_constants = gl_max;
3302 TRACE("Max ARB_VERTEX_PROGRAM native float constants: %d.\n",
3303 gl_info->limits.arb_vs_native_constants);
3304 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl_max));
3305 gl_info->limits.arb_vs_temps = gl_max;
3306 TRACE("Max ARB_VERTEX_PROGRAM native temporaries: %d.\n", gl_info->limits.arb_vs_temps);
3307 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl_max));
3308 gl_info->limits.arb_vs_instructions = gl_max;
3309 TRACE("Max ARB_VERTEX_PROGRAM native instructions: %d.\n", gl_info->limits.arb_vs_instructions);
3311 if (gl_info->supported[ARB_VERTEX_SHADER])
3313 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, &gl_max);
3314 gl_info->limits.glsl_vs_float_constants = gl_max / 4;
3315 TRACE("Max ARB_VERTEX_SHADER float constants: %u.\n", gl_info->limits.glsl_vs_float_constants);
3317 if (gl_info->supported[ARB_UNIFORM_BUFFER_OBJECT])
3319 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_VERTEX_UNIFORM_BLOCKS, &gl_max);
3320 gl_info->limits.vertex_uniform_blocks = min(gl_max, WINED3D_MAX_CBS);
3321 TRACE("Max vertex uniform blocks: %u (%d).\n", gl_info->limits.vertex_uniform_blocks, gl_max);
3324 if (gl_info->supported[ARB_GEOMETRY_SHADER4] && gl_info->supported[ARB_UNIFORM_BUFFER_OBJECT])
3326 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_GEOMETRY_UNIFORM_BLOCKS, &gl_max);
3327 gl_info->limits.geometry_uniform_blocks = min(gl_max, WINED3D_MAX_CBS);
3328 TRACE("Max geometry uniform blocks: %u (%d).\n", gl_info->limits.geometry_uniform_blocks, gl_max);
3330 if (gl_info->supported[ARB_FRAGMENT_SHADER])
3332 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB, &gl_max);
3333 gl_info->limits.glsl_ps_float_constants = gl_max / 4;
3334 TRACE("Max ARB_FRAGMENT_SHADER float constants: %u.\n", gl_info->limits.glsl_ps_float_constants);
3335 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_VARYING_FLOATS_ARB, &gl_max);
3336 gl_info->limits.glsl_varyings = gl_max;
3337 TRACE("Max GLSL varyings: %u (%u 4 component varyings).\n", gl_max, gl_max / 4);
3339 if (gl_info->supported[ARB_UNIFORM_BUFFER_OBJECT])
3341 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_BLOCKS, &gl_max);
3342 gl_info->limits.fragment_uniform_blocks = min(gl_max, WINED3D_MAX_CBS);
3343 TRACE("Max fragment uniform blocks: %u (%d).\n", gl_info->limits.fragment_uniform_blocks, gl_max);
3346 if (gl_info->supported[ARB_UNIFORM_BUFFER_OBJECT])
3348 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_COMBINED_UNIFORM_BLOCKS, &gl_max);
3349 TRACE("Max combined uniform blocks: %d.\n", gl_max);
3350 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, &gl_max);
3351 TRACE("Max uniform buffer bindings: %d.\n", gl_max);
3354 if (gl_info->supported[NV_LIGHT_MAX_EXPONENT])
3355 gl_info->gl_ops.gl.p_glGetFloatv(GL_MAX_SHININESS_NV, &gl_info->limits.shininess);
3356 else
3357 gl_info->limits.shininess = 128.0f;
3359 if ((gl_info->supported[ARB_FRAMEBUFFER_OBJECT] || gl_info->supported[EXT_FRAMEBUFFER_MULTISAMPLE])
3360 && wined3d_settings.allow_multisampling)
3362 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_SAMPLES, &gl_max);
3363 gl_info->limits.samples = gl_max;
3367 /* Context activation is done by the caller. */
3368 static BOOL wined3d_adapter_init_gl_caps(struct wined3d_adapter *adapter, DWORD wined3d_creation_flags)
3370 static const struct
3372 enum wined3d_gl_extension extension;
3373 DWORD min_gl_version;
3375 core_extensions[] =
3377 {EXT_TEXTURE3D, MAKEDWORD_VERSION(1, 2)},
3378 {ARB_MULTISAMPLE, MAKEDWORD_VERSION(1, 3)},
3379 {ARB_MULTITEXTURE, MAKEDWORD_VERSION(1, 3)},
3380 {ARB_TEXTURE_BORDER_CLAMP, MAKEDWORD_VERSION(1, 3)},
3381 {ARB_TEXTURE_COMPRESSION, MAKEDWORD_VERSION(1, 3)},
3382 {ARB_TEXTURE_CUBE_MAP, MAKEDWORD_VERSION(1, 3)},
3383 {ARB_DEPTH_TEXTURE, MAKEDWORD_VERSION(1, 4)},
3384 {ARB_POINT_PARAMETERS, MAKEDWORD_VERSION(1, 4)},
3385 {ARB_SHADOW, MAKEDWORD_VERSION(1, 4)},
3386 {ARB_TEXTURE_MIRRORED_REPEAT, MAKEDWORD_VERSION(1, 4)},
3387 {EXT_BLEND_COLOR, MAKEDWORD_VERSION(1, 4)},
3388 {EXT_BLEND_FUNC_SEPARATE, MAKEDWORD_VERSION(1, 4)},
3389 {EXT_BLEND_MINMAX, MAKEDWORD_VERSION(1, 4)},
3390 {EXT_BLEND_SUBTRACT, MAKEDWORD_VERSION(1, 4)},
3391 {EXT_STENCIL_WRAP, MAKEDWORD_VERSION(1, 4)},
3392 {NV_POINT_SPRITE, MAKEDWORD_VERSION(1, 4)},
3393 {ARB_OCCLUSION_QUERY, MAKEDWORD_VERSION(1, 5)},
3394 {ARB_VERTEX_BUFFER_OBJECT, MAKEDWORD_VERSION(1, 5)},
3395 {ARB_DRAW_BUFFERS, MAKEDWORD_VERSION(2, 0)},
3396 {ARB_FRAGMENT_SHADER, MAKEDWORD_VERSION(2, 0)},
3397 {ARB_SHADING_LANGUAGE_100, MAKEDWORD_VERSION(2, 0)},
3398 {ARB_TEXTURE_NON_POWER_OF_TWO, MAKEDWORD_VERSION(2, 0)},
3399 {ARB_VERTEX_SHADER, MAKEDWORD_VERSION(2, 0)},
3400 {EXT_BLEND_EQUATION_SEPARATE, MAKEDWORD_VERSION(2, 0)},
3401 {ARB_PIXEL_BUFFER_OBJECT, MAKEDWORD_VERSION(2, 1)},
3402 {EXT_TEXTURE_SRGB, MAKEDWORD_VERSION(2, 1)},
3403 {ARB_COLOR_BUFFER_FLOAT, MAKEDWORD_VERSION(3, 0)},
3404 {ARB_DEPTH_BUFFER_FLOAT, MAKEDWORD_VERSION(3, 0)},
3405 {ARB_FRAMEBUFFER_OBJECT, MAKEDWORD_VERSION(3, 0)},
3406 {ARB_FRAMEBUFFER_SRGB, MAKEDWORD_VERSION(3, 0)},
3407 {ARB_HALF_FLOAT_PIXEL, MAKEDWORD_VERSION(3, 0)},
3408 {ARB_HALF_FLOAT_VERTEX, MAKEDWORD_VERSION(3, 0)},
3409 {ARB_MAP_BUFFER_RANGE, MAKEDWORD_VERSION(3, 0)},
3410 {ARB_TEXTURE_COMPRESSION_RGTC, MAKEDWORD_VERSION(3, 0)},
3411 {ARB_TEXTURE_FLOAT, MAKEDWORD_VERSION(3, 0)},
3412 {ARB_TEXTURE_RG, MAKEDWORD_VERSION(3, 0)},
3413 {EXT_DRAW_BUFFERS2, MAKEDWORD_VERSION(3, 0)},
3414 {EXT_TEXTURE_INTEGER, MAKEDWORD_VERSION(3, 0)},
3415 /* We don't want to enable EXT_GPU_SHADER4: even though similar
3416 * functionality is available in core GL 3.0 / GLSL 1.30, it's different
3417 * enough that reusing the same flag for the new features hurts more
3418 * than it helps. */
3419 /* EXT_framebuffer_object, EXT_framebuffer_blit,
3420 * EXT_framebuffer_multisample and EXT_packed_depth_stencil
3421 * are integrated into ARB_framebuffer_object. */
3423 {ARB_DRAW_INSTANCED, MAKEDWORD_VERSION(3, 1)},
3424 {ARB_UNIFORM_BUFFER_OBJECT, MAKEDWORD_VERSION(3, 1)},
3425 {EXT_TEXTURE_SNORM, MAKEDWORD_VERSION(3, 1)},
3426 /* We don't need or want GL_ARB_texture_rectangle (core in 3.1). */
3428 {ARB_DRAW_ELEMENTS_BASE_VERTEX, MAKEDWORD_VERSION(3, 2)},
3429 /* ARB_geometry_shader4 exposes a somewhat different API compared to 3.2
3430 * core geometry shaders so it's not really correct to expose the
3431 * extension for core-only support. */
3432 {ARB_PROVOKING_VERTEX, MAKEDWORD_VERSION(3, 2)},
3433 {ARB_SYNC, MAKEDWORD_VERSION(3, 2)},
3434 {ARB_VERTEX_ARRAY_BGRA, MAKEDWORD_VERSION(3, 2)},
3436 {ARB_BLEND_FUNC_EXTENDED, MAKEDWORD_VERSION(3, 3)},
3437 {ARB_INSTANCED_ARRAYS, MAKEDWORD_VERSION(3, 3)},
3438 {ARB_SAMPLER_OBJECTS, MAKEDWORD_VERSION(3, 3)},
3439 {ARB_SHADER_BIT_ENCODING, MAKEDWORD_VERSION(3, 3)},
3440 {ARB_TEXTURE_RGB10_A2UI, MAKEDWORD_VERSION(3, 3)},
3441 {ARB_TIMER_QUERY, MAKEDWORD_VERSION(3, 3)},
3443 {ARB_ES2_COMPATIBILITY, MAKEDWORD_VERSION(4, 1)},
3445 {ARB_INTERNALFORMAT_QUERY, MAKEDWORD_VERSION(4, 2)},
3446 {ARB_MAP_BUFFER_ALIGNMENT, MAKEDWORD_VERSION(4, 2)},
3448 {ARB_DEBUG_OUTPUT, MAKEDWORD_VERSION(4, 3)},
3449 {ARB_INTERNALFORMAT_QUERY2, MAKEDWORD_VERSION(4, 3)},
3450 {ARB_TEXTURE_QUERY_LEVELS, MAKEDWORD_VERSION(4, 3)},
3452 struct wined3d_driver_info *driver_info = &adapter->driver_info;
3453 const char *gl_vendor_str, *gl_renderer_str, *gl_version_str;
3454 struct wined3d_gl_info *gl_info = &adapter->gl_info;
3455 struct wined3d_vertex_caps vertex_caps;
3456 enum wined3d_pci_vendor card_vendor;
3457 struct fragment_caps fragment_caps;
3458 struct shader_caps shader_caps;
3459 const char *WGL_Extensions = NULL;
3460 enum wined3d_gl_vendor gl_vendor;
3461 enum wined3d_pci_device device;
3462 DWORD gl_version, gl_ext_emul_mask;
3463 HDC hdc;
3464 unsigned int i, j;
3465 GLint context_profile = 0;
3467 TRACE("adapter %p.\n", adapter);
3469 gl_renderer_str = (const char *)gl_info->gl_ops.gl.p_glGetString(GL_RENDERER);
3470 TRACE("GL_RENDERER: %s.\n", debugstr_a(gl_renderer_str));
3471 if (!gl_renderer_str)
3473 ERR("Received a NULL GL_RENDERER.\n");
3474 return FALSE;
3477 gl_vendor_str = (const char *)gl_info->gl_ops.gl.p_glGetString(GL_VENDOR);
3478 TRACE("GL_VENDOR: %s.\n", debugstr_a(gl_vendor_str));
3479 if (!gl_vendor_str)
3481 ERR("Received a NULL GL_VENDOR.\n");
3482 return FALSE;
3485 /* Parse the GL_VERSION field into major and minor information */
3486 gl_version_str = (const char *)gl_info->gl_ops.gl.p_glGetString(GL_VERSION);
3487 TRACE("GL_VERSION: %s.\n", debugstr_a(gl_version_str));
3488 if (!gl_version_str)
3490 ERR("Received a NULL GL_VERSION.\n");
3491 return FALSE;
3493 gl_version = wined3d_parse_gl_version(gl_version_str);
3495 load_gl_funcs(gl_info);
3497 memset(gl_info->supported, 0, sizeof(gl_info->supported));
3498 gl_info->supported[WINED3D_GL_EXT_NONE] = TRUE;
3500 if (gl_version >= MAKEDWORD_VERSION(3, 2))
3502 glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &context_profile);
3503 checkGLcall("Querying context profile");
3505 if (context_profile & GL_CONTEXT_CORE_PROFILE_BIT)
3506 TRACE("Got a core profile context.\n");
3507 else
3508 gl_info->supported[WINED3D_GL_LEGACY_CONTEXT] = TRUE;
3510 TRACE("GL extensions reported:\n");
3511 if (gl_info->supported[WINED3D_GL_LEGACY_CONTEXT])
3513 const char *gl_extensions = (const char *)gl_info->gl_ops.gl.p_glGetString(GL_EXTENSIONS);
3515 if (!gl_extensions)
3517 ERR("Received a NULL GL_EXTENSIONS.\n");
3518 return FALSE;
3520 parse_extension_string(gl_info, gl_extensions, gl_extension_map,
3521 sizeof(gl_extension_map) / sizeof(*gl_extension_map));
3523 else
3525 enumerate_gl_extensions(gl_info, gl_extension_map,
3526 sizeof(gl_extension_map) / sizeof(*gl_extension_map));
3529 hdc = wglGetCurrentDC();
3530 /* Not all GL drivers might offer WGL extensions e.g. VirtualBox. */
3531 if (GL_EXTCALL(wglGetExtensionsStringARB))
3532 WGL_Extensions = (const char *)GL_EXTCALL(wglGetExtensionsStringARB(hdc));
3533 if (!WGL_Extensions)
3534 WARN("WGL extensions not supported.\n");
3535 else
3536 parse_extension_string(gl_info, WGL_Extensions, wgl_extension_map,
3537 sizeof(wgl_extension_map) / sizeof(*wgl_extension_map));
3539 for (i = 0; i < ARRAY_SIZE(core_extensions); ++i)
3541 if (!gl_info->supported[core_extensions[i].extension]
3542 && gl_version >= core_extensions[i].min_gl_version)
3544 for (j = 0; j < ARRAY_SIZE(gl_extension_map); ++j)
3545 if (gl_extension_map[j].extension == core_extensions[i].extension)
3546 break;
3548 if (j < ARRAY_SIZE(gl_extension_map))
3550 TRACE("GL CORE: %s support.\n", gl_extension_map[j].extension_string);
3551 gl_info->supported[core_extensions[i].extension] = TRUE;
3553 else
3555 FIXME("GL extension %u not in the GL extensions map.\n", core_extensions[i].extension);
3560 if (gl_info->supported[EXT_BLEND_MINMAX] || gl_info->supported[EXT_BLEND_SUBTRACT])
3561 gl_info->supported[WINED3D_GL_BLEND_EQUATION] = TRUE;
3563 if (gl_version >= MAKEDWORD_VERSION(2, 0))
3564 gl_info->supported[WINED3D_GL_VERSION_2_0] = TRUE;
3565 if (gl_version >= MAKEDWORD_VERSION(3, 2))
3566 gl_info->supported[WINED3D_GL_VERSION_3_2] = TRUE;
3568 if (gl_info->supported[APPLE_FENCE])
3570 /* GL_NV_fence and GL_APPLE_fence provide the same functionality basically.
3571 * The apple extension interacts with some other apple exts. Disable the NV
3572 * extension if the apple one is support to prevent confusion in other parts
3573 * of the code. */
3574 gl_info->supported[NV_FENCE] = FALSE;
3576 if (gl_info->supported[APPLE_FLOAT_PIXELS])
3578 /* GL_APPLE_float_pixels == GL_ARB_texture_float + GL_ARB_half_float_pixel
3580 * The enums are the same:
3581 * GL_RGBA16F_ARB = GL_RGBA_FLOAT16_APPLE = 0x881a
3582 * GL_RGB16F_ARB = GL_RGB_FLOAT16_APPLE = 0x881b
3583 * GL_RGBA32F_ARB = GL_RGBA_FLOAT32_APPLE = 0x8814
3584 * GL_RGB32F_ARB = GL_RGB_FLOAT32_APPLE = 0x8815
3585 * GL_HALF_FLOAT_ARB = GL_HALF_APPLE = 0x140b
3587 if (!gl_info->supported[ARB_TEXTURE_FLOAT])
3589 TRACE(" IMPLIED: GL_ARB_texture_float support (by GL_APPLE_float_pixels).\n");
3590 gl_info->supported[ARB_TEXTURE_FLOAT] = TRUE;
3592 if (!gl_info->supported[ARB_HALF_FLOAT_PIXEL])
3594 TRACE(" IMPLIED: GL_ARB_half_float_pixel support (by GL_APPLE_float_pixels).\n");
3595 gl_info->supported[ARB_HALF_FLOAT_PIXEL] = TRUE;
3598 if (gl_info->supported[ARB_MAP_BUFFER_RANGE])
3600 /* GL_ARB_map_buffer_range and GL_APPLE_flush_buffer_range provide the same
3601 * functionality. Prefer the ARB extension */
3602 gl_info->supported[APPLE_FLUSH_BUFFER_RANGE] = FALSE;
3604 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
3606 TRACE(" IMPLIED: NVIDIA (NV) Texture Gen Reflection support.\n");
3607 gl_info->supported[NV_TEXGEN_REFLECTION] = TRUE;
3609 if (!gl_info->supported[ARB_VERTEX_ARRAY_BGRA] && gl_info->supported[EXT_VERTEX_ARRAY_BGRA])
3611 TRACE(" IMPLIED: ARB_vertex_array_bgra support (by EXT_vertex_array_bgra).\n");
3612 gl_info->supported[ARB_VERTEX_ARRAY_BGRA] = TRUE;
3614 if (!gl_info->supported[EXT_TEXTURE_COMPRESSION_RGTC] && gl_info->supported[ARB_TEXTURE_COMPRESSION_RGTC])
3616 TRACE(" IMPLIED: EXT_texture_compression_rgtc support (by ARB_texture_compression_rgtc).\n");
3617 gl_info->supported[EXT_TEXTURE_COMPRESSION_RGTC] = TRUE;
3619 if (!gl_info->supported[ARB_TEXTURE_COMPRESSION_RGTC] && gl_info->supported[EXT_TEXTURE_COMPRESSION_RGTC])
3621 TRACE(" IMPLIED: ARB_texture_compression_rgtc support (by EXT_texture_compression_rgtc).\n");
3622 gl_info->supported[ARB_TEXTURE_COMPRESSION_RGTC] = TRUE;
3624 if (gl_info->supported[ARB_TEXTURE_COMPRESSION_RGTC] && !gl_info->supported[ARB_TEXTURE_RG])
3626 TRACE("ARB_texture_rg not supported, disabling ARB_texture_compression_rgtc.\n");
3627 gl_info->supported[ARB_TEXTURE_COMPRESSION_RGTC] = FALSE;
3629 if (gl_info->supported[NV_TEXTURE_SHADER2])
3631 if (gl_info->supported[NV_REGISTER_COMBINERS])
3633 /* Also disable ATI_FRAGMENT_SHADER if register combiners and texture_shader2
3634 * are supported. The nv extensions provide the same functionality as the
3635 * ATI one, and a bit more(signed pixelformats). */
3636 gl_info->supported[ATI_FRAGMENT_SHADER] = FALSE;
3639 if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
3641 /* If we have full NP2 texture support, disable
3642 * GL_ARB_texture_rectangle because we will never use it.
3643 * This saves a few redundant glDisable calls. */
3644 gl_info->supported[ARB_TEXTURE_RECTANGLE] = FALSE;
3646 if (gl_info->supported[ATI_FRAGMENT_SHADER])
3648 /* Disable NV_register_combiners and fragment shader if this is supported.
3649 * generally the NV extensions are preferred over the ATI ones, and this
3650 * extension is disabled if register_combiners and texture_shader2 are both
3651 * supported. So we reach this place only if we have incomplete NV dxlevel 8
3652 * fragment processing support. */
3653 gl_info->supported[NV_REGISTER_COMBINERS] = FALSE;
3654 gl_info->supported[NV_REGISTER_COMBINERS2] = FALSE;
3655 gl_info->supported[NV_TEXTURE_SHADER] = FALSE;
3656 gl_info->supported[NV_TEXTURE_SHADER2] = FALSE;
3658 if (gl_info->supported[NV_HALF_FLOAT])
3660 /* GL_ARB_half_float_vertex is a subset of GL_NV_half_float. */
3661 gl_info->supported[ARB_HALF_FLOAT_VERTEX] = TRUE;
3663 if (gl_info->supported[ARB_FRAMEBUFFER_SRGB] && !gl_info->supported[EXT_TEXTURE_SRGB_DECODE])
3665 /* Current wined3d sRGB infrastructure requires EXT_texture_sRGB_decode
3666 * for GL_ARB_framebuffer_sRGB support (without EXT_texture_sRGB_decode
3667 * we never render to sRGB surfaces). */
3668 gl_info->supported[ARB_FRAMEBUFFER_SRGB] = FALSE;
3670 if (gl_info->supported[ARB_OCCLUSION_QUERY])
3672 GLint counter_bits;
3674 GL_EXTCALL(glGetQueryiv(GL_SAMPLES_PASSED, GL_QUERY_COUNTER_BITS, &counter_bits));
3675 TRACE("Occlusion query counter has %d bits.\n", counter_bits);
3676 if (!counter_bits)
3677 gl_info->supported[ARB_OCCLUSION_QUERY] = FALSE;
3679 if (gl_info->supported[ARB_TIMER_QUERY])
3681 GLint counter_bits;
3683 GL_EXTCALL(glGetQueryiv(GL_TIMESTAMP, GL_QUERY_COUNTER_BITS, &counter_bits));
3684 TRACE("Timestamp query counter has %d bits.\n", counter_bits);
3685 if (!counter_bits)
3686 gl_info->supported[ARB_TIMER_QUERY] = FALSE;
3688 if (!gl_info->supported[ATI_TEXTURE_MIRROR_ONCE] && gl_info->supported[EXT_TEXTURE_MIRROR_CLAMP])
3690 TRACE(" IMPLIED: ATI_texture_mirror_once support (by EXT_texture_mirror_clamp).\n");
3691 gl_info->supported[ATI_TEXTURE_MIRROR_ONCE] = TRUE;
3693 if (!gl_info->supported[ARB_TEXTURE_MIRROR_CLAMP_TO_EDGE] && gl_info->supported[ATI_TEXTURE_MIRROR_ONCE])
3695 TRACE(" IMPLIED: ARB_texture_mirror_clamp_to_edge support (by ATI_texture_mirror_once).\n");
3696 gl_info->supported[ARB_TEXTURE_MIRROR_CLAMP_TO_EDGE] = TRUE;
3699 wined3d_adapter_init_limits(gl_info);
3701 if (gl_info->supported[ARB_VERTEX_PROGRAM] && test_arb_vs_offset_limit(gl_info))
3702 gl_info->quirks |= WINED3D_QUIRK_ARB_VS_OFFSET_LIMIT;
3704 if (gl_info->supported[ARB_SHADING_LANGUAGE_100])
3706 const char *str = (const char *)gl_info->gl_ops.gl.p_glGetString(GL_SHADING_LANGUAGE_VERSION_ARB);
3707 unsigned int major, minor;
3709 TRACE("GLSL version string: %s.\n", debugstr_a(str));
3711 /* The format of the GLSL version string is "major.minor[.release] [vendor info]". */
3712 sscanf(str, "%u.%u", &major, &minor);
3713 gl_info->glsl_version = MAKEDWORD_VERSION(major, minor);
3716 checkGLcall("extension detection");
3718 adapter->shader_backend = select_shader_backend(gl_info);
3719 adapter->vertex_pipe = select_vertex_implementation(gl_info, adapter->shader_backend);
3720 adapter->fragment_pipe = select_fragment_implementation(gl_info, adapter->shader_backend);
3721 adapter->blitter = select_blit_implementation(gl_info, adapter->shader_backend);
3723 adapter->shader_backend->shader_get_caps(gl_info, &shader_caps);
3724 adapter->d3d_info.vs_clipping = shader_caps.wined3d_caps & WINED3D_SHADER_CAP_VS_CLIPPING;
3725 adapter->d3d_info.limits.vs_version = shader_caps.vs_version;
3726 adapter->d3d_info.limits.gs_version = shader_caps.gs_version;
3727 adapter->d3d_info.limits.ps_version = shader_caps.ps_version;
3728 adapter->d3d_info.limits.vs_uniform_count = shader_caps.vs_uniform_count;
3729 adapter->d3d_info.limits.ps_uniform_count = shader_caps.ps_uniform_count;
3730 adapter->d3d_info.limits.varying_count = shader_caps.varying_count;
3732 adapter->vertex_pipe->vp_get_caps(gl_info, &vertex_caps);
3733 adapter->d3d_info.xyzrhw = vertex_caps.xyzrhw;
3734 adapter->d3d_info.ffp_generic_attributes = vertex_caps.ffp_generic_attributes;
3735 adapter->d3d_info.limits.ffp_vertex_blend_matrices = vertex_caps.max_vertex_blend_matrices;
3736 adapter->d3d_info.emulated_flatshading = vertex_caps.emulated_flatshading;
3738 adapter->fragment_pipe->get_caps(gl_info, &fragment_caps);
3739 adapter->d3d_info.limits.ffp_blend_stages = fragment_caps.MaxTextureBlendStages;
3740 adapter->d3d_info.limits.ffp_textures = fragment_caps.MaxSimultaneousTextures;
3741 adapter->d3d_info.shader_color_key = fragment_caps.wined3d_caps & WINED3D_FRAGMENT_CAP_COLOR_KEY;
3742 adapter->d3d_info.wined3d_creation_flags = wined3d_creation_flags;
3743 TRACE("Max texture stages: %u.\n", adapter->d3d_info.limits.ffp_blend_stages);
3745 if (gl_info->supported[ARB_FRAMEBUFFER_OBJECT])
3747 gl_info->fbo_ops.glIsRenderbuffer = gl_info->gl_ops.ext.p_glIsRenderbuffer;
3748 gl_info->fbo_ops.glBindRenderbuffer = gl_info->gl_ops.ext.p_glBindRenderbuffer;
3749 gl_info->fbo_ops.glDeleteRenderbuffers = gl_info->gl_ops.ext.p_glDeleteRenderbuffers;
3750 gl_info->fbo_ops.glGenRenderbuffers = gl_info->gl_ops.ext.p_glGenRenderbuffers;
3751 gl_info->fbo_ops.glRenderbufferStorage = gl_info->gl_ops.ext.p_glRenderbufferStorage;
3752 gl_info->fbo_ops.glRenderbufferStorageMultisample = gl_info->gl_ops.ext.p_glRenderbufferStorageMultisample;
3753 gl_info->fbo_ops.glGetRenderbufferParameteriv = gl_info->gl_ops.ext.p_glGetRenderbufferParameteriv;
3754 gl_info->fbo_ops.glIsFramebuffer = gl_info->gl_ops.ext.p_glIsFramebuffer;
3755 gl_info->fbo_ops.glBindFramebuffer = gl_info->gl_ops.ext.p_glBindFramebuffer;
3756 gl_info->fbo_ops.glDeleteFramebuffers = gl_info->gl_ops.ext.p_glDeleteFramebuffers;
3757 gl_info->fbo_ops.glGenFramebuffers = gl_info->gl_ops.ext.p_glGenFramebuffers;
3758 gl_info->fbo_ops.glCheckFramebufferStatus = gl_info->gl_ops.ext.p_glCheckFramebufferStatus;
3759 gl_info->fbo_ops.glFramebufferTexture1D = gl_info->gl_ops.ext.p_glFramebufferTexture1D;
3760 gl_info->fbo_ops.glFramebufferTexture2D = gl_info->gl_ops.ext.p_glFramebufferTexture2D;
3761 gl_info->fbo_ops.glFramebufferTexture3D = gl_info->gl_ops.ext.p_glFramebufferTexture3D;
3762 gl_info->fbo_ops.glFramebufferRenderbuffer = gl_info->gl_ops.ext.p_glFramebufferRenderbuffer;
3763 gl_info->fbo_ops.glGetFramebufferAttachmentParameteriv
3764 = gl_info->gl_ops.ext.p_glGetFramebufferAttachmentParameteriv;
3765 gl_info->fbo_ops.glBlitFramebuffer = gl_info->gl_ops.ext.p_glBlitFramebuffer;
3766 gl_info->fbo_ops.glGenerateMipmap = gl_info->gl_ops.ext.p_glGenerateMipmap;
3768 else
3770 if (gl_info->supported[EXT_FRAMEBUFFER_OBJECT])
3772 gl_info->fbo_ops.glIsRenderbuffer = gl_info->gl_ops.ext.p_glIsRenderbufferEXT;
3773 gl_info->fbo_ops.glBindRenderbuffer = gl_info->gl_ops.ext.p_glBindRenderbufferEXT;
3774 gl_info->fbo_ops.glDeleteRenderbuffers = gl_info->gl_ops.ext.p_glDeleteRenderbuffersEXT;
3775 gl_info->fbo_ops.glGenRenderbuffers = gl_info->gl_ops.ext.p_glGenRenderbuffersEXT;
3776 gl_info->fbo_ops.glRenderbufferStorage = gl_info->gl_ops.ext.p_glRenderbufferStorageEXT;
3777 gl_info->fbo_ops.glGetRenderbufferParameteriv = gl_info->gl_ops.ext.p_glGetRenderbufferParameterivEXT;
3778 gl_info->fbo_ops.glIsFramebuffer = gl_info->gl_ops.ext.p_glIsFramebufferEXT;
3779 gl_info->fbo_ops.glBindFramebuffer = gl_info->gl_ops.ext.p_glBindFramebufferEXT;
3780 gl_info->fbo_ops.glDeleteFramebuffers = gl_info->gl_ops.ext.p_glDeleteFramebuffersEXT;
3781 gl_info->fbo_ops.glGenFramebuffers = gl_info->gl_ops.ext.p_glGenFramebuffersEXT;
3782 gl_info->fbo_ops.glCheckFramebufferStatus = gl_info->gl_ops.ext.p_glCheckFramebufferStatusEXT;
3783 gl_info->fbo_ops.glFramebufferTexture1D = gl_info->gl_ops.ext.p_glFramebufferTexture1DEXT;
3784 gl_info->fbo_ops.glFramebufferTexture2D = gl_info->gl_ops.ext.p_glFramebufferTexture2DEXT;
3785 gl_info->fbo_ops.glFramebufferTexture3D = gl_info->gl_ops.ext.p_glFramebufferTexture3DEXT;
3786 gl_info->fbo_ops.glFramebufferRenderbuffer = gl_info->gl_ops.ext.p_glFramebufferRenderbufferEXT;
3787 gl_info->fbo_ops.glGetFramebufferAttachmentParameteriv
3788 = gl_info->gl_ops.ext.p_glGetFramebufferAttachmentParameterivEXT;
3789 gl_info->fbo_ops.glGenerateMipmap = gl_info->gl_ops.ext.p_glGenerateMipmapEXT;
3791 else if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
3793 WARN_(d3d_perf)("Framebuffer objects not supported, falling back to backbuffer offscreen rendering mode.\n");
3794 wined3d_settings.offscreen_rendering_mode = ORM_BACKBUFFER;
3796 if (gl_info->supported[EXT_FRAMEBUFFER_BLIT])
3798 gl_info->fbo_ops.glBlitFramebuffer = gl_info->gl_ops.ext.p_glBlitFramebufferEXT;
3800 if (gl_info->supported[EXT_FRAMEBUFFER_MULTISAMPLE])
3802 gl_info->fbo_ops.glRenderbufferStorageMultisample
3803 = gl_info->gl_ops.ext.p_glRenderbufferStorageMultisampleEXT;
3807 gl_vendor = wined3d_guess_gl_vendor(gl_info, gl_vendor_str, gl_renderer_str);
3808 card_vendor = wined3d_guess_card_vendor(gl_vendor_str, gl_renderer_str);
3809 TRACE("Found GL_VENDOR (%s)->(0x%04x/0x%04x).\n", debugstr_a(gl_vendor_str), gl_vendor, card_vendor);
3811 device = wined3d_guess_card(&shader_caps, &fragment_caps, gl_info->glsl_version, gl_renderer_str, &gl_vendor, &card_vendor);
3812 TRACE("Found (fake) card: 0x%x (vendor id), 0x%x (device id).\n", card_vendor, device);
3814 gl_info->wrap_lookup[WINED3D_TADDRESS_WRAP - WINED3D_TADDRESS_WRAP] = GL_REPEAT;
3815 gl_info->wrap_lookup[WINED3D_TADDRESS_MIRROR - WINED3D_TADDRESS_WRAP] =
3816 gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT] ? GL_MIRRORED_REPEAT_ARB : GL_REPEAT;
3817 gl_info->wrap_lookup[WINED3D_TADDRESS_CLAMP - WINED3D_TADDRESS_WRAP] = GL_CLAMP_TO_EDGE;
3818 gl_info->wrap_lookup[WINED3D_TADDRESS_BORDER - WINED3D_TADDRESS_WRAP] =
3819 gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] ? GL_CLAMP_TO_BORDER_ARB : GL_REPEAT;
3820 gl_info->wrap_lookup[WINED3D_TADDRESS_MIRROR_ONCE - WINED3D_TADDRESS_WRAP] =
3821 gl_info->supported[ARB_TEXTURE_MIRROR_CLAMP_TO_EDGE] ? GL_MIRROR_CLAMP_TO_EDGE : GL_REPEAT;
3823 adapter->d3d_info.valid_rt_mask = 0;
3824 for (i = 0; i < gl_info->limits.buffers; ++i)
3825 adapter->d3d_info.valid_rt_mask |= (1u << i);
3827 if (!gl_info->supported[WINED3D_GL_LEGACY_CONTEXT])
3829 GLuint vao;
3831 GL_EXTCALL(glGenVertexArrays(1, &vao));
3832 GL_EXTCALL(glBindVertexArray(vao));
3833 checkGLcall("creating VAO");
3836 fixup_extensions(gl_info, gl_renderer_str, gl_vendor, card_vendor, device);
3837 init_driver_info(driver_info, card_vendor, device);
3838 gl_ext_emul_mask = adapter->vertex_pipe->vp_get_emul_mask(gl_info)
3839 | adapter->fragment_pipe->get_emul_mask(gl_info);
3840 if (gl_ext_emul_mask & GL_EXT_EMUL_ARB_MULTITEXTURE)
3841 install_gl_compat_wrapper(gl_info, ARB_MULTITEXTURE);
3842 if (gl_ext_emul_mask & GL_EXT_EMUL_EXT_FOG_COORD)
3843 install_gl_compat_wrapper(gl_info, EXT_FOG_COORD);
3845 return TRUE;
3848 UINT CDECL wined3d_get_adapter_count(const struct wined3d *wined3d)
3850 TRACE("wined3d %p, reporting %u adapters.\n",
3851 wined3d, wined3d->adapter_count);
3853 return wined3d->adapter_count;
3856 HRESULT CDECL wined3d_register_software_device(struct wined3d *wined3d, void *init_function)
3858 FIXME("wined3d %p, init_function %p stub!\n", wined3d, init_function);
3860 return WINED3D_OK;
3863 HRESULT CDECL wined3d_get_output_desc(const struct wined3d *wined3d, unsigned int adapter_idx,
3864 struct wined3d_output_desc *desc)
3866 enum wined3d_display_rotation rotation;
3867 const struct wined3d_adapter *adapter;
3868 struct wined3d_display_mode mode;
3869 HMONITOR monitor;
3870 HRESULT hr;
3872 TRACE("wined3d %p, adapter_idx %u, desc %p.\n", wined3d, adapter_idx, desc);
3874 if (adapter_idx >= wined3d->adapter_count)
3875 return WINED3DERR_INVALIDCALL;
3877 adapter = &wined3d->adapters[adapter_idx];
3878 if (!(monitor = MonitorFromPoint(adapter->monitor_position, MONITOR_DEFAULTTOPRIMARY)))
3879 return WINED3DERR_INVALIDCALL;
3881 if (FAILED(hr = wined3d_get_adapter_display_mode(wined3d, adapter_idx, &mode, &rotation)))
3882 return hr;
3884 memcpy(desc->device_name, adapter->DeviceName, sizeof(desc->device_name));
3885 SetRect(&desc->desktop_rect, 0, 0, mode.width, mode.height);
3886 OffsetRect(&desc->desktop_rect, adapter->monitor_position.x, adapter->monitor_position.y);
3887 /* FIXME: We should get this from EnumDisplayDevices() when the adapters
3888 * are created. */
3889 desc->attached_to_desktop = TRUE;
3890 desc->rotation = rotation;
3891 desc->monitor = monitor;
3893 return WINED3D_OK;
3896 /* FIXME: GetAdapterModeCount and EnumAdapterModes currently only returns modes
3897 of the same bpp but different resolutions */
3899 /* Note: dx9 supplies a format. Calls from d3d8 supply WINED3DFMT_UNKNOWN */
3900 UINT CDECL wined3d_get_adapter_mode_count(const struct wined3d *wined3d, UINT adapter_idx,
3901 enum wined3d_format_id format_id, enum wined3d_scanline_ordering scanline_ordering)
3903 const struct wined3d_adapter *adapter;
3904 const struct wined3d_format *format;
3905 unsigned int i = 0;
3906 unsigned int j = 0;
3907 UINT format_bits;
3908 DEVMODEW mode;
3910 TRACE("wined3d %p, adapter_idx %u, format %s, scanline_ordering %#x.\n",
3911 wined3d, adapter_idx, debug_d3dformat(format_id), scanline_ordering);
3913 if (adapter_idx >= wined3d->adapter_count)
3914 return 0;
3916 adapter = &wined3d->adapters[adapter_idx];
3917 format = wined3d_get_format(&adapter->gl_info, format_id);
3918 format_bits = format->byte_count * CHAR_BIT;
3920 memset(&mode, 0, sizeof(mode));
3921 mode.dmSize = sizeof(mode);
3923 while (EnumDisplaySettingsExW(adapter->DeviceName, j++, &mode, 0))
3925 if (mode.dmFields & DM_DISPLAYFLAGS)
3927 if (scanline_ordering == WINED3D_SCANLINE_ORDERING_PROGRESSIVE
3928 && (mode.u2.dmDisplayFlags & DM_INTERLACED))
3929 continue;
3931 if (scanline_ordering == WINED3D_SCANLINE_ORDERING_INTERLACED
3932 && !(mode.u2.dmDisplayFlags & DM_INTERLACED))
3933 continue;
3936 if (format_id == WINED3DFMT_UNKNOWN)
3938 /* This is for d3d8, do not enumerate P8 here. */
3939 if (mode.dmBitsPerPel == 32 || mode.dmBitsPerPel == 16) ++i;
3941 else if (mode.dmBitsPerPel == format_bits)
3943 ++i;
3947 TRACE("Returning %u matching modes (out of %u total) for adapter %u.\n", i, j, adapter_idx);
3949 return i;
3952 /* Note: dx9 supplies a format. Calls from d3d8 supply WINED3DFMT_UNKNOWN */
3953 HRESULT CDECL wined3d_enum_adapter_modes(const struct wined3d *wined3d, UINT adapter_idx,
3954 enum wined3d_format_id format_id, enum wined3d_scanline_ordering scanline_ordering,
3955 UINT mode_idx, struct wined3d_display_mode *mode)
3957 const struct wined3d_adapter *adapter;
3958 const struct wined3d_format *format;
3959 UINT format_bits;
3960 DEVMODEW m;
3961 UINT i = 0;
3962 int j = 0;
3964 TRACE("wined3d %p, adapter_idx %u, format %s, scanline_ordering %#x, mode_idx %u, mode %p.\n",
3965 wined3d, adapter_idx, debug_d3dformat(format_id), scanline_ordering, mode_idx, mode);
3967 if (!mode || adapter_idx >= wined3d->adapter_count)
3968 return WINED3DERR_INVALIDCALL;
3970 adapter = &wined3d->adapters[adapter_idx];
3971 format = wined3d_get_format(&adapter->gl_info, format_id);
3972 format_bits = format->byte_count * CHAR_BIT;
3974 memset(&m, 0, sizeof(m));
3975 m.dmSize = sizeof(m);
3977 while (i <= mode_idx)
3979 if (!EnumDisplaySettingsExW(adapter->DeviceName, j++, &m, 0))
3981 WARN("Invalid mode_idx %u.\n", mode_idx);
3982 return WINED3DERR_INVALIDCALL;
3985 if (m.dmFields & DM_DISPLAYFLAGS)
3987 if (scanline_ordering == WINED3D_SCANLINE_ORDERING_PROGRESSIVE
3988 && (m.u2.dmDisplayFlags & DM_INTERLACED))
3989 continue;
3991 if (scanline_ordering == WINED3D_SCANLINE_ORDERING_INTERLACED
3992 && !(m.u2.dmDisplayFlags & DM_INTERLACED))
3993 continue;
3996 if (format_id == WINED3DFMT_UNKNOWN)
3998 /* This is for d3d8, do not enumerate P8 here. */
3999 if (m.dmBitsPerPel == 32 || m.dmBitsPerPel == 16) ++i;
4001 else if (m.dmBitsPerPel == format_bits)
4003 ++i;
4007 mode->width = m.dmPelsWidth;
4008 mode->height = m.dmPelsHeight;
4009 mode->refresh_rate = DEFAULT_REFRESH_RATE;
4010 if (m.dmFields & DM_DISPLAYFREQUENCY)
4011 mode->refresh_rate = m.dmDisplayFrequency;
4013 if (format_id == WINED3DFMT_UNKNOWN)
4014 mode->format_id = pixelformat_for_depth(m.dmBitsPerPel);
4015 else
4016 mode->format_id = format_id;
4018 if (!(m.dmFields & DM_DISPLAYFLAGS))
4019 mode->scanline_ordering = WINED3D_SCANLINE_ORDERING_UNKNOWN;
4020 else if (m.u2.dmDisplayFlags & DM_INTERLACED)
4021 mode->scanline_ordering = WINED3D_SCANLINE_ORDERING_INTERLACED;
4022 else
4023 mode->scanline_ordering = WINED3D_SCANLINE_ORDERING_PROGRESSIVE;
4025 TRACE("%ux%u@%u %u bpp, %s %#x.\n", mode->width, mode->height, mode->refresh_rate,
4026 m.dmBitsPerPel, debug_d3dformat(mode->format_id), mode->scanline_ordering);
4028 return WINED3D_OK;
4031 HRESULT CDECL wined3d_get_adapter_display_mode(const struct wined3d *wined3d, UINT adapter_idx,
4032 struct wined3d_display_mode *mode, enum wined3d_display_rotation *rotation)
4034 const struct wined3d_adapter *adapter;
4035 DEVMODEW m;
4037 TRACE("wined3d %p, adapter_idx %u, display_mode %p, rotation %p.\n",
4038 wined3d, adapter_idx, mode, rotation);
4040 if (!mode || adapter_idx >= wined3d->adapter_count)
4041 return WINED3DERR_INVALIDCALL;
4043 adapter = &wined3d->adapters[adapter_idx];
4045 memset(&m, 0, sizeof(m));
4046 m.dmSize = sizeof(m);
4048 EnumDisplaySettingsExW(adapter->DeviceName, ENUM_CURRENT_SETTINGS, &m, 0);
4049 mode->width = m.dmPelsWidth;
4050 mode->height = m.dmPelsHeight;
4051 mode->refresh_rate = DEFAULT_REFRESH_RATE;
4052 if (m.dmFields & DM_DISPLAYFREQUENCY)
4053 mode->refresh_rate = m.dmDisplayFrequency;
4054 mode->format_id = pixelformat_for_depth(m.dmBitsPerPel);
4056 /* Lie about the format. X11 can't change the color depth, and some apps
4057 * are pretty angry if they SetDisplayMode from 24 to 16 bpp and find out
4058 * that GetDisplayMode still returns 24 bpp. This should probably be
4059 * handled in winex11 instead. */
4060 if (adapter->screen_format && adapter->screen_format != mode->format_id)
4062 WARN("Overriding format %s with stored format %s.\n",
4063 debug_d3dformat(mode->format_id),
4064 debug_d3dformat(adapter->screen_format));
4065 mode->format_id = adapter->screen_format;
4068 if (!(m.dmFields & DM_DISPLAYFLAGS))
4069 mode->scanline_ordering = WINED3D_SCANLINE_ORDERING_UNKNOWN;
4070 else if (m.u2.dmDisplayFlags & DM_INTERLACED)
4071 mode->scanline_ordering = WINED3D_SCANLINE_ORDERING_INTERLACED;
4072 else
4073 mode->scanline_ordering = WINED3D_SCANLINE_ORDERING_PROGRESSIVE;
4075 if (rotation)
4077 switch (m.u1.s2.dmDisplayOrientation)
4079 case DMDO_DEFAULT:
4080 *rotation = WINED3D_DISPLAY_ROTATION_0;
4081 break;
4082 case DMDO_90:
4083 *rotation = WINED3D_DISPLAY_ROTATION_90;
4084 break;
4085 case DMDO_180:
4086 *rotation = WINED3D_DISPLAY_ROTATION_180;
4087 break;
4088 case DMDO_270:
4089 *rotation = WINED3D_DISPLAY_ROTATION_270;
4090 break;
4091 default:
4092 FIXME("Unhandled display rotation %#x.\n", m.u1.s2.dmDisplayOrientation);
4093 *rotation = WINED3D_DISPLAY_ROTATION_UNSPECIFIED;
4094 break;
4098 TRACE("Returning %ux%u@%u %s %#x.\n", mode->width, mode->height,
4099 mode->refresh_rate, debug_d3dformat(mode->format_id),
4100 mode->scanline_ordering);
4101 return WINED3D_OK;
4104 HRESULT CDECL wined3d_set_adapter_display_mode(struct wined3d *wined3d,
4105 UINT adapter_idx, const struct wined3d_display_mode *mode)
4107 struct wined3d_adapter *adapter;
4108 DEVMODEW new_mode, current_mode;
4109 RECT clip_rc;
4110 LONG ret;
4111 enum wined3d_format_id new_format_id;
4113 TRACE("wined3d %p, adapter_idx %u, mode %p.\n", wined3d, adapter_idx, mode);
4115 if (adapter_idx >= wined3d->adapter_count)
4116 return WINED3DERR_INVALIDCALL;
4117 adapter = &wined3d->adapters[adapter_idx];
4119 memset(&new_mode, 0, sizeof(new_mode));
4120 new_mode.dmSize = sizeof(new_mode);
4121 memset(&current_mode, 0, sizeof(current_mode));
4122 current_mode.dmSize = sizeof(current_mode);
4123 if (mode)
4125 const struct wined3d_format *format;
4127 TRACE("mode %ux%u@%u %s %#x.\n", mode->width, mode->height, mode->refresh_rate,
4128 debug_d3dformat(mode->format_id), mode->scanline_ordering);
4130 format = wined3d_get_format(&adapter->gl_info, mode->format_id);
4132 new_mode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
4133 new_mode.dmBitsPerPel = format->byte_count * CHAR_BIT;
4134 new_mode.dmPelsWidth = mode->width;
4135 new_mode.dmPelsHeight = mode->height;
4137 new_mode.dmDisplayFrequency = mode->refresh_rate;
4138 if (mode->refresh_rate)
4139 new_mode.dmFields |= DM_DISPLAYFREQUENCY;
4141 if (mode->scanline_ordering != WINED3D_SCANLINE_ORDERING_UNKNOWN)
4143 new_mode.dmFields |= DM_DISPLAYFLAGS;
4144 if (mode->scanline_ordering == WINED3D_SCANLINE_ORDERING_INTERLACED)
4145 new_mode.u2.dmDisplayFlags |= DM_INTERLACED;
4147 new_format_id = mode->format_id;
4149 else
4151 if (!EnumDisplaySettingsW(adapter->DeviceName, ENUM_REGISTRY_SETTINGS, &new_mode))
4153 ERR("Failed to read mode from registry.\n");
4154 return WINED3DERR_NOTAVAILABLE;
4156 new_format_id = pixelformat_for_depth(new_mode.dmBitsPerPel);
4159 /* Only change the mode if necessary. */
4160 if (!EnumDisplaySettingsW(adapter->DeviceName, ENUM_CURRENT_SETTINGS, &current_mode))
4162 ERR("Failed to get current display mode.\n");
4164 else if (current_mode.dmPelsWidth == new_mode.dmPelsWidth
4165 && current_mode.dmPelsHeight == new_mode.dmPelsHeight
4166 && current_mode.dmBitsPerPel == new_mode.dmBitsPerPel
4167 && (current_mode.dmDisplayFrequency == new_mode.dmDisplayFrequency
4168 || !(new_mode.dmFields & DM_DISPLAYFREQUENCY))
4169 && (current_mode.u2.dmDisplayFlags == new_mode.u2.dmDisplayFlags
4170 || !(new_mode.dmFields & DM_DISPLAYFLAGS)))
4172 TRACE("Skipping redundant mode setting call.\n");
4173 return WINED3D_OK;
4176 ret = ChangeDisplaySettingsExW(adapter->DeviceName, &new_mode, NULL, CDS_FULLSCREEN, NULL);
4177 if (ret != DISP_CHANGE_SUCCESSFUL)
4179 if (new_mode.dmFields & DM_DISPLAYFREQUENCY)
4181 WARN("ChangeDisplaySettingsExW failed, trying without the refresh rate.\n");
4182 new_mode.dmFields &= ~DM_DISPLAYFREQUENCY;
4183 new_mode.dmDisplayFrequency = 0;
4184 ret = ChangeDisplaySettingsExW(adapter->DeviceName, &new_mode, NULL, CDS_FULLSCREEN, NULL);
4186 if (ret != DISP_CHANGE_SUCCESSFUL)
4187 return WINED3DERR_NOTAVAILABLE;
4190 /* Store the new values. */
4191 adapter->screen_format = new_format_id;
4193 /* And finally clip mouse to our screen. */
4194 SetRect(&clip_rc, 0, 0, new_mode.dmPelsWidth, new_mode.dmPelsHeight);
4195 ClipCursor(&clip_rc);
4197 return WINED3D_OK;
4200 /* NOTE: due to structure differences between dx8 and dx9 D3DADAPTER_IDENTIFIER,
4201 and fields being inserted in the middle, a new structure is used in place */
4202 HRESULT CDECL wined3d_get_adapter_identifier(const struct wined3d *wined3d,
4203 UINT adapter_idx, DWORD flags, struct wined3d_adapter_identifier *identifier)
4205 const struct wined3d_adapter *adapter;
4206 size_t len;
4208 TRACE("wined3d %p, adapter_idx %u, flags %#x, identifier %p.\n",
4209 wined3d, adapter_idx, flags, identifier);
4211 if (adapter_idx >= wined3d->adapter_count)
4212 return WINED3DERR_INVALIDCALL;
4214 adapter = &wined3d->adapters[adapter_idx];
4216 if (identifier->driver_size)
4218 const char *name = adapter->driver_info.name;
4219 len = min(strlen(name), identifier->driver_size - 1);
4220 memcpy(identifier->driver, name, len);
4221 memset(&identifier->driver[len], 0, identifier->driver_size - len);
4224 if (identifier->description_size)
4226 const char *description = adapter->driver_info.description;
4227 len = min(strlen(description), identifier->description_size - 1);
4228 memcpy(identifier->description, description, len);
4229 memset(&identifier->description[len], 0, identifier->description_size - len);
4232 /* Note that d3d8 doesn't supply a device name. */
4233 if (identifier->device_name_size)
4235 if (!WideCharToMultiByte(CP_ACP, 0, adapter->DeviceName, -1, identifier->device_name,
4236 identifier->device_name_size, NULL, NULL))
4238 ERR("Failed to convert device name, last error %#x.\n", GetLastError());
4239 return WINED3DERR_INVALIDCALL;
4243 identifier->driver_version.u.HighPart = adapter->driver_info.version_high;
4244 identifier->driver_version.u.LowPart = adapter->driver_info.version_low;
4245 identifier->vendor_id = adapter->driver_info.vendor;
4246 identifier->device_id = adapter->driver_info.device;
4247 identifier->subsystem_id = 0;
4248 identifier->revision = 0;
4249 memcpy(&identifier->device_identifier, &IID_D3DDEVICE_D3DUID, sizeof(identifier->device_identifier));
4250 identifier->whql_level = (flags & WINED3DENUM_NO_WHQL_LEVEL) ? 0 : 1;
4251 memcpy(&identifier->adapter_luid, &adapter->luid, sizeof(identifier->adapter_luid));
4252 identifier->video_memory = min(~(SIZE_T)0, adapter->vram_bytes);
4254 return WINED3D_OK;
4257 HRESULT CDECL wined3d_get_adapter_raster_status(const struct wined3d *wined3d, UINT adapter_idx,
4258 struct wined3d_raster_status *raster_status)
4260 LONGLONG freq_per_frame, freq_per_line;
4261 LARGE_INTEGER counter, freq_per_sec;
4262 struct wined3d_display_mode mode;
4263 static UINT once;
4265 if (!once++)
4266 FIXME("wined3d %p, adapter_idx %u, raster_status %p semi-stub!\n",
4267 wined3d, adapter_idx, raster_status);
4268 else
4269 WARN("wined3d %p, adapter_idx %u, raster_status %p semi-stub!\n",
4270 wined3d, adapter_idx, raster_status);
4272 /* Obtaining the raster status is a widely implemented but optional
4273 * feature. When this method returns OK StarCraft 2 expects the
4274 * raster_status->InVBlank value to actually change over time.
4275 * And Endless Alice Crysis doesn't care even if this method fails.
4276 * Thus this method returns OK and fakes raster_status by
4277 * QueryPerformanceCounter. */
4279 if (!QueryPerformanceCounter(&counter) || !QueryPerformanceFrequency(&freq_per_sec))
4280 return WINED3DERR_INVALIDCALL;
4281 if (FAILED(wined3d_get_adapter_display_mode(wined3d, adapter_idx, &mode, NULL)))
4282 return WINED3DERR_INVALIDCALL;
4283 if (mode.refresh_rate == DEFAULT_REFRESH_RATE)
4284 mode.refresh_rate = 60;
4286 freq_per_frame = freq_per_sec.QuadPart / mode.refresh_rate;
4287 /* Assume 20 scan lines in the vertical blank. */
4288 freq_per_line = freq_per_frame / (mode.height + 20);
4289 raster_status->scan_line = (counter.QuadPart % freq_per_frame) / freq_per_line;
4290 if (raster_status->scan_line < mode.height)
4291 raster_status->in_vblank = FALSE;
4292 else
4294 raster_status->scan_line = 0;
4295 raster_status->in_vblank = TRUE;
4298 TRACE("Returning fake value, in_vblank %u, scan_line %u.\n",
4299 raster_status->in_vblank, raster_status->scan_line);
4301 return WINED3D_OK;
4304 static BOOL wined3d_check_pixel_format_color(const struct wined3d_gl_info *gl_info,
4305 const struct wined3d_pixel_format *cfg, const struct wined3d_format *format)
4307 /* Float formats need FBOs. If FBOs are used this function isn't called */
4308 if (format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_FLOAT)
4309 return FALSE;
4311 /* Probably a RGBA_float or color index mode. */
4312 if (cfg->iPixelType != WGL_TYPE_RGBA_ARB)
4313 return FALSE;
4315 if (cfg->redSize < format->red_size
4316 || cfg->greenSize < format->green_size
4317 || cfg->blueSize < format->blue_size
4318 || cfg->alphaSize < format->alpha_size)
4319 return FALSE;
4321 return TRUE;
4324 static BOOL wined3d_check_pixel_format_depth(const struct wined3d_gl_info *gl_info,
4325 const struct wined3d_pixel_format *cfg, const struct wined3d_format *format)
4327 BOOL lockable = FALSE;
4329 /* Float formats need FBOs. If FBOs are used this function isn't called */
4330 if (format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_FLOAT)
4331 return FALSE;
4333 if ((format->id == WINED3DFMT_D16_LOCKABLE) || (format->id == WINED3DFMT_D32_FLOAT))
4334 lockable = TRUE;
4336 /* On some modern cards like the Geforce8/9, GLX doesn't offer some
4337 * dephth/stencil formats which D3D9 reports. We can safely report
4338 * "compatible" formats (e.g. D24 can be used for D16) as long as we
4339 * aren't dealing with a lockable format. This also helps D3D <= 7 as they
4340 * expect D16 which isn't offered without this on Geforce8 cards. */
4341 if (!(cfg->depthSize == format->depth_size || (!lockable && cfg->depthSize > format->depth_size)))
4342 return FALSE;
4344 /* Some cards like Intel i915 ones only offer D24S8 but lots of games also
4345 * need a format without stencil. We can allow a mismatch if the format
4346 * doesn't have any stencil bits. If it does have stencil bits the size
4347 * must match, or stencil wrapping would break. */
4348 if (format->stencil_size && cfg->stencilSize != format->stencil_size)
4349 return FALSE;
4351 return TRUE;
4354 HRESULT CDECL wined3d_check_depth_stencil_match(const struct wined3d *wined3d,
4355 UINT adapter_idx, enum wined3d_device_type device_type, enum wined3d_format_id adapter_format_id,
4356 enum wined3d_format_id render_target_format_id, enum wined3d_format_id depth_stencil_format_id)
4358 const struct wined3d_format *rt_format;
4359 const struct wined3d_format *ds_format;
4360 const struct wined3d_adapter *adapter;
4362 TRACE("wined3d %p, adapter_idx %u, device_type %s,\n"
4363 "adapter_format %s, render_target_format %s, depth_stencil_format %s.\n",
4364 wined3d, adapter_idx, debug_d3ddevicetype(device_type), debug_d3dformat(adapter_format_id),
4365 debug_d3dformat(render_target_format_id), debug_d3dformat(depth_stencil_format_id));
4367 if (adapter_idx >= wined3d->adapter_count)
4368 return WINED3DERR_INVALIDCALL;
4370 adapter = &wined3d->adapters[adapter_idx];
4371 rt_format = wined3d_get_format(&adapter->gl_info, render_target_format_id);
4372 ds_format = wined3d_get_format(&adapter->gl_info, depth_stencil_format_id);
4373 if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
4375 if ((rt_format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_RENDERTARGET)
4376 && (ds_format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL)))
4378 TRACE("Formats match.\n");
4379 return WINED3D_OK;
4382 else
4384 const struct wined3d_pixel_format *cfgs;
4385 unsigned int cfg_count;
4386 unsigned int i;
4388 cfgs = adapter->cfgs;
4389 cfg_count = adapter->cfg_count;
4390 for (i = 0; i < cfg_count; ++i)
4392 if (wined3d_check_pixel_format_color(&adapter->gl_info, &cfgs[i], rt_format)
4393 && wined3d_check_pixel_format_depth(&adapter->gl_info, &cfgs[i], ds_format))
4395 TRACE("Formats match.\n");
4396 return WINED3D_OK;
4401 TRACE("Unsupported format pair: %s and %s.\n",
4402 debug_d3dformat(render_target_format_id),
4403 debug_d3dformat(depth_stencil_format_id));
4405 return WINED3DERR_NOTAVAILABLE;
4408 HRESULT CDECL wined3d_check_device_multisample_type(const struct wined3d *wined3d, UINT adapter_idx,
4409 enum wined3d_device_type device_type, enum wined3d_format_id surface_format_id, BOOL windowed,
4410 enum wined3d_multisample_type multisample_type, DWORD *quality_levels)
4412 const struct wined3d_gl_info *gl_info = &wined3d->adapters[adapter_idx].gl_info;
4413 const struct wined3d_format *format = wined3d_get_format(gl_info, surface_format_id);
4414 HRESULT hr = WINED3D_OK;
4416 TRACE("wined3d %p, adapter_idx %u, device_type %s, surface_format %s, "
4417 "windowed %#x, multisample_type %#x, quality_levels %p.\n",
4418 wined3d, adapter_idx, debug_d3ddevicetype(device_type), debug_d3dformat(surface_format_id),
4419 windowed, multisample_type, quality_levels);
4421 if (adapter_idx >= wined3d->adapter_count)
4422 return WINED3DERR_INVALIDCALL;
4423 if (surface_format_id == WINED3DFMT_UNKNOWN)
4424 return WINED3DERR_INVALIDCALL;
4425 if (multisample_type < WINED3D_MULTISAMPLE_NONE)
4426 return WINED3DERR_INVALIDCALL;
4427 if (multisample_type > WINED3D_MULTISAMPLE_16_SAMPLES)
4429 FIXME("multisample_type %u not handled yet.\n", multisample_type);
4430 return WINED3DERR_NOTAVAILABLE;
4433 if (multisample_type && !(format->multisample_types & 1u << (multisample_type - 1)))
4434 hr = WINED3DERR_NOTAVAILABLE;
4436 if (SUCCEEDED(hr) || (multisample_type == WINED3D_MULTISAMPLE_NON_MASKABLE && format->multisample_types))
4438 if (quality_levels)
4440 if (multisample_type == WINED3D_MULTISAMPLE_NON_MASKABLE)
4441 *quality_levels = wined3d_popcount(format->multisample_types);
4442 else
4443 *quality_levels = 1;
4445 return WINED3D_OK;
4448 TRACE("Returning not supported.\n");
4449 return hr;
4452 /* Check if the given DisplayFormat + DepthStencilFormat combination is valid for the Adapter */
4453 static BOOL CheckDepthStencilCapability(const struct wined3d_adapter *adapter,
4454 const struct wined3d_format *display_format, const struct wined3d_format *ds_format,
4455 enum wined3d_gl_resource_type gl_type)
4457 /* Only allow depth/stencil formats */
4458 if (!(ds_format->depth_size || ds_format->stencil_size)) return FALSE;
4460 /* Blacklist formats not supported on Windows */
4461 switch (ds_format->id)
4463 case WINED3DFMT_S1_UINT_D15_UNORM: /* Breaks the shadowvol2 dx7 sdk sample */
4464 case WINED3DFMT_S4X4_UINT_D24_UNORM:
4465 TRACE("[FAILED] - not supported on windows.\n");
4466 return FALSE;
4468 default:
4469 break;
4472 if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
4474 /* With FBOs WGL limitations do not apply, but the format needs to be FBO attachable */
4475 if (ds_format->flags[gl_type] & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL))
4476 return TRUE;
4478 else
4480 unsigned int i;
4482 /* Walk through all WGL pixel formats to find a match */
4483 for (i = 0; i < adapter->cfg_count; ++i)
4485 const struct wined3d_pixel_format *cfg = &adapter->cfgs[i];
4486 if (wined3d_check_pixel_format_color(&adapter->gl_info, cfg, display_format)
4487 && wined3d_check_pixel_format_depth(&adapter->gl_info, cfg, ds_format))
4488 return TRUE;
4492 return FALSE;
4495 /* Check the render target capabilities of a format */
4496 static BOOL CheckRenderTargetCapability(const struct wined3d_adapter *adapter,
4497 const struct wined3d_format *adapter_format, const struct wined3d_format *check_format,
4498 enum wined3d_gl_resource_type gl_type)
4500 /* Filter out non-RT formats */
4501 if (!(check_format->flags[gl_type] & WINED3DFMT_FLAG_RENDERTARGET))
4502 return FALSE;
4503 if (wined3d_settings.offscreen_rendering_mode == ORM_BACKBUFFER)
4505 const struct wined3d_pixel_format *cfgs = adapter->cfgs;
4506 unsigned int i;
4508 /* In backbuffer mode the front and backbuffer share the same WGL
4509 * pixelformat. The format must match in RGB, alpha is allowed to be
4510 * different. (Only the backbuffer can have alpha.) */
4511 if (adapter_format->red_size != check_format->red_size
4512 || adapter_format->green_size != check_format->green_size
4513 || adapter_format->blue_size != check_format->blue_size)
4515 TRACE("[FAILED]\n");
4516 return FALSE;
4519 /* Check if there is a WGL pixel format matching the requirements, the format should also be window
4520 * drawable (not offscreen; e.g. Nvidia offers R5G6B5 for pbuffers even when X is running at 24bit) */
4521 for (i = 0; i < adapter->cfg_count; ++i)
4523 if (cfgs[i].windowDrawable
4524 && wined3d_check_pixel_format_color(&adapter->gl_info, &cfgs[i], check_format))
4526 TRACE("Pixel format %d is compatible with format %s.\n",
4527 cfgs[i].iPixelFormat, debug_d3dformat(check_format->id));
4528 return TRUE;
4532 else if(wined3d_settings.offscreen_rendering_mode == ORM_FBO)
4534 /* For now return TRUE for FBOs until we have some proper checks.
4535 * Note that this function will only be called when the format is around for texturing. */
4536 return TRUE;
4538 return FALSE;
4541 static BOOL CheckSurfaceCapability(const struct wined3d_adapter *adapter,
4542 const struct wined3d_format *adapter_format,
4543 const struct wined3d_format *check_format, BOOL no3d)
4545 if (no3d)
4547 switch (check_format->id)
4549 case WINED3DFMT_B8G8R8_UNORM:
4550 TRACE("[FAILED] - Not enumerated on Windows.\n");
4551 return FALSE;
4552 case WINED3DFMT_B8G8R8A8_UNORM:
4553 case WINED3DFMT_B8G8R8X8_UNORM:
4554 case WINED3DFMT_B5G6R5_UNORM:
4555 case WINED3DFMT_B5G5R5X1_UNORM:
4556 case WINED3DFMT_B5G5R5A1_UNORM:
4557 case WINED3DFMT_B4G4R4A4_UNORM:
4558 case WINED3DFMT_B2G3R3_UNORM:
4559 case WINED3DFMT_A8_UNORM:
4560 case WINED3DFMT_B2G3R3A8_UNORM:
4561 case WINED3DFMT_B4G4R4X4_UNORM:
4562 case WINED3DFMT_R10G10B10A2_UNORM:
4563 case WINED3DFMT_R8G8B8A8_UNORM:
4564 case WINED3DFMT_R8G8B8X8_UNORM:
4565 case WINED3DFMT_R16G16_UNORM:
4566 case WINED3DFMT_B10G10R10A2_UNORM:
4567 case WINED3DFMT_R16G16B16A16_UNORM:
4568 case WINED3DFMT_P8_UINT:
4569 TRACE("[OK]\n");
4570 return TRUE;
4571 default:
4572 TRACE("[FAILED] - Not available on GDI surfaces.\n");
4573 return FALSE;
4577 /* All formats that are supported for textures are supported for surfaces
4578 * as well. */
4579 if (check_format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_TEXTURE)
4580 return TRUE;
4581 /* All depth stencil formats are supported on surfaces */
4582 if (CheckDepthStencilCapability(adapter, adapter_format, check_format, WINED3D_GL_RES_TYPE_TEX_2D))
4583 return TRUE;
4584 if (CheckDepthStencilCapability(adapter, adapter_format, check_format, WINED3D_GL_RES_TYPE_RB))
4585 return TRUE;
4587 /* If opengl can't process the format natively, the blitter may be able to convert it */
4588 if (adapter->blitter->blit_supported(&adapter->gl_info, &adapter->d3d_info,
4589 WINED3D_BLIT_OP_COLOR_BLIT,
4590 NULL, WINED3D_POOL_DEFAULT, 0, check_format,
4591 NULL, WINED3D_POOL_DEFAULT, 0, adapter_format))
4593 TRACE("[OK]\n");
4594 return TRUE;
4597 /* Reject other formats */
4598 TRACE("[FAILED]\n");
4599 return FALSE;
4602 /* OpenGL supports mipmapping on all formats. Wrapping is unsupported, but we
4603 * have to report mipmapping so we cannot reject WRAPANDMIP. Tests show that
4604 * Windows reports WRAPANDMIP on unfilterable surfaces as well, apparently to
4605 * show that wrapping is supported. The lack of filtering will sort out the
4606 * mipmapping capability anyway.
4608 * For now lets report this on all formats, but in the future we may want to
4609 * restrict it to some should applications need that. */
4610 HRESULT CDECL wined3d_check_device_format(const struct wined3d *wined3d, UINT adapter_idx,
4611 enum wined3d_device_type device_type, enum wined3d_format_id adapter_format_id, DWORD usage,
4612 enum wined3d_resource_type resource_type, enum wined3d_format_id check_format_id)
4614 const struct wined3d_adapter *adapter = &wined3d->adapters[adapter_idx];
4615 const struct wined3d_gl_info *gl_info = &adapter->gl_info;
4616 const struct wined3d_format *adapter_format = wined3d_get_format(gl_info, adapter_format_id);
4617 const struct wined3d_format *format = wined3d_get_format(gl_info, check_format_id);
4618 DWORD format_flags = 0;
4619 DWORD allowed_usage;
4620 enum wined3d_gl_resource_type gl_type;
4622 TRACE("wined3d %p, adapter_idx %u, device_type %s, adapter_format %s, usage %s, %s,\n"
4623 "resource_type %s, check_format %s.\n",
4624 wined3d, adapter_idx, debug_d3ddevicetype(device_type), debug_d3dformat(adapter_format_id),
4625 debug_d3dusage(usage), debug_d3dusagequery(usage), debug_d3dresourcetype(resource_type),
4626 debug_d3dformat(check_format_id));
4628 if (adapter_idx >= wined3d->adapter_count)
4629 return WINED3DERR_INVALIDCALL;
4631 switch (resource_type)
4633 case WINED3D_RTYPE_SURFACE:
4634 if (!CheckSurfaceCapability(adapter, adapter_format, format, wined3d->flags & WINED3D_NO3D))
4636 TRACE("[FAILED] - Not supported for plain surfaces.\n");
4637 return WINED3DERR_NOTAVAILABLE;
4640 allowed_usage = WINED3DUSAGE_DEPTHSTENCIL
4641 | WINED3DUSAGE_RENDERTARGET
4642 | WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
4643 if (usage & WINED3DUSAGE_RENDERTARGET)
4644 allowed_usage |= WINED3DUSAGE_QUERY_SRGBWRITE;
4645 gl_type = WINED3D_GL_RES_TYPE_RB;
4646 break;
4648 case WINED3D_RTYPE_TEXTURE_2D:
4649 format_flags |= WINED3DFMT_FLAG_TEXTURE;
4650 allowed_usage = WINED3DUSAGE_AUTOGENMIPMAP
4651 | WINED3DUSAGE_DEPTHSTENCIL
4652 | WINED3DUSAGE_DYNAMIC
4653 | WINED3DUSAGE_LEGACY_CUBEMAP
4654 | WINED3DUSAGE_RENDERTARGET
4655 | WINED3DUSAGE_SOFTWAREPROCESSING
4656 | WINED3DUSAGE_QUERY_FILTER
4657 | WINED3DUSAGE_QUERY_LEGACYBUMPMAP
4658 | WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING
4659 | WINED3DUSAGE_QUERY_SRGBREAD
4660 | WINED3DUSAGE_QUERY_SRGBWRITE
4661 | WINED3DUSAGE_QUERY_VERTEXTEXTURE
4662 | WINED3DUSAGE_QUERY_WRAPANDMIP;
4663 gl_type = WINED3D_GL_RES_TYPE_TEX_2D;
4664 if (usage & WINED3DUSAGE_LEGACY_CUBEMAP)
4666 allowed_usage &= ~(WINED3DUSAGE_DEPTHSTENCIL | WINED3DUSAGE_QUERY_LEGACYBUMPMAP);
4667 gl_type = WINED3D_GL_RES_TYPE_TEX_CUBE;
4669 else if ((usage & WINED3DUSAGE_DEPTHSTENCIL)
4670 && (format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_SHADOW)
4671 && !gl_info->supported[ARB_SHADOW])
4673 TRACE("[FAILED] - No shadow sampler support.\n");
4674 return WINED3DERR_NOTAVAILABLE;
4676 break;
4678 case WINED3D_RTYPE_TEXTURE_3D:
4679 case WINED3D_RTYPE_VOLUME:
4680 format_flags |= WINED3DFMT_FLAG_TEXTURE;
4681 allowed_usage = WINED3DUSAGE_DYNAMIC
4682 | WINED3DUSAGE_SOFTWAREPROCESSING
4683 | WINED3DUSAGE_QUERY_FILTER
4684 | WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING
4685 | WINED3DUSAGE_QUERY_SRGBREAD
4686 | WINED3DUSAGE_QUERY_SRGBWRITE
4687 | WINED3DUSAGE_QUERY_VERTEXTEXTURE
4688 | WINED3DUSAGE_QUERY_WRAPANDMIP;
4689 gl_type = WINED3D_GL_RES_TYPE_TEX_3D;
4690 break;
4692 default:
4693 FIXME("Unhandled resource type %s.\n", debug_d3dresourcetype(resource_type));
4694 return WINED3DERR_NOTAVAILABLE;
4697 if ((usage & allowed_usage) != usage)
4699 TRACE("Requested usage %#x, but resource type %s only allows %#x.\n",
4700 usage, debug_d3dresourcetype(resource_type), allowed_usage);
4701 return WINED3DERR_NOTAVAILABLE;
4704 if (usage & WINED3DUSAGE_QUERY_FILTER)
4705 format_flags |= WINED3DFMT_FLAG_FILTERING;
4706 if (usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING)
4707 format_flags |= WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING;
4708 if (usage & WINED3DUSAGE_QUERY_SRGBREAD)
4709 format_flags |= WINED3DFMT_FLAG_SRGB_READ;
4710 if (usage & WINED3DUSAGE_QUERY_SRGBWRITE)
4711 format_flags |= WINED3DFMT_FLAG_SRGB_WRITE;
4712 if (usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE)
4713 format_flags |= WINED3DFMT_FLAG_VTF;
4714 if (usage & WINED3DUSAGE_QUERY_LEGACYBUMPMAP)
4715 format_flags |= WINED3DFMT_FLAG_BUMPMAP;
4717 if ((format->flags[gl_type] & format_flags) != format_flags)
4719 TRACE("Requested format flags %#x, but format %s only has %#x.\n",
4720 format_flags, debug_d3dformat(check_format_id), format->flags[gl_type]);
4721 return WINED3DERR_NOTAVAILABLE;
4724 if ((format_flags & WINED3DFMT_FLAG_TEXTURE) && (wined3d->flags & WINED3D_NO3D))
4726 TRACE("Requested texturing support, but wined3d was created with WINED3D_NO3D.\n");
4727 return WINED3DERR_NOTAVAILABLE;
4730 if ((usage & WINED3DUSAGE_DEPTHSTENCIL)
4731 && !CheckDepthStencilCapability(adapter, adapter_format, format, gl_type))
4733 TRACE("Requested WINED3DUSAGE_DEPTHSTENCIL, but format %s is not supported for depth / stencil buffers.\n",
4734 debug_d3dformat(check_format_id));
4735 return WINED3DERR_NOTAVAILABLE;
4738 if ((usage & WINED3DUSAGE_RENDERTARGET)
4739 && !CheckRenderTargetCapability(adapter, adapter_format, format, gl_type))
4741 TRACE("Requested WINED3DUSAGE_RENDERTARGET, but format %s is not supported for render targets.\n",
4742 debug_d3dformat(check_format_id));
4743 return WINED3DERR_NOTAVAILABLE;
4746 if ((usage & WINED3DUSAGE_AUTOGENMIPMAP) && !gl_info->supported[SGIS_GENERATE_MIPMAP])
4748 TRACE("No WINED3DUSAGE_AUTOGENMIPMAP support, returning WINED3DOK_NOAUTOGEN.\n");
4749 return WINED3DOK_NOAUTOGEN;
4752 return WINED3D_OK;
4755 UINT CDECL wined3d_calculate_format_pitch(const struct wined3d *wined3d, UINT adapter_idx,
4756 enum wined3d_format_id format_id, UINT width)
4758 const struct wined3d_gl_info *gl_info;
4759 unsigned int row_pitch, slice_pitch;
4761 TRACE("wined3d %p, adapter_idx %u, format_id %s, width %u.\n",
4762 wined3d, adapter_idx, debug_d3dformat(format_id), width);
4764 if (adapter_idx >= wined3d->adapter_count)
4765 return ~0u;
4767 gl_info = &wined3d->adapters[adapter_idx].gl_info;
4768 wined3d_format_calculate_pitch(wined3d_get_format(gl_info, format_id),
4769 1, width, 1, &row_pitch, &slice_pitch);
4771 return row_pitch;
4774 HRESULT CDECL wined3d_check_device_format_conversion(const struct wined3d *wined3d, UINT adapter_idx,
4775 enum wined3d_device_type device_type, enum wined3d_format_id src_format, enum wined3d_format_id dst_format)
4777 FIXME("wined3d %p, adapter_idx %u, device_type %s, src_format %s, dst_format %s stub!\n",
4778 wined3d, adapter_idx, debug_d3ddevicetype(device_type), debug_d3dformat(src_format),
4779 debug_d3dformat(dst_format));
4781 return WINED3D_OK;
4784 HRESULT CDECL wined3d_check_device_type(const struct wined3d *wined3d, UINT adapter_idx,
4785 enum wined3d_device_type device_type, enum wined3d_format_id display_format,
4786 enum wined3d_format_id backbuffer_format, BOOL windowed)
4788 BOOL present_conversion = wined3d->flags & WINED3D_PRESENT_CONVERSION;
4790 TRACE("wined3d %p, adapter_idx %u, device_type %s, display_format %s, backbuffer_format %s, windowed %#x.\n",
4791 wined3d, adapter_idx, debug_d3ddevicetype(device_type), debug_d3dformat(display_format),
4792 debug_d3dformat(backbuffer_format), windowed);
4794 if (adapter_idx >= wined3d->adapter_count)
4795 return WINED3DERR_INVALIDCALL;
4797 /* The task of this function is to check whether a certain display / backbuffer format
4798 * combination is available on the given adapter. In fullscreen mode microsoft specified
4799 * that the display format shouldn't provide alpha and that ignoring alpha the backbuffer
4800 * and display format should match exactly.
4801 * In windowed mode format conversion can occur and this depends on the driver. */
4803 /* There are only 4 display formats. */
4804 if (!(display_format == WINED3DFMT_B5G6R5_UNORM
4805 || display_format == WINED3DFMT_B5G5R5X1_UNORM
4806 || display_format == WINED3DFMT_B8G8R8X8_UNORM
4807 || display_format == WINED3DFMT_B10G10R10A2_UNORM))
4809 TRACE("Format %s is not supported as display format.\n", debug_d3dformat(display_format));
4810 return WINED3DERR_NOTAVAILABLE;
4813 if (!windowed)
4815 /* If the requested display format is not available, don't continue. */
4816 if (!wined3d_get_adapter_mode_count(wined3d, adapter_idx,
4817 display_format, WINED3D_SCANLINE_ORDERING_UNKNOWN))
4819 TRACE("No available modes for display format %s.\n", debug_d3dformat(display_format));
4820 return WINED3DERR_NOTAVAILABLE;
4823 present_conversion = FALSE;
4825 else if (display_format == WINED3DFMT_B10G10R10A2_UNORM)
4827 /* WINED3DFMT_B10G10R10A2_UNORM is only allowed in fullscreen mode. */
4828 TRACE("Unsupported format combination %s / %s in windowed mode.\n",
4829 debug_d3dformat(display_format), debug_d3dformat(backbuffer_format));
4830 return WINED3DERR_NOTAVAILABLE;
4833 if (present_conversion)
4835 /* Use the display format as back buffer format if the latter is
4836 * WINED3DFMT_UNKNOWN. */
4837 if (backbuffer_format == WINED3DFMT_UNKNOWN)
4838 backbuffer_format = display_format;
4840 if (FAILED(wined3d_check_device_format_conversion(wined3d, adapter_idx,
4841 device_type, backbuffer_format, display_format)))
4843 TRACE("Format conversion from %s to %s not supported.\n",
4844 debug_d3dformat(backbuffer_format), debug_d3dformat(display_format));
4845 return WINED3DERR_NOTAVAILABLE;
4848 else
4850 /* When format conversion from the back buffer format to the display
4851 * format is not allowed, only a limited number of combinations are
4852 * valid. */
4854 if (display_format == WINED3DFMT_B5G6R5_UNORM && backbuffer_format != WINED3DFMT_B5G6R5_UNORM)
4856 TRACE("Unsupported format combination %s / %s.\n",
4857 debug_d3dformat(display_format), debug_d3dformat(backbuffer_format));
4858 return WINED3DERR_NOTAVAILABLE;
4861 if (display_format == WINED3DFMT_B5G5R5X1_UNORM
4862 && !(backbuffer_format == WINED3DFMT_B5G5R5X1_UNORM || backbuffer_format == WINED3DFMT_B5G5R5A1_UNORM))
4864 TRACE("Unsupported format combination %s / %s.\n",
4865 debug_d3dformat(display_format), debug_d3dformat(backbuffer_format));
4866 return WINED3DERR_NOTAVAILABLE;
4869 if (display_format == WINED3DFMT_B8G8R8X8_UNORM
4870 && !(backbuffer_format == WINED3DFMT_B8G8R8X8_UNORM || backbuffer_format == WINED3DFMT_B8G8R8A8_UNORM))
4872 TRACE("Unsupported format combination %s / %s.\n",
4873 debug_d3dformat(display_format), debug_d3dformat(backbuffer_format));
4874 return WINED3DERR_NOTAVAILABLE;
4877 if (display_format == WINED3DFMT_B10G10R10A2_UNORM
4878 && backbuffer_format != WINED3DFMT_B10G10R10A2_UNORM)
4880 TRACE("Unsupported format combination %s / %s.\n",
4881 debug_d3dformat(display_format), debug_d3dformat(backbuffer_format));
4882 return WINED3DERR_NOTAVAILABLE;
4886 /* Validate that the back buffer format is usable for render targets. */
4887 if (FAILED(wined3d_check_device_format(wined3d, adapter_idx, device_type, display_format,
4888 WINED3DUSAGE_RENDERTARGET, WINED3D_RTYPE_SURFACE, backbuffer_format)))
4890 TRACE("Format %s not allowed for render targets.\n", debug_d3dformat(backbuffer_format));
4891 return WINED3DERR_NOTAVAILABLE;
4894 return WINED3D_OK;
4897 HRESULT CDECL wined3d_get_device_caps(const struct wined3d *wined3d, UINT adapter_idx,
4898 enum wined3d_device_type device_type, WINED3DCAPS *caps)
4900 const struct wined3d_adapter *adapter = &wined3d->adapters[adapter_idx];
4901 const struct wined3d_gl_info *gl_info = &adapter->gl_info;
4902 struct shader_caps shader_caps;
4903 struct fragment_caps fragment_caps;
4904 struct wined3d_vertex_caps vertex_caps;
4905 DWORD ckey_caps, blit_caps, fx_caps;
4907 TRACE("wined3d %p, adapter_idx %u, device_type %s, caps %p.\n",
4908 wined3d, adapter_idx, debug_d3ddevicetype(device_type), caps);
4910 if (adapter_idx >= wined3d->adapter_count)
4911 return WINED3DERR_INVALIDCALL;
4913 caps->DeviceType = (device_type == WINED3D_DEVICE_TYPE_HAL) ? WINED3D_DEVICE_TYPE_HAL : WINED3D_DEVICE_TYPE_REF;
4914 caps->AdapterOrdinal = adapter_idx;
4916 caps->Caps = 0;
4917 caps->Caps2 = WINED3DCAPS2_CANRENDERWINDOWED |
4918 WINED3DCAPS2_FULLSCREENGAMMA |
4919 WINED3DCAPS2_DYNAMICTEXTURES;
4920 if (gl_info->supported[SGIS_GENERATE_MIPMAP])
4921 caps->Caps2 |= WINED3DCAPS2_CANAUTOGENMIPMAP;
4923 caps->Caps3 = WINED3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD |
4924 WINED3DCAPS3_COPY_TO_VIDMEM |
4925 WINED3DCAPS3_COPY_TO_SYSTEMMEM;
4927 caps->PresentationIntervals = WINED3DPRESENT_INTERVAL_IMMEDIATE |
4928 WINED3DPRESENT_INTERVAL_ONE;
4930 caps->CursorCaps = WINED3DCURSORCAPS_COLOR |
4931 WINED3DCURSORCAPS_LOWRES;
4933 caps->DevCaps = WINED3DDEVCAPS_FLOATTLVERTEX |
4934 WINED3DDEVCAPS_EXECUTESYSTEMMEMORY |
4935 WINED3DDEVCAPS_TLVERTEXSYSTEMMEMORY|
4936 WINED3DDEVCAPS_TLVERTEXVIDEOMEMORY |
4937 WINED3DDEVCAPS_DRAWPRIMTLVERTEX |
4938 WINED3DDEVCAPS_HWTRANSFORMANDLIGHT |
4939 WINED3DDEVCAPS_EXECUTEVIDEOMEMORY |
4940 WINED3DDEVCAPS_PUREDEVICE |
4941 WINED3DDEVCAPS_HWRASTERIZATION |
4942 WINED3DDEVCAPS_TEXTUREVIDEOMEMORY |
4943 WINED3DDEVCAPS_TEXTURESYSTEMMEMORY |
4944 WINED3DDEVCAPS_CANRENDERAFTERFLIP |
4945 WINED3DDEVCAPS_DRAWPRIMITIVES2 |
4946 WINED3DDEVCAPS_DRAWPRIMITIVES2EX;
4948 caps->PrimitiveMiscCaps = WINED3DPMISCCAPS_CULLNONE |
4949 WINED3DPMISCCAPS_CULLCCW |
4950 WINED3DPMISCCAPS_CULLCW |
4951 WINED3DPMISCCAPS_COLORWRITEENABLE |
4952 WINED3DPMISCCAPS_CLIPTLVERTS |
4953 WINED3DPMISCCAPS_CLIPPLANESCALEDPOINTS |
4954 WINED3DPMISCCAPS_MASKZ |
4955 WINED3DPMISCCAPS_MRTPOSTPIXELSHADERBLENDING;
4956 /* TODO:
4957 WINED3DPMISCCAPS_NULLREFERENCE
4958 WINED3DPMISCCAPS_FOGANDSPECULARALPHA
4959 WINED3DPMISCCAPS_MRTINDEPENDENTBITDEPTHS
4960 WINED3DPMISCCAPS_FOGVERTEXCLAMPED */
4962 if (gl_info->supported[WINED3D_GL_BLEND_EQUATION])
4963 caps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_BLENDOP;
4964 if (gl_info->supported[EXT_BLEND_EQUATION_SEPARATE] && gl_info->supported[EXT_BLEND_FUNC_SEPARATE])
4965 caps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_SEPARATEALPHABLEND;
4966 if (gl_info->supported[EXT_DRAW_BUFFERS2])
4967 caps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_INDEPENDENTWRITEMASKS;
4968 if (gl_info->supported[ARB_FRAMEBUFFER_SRGB])
4969 caps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_POSTBLENDSRGBCONVERT;
4971 caps->RasterCaps = WINED3DPRASTERCAPS_DITHER |
4972 WINED3DPRASTERCAPS_PAT |
4973 WINED3DPRASTERCAPS_WFOG |
4974 WINED3DPRASTERCAPS_ZFOG |
4975 WINED3DPRASTERCAPS_FOGVERTEX |
4976 WINED3DPRASTERCAPS_FOGTABLE |
4977 WINED3DPRASTERCAPS_STIPPLE |
4978 WINED3DPRASTERCAPS_SUBPIXEL |
4979 WINED3DPRASTERCAPS_ZTEST |
4980 WINED3DPRASTERCAPS_SCISSORTEST |
4981 WINED3DPRASTERCAPS_SLOPESCALEDEPTHBIAS |
4982 WINED3DPRASTERCAPS_DEPTHBIAS;
4984 if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
4986 caps->RasterCaps |= WINED3DPRASTERCAPS_ANISOTROPY |
4987 WINED3DPRASTERCAPS_ZBIAS |
4988 WINED3DPRASTERCAPS_MIPMAPLODBIAS;
4991 caps->ZCmpCaps = WINED3DPCMPCAPS_ALWAYS |
4992 WINED3DPCMPCAPS_EQUAL |
4993 WINED3DPCMPCAPS_GREATER |
4994 WINED3DPCMPCAPS_GREATEREQUAL |
4995 WINED3DPCMPCAPS_LESS |
4996 WINED3DPCMPCAPS_LESSEQUAL |
4997 WINED3DPCMPCAPS_NEVER |
4998 WINED3DPCMPCAPS_NOTEQUAL;
5000 /* WINED3DPBLENDCAPS_BOTHINVSRCALPHA and WINED3DPBLENDCAPS_BOTHSRCALPHA
5001 * are legacy settings for srcblend only. */
5002 caps->SrcBlendCaps = WINED3DPBLENDCAPS_BOTHINVSRCALPHA |
5003 WINED3DPBLENDCAPS_BOTHSRCALPHA |
5004 WINED3DPBLENDCAPS_DESTALPHA |
5005 WINED3DPBLENDCAPS_DESTCOLOR |
5006 WINED3DPBLENDCAPS_INVDESTALPHA |
5007 WINED3DPBLENDCAPS_INVDESTCOLOR |
5008 WINED3DPBLENDCAPS_INVSRCALPHA |
5009 WINED3DPBLENDCAPS_INVSRCCOLOR |
5010 WINED3DPBLENDCAPS_ONE |
5011 WINED3DPBLENDCAPS_SRCALPHA |
5012 WINED3DPBLENDCAPS_SRCALPHASAT |
5013 WINED3DPBLENDCAPS_SRCCOLOR |
5014 WINED3DPBLENDCAPS_ZERO;
5016 caps->DestBlendCaps = WINED3DPBLENDCAPS_DESTALPHA |
5017 WINED3DPBLENDCAPS_DESTCOLOR |
5018 WINED3DPBLENDCAPS_INVDESTALPHA |
5019 WINED3DPBLENDCAPS_INVDESTCOLOR |
5020 WINED3DPBLENDCAPS_INVSRCALPHA |
5021 WINED3DPBLENDCAPS_INVSRCCOLOR |
5022 WINED3DPBLENDCAPS_ONE |
5023 WINED3DPBLENDCAPS_SRCALPHA |
5024 WINED3DPBLENDCAPS_SRCCOLOR |
5025 WINED3DPBLENDCAPS_ZERO;
5027 if (gl_info->supported[ARB_BLEND_FUNC_EXTENDED])
5028 caps->DestBlendCaps |= WINED3DPBLENDCAPS_SRCALPHASAT;
5030 if (gl_info->supported[EXT_BLEND_COLOR])
5032 caps->SrcBlendCaps |= WINED3DPBLENDCAPS_BLENDFACTOR;
5033 caps->DestBlendCaps |= WINED3DPBLENDCAPS_BLENDFACTOR;
5037 caps->AlphaCmpCaps = WINED3DPCMPCAPS_ALWAYS |
5038 WINED3DPCMPCAPS_EQUAL |
5039 WINED3DPCMPCAPS_GREATER |
5040 WINED3DPCMPCAPS_GREATEREQUAL |
5041 WINED3DPCMPCAPS_LESS |
5042 WINED3DPCMPCAPS_LESSEQUAL |
5043 WINED3DPCMPCAPS_NEVER |
5044 WINED3DPCMPCAPS_NOTEQUAL;
5046 caps->ShadeCaps = WINED3DPSHADECAPS_SPECULARGOURAUDRGB |
5047 WINED3DPSHADECAPS_COLORGOURAUDRGB |
5048 WINED3DPSHADECAPS_ALPHAFLATBLEND |
5049 WINED3DPSHADECAPS_ALPHAGOURAUDBLEND |
5050 WINED3DPSHADECAPS_COLORFLATRGB |
5051 WINED3DPSHADECAPS_FOGFLAT |
5052 WINED3DPSHADECAPS_FOGGOURAUD |
5053 WINED3DPSHADECAPS_SPECULARFLATRGB;
5055 caps->TextureCaps = WINED3DPTEXTURECAPS_ALPHA |
5056 WINED3DPTEXTURECAPS_ALPHAPALETTE |
5057 WINED3DPTEXTURECAPS_TRANSPARENCY |
5058 WINED3DPTEXTURECAPS_BORDER |
5059 WINED3DPTEXTURECAPS_MIPMAP |
5060 WINED3DPTEXTURECAPS_PROJECTED |
5061 WINED3DPTEXTURECAPS_PERSPECTIVE;
5063 if (!gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
5065 caps->TextureCaps |= WINED3DPTEXTURECAPS_POW2;
5066 if (gl_info->supported[WINED3D_GL_NORMALIZED_TEXRECT] || gl_info->supported[ARB_TEXTURE_RECTANGLE])
5067 caps->TextureCaps |= WINED3DPTEXTURECAPS_NONPOW2CONDITIONAL;
5070 if (gl_info->supported[EXT_TEXTURE3D])
5072 caps->TextureCaps |= WINED3DPTEXTURECAPS_VOLUMEMAP |
5073 WINED3DPTEXTURECAPS_MIPVOLUMEMAP;
5074 if (!gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
5076 caps->TextureCaps |= WINED3DPTEXTURECAPS_VOLUMEMAP_POW2;
5080 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
5082 caps->TextureCaps |= WINED3DPTEXTURECAPS_CUBEMAP |
5083 WINED3DPTEXTURECAPS_MIPCUBEMAP;
5084 if (!gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
5086 caps->TextureCaps |= WINED3DPTEXTURECAPS_CUBEMAP_POW2;
5090 caps->TextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
5091 WINED3DPTFILTERCAPS_MAGFPOINT |
5092 WINED3DPTFILTERCAPS_MINFLINEAR |
5093 WINED3DPTFILTERCAPS_MINFPOINT |
5094 WINED3DPTFILTERCAPS_MIPFLINEAR |
5095 WINED3DPTFILTERCAPS_MIPFPOINT |
5096 WINED3DPTFILTERCAPS_LINEAR |
5097 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
5098 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
5099 WINED3DPTFILTERCAPS_MIPLINEAR |
5100 WINED3DPTFILTERCAPS_MIPNEAREST |
5101 WINED3DPTFILTERCAPS_NEAREST;
5103 if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
5105 caps->TextureFilterCaps |= WINED3DPTFILTERCAPS_MAGFANISOTROPIC |
5106 WINED3DPTFILTERCAPS_MINFANISOTROPIC;
5109 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
5111 caps->CubeTextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
5112 WINED3DPTFILTERCAPS_MAGFPOINT |
5113 WINED3DPTFILTERCAPS_MINFLINEAR |
5114 WINED3DPTFILTERCAPS_MINFPOINT |
5115 WINED3DPTFILTERCAPS_MIPFLINEAR |
5116 WINED3DPTFILTERCAPS_MIPFPOINT |
5117 WINED3DPTFILTERCAPS_LINEAR |
5118 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
5119 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
5120 WINED3DPTFILTERCAPS_MIPLINEAR |
5121 WINED3DPTFILTERCAPS_MIPNEAREST |
5122 WINED3DPTFILTERCAPS_NEAREST;
5124 if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
5126 caps->CubeTextureFilterCaps |= WINED3DPTFILTERCAPS_MAGFANISOTROPIC |
5127 WINED3DPTFILTERCAPS_MINFANISOTROPIC;
5130 else
5132 caps->CubeTextureFilterCaps = 0;
5135 if (gl_info->supported[EXT_TEXTURE3D])
5137 caps->VolumeTextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
5138 WINED3DPTFILTERCAPS_MAGFPOINT |
5139 WINED3DPTFILTERCAPS_MINFLINEAR |
5140 WINED3DPTFILTERCAPS_MINFPOINT |
5141 WINED3DPTFILTERCAPS_MIPFLINEAR |
5142 WINED3DPTFILTERCAPS_MIPFPOINT |
5143 WINED3DPTFILTERCAPS_LINEAR |
5144 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
5145 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
5146 WINED3DPTFILTERCAPS_MIPLINEAR |
5147 WINED3DPTFILTERCAPS_MIPNEAREST |
5148 WINED3DPTFILTERCAPS_NEAREST;
5150 else
5152 caps->VolumeTextureFilterCaps = 0;
5155 caps->TextureAddressCaps = WINED3DPTADDRESSCAPS_INDEPENDENTUV |
5156 WINED3DPTADDRESSCAPS_CLAMP |
5157 WINED3DPTADDRESSCAPS_WRAP;
5159 if (gl_info->supported[ARB_TEXTURE_BORDER_CLAMP])
5161 caps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_BORDER;
5163 if (gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT])
5165 caps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRROR;
5167 if (gl_info->supported[ARB_TEXTURE_MIRROR_CLAMP_TO_EDGE])
5169 caps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRRORONCE;
5172 if (gl_info->supported[EXT_TEXTURE3D])
5174 caps->VolumeTextureAddressCaps = WINED3DPTADDRESSCAPS_INDEPENDENTUV |
5175 WINED3DPTADDRESSCAPS_CLAMP |
5176 WINED3DPTADDRESSCAPS_WRAP;
5177 if (gl_info->supported[ARB_TEXTURE_BORDER_CLAMP])
5179 caps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_BORDER;
5181 if (gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT])
5183 caps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRROR;
5185 if (gl_info->supported[ARB_TEXTURE_MIRROR_CLAMP_TO_EDGE])
5187 caps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRRORONCE;
5190 else
5192 caps->VolumeTextureAddressCaps = 0;
5195 caps->LineCaps = WINED3DLINECAPS_TEXTURE |
5196 WINED3DLINECAPS_ZTEST |
5197 WINED3DLINECAPS_BLEND |
5198 WINED3DLINECAPS_ALPHACMP |
5199 WINED3DLINECAPS_FOG;
5200 /* WINED3DLINECAPS_ANTIALIAS is not supported on Windows, and dx and gl seem to have a different
5201 * idea how generating the smoothing alpha values works; the result is different
5204 caps->MaxTextureWidth = gl_info->limits.texture_size;
5205 caps->MaxTextureHeight = gl_info->limits.texture_size;
5207 if (gl_info->supported[EXT_TEXTURE3D])
5208 caps->MaxVolumeExtent = gl_info->limits.texture3d_size;
5209 else
5210 caps->MaxVolumeExtent = 0;
5212 caps->MaxTextureRepeat = 32768;
5213 caps->MaxTextureAspectRatio = gl_info->limits.texture_size;
5214 caps->MaxVertexW = 1.0f;
5216 caps->GuardBandLeft = 0.0f;
5217 caps->GuardBandTop = 0.0f;
5218 caps->GuardBandRight = 0.0f;
5219 caps->GuardBandBottom = 0.0f;
5221 caps->ExtentsAdjust = 0.0f;
5223 caps->StencilCaps = WINED3DSTENCILCAPS_DECRSAT |
5224 WINED3DSTENCILCAPS_INCRSAT |
5225 WINED3DSTENCILCAPS_INVERT |
5226 WINED3DSTENCILCAPS_KEEP |
5227 WINED3DSTENCILCAPS_REPLACE |
5228 WINED3DSTENCILCAPS_ZERO;
5229 if (gl_info->supported[EXT_STENCIL_WRAP])
5231 caps->StencilCaps |= WINED3DSTENCILCAPS_DECR |
5232 WINED3DSTENCILCAPS_INCR;
5234 if (gl_info->supported[WINED3D_GL_VERSION_2_0] || gl_info->supported[EXT_STENCIL_TWO_SIDE]
5235 || gl_info->supported[ATI_SEPARATE_STENCIL])
5237 caps->StencilCaps |= WINED3DSTENCILCAPS_TWOSIDED;
5240 caps->MaxAnisotropy = gl_info->limits.anisotropy;
5241 caps->MaxPointSize = gl_info->limits.pointsize_max;
5243 caps->MaxPrimitiveCount = 0x555555; /* Taken from an AMD Radeon HD 5700 (Evergreen) GPU. */
5244 caps->MaxVertexIndex = 0xffffff; /* Taken from an AMD Radeon HD 5700 (Evergreen) GPU. */
5245 caps->MaxStreams = MAX_STREAMS;
5246 caps->MaxStreamStride = 1024;
5248 /* d3d9.dll sets D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES here because StretchRects is implemented in d3d9 */
5249 caps->DevCaps2 = WINED3DDEVCAPS2_STREAMOFFSET |
5250 WINED3DDEVCAPS2_VERTEXELEMENTSCANSHARESTREAMOFFSET;
5251 caps->MaxNpatchTessellationLevel = 0;
5252 caps->MasterAdapterOrdinal = 0;
5253 caps->AdapterOrdinalInGroup = 0;
5254 caps->NumberOfAdaptersInGroup = 1;
5256 caps->NumSimultaneousRTs = gl_info->limits.buffers;
5258 caps->StretchRectFilterCaps = WINED3DPTFILTERCAPS_MINFPOINT |
5259 WINED3DPTFILTERCAPS_MAGFPOINT |
5260 WINED3DPTFILTERCAPS_MINFLINEAR |
5261 WINED3DPTFILTERCAPS_MAGFLINEAR;
5262 caps->VertexTextureFilterCaps = 0;
5264 adapter->shader_backend->shader_get_caps(&adapter->gl_info, &shader_caps);
5265 adapter->fragment_pipe->get_caps(&adapter->gl_info, &fragment_caps);
5266 adapter->vertex_pipe->vp_get_caps(&adapter->gl_info, &vertex_caps);
5268 /* Add shader misc caps. Only some of them belong to the shader parts of the pipeline */
5269 caps->PrimitiveMiscCaps |= fragment_caps.PrimitiveMiscCaps;
5271 caps->VertexShaderVersion = shader_caps.vs_version;
5272 caps->MaxVertexShaderConst = shader_caps.vs_uniform_count;
5274 caps->PixelShaderVersion = shader_caps.ps_version;
5275 caps->PixelShader1xMaxValue = shader_caps.ps_1x_max_value;
5277 caps->TextureOpCaps = fragment_caps.TextureOpCaps;
5278 caps->MaxTextureBlendStages = fragment_caps.MaxTextureBlendStages;
5279 caps->MaxSimultaneousTextures = fragment_caps.MaxSimultaneousTextures;
5281 caps->MaxUserClipPlanes = vertex_caps.max_user_clip_planes;
5282 caps->MaxActiveLights = vertex_caps.max_active_lights;
5283 caps->MaxVertexBlendMatrices = vertex_caps.max_vertex_blend_matrices;
5284 caps->MaxVertexBlendMatrixIndex = vertex_caps.max_vertex_blend_matrix_index;
5285 caps->VertexProcessingCaps = vertex_caps.vertex_processing_caps;
5286 caps->FVFCaps = vertex_caps.fvf_caps;
5287 caps->RasterCaps |= vertex_caps.raster_caps;
5289 /* The following caps are shader specific, but they are things we cannot detect, or which
5290 * are the same among all shader models. So to avoid code duplication set the shader version
5291 * specific, but otherwise constant caps here
5293 if (caps->VertexShaderVersion >= 3)
5295 /* Where possible set the caps based on OpenGL extensions and if they
5296 * aren't set (in case of software rendering) use the VS 3.0 from
5297 * MSDN or else if there's OpenGL spec use a hardcoded value minimum
5298 * VS3.0 value. */
5299 caps->VS20Caps.caps = WINED3DVS20CAPS_PREDICATION;
5300 /* VS 3.0 requires MAX_DYNAMICFLOWCONTROLDEPTH (24) */
5301 caps->VS20Caps.dynamic_flow_control_depth = WINED3DVS20_MAX_DYNAMICFLOWCONTROLDEPTH;
5302 caps->VS20Caps.temp_count = max(32, adapter->gl_info.limits.arb_vs_temps);
5303 /* level of nesting in loops / if-statements; VS 3.0 requires MAX (4) */
5304 caps->VS20Caps.static_flow_control_depth = WINED3DVS20_MAX_STATICFLOWCONTROLDEPTH;
5306 caps->MaxVShaderInstructionsExecuted = 65535; /* VS 3.0 needs at least 65535, some cards even use 2^32-1 */
5307 caps->MaxVertexShader30InstructionSlots = max(512, adapter->gl_info.limits.arb_vs_instructions);
5308 caps->VertexTextureFilterCaps = WINED3DPTFILTERCAPS_MINFPOINT | WINED3DPTFILTERCAPS_MAGFPOINT;
5310 else if (caps->VertexShaderVersion == 2)
5312 caps->VS20Caps.caps = 0;
5313 caps->VS20Caps.dynamic_flow_control_depth = WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH;
5314 caps->VS20Caps.temp_count = max(12, adapter->gl_info.limits.arb_vs_temps);
5315 caps->VS20Caps.static_flow_control_depth = 1;
5317 caps->MaxVShaderInstructionsExecuted = 65535;
5318 caps->MaxVertexShader30InstructionSlots = 0;
5320 else
5321 { /* VS 1.x */
5322 caps->VS20Caps.caps = 0;
5323 caps->VS20Caps.dynamic_flow_control_depth = 0;
5324 caps->VS20Caps.temp_count = 0;
5325 caps->VS20Caps.static_flow_control_depth = 0;
5327 caps->MaxVShaderInstructionsExecuted = 0;
5328 caps->MaxVertexShader30InstructionSlots = 0;
5331 if (caps->PixelShaderVersion >= 3)
5333 /* Where possible set the caps based on OpenGL extensions and if they
5334 * aren't set (in case of software rendering) use the PS 3.0 from
5335 * MSDN or else if there's OpenGL spec use a hardcoded value minimum
5336 * PS 3.0 value. */
5338 /* Caps is more or less undocumented on MSDN but it appears to be
5339 * used for PS20Caps based on results from R9600/FX5900/Geforce6800
5340 * cards from Windows */
5341 caps->PS20Caps.caps = WINED3DPS20CAPS_ARBITRARYSWIZZLE |
5342 WINED3DPS20CAPS_GRADIENTINSTRUCTIONS |
5343 WINED3DPS20CAPS_PREDICATION |
5344 WINED3DPS20CAPS_NODEPENDENTREADLIMIT |
5345 WINED3DPS20CAPS_NOTEXINSTRUCTIONLIMIT;
5346 /* PS 3.0 requires MAX_DYNAMICFLOWCONTROLDEPTH (24) */
5347 caps->PS20Caps.dynamic_flow_control_depth = WINED3DPS20_MAX_DYNAMICFLOWCONTROLDEPTH;
5348 caps->PS20Caps.temp_count = max(32, adapter->gl_info.limits.arb_ps_temps);
5349 /* PS 3.0 requires MAX_STATICFLOWCONTROLDEPTH (4) */
5350 caps->PS20Caps.static_flow_control_depth = WINED3DPS20_MAX_STATICFLOWCONTROLDEPTH;
5351 /* PS 3.0 requires MAX_NUMINSTRUCTIONSLOTS (512) */
5352 caps->PS20Caps.instruction_slot_count = WINED3DPS20_MAX_NUMINSTRUCTIONSLOTS;
5354 caps->MaxPShaderInstructionsExecuted = 65535;
5355 caps->MaxPixelShader30InstructionSlots = max(WINED3DMIN30SHADERINSTRUCTIONS,
5356 adapter->gl_info.limits.arb_ps_instructions);
5358 else if(caps->PixelShaderVersion == 2)
5360 /* Below we assume PS2.0 specs, not extended 2.0a(GeforceFX)/2.0b(Radeon R3xx) ones */
5361 caps->PS20Caps.caps = 0;
5362 caps->PS20Caps.dynamic_flow_control_depth = 0; /* WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH = 0 */
5363 caps->PS20Caps.temp_count = max(12, adapter->gl_info.limits.arb_ps_temps);
5364 caps->PS20Caps.static_flow_control_depth = WINED3DPS20_MIN_STATICFLOWCONTROLDEPTH; /* Minimum: 1 */
5365 /* Minimum number (64 ALU + 32 Texture), a GeforceFX uses 512 */
5366 caps->PS20Caps.instruction_slot_count = WINED3DPS20_MIN_NUMINSTRUCTIONSLOTS;
5368 caps->MaxPShaderInstructionsExecuted = 512; /* Minimum value, a GeforceFX uses 1024 */
5369 caps->MaxPixelShader30InstructionSlots = 0;
5371 else /* PS 1.x */
5373 caps->PS20Caps.caps = 0;
5374 caps->PS20Caps.dynamic_flow_control_depth = 0;
5375 caps->PS20Caps.temp_count = 0;
5376 caps->PS20Caps.static_flow_control_depth = 0;
5377 caps->PS20Caps.instruction_slot_count = 0;
5379 caps->MaxPShaderInstructionsExecuted = 0;
5380 caps->MaxPixelShader30InstructionSlots = 0;
5383 if (caps->VertexShaderVersion >= 2)
5385 /* OpenGL supports all the formats below, perhaps not always
5386 * without conversion, but it supports them.
5387 * Further GLSL doesn't seem to have an official unsigned type so
5388 * don't advertise it yet as I'm not sure how we handle it.
5389 * We might need to add some clamping in the shader engine to
5390 * support it.
5391 * TODO: WINED3DDTCAPS_USHORT2N, WINED3DDTCAPS_USHORT4N, WINED3DDTCAPS_UDEC3, WINED3DDTCAPS_DEC3N */
5392 caps->DeclTypes = WINED3DDTCAPS_UBYTE4 |
5393 WINED3DDTCAPS_UBYTE4N |
5394 WINED3DDTCAPS_SHORT2N |
5395 WINED3DDTCAPS_SHORT4N;
5396 if (gl_info->supported[ARB_HALF_FLOAT_VERTEX])
5398 caps->DeclTypes |= WINED3DDTCAPS_FLOAT16_2 |
5399 WINED3DDTCAPS_FLOAT16_4;
5402 else
5404 caps->DeclTypes = 0;
5407 /* Set DirectDraw helper Caps */
5408 ckey_caps = WINEDDCKEYCAPS_DESTBLT |
5409 WINEDDCKEYCAPS_SRCBLT;
5410 fx_caps = WINEDDFXCAPS_BLTALPHA |
5411 WINEDDFXCAPS_BLTMIRRORLEFTRIGHT |
5412 WINEDDFXCAPS_BLTMIRRORUPDOWN |
5413 WINEDDFXCAPS_BLTROTATION90 |
5414 WINEDDFXCAPS_BLTSHRINKX |
5415 WINEDDFXCAPS_BLTSHRINKXN |
5416 WINEDDFXCAPS_BLTSHRINKY |
5417 WINEDDFXCAPS_BLTSHRINKYN |
5418 WINEDDFXCAPS_BLTSTRETCHX |
5419 WINEDDFXCAPS_BLTSTRETCHXN |
5420 WINEDDFXCAPS_BLTSTRETCHY |
5421 WINEDDFXCAPS_BLTSTRETCHYN;
5422 blit_caps = WINEDDCAPS_BLT |
5423 WINEDDCAPS_BLTCOLORFILL |
5424 WINEDDCAPS_BLTDEPTHFILL |
5425 WINEDDCAPS_BLTSTRETCH |
5426 WINEDDCAPS_CANBLTSYSMEM |
5427 WINEDDCAPS_CANCLIP |
5428 WINEDDCAPS_CANCLIPSTRETCHED |
5429 WINEDDCAPS_COLORKEY |
5430 WINEDDCAPS_COLORKEYHWASSIST |
5431 WINEDDCAPS_ALIGNBOUNDARYSRC;
5433 /* Fill the ddraw caps structure */
5434 caps->ddraw_caps.caps = WINEDDCAPS_GDI |
5435 WINEDDCAPS_PALETTE |
5436 blit_caps;
5437 caps->ddraw_caps.caps2 = WINEDDCAPS2_CERTIFIED |
5438 WINEDDCAPS2_NOPAGELOCKREQUIRED |
5439 WINEDDCAPS2_PRIMARYGAMMA |
5440 WINEDDCAPS2_WIDESURFACES |
5441 WINEDDCAPS2_CANRENDERWINDOWED;
5442 caps->ddraw_caps.color_key_caps = ckey_caps;
5443 caps->ddraw_caps.fx_caps = fx_caps;
5444 caps->ddraw_caps.svb_caps = blit_caps;
5445 caps->ddraw_caps.svb_color_key_caps = ckey_caps;
5446 caps->ddraw_caps.svb_fx_caps = fx_caps;
5447 caps->ddraw_caps.vsb_caps = blit_caps;
5448 caps->ddraw_caps.vsb_color_key_caps = ckey_caps;
5449 caps->ddraw_caps.vsb_fx_caps = fx_caps;
5450 caps->ddraw_caps.ssb_caps = blit_caps;
5451 caps->ddraw_caps.ssb_color_key_caps = ckey_caps;
5452 caps->ddraw_caps.ssb_fx_caps = fx_caps;
5454 caps->ddraw_caps.dds_caps = WINEDDSCAPS_ALPHA |
5455 WINEDDSCAPS_BACKBUFFER |
5456 WINEDDSCAPS_FLIP |
5457 WINEDDSCAPS_FRONTBUFFER |
5458 WINEDDSCAPS_OFFSCREENPLAIN |
5459 WINEDDSCAPS_PALETTE |
5460 WINEDDSCAPS_PRIMARYSURFACE |
5461 WINEDDSCAPS_SYSTEMMEMORY |
5462 WINEDDSCAPS_VIDEOMEMORY |
5463 WINEDDSCAPS_VISIBLE;
5465 if (!(wined3d->flags & WINED3D_NO3D))
5467 caps->ddraw_caps.dds_caps |= WINEDDSCAPS_3DDEVICE |
5468 WINEDDSCAPS_MIPMAP |
5469 WINEDDSCAPS_TEXTURE |
5470 WINEDDSCAPS_ZBUFFER;
5471 caps->ddraw_caps.caps |= WINEDDCAPS_3D;
5474 return WINED3D_OK;
5477 HRESULT CDECL wined3d_device_create(struct wined3d *wined3d, UINT adapter_idx, enum wined3d_device_type device_type,
5478 HWND focus_window, DWORD flags, BYTE surface_alignment, struct wined3d_device_parent *device_parent,
5479 struct wined3d_device **device)
5481 struct wined3d_device *object;
5482 HRESULT hr;
5484 TRACE("wined3d %p, adapter_idx %u, device_type %#x, focus_window %p, flags %#x, surface_alignment %u, device_parent %p, device %p.\n",
5485 wined3d, adapter_idx, device_type, focus_window, flags, surface_alignment, device_parent, device);
5487 /* Validate the adapter number. If no adapters are available(no GL), ignore the adapter
5488 * number and create a device without a 3D adapter for 2D only operation. */
5489 if (wined3d->adapter_count && adapter_idx >= wined3d->adapter_count)
5490 return WINED3DERR_INVALIDCALL;
5492 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
5493 if (!object)
5494 return E_OUTOFMEMORY;
5496 hr = device_init(object, wined3d, adapter_idx, device_type,
5497 focus_window, flags, surface_alignment, device_parent);
5498 if (FAILED(hr))
5500 WARN("Failed to initialize device, hr %#x.\n", hr);
5501 HeapFree(GetProcessHeap(), 0, object);
5502 return hr;
5505 TRACE("Created device %p.\n", object);
5506 *device = object;
5508 device_parent->ops->wined3d_device_created(device_parent, *device);
5510 return WINED3D_OK;
5513 static void WINE_GLAPI invalid_func(const void *data)
5515 ERR("Invalid vertex attribute function called\n");
5516 DebugBreak();
5519 static void WINE_GLAPI invalid_texcoord_func(GLenum unit, const void *data)
5521 ERR("Invalid texcoord function called\n");
5522 DebugBreak();
5525 /* Helper functions for providing vertex data to opengl. The arrays are initialized based on
5526 * the extension detection and are used in drawStridedSlow
5528 static void WINE_GLAPI position_d3dcolor(const void *data)
5530 DWORD pos = *((const DWORD *)data);
5532 FIXME("Add a test for fixed function position from d3dcolor type\n");
5533 context_get_current()->gl_info->gl_ops.gl.p_glVertex4s(D3DCOLOR_B_R(pos),
5534 D3DCOLOR_B_G(pos),
5535 D3DCOLOR_B_B(pos),
5536 D3DCOLOR_B_A(pos));
5539 static void WINE_GLAPI position_float4(const void *data)
5541 const GLfloat *pos = data;
5543 if (pos[3] != 0.0f && pos[3] != 1.0f)
5545 float w = 1.0f / pos[3];
5547 context_get_current()->gl_info->gl_ops.gl.p_glVertex4f(pos[0] * w, pos[1] * w, pos[2] * w, w);
5549 else
5551 context_get_current()->gl_info->gl_ops.gl.p_glVertex3fv(pos);
5555 static void WINE_GLAPI diffuse_d3dcolor(const void *data)
5557 DWORD diffuseColor = *((const DWORD *)data);
5559 context_get_current()->gl_info->gl_ops.gl.p_glColor4ub(D3DCOLOR_B_R(diffuseColor),
5560 D3DCOLOR_B_G(diffuseColor),
5561 D3DCOLOR_B_B(diffuseColor),
5562 D3DCOLOR_B_A(diffuseColor));
5565 static void WINE_GLAPI specular_d3dcolor(const void *data)
5567 DWORD specularColor = *((const DWORD *)data);
5568 GLubyte d[] =
5570 D3DCOLOR_B_R(specularColor),
5571 D3DCOLOR_B_G(specularColor),
5572 D3DCOLOR_B_B(specularColor)
5575 context_get_current()->gl_info->gl_ops.ext.p_glSecondaryColor3ubvEXT(d);
5578 static void WINE_GLAPI warn_no_specular_func(const void *data)
5580 WARN("GL_EXT_secondary_color not supported\n");
5583 static void wined3d_adapter_init_ffp_attrib_ops(struct wined3d_adapter *adapter)
5585 const struct wined3d_gl_info *gl_info = &adapter->gl_info;
5586 struct wined3d_d3d_info *d3d_info = &adapter->d3d_info;
5587 struct wined3d_ffp_attrib_ops *ops = &d3d_info->ffp_attrib_ops;
5589 ops->position[WINED3D_FFP_EMIT_FLOAT1] = invalid_func;
5590 ops->position[WINED3D_FFP_EMIT_FLOAT2] = invalid_func;
5591 ops->position[WINED3D_FFP_EMIT_FLOAT3] = (wined3d_ffp_attrib_func)gl_info->gl_ops.gl.p_glVertex3fv;
5592 if (!d3d_info->xyzrhw)
5593 ops->position[WINED3D_FFP_EMIT_FLOAT4] = position_float4;
5594 else
5595 ops->position[WINED3D_FFP_EMIT_FLOAT4] = (wined3d_ffp_attrib_func)gl_info->gl_ops.gl.p_glVertex4fv;
5596 ops->position[WINED3D_FFP_EMIT_D3DCOLOR] = position_d3dcolor;
5597 ops->position[WINED3D_FFP_EMIT_UBYTE4] = invalid_func;
5598 ops->position[WINED3D_FFP_EMIT_SHORT2] = invalid_func;
5599 ops->position[WINED3D_FFP_EMIT_SHORT4] = (wined3d_ffp_attrib_func)gl_info->gl_ops.gl.p_glVertex2sv;
5600 ops->position[WINED3D_FFP_EMIT_UBYTE4N] = invalid_func;
5601 ops->position[WINED3D_FFP_EMIT_SHORT2N] = invalid_func;
5602 ops->position[WINED3D_FFP_EMIT_SHORT4N] = invalid_func;
5603 ops->position[WINED3D_FFP_EMIT_USHORT2N] = invalid_func;
5604 ops->position[WINED3D_FFP_EMIT_USHORT4N] = invalid_func;
5605 ops->position[WINED3D_FFP_EMIT_UDEC3] = invalid_func;
5606 ops->position[WINED3D_FFP_EMIT_DEC3N] = invalid_func;
5607 ops->position[WINED3D_FFP_EMIT_FLOAT16_2] = invalid_func;
5608 ops->position[WINED3D_FFP_EMIT_FLOAT16_4] = invalid_func;
5609 ops->position[WINED3D_FFP_EMIT_INVALID] = invalid_func;
5611 ops->diffuse[WINED3D_FFP_EMIT_FLOAT1] = invalid_func;
5612 ops->diffuse[WINED3D_FFP_EMIT_FLOAT2] = invalid_func;
5613 ops->diffuse[WINED3D_FFP_EMIT_FLOAT3] = (wined3d_ffp_attrib_func)gl_info->gl_ops.gl.p_glColor3fv;
5614 ops->diffuse[WINED3D_FFP_EMIT_FLOAT4] = (wined3d_ffp_attrib_func)gl_info->gl_ops.gl.p_glColor4fv;
5615 ops->diffuse[WINED3D_FFP_EMIT_D3DCOLOR] = diffuse_d3dcolor;
5616 ops->diffuse[WINED3D_FFP_EMIT_UBYTE4] = invalid_func;
5617 ops->diffuse[WINED3D_FFP_EMIT_SHORT2] = invalid_func;
5618 ops->diffuse[WINED3D_FFP_EMIT_SHORT4] = invalid_func;
5619 ops->diffuse[WINED3D_FFP_EMIT_UBYTE4N] = (wined3d_ffp_attrib_func)gl_info->gl_ops.gl.p_glColor4ubv;
5620 ops->diffuse[WINED3D_FFP_EMIT_SHORT2N] = invalid_func;
5621 ops->diffuse[WINED3D_FFP_EMIT_SHORT4N] = (wined3d_ffp_attrib_func)gl_info->gl_ops.gl.p_glColor4sv;
5622 ops->diffuse[WINED3D_FFP_EMIT_USHORT2N] = invalid_func;
5623 ops->diffuse[WINED3D_FFP_EMIT_USHORT4N] = (wined3d_ffp_attrib_func)gl_info->gl_ops.gl.p_glColor4usv;
5624 ops->diffuse[WINED3D_FFP_EMIT_UDEC3] = invalid_func;
5625 ops->diffuse[WINED3D_FFP_EMIT_DEC3N] = invalid_func;
5626 ops->diffuse[WINED3D_FFP_EMIT_FLOAT16_2] = invalid_func;
5627 ops->diffuse[WINED3D_FFP_EMIT_FLOAT16_4] = invalid_func;
5628 ops->diffuse[WINED3D_FFP_EMIT_INVALID] = invalid_func;
5630 /* No 4 component entry points here. */
5631 ops->specular[WINED3D_FFP_EMIT_FLOAT1] = invalid_func;
5632 ops->specular[WINED3D_FFP_EMIT_FLOAT2] = invalid_func;
5633 if (gl_info->supported[EXT_SECONDARY_COLOR])
5634 ops->specular[WINED3D_FFP_EMIT_FLOAT3] = (wined3d_ffp_attrib_func)GL_EXTCALL(glSecondaryColor3fvEXT);
5635 else
5636 ops->specular[WINED3D_FFP_EMIT_FLOAT3] = warn_no_specular_func;
5637 ops->specular[WINED3D_FFP_EMIT_FLOAT4] = invalid_func;
5638 if (gl_info->supported[EXT_SECONDARY_COLOR])
5639 ops->specular[WINED3D_FFP_EMIT_D3DCOLOR] = specular_d3dcolor;
5640 else
5641 ops->specular[WINED3D_FFP_EMIT_D3DCOLOR] = warn_no_specular_func;
5642 ops->specular[WINED3D_FFP_EMIT_UBYTE4] = invalid_func;
5643 ops->specular[WINED3D_FFP_EMIT_SHORT2] = invalid_func;
5644 ops->specular[WINED3D_FFP_EMIT_SHORT4] = invalid_func;
5645 ops->specular[WINED3D_FFP_EMIT_UBYTE4N] = invalid_func;
5646 ops->specular[WINED3D_FFP_EMIT_SHORT2N] = invalid_func;
5647 ops->specular[WINED3D_FFP_EMIT_SHORT4N] = invalid_func;
5648 ops->specular[WINED3D_FFP_EMIT_USHORT2N] = invalid_func;
5649 ops->specular[WINED3D_FFP_EMIT_USHORT4N] = invalid_func;
5650 ops->specular[WINED3D_FFP_EMIT_UDEC3] = invalid_func;
5651 ops->specular[WINED3D_FFP_EMIT_DEC3N] = invalid_func;
5652 ops->specular[WINED3D_FFP_EMIT_FLOAT16_2] = invalid_func;
5653 ops->specular[WINED3D_FFP_EMIT_FLOAT16_4] = invalid_func;
5654 ops->specular[WINED3D_FFP_EMIT_INVALID] = invalid_func;
5656 /* Only 3 component entry points here. Test how others behave. Float4
5657 * normals are used by one of our tests, trying to pass it to the pixel
5658 * shader, which fails on Windows. */
5659 ops->normal[WINED3D_FFP_EMIT_FLOAT1] = invalid_func;
5660 ops->normal[WINED3D_FFP_EMIT_FLOAT2] = invalid_func;
5661 ops->normal[WINED3D_FFP_EMIT_FLOAT3] = (wined3d_ffp_attrib_func)gl_info->gl_ops.gl.p_glNormal3fv;
5662 /* Just ignore the 4th value. */
5663 ops->normal[WINED3D_FFP_EMIT_FLOAT4] = (wined3d_ffp_attrib_func)gl_info->gl_ops.gl.p_glNormal3fv;
5664 ops->normal[WINED3D_FFP_EMIT_D3DCOLOR] = invalid_func;
5665 ops->normal[WINED3D_FFP_EMIT_UBYTE4] = invalid_func;
5666 ops->normal[WINED3D_FFP_EMIT_SHORT2] = invalid_func;
5667 ops->normal[WINED3D_FFP_EMIT_SHORT4] = invalid_func;
5668 ops->normal[WINED3D_FFP_EMIT_UBYTE4N] = invalid_func;
5669 ops->normal[WINED3D_FFP_EMIT_SHORT2N] = invalid_func;
5670 ops->normal[WINED3D_FFP_EMIT_SHORT4N] = invalid_func;
5671 ops->normal[WINED3D_FFP_EMIT_USHORT2N] = invalid_func;
5672 ops->normal[WINED3D_FFP_EMIT_USHORT4N] = invalid_func;
5673 ops->normal[WINED3D_FFP_EMIT_UDEC3] = invalid_func;
5674 ops->normal[WINED3D_FFP_EMIT_DEC3N] = invalid_func;
5675 ops->normal[WINED3D_FFP_EMIT_FLOAT16_2] = invalid_func;
5676 ops->normal[WINED3D_FFP_EMIT_FLOAT16_4] = invalid_func;
5677 ops->normal[WINED3D_FFP_EMIT_INVALID] = invalid_func;
5679 ops->texcoord[WINED3D_FFP_EMIT_FLOAT1] = (wined3d_ffp_texcoord_func)gl_info->gl_ops.ext.p_glMultiTexCoord1fvARB;
5680 ops->texcoord[WINED3D_FFP_EMIT_FLOAT2] = (wined3d_ffp_texcoord_func)gl_info->gl_ops.ext.p_glMultiTexCoord2fvARB;
5681 ops->texcoord[WINED3D_FFP_EMIT_FLOAT3] = (wined3d_ffp_texcoord_func)gl_info->gl_ops.ext.p_glMultiTexCoord3fvARB;
5682 ops->texcoord[WINED3D_FFP_EMIT_FLOAT4] = (wined3d_ffp_texcoord_func)gl_info->gl_ops.ext.p_glMultiTexCoord4fvARB;
5683 ops->texcoord[WINED3D_FFP_EMIT_D3DCOLOR] = invalid_texcoord_func;
5684 ops->texcoord[WINED3D_FFP_EMIT_UBYTE4] = invalid_texcoord_func;
5685 ops->texcoord[WINED3D_FFP_EMIT_SHORT2] = (wined3d_ffp_texcoord_func)gl_info->gl_ops.ext.p_glMultiTexCoord2svARB;
5686 ops->texcoord[WINED3D_FFP_EMIT_SHORT4] = (wined3d_ffp_texcoord_func)gl_info->gl_ops.ext.p_glMultiTexCoord4svARB;
5687 ops->texcoord[WINED3D_FFP_EMIT_UBYTE4N] = invalid_texcoord_func;
5688 ops->texcoord[WINED3D_FFP_EMIT_SHORT2N] = invalid_texcoord_func;
5689 ops->texcoord[WINED3D_FFP_EMIT_SHORT4N] = invalid_texcoord_func;
5690 ops->texcoord[WINED3D_FFP_EMIT_USHORT2N] = invalid_texcoord_func;
5691 ops->texcoord[WINED3D_FFP_EMIT_USHORT4N] = invalid_texcoord_func;
5692 ops->texcoord[WINED3D_FFP_EMIT_UDEC3] = invalid_texcoord_func;
5693 ops->texcoord[WINED3D_FFP_EMIT_DEC3N] = invalid_texcoord_func;
5694 if (gl_info->supported[NV_HALF_FLOAT])
5696 /* Not supported by ARB_HALF_FLOAT_VERTEX, so check for NV_HALF_FLOAT. */
5697 ops->texcoord[WINED3D_FFP_EMIT_FLOAT16_2] =
5698 (wined3d_ffp_texcoord_func)gl_info->gl_ops.ext.p_glMultiTexCoord2hvNV;
5699 ops->texcoord[WINED3D_FFP_EMIT_FLOAT16_4] =
5700 (wined3d_ffp_texcoord_func)gl_info->gl_ops.ext.p_glMultiTexCoord4hvNV;
5702 else
5704 ops->texcoord[WINED3D_FFP_EMIT_FLOAT16_2] = invalid_texcoord_func;
5705 ops->texcoord[WINED3D_FFP_EMIT_FLOAT16_4] = invalid_texcoord_func;
5707 ops->texcoord[WINED3D_FFP_EMIT_INVALID] = invalid_texcoord_func;
5710 static void wined3d_adapter_init_fb_cfgs(struct wined3d_adapter *adapter, HDC dc)
5712 const struct wined3d_gl_info *gl_info = &adapter->gl_info;
5713 int i;
5715 if (gl_info->supported[WGL_ARB_PIXEL_FORMAT])
5717 UINT attrib_count = 0;
5718 GLint cfg_count;
5719 int attribs[11];
5720 int values[11];
5721 int attribute;
5723 attribute = WGL_NUMBER_PIXEL_FORMATS_ARB;
5724 GL_EXTCALL(wglGetPixelFormatAttribivARB(dc, 0, 0, 1, &attribute, &cfg_count));
5726 adapter->cfgs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cfg_count * sizeof(*adapter->cfgs));
5727 attribs[attrib_count++] = WGL_RED_BITS_ARB;
5728 attribs[attrib_count++] = WGL_GREEN_BITS_ARB;
5729 attribs[attrib_count++] = WGL_BLUE_BITS_ARB;
5730 attribs[attrib_count++] = WGL_ALPHA_BITS_ARB;
5731 attribs[attrib_count++] = WGL_COLOR_BITS_ARB;
5732 attribs[attrib_count++] = WGL_DEPTH_BITS_ARB;
5733 attribs[attrib_count++] = WGL_STENCIL_BITS_ARB;
5734 attribs[attrib_count++] = WGL_DRAW_TO_WINDOW_ARB;
5735 attribs[attrib_count++] = WGL_PIXEL_TYPE_ARB;
5736 attribs[attrib_count++] = WGL_DOUBLE_BUFFER_ARB;
5737 attribs[attrib_count++] = WGL_AUX_BUFFERS_ARB;
5739 for (i = 0, adapter->cfg_count = 0; i < cfg_count; ++i)
5741 struct wined3d_pixel_format *cfg = &adapter->cfgs[adapter->cfg_count];
5742 int format_id = i + 1;
5744 if (!GL_EXTCALL(wglGetPixelFormatAttribivARB(dc, format_id, 0, attrib_count, attribs, values)))
5745 continue;
5747 cfg->iPixelFormat = format_id;
5748 cfg->redSize = values[0];
5749 cfg->greenSize = values[1];
5750 cfg->blueSize = values[2];
5751 cfg->alphaSize = values[3];
5752 cfg->colorSize = values[4];
5753 cfg->depthSize = values[5];
5754 cfg->stencilSize = values[6];
5755 cfg->windowDrawable = values[7];
5756 cfg->iPixelType = values[8];
5757 cfg->doubleBuffer = values[9];
5758 cfg->auxBuffers = values[10];
5760 cfg->numSamples = 0;
5761 /* Check multisample support. */
5762 if (gl_info->supported[ARB_MULTISAMPLE])
5764 int attribs[2] = {WGL_SAMPLE_BUFFERS_ARB, WGL_SAMPLES_ARB};
5765 int values[2];
5767 if (GL_EXTCALL(wglGetPixelFormatAttribivARB(dc, format_id, 0, 2, attribs, values)))
5769 /* values[0] = WGL_SAMPLE_BUFFERS_ARB which tells whether
5770 * multisampling is supported. values[1] = number of
5771 * multisample buffers. */
5772 if (values[0])
5773 cfg->numSamples = values[1];
5777 TRACE("iPixelFormat=%d, iPixelType=%#x, doubleBuffer=%d, RGBA=%d/%d/%d/%d, "
5778 "depth=%d, stencil=%d, samples=%d, windowDrawable=%d\n",
5779 cfg->iPixelFormat, cfg->iPixelType, cfg->doubleBuffer,
5780 cfg->redSize, cfg->greenSize, cfg->blueSize, cfg->alphaSize,
5781 cfg->depthSize, cfg->stencilSize, cfg->numSamples, cfg->windowDrawable);
5783 ++adapter->cfg_count;
5786 else
5788 int cfg_count;
5790 cfg_count = DescribePixelFormat(dc, 0, 0, 0);
5791 adapter->cfgs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cfg_count * sizeof(*adapter->cfgs));
5793 for (i = 0, adapter->cfg_count = 0; i < cfg_count; ++i)
5795 struct wined3d_pixel_format *cfg = &adapter->cfgs[adapter->cfg_count];
5796 PIXELFORMATDESCRIPTOR pfd;
5797 int format_id = i + 1;
5799 if (!DescribePixelFormat(dc, format_id, sizeof(pfd), &pfd))
5800 continue;
5802 /* We only want HW acceleration using an OpenGL ICD driver.
5803 * PFD_GENERIC_FORMAT = slow opengl 1.1 gdi software rendering.
5804 * PFD_GENERIC_ACCELERATED = partial hw acceleration using a MCD
5805 * driver (e.g. 3dfx minigl). */
5806 if (pfd.dwFlags & (PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED))
5808 TRACE("Skipping format %d because it isn't ICD accelerated.\n", format_id);
5809 continue;
5812 cfg->iPixelFormat = format_id;
5813 cfg->redSize = pfd.cRedBits;
5814 cfg->greenSize = pfd.cGreenBits;
5815 cfg->blueSize = pfd.cBlueBits;
5816 cfg->alphaSize = pfd.cAlphaBits;
5817 cfg->colorSize = pfd.cColorBits;
5818 cfg->depthSize = pfd.cDepthBits;
5819 cfg->stencilSize = pfd.cStencilBits;
5820 cfg->windowDrawable = (pfd.dwFlags & PFD_DRAW_TO_WINDOW) ? 1 : 0;
5821 cfg->iPixelType = (pfd.iPixelType == PFD_TYPE_RGBA) ? WGL_TYPE_RGBA_ARB : WGL_TYPE_COLORINDEX_ARB;
5822 cfg->doubleBuffer = (pfd.dwFlags & PFD_DOUBLEBUFFER) ? 1 : 0;
5823 cfg->auxBuffers = pfd.cAuxBuffers;
5824 cfg->numSamples = 0;
5826 TRACE("iPixelFormat=%d, iPixelType=%#x, doubleBuffer=%d, RGBA=%d/%d/%d/%d, "
5827 "depth=%d, stencil=%d, windowDrawable=%d\n",
5828 cfg->iPixelFormat, cfg->iPixelType, cfg->doubleBuffer,
5829 cfg->redSize, cfg->greenSize, cfg->blueSize, cfg->alphaSize,
5830 cfg->depthSize, cfg->stencilSize, cfg->windowDrawable);
5832 ++adapter->cfg_count;
5837 static BOOL wined3d_adapter_init(struct wined3d_adapter *adapter, UINT ordinal, DWORD wined3d_creation_flags)
5839 static const DWORD supported_gl_versions[] =
5841 MAKEDWORD_VERSION(3, 2),
5842 MAKEDWORD_VERSION(1, 0),
5844 struct wined3d_gl_info *gl_info = &adapter->gl_info;
5845 struct wined3d_caps_gl_ctx caps_gl_ctx = {0};
5846 unsigned int i;
5847 DISPLAY_DEVICEW display_device;
5849 TRACE("adapter %p, ordinal %u.\n", adapter, ordinal);
5851 adapter->ordinal = ordinal;
5853 /* Dynamically load all GL core functions */
5854 #ifdef USE_WIN32_OPENGL
5856 HMODULE mod_gl = GetModuleHandleA("opengl32.dll");
5857 #define USE_GL_FUNC(f) gl_info->gl_ops.gl.p_##f = (void *)GetProcAddress(mod_gl, #f);
5858 ALL_WGL_FUNCS
5859 #undef USE_GL_FUNC
5860 gl_info->gl_ops.wgl.p_wglSwapBuffers = (void *)GetProcAddress(mod_gl, "wglSwapBuffers");
5862 #else
5863 /* To bypass the opengl32 thunks retrieve functions from the WGL driver instead of opengl32 */
5865 HDC hdc = GetDC( 0 );
5866 const struct opengl_funcs *wgl_driver = __wine_get_wgl_driver( hdc, WINE_WGL_DRIVER_VERSION );
5867 ReleaseDC( 0, hdc );
5868 if (!wgl_driver || wgl_driver == (void *)-1) return FALSE;
5869 gl_info->gl_ops.wgl = wgl_driver->wgl;
5870 gl_info->gl_ops.gl = wgl_driver->gl;
5872 #endif
5874 glEnableWINE = gl_info->gl_ops.gl.p_glEnable;
5875 glDisableWINE = gl_info->gl_ops.gl.p_glDisable;
5877 if (!AllocateLocallyUniqueId(&adapter->luid))
5879 ERR("Failed to set adapter LUID (%#x).\n", GetLastError());
5880 return FALSE;
5882 TRACE("Allocated LUID %08x:%08x for adapter %p.\n",
5883 adapter->luid.HighPart, adapter->luid.LowPart, adapter);
5885 if (!wined3d_caps_gl_ctx_create(adapter, &caps_gl_ctx))
5887 ERR("Failed to get a GL context for adapter %p.\n", adapter);
5888 return FALSE;
5891 for (i = 0; i < ARRAY_SIZE(supported_gl_versions); ++i)
5893 if (supported_gl_versions[i] <= wined3d_settings.max_gl_version)
5894 break;
5896 if (i == ARRAY_SIZE(supported_gl_versions))
5898 ERR_(winediag)("Requested invalid GL version %u.%u.\n",
5899 wined3d_settings.max_gl_version >> 16, wined3d_settings.max_gl_version & 0xffff);
5900 i = ARRAY_SIZE(supported_gl_versions) - 1;
5903 for (; i < ARRAY_SIZE(supported_gl_versions); ++i)
5905 gl_info->selected_gl_version = supported_gl_versions[i];
5907 if (wined3d_caps_gl_ctx_create_attribs(&caps_gl_ctx, gl_info))
5908 break;
5910 WARN("Couldn't create an OpenGL %u.%u context, trying fallback to a lower version.\n",
5911 supported_gl_versions[i] >> 16, supported_gl_versions[i] & 0xffff);
5914 if (!wined3d_adapter_init_gl_caps(adapter, wined3d_creation_flags))
5916 ERR("Failed to initialize GL caps for adapter %p.\n", adapter);
5917 wined3d_caps_gl_ctx_destroy(&caps_gl_ctx);
5918 return FALSE;
5921 wined3d_adapter_init_fb_cfgs(adapter, caps_gl_ctx.dc);
5922 /* We haven't found any suitable formats. This should only happen in
5923 * case of GDI software rendering, which is pretty useless anyway. */
5924 if (!adapter->cfg_count)
5926 WARN("No suitable pixel formats found.\n");
5927 wined3d_caps_gl_ctx_destroy(&caps_gl_ctx);
5928 HeapFree(GetProcessHeap(), 0, adapter->cfgs);
5929 return FALSE;
5932 if (!wined3d_adapter_init_format_info(adapter, &caps_gl_ctx))
5934 ERR("Failed to initialize GL format info.\n");
5935 wined3d_caps_gl_ctx_destroy(&caps_gl_ctx);
5936 HeapFree(GetProcessHeap(), 0, adapter->cfgs);
5937 return FALSE;
5940 gl_info->fixed_polyoffset_scale = wined3d_adapter_find_polyoffset_scale(&caps_gl_ctx, GL_DEPTH_COMPONENT);
5941 if (gl_info->supported[ARB_DEPTH_BUFFER_FLOAT])
5942 gl_info->float_polyoffset_scale = wined3d_adapter_find_polyoffset_scale(&caps_gl_ctx, GL_DEPTH32F_STENCIL8);
5944 adapter->vram_bytes = adapter->driver_info.vram_bytes;
5945 adapter->vram_bytes_used = 0;
5946 TRACE("Emulating 0x%s bytes of video ram.\n", wine_dbgstr_longlong(adapter->vram_bytes));
5948 display_device.cb = sizeof(display_device);
5949 EnumDisplayDevicesW(NULL, ordinal, &display_device, 0);
5950 TRACE("DeviceName: %s\n", debugstr_w(display_device.DeviceName));
5951 strcpyW(adapter->DeviceName, display_device.DeviceName);
5953 wined3d_caps_gl_ctx_destroy(&caps_gl_ctx);
5955 wined3d_adapter_init_ffp_attrib_ops(adapter);
5957 return TRUE;
5960 static void wined3d_adapter_init_nogl(struct wined3d_adapter *adapter, UINT ordinal)
5962 DISPLAY_DEVICEW display_device;
5964 memset(adapter, 0, sizeof(*adapter));
5965 adapter->ordinal = ordinal;
5967 adapter->driver_info.name = "Display";
5968 adapter->driver_info.description = "WineD3D DirectDraw Emulation";
5969 if (wined3d_settings.emulated_textureram)
5970 adapter->vram_bytes = wined3d_settings.emulated_textureram;
5971 else
5972 adapter->vram_bytes = 128 * 1024 * 1024;
5974 initPixelFormatsNoGL(&adapter->gl_info);
5976 adapter->vertex_pipe = &none_vertex_pipe;
5977 adapter->fragment_pipe = &none_fragment_pipe;
5978 adapter->shader_backend = &none_shader_backend;
5979 adapter->blitter = &cpu_blit;
5981 display_device.cb = sizeof(display_device);
5982 EnumDisplayDevicesW(NULL, ordinal, &display_device, 0);
5983 TRACE("DeviceName: %s\n", debugstr_w(display_device.DeviceName));
5984 strcpyW(adapter->DeviceName, display_device.DeviceName);
5987 static void STDMETHODCALLTYPE wined3d_null_wined3d_object_destroyed(void *parent) {}
5989 const struct wined3d_parent_ops wined3d_null_parent_ops =
5991 wined3d_null_wined3d_object_destroyed,
5994 HRESULT wined3d_init(struct wined3d *wined3d, DWORD flags)
5996 wined3d->ref = 1;
5997 wined3d->flags = flags;
5999 TRACE("Initializing adapters.\n");
6001 if (flags & WINED3D_NO3D)
6003 wined3d_adapter_init_nogl(&wined3d->adapters[0], 0);
6004 wined3d->adapter_count = 1;
6005 return WINED3D_OK;
6008 if (!wined3d_adapter_init(&wined3d->adapters[0], 0, flags))
6010 WARN("Failed to initialize adapter.\n");
6011 return E_FAIL;
6013 wined3d->adapter_count = 1;
6015 return WINED3D_OK;