d3d11/tests: Add some tests for Map() on deferred contexts.
[wine.git] / dlls / wined3d / adapter_gl.c
blob8787324571a7e65c547184608a2f3c140287f890
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, 2018 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"
31 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
32 WINE_DECLARE_DEBUG_CHANNEL(d3d_perf);
33 WINE_DECLARE_DEBUG_CHANNEL(winediag);
35 enum wined3d_gl_vendor
37 GL_VENDOR_UNKNOWN,
38 GL_VENDOR_APPLE,
39 GL_VENDOR_FGLRX,
40 GL_VENDOR_MESA,
41 GL_VENDOR_NVIDIA,
44 struct wined3d_extension_map
46 const char *extension_string;
47 enum wined3d_gl_extension extension;
50 static const struct wined3d_extension_map gl_extension_map[] =
52 /* APPLE */
53 {"GL_APPLE_fence", APPLE_FENCE },
54 {"GL_APPLE_float_pixels", APPLE_FLOAT_PIXELS },
55 {"GL_APPLE_flush_buffer_range", APPLE_FLUSH_BUFFER_RANGE },
56 {"GL_APPLE_flush_render", APPLE_FLUSH_RENDER },
57 {"GL_APPLE_rgb_422", APPLE_RGB_422 },
58 {"GL_APPLE_ycbcr_422", APPLE_YCBCR_422 },
60 /* ARB */
61 {"GL_ARB_base_instance", ARB_BASE_INSTANCE },
62 {"GL_ARB_blend_func_extended", ARB_BLEND_FUNC_EXTENDED },
63 {"GL_ARB_buffer_storage", ARB_BUFFER_STORAGE },
64 {"GL_ARB_clear_buffer_object", ARB_CLEAR_BUFFER_OBJECT },
65 {"GL_ARB_clear_texture", ARB_CLEAR_TEXTURE },
66 {"GL_ARB_clip_control", ARB_CLIP_CONTROL },
67 {"GL_ARB_color_buffer_float", ARB_COLOR_BUFFER_FLOAT },
68 {"GL_ARB_compute_shader", ARB_COMPUTE_SHADER },
69 {"GL_ARB_conservative_depth", ARB_CONSERVATIVE_DEPTH },
70 {"GL_ARB_copy_buffer", ARB_COPY_BUFFER },
71 {"GL_ARB_copy_image", ARB_COPY_IMAGE },
72 {"GL_ARB_cull_distance", ARB_CULL_DISTANCE },
73 {"GL_ARB_debug_output", ARB_DEBUG_OUTPUT },
74 {"GL_ARB_depth_buffer_float", ARB_DEPTH_BUFFER_FLOAT },
75 {"GL_ARB_depth_clamp", ARB_DEPTH_CLAMP },
76 {"GL_ARB_depth_texture", ARB_DEPTH_TEXTURE },
77 {"GL_ARB_derivative_control", ARB_DERIVATIVE_CONTROL },
78 {"GL_ARB_draw_buffers", ARB_DRAW_BUFFERS },
79 {"GL_ARB_draw_buffers_blend", ARB_DRAW_BUFFERS_BLEND },
80 {"GL_ARB_draw_elements_base_vertex", ARB_DRAW_ELEMENTS_BASE_VERTEX },
81 {"GL_ARB_draw_indirect", ARB_DRAW_INDIRECT },
82 {"GL_ARB_draw_instanced", ARB_DRAW_INSTANCED },
83 {"GL_ARB_ES2_compatibility", ARB_ES2_COMPATIBILITY },
84 {"GL_ARB_ES3_compatibility", ARB_ES3_COMPATIBILITY },
85 {"GL_ARB_explicit_attrib_location", ARB_EXPLICIT_ATTRIB_LOCATION },
86 {"GL_ARB_fragment_coord_conventions", ARB_FRAGMENT_COORD_CONVENTIONS},
87 {"GL_ARB_fragment_layer_viewport", ARB_FRAGMENT_LAYER_VIEWPORT },
88 {"GL_ARB_fragment_program", ARB_FRAGMENT_PROGRAM },
89 {"GL_ARB_fragment_shader", ARB_FRAGMENT_SHADER },
90 {"GL_ARB_framebuffer_no_attachments", ARB_FRAMEBUFFER_NO_ATTACHMENTS},
91 {"GL_ARB_framebuffer_object", ARB_FRAMEBUFFER_OBJECT },
92 {"GL_ARB_framebuffer_sRGB", ARB_FRAMEBUFFER_SRGB },
93 {"GL_ARB_geometry_shader4", ARB_GEOMETRY_SHADER4 },
94 {"GL_ARB_gpu_shader5", ARB_GPU_SHADER5 },
95 {"GL_ARB_half_float_pixel", ARB_HALF_FLOAT_PIXEL },
96 {"GL_ARB_half_float_vertex", ARB_HALF_FLOAT_VERTEX },
97 {"GL_ARB_instanced_arrays", ARB_INSTANCED_ARRAYS },
98 {"GL_ARB_internalformat_query", ARB_INTERNALFORMAT_QUERY },
99 {"GL_ARB_internalformat_query2", ARB_INTERNALFORMAT_QUERY2 },
100 {"GL_ARB_map_buffer_alignment", ARB_MAP_BUFFER_ALIGNMENT },
101 {"GL_ARB_map_buffer_range", ARB_MAP_BUFFER_RANGE },
102 {"GL_ARB_multisample", ARB_MULTISAMPLE },
103 {"GL_ARB_multitexture", ARB_MULTITEXTURE },
104 {"GL_ARB_occlusion_query", ARB_OCCLUSION_QUERY },
105 {"GL_ARB_pipeline_statistics_query", ARB_PIPELINE_STATISTICS_QUERY },
106 {"GL_ARB_pixel_buffer_object", ARB_PIXEL_BUFFER_OBJECT },
107 {"GL_ARB_point_parameters", ARB_POINT_PARAMETERS },
108 {"GL_ARB_point_sprite", ARB_POINT_SPRITE },
109 {"GL_ARB_polygon_offset_clamp", ARB_POLYGON_OFFSET_CLAMP },
110 {"GL_ARB_provoking_vertex", ARB_PROVOKING_VERTEX },
111 {"GL_ARB_query_buffer_object", ARB_QUERY_BUFFER_OBJECT },
112 {"GL_ARB_sample_shading", ARB_SAMPLE_SHADING },
113 {"GL_ARB_sampler_objects", ARB_SAMPLER_OBJECTS },
114 {"GL_ARB_seamless_cube_map", ARB_SEAMLESS_CUBE_MAP },
115 {"GL_ARB_shader_atomic_counters", ARB_SHADER_ATOMIC_COUNTERS },
116 {"GL_ARB_shader_bit_encoding", ARB_SHADER_BIT_ENCODING },
117 {"GL_ARB_shader_image_load_store", ARB_SHADER_IMAGE_LOAD_STORE },
118 {"GL_ARB_shader_image_size", ARB_SHADER_IMAGE_SIZE },
119 {"GL_ARB_shader_storage_buffer_object", ARB_SHADER_STORAGE_BUFFER_OBJECT},
120 {"GL_ARB_shader_texture_image_samples", ARB_SHADER_TEXTURE_IMAGE_SAMPLES},
121 {"GL_ARB_shader_texture_lod", ARB_SHADER_TEXTURE_LOD },
122 {"GL_ARB_shader_viewport_layer_array", ARB_SHADER_VIEWPORT_LAYER_ARRAY},
123 {"GL_ARB_shading_language_100", ARB_SHADING_LANGUAGE_100 },
124 {"GL_ARB_shading_language_420pack", ARB_SHADING_LANGUAGE_420PACK },
125 {"GL_ARB_shading_language_packing", ARB_SHADING_LANGUAGE_PACKING },
126 {"GL_ARB_shadow", ARB_SHADOW },
127 {"GL_ARB_stencil_texturing", ARB_STENCIL_TEXTURING },
128 {"GL_ARB_sync", ARB_SYNC },
129 {"GL_ARB_tessellation_shader", ARB_TESSELLATION_SHADER },
130 {"GL_ARB_texture_border_clamp", ARB_TEXTURE_BORDER_CLAMP },
131 {"GL_ARB_texture_buffer_object", ARB_TEXTURE_BUFFER_OBJECT },
132 {"GL_ARB_texture_buffer_range", ARB_TEXTURE_BUFFER_RANGE },
133 {"GL_ARB_texture_compression", ARB_TEXTURE_COMPRESSION },
134 {"GL_ARB_texture_compression_bptc", ARB_TEXTURE_COMPRESSION_BPTC },
135 {"GL_ARB_texture_compression_rgtc", ARB_TEXTURE_COMPRESSION_RGTC },
136 {"GL_ARB_texture_cube_map", ARB_TEXTURE_CUBE_MAP },
137 {"GL_ARB_texture_cube_map_array", ARB_TEXTURE_CUBE_MAP_ARRAY },
138 {"GL_ARB_texture_env_combine", ARB_TEXTURE_ENV_COMBINE },
139 {"GL_ARB_texture_env_dot3", ARB_TEXTURE_ENV_DOT3 },
140 {"GL_ARB_texture_filter_anisotropic", ARB_TEXTURE_FILTER_ANISOTROPIC},
141 {"GL_ARB_texture_float", ARB_TEXTURE_FLOAT },
142 {"GL_ARB_texture_gather", ARB_TEXTURE_GATHER },
143 {"GL_ARB_texture_mirrored_repeat", ARB_TEXTURE_MIRRORED_REPEAT },
144 {"GL_ARB_texture_mirror_clamp_to_edge", ARB_TEXTURE_MIRROR_CLAMP_TO_EDGE},
145 {"GL_ARB_texture_multisample", ARB_TEXTURE_MULTISAMPLE },
146 {"GL_ARB_texture_non_power_of_two", ARB_TEXTURE_NON_POWER_OF_TWO },
147 {"GL_ARB_texture_query_levels", ARB_TEXTURE_QUERY_LEVELS },
148 {"GL_ARB_texture_rectangle", ARB_TEXTURE_RECTANGLE },
149 {"GL_ARB_texture_rg", ARB_TEXTURE_RG },
150 {"GL_ARB_texture_rgb10_a2ui", ARB_TEXTURE_RGB10_A2UI },
151 {"GL_ARB_texture_storage", ARB_TEXTURE_STORAGE },
152 {"GL_ARB_texture_storage_multisample", ARB_TEXTURE_STORAGE_MULTISAMPLE},
153 {"GL_ARB_texture_swizzle", ARB_TEXTURE_SWIZZLE },
154 {"GL_ARB_texture_view", ARB_TEXTURE_VIEW },
155 {"GL_ARB_timer_query", ARB_TIMER_QUERY },
156 {"GL_ARB_transform_feedback2", ARB_TRANSFORM_FEEDBACK2 },
157 {"GL_ARB_transform_feedback3", ARB_TRANSFORM_FEEDBACK3 },
158 {"GL_ARB_uniform_buffer_object", ARB_UNIFORM_BUFFER_OBJECT },
159 {"GL_ARB_vertex_array_bgra", ARB_VERTEX_ARRAY_BGRA },
160 {"GL_ARB_vertex_buffer_object", ARB_VERTEX_BUFFER_OBJECT },
161 {"GL_ARB_vertex_program", ARB_VERTEX_PROGRAM },
162 {"GL_ARB_vertex_shader", ARB_VERTEX_SHADER },
163 {"GL_ARB_vertex_type_2_10_10_10_rev", ARB_VERTEX_TYPE_2_10_10_10_REV},
164 {"GL_ARB_viewport_array", ARB_VIEWPORT_ARRAY },
165 {"GL_ARB_texture_barrier", ARB_TEXTURE_BARRIER },
167 /* ATI */
168 {"GL_ATI_fragment_shader", ATI_FRAGMENT_SHADER },
169 {"GL_ATI_separate_stencil", ATI_SEPARATE_STENCIL },
170 {"GL_ATI_texture_compression_3dc", ATI_TEXTURE_COMPRESSION_3DC },
171 {"GL_ATI_texture_env_combine3", ATI_TEXTURE_ENV_COMBINE3 },
172 {"GL_ATI_texture_mirror_once", ATI_TEXTURE_MIRROR_ONCE },
174 /* EXT */
175 {"GL_EXT_blend_color", EXT_BLEND_COLOR },
176 {"GL_EXT_blend_equation_separate", EXT_BLEND_EQUATION_SEPARATE },
177 {"GL_EXT_blend_func_separate", EXT_BLEND_FUNC_SEPARATE },
178 {"GL_EXT_blend_minmax", EXT_BLEND_MINMAX },
179 {"GL_EXT_blend_subtract", EXT_BLEND_SUBTRACT },
180 {"GL_EXT_depth_bounds_test", EXT_DEPTH_BOUNDS_TEST },
181 {"GL_EXT_draw_buffers2", EXT_DRAW_BUFFERS2 },
182 {"GL_EXT_fog_coord", EXT_FOG_COORD },
183 {"GL_EXT_framebuffer_blit", EXT_FRAMEBUFFER_BLIT },
184 {"GL_EXT_framebuffer_multisample", EXT_FRAMEBUFFER_MULTISAMPLE },
185 {"GL_EXT_framebuffer_multisample_blit_scaled",
186 EXT_FRAMEBUFFER_MULTISAMPLE_BLIT_SCALED},
187 {"GL_EXT_framebuffer_object", EXT_FRAMEBUFFER_OBJECT },
188 {"GL_EXT_memory_object", EXT_MEMORY_OBJECT },
189 {"GL_EXT_gpu_program_parameters", EXT_GPU_PROGRAM_PARAMETERS },
190 {"GL_EXT_gpu_shader4", EXT_GPU_SHADER4 },
191 {"GL_EXT_packed_depth_stencil", EXT_PACKED_DEPTH_STENCIL },
192 {"GL_EXT_packed_float", EXT_PACKED_FLOAT },
193 {"GL_EXT_point_parameters", EXT_POINT_PARAMETERS },
194 {"GL_EXT_polygon_offset_clamp", ARB_POLYGON_OFFSET_CLAMP },
195 {"GL_EXT_provoking_vertex", EXT_PROVOKING_VERTEX },
196 {"GL_EXT_secondary_color", EXT_SECONDARY_COLOR },
197 {"GL_EXT_stencil_two_side", EXT_STENCIL_TWO_SIDE },
198 {"GL_EXT_stencil_wrap", EXT_STENCIL_WRAP },
199 {"GL_EXT_texture3D", EXT_TEXTURE3D },
200 {"GL_EXT_texture_array", EXT_TEXTURE_ARRAY },
201 {"GL_EXT_texture_compression_rgtc", EXT_TEXTURE_COMPRESSION_RGTC },
202 {"GL_EXT_texture_compression_s3tc", EXT_TEXTURE_COMPRESSION_S3TC },
203 {"GL_EXT_texture_env_combine", EXT_TEXTURE_ENV_COMBINE },
204 {"GL_EXT_texture_env_dot3", EXT_TEXTURE_ENV_DOT3 },
205 {"GL_EXT_texture_filter_anisotropic", ARB_TEXTURE_FILTER_ANISOTROPIC},
206 {"GL_EXT_texture_integer", EXT_TEXTURE_INTEGER },
207 {"GL_EXT_texture_lod_bias", EXT_TEXTURE_LOD_BIAS },
208 {"GL_EXT_texture_mirror_clamp", EXT_TEXTURE_MIRROR_CLAMP },
209 {"GL_EXT_texture_shadow_lod", EXT_TEXTURE_SHADOW_LOD },
210 {"GL_EXT_texture_shared_exponent", EXT_TEXTURE_SHARED_EXPONENT },
211 {"GL_EXT_texture_snorm", EXT_TEXTURE_SNORM },
212 {"GL_EXT_texture_sRGB", EXT_TEXTURE_SRGB },
213 {"GL_EXT_texture_sRGB_decode", EXT_TEXTURE_SRGB_DECODE },
214 {"GL_EXT_texture_swizzle", ARB_TEXTURE_SWIZZLE },
215 {"GL_EXT_vertex_array_bgra", ARB_VERTEX_ARRAY_BGRA },
217 /* NV */
218 {"GL_NV_fence", NV_FENCE },
219 {"GL_NV_fog_distance", NV_FOG_DISTANCE },
220 {"GL_NV_fragment_program", NV_FRAGMENT_PROGRAM },
221 {"GL_NV_fragment_program2", NV_FRAGMENT_PROGRAM2 },
222 {"GL_NV_fragment_program_option", NV_FRAGMENT_PROGRAM_OPTION },
223 {"GL_NV_half_float", NV_HALF_FLOAT },
224 {"GL_NV_light_max_exponent", NV_LIGHT_MAX_EXPONENT },
225 {"GL_NV_point_sprite", NV_POINT_SPRITE },
226 {"GL_NV_register_combiners", NV_REGISTER_COMBINERS },
227 {"GL_NV_register_combiners2", NV_REGISTER_COMBINERS2 },
228 {"GL_NV_texgen_reflection", NV_TEXGEN_REFLECTION },
229 {"GL_NV_texture_env_combine4", NV_TEXTURE_ENV_COMBINE4 },
230 {"GL_NV_texture_shader", NV_TEXTURE_SHADER },
231 {"GL_NV_texture_shader2", NV_TEXTURE_SHADER2 },
232 {"GL_NV_vertex_program", NV_VERTEX_PROGRAM },
233 {"GL_NV_vertex_program1_1", NV_VERTEX_PROGRAM1_1 },
234 {"GL_NV_vertex_program2", NV_VERTEX_PROGRAM2 },
235 {"GL_NV_vertex_program2_option", NV_VERTEX_PROGRAM2_OPTION },
236 {"GL_NV_vertex_program3", NV_VERTEX_PROGRAM3 },
237 {"GL_NV_texture_barrier", NV_TEXTURE_BARRIER },
240 static const struct wined3d_extension_map wgl_extension_map[] =
242 {"WGL_ARB_pixel_format", WGL_ARB_PIXEL_FORMAT },
243 {"WGL_EXT_swap_control", WGL_EXT_SWAP_CONTROL },
244 {"WGL_WINE_pixel_format_passthrough", WGL_WINE_PIXEL_FORMAT_PASSTHROUGH},
245 {"WGL_WINE_query_renderer", WGL_WINE_QUERY_RENDERER },
248 static void wined3d_caps_gl_ctx_destroy(const struct wined3d_caps_gl_ctx *ctx)
250 const struct wined3d_gl_info *gl_info = ctx->gl_info;
252 TRACE("Destroying caps GL context.\n");
254 /* Both glDeleteProgram and glDeleteBuffers silently ignore 0 IDs but
255 * this function might be called before the relevant function pointers
256 * in gl_info are initialized. */
257 if (ctx->test_program_id || ctx->test_vbo)
259 GL_EXTCALL(glDeleteProgram(ctx->test_program_id));
260 GL_EXTCALL(glDeleteBuffers(1, &ctx->test_vbo));
263 if (!wglMakeCurrent(NULL, NULL))
264 ERR("Failed to disable caps GL context.\n");
266 if (!wglDeleteContext(ctx->gl_ctx))
268 DWORD err = GetLastError();
269 ERR("wglDeleteContext(%p) failed, last error %#x.\n", ctx->gl_ctx, err);
272 wined3d_release_dc(ctx->wnd, ctx->dc);
273 DestroyWindow(ctx->wnd);
275 if (ctx->restore_gl_ctx && !wglMakeCurrent(ctx->restore_dc, ctx->restore_gl_ctx))
276 ERR("Failed to restore previous GL context.\n");
279 static BOOL wined3d_caps_gl_ctx_create_attribs(struct wined3d_caps_gl_ctx *caps_gl_ctx,
280 struct wined3d_gl_info *gl_info)
282 HGLRC new_ctx;
284 if (!(gl_info->p_wglCreateContextAttribsARB = (void *)wglGetProcAddress("wglCreateContextAttribsARB")))
285 return TRUE;
287 if (!(new_ctx = context_create_wgl_attribs(gl_info, caps_gl_ctx->dc, NULL)))
289 gl_info->p_wglCreateContextAttribsARB = NULL;
290 return FALSE;
293 if (!wglMakeCurrent(caps_gl_ctx->dc, new_ctx))
295 ERR("Failed to make new context current, last error %#x.\n", GetLastError());
296 if (!wglDeleteContext(new_ctx))
297 ERR("Failed to delete new context, last error %#x.\n", GetLastError());
298 gl_info->p_wglCreateContextAttribsARB = NULL;
299 return TRUE;
302 if (!wglDeleteContext(caps_gl_ctx->gl_ctx))
303 ERR("Failed to delete old context, last error %#x.\n", GetLastError());
304 caps_gl_ctx->gl_ctx = new_ctx;
306 return TRUE;
309 static BOOL wined3d_caps_gl_ctx_create(struct wined3d_adapter *adapter, struct wined3d_caps_gl_ctx *ctx)
311 PIXELFORMATDESCRIPTOR pfd;
312 int iPixelFormat;
314 TRACE("getting context...\n");
316 ctx->restore_dc = wglGetCurrentDC();
317 ctx->restore_gl_ctx = wglGetCurrentContext();
319 /* We need a fake window as a hdc retrieved using GetDC(0) can't be used for much GL purposes. */
320 ctx->wnd = CreateWindowA(WINED3D_OPENGL_WINDOW_CLASS_NAME, "WineD3D fake window",
321 WS_OVERLAPPEDWINDOW, 10, 10, 10, 10, NULL, NULL, NULL, NULL);
322 if (!ctx->wnd)
324 ERR("Failed to create a window.\n");
325 goto fail;
328 ctx->dc = GetDC(ctx->wnd);
329 if (!ctx->dc)
331 ERR("Failed to get a DC.\n");
332 goto fail;
335 /* PixelFormat selection */
336 ZeroMemory(&pfd, sizeof(pfd));
337 pfd.nSize = sizeof(pfd);
338 pfd.nVersion = 1;
339 pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW; /* PFD_GENERIC_ACCELERATED */
340 pfd.iPixelType = PFD_TYPE_RGBA;
341 pfd.cColorBits = 32;
342 pfd.iLayerType = PFD_MAIN_PLANE;
344 if (!(iPixelFormat = ChoosePixelFormat(ctx->dc, &pfd)))
346 /* If this happens something is very wrong as ChoosePixelFormat barely fails. */
347 ERR("Failed to find a suitable pixel format.\n");
348 goto fail;
350 DescribePixelFormat(ctx->dc, iPixelFormat, sizeof(pfd), &pfd);
351 SetPixelFormat(ctx->dc, iPixelFormat, &pfd);
353 /* Create a GL context. */
354 if (!(ctx->gl_ctx = wglCreateContext(ctx->dc)))
356 WARN("Failed to create default context for capabilities initialization.\n");
357 goto fail;
360 /* Make it the current GL context. */
361 if (!wglMakeCurrent(ctx->dc, ctx->gl_ctx))
363 ERR("Failed to make caps GL context current.\n");
364 goto fail;
367 ctx->gl_info = &adapter->gl_info;
368 return TRUE;
370 fail:
371 if (ctx->gl_ctx) wglDeleteContext(ctx->gl_ctx);
372 ctx->gl_ctx = NULL;
373 if (ctx->dc) ReleaseDC(ctx->wnd, ctx->dc);
374 ctx->dc = NULL;
375 if (ctx->wnd) DestroyWindow(ctx->wnd);
376 ctx->wnd = NULL;
377 if (ctx->restore_gl_ctx && !wglMakeCurrent(ctx->restore_dc, ctx->restore_gl_ctx))
378 ERR("Failed to restore previous GL context.\n");
380 return FALSE;
383 /* Context activation is done by the caller. */
384 static BOOL test_arb_vs_offset_limit(const struct wined3d_gl_info *gl_info)
386 GLuint prog;
387 BOOL ret = FALSE;
388 static const char testcode[] =
389 "!!ARBvp1.0\n"
390 "PARAM C[66] = { program.env[0..65] };\n"
391 "ADDRESS A0;"
392 "PARAM zero = {0.0, 0.0, 0.0, 0.0};\n"
393 "ARL A0.x, zero.x;\n"
394 "MOV result.position, C[A0.x + 65];\n"
395 "END\n";
397 while (gl_info->gl_ops.gl.p_glGetError());
398 GL_EXTCALL(glGenProgramsARB(1, &prog));
399 if(!prog) {
400 ERR("Failed to create an ARB offset limit test program\n");
402 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prog));
403 GL_EXTCALL(glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
404 strlen(testcode), testcode));
405 if (gl_info->gl_ops.gl.p_glGetError())
407 TRACE("OpenGL implementation does not allow indirect addressing offsets > 63\n");
408 TRACE("error: %s\n", debugstr_a((const char *)gl_info->gl_ops.gl.p_glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
409 ret = TRUE;
410 } else TRACE("OpenGL implementation allows offsets > 63\n");
412 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, 0));
413 GL_EXTCALL(glDeleteProgramsARB(1, &prog));
414 checkGLcall("ARB vp offset limit test cleanup");
416 return ret;
419 static BOOL match_amd_r300_to_500(const struct wined3d_gl_info *gl_info, struct wined3d_caps_gl_ctx *ctx,
420 const char *gl_renderer, enum wined3d_gl_vendor gl_vendor,
421 enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
423 return card_vendor == HW_VENDOR_AMD
424 && (device == CARD_AMD_RADEON_9500
425 || device == CARD_AMD_RADEON_X700
426 || device == CARD_AMD_RADEON_X1600);
429 static BOOL match_geforce5(const struct wined3d_gl_info *gl_info, struct wined3d_caps_gl_ctx *ctx,
430 const char *gl_renderer, enum wined3d_gl_vendor gl_vendor,
431 enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
433 return card_vendor == HW_VENDOR_NVIDIA
434 && (device == CARD_NVIDIA_GEFORCEFX_5200
435 || device == CARD_NVIDIA_GEFORCEFX_5600
436 || device == CARD_NVIDIA_GEFORCEFX_5800);
439 static BOOL match_apple(const struct wined3d_gl_info *gl_info, struct wined3d_caps_gl_ctx *ctx,
440 const char *gl_renderer, enum wined3d_gl_vendor gl_vendor,
441 enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
443 /* MacOS has various specialities in the extensions it advertises. Some
444 * have to be loaded from the OpenGL 1.2+ core, while other extensions are
445 * advertised, but software emulated. So try to detect the Apple OpenGL
446 * implementation to apply some extension fixups afterwards.
448 * Detecting this isn't really easy. The vendor string doesn't mention
449 * Apple. Compile-time checks aren't sufficient either because a Linux
450 * binary may display on a macOS X server via remote X11. So try to detect
451 * the OpenGL implementation by looking at certain Apple extensions. Some
452 * extensions like client storage might be supported on other
453 * implementations too, but GL_APPLE_flush_render is specific to the
454 * macOS X window management, and GL_APPLE_ycbcr_422 is QuickTime
455 * specific. So the chance that other implementations support them is
456 * rather small since Win32 QuickTime uses DirectDraw, not OpenGL.
458 * This test has been moved into wined3d_guess_gl_vendor(). */
459 return gl_vendor == GL_VENDOR_APPLE;
462 /* Context activation is done by the caller. */
463 static void test_pbo_functionality(struct wined3d_gl_info *gl_info)
465 /* Some OpenGL implementations, namely Apple's Geforce 8 driver, advertises PBOs,
466 * but glTexSubImage from a PBO fails miserably, with the first line repeated over
467 * all the texture. This function detects this bug by its symptom and disables PBOs
468 * if the test fails.
470 * The test uploads a 4x4 texture via the PBO in the "native" format GL_BGRA,
471 * GL_UNSIGNED_INT_8_8_8_8_REV. This format triggers the bug, and it is what we use
472 * for D3DFMT_A8R8G8B8. Then the texture is read back without any PBO and the data
473 * read back is compared to the original. If they are equal PBOs are assumed to work,
474 * otherwise the PBO extension is disabled. */
475 GLuint texture, pbo;
476 static const unsigned int pattern[] =
478 0x00000000, 0x000000ff, 0x0000ff00, 0x40ff0000,
479 0x80ffffff, 0x40ffff00, 0x00ff00ff, 0x0000ffff,
480 0x00ffff00, 0x00ff00ff, 0x0000ffff, 0x000000ff,
481 0x80ff00ff, 0x0000ffff, 0x00ff00ff, 0x40ff00ff
483 unsigned int check[ARRAY_SIZE(pattern)];
485 /* No PBO -> No point in testing them. */
486 if (!gl_info->supported[ARB_PIXEL_BUFFER_OBJECT]) return;
488 while (gl_info->gl_ops.gl.p_glGetError());
489 gl_info->gl_ops.gl.p_glGenTextures(1, &texture);
490 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, texture);
492 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
493 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);
494 checkGLcall("Specifying the PBO test texture");
496 GL_EXTCALL(glGenBuffers(1, &pbo));
497 GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo));
498 GL_EXTCALL(glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(pattern), pattern, GL_STREAM_DRAW));
499 checkGLcall("Specifying the PBO test pbo");
501 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);
502 checkGLcall("Loading the PBO test texture");
504 GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0));
506 gl_info->gl_ops.gl.p_glFinish(); /* just to be sure */
508 memset(check, 0, sizeof(check));
509 gl_info->gl_ops.gl.p_glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, check);
510 checkGLcall("Reading back the PBO test texture");
512 gl_info->gl_ops.gl.p_glDeleteTextures(1, &texture);
513 GL_EXTCALL(glDeleteBuffers(1, &pbo));
514 checkGLcall("PBO test cleanup");
516 if (memcmp(check, pattern, sizeof(check)))
518 WARN_(d3d_perf)("PBO test failed, read back data doesn't match original.\n"
519 "Disabling PBOs. This may result in slower performance.\n");
520 gl_info->supported[ARB_PIXEL_BUFFER_OBJECT] = FALSE;
522 else
524 TRACE("PBO test successful.\n");
528 static BOOL match_dx10_capable(const struct wined3d_gl_info *gl_info, struct wined3d_caps_gl_ctx *ctx,
529 const char *gl_renderer, enum wined3d_gl_vendor gl_vendor,
530 enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
532 /* Direct3D 9 cards support 40 single float varyings in hardware, most
533 * drivers report 32. ATI misreports 44 varyings. So assume that if we
534 * have more than 44 varyings we have a Direct3D 10+ card. This detection
535 * is for the gl_ClipPos varying quirk. If a Direct3D 9 card really
536 * supports more than 44 varyings and we subtract one in Direct3D 9
537 * shaders it's not going to hurt us because the Direct3D 9 limit is
538 * hardcoded.
540 * Direct3D 10 cards usually have 64 varyings. */
541 return gl_info->limits.glsl_varyings > 44;
544 static BOOL match_not_dx10_capable(const struct wined3d_gl_info *gl_info, struct wined3d_caps_gl_ctx *ctx,
545 const char *gl_renderer, enum wined3d_gl_vendor gl_vendor,
546 enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
548 return !match_dx10_capable(gl_info, ctx, gl_renderer, gl_vendor, card_vendor, device);
551 /* A GL context is provided by the caller */
552 static BOOL match_allows_spec_alpha(const struct wined3d_gl_info *gl_info, struct wined3d_caps_gl_ctx *ctx,
553 const char *gl_renderer, enum wined3d_gl_vendor gl_vendor,
554 enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
556 GLenum error;
557 DWORD data[16];
559 if (!gl_info->supported[EXT_SECONDARY_COLOR] || !gl_info->supported[WINED3D_GL_LEGACY_CONTEXT])
560 return FALSE;
562 while (gl_info->gl_ops.gl.p_glGetError());
563 GL_EXTCALL(glSecondaryColorPointerEXT)(4, GL_UNSIGNED_BYTE, 4, data);
564 error = gl_info->gl_ops.gl.p_glGetError();
566 if (error == GL_NO_ERROR)
568 TRACE("GL Implementation accepts 4 component specular color pointers\n");
569 return TRUE;
571 else
573 TRACE("GL implementation does not accept 4 component specular colors, error %s\n",
574 debug_glerror(error));
575 return FALSE;
579 /* A GL context is provided by the caller */
580 static BOOL match_broken_nv_clip(const struct wined3d_gl_info *gl_info, struct wined3d_caps_gl_ctx *ctx,
581 const char *gl_renderer, enum wined3d_gl_vendor gl_vendor,
582 enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
584 GLuint prog;
585 BOOL ret = FALSE;
586 GLint pos;
587 static const char testcode[] =
588 "!!ARBvp1.0\n"
589 "OPTION NV_vertex_program2;\n"
590 "MOV result.clip[0], 0.0;\n"
591 "MOV result.position, 0.0;\n"
592 "END\n";
594 if (!gl_info->supported[NV_VERTEX_PROGRAM2_OPTION]) return FALSE;
596 while (gl_info->gl_ops.gl.p_glGetError());
598 GL_EXTCALL(glGenProgramsARB(1, &prog));
599 if(!prog)
601 ERR("Failed to create the NVvp clip test program\n");
602 return FALSE;
604 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prog));
605 GL_EXTCALL(glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
606 strlen(testcode), testcode));
607 gl_info->gl_ops.gl.p_glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
608 if(pos != -1)
610 WARN("GL_NV_vertex_program2_option result.clip[] test failed\n");
611 TRACE("error: %s\n", debugstr_a((const char *)gl_info->gl_ops.gl.p_glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
612 ret = TRUE;
613 while (gl_info->gl_ops.gl.p_glGetError());
615 else TRACE("GL_NV_vertex_program2_option result.clip[] test passed\n");
617 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, 0));
618 GL_EXTCALL(glDeleteProgramsARB(1, &prog));
619 checkGLcall("GL_NV_vertex_program2_option result.clip[] test cleanup");
621 return ret;
624 /* Context activation is done by the caller. */
625 static BOOL match_fbo_tex_update(const struct wined3d_gl_info *gl_info, struct wined3d_caps_gl_ctx *ctx,
626 const char *gl_renderer, enum wined3d_gl_vendor gl_vendor,
627 enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
629 char data[4 * 4 * 4];
630 GLuint tex, fbo;
631 GLenum status;
633 if (wined3d_settings.offscreen_rendering_mode != ORM_FBO) return FALSE;
635 memset(data, 0xcc, sizeof(data));
637 gl_info->gl_ops.gl.p_glGenTextures(1, &tex);
638 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, tex);
639 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
640 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
641 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);
642 checkGLcall("glTexImage2D");
644 gl_info->fbo_ops.glGenFramebuffers(1, &fbo);
645 gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
646 gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
647 checkGLcall("glFramebufferTexture2D");
649 status = gl_info->fbo_ops.glCheckFramebufferStatus(GL_FRAMEBUFFER);
650 if (status != GL_FRAMEBUFFER_COMPLETE) ERR("FBO status %#x\n", status);
651 checkGLcall("glCheckFramebufferStatus");
653 memset(data, 0x11, sizeof(data));
654 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);
655 checkGLcall("glTexSubImage2D");
657 gl_info->gl_ops.gl.p_glClearColor(0.996f, 0.729f, 0.745f, 0.792f);
658 gl_info->gl_ops.gl.p_glClear(GL_COLOR_BUFFER_BIT);
659 checkGLcall("glClear");
661 gl_info->gl_ops.gl.p_glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, data);
662 checkGLcall("glGetTexImage");
664 gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
665 gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, 0);
666 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, 0);
667 checkGLcall("glBindTexture");
669 gl_info->fbo_ops.glDeleteFramebuffers(1, &fbo);
670 gl_info->gl_ops.gl.p_glDeleteTextures(1, &tex);
671 checkGLcall("glDeleteTextures");
673 return *(DWORD *)data == 0x11111111;
676 /* Context activation is done by the caller. */
677 static BOOL match_broken_rgba16(const struct wined3d_gl_info *gl_info, struct wined3d_caps_gl_ctx *ctx,
678 const char *gl_renderer, enum wined3d_gl_vendor gl_vendor,
679 enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
681 /* GL_RGBA16 uses GL_RGBA8 internally on Geforce 7 and older cards.
682 * This leads to graphical bugs in Half Life 2 and Unreal engine games. */
683 GLuint tex;
684 GLint size;
686 gl_info->gl_ops.gl.p_glGenTextures(1, &tex);
687 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, tex);
688 gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT, NULL);
689 checkGLcall("glTexImage2D");
691 gl_info->gl_ops.gl.p_glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_RED_SIZE, &size);
692 checkGLcall("glGetTexLevelParameteriv");
693 TRACE("Real color depth is %d\n", size);
695 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, 0);
696 checkGLcall("glBindTexture");
697 gl_info->gl_ops.gl.p_glDeleteTextures(1, &tex);
698 checkGLcall("glDeleteTextures");
700 return size < 16;
703 static BOOL match_fglrx(const struct wined3d_gl_info *gl_info, struct wined3d_caps_gl_ctx *ctx,
704 const char *gl_renderer, enum wined3d_gl_vendor gl_vendor,
705 enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
707 return gl_vendor == GL_VENDOR_FGLRX;
710 static BOOL match_r200(const struct wined3d_gl_info *gl_info, struct wined3d_caps_gl_ctx *ctx,
711 const char *gl_renderer, enum wined3d_gl_vendor gl_vendor,
712 enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
714 if (card_vendor != HW_VENDOR_AMD) return FALSE;
715 if (device == CARD_AMD_RADEON_8500) return TRUE;
716 return FALSE;
719 static BOOL match_broken_arb_fog(const struct wined3d_gl_info *gl_info, struct wined3d_caps_gl_ctx *ctx,
720 const char *gl_renderer, enum wined3d_gl_vendor gl_vendor,
721 enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
723 DWORD data[4];
724 GLuint tex, fbo;
725 GLenum status;
726 float color[4] = {0.0f, 1.0f, 0.0f, 0.0f};
727 GLuint prog;
728 GLint err_pos;
729 static const char program_code[] =
730 "!!ARBfp1.0\n"
731 "OPTION ARB_fog_linear;\n"
732 "MOV result.color, {1.0, 0.0, 0.0, 0.0};\n"
733 "END\n";
735 if (wined3d_settings.offscreen_rendering_mode != ORM_FBO)
736 return FALSE;
737 if (!gl_info->supported[ARB_FRAGMENT_PROGRAM])
738 return FALSE;
739 if (!gl_info->supported[WINED3D_GL_LEGACY_CONTEXT])
740 return FALSE;
742 gl_info->gl_ops.gl.p_glGenTextures(1, &tex);
743 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, tex);
744 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
745 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
746 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);
747 checkGLcall("glTexImage2D");
749 gl_info->fbo_ops.glGenFramebuffers(1, &fbo);
750 gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
751 gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
752 checkGLcall("glFramebufferTexture2D");
754 status = gl_info->fbo_ops.glCheckFramebufferStatus(GL_FRAMEBUFFER);
755 if (status != GL_FRAMEBUFFER_COMPLETE) ERR("FBO status %#x\n", status);
756 checkGLcall("glCheckFramebufferStatus");
758 gl_info->gl_ops.gl.p_glClearColor(0.0f, 0.0f, 1.0f, 0.0f);
759 gl_info->gl_ops.gl.p_glClear(GL_COLOR_BUFFER_BIT);
760 checkGLcall("glClear");
761 gl_info->gl_ops.gl.p_glViewport(0, 0, 4, 1);
762 checkGLcall("glViewport");
764 gl_info->gl_ops.gl.p_glEnable(GL_FOG);
765 gl_info->gl_ops.gl.p_glFogf(GL_FOG_START, 0.5f);
766 gl_info->gl_ops.gl.p_glFogf(GL_FOG_END, 0.5f);
767 gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_LINEAR);
768 gl_info->gl_ops.gl.p_glHint(GL_FOG_HINT, GL_NICEST);
769 gl_info->gl_ops.gl.p_glFogfv(GL_FOG_COLOR, color);
770 checkGLcall("fog setup");
772 GL_EXTCALL(glGenProgramsARB(1, &prog));
773 GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, prog));
774 GL_EXTCALL(glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
775 strlen(program_code), program_code));
776 gl_info->gl_ops.gl.p_glEnable(GL_FRAGMENT_PROGRAM_ARB);
777 checkGLcall("Test fragment program setup");
779 gl_info->gl_ops.gl.p_glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &err_pos);
780 if (err_pos != -1)
782 const char *error_str;
783 error_str = (const char *)gl_info->gl_ops.gl.p_glGetString(GL_PROGRAM_ERROR_STRING_ARB);
784 FIXME("Fog test program error at position %d: %s\n\n", err_pos, debugstr_a(error_str));
787 gl_info->gl_ops.gl.p_glBegin(GL_TRIANGLE_STRIP);
788 gl_info->gl_ops.gl.p_glVertex3f(-1.0f, -1.0f, 0.0f);
789 gl_info->gl_ops.gl.p_glVertex3f( 1.0f, -1.0f, 1.0f);
790 gl_info->gl_ops.gl.p_glVertex3f(-1.0f, 1.0f, 0.0f);
791 gl_info->gl_ops.gl.p_glVertex3f( 1.0f, 1.0f, 1.0f);
792 gl_info->gl_ops.gl.p_glEnd();
793 checkGLcall("ARBfp fog test draw");
795 gl_info->gl_ops.gl.p_glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, data);
796 checkGLcall("glGetTexImage");
797 data[0] &= 0x00ffffff;
798 data[1] &= 0x00ffffff;
799 data[2] &= 0x00ffffff;
800 data[3] &= 0x00ffffff;
802 gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, 0);
803 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, 0);
805 gl_info->fbo_ops.glDeleteFramebuffers(1, &fbo);
806 gl_info->gl_ops.gl.p_glDeleteTextures(1, &tex);
807 gl_info->gl_ops.gl.p_glDisable(GL_FOG);
808 GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, 0));
809 gl_info->gl_ops.gl.p_glDisable(GL_FRAGMENT_PROGRAM_ARB);
810 GL_EXTCALL(glDeleteProgramsARB(1, &prog));
811 checkGLcall("ARBfp fog test teardown");
813 TRACE("Fog test data: %08x %08x %08x %08x\n", data[0], data[1], data[2], data[3]);
814 return data[0] != 0x00ff0000 || data[3] != 0x0000ff00;
817 static BOOL match_broken_viewport_subpixel_bits(const struct wined3d_gl_info *gl_info,
818 struct wined3d_caps_gl_ctx *ctx, const char *gl_renderer, enum wined3d_gl_vendor gl_vendor,
819 enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
821 if (!gl_info->supported[ARB_VIEWPORT_ARRAY])
822 return FALSE;
823 if (wined3d_settings.offscreen_rendering_mode != ORM_FBO)
824 return FALSE;
825 return !wined3d_caps_gl_ctx_test_viewport_subpixel_bits(ctx);
828 static BOOL match_no_independent_bit_depths(const struct wined3d_gl_info *gl_info,
829 struct wined3d_caps_gl_ctx *ctx, const char *gl_renderer, enum wined3d_gl_vendor gl_vendor,
830 enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
832 GLuint tex[2], fbo;
833 GLenum status;
835 /* ARB_framebuffer_object allows implementation-dependent internal format
836 * restrictions. The EXT extension explicitly calls out an error in the
837 * relevant case. */
838 if (!gl_info->supported[ARB_FRAMEBUFFER_OBJECT])
839 return TRUE;
840 if (wined3d_settings.offscreen_rendering_mode != ORM_FBO)
841 return TRUE;
843 gl_info->gl_ops.gl.p_glGenTextures(2, tex);
845 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, tex[0]);
846 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
847 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
848 gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 1, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, NULL);
850 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, tex[1]);
851 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
852 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
853 gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB5, 4, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, NULL);
854 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, 0);
856 gl_info->fbo_ops.glGenFramebuffers(1, &fbo);
857 gl_info->fbo_ops.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
858 gl_info->fbo_ops.glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex[0], 0);
859 gl_info->fbo_ops.glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, tex[1], 0);
861 status = gl_info->fbo_ops.glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER);
863 gl_info->fbo_ops.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
864 gl_info->fbo_ops.glDeleteFramebuffers(1, &fbo);
865 gl_info->gl_ops.gl.p_glDeleteTextures(2, tex);
866 checkGLcall("testing multiple framebuffer attachments with different bit depths");
868 return status != GL_FRAMEBUFFER_COMPLETE;
871 static void quirk_apple_glsl_constants(struct wined3d_gl_info *gl_info)
873 /* MacOS needs uniforms for relative addressing offsets. This can
874 * accumulate to quite a few uniforms. Beyond that the general uniform
875 * isn't optimal, so reserve a number of uniforms. 12 vec4's should allow
876 * 48 different offsets or other helper immediate values. */
877 TRACE("Reserving 12 GLSL constants for compiler private use.\n");
878 gl_info->reserved_glsl_constants = max(gl_info->reserved_glsl_constants, 12);
881 static void quirk_amd_dx9(struct wined3d_gl_info *gl_info)
883 /* MacOS advertises GL_ARB_texture_non_power_of_two on ATI r500 and
884 * earlier cards, although these cards only support
885 * GL_ARB_texture_rectangle (D3DPTEXTURECAPS_NONPOW2CONDITIONAL).
887 * If real NP2 textures are used, the driver falls back to software. We
888 * could just disable the extension and use GL_ARB_texture_rectangle
889 * instead, but texture_rectangle is inconvenient due to the
890 * non-normalised texture coordinates. Thus set an internal extension
891 * flag, GL_WINE_normalized_texrect, which signals the code that it can
892 * use non-power-of-two textures as per GL_ARB_texture_non_power_of_two,
893 * but has to stick to the texture_rectangle limits.
895 * Fglrx doesn't advertise GL_ARB_texture_non_power_of_two, but it
896 * advertises OpenGL 2.0, which has this extension promoted to core. The
897 * extension loading code sets this extension supported due to that, so
898 * this code works on fglrx as well. */
899 if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
901 TRACE("GL_ARB_texture_non_power_of_two advertised on R500 or earlier card, removing.\n");
902 gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] = FALSE;
903 gl_info->supported[WINED3D_GL_NORMALIZED_TEXRECT] = TRUE;
907 static void quirk_no_np2(struct wined3d_gl_info *gl_info)
909 /* The NVIDIA GeForce FX series reports OpenGL 2.0 capabilities with the
910 * latest drivers versions, but doesn't explicitly advertise the
911 * ARB_tex_npot extension in the OpenGL extension string. This usually
912 * means that ARB_tex_npot is supported in hardware as long as the
913 * application is staying within the limits enforced by the
914 * ARB_texture_rectangle extension. This however is not true for the
915 * FX series, which instantly falls back to a slower software path as
916 * soon as ARB_tex_npot is used. We therefore completely remove
917 * ARB_tex_npot from the list of supported extensions.
919 * Note that WINE_normalized_texrect can't be used in this case because
920 * internally it uses ARB_tex_npot, triggering the software fallback.
921 * There is not much we can do here apart from disabling the
922 * software-emulated extension and re-enable ARB_tex_rect (which was
923 * previously disabled in wined3d_adapter_init_gl_caps).
925 * This fixup removes performance problems on both the FX 5900 and
926 * FX 5700 (e.g. for framebuffer post-processing effects in the game
927 * "Max Payne 2"). The behaviour can be verified through a simple test
928 * app attached in bugreport #14724. */
929 TRACE("GL_ARB_texture_non_power_of_two advertised through OpenGL 2.0 on NV FX card, removing.\n");
930 gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] = FALSE;
931 gl_info->supported[ARB_TEXTURE_RECTANGLE] = TRUE;
934 static void quirk_clip_varying(struct wined3d_gl_info *gl_info)
936 gl_info->quirks |= WINED3D_QUIRK_GLSL_CLIP_VARYING;
939 static void quirk_allows_specular_alpha(struct wined3d_gl_info *gl_info)
941 gl_info->quirks |= WINED3D_QUIRK_ALLOWS_SPECULAR_ALPHA;
944 static void quirk_disable_nvvp_clip(struct wined3d_gl_info *gl_info)
946 gl_info->quirks |= WINED3D_QUIRK_NV_CLIP_BROKEN;
949 static void quirk_fbo_tex_update(struct wined3d_gl_info *gl_info)
951 gl_info->quirks |= WINED3D_QUIRK_FBO_TEX_UPDATE;
954 static void quirk_broken_rgba16(struct wined3d_gl_info *gl_info)
956 gl_info->quirks |= WINED3D_QUIRK_BROKEN_RGBA16;
959 static void quirk_infolog_spam(struct wined3d_gl_info *gl_info)
961 gl_info->quirks |= WINED3D_QUIRK_INFO_LOG_SPAM;
964 static void quirk_limited_tex_filtering(struct wined3d_gl_info *gl_info)
966 /* NVIDIA GeForce 6xxx and 7xxx support accelerated VTF only on a few
967 * selected texture formats. They are apparently the only Direct3D 9 class
968 * GPUs supporting VTF. Also, Direct3D 9-era GPUs are somewhat limited
969 * with float texture filtering and blending. */
970 gl_info->quirks |= WINED3D_QUIRK_LIMITED_TEX_FILTERING;
973 static void quirk_r200_constants(struct wined3d_gl_info *gl_info)
975 /* The Mesa r200 driver (and there is no other driver for this GPU Wine
976 * would run on) loads some fog parameters (start, end, exponent, but not
977 * the colour) into the program.
979 * Apparently the fog hardware is only able to handle linear fog with a
980 * range of 0.0;1.0, and it is the responsibility of the vertex pipeline
981 * to handle non-linear fog and linear fog with start and end other than
982 * 0.0 and 1.0. */
983 TRACE("Reserving 1 ARB constant for compiler private use.\n");
984 gl_info->reserved_arb_constants = max(gl_info->reserved_arb_constants, 1);
987 static void quirk_broken_arb_fog(struct wined3d_gl_info *gl_info)
989 gl_info->quirks |= WINED3D_QUIRK_BROKEN_ARB_FOG;
992 static void quirk_broken_viewport_subpixel_bits(struct wined3d_gl_info *gl_info)
994 if (gl_info->supported[ARB_CLIP_CONTROL])
996 TRACE("Disabling ARB_clip_control.\n");
997 gl_info->supported[ARB_CLIP_CONTROL] = FALSE;
1001 static void quirk_no_independent_bit_depths(struct wined3d_gl_info *gl_info)
1003 gl_info->quirks |= WINED3D_QUIRK_NO_INDEPENDENT_BIT_DEPTHS;
1006 static const struct wined3d_gpu_description *query_gpu_description(const struct wined3d_gl_info *gl_info,
1007 UINT64 *vram_bytes)
1009 const struct wined3d_gpu_description *gpu_description = NULL, *gpu_description_override;
1010 enum wined3d_pci_vendor vendor = PCI_VENDOR_NONE;
1011 enum wined3d_pci_device device = PCI_DEVICE_NONE;
1012 GLuint value;
1014 if (gl_info->supported[WGL_WINE_QUERY_RENDERER])
1016 if (GL_EXTCALL(wglQueryCurrentRendererIntegerWINE(WGL_RENDERER_VENDOR_ID_WINE, &value)))
1017 vendor = value;
1018 if (GL_EXTCALL(wglQueryCurrentRendererIntegerWINE(WGL_RENDERER_DEVICE_ID_WINE, &value)))
1019 device = value;
1020 if (GL_EXTCALL(wglQueryCurrentRendererIntegerWINE(WGL_RENDERER_VIDEO_MEMORY_WINE, &value)))
1021 *vram_bytes = (UINT64)value * 1024 * 1024;
1023 TRACE("Card reports vendor PCI ID 0x%04x, device PCI ID 0x%04x, 0x%s bytes of video memory.\n",
1024 vendor, device, wine_dbgstr_longlong(*vram_bytes));
1026 gpu_description = wined3d_get_gpu_description(vendor, device);
1029 if ((gpu_description_override = wined3d_get_user_override_gpu_description(vendor, device)))
1030 gpu_description = gpu_description_override;
1032 return gpu_description;
1035 /* Context activation is done by the caller. */
1036 static void fixup_extensions(struct wined3d_gl_info *gl_info, struct wined3d_caps_gl_ctx *ctx,
1037 const char *gl_renderer, enum wined3d_gl_vendor gl_vendor)
1039 enum wined3d_pci_vendor card_vendor = ctx->gpu_description->vendor;
1040 enum wined3d_pci_device device = ctx->gpu_description->device;
1041 unsigned int i;
1043 static const struct driver_quirk
1045 BOOL (*match)(const struct wined3d_gl_info *gl_info, struct wined3d_caps_gl_ctx *ctx,
1046 const char *gl_renderer, enum wined3d_gl_vendor gl_vendor,
1047 enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device);
1048 void (*apply)(struct wined3d_gl_info *gl_info);
1049 const char *description;
1051 quirk_table[] =
1054 match_amd_r300_to_500,
1055 quirk_amd_dx9,
1056 "AMD normalised texrect quirk"
1059 match_apple,
1060 quirk_apple_glsl_constants,
1061 "Apple GLSL uniform override"
1064 match_geforce5,
1065 quirk_no_np2,
1066 "Geforce 5 NP2 disable"
1069 match_dx10_capable,
1070 quirk_clip_varying,
1071 "Reserved varying for gl_ClipPos"
1074 /* GL_EXT_secondary_color does not allow 4 component secondary
1075 * colours, but most OpenGL implementations accept it. Apple's
1076 * is the only OpenGL implementation known to reject it.
1078 * If we can pass 4-component specular colours, do it, because
1079 * (a) we don't have to screw around with the data, and (b) the
1080 * Direct3D fixed-function vertex pipeline passes specular alpha
1081 * to the pixel shader if any is used. Otherwise the specular
1082 * alpha is used to pass the fog coordinate, which we pass to
1083 * OpenGL via GL_EXT_fog_coord. */
1084 match_allows_spec_alpha,
1085 quirk_allows_specular_alpha,
1086 "Allow specular alpha quirk"
1089 match_broken_nv_clip,
1090 quirk_disable_nvvp_clip,
1091 "Apple NV_vertex_program clip bug quirk"
1094 match_fbo_tex_update,
1095 quirk_fbo_tex_update,
1096 "FBO rebind for attachment updates"
1099 match_broken_rgba16,
1100 quirk_broken_rgba16,
1101 "True RGBA16 is not available"
1104 match_fglrx,
1105 quirk_infolog_spam,
1106 "Not printing GLSL infolog"
1109 match_not_dx10_capable,
1110 quirk_limited_tex_filtering,
1111 "Texture filtering, blending and VTF support is limited"
1114 match_r200,
1115 quirk_r200_constants,
1116 "r200 vertex shader constants"
1119 match_broken_arb_fog,
1120 quirk_broken_arb_fog,
1121 "ARBfp fogstart == fogend workaround"
1124 match_broken_viewport_subpixel_bits,
1125 quirk_broken_viewport_subpixel_bits,
1126 "NVIDIA viewport subpixel bits bug"
1129 match_no_independent_bit_depths,
1130 quirk_no_independent_bit_depths,
1131 "No support for MRT with independent bit depths"
1135 for (i = 0; i < ARRAY_SIZE(quirk_table); ++i)
1137 if (!quirk_table[i].match(gl_info, ctx, gl_renderer, gl_vendor, card_vendor, device)) continue;
1138 TRACE("Applying driver quirk \"%s\".\n", quirk_table[i].description);
1139 quirk_table[i].apply(gl_info);
1142 /* Find out if PBOs work as they are supposed to. */
1143 test_pbo_functionality(gl_info);
1146 static DWORD wined3d_parse_gl_version(const char *gl_version)
1148 const char *ptr = gl_version;
1149 int major, minor;
1151 major = atoi(ptr);
1152 if (major <= 0)
1153 ERR("Invalid OpenGL major version %d.\n", major);
1155 while (isdigit(*ptr)) ++ptr;
1156 if (*ptr++ != '.')
1157 ERR("Invalid OpenGL version string %s.\n", debugstr_a(gl_version));
1159 minor = atoi(ptr);
1161 TRACE("Found OpenGL version %d.%d.\n", major, minor);
1163 return MAKEDWORD_VERSION(major, minor);
1166 static enum wined3d_gl_vendor wined3d_guess_gl_vendor(const struct wined3d_gl_info *gl_info,
1167 const char *gl_vendor_string, const char *gl_renderer, const char *gl_version)
1169 /* MacOS has various specialities in the extensions it advertises. Some have to be loaded from
1170 * the opengl 1.2+ core, while other extensions are advertised, but software emulated. So try to
1171 * detect the Apple OpenGL implementation to apply some extension fixups afterwards.
1173 * Detecting this isn't really easy. The vendor string doesn't mention Apple. Compile-time checks
1174 * aren't sufficient either because a Linux binary may display on a macos X server via remote X11.
1175 * So try to detect the GL implementation by looking at certain Apple extensions. Some extensions
1176 * like client storage might be supported on other implementations too, but GL_APPLE_flush_render
1177 * is specific to the Mac OS X window management, and GL_APPLE_ycbcr_422 is QuickTime specific. So
1178 * the chance that other implementations support them is rather small since Win32 QuickTime uses
1179 * DirectDraw, not OpenGL. */
1180 if (gl_info->supported[APPLE_FLUSH_RENDER]
1181 && (gl_info->supported[APPLE_YCBCR_422] || gl_info->supported[APPLE_RGB_422]))
1182 return GL_VENDOR_APPLE;
1184 if (strstr(gl_vendor_string, "NVIDIA"))
1185 return GL_VENDOR_NVIDIA;
1187 if (strstr(gl_vendor_string, "ATI"))
1188 return GL_VENDOR_FGLRX;
1190 if (strstr(gl_vendor_string, "Mesa")
1191 || strstr(gl_vendor_string, "X.Org")
1192 || strstr(gl_vendor_string, "Advanced Micro Devices, Inc.")
1193 || strstr(gl_vendor_string, "DRI R300 Project")
1194 || strstr(gl_vendor_string, "Tungsten Graphics, Inc")
1195 || strstr(gl_vendor_string, "VMware, Inc.")
1196 || strstr(gl_vendor_string, "Red Hat")
1197 || strstr(gl_vendor_string, "Intel")
1198 || strstr(gl_renderer, "Mesa")
1199 || strstr(gl_renderer, "Gallium")
1200 || strstr(gl_renderer, "Intel")
1201 || strstr(gl_version, "Mesa"))
1202 return GL_VENDOR_MESA;
1204 FIXME("Received unrecognized GL_VENDOR %s. Returning GL_VENDOR_UNKNOWN.\n",
1205 debugstr_a(gl_vendor_string));
1207 return GL_VENDOR_UNKNOWN;
1210 static enum wined3d_pci_vendor wined3d_guess_card_vendor(const char *gl_vendor_string, const char *gl_renderer)
1212 if (strstr(gl_vendor_string, "NVIDIA")
1213 || strstr(gl_vendor_string, "Nouveau")
1214 || strstr(gl_vendor_string, "nouveau"))
1215 return HW_VENDOR_NVIDIA;
1217 if (strstr(gl_vendor_string, "ATI")
1218 || strstr(gl_vendor_string, "Advanced Micro Devices, Inc.")
1219 || strstr(gl_vendor_string, "X.Org R300 Project")
1220 || strstr(gl_renderer, "AMD")
1221 || strstr(gl_renderer, "FirePro")
1222 || strstr(gl_renderer, "Radeon")
1223 || strstr(gl_renderer, "R100")
1224 || strstr(gl_renderer, "R200")
1225 || strstr(gl_renderer, "R300")
1226 || strstr(gl_renderer, "R600")
1227 || strstr(gl_renderer, "R700"))
1228 return HW_VENDOR_AMD;
1230 if (strstr(gl_vendor_string, "Intel(R)")
1231 /* Intel switched from Intel(R) to Intel® recently, so just match Intel. */
1232 || strstr(gl_renderer, "Intel")
1233 || strstr(gl_renderer, "i915")
1234 || strstr(gl_vendor_string, "Intel Inc."))
1235 return HW_VENDOR_INTEL;
1237 if (strstr(gl_vendor_string, "Red Hat")
1238 || strstr(gl_renderer, "virgl"))
1239 return HW_VENDOR_REDHAT;
1241 if (strstr(gl_renderer, "SVGA3D"))
1242 return HW_VENDOR_VMWARE;
1244 if (strstr(gl_vendor_string, "Mesa")
1245 || strstr(gl_vendor_string, "Brian Paul")
1246 || strstr(gl_vendor_string, "Tungsten Graphics, Inc")
1247 || strstr(gl_vendor_string, "VMware, Inc."))
1248 return HW_VENDOR_SOFTWARE;
1250 FIXME("Received unrecognized GL_VENDOR %s. Returning HW_VENDOR_NVIDIA.\n", debugstr_a(gl_vendor_string));
1252 return HW_VENDOR_NVIDIA;
1255 static enum wined3d_feature_level feature_level_from_caps(const struct wined3d_gl_info *gl_info,
1256 const struct shader_caps *shader_caps, const struct fragment_caps *fragment_caps)
1258 unsigned int shader_model;
1260 shader_model = min(shader_caps->vs_version, shader_caps->ps_version);
1261 shader_model = min(shader_model, max(shader_caps->gs_version, 3));
1262 shader_model = min(shader_model, max(shader_caps->hs_version, 4));
1263 shader_model = min(shader_model, max(shader_caps->ds_version, 4));
1265 if (gl_info->supported[WINED3D_GL_VERSION_3_2]
1266 && gl_info->supported[ARB_POLYGON_OFFSET_CLAMP]
1267 && gl_info->supported[ARB_SAMPLER_OBJECTS])
1269 if (shader_model >= 5
1270 && gl_info->supported[ARB_DRAW_INDIRECT]
1271 && gl_info->supported[ARB_TEXTURE_COMPRESSION_BPTC])
1272 return WINED3D_FEATURE_LEVEL_11_1;
1274 if (shader_model >= 4)
1276 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP_ARRAY]
1277 && gl_info->supported[ARB_DRAW_BUFFERS_BLEND])
1278 return WINED3D_FEATURE_LEVEL_10_1;
1279 return WINED3D_FEATURE_LEVEL_10;
1283 if (shader_model >= 3 && gl_info->limits.texture_size >= 4096 && gl_info->limits.buffers >= 4)
1284 return WINED3D_FEATURE_LEVEL_9_3;
1285 if (shader_model >= 2)
1287 if (gl_info->supported[ARB_OCCLUSION_QUERY]
1288 && gl_info->supported[ARB_TEXTURE_MIRROR_CLAMP_TO_EDGE]
1289 && gl_info->supported[EXT_BLEND_EQUATION_SEPARATE]
1290 && gl_info->supported[EXT_BLEND_FUNC_SEPARATE])
1291 return WINED3D_FEATURE_LEVEL_9_2;
1293 return WINED3D_FEATURE_LEVEL_9_1;
1295 if (shader_model >= 1)
1296 return WINED3D_FEATURE_LEVEL_8;
1298 if (fragment_caps->TextureOpCaps & WINED3DTEXOPCAPS_DOTPRODUCT3)
1299 return WINED3D_FEATURE_LEVEL_7;
1300 if (fragment_caps->MaxSimultaneousTextures > 1)
1301 return WINED3D_FEATURE_LEVEL_6;
1303 return WINED3D_FEATURE_LEVEL_5;
1306 static const struct wined3d_renderer_table
1308 const char *renderer;
1309 enum wined3d_pci_device id;
1311 cards_nvidia_binary[] =
1313 /* Direct 3D 11 */
1314 {"RTX 2080 Ti", CARD_NVIDIA_GEFORCE_RTX2080TI}, /* GeForce 2000 - highend */
1315 {"RTX 2080", CARD_NVIDIA_GEFORCE_RTX2080}, /* GeForce 2000 - highend */
1316 {"RTX 2070", CARD_NVIDIA_GEFORCE_RTX2070}, /* GeForce 2000 - highend */
1317 {"RTX 2060", CARD_NVIDIA_GEFORCE_RTX2060}, /* GeForce 2000 - highend */
1318 {"GTX 1660 Ti", CARD_NVIDIA_GEFORCE_GTX1660TI}, /* GeForce 1600 - highend */
1319 {"GTX 1660 SUPER", CARD_NVIDIA_GEFORCE_GTX1660SUPER}, /* GeForce 1600 - highend */
1320 {"GTX 1650 SUPER", CARD_NVIDIA_GEFORCE_GTX1650SUPER}, /* GeForce 1600 - midend high */
1321 {"TITAN V", CARD_NVIDIA_TITANV}, /* GeForce 1000 - highend */
1322 {"TITAN X (Pascal)", CARD_NVIDIA_TITANX_PASCAL}, /* GeForce 1000 - highend */
1323 {"GTX 1080 Ti", CARD_NVIDIA_GEFORCE_GTX1080TI}, /* GeForce 1000 - highend */
1324 {"GTX 1080", CARD_NVIDIA_GEFORCE_GTX1080}, /* GeForce 1000 - highend */
1325 {"GTX 1070", CARD_NVIDIA_GEFORCE_GTX1070}, /* GeForce 1000 - highend */
1326 {"GTX 1060 3GB", CARD_NVIDIA_GEFORCE_GTX1060_3GB},/* GeForce 1000 - midend high */
1327 {"GTX 1060", CARD_NVIDIA_GEFORCE_GTX1060}, /* GeForce 1000 - midend high */
1328 {"GTX 1050 Ti", CARD_NVIDIA_GEFORCE_GTX1050TI}, /* GeForce 1000 - midend */
1329 {"GTX 1050", CARD_NVIDIA_GEFORCE_GTX1050}, /* GeForce 1000 - midend */
1330 {"GTX 980 Ti", CARD_NVIDIA_GEFORCE_GTX980TI}, /* GeForce 900 - highend */
1331 {"GTX 980", CARD_NVIDIA_GEFORCE_GTX980}, /* GeForce 900 - highend */
1332 {"GTX 970M", CARD_NVIDIA_GEFORCE_GTX970M}, /* GeForce 900 - highend mobile*/
1333 {"GTX 970", CARD_NVIDIA_GEFORCE_GTX970}, /* GeForce 900 - highend */
1334 {"GTX TITAN X", CARD_NVIDIA_GEFORCE_GTXTITANX}, /* Geforce 900 - highend */
1335 {"GTX 960M", CARD_NVIDIA_GEFORCE_GTX960M}, /* GeForce 900 - midend high mobile */
1336 {"GTX 960", CARD_NVIDIA_GEFORCE_GTX960}, /* GeForce 900 - midend high */
1337 {"GTX 950M", CARD_NVIDIA_GEFORCE_GTX950M}, /* GeForce 900 - midend mobile */
1338 {"GTX 950", CARD_NVIDIA_GEFORCE_GTX950}, /* GeForce 900 - midend */
1339 {"GeForce 940M", CARD_NVIDIA_GEFORCE_940M}, /* GeForce 900 - midend mobile */
1340 {"GTX 880M", CARD_NVIDIA_GEFORCE_GTX880M}, /* GeForce 800 - mobile */
1341 {"GTX 870M", CARD_NVIDIA_GEFORCE_GTX870M}, /* GeForce 800 - mobile */
1342 {"GTX 860M", CARD_NVIDIA_GEFORCE_GTX860M}, /* GeForce 800 - mobile */
1343 {"GTX 850M", CARD_NVIDIA_GEFORCE_GTX850M}, /* GeForce 800 - mobile */
1344 {"GeForce 845M", CARD_NVIDIA_GEFORCE_845M}, /* GeForce 800 - mobile */
1345 {"GeForce 840M", CARD_NVIDIA_GEFORCE_840M}, /* GeForce 800 - mobile */
1346 {"GeForce 830M", CARD_NVIDIA_GEFORCE_830M}, /* GeForce 800 - mobile */
1347 {"GeForce 820M", CARD_NVIDIA_GEFORCE_820M}, /* GeForce 800 - mobile */
1348 {"GTX 780 Ti", CARD_NVIDIA_GEFORCE_GTX780TI}, /* Geforce 700 - highend */
1349 {"GTX TITAN Black", CARD_NVIDIA_GEFORCE_GTXTITANB}, /* Geforce 700 - highend */
1350 {"GTX TITAN Z", CARD_NVIDIA_GEFORCE_GTXTITANZ}, /* Geforce 700 - highend */
1351 {"GTX TITAN", CARD_NVIDIA_GEFORCE_GTXTITAN}, /* Geforce 700 - highend */
1352 {"GTX 780", CARD_NVIDIA_GEFORCE_GTX780}, /* Geforce 700 - highend */
1353 {"GTX 770M", CARD_NVIDIA_GEFORCE_GTX770M}, /* Geforce 700 - midend high mobile */
1354 {"GTX 770", CARD_NVIDIA_GEFORCE_GTX770}, /* Geforce 700 - highend */
1355 {"GTX 765M", CARD_NVIDIA_GEFORCE_GTX765M}, /* Geforce 700 - midend high mobile */
1356 {"GTX 760 Ti", CARD_NVIDIA_GEFORCE_GTX760TI}, /* Geforce 700 - midend high */
1357 {"GTX 760", CARD_NVIDIA_GEFORCE_GTX760}, /* Geforce 700 - midend high */
1358 {"GTX 750 Ti", CARD_NVIDIA_GEFORCE_GTX750TI}, /* Geforce 700 - midend */
1359 {"GTX 750", CARD_NVIDIA_GEFORCE_GTX750}, /* Geforce 700 - midend */
1360 {"GT 750M", CARD_NVIDIA_GEFORCE_GT750M}, /* Geforce 700 - midend mobile */
1361 {"GT 740M", CARD_NVIDIA_GEFORCE_GT740M}, /* Geforce 700 - midend mobile */
1362 {"GT 730M", CARD_NVIDIA_GEFORCE_GT730M}, /* Geforce 700 - midend mobile */
1363 {"GT 730", CARD_NVIDIA_GEFORCE_GT730}, /* Geforce 700 - lowend */
1364 {"GTX 690", CARD_NVIDIA_GEFORCE_GTX690}, /* Geforce 600 - highend */
1365 {"GTX 680", CARD_NVIDIA_GEFORCE_GTX680}, /* Geforce 600 - highend */
1366 {"GTX 675MX", CARD_NVIDIA_GEFORCE_GTX675MX_1},/* Geforce 600 - highend */
1367 {"GTX 670MX", CARD_NVIDIA_GEFORCE_GTX670MX}, /* Geforce 600 - highend */
1368 {"GTX 670", CARD_NVIDIA_GEFORCE_GTX670}, /* Geforce 600 - midend high */
1369 {"GTX 660 Ti", CARD_NVIDIA_GEFORCE_GTX660TI}, /* Geforce 600 - midend high */
1370 {"GTX 660M", CARD_NVIDIA_GEFORCE_GTX660M}, /* Geforce 600 - midend high mobile */
1371 {"GTX 660", CARD_NVIDIA_GEFORCE_GTX660}, /* Geforce 600 - midend high */
1372 {"GTX 650 Ti", CARD_NVIDIA_GEFORCE_GTX650TI}, /* Geforce 600 - lowend */
1373 {"GTX 650", CARD_NVIDIA_GEFORCE_GTX650}, /* Geforce 600 - lowend */
1374 {"GT 650M", CARD_NVIDIA_GEFORCE_GT650M}, /* Geforce 600 - midend mobile */
1375 {"GT 640M", CARD_NVIDIA_GEFORCE_GT640M}, /* Geforce 600 - midend mobile */
1376 {"GT 630M", CARD_NVIDIA_GEFORCE_GT630M}, /* Geforce 600 - midend mobile */
1377 {"GT 630", CARD_NVIDIA_GEFORCE_GT630}, /* Geforce 600 - lowend */
1378 {"GT 610", CARD_NVIDIA_GEFORCE_GT610}, /* Geforce 600 - lowend */
1379 {"GTX 580", CARD_NVIDIA_GEFORCE_GTX580}, /* Geforce 500 - highend */
1380 {"GTX 570", CARD_NVIDIA_GEFORCE_GTX570}, /* Geforce 500 - midend high */
1381 {"GTX 560 Ti", CARD_NVIDIA_GEFORCE_GTX560TI}, /* Geforce 500 - midend */
1382 {"GTX 560M", CARD_NVIDIA_GEFORCE_GTX560M}, /* Geforce 500 - midend mobile */
1383 {"GTX 560", CARD_NVIDIA_GEFORCE_GTX560}, /* Geforce 500 - midend */
1384 {"GT 555M", CARD_NVIDIA_GEFORCE_GT555M}, /* Geforce 500 - midend mobile */
1385 {"GTX 550 Ti", CARD_NVIDIA_GEFORCE_GTX550}, /* Geforce 500 - midend */
1386 {"GT 540M", CARD_NVIDIA_GEFORCE_GT540M}, /* Geforce 500 - midend mobile */
1387 {"GT 525M", CARD_NVIDIA_GEFORCE_GT525M}, /* Geforce 500 - lowend mobile */
1388 {"GT 520", CARD_NVIDIA_GEFORCE_GT520}, /* Geforce 500 - lowend */
1389 {"GTX 480", CARD_NVIDIA_GEFORCE_GTX480}, /* Geforce 400 - highend */
1390 {"GTX 470", CARD_NVIDIA_GEFORCE_GTX470}, /* Geforce 400 - midend high */
1391 /* Direct 3D 10 */
1392 {"GTX 465", CARD_NVIDIA_GEFORCE_GTX465}, /* Geforce 400 - midend */
1393 {"GTX 460M", CARD_NVIDIA_GEFORCE_GTX460M}, /* Geforce 400 - highend mobile */
1394 {"GTX 460", CARD_NVIDIA_GEFORCE_GTX460}, /* Geforce 400 - midend */
1395 {"GTS 450", CARD_NVIDIA_GEFORCE_GTS450}, /* Geforce 400 - midend low */
1396 {"GT 440", CARD_NVIDIA_GEFORCE_GT440}, /* Geforce 400 - lowend */
1397 {"GT 430", CARD_NVIDIA_GEFORCE_GT430}, /* Geforce 400 - lowend */
1398 {"GT 425M", CARD_NVIDIA_GEFORCE_GT425M}, /* Geforce 400 - lowend mobile */
1399 {"GT 420", CARD_NVIDIA_GEFORCE_GT420}, /* Geforce 400 - lowend */
1400 {"410M", CARD_NVIDIA_GEFORCE_410M}, /* Geforce 400 - lowend mobile */
1401 {"GT 330", CARD_NVIDIA_GEFORCE_GT330}, /* Geforce 300 - highend */
1402 {"GTS 360M", CARD_NVIDIA_GEFORCE_GTS350M}, /* Geforce 300 - highend mobile */
1403 {"GTS 350M", CARD_NVIDIA_GEFORCE_GTS350M}, /* Geforce 300 - highend mobile */
1404 {"GT 330M", CARD_NVIDIA_GEFORCE_GT325M}, /* Geforce 300 - midend mobile */
1405 {"GT 325M", CARD_NVIDIA_GEFORCE_GT325M}, /* Geforce 300 - midend mobile */
1406 {"GT 320M", CARD_NVIDIA_GEFORCE_GT320M}, /* Geforce 300 - midend mobile */
1407 {"320M", CARD_NVIDIA_GEFORCE_320M}, /* Geforce 300 - midend mobile */
1408 {"315M", CARD_NVIDIA_GEFORCE_315M}, /* Geforce 300 - midend mobile */
1409 {"GTX 295", CARD_NVIDIA_GEFORCE_GTX280}, /* Geforce 200 - highend */
1410 {"GTX 285", CARD_NVIDIA_GEFORCE_GTX280}, /* Geforce 200 - highend */
1411 {"GTX 280", CARD_NVIDIA_GEFORCE_GTX280}, /* Geforce 200 - highend */
1412 {"GTX 275", CARD_NVIDIA_GEFORCE_GTX275}, /* Geforce 200 - midend high */
1413 {"GTX 260", CARD_NVIDIA_GEFORCE_GTX260}, /* Geforce 200 - midend */
1414 {"GTS 250", CARD_NVIDIA_GEFORCE_GTS250}, /* Geforce 200 - midend */
1415 {"GT 240", CARD_NVIDIA_GEFORCE_GT240}, /* Geforce 200 - midend */
1416 {"GT 220", CARD_NVIDIA_GEFORCE_GT220}, /* Geforce 200 - lowend */
1417 {"GeForce 310", CARD_NVIDIA_GEFORCE_210}, /* Geforce 200 - lowend */
1418 {"GeForce 305", CARD_NVIDIA_GEFORCE_210}, /* Geforce 200 - lowend */
1419 {"GeForce 210", CARD_NVIDIA_GEFORCE_210}, /* Geforce 200 - lowend */
1420 {"G 210", CARD_NVIDIA_GEFORCE_210}, /* Geforce 200 - lowend */
1421 {"GTS 150", CARD_NVIDIA_GEFORCE_9800GT}, /* Geforce 9 - highend / Geforce 200 - midend */
1422 {"9800", CARD_NVIDIA_GEFORCE_9800GT}, /* Geforce 9 - highend / Geforce 200 - midend */
1423 {"9700M GT", CARD_NVIDIA_GEFORCE_9700MGT}, /* Geforce 9 - midend */
1424 {"GT 140", CARD_NVIDIA_GEFORCE_9600GT}, /* Geforce 9 - midend */
1425 {"9600", CARD_NVIDIA_GEFORCE_9600GT}, /* Geforce 9 - midend */
1426 {"GT 130", CARD_NVIDIA_GEFORCE_9500GT}, /* Geforce 9 - midend low / Geforce 200 - low */
1427 {"GT 120", CARD_NVIDIA_GEFORCE_9500GT}, /* Geforce 9 - midend low / Geforce 200 - low */
1428 {"9500", CARD_NVIDIA_GEFORCE_9500GT}, /* Geforce 9 - midend low / Geforce 200 - low */
1429 {"9400M", CARD_NVIDIA_GEFORCE_9400M}, /* Geforce 9 - lowend */
1430 {"9400", CARD_NVIDIA_GEFORCE_9400GT}, /* Geforce 9 - lowend */
1431 {"9300", CARD_NVIDIA_GEFORCE_9300}, /* Geforce 9 - lowend low */
1432 {"9200", CARD_NVIDIA_GEFORCE_9200}, /* Geforce 9 - lowend low */
1433 {"9100", CARD_NVIDIA_GEFORCE_9200}, /* Geforce 9 - lowend low */
1434 {"G 100", CARD_NVIDIA_GEFORCE_9200}, /* Geforce 9 - lowend low */
1435 {"8800 GTX", CARD_NVIDIA_GEFORCE_8800GTX}, /* Geforce 8 - highend high */
1436 {"8800", CARD_NVIDIA_GEFORCE_8800GTS}, /* Geforce 8 - highend */
1437 {"8600M", CARD_NVIDIA_GEFORCE_8600MGT}, /* Geforce 8 - midend mobile */
1438 {"8600 M", CARD_NVIDIA_GEFORCE_8600MGT}, /* Geforce 8 - midend mobile */
1439 {"8700", CARD_NVIDIA_GEFORCE_8600GT}, /* Geforce 8 - midend */
1440 {"8600", CARD_NVIDIA_GEFORCE_8600GT}, /* Geforce 8 - midend */
1441 {"8500", CARD_NVIDIA_GEFORCE_8500GT}, /* Geforce 8 - mid-lowend */
1442 {"8400", CARD_NVIDIA_GEFORCE_8400GS}, /* Geforce 8 - mid-lowend */
1443 {"8300", CARD_NVIDIA_GEFORCE_8300GS}, /* Geforce 8 - lowend */
1444 {"8200", CARD_NVIDIA_GEFORCE_8200}, /* Geforce 8 - lowend */
1445 {"8100", CARD_NVIDIA_GEFORCE_8200}, /* Geforce 8 - lowend */
1446 /* Direct 3D 9 SM3 */
1447 {"Quadro FX 5", CARD_NVIDIA_GEFORCE_7800GT}, /* Geforce 7 - highend */
1448 {"Quadro FX 4", CARD_NVIDIA_GEFORCE_7800GT}, /* Geforce 7 - highend */
1449 {"7950", CARD_NVIDIA_GEFORCE_7800GT}, /* Geforce 7 - highend */
1450 {"7900", CARD_NVIDIA_GEFORCE_7800GT}, /* Geforce 7 - highend */
1451 {"7800", CARD_NVIDIA_GEFORCE_7800GT}, /* Geforce 7 - highend */
1452 {"7700", CARD_NVIDIA_GEFORCE_7600}, /* Geforce 7 - midend */
1453 {"7600", CARD_NVIDIA_GEFORCE_7600}, /* Geforce 7 - midend */
1454 {"7400", CARD_NVIDIA_GEFORCE_7400}, /* Geforce 7 - lower medium */
1455 {"7300", CARD_NVIDIA_GEFORCE_7300}, /* Geforce 7 - lowend */
1456 {"6800", CARD_NVIDIA_GEFORCE_6800}, /* Geforce 6 - highend */
1457 {"6700", CARD_NVIDIA_GEFORCE_6600GT}, /* Geforce 6 - midend */
1458 {"6610", CARD_NVIDIA_GEFORCE_6600GT}, /* Geforce 6 - midend */
1459 {"6600", CARD_NVIDIA_GEFORCE_6600GT}, /* Geforce 6 - midend */
1460 /* Direct 3D 9 SM2 */
1461 {"Quadro FX", CARD_NVIDIA_GEFORCEFX_5800}, /* GeforceFX - highend */
1462 {"5950", CARD_NVIDIA_GEFORCEFX_5800}, /* GeforceFX - highend */
1463 {"5900", CARD_NVIDIA_GEFORCEFX_5800}, /* GeforceFX - highend */
1464 {"5800", CARD_NVIDIA_GEFORCEFX_5800}, /* GeforceFX - highend */
1465 {"5750", CARD_NVIDIA_GEFORCEFX_5600}, /* GeforceFX - midend */
1466 {"5700", CARD_NVIDIA_GEFORCEFX_5600}, /* GeforceFX - midend */
1467 {"5650", CARD_NVIDIA_GEFORCEFX_5600}, /* GeforceFX - midend */
1468 {"5600", CARD_NVIDIA_GEFORCEFX_5600}, /* GeforceFX - midend */
1469 {"5500", CARD_NVIDIA_GEFORCEFX_5200}, /* GeforceFX - lowend */
1470 {"5300", CARD_NVIDIA_GEFORCEFX_5200}, /* GeforceFX - lowend */
1471 {"5250", CARD_NVIDIA_GEFORCEFX_5200}, /* GeforceFX - lowend */
1472 {"5200", CARD_NVIDIA_GEFORCEFX_5200}, /* GeforceFX - lowend */
1473 {"5100", CARD_NVIDIA_GEFORCEFX_5200}, /* GeforceFX - lowend */
1474 /* Direct 3D 8 */
1475 {"Quadro4", CARD_NVIDIA_GEFORCE4_TI4200},
1476 {"GeForce4 Ti", CARD_NVIDIA_GEFORCE4_TI4200}, /* Geforce4 Ti4200/Ti4400/Ti4600/Ti4800 */
1477 /* Direct 3D 7 */
1478 {"GeForce4 MX", CARD_NVIDIA_GEFORCE4_MX}, /* MX420/MX440/MX460/MX4000 */
1479 {"Quadro2 MXR", CARD_NVIDIA_GEFORCE2_MX},
1480 {"GeForce2 MX", CARD_NVIDIA_GEFORCE2_MX}, /* Geforce2 standard/MX100/MX200/MX400 */
1481 {"Quadro2", CARD_NVIDIA_GEFORCE2},
1482 {"GeForce2", CARD_NVIDIA_GEFORCE2}, /* Geforce2 GTS/Pro/Ti/Ultra */
1483 /* Direct 3D 6 */
1484 {"TNT2", CARD_NVIDIA_RIVA_TNT2}, /* Riva TNT2 standard/M64/Pro/Ultra */
1486 /* See http://developer.amd.com/resources/hardware-drivers/ati-catalyst-pc-vendor-id-1002-li/
1488 * Beware: renderer string do not match exact card model,
1489 * e.g. HD 4800 is returned for multiple cards, even for RV790 based ones. */
1490 cards_amd_binary[] =
1492 {"RX 480", CARD_AMD_RADEON_RX_480},
1493 {"RX 460", CARD_AMD_RADEON_RX_460},
1494 {"R9 Fury Series", CARD_AMD_RADEON_R9_FURY},
1495 /* Southern Islands */
1496 {"HD 7900", CARD_AMD_RADEON_HD7900},
1497 {"HD 7800", CARD_AMD_RADEON_HD7800},
1498 {"HD 7700", CARD_AMD_RADEON_HD7700},
1499 /* Northern Islands */
1500 {"HD 6970", CARD_AMD_RADEON_HD6900},
1501 {"HD 6900", CARD_AMD_RADEON_HD6900},
1502 {"HD 6800", CARD_AMD_RADEON_HD6800},
1503 {"HD 6770M", CARD_AMD_RADEON_HD6600M},
1504 {"HD 6750M", CARD_AMD_RADEON_HD6600M},
1505 {"HD 6700", CARD_AMD_RADEON_HD6700},
1506 {"HD 6670", CARD_AMD_RADEON_HD6600},
1507 {"HD 6630M", CARD_AMD_RADEON_HD6600M},
1508 {"HD 6600M", CARD_AMD_RADEON_HD6600M},
1509 {"HD 6600", CARD_AMD_RADEON_HD6600},
1510 {"HD 6570", CARD_AMD_RADEON_HD6600},
1511 {"HD 6500M", CARD_AMD_RADEON_HD6600M},
1512 {"HD 6500", CARD_AMD_RADEON_HD6600},
1513 {"HD 6480G", CARD_AMD_RADEON_HD6480G},
1514 {"HD 6400", CARD_AMD_RADEON_HD6400},
1515 {"HD 6300", CARD_AMD_RADEON_HD6300},
1516 {"HD 6200", CARD_AMD_RADEON_HD6300},
1517 /* Evergreen */
1518 {"HD 5870", CARD_AMD_RADEON_HD5800}, /* Radeon EG CYPRESS PRO */
1519 {"HD 5850", CARD_AMD_RADEON_HD5800}, /* Radeon EG CYPRESS XT */
1520 {"HD 5800", CARD_AMD_RADEON_HD5800}, /* Radeon EG CYPRESS HD58xx generic renderer string */
1521 {"HD 5770", CARD_AMD_RADEON_HD5700}, /* Radeon EG JUNIPER XT */
1522 {"HD 5750", CARD_AMD_RADEON_HD5700}, /* Radeon EG JUNIPER LE */
1523 {"HD 5700", CARD_AMD_RADEON_HD5700}, /* Radeon EG JUNIPER HD57xx generic renderer string */
1524 {"HD 5670", CARD_AMD_RADEON_HD5600}, /* Radeon EG REDWOOD XT */
1525 {"HD 5570", CARD_AMD_RADEON_HD5600}, /* Radeon EG REDWOOD PRO mapped to HD5600 series */
1526 {"HD 5550", CARD_AMD_RADEON_HD5600}, /* Radeon EG REDWOOD LE mapped to HD5600 series */
1527 {"HD 5450", CARD_AMD_RADEON_HD5400}, /* Radeon EG CEDAR PRO */
1528 {"HD 5000", CARD_AMD_RADEON_HD5600}, /* Defaulting to HD 5600 */
1529 /* R700 */
1530 {"HD 4890", CARD_AMD_RADEON_HD4800}, /* Radeon RV790 */
1531 {"HD 4870", CARD_AMD_RADEON_HD4800}, /* Radeon RV770 */
1532 {"HD 4850", CARD_AMD_RADEON_HD4800}, /* Radeon RV770 */
1533 {"HD 4830", CARD_AMD_RADEON_HD4800}, /* Radeon RV770 */
1534 {"HD 4800", CARD_AMD_RADEON_HD4800}, /* Radeon RV7xx HD48xx generic renderer string */
1535 {"HD 4770", CARD_AMD_RADEON_HD4700}, /* Radeon RV740 */
1536 {"HD 4700", CARD_AMD_RADEON_HD4700}, /* Radeon RV7xx HD47xx generic renderer string */
1537 {"HD 4670", CARD_AMD_RADEON_HD4600}, /* Radeon RV730 */
1538 {"HD 4650", CARD_AMD_RADEON_HD4600}, /* Radeon RV730 */
1539 {"HD 4600", CARD_AMD_RADEON_HD4600}, /* Radeon RV730 */
1540 {"HD 4550", CARD_AMD_RADEON_HD4350}, /* Radeon RV710 */
1541 {"HD 4350", CARD_AMD_RADEON_HD4350}, /* Radeon RV710 */
1542 /* R600/R700 integrated */
1543 {"HD 4200M", CARD_AMD_RADEON_HD4200M},
1544 {"HD 3300", CARD_AMD_RADEON_HD3200},
1545 {"HD 3200", CARD_AMD_RADEON_HD3200},
1546 {"HD 3100", CARD_AMD_RADEON_HD3200},
1547 /* R600 */
1548 {"HD 3870", CARD_AMD_RADEON_HD2900}, /* HD2900/HD3800 - highend */
1549 {"HD 3850", CARD_AMD_RADEON_HD2900}, /* HD2900/HD3800 - highend */
1550 {"HD 2900", CARD_AMD_RADEON_HD2900}, /* HD2900/HD3800 - highend */
1551 {"HD 3830", CARD_AMD_RADEON_HD2600}, /* China-only midend */
1552 {"HD 3690", CARD_AMD_RADEON_HD2600}, /* HD2600/HD3600 - midend */
1553 {"HD 3650", CARD_AMD_RADEON_HD2600}, /* HD2600/HD3600 - midend */
1554 {"HD 2600", CARD_AMD_RADEON_HD2600}, /* HD2600/HD3600 - midend */
1555 {"HD 3470", CARD_AMD_RADEON_HD2350}, /* HD2350/HD2400/HD3400 - lowend */
1556 {"HD 3450", CARD_AMD_RADEON_HD2350}, /* HD2350/HD2400/HD3400 - lowend */
1557 {"HD 3430", CARD_AMD_RADEON_HD2350}, /* HD2350/HD2400/HD3400 - lowend */
1558 {"HD 3400", CARD_AMD_RADEON_HD2350}, /* HD2350/HD2400/HD3400 - lowend */
1559 {"HD 2400", CARD_AMD_RADEON_HD2350}, /* HD2350/HD2400/HD3400 - lowend */
1560 {"HD 2350", CARD_AMD_RADEON_HD2350}, /* HD2350/HD2400/HD3400 - lowend */
1561 /* Radeon R5xx */
1562 {"X1950", CARD_AMD_RADEON_X1600},
1563 {"X1900", CARD_AMD_RADEON_X1600},
1564 {"X1800", CARD_AMD_RADEON_X1600},
1565 {"X1650", CARD_AMD_RADEON_X1600},
1566 {"X1600", CARD_AMD_RADEON_X1600},
1567 /* Radeon R4xx + X1300/X1400/X1450/X1550/X2300/X2500/HD2300 (lowend R5xx)
1568 * Note X2300/X2500/HD2300 are R5xx GPUs with a 2xxx naming but they are still DX9-only */
1569 {"HD 2300", CARD_AMD_RADEON_X700},
1570 {"X2500", CARD_AMD_RADEON_X700},
1571 {"X2300", CARD_AMD_RADEON_X700},
1572 {"X1550", CARD_AMD_RADEON_X700},
1573 {"X1450", CARD_AMD_RADEON_X700},
1574 {"X1400", CARD_AMD_RADEON_X700},
1575 {"X1300", CARD_AMD_RADEON_X700},
1576 {"X850", CARD_AMD_RADEON_X700},
1577 {"X800", CARD_AMD_RADEON_X700},
1578 {"X700", CARD_AMD_RADEON_X700},
1579 /* Radeon Xpress Series - onboard, DX9b, Shader 2.0, 300-400 MHz */
1580 {"Radeon Xpress", CARD_AMD_RADEON_XPRESS_200M},
1582 cards_intel[] =
1584 /* Skylake */
1585 {"Iris Pro Graphics P580", CARD_INTEL_IPP580_1},
1586 {"Skylake", CARD_INTEL_HD520_1},
1587 /* Broadwell */
1588 {"Iris Pro P6300", CARD_INTEL_IPP6300},
1589 {"Iris Pro 6200", CARD_INTEL_IP6200},
1590 {"Iris 6100", CARD_INTEL_I6100},
1591 {"Iris(TM) Graphics 6100", CARD_INTEL_I6100}, /* MacOS */
1592 /* Haswell */
1593 {"Iris Pro 5200", CARD_INTEL_IP5200_1},
1594 {"Iris 5100", CARD_INTEL_I5100_1},
1595 {"HD Graphics 5000", CARD_INTEL_HD5000_1}, /* MacOS */
1596 {"Haswell Mobile", CARD_INTEL_HWM},
1597 {"Iris OpenGL Engine", CARD_INTEL_HWM}, /* MacOS */
1598 /* Ivybridge */
1599 {"Ivybridge Server", CARD_INTEL_IVBS},
1600 {"Ivybridge Mobile", CARD_INTEL_IVBM},
1601 {"Ivybridge Desktop", CARD_INTEL_IVBD},
1602 {"HD Graphics 4000", CARD_INTEL_IVBD}, /* MacOS */
1603 /* Sandybridge */
1604 {"Sandybridge Server", CARD_INTEL_SNBS},
1605 {"Sandybridge Mobile", CARD_INTEL_SNBM},
1606 {"Sandybridge Desktop", CARD_INTEL_SNBD},
1607 /* Ironlake */
1608 {"Ironlake Mobile", CARD_INTEL_ILKM},
1609 {"Ironlake Desktop", CARD_INTEL_ILKD},
1610 /* G4x */
1611 {"B43", CARD_INTEL_B43},
1612 {"G41", CARD_INTEL_G41},
1613 {"G45", CARD_INTEL_G45},
1614 {"Q45", CARD_INTEL_Q45},
1615 {"Integrated Graphics Device", CARD_INTEL_IGD},
1616 {"GM45", CARD_INTEL_GM45},
1617 /* i965 */
1618 {"965GME", CARD_INTEL_965GME},
1619 {"965GM", CARD_INTEL_965GM},
1620 {"X3100", CARD_INTEL_965GM}, /* MacOS */
1621 {"946GZ", CARD_INTEL_946GZ},
1622 {"965G", CARD_INTEL_965G},
1623 {"965Q", CARD_INTEL_965Q},
1624 /* i945 */
1625 {"Pineview M", CARD_INTEL_PNVM},
1626 {"Pineview G", CARD_INTEL_PNVG},
1627 {"IGD", CARD_INTEL_PNVG},
1628 {"Q33", CARD_INTEL_Q33},
1629 {"G33", CARD_INTEL_G33},
1630 {"Q35", CARD_INTEL_Q35},
1631 {"945GME", CARD_INTEL_945GME},
1632 {"945GM", CARD_INTEL_945GM},
1633 {"GMA 950", CARD_INTEL_945GM}, /* MacOS */
1634 {"945G", CARD_INTEL_945G},
1635 /* i915 */
1636 {"915GM", CARD_INTEL_915GM},
1637 {"E7221G", CARD_INTEL_E7221G},
1638 {"915G", CARD_INTEL_915G},
1639 /* i8xx */
1640 {"865G", CARD_INTEL_865G},
1641 {"845G", CARD_INTEL_845G},
1642 {"855GM", CARD_INTEL_855GM},
1643 {"830M", CARD_INTEL_830M},
1645 /* 20101109 - These are never returned by current Gallium radeon
1646 * drivers: R700, RV790, R680, RV535, RV516, R410, RS485, RV360, RV351. */
1647 cards_amd_mesa[] =
1649 /* Navi 10/14 */
1650 {"NAVI10", CARD_AMD_RADEON_RX_NAVI_10},
1651 {"NAVI14", CARD_AMD_RADEON_RX_NAVI_14},
1652 /* Polaris 10/11 */
1653 {"POLARIS10", CARD_AMD_RADEON_RX_480},
1654 {"POLARIS11", CARD_AMD_RADEON_RX_460},
1655 /* Volcanic Islands */
1656 {"FIJI", CARD_AMD_RADEON_R9_FURY},
1657 {"TONGA", CARD_AMD_RADEON_R9_285},
1658 /* Sea Islands */
1659 {"HAWAII", CARD_AMD_RADEON_R9_290},
1660 {"KAVERI", CARD_AMD_RADEON_R7 },
1661 {"KABINI", CARD_AMD_RADEON_R3 },
1662 {"BONAIRE", CARD_AMD_RADEON_HD8770},
1663 /* Southern Islands */
1664 {"OLAND", CARD_AMD_RADEON_HD8670},
1665 {"HAINAN", CARD_AMD_RADEON_HD8600M},
1666 {"TAHITI", CARD_AMD_RADEON_HD7900},
1667 {"PITCAIRN", CARD_AMD_RADEON_HD7800},
1668 {"CAPE VERDE", CARD_AMD_RADEON_HD7700},
1669 /* Northern Islands */
1670 {"ARUBA", CARD_AMD_RADEON_HD7660D},
1671 {"CAYMAN", CARD_AMD_RADEON_HD6900},
1672 {"BARTS", CARD_AMD_RADEON_HD6800},
1673 {"TURKS", CARD_AMD_RADEON_HD6600},
1674 {"SUMO2", CARD_AMD_RADEON_HD6410D}, /* SUMO2 first, because we do a strstr(). */
1675 {"SUMO", CARD_AMD_RADEON_HD6550D},
1676 {"CAICOS", CARD_AMD_RADEON_HD6400},
1677 {"PALM", CARD_AMD_RADEON_HD6300},
1678 /* Evergreen */
1679 {"HEMLOCK", CARD_AMD_RADEON_HD5900},
1680 {"CYPRESS", CARD_AMD_RADEON_HD5800},
1681 {"JUNIPER", CARD_AMD_RADEON_HD5700},
1682 {"REDWOOD", CARD_AMD_RADEON_HD5600},
1683 {"CEDAR", CARD_AMD_RADEON_HD5400},
1684 /* R700 */
1685 {"R700", CARD_AMD_RADEON_HD4800},
1686 {"RV790", CARD_AMD_RADEON_HD4800},
1687 {"RV770", CARD_AMD_RADEON_HD4800},
1688 {"RV740", CARD_AMD_RADEON_HD4700},
1689 {"RV730", CARD_AMD_RADEON_HD4600},
1690 {"RV710", CARD_AMD_RADEON_HD4350},
1691 /* R600/R700 integrated */
1692 {"RS880", CARD_AMD_RADEON_HD4200M},
1693 {"RS780", CARD_AMD_RADEON_HD3200},
1694 /* R600 */
1695 {"R680", CARD_AMD_RADEON_HD2900},
1696 {"R600", CARD_AMD_RADEON_HD2900},
1697 {"RV670", CARD_AMD_RADEON_HD3850},
1698 {"RV635", CARD_AMD_RADEON_HD2600},
1699 {"RV630", CARD_AMD_RADEON_HD2600},
1700 {"RV620", CARD_AMD_RADEON_HD2350},
1701 {"RV610", CARD_AMD_RADEON_HD2350},
1702 /* R500 */
1703 {"R580", CARD_AMD_RADEON_X1600},
1704 {"R520", CARD_AMD_RADEON_X1600},
1705 {"RV570", CARD_AMD_RADEON_X1600},
1706 {"RV560", CARD_AMD_RADEON_X1600},
1707 {"RV535", CARD_AMD_RADEON_X1600},
1708 {"RV530", CARD_AMD_RADEON_X1600},
1709 {"RV516", CARD_AMD_RADEON_X700},
1710 {"RV515", CARD_AMD_RADEON_X700},
1711 /* R400 */
1712 {"R481", CARD_AMD_RADEON_X700},
1713 {"R480", CARD_AMD_RADEON_X700},
1714 {"R430", CARD_AMD_RADEON_X700},
1715 {"R423", CARD_AMD_RADEON_X700},
1716 {"R420", CARD_AMD_RADEON_X700},
1717 {"R410", CARD_AMD_RADEON_X700},
1718 {"RV410", CARD_AMD_RADEON_X700},
1719 /* Radeon Xpress - onboard, DX9b, Shader 2.0, 300-400 MHz */
1720 {"RS740", CARD_AMD_RADEON_XPRESS_200M},
1721 {"RS690", CARD_AMD_RADEON_XPRESS_200M},
1722 {"RS600", CARD_AMD_RADEON_XPRESS_200M},
1723 {"RS485", CARD_AMD_RADEON_XPRESS_200M},
1724 {"RS482", CARD_AMD_RADEON_XPRESS_200M},
1725 {"RS480", CARD_AMD_RADEON_XPRESS_200M},
1726 {"RS400", CARD_AMD_RADEON_XPRESS_200M},
1727 {"RC410", CARD_AMD_RADEON_XPRESS_200M},
1728 /* R300 */
1729 {"R360", CARD_AMD_RADEON_9500},
1730 {"R350", CARD_AMD_RADEON_9500},
1731 {"R300", CARD_AMD_RADEON_9500},
1732 {"RV380", CARD_AMD_RADEON_9500},
1733 {"RV370", CARD_AMD_RADEON_9500},
1734 {"RV360", CARD_AMD_RADEON_9500},
1735 {"RV351", CARD_AMD_RADEON_9500},
1736 {"RV350", CARD_AMD_RADEON_9500},
1738 cards_nvidia_mesa[] =
1740 /* Maxwell */
1741 {"NV124", CARD_NVIDIA_GEFORCE_GTX970},
1742 {"NV120", CARD_NVIDIA_GEFORCE_GTX980TI},
1743 {"NV118", CARD_NVIDIA_GEFORCE_840M},
1744 {"NV117", CARD_NVIDIA_GEFORCE_GTX750},
1745 /* Kepler */
1746 {"NV108", CARD_NVIDIA_GEFORCE_GT740M},
1747 {"NV106", CARD_NVIDIA_GEFORCE_GT720},
1748 {"NVF1", CARD_NVIDIA_GEFORCE_GTX780TI},
1749 {"NVF0", CARD_NVIDIA_GEFORCE_GTX780},
1750 {"NVE6", CARD_NVIDIA_GEFORCE_GTX770M},
1751 {"NVE4", CARD_NVIDIA_GEFORCE_GTX680}, /* 690 / 675MX / 760TI */
1752 /* Fermi */
1753 {"NVD9", CARD_NVIDIA_GEFORCE_GT520},
1754 {"NVD7", CARD_NVIDIA_GEFORCE_820M},
1755 {"NVCF", CARD_NVIDIA_GEFORCE_GTX550},
1756 {"NVCE", CARD_NVIDIA_GEFORCE_GTX560},
1757 {"NVC8", CARD_NVIDIA_GEFORCE_GTX570},
1758 {"NVC4", CARD_NVIDIA_GEFORCE_GTX460},
1759 {"NVC3", CARD_NVIDIA_GEFORCE_GT440},
1760 {"NVC1", CARD_NVIDIA_GEFORCE_GT420},
1761 {"NVC0", CARD_NVIDIA_GEFORCE_GTX480},
1762 /* Tesla */
1763 {"NVAF", CARD_NVIDIA_GEFORCE_GT320M},
1764 {"NVAC", CARD_NVIDIA_GEFORCE_8200},
1765 {"NVAA", CARD_NVIDIA_GEFORCE_8200}, /* 8100 */
1766 {"NVA8", CARD_NVIDIA_GEFORCE_210},
1767 {"NVA5", CARD_NVIDIA_GEFORCE_GT220},
1768 {"NVA3", CARD_NVIDIA_GEFORCE_GT240},
1769 {"NVA0", CARD_NVIDIA_GEFORCE_GTX280},
1770 {"NV98", CARD_NVIDIA_GEFORCE_9200},
1771 {"NV96", CARD_NVIDIA_GEFORCE_9400GT},
1772 {"NV94", CARD_NVIDIA_GEFORCE_9600GT},
1773 {"NV92", CARD_NVIDIA_GEFORCE_9800GT},
1774 {"NV86", CARD_NVIDIA_GEFORCE_8500GT},
1775 {"NV84", CARD_NVIDIA_GEFORCE_8600GT},
1776 {"NV50", CARD_NVIDIA_GEFORCE_8800GTX},
1777 /* Curie */
1778 {"NV68", CARD_NVIDIA_GEFORCE_6200}, /* 7050 */
1779 {"NV67", CARD_NVIDIA_GEFORCE_6200}, /* 7000M */
1780 {"NV63", CARD_NVIDIA_GEFORCE_6200}, /* 7100 */
1781 {"NV4E", CARD_NVIDIA_GEFORCE_6200}, /* 6100 Go / 6150 Go */
1782 {"NV4C", CARD_NVIDIA_GEFORCE_6200}, /* 6150SE */
1783 {"NV4B", CARD_NVIDIA_GEFORCE_7600},
1784 {"NV4A", CARD_NVIDIA_GEFORCE_6200},
1785 {"NV49", CARD_NVIDIA_GEFORCE_7800GT}, /* 7900 */
1786 {"NV47", CARD_NVIDIA_GEFORCE_7800GT},
1787 {"NV46", CARD_NVIDIA_GEFORCE_7400},
1788 {"NV45", CARD_NVIDIA_GEFORCE_6800},
1789 {"NV44", CARD_NVIDIA_GEFORCE_6200},
1790 {"NV43", CARD_NVIDIA_GEFORCE_6600GT},
1791 {"NV42", CARD_NVIDIA_GEFORCE_6800},
1792 {"NV41", CARD_NVIDIA_GEFORCE_6800},
1793 {"NV40", CARD_NVIDIA_GEFORCE_6800},
1794 /* Rankine */
1795 {"NV38", CARD_NVIDIA_GEFORCEFX_5800}, /* FX 5950 Ultra */
1796 {"NV36", CARD_NVIDIA_GEFORCEFX_5800}, /* FX 5700/5750 */
1797 {"NV35", CARD_NVIDIA_GEFORCEFX_5800}, /* FX 5900 */
1798 {"NV34", CARD_NVIDIA_GEFORCEFX_5200},
1799 {"NV31", CARD_NVIDIA_GEFORCEFX_5600},
1800 {"NV30", CARD_NVIDIA_GEFORCEFX_5800},
1801 /* Kelvin */
1802 {"nv28", CARD_NVIDIA_GEFORCE4_TI4200},
1803 {"nv25", CARD_NVIDIA_GEFORCE4_TI4200},
1804 {"nv20", CARD_NVIDIA_GEFORCE3},
1805 /* Celsius */
1806 {"nv1F", CARD_NVIDIA_GEFORCE4_MX}, /* GF4 MX IGP */
1807 {"nv1A", CARD_NVIDIA_GEFORCE2}, /* GF2 IGP */
1808 {"nv18", CARD_NVIDIA_GEFORCE4_MX},
1809 {"nv17", CARD_NVIDIA_GEFORCE4_MX},
1810 {"nv16", CARD_NVIDIA_GEFORCE2},
1811 {"nv15", CARD_NVIDIA_GEFORCE2},
1812 {"nv11", CARD_NVIDIA_GEFORCE2_MX},
1813 {"nv10", CARD_NVIDIA_GEFORCE},
1814 /* Fahrenheit */
1815 {"nv05", CARD_NVIDIA_RIVA_TNT2},
1816 {"nv04", CARD_NVIDIA_RIVA_TNT},
1817 {"nv03", CARD_NVIDIA_RIVA_128},
1819 cards_redhat[] =
1821 {"virgl", CARD_REDHAT_VIRGL},
1823 cards_vmware[] =
1825 {"SVGA3D", CARD_VMWARE_SVGA3D},
1828 static const struct gl_vendor_selection
1830 enum wined3d_gl_vendor gl_vendor;
1831 const char *description; /* Description of the card selector i.e. Apple OS/X Intel */
1832 const struct wined3d_renderer_table *cards; /* To be used as cards[], pointer to the first member in an array */
1833 size_t cards_size; /* Number of entries in the array above */
1835 amd_gl_vendor_table[] =
1837 {GL_VENDOR_APPLE, "Apple OSX AMD/ATI binary driver", cards_amd_binary, ARRAY_SIZE(cards_amd_binary)},
1838 {GL_VENDOR_FGLRX, "AMD/ATI binary driver", cards_amd_binary, ARRAY_SIZE(cards_amd_binary)},
1839 {GL_VENDOR_MESA, "Mesa AMD/ATI driver", cards_amd_mesa, ARRAY_SIZE(cards_amd_mesa)},
1841 nvidia_gl_vendor_table[] =
1843 {GL_VENDOR_APPLE, "Apple OSX NVidia binary driver", cards_nvidia_binary, ARRAY_SIZE(cards_nvidia_binary)},
1844 {GL_VENDOR_MESA, "Mesa Nouveau driver", cards_nvidia_mesa, ARRAY_SIZE(cards_nvidia_mesa)},
1845 {GL_VENDOR_NVIDIA, "NVIDIA binary driver", cards_nvidia_binary, ARRAY_SIZE(cards_nvidia_binary)},
1847 redhat_gl_vendor_table[] =
1849 {GL_VENDOR_MESA, "Red Hat driver", cards_redhat, ARRAY_SIZE(cards_redhat)},
1851 vmware_gl_vendor_table[] =
1853 {GL_VENDOR_MESA, "VMware driver", cards_vmware, ARRAY_SIZE(cards_vmware)},
1855 intel_gl_vendor_table[] =
1857 {GL_VENDOR_APPLE, "Apple OSX Intel binary driver", cards_intel, ARRAY_SIZE(cards_intel)},
1858 {GL_VENDOR_MESA, "Mesa Intel driver", cards_intel, ARRAY_SIZE(cards_intel)},
1861 static enum wined3d_pci_device select_card_handler(const struct gl_vendor_selection *table,
1862 unsigned int table_size, enum wined3d_gl_vendor gl_vendor, const char *gl_renderer)
1864 unsigned int i, j;
1866 for (i = 0; i < table_size; ++i)
1868 if (table[i].gl_vendor != gl_vendor)
1869 continue;
1871 TRACE("Applying card selector \"%s\".\n", table[i].description);
1873 for (j = 0; j < table[i].cards_size; ++j)
1875 if (strstr(gl_renderer, table[i].cards[j].renderer))
1876 return table[i].cards[j].id;
1878 return PCI_DEVICE_NONE;
1880 FIXME("Couldn't find a suitable card selector for GL vendor %04x (using GL_RENDERER %s)\n",
1881 gl_vendor, debugstr_a(gl_renderer));
1883 return PCI_DEVICE_NONE;
1886 static const struct
1888 enum wined3d_pci_vendor card_vendor;
1889 const char *description; /* Description of the card selector i.e. Apple OS/X Intel */
1890 const struct gl_vendor_selection *gl_vendor_selection;
1891 unsigned int gl_vendor_count;
1893 card_vendor_table[] =
1895 {HW_VENDOR_AMD, "AMD", amd_gl_vendor_table, ARRAY_SIZE(amd_gl_vendor_table)},
1896 {HW_VENDOR_NVIDIA, "NVIDIA", nvidia_gl_vendor_table, ARRAY_SIZE(nvidia_gl_vendor_table)},
1897 {HW_VENDOR_REDHAT, "Red Hat",redhat_gl_vendor_table, ARRAY_SIZE(redhat_gl_vendor_table)},
1898 {HW_VENDOR_VMWARE, "VMware", vmware_gl_vendor_table, ARRAY_SIZE(vmware_gl_vendor_table)},
1899 {HW_VENDOR_INTEL, "Intel", intel_gl_vendor_table, ARRAY_SIZE(intel_gl_vendor_table)},
1902 static enum wined3d_pci_device wined3d_guess_card(enum wined3d_feature_level feature_level,
1903 const char *gl_renderer, enum wined3d_gl_vendor *gl_vendor,
1904 enum wined3d_pci_vendor *card_vendor)
1906 /* A Direct3D device object contains the PCI id (vendor + device) of the
1907 * videocard which is used for rendering. Various applications use this
1908 * information to get a rough estimation of the features of the card and
1909 * some might use it for enabling 3d effects only on certain types of
1910 * videocards. In some cases games might even use it to work around bugs
1911 * which happen on certain videocards/driver combinations. The problem is
1912 * that OpenGL only exposes a rendering string containing the name of the
1913 * videocard and not the PCI id.
1915 * Various games depend on the PCI id, so somehow we need to provide one.
1916 * A simple option is to parse the renderer string and translate this to
1917 * the right PCI id. This is a lot of work because there are more than 200
1918 * GPUs just for NVIDIA. Various cards share the same renderer string, so
1919 * the amount of code might be 'small' but there are quite a number of
1920 * exceptions which would make this a pain to maintain. Another way would
1921 * be to query the PCI id from the operating system (assuming this is the
1922 * videocard which is used for rendering which is not always the case).
1923 * This would work but it is not very portable. Second it would not work
1924 * well in, let's say, a remote X situation in which the amount of 3d
1925 * features which can be used is limited.
1927 * As said most games only use the PCI id to get an indication of the
1928 * capabilities of the card. It doesn't really matter if the given id is
1929 * the correct one if we return the id of a card with similar 3d features.
1931 * The code below checks the OpenGL capabilities of a videocard and matches
1932 * that to a certain level of Direct3D functionality. Once a card passes
1933 * the Direct3D9 check, we know that the card (in case of NVIDIA) is at
1934 * least a GeforceFX. To give a better estimate we do a basic check on the
1935 * renderer string but if that won't pass we return a default card. This
1936 * way is better than maintaining a full card database as even without a
1937 * full database we can return a card with similar features. Second the
1938 * size of the database can be made quite small because when you know what
1939 * type of 3d functionality a card has, you know to which GPU family the
1940 * GPU must belong. Because of this you only have to check a small part of
1941 * the renderer string to distinguish between different models from that
1942 * family.
1944 * The code also selects a default amount of video memory which we will
1945 * use for an estimation of the amount of free texture memory. In case of
1946 * real D3D the amount of texture memory includes video memory and system
1947 * memory (to be specific AGP memory or in case of PCIE TurboCache /
1948 * HyperMemory). We don't know how much system memory can be addressed by
1949 * the system but we can make a reasonable estimation about the amount of
1950 * video memory. If the value is slightly wrong it doesn't matter as we
1951 * didn't include AGP-like memory which makes the amount of addressable
1952 * memory higher and second OpenGL isn't that critical it moves to system
1953 * memory behind our backs if really needed. Note that the amount of video
1954 * memory can be overruled using a registry setting. */
1956 enum wined3d_pci_device device;
1957 unsigned int i;
1959 for (i = 0; i < ARRAY_SIZE(card_vendor_table); ++i)
1961 if (card_vendor_table[i].card_vendor != *card_vendor)
1962 continue;
1964 TRACE("Applying card selector \"%s\".\n", card_vendor_table[i].description);
1965 device = select_card_handler(card_vendor_table[i].gl_vendor_selection,
1966 card_vendor_table[i].gl_vendor_count, *gl_vendor, gl_renderer);
1967 if (device != PCI_DEVICE_NONE)
1968 return device;
1970 TRACE("Unrecognized renderer %s, falling back to default.\n", debugstr_a(gl_renderer));
1972 return wined3d_gpu_from_feature_level(card_vendor, feature_level);
1975 FIXME("No card selector available for card vendor %04x (using GL_RENDERER %s).\n",
1976 *card_vendor, debugstr_a(gl_renderer));
1978 return wined3d_gpu_from_feature_level(card_vendor, feature_level);
1981 static const struct wined3d_vertex_pipe_ops *select_vertex_implementation(const struct wined3d_gl_info *gl_info,
1982 const struct wined3d_shader_backend_ops *shader_backend_ops)
1984 if (shader_backend_ops == &glsl_shader_backend && gl_info->supported[ARB_VERTEX_SHADER])
1985 return &glsl_vertex_pipe;
1986 return &ffp_vertex_pipe;
1989 static const struct wined3d_fragment_pipe_ops *select_fragment_implementation(const struct wined3d_gl_info *gl_info,
1990 const struct wined3d_shader_backend_ops *shader_backend_ops)
1992 if (shader_backend_ops == &glsl_shader_backend && gl_info->supported[ARB_FRAGMENT_SHADER])
1993 return &glsl_fragment_pipe;
1994 if (gl_info->supported[ARB_FRAGMENT_PROGRAM])
1995 return &arbfp_fragment_pipeline;
1996 if (gl_info->supported[ATI_FRAGMENT_SHADER])
1997 return &atifs_fragment_pipeline;
1998 if (gl_info->supported[NV_REGISTER_COMBINERS] && gl_info->supported[NV_TEXTURE_SHADER2])
1999 return &nvts_fragment_pipeline;
2000 if (gl_info->supported[NV_REGISTER_COMBINERS])
2001 return &nvrc_fragment_pipeline;
2002 return &ffp_fragment_pipeline;
2005 static const struct wined3d_shader_backend_ops *select_shader_backend(const struct wined3d_gl_info *gl_info)
2007 BOOL glsl = wined3d_settings.shader_backend == WINED3D_SHADER_BACKEND_AUTO
2008 || wined3d_settings.shader_backend == WINED3D_SHADER_BACKEND_GLSL;
2009 BOOL arb = wined3d_settings.shader_backend == WINED3D_SHADER_BACKEND_AUTO
2010 || wined3d_settings.shader_backend == WINED3D_SHADER_BACKEND_ARB;
2012 if (!gl_info->supported[WINED3D_GL_LEGACY_CONTEXT] && !glsl)
2014 ERR_(winediag)("Ignoring the shader backend registry key. "
2015 "GLSL is the only shader backend available on core profile contexts. "
2016 "You need to explicitly set GL version to use legacy contexts.\n");
2017 glsl = TRUE;
2020 glsl = glsl && gl_info->glsl_version >= MAKEDWORD_VERSION(1, 20);
2022 if (glsl && gl_info->supported[ARB_VERTEX_SHADER] && gl_info->supported[ARB_FRAGMENT_SHADER])
2023 return &glsl_shader_backend;
2024 if (arb && gl_info->supported[ARB_VERTEX_PROGRAM] && gl_info->supported[ARB_FRAGMENT_PROGRAM])
2025 return &arb_program_shader_backend;
2026 if (glsl && (gl_info->supported[ARB_VERTEX_SHADER] || gl_info->supported[ARB_FRAGMENT_SHADER]))
2027 return &glsl_shader_backend;
2028 if (arb && (gl_info->supported[ARB_VERTEX_PROGRAM] || gl_info->supported[ARB_FRAGMENT_PROGRAM]))
2029 return &arb_program_shader_backend;
2030 return &none_shader_backend;
2033 static void parse_extension_string(struct wined3d_gl_info *gl_info, const char *extensions,
2034 const struct wined3d_extension_map *map, UINT entry_count)
2036 while (*extensions)
2038 const char *start;
2039 size_t len;
2040 UINT i;
2042 while (isspace(*extensions))
2043 ++extensions;
2044 start = extensions;
2045 while (!isspace(*extensions) && *extensions)
2046 ++extensions;
2048 len = extensions - start;
2049 if (!len)
2050 continue;
2052 TRACE("- %s.\n", debugstr_an(start, len));
2054 for (i = 0; i < entry_count; ++i)
2056 if (len == strlen(map[i].extension_string)
2057 && !memcmp(start, map[i].extension_string, len))
2059 TRACE(" FOUND: %s support.\n", map[i].extension_string);
2060 gl_info->supported[map[i].extension] = TRUE;
2061 break;
2067 static void enumerate_gl_extensions(struct wined3d_gl_info *gl_info,
2068 const struct wined3d_extension_map *map, unsigned int map_entries_count)
2070 const char *gl_extension_name;
2071 unsigned int i, j;
2072 GLint extensions_count;
2074 gl_info->gl_ops.gl.p_glGetIntegerv(GL_NUM_EXTENSIONS, &extensions_count);
2075 for (i = 0; i < extensions_count; ++i)
2077 gl_extension_name = (const char *)GL_EXTCALL(glGetStringi(GL_EXTENSIONS, i));
2078 TRACE("- %s.\n", debugstr_a(gl_extension_name));
2079 for (j = 0; j < map_entries_count; ++j)
2081 if (!strcmp(gl_extension_name, map[j].extension_string))
2083 TRACE("FOUND: %s support.\n", map[j].extension_string);
2084 gl_info->supported[map[j].extension] = TRUE;
2085 break;
2091 static void load_gl_funcs(struct wined3d_gl_info *gl_info)
2093 #define USE_GL_FUNC(pfn) gl_info->gl_ops.ext.p_##pfn = (void *)wglGetProcAddress(#pfn);
2094 /* GL_APPLE_fence */
2095 USE_GL_FUNC(glDeleteFencesAPPLE)
2096 USE_GL_FUNC(glFinishFenceAPPLE)
2097 USE_GL_FUNC(glFinishObjectAPPLE)
2098 USE_GL_FUNC(glGenFencesAPPLE)
2099 USE_GL_FUNC(glIsFenceAPPLE)
2100 USE_GL_FUNC(glSetFenceAPPLE)
2101 USE_GL_FUNC(glTestFenceAPPLE)
2102 USE_GL_FUNC(glTestObjectAPPLE)
2103 /* GL_APPLE_flush_buffer_range */
2104 USE_GL_FUNC(glBufferParameteriAPPLE)
2105 USE_GL_FUNC(glFlushMappedBufferRangeAPPLE)
2106 /* GL_ARB_base_instance */
2107 USE_GL_FUNC(glDrawArraysInstancedBaseInstance)
2108 USE_GL_FUNC(glDrawElementsInstancedBaseVertexBaseInstance)
2109 /* GL_ARB_blend_func_extended */
2110 USE_GL_FUNC(glBindFragDataLocationIndexed)
2111 USE_GL_FUNC(glGetFragDataIndex)
2112 /* GL_ARB_buffer_storage */
2113 USE_GL_FUNC(glBufferStorage)
2114 /* GL_ARB_clear_buffer_object */
2115 USE_GL_FUNC(glClearBufferData)
2116 USE_GL_FUNC(glClearBufferSubData)
2117 /* GL_ARB_clear_texture */
2118 USE_GL_FUNC(glClearTexImage)
2119 USE_GL_FUNC(glClearTexSubImage)
2120 /* GL_ARB_clip_control */
2121 USE_GL_FUNC(glClipControl)
2122 /* GL_ARB_color_buffer_float */
2123 USE_GL_FUNC(glClampColorARB)
2124 /* GL_ARB_compute_shader */
2125 USE_GL_FUNC(glDispatchCompute)
2126 USE_GL_FUNC(glDispatchComputeIndirect)
2127 /* GL_ARB_copy_buffer */
2128 USE_GL_FUNC(glCopyBufferSubData)
2129 /* GL_ARB_copy_image */
2130 USE_GL_FUNC(glCopyImageSubData)
2131 /* GL_ARB_debug_output */
2132 USE_GL_FUNC(glDebugMessageCallbackARB)
2133 USE_GL_FUNC(glDebugMessageControlARB)
2134 USE_GL_FUNC(glDebugMessageInsertARB)
2135 USE_GL_FUNC(glGetDebugMessageLogARB)
2136 /* GL_ARB_draw_buffers */
2137 USE_GL_FUNC(glDrawBuffersARB)
2138 /* GL_ARB_draw_buffers_blend */
2139 USE_GL_FUNC(glBlendEquationiARB)
2140 USE_GL_FUNC(glBlendEquationSeparateiARB)
2141 USE_GL_FUNC(glBlendFunciARB)
2142 USE_GL_FUNC(glBlendFuncSeparateiARB)
2143 /* GL_ARB_draw_elements_base_vertex */
2144 USE_GL_FUNC(glDrawElementsBaseVertex)
2145 USE_GL_FUNC(glDrawElementsInstancedBaseVertex)
2146 USE_GL_FUNC(glDrawRangeElementsBaseVertex)
2147 USE_GL_FUNC(glMultiDrawElementsBaseVertex)
2148 /* GL_ARB_draw_indirect */
2149 USE_GL_FUNC(glDrawArraysIndirect)
2150 USE_GL_FUNC(glDrawElementsIndirect)
2151 /* GL_ARB_draw_instanced */
2152 USE_GL_FUNC(glDrawArraysInstancedARB)
2153 USE_GL_FUNC(glDrawElementsInstancedARB)
2154 /* GL_ARB_ES2_compatibility */
2155 USE_GL_FUNC(glReleaseShaderCompiler)
2156 USE_GL_FUNC(glShaderBinary)
2157 USE_GL_FUNC(glGetShaderPrecisionFormat)
2158 USE_GL_FUNC(glDepthRangef)
2159 USE_GL_FUNC(glClearDepthf)
2160 /* GL_ARB_framebuffer_no_attachments */
2161 USE_GL_FUNC(glFramebufferParameteri)
2162 /* GL_ARB_framebuffer_object */
2163 USE_GL_FUNC(glBindFramebuffer)
2164 USE_GL_FUNC(glBindRenderbuffer)
2165 USE_GL_FUNC(glBlitFramebuffer)
2166 USE_GL_FUNC(glCheckFramebufferStatus)
2167 USE_GL_FUNC(glDeleteFramebuffers)
2168 USE_GL_FUNC(glDeleteRenderbuffers)
2169 USE_GL_FUNC(glFramebufferRenderbuffer)
2170 USE_GL_FUNC(glFramebufferTexture)
2171 USE_GL_FUNC(glFramebufferTexture1D)
2172 USE_GL_FUNC(glFramebufferTexture2D)
2173 USE_GL_FUNC(glFramebufferTexture3D)
2174 USE_GL_FUNC(glFramebufferTextureLayer)
2175 USE_GL_FUNC(glGenFramebuffers)
2176 USE_GL_FUNC(glGenRenderbuffers)
2177 USE_GL_FUNC(glGenerateMipmap)
2178 USE_GL_FUNC(glGetFramebufferAttachmentParameteriv)
2179 USE_GL_FUNC(glGetRenderbufferParameteriv)
2180 USE_GL_FUNC(glIsFramebuffer)
2181 USE_GL_FUNC(glIsRenderbuffer)
2182 USE_GL_FUNC(glRenderbufferStorage)
2183 USE_GL_FUNC(glRenderbufferStorageMultisample)
2184 /* GL_ARB_geometry_shader4 */
2185 USE_GL_FUNC(glFramebufferTextureARB)
2186 USE_GL_FUNC(glFramebufferTextureFaceARB)
2187 USE_GL_FUNC(glFramebufferTextureLayerARB)
2188 USE_GL_FUNC(glProgramParameteriARB)
2189 /* GL_ARB_instanced_arrays */
2190 USE_GL_FUNC(glVertexAttribDivisorARB)
2191 /* GL_ARB_internalformat_query */
2192 USE_GL_FUNC(glGetInternalformativ)
2193 /* GL_ARB_internalformat_query2 */
2194 USE_GL_FUNC(glGetInternalformati64v)
2195 /* GL_ARB_map_buffer_range */
2196 USE_GL_FUNC(glFlushMappedBufferRange)
2197 USE_GL_FUNC(glMapBufferRange)
2198 /* GL_ARB_multisample */
2199 USE_GL_FUNC(glSampleCoverageARB)
2200 /* GL_ARB_multitexture */
2201 USE_GL_FUNC(glActiveTextureARB)
2202 USE_GL_FUNC(glClientActiveTextureARB)
2203 USE_GL_FUNC(glMultiTexCoord1fARB)
2204 USE_GL_FUNC(glMultiTexCoord1fvARB)
2205 USE_GL_FUNC(glMultiTexCoord2fARB)
2206 USE_GL_FUNC(glMultiTexCoord2fvARB)
2207 USE_GL_FUNC(glMultiTexCoord2svARB)
2208 USE_GL_FUNC(glMultiTexCoord3fARB)
2209 USE_GL_FUNC(glMultiTexCoord3fvARB)
2210 USE_GL_FUNC(glMultiTexCoord4fARB)
2211 USE_GL_FUNC(glMultiTexCoord4fvARB)
2212 USE_GL_FUNC(glMultiTexCoord4svARB)
2213 /* GL_ARB_occlusion_query */
2214 USE_GL_FUNC(glBeginQueryARB)
2215 USE_GL_FUNC(glDeleteQueriesARB)
2216 USE_GL_FUNC(glEndQueryARB)
2217 USE_GL_FUNC(glGenQueriesARB)
2218 USE_GL_FUNC(glGetQueryivARB)
2219 USE_GL_FUNC(glGetQueryObjectivARB)
2220 USE_GL_FUNC(glGetQueryObjectuivARB)
2221 USE_GL_FUNC(glIsQueryARB)
2222 /* GL_ARB_point_parameters */
2223 USE_GL_FUNC(glPointParameterfARB)
2224 USE_GL_FUNC(glPointParameterfvARB)
2225 /* GL_ARB_polgyon_offset_clamp */
2226 USE_GL_FUNC(glPolygonOffsetClamp)
2227 /* GL_ARB_provoking_vertex */
2228 USE_GL_FUNC(glProvokingVertex)
2229 /* GL_ARB_sample_shading */
2230 USE_GL_FUNC(glMinSampleShadingARB)
2231 /* GL_ARB_sampler_objects */
2232 USE_GL_FUNC(glGenSamplers)
2233 USE_GL_FUNC(glDeleteSamplers)
2234 USE_GL_FUNC(glIsSampler)
2235 USE_GL_FUNC(glBindSampler)
2236 USE_GL_FUNC(glSamplerParameteri)
2237 USE_GL_FUNC(glSamplerParameterf)
2238 USE_GL_FUNC(glSamplerParameteriv)
2239 USE_GL_FUNC(glSamplerParameterfv)
2240 USE_GL_FUNC(glSamplerParameterIiv)
2241 USE_GL_FUNC(glSamplerParameterIuiv)
2242 USE_GL_FUNC(glGetSamplerParameteriv)
2243 USE_GL_FUNC(glGetSamplerParameterfv)
2244 USE_GL_FUNC(glGetSamplerParameterIiv)
2245 USE_GL_FUNC(glGetSamplerParameterIuiv)
2246 /* GL_ARB_shader_atomic_counters */
2247 USE_GL_FUNC(glGetActiveAtomicCounterBufferiv)
2248 /* GL_ARB_shader_image_load_store */
2249 USE_GL_FUNC(glBindImageTexture)
2250 USE_GL_FUNC(glMemoryBarrier)
2251 /* GL_ARB_shader_objects */
2252 USE_GL_FUNC(glAttachObjectARB)
2253 USE_GL_FUNC(glBindAttribLocationARB)
2254 USE_GL_FUNC(glCompileShaderARB)
2255 USE_GL_FUNC(glCreateProgramObjectARB)
2256 USE_GL_FUNC(glCreateShaderObjectARB)
2257 USE_GL_FUNC(glDeleteObjectARB)
2258 USE_GL_FUNC(glDetachObjectARB)
2259 USE_GL_FUNC(glGetActiveUniformARB)
2260 USE_GL_FUNC(glGetAttachedObjectsARB)
2261 USE_GL_FUNC(glGetAttribLocationARB)
2262 USE_GL_FUNC(glGetHandleARB)
2263 USE_GL_FUNC(glGetInfoLogARB)
2264 USE_GL_FUNC(glGetObjectParameterfvARB)
2265 USE_GL_FUNC(glGetObjectParameterivARB)
2266 USE_GL_FUNC(glGetShaderSourceARB)
2267 USE_GL_FUNC(glGetUniformLocationARB)
2268 USE_GL_FUNC(glGetUniformfvARB)
2269 USE_GL_FUNC(glGetUniformivARB)
2270 USE_GL_FUNC(glLinkProgramARB)
2271 USE_GL_FUNC(glShaderSourceARB)
2272 USE_GL_FUNC(glUniform1fARB)
2273 USE_GL_FUNC(glUniform1fvARB)
2274 USE_GL_FUNC(glUniform1iARB)
2275 USE_GL_FUNC(glUniform1ivARB)
2276 USE_GL_FUNC(glUniform2fARB)
2277 USE_GL_FUNC(glUniform2fvARB)
2278 USE_GL_FUNC(glUniform2iARB)
2279 USE_GL_FUNC(glUniform2ivARB)
2280 USE_GL_FUNC(glUniform3fARB)
2281 USE_GL_FUNC(glUniform3fvARB)
2282 USE_GL_FUNC(glUniform3iARB)
2283 USE_GL_FUNC(glUniform3ivARB)
2284 USE_GL_FUNC(glUniform4fARB)
2285 USE_GL_FUNC(glUniform4fvARB)
2286 USE_GL_FUNC(glUniform4iARB)
2287 USE_GL_FUNC(glUniform4ivARB)
2288 USE_GL_FUNC(glUniformMatrix2fvARB)
2289 USE_GL_FUNC(glUniformMatrix3fvARB)
2290 USE_GL_FUNC(glUniformMatrix4fvARB)
2291 USE_GL_FUNC(glUseProgramObjectARB)
2292 USE_GL_FUNC(glValidateProgramARB)
2293 /* GL_ARB_shader_storage_buffer_object */
2294 USE_GL_FUNC(glShaderStorageBlockBinding)
2295 /* GL_ARB_sync */
2296 USE_GL_FUNC(glClientWaitSync)
2297 USE_GL_FUNC(glDeleteSync)
2298 USE_GL_FUNC(glFenceSync)
2299 USE_GL_FUNC(glGetInteger64v)
2300 USE_GL_FUNC(glGetSynciv)
2301 USE_GL_FUNC(glIsSync)
2302 USE_GL_FUNC(glWaitSync)
2303 /* GL_ARB_tessellation_shader */
2304 USE_GL_FUNC(glPatchParameteri)
2305 USE_GL_FUNC(glPatchParameterfv)
2306 /* GL_ARB_texture_buffer_object */
2307 USE_GL_FUNC(glTexBufferARB)
2308 /* GL_ARB_texture_buffer_range */
2309 USE_GL_FUNC(glTexBufferRange)
2310 /* GL_ARB_texture_compression */
2311 USE_GL_FUNC(glCompressedTexImage2DARB)
2312 USE_GL_FUNC(glCompressedTexImage3DARB)
2313 USE_GL_FUNC(glCompressedTexSubImage2DARB)
2314 USE_GL_FUNC(glCompressedTexSubImage3DARB)
2315 USE_GL_FUNC(glGetCompressedTexImageARB)
2316 /* GL_ARB_texture_multisample */
2317 USE_GL_FUNC(glGetMultisamplefv);
2318 USE_GL_FUNC(glSampleMaski);
2319 USE_GL_FUNC(glTexImage2DMultisample);
2320 USE_GL_FUNC(glTexImage3DMultisample);
2321 /* GL_ARB_texture_storage */
2322 USE_GL_FUNC(glTexStorage1D)
2323 USE_GL_FUNC(glTexStorage2D)
2324 USE_GL_FUNC(glTexStorage3D)
2325 /* GL_ARB_texture_storage_multisample */
2326 USE_GL_FUNC(glTexStorage2DMultisample);
2327 USE_GL_FUNC(glTexStorage3DMultisample);
2328 /* GL_ARB_texture_view */
2329 USE_GL_FUNC(glTextureView)
2330 /* GL_ARB_timer_query */
2331 USE_GL_FUNC(glQueryCounter)
2332 USE_GL_FUNC(glGetQueryObjectui64v)
2333 /* GL_ARB_transform_feedback2 */
2334 USE_GL_FUNC(glBindTransformFeedback);
2335 USE_GL_FUNC(glDeleteTransformFeedbacks);
2336 USE_GL_FUNC(glDrawTransformFeedback);
2337 USE_GL_FUNC(glGenTransformFeedbacks);
2338 USE_GL_FUNC(glIsTransformFeedback);
2339 USE_GL_FUNC(glPauseTransformFeedback);
2340 USE_GL_FUNC(glResumeTransformFeedback);
2341 /* GL_ARB_transform_feedback3 */
2342 USE_GL_FUNC(glBeginQueryIndexed);
2343 USE_GL_FUNC(glDrawTransformFeedbackStream);
2344 USE_GL_FUNC(glEndQueryIndexed);
2345 USE_GL_FUNC(glGetQueryIndexediv);
2346 /* GL_ARB_uniform_buffer_object */
2347 USE_GL_FUNC(glBindBufferBase)
2348 USE_GL_FUNC(glBindBufferRange)
2349 USE_GL_FUNC(glGetActiveUniformBlockName)
2350 USE_GL_FUNC(glGetActiveUniformBlockiv)
2351 USE_GL_FUNC(glGetActiveUniformName)
2352 USE_GL_FUNC(glGetActiveUniformsiv)
2353 USE_GL_FUNC(glGetIntegeri_v)
2354 USE_GL_FUNC(glGetUniformBlockIndex)
2355 USE_GL_FUNC(glGetUniformIndices)
2356 USE_GL_FUNC(glUniformBlockBinding)
2357 /* GL_ARB_vertex_buffer_object */
2358 USE_GL_FUNC(glBindBufferARB)
2359 USE_GL_FUNC(glBufferDataARB)
2360 USE_GL_FUNC(glBufferSubDataARB)
2361 USE_GL_FUNC(glDeleteBuffersARB)
2362 USE_GL_FUNC(glGenBuffersARB)
2363 USE_GL_FUNC(glGetBufferParameterivARB)
2364 USE_GL_FUNC(glGetBufferPointervARB)
2365 USE_GL_FUNC(glGetBufferSubDataARB)
2366 USE_GL_FUNC(glIsBufferARB)
2367 USE_GL_FUNC(glMapBufferARB)
2368 USE_GL_FUNC(glUnmapBufferARB)
2369 /* GL_ARB_vertex_program */
2370 USE_GL_FUNC(glBindProgramARB)
2371 USE_GL_FUNC(glDeleteProgramsARB)
2372 USE_GL_FUNC(glDisableVertexAttribArrayARB)
2373 USE_GL_FUNC(glEnableVertexAttribArrayARB)
2374 USE_GL_FUNC(glGenProgramsARB)
2375 USE_GL_FUNC(glGetProgramivARB)
2376 USE_GL_FUNC(glProgramEnvParameter4fvARB)
2377 USE_GL_FUNC(glProgramLocalParameter4fvARB)
2378 USE_GL_FUNC(glProgramStringARB)
2379 USE_GL_FUNC(glVertexAttrib1dARB)
2380 USE_GL_FUNC(glVertexAttrib1dvARB)
2381 USE_GL_FUNC(glVertexAttrib1fARB)
2382 USE_GL_FUNC(glVertexAttrib1fvARB)
2383 USE_GL_FUNC(glVertexAttrib1sARB)
2384 USE_GL_FUNC(glVertexAttrib1svARB)
2385 USE_GL_FUNC(glVertexAttrib2dARB)
2386 USE_GL_FUNC(glVertexAttrib2dvARB)
2387 USE_GL_FUNC(glVertexAttrib2fARB)
2388 USE_GL_FUNC(glVertexAttrib2fvARB)
2389 USE_GL_FUNC(glVertexAttrib2sARB)
2390 USE_GL_FUNC(glVertexAttrib2svARB)
2391 USE_GL_FUNC(glVertexAttrib3dARB)
2392 USE_GL_FUNC(glVertexAttrib3dvARB)
2393 USE_GL_FUNC(glVertexAttrib3fARB)
2394 USE_GL_FUNC(glVertexAttrib3fvARB)
2395 USE_GL_FUNC(glVertexAttrib3sARB)
2396 USE_GL_FUNC(glVertexAttrib3svARB)
2397 USE_GL_FUNC(glVertexAttrib4NbvARB)
2398 USE_GL_FUNC(glVertexAttrib4NivARB)
2399 USE_GL_FUNC(glVertexAttrib4NsvARB)
2400 USE_GL_FUNC(glVertexAttrib4NubARB)
2401 USE_GL_FUNC(glVertexAttrib4NubvARB)
2402 USE_GL_FUNC(glVertexAttrib4NuivARB)
2403 USE_GL_FUNC(glVertexAttrib4NusvARB)
2404 USE_GL_FUNC(glVertexAttrib4bvARB)
2405 USE_GL_FUNC(glVertexAttrib4dARB)
2406 USE_GL_FUNC(glVertexAttrib4dvARB)
2407 USE_GL_FUNC(glVertexAttrib4fARB)
2408 USE_GL_FUNC(glVertexAttrib4fvARB)
2409 USE_GL_FUNC(glVertexAttrib4ivARB)
2410 USE_GL_FUNC(glVertexAttrib4sARB)
2411 USE_GL_FUNC(glVertexAttrib4svARB)
2412 USE_GL_FUNC(glVertexAttrib4ubvARB)
2413 USE_GL_FUNC(glVertexAttrib4uivARB)
2414 USE_GL_FUNC(glVertexAttrib4usvARB)
2415 USE_GL_FUNC(glVertexAttribPointerARB)
2416 /* GL_ARB_viewport_array */
2417 USE_GL_FUNC(glDepthRangeArrayv)
2418 USE_GL_FUNC(glDepthRangeIndexed)
2419 USE_GL_FUNC(glGetDoublei_v)
2420 USE_GL_FUNC(glGetFloati_v)
2421 USE_GL_FUNC(glScissorArrayv)
2422 USE_GL_FUNC(glScissorIndexed)
2423 USE_GL_FUNC(glScissorIndexedv)
2424 USE_GL_FUNC(glViewportArrayv)
2425 USE_GL_FUNC(glViewportIndexedf)
2426 USE_GL_FUNC(glViewportIndexedfv)
2427 /* GL_ARB_texture_barrier */
2428 USE_GL_FUNC(glTextureBarrier);
2429 /* GL_ATI_fragment_shader */
2430 USE_GL_FUNC(glAlphaFragmentOp1ATI)
2431 USE_GL_FUNC(glAlphaFragmentOp2ATI)
2432 USE_GL_FUNC(glAlphaFragmentOp3ATI)
2433 USE_GL_FUNC(glBeginFragmentShaderATI)
2434 USE_GL_FUNC(glBindFragmentShaderATI)
2435 USE_GL_FUNC(glColorFragmentOp1ATI)
2436 USE_GL_FUNC(glColorFragmentOp2ATI)
2437 USE_GL_FUNC(glColorFragmentOp3ATI)
2438 USE_GL_FUNC(glDeleteFragmentShaderATI)
2439 USE_GL_FUNC(glEndFragmentShaderATI)
2440 USE_GL_FUNC(glGenFragmentShadersATI)
2441 USE_GL_FUNC(glPassTexCoordATI)
2442 USE_GL_FUNC(glSampleMapATI)
2443 USE_GL_FUNC(glSetFragmentShaderConstantATI)
2444 /* GL_ATI_separate_stencil */
2445 USE_GL_FUNC(glStencilOpSeparateATI)
2446 USE_GL_FUNC(glStencilFuncSeparateATI)
2447 /* GL_EXT_blend_color */
2448 USE_GL_FUNC(glBlendColorEXT)
2449 /* GL_EXT_blend_equation_separate */
2450 USE_GL_FUNC(glBlendFuncSeparateEXT)
2451 /* GL_EXT_blend_func_separate */
2452 USE_GL_FUNC(glBlendEquationSeparateEXT)
2453 /* GL_EXT_blend_minmax */
2454 USE_GL_FUNC(glBlendEquationEXT)
2455 /* GL_EXT_depth_bounds_test */
2456 USE_GL_FUNC(glDepthBoundsEXT)
2457 /* GL_EXT_draw_buffers2 */
2458 USE_GL_FUNC(glColorMaskIndexedEXT)
2459 USE_GL_FUNC(glDisableIndexedEXT)
2460 USE_GL_FUNC(glEnableIndexedEXT)
2461 USE_GL_FUNC(glGetBooleanIndexedvEXT)
2462 USE_GL_FUNC(glGetIntegerIndexedvEXT)
2463 USE_GL_FUNC(glIsEnabledIndexedEXT)
2464 /* GL_EXT_fog_coord */
2465 USE_GL_FUNC(glFogCoordPointerEXT)
2466 USE_GL_FUNC(glFogCoorddEXT)
2467 USE_GL_FUNC(glFogCoorddvEXT)
2468 USE_GL_FUNC(glFogCoordfEXT)
2469 USE_GL_FUNC(glFogCoordfvEXT)
2470 /* GL_EXT_framebuffer_blit */
2471 USE_GL_FUNC(glBlitFramebufferEXT)
2472 /* GL_EXT_framebuffer_multisample */
2473 USE_GL_FUNC(glRenderbufferStorageMultisampleEXT)
2474 /* GL_EXT_framebuffer_object */
2475 USE_GL_FUNC(glBindFramebufferEXT)
2476 USE_GL_FUNC(glBindRenderbufferEXT)
2477 USE_GL_FUNC(glCheckFramebufferStatusEXT)
2478 USE_GL_FUNC(glDeleteFramebuffersEXT)
2479 USE_GL_FUNC(glDeleteRenderbuffersEXT)
2480 USE_GL_FUNC(glFramebufferRenderbufferEXT)
2481 USE_GL_FUNC(glFramebufferTexture1DEXT)
2482 USE_GL_FUNC(glFramebufferTexture2DEXT)
2483 USE_GL_FUNC(glFramebufferTexture3DEXT)
2484 USE_GL_FUNC(glGenFramebuffersEXT)
2485 USE_GL_FUNC(glGenRenderbuffersEXT)
2486 USE_GL_FUNC(glGenerateMipmapEXT)
2487 USE_GL_FUNC(glGetFramebufferAttachmentParameterivEXT)
2488 USE_GL_FUNC(glGetRenderbufferParameterivEXT)
2489 USE_GL_FUNC(glIsFramebufferEXT)
2490 USE_GL_FUNC(glIsRenderbufferEXT)
2491 USE_GL_FUNC(glRenderbufferStorageEXT)
2492 /* GL_EXT_gpu_program_parameters */
2493 USE_GL_FUNC(glProgramEnvParameters4fvEXT)
2494 USE_GL_FUNC(glProgramLocalParameters4fvEXT)
2495 /* GL_EXT_gpu_shader4 */
2496 USE_GL_FUNC(glBindFragDataLocationEXT)
2497 USE_GL_FUNC(glGetFragDataLocationEXT)
2498 USE_GL_FUNC(glGetUniformuivEXT)
2499 USE_GL_FUNC(glGetVertexAttribIivEXT)
2500 USE_GL_FUNC(glGetVertexAttribIuivEXT)
2501 USE_GL_FUNC(glUniform1uiEXT)
2502 USE_GL_FUNC(glUniform1uivEXT)
2503 USE_GL_FUNC(glUniform2uiEXT)
2504 USE_GL_FUNC(glUniform2uivEXT)
2505 USE_GL_FUNC(glUniform3uiEXT)
2506 USE_GL_FUNC(glUniform3uivEXT)
2507 USE_GL_FUNC(glUniform4uiEXT)
2508 USE_GL_FUNC(glUniform4uivEXT)
2509 USE_GL_FUNC(glVertexAttribI1iEXT)
2510 USE_GL_FUNC(glVertexAttribI1ivEXT)
2511 USE_GL_FUNC(glVertexAttribI1uiEXT)
2512 USE_GL_FUNC(glVertexAttribI1uivEXT)
2513 USE_GL_FUNC(glVertexAttribI2iEXT)
2514 USE_GL_FUNC(glVertexAttribI2ivEXT)
2515 USE_GL_FUNC(glVertexAttribI2uiEXT)
2516 USE_GL_FUNC(glVertexAttribI2uivEXT)
2517 USE_GL_FUNC(glVertexAttribI3iEXT)
2518 USE_GL_FUNC(glVertexAttribI3ivEXT)
2519 USE_GL_FUNC(glVertexAttribI3uiEXT)
2520 USE_GL_FUNC(glVertexAttribI3uivEXT)
2521 USE_GL_FUNC(glVertexAttribI4bvEXT)
2522 USE_GL_FUNC(glVertexAttribI4iEXT)
2523 USE_GL_FUNC(glVertexAttribI4ivEXT)
2524 USE_GL_FUNC(glVertexAttribI4svEXT)
2525 USE_GL_FUNC(glVertexAttribI4ubvEXT)
2526 USE_GL_FUNC(glVertexAttribI4uiEXT)
2527 USE_GL_FUNC(glVertexAttribI4uivEXT)
2528 USE_GL_FUNC(glVertexAttribI4usvEXT)
2529 USE_GL_FUNC(glVertexAttribIPointerEXT)
2530 /* GL_EXT_memory_object */
2531 USE_GL_FUNC(glGetUnsignedBytei_vEXT)
2532 USE_GL_FUNC(glGetUnsignedBytevEXT)
2533 /* GL_EXT_point_parameters */
2534 USE_GL_FUNC(glPointParameterfEXT)
2535 USE_GL_FUNC(glPointParameterfvEXT)
2536 /* GL_EXT_polgyon_offset_clamp */
2537 USE_GL_FUNC(glPolygonOffsetClampEXT)
2538 /* GL_EXT_provoking_vertex */
2539 USE_GL_FUNC(glProvokingVertexEXT)
2540 /* GL_EXT_secondary_color */
2541 USE_GL_FUNC(glSecondaryColor3fEXT)
2542 USE_GL_FUNC(glSecondaryColor3fvEXT)
2543 USE_GL_FUNC(glSecondaryColor3ubEXT)
2544 USE_GL_FUNC(glSecondaryColor3ubvEXT)
2545 USE_GL_FUNC(glSecondaryColorPointerEXT)
2546 /* GL_EXT_stencil_two_side */
2547 USE_GL_FUNC(glActiveStencilFaceEXT)
2548 /* GL_EXT_texture3D */
2549 USE_GL_FUNC(glTexImage3D)
2550 USE_GL_FUNC(glTexImage3DEXT)
2551 USE_GL_FUNC(glTexSubImage3D)
2552 USE_GL_FUNC(glTexSubImage3DEXT)
2553 /* GL_NV_fence */
2554 USE_GL_FUNC(glDeleteFencesNV)
2555 USE_GL_FUNC(glFinishFenceNV)
2556 USE_GL_FUNC(glGenFencesNV)
2557 USE_GL_FUNC(glGetFenceivNV)
2558 USE_GL_FUNC(glIsFenceNV)
2559 USE_GL_FUNC(glSetFenceNV)
2560 USE_GL_FUNC(glTestFenceNV)
2561 /* GL_NV_half_float */
2562 USE_GL_FUNC(glColor3hNV)
2563 USE_GL_FUNC(glColor3hvNV)
2564 USE_GL_FUNC(glColor4hNV)
2565 USE_GL_FUNC(glColor4hvNV)
2566 USE_GL_FUNC(glFogCoordhNV)
2567 USE_GL_FUNC(glFogCoordhvNV)
2568 USE_GL_FUNC(glMultiTexCoord1hNV)
2569 USE_GL_FUNC(glMultiTexCoord1hvNV)
2570 USE_GL_FUNC(glMultiTexCoord2hNV)
2571 USE_GL_FUNC(glMultiTexCoord2hvNV)
2572 USE_GL_FUNC(glMultiTexCoord3hNV)
2573 USE_GL_FUNC(glMultiTexCoord3hvNV)
2574 USE_GL_FUNC(glMultiTexCoord4hNV)
2575 USE_GL_FUNC(glMultiTexCoord4hvNV)
2576 USE_GL_FUNC(glNormal3hNV)
2577 USE_GL_FUNC(glNormal3hvNV)
2578 USE_GL_FUNC(glSecondaryColor3hNV)
2579 USE_GL_FUNC(glSecondaryColor3hvNV)
2580 USE_GL_FUNC(glTexCoord1hNV)
2581 USE_GL_FUNC(glTexCoord1hvNV)
2582 USE_GL_FUNC(glTexCoord2hNV)
2583 USE_GL_FUNC(glTexCoord2hvNV)
2584 USE_GL_FUNC(glTexCoord3hNV)
2585 USE_GL_FUNC(glTexCoord3hvNV)
2586 USE_GL_FUNC(glTexCoord4hNV)
2587 USE_GL_FUNC(glTexCoord4hvNV)
2588 USE_GL_FUNC(glVertex2hNV)
2589 USE_GL_FUNC(glVertex2hvNV)
2590 USE_GL_FUNC(glVertex3hNV)
2591 USE_GL_FUNC(glVertex3hvNV)
2592 USE_GL_FUNC(glVertex4hNV)
2593 USE_GL_FUNC(glVertex4hvNV)
2594 USE_GL_FUNC(glVertexAttrib1hNV)
2595 USE_GL_FUNC(glVertexAttrib1hvNV)
2596 USE_GL_FUNC(glVertexAttrib2hNV)
2597 USE_GL_FUNC(glVertexAttrib2hvNV)
2598 USE_GL_FUNC(glVertexAttrib3hNV)
2599 USE_GL_FUNC(glVertexAttrib3hvNV)
2600 USE_GL_FUNC(glVertexAttrib4hNV)
2601 USE_GL_FUNC(glVertexAttrib4hvNV)
2602 USE_GL_FUNC(glVertexAttribs1hvNV)
2603 USE_GL_FUNC(glVertexAttribs2hvNV)
2604 USE_GL_FUNC(glVertexAttribs3hvNV)
2605 USE_GL_FUNC(glVertexAttribs4hvNV)
2606 USE_GL_FUNC(glVertexWeighthNV)
2607 USE_GL_FUNC(glVertexWeighthvNV)
2608 /* GL_NV_point_sprite */
2609 USE_GL_FUNC(glPointParameteriNV)
2610 USE_GL_FUNC(glPointParameterivNV)
2611 /* GL_NV_register_combiners */
2612 USE_GL_FUNC(glCombinerInputNV)
2613 USE_GL_FUNC(glCombinerOutputNV)
2614 USE_GL_FUNC(glCombinerParameterfNV)
2615 USE_GL_FUNC(glCombinerParameterfvNV)
2616 USE_GL_FUNC(glCombinerParameteriNV)
2617 USE_GL_FUNC(glCombinerParameterivNV)
2618 USE_GL_FUNC(glFinalCombinerInputNV)
2619 /* GL_NV_texture_barrier */
2620 USE_GL_FUNC(glTextureBarrierNV);
2621 /* WGL extensions */
2622 USE_GL_FUNC(wglChoosePixelFormatARB)
2623 USE_GL_FUNC(wglGetExtensionsStringARB)
2624 USE_GL_FUNC(wglGetPixelFormatAttribfvARB)
2625 USE_GL_FUNC(wglGetPixelFormatAttribivARB)
2626 USE_GL_FUNC(wglQueryCurrentRendererIntegerWINE)
2627 USE_GL_FUNC(wglQueryCurrentRendererStringWINE)
2628 USE_GL_FUNC(wglQueryRendererIntegerWINE)
2629 USE_GL_FUNC(wglQueryRendererStringWINE)
2630 USE_GL_FUNC(wglSetPixelFormatWINE)
2631 USE_GL_FUNC(wglSwapIntervalEXT)
2633 /* Newer core functions */
2634 USE_GL_FUNC(glActiveTexture) /* OpenGL 1.3 */
2635 USE_GL_FUNC(glAttachShader) /* OpenGL 2.0 */
2636 USE_GL_FUNC(glBeginQuery) /* OpenGL 1.5 */
2637 USE_GL_FUNC(glBeginTransformFeedback) /* OpenGL 3.0 */
2638 USE_GL_FUNC(glBindAttribLocation) /* OpenGL 2.0 */
2639 USE_GL_FUNC(glBindBuffer) /* OpenGL 1.5 */
2640 USE_GL_FUNC(glBindFragDataLocation) /* OpenGL 3.0 */
2641 USE_GL_FUNC(glBindVertexArray) /* OpenGL 3.0 */
2642 USE_GL_FUNC(glBlendColor) /* OpenGL 1.4 */
2643 USE_GL_FUNC(glBlendEquation) /* OpenGL 1.4 */
2644 USE_GL_FUNC(glBlendEquationi) /* OpenGL 4.0 */
2645 USE_GL_FUNC(glBlendEquationSeparate) /* OpenGL 2.0 */
2646 USE_GL_FUNC(glBlendEquationSeparatei) /* OpenGL 4.0 */
2647 USE_GL_FUNC(glBlendFunci) /* OpenGL 4.0 */
2648 USE_GL_FUNC(glBlendFuncSeparate) /* OpenGL 1.4 */
2649 USE_GL_FUNC(glBlendFuncSeparatei) /* OpenGL 4.0 */
2650 USE_GL_FUNC(glBufferData) /* OpenGL 1.5 */
2651 USE_GL_FUNC(glBufferSubData) /* OpenGL 1.5 */
2652 USE_GL_FUNC(glColorMaski) /* OpenGL 3.0 */
2653 USE_GL_FUNC(glCompileShader) /* OpenGL 2.0 */
2654 USE_GL_FUNC(glCompressedTexImage2D) /* OpenGL 1.3 */
2655 USE_GL_FUNC(glCompressedTexImage3D) /* OpenGL 1.3 */
2656 USE_GL_FUNC(glCompressedTexSubImage2D) /* OpenGL 1.3 */
2657 USE_GL_FUNC(glCompressedTexSubImage3D) /* OpenGL 1.3 */
2658 USE_GL_FUNC(glCreateProgram) /* OpenGL 2.0 */
2659 USE_GL_FUNC(glCreateShader) /* OpenGL 2.0 */
2660 USE_GL_FUNC(glDebugMessageCallback) /* OpenGL 4.3 */
2661 USE_GL_FUNC(glDebugMessageControl) /* OpenGL 4.3 */
2662 USE_GL_FUNC(glDebugMessageInsert) /* OpenGL 4.3 */
2663 USE_GL_FUNC(glDeleteBuffers) /* OpenGL 1.5 */
2664 USE_GL_FUNC(glDeleteProgram) /* OpenGL 2.0 */
2665 USE_GL_FUNC(glDeleteQueries) /* OpenGL 1.5 */
2666 USE_GL_FUNC(glDeleteShader) /* OpenGL 2.0 */
2667 USE_GL_FUNC(glDeleteVertexArrays) /* OpenGL 3.0 */
2668 USE_GL_FUNC(glDetachShader) /* OpenGL 2.0 */
2669 USE_GL_FUNC(glDisablei) /* OpenGL 3.0 */
2670 USE_GL_FUNC(glDisableVertexAttribArray) /* OpenGL 2.0 */
2671 USE_GL_FUNC(glDrawArraysInstanced) /* OpenGL 3.1 */
2672 USE_GL_FUNC(glDrawBuffers) /* OpenGL 2.0 */
2673 USE_GL_FUNC(glDrawElementsInstanced) /* OpenGL 3.1 */
2674 USE_GL_FUNC(glEnablei) /* OpenGL 3.0 */
2675 USE_GL_FUNC(glEnableVertexAttribArray) /* OpenGL 2.0 */
2676 USE_GL_FUNC(glEndQuery) /* OpenGL 1.5 */
2677 USE_GL_FUNC(glEndTransformFeedback) /* OpenGL 3.0 */
2678 USE_GL_FUNC(glFramebufferTexture) /* OpenGL 3.2 */
2679 USE_GL_FUNC(glGenBuffers) /* OpenGL 1.5 */
2680 USE_GL_FUNC(glGenQueries) /* OpenGL 1.5 */
2681 USE_GL_FUNC(glGenVertexArrays) /* OpenGL 3.0 */
2682 USE_GL_FUNC(glGetActiveUniform) /* OpenGL 2.0 */
2683 USE_GL_FUNC(glGetAttachedShaders) /* OpenGL 2.0 */
2684 USE_GL_FUNC(glGetAttribLocation) /* OpenGL 2.0 */
2685 USE_GL_FUNC(glGetBooleani_v) /* OpenGL 3.0 */
2686 USE_GL_FUNC(glGetBufferSubData) /* OpenGL 1.5 */
2687 USE_GL_FUNC(glGetCompressedTexImage) /* OpenGL 1.3 */
2688 USE_GL_FUNC(glGetDebugMessageLog) /* OpenGL 4.3 */
2689 USE_GL_FUNC(glGetIntegeri_v) /* OpenGL 3.0 */
2690 USE_GL_FUNC(glGetProgramInfoLog) /* OpenGL 2.0 */
2691 USE_GL_FUNC(glGetProgramiv) /* OpenGL 2.0 */
2692 USE_GL_FUNC(glGetQueryiv) /* OpenGL 1.5 */
2693 USE_GL_FUNC(glGetQueryObjectuiv) /* OpenGL 1.5 */
2694 USE_GL_FUNC(glGetShaderInfoLog) /* OpenGL 2.0 */
2695 USE_GL_FUNC(glGetShaderiv) /* OpenGL 2.0 */
2696 USE_GL_FUNC(glGetShaderSource) /* OpenGL 2.0 */
2697 USE_GL_FUNC(glGetStringi) /* OpenGL 3.0 */
2698 USE_GL_FUNC(glGetTextureLevelParameteriv) /* OpenGL 4.5 */
2699 USE_GL_FUNC(glGetTextureParameteriv) /* OpenGL 4.5 */
2700 USE_GL_FUNC(glGetUniformfv) /* OpenGL 2.0 */
2701 USE_GL_FUNC(glGetUniformiv) /* OpenGL 2.0 */
2702 USE_GL_FUNC(glGetUniformLocation) /* OpenGL 2.0 */
2703 USE_GL_FUNC(glIsEnabledi) /* OpenGL 3.0 */
2704 USE_GL_FUNC(glLinkProgram) /* OpenGL 2.0 */
2705 USE_GL_FUNC(glMapBuffer) /* OpenGL 1.5 */
2706 USE_GL_FUNC(glMinSampleShading) /* OpenGL 4.0 */
2707 USE_GL_FUNC(glPointParameteri) /* OpenGL 1.4 */
2708 USE_GL_FUNC(glPointParameteriv) /* OpenGL 1.4 */
2709 USE_GL_FUNC(glShaderSource) /* OpenGL 2.0 */
2710 USE_GL_FUNC(glStencilFuncSeparate) /* OpenGL 2.0 */
2711 USE_GL_FUNC(glStencilOpSeparate) /* OpenGL 2.0 */
2712 USE_GL_FUNC(glTexBuffer) /* OpenGL 3.1 */
2713 USE_GL_FUNC(glTexImage3D) /* OpenGL 1.2 */
2714 USE_GL_FUNC(glTexSubImage3D) /* OpenGL 1.2 */
2715 USE_GL_FUNC(glTransformFeedbackVaryings) /* OpenGL 3.0 */
2716 USE_GL_FUNC(glUniform1f) /* OpenGL 2.0 */
2717 USE_GL_FUNC(glUniform1fv) /* OpenGL 2.0 */
2718 USE_GL_FUNC(glUniform1i) /* OpenGL 2.0 */
2719 USE_GL_FUNC(glUniform1iv) /* OpenGL 2.0 */
2720 USE_GL_FUNC(glUniform2f) /* OpenGL 2.0 */
2721 USE_GL_FUNC(glUniform2fv) /* OpenGL 2.0 */
2722 USE_GL_FUNC(glUniform2i) /* OpenGL 2.0 */
2723 USE_GL_FUNC(glUniform2iv) /* OpenGL 2.0 */
2724 USE_GL_FUNC(glUniform3f) /* OpenGL 2.0 */
2725 USE_GL_FUNC(glUniform3fv) /* OpenGL 2.0 */
2726 USE_GL_FUNC(glUniform3i) /* OpenGL 2.0 */
2727 USE_GL_FUNC(glUniform3iv) /* OpenGL 2.0 */
2728 USE_GL_FUNC(glUniform4f) /* OpenGL 2.0 */
2729 USE_GL_FUNC(glUniform4fv) /* OpenGL 2.0 */
2730 USE_GL_FUNC(glUniform4i) /* OpenGL 2.0 */
2731 USE_GL_FUNC(glUniform4iv) /* OpenGL 2.0 */
2732 USE_GL_FUNC(glUniformMatrix2fv) /* OpenGL 2.0 */
2733 USE_GL_FUNC(glUniformMatrix3fv) /* OpenGL 2.0 */
2734 USE_GL_FUNC(glUniformMatrix4fv) /* OpenGL 2.0 */
2735 USE_GL_FUNC(glUnmapBuffer) /* OpenGL 1.5 */
2736 USE_GL_FUNC(glUseProgram) /* OpenGL 2.0 */
2737 USE_GL_FUNC(glValidateProgram) /* OpenGL 2.0 */
2738 USE_GL_FUNC(glVertexAttrib1f) /* OpenGL 2.0 */
2739 USE_GL_FUNC(glVertexAttrib1fv) /* OpenGL 2.0 */
2740 USE_GL_FUNC(glVertexAttrib2f) /* OpenGL 2.0 */
2741 USE_GL_FUNC(glVertexAttrib2fv) /* OpenGL 2.0 */
2742 USE_GL_FUNC(glVertexAttrib3f) /* OpenGL 2.0 */
2743 USE_GL_FUNC(glVertexAttrib3fv) /* OpenGL 2.0 */
2744 USE_GL_FUNC(glVertexAttrib4f) /* OpenGL 2.0 */
2745 USE_GL_FUNC(glVertexAttrib4fv) /* OpenGL 2.0 */
2746 USE_GL_FUNC(glVertexAttrib4Nsv) /* OpenGL 2.0 */
2747 USE_GL_FUNC(glVertexAttrib4Nub) /* OpenGL 2.0 */
2748 USE_GL_FUNC(glVertexAttrib4Nubv) /* OpenGL 2.0 */
2749 USE_GL_FUNC(glVertexAttrib4Nusv) /* OpenGL 2.0 */
2750 USE_GL_FUNC(glVertexAttrib4sv) /* OpenGL 2.0 */
2751 USE_GL_FUNC(glVertexAttrib4ubv) /* OpenGL 2.0 */
2752 USE_GL_FUNC(glVertexAttribDivisor) /* OpenGL 3.3 */
2753 USE_GL_FUNC(glVertexAttribIPointer) /* OpenGL 3.0 */
2754 USE_GL_FUNC(glVertexAttribPointer) /* OpenGL 2.0 */
2755 #undef USE_GL_FUNC
2757 #ifndef USE_WIN32_OPENGL
2758 /* hack: use the functions directly from the TEB table to bypass the thunks */
2759 /* note that we still need the above wglGetProcAddress calls to initialize the table */
2760 gl_info->gl_ops.ext = ((struct opengl_funcs *)NtCurrentTeb()->glTable)->ext;
2761 #endif
2763 #define MAP_GL_FUNCTION(core_func, ext_func) \
2764 do \
2766 if (!gl_info->gl_ops.ext.p_##core_func) \
2767 gl_info->gl_ops.ext.p_##core_func = gl_info->gl_ops.ext.p_##ext_func; \
2768 } while (0)
2769 #define MAP_GL_FUNCTION_CAST(core_func, ext_func) \
2770 do \
2772 if (!gl_info->gl_ops.ext.p_##core_func) \
2773 gl_info->gl_ops.ext.p_##core_func = (void *)gl_info->gl_ops.ext.p_##ext_func; \
2774 } while (0)
2776 MAP_GL_FUNCTION(glActiveTexture, glActiveTextureARB);
2777 MAP_GL_FUNCTION(glAttachShader, glAttachObjectARB);
2778 MAP_GL_FUNCTION(glBeginQuery, glBeginQueryARB);
2779 MAP_GL_FUNCTION(glBindAttribLocation, glBindAttribLocationARB);
2780 MAP_GL_FUNCTION(glBindBuffer, glBindBufferARB);
2781 MAP_GL_FUNCTION(glBindFragDataLocation, glBindFragDataLocationEXT);
2782 MAP_GL_FUNCTION(glBlendColor, glBlendColorEXT);
2783 MAP_GL_FUNCTION(glBlendEquation, glBlendEquationEXT);
2784 MAP_GL_FUNCTION(glBlendEquationi, glBlendEquationiARB);
2785 MAP_GL_FUNCTION(glBlendEquationSeparate, glBlendEquationSeparateEXT);
2786 MAP_GL_FUNCTION(glBlendEquationSeparatei, glBlendEquationSeparateiARB);
2787 MAP_GL_FUNCTION(glBlendFunci, glBlendFunciARB);
2788 MAP_GL_FUNCTION(glBlendFuncSeparate, glBlendFuncSeparateEXT);
2789 MAP_GL_FUNCTION(glBlendFuncSeparatei, glBlendFuncSeparateiARB);
2790 MAP_GL_FUNCTION(glBufferData, glBufferDataARB);
2791 MAP_GL_FUNCTION(glBufferSubData, glBufferSubDataARB);
2792 MAP_GL_FUNCTION(glColorMaski, glColorMaskIndexedEXT);
2793 MAP_GL_FUNCTION(glCompileShader, glCompileShaderARB);
2794 MAP_GL_FUNCTION(glCompressedTexImage2D, glCompressedTexImage2DARB);
2795 MAP_GL_FUNCTION(glCompressedTexImage3D, glCompressedTexImage3DARB);
2796 MAP_GL_FUNCTION(glCompressedTexSubImage2D, glCompressedTexSubImage2DARB);
2797 MAP_GL_FUNCTION(glCompressedTexSubImage3D, glCompressedTexSubImage3DARB);
2798 MAP_GL_FUNCTION(glCreateProgram, glCreateProgramObjectARB);
2799 MAP_GL_FUNCTION(glCreateShader, glCreateShaderObjectARB);
2800 MAP_GL_FUNCTION(glDebugMessageCallback, glDebugMessageCallbackARB);
2801 MAP_GL_FUNCTION(glDebugMessageControl, glDebugMessageControlARB);
2802 MAP_GL_FUNCTION(glDebugMessageInsert, glDebugMessageInsertARB);
2803 MAP_GL_FUNCTION(glDeleteBuffers, glDeleteBuffersARB);
2804 MAP_GL_FUNCTION(glDeleteProgram, glDeleteObjectARB);
2805 MAP_GL_FUNCTION(glDeleteQueries, glDeleteQueriesARB);
2806 MAP_GL_FUNCTION(glDeleteShader, glDeleteObjectARB);
2807 MAP_GL_FUNCTION(glDetachShader, glDetachObjectARB);
2808 MAP_GL_FUNCTION(glDisablei, glDisableIndexedEXT);
2809 MAP_GL_FUNCTION(glDisableVertexAttribArray, glDisableVertexAttribArrayARB);
2810 MAP_GL_FUNCTION(glDrawArraysInstanced, glDrawArraysInstancedARB);
2811 MAP_GL_FUNCTION(glDrawBuffers, glDrawBuffersARB);
2812 MAP_GL_FUNCTION(glDrawElementsInstanced, glDrawElementsInstancedARB);
2813 MAP_GL_FUNCTION(glEnablei, glEnableIndexedEXT);
2814 MAP_GL_FUNCTION(glEnableVertexAttribArray, glEnableVertexAttribArrayARB);
2815 MAP_GL_FUNCTION(glEndQuery, glEndQueryARB);
2816 MAP_GL_FUNCTION(glFramebufferTexture, glFramebufferTextureARB);
2817 MAP_GL_FUNCTION(glGenBuffers, glGenBuffersARB);
2818 MAP_GL_FUNCTION(glGenQueries, glGenQueriesARB);
2819 MAP_GL_FUNCTION(glGetActiveUniform, glGetActiveUniformARB);
2820 MAP_GL_FUNCTION(glGetAttachedShaders, glGetAttachedObjectsARB);
2821 MAP_GL_FUNCTION(glGetAttribLocation, glGetAttribLocationARB);
2822 MAP_GL_FUNCTION(glGetBooleani_v, glGetBooleanIndexedvEXT);
2823 MAP_GL_FUNCTION(glGetBufferSubData, glGetBufferSubDataARB);
2824 MAP_GL_FUNCTION(glGetCompressedTexImage, glGetCompressedTexImageARB);
2825 MAP_GL_FUNCTION(glGetDebugMessageLog, glGetDebugMessageLogARB);
2826 MAP_GL_FUNCTION(glGetIntegeri_v, glGetIntegerIndexedvEXT);
2827 MAP_GL_FUNCTION(glGetProgramInfoLog, glGetInfoLogARB);
2828 MAP_GL_FUNCTION(glGetProgramiv, glGetObjectParameterivARB);
2829 MAP_GL_FUNCTION(glGetQueryiv, glGetQueryivARB);
2830 MAP_GL_FUNCTION(glGetQueryObjectuiv, glGetQueryObjectuivARB);
2831 MAP_GL_FUNCTION(glGetShaderInfoLog, glGetInfoLogARB);
2832 MAP_GL_FUNCTION(glGetShaderiv, glGetObjectParameterivARB);
2833 MAP_GL_FUNCTION(glGetShaderSource, glGetShaderSourceARB);
2834 MAP_GL_FUNCTION(glGetUniformfv, glGetUniformfvARB);
2835 MAP_GL_FUNCTION(glGetUniformiv, glGetUniformivARB);
2836 MAP_GL_FUNCTION(glGetUniformLocation, glGetUniformLocationARB);
2837 MAP_GL_FUNCTION(glIsEnabledi, glIsEnabledIndexedEXT);
2838 MAP_GL_FUNCTION(glLinkProgram, glLinkProgramARB);
2839 MAP_GL_FUNCTION(glMapBuffer, glMapBufferARB);
2840 MAP_GL_FUNCTION(glMinSampleShading, glMinSampleShadingARB);
2841 MAP_GL_FUNCTION(glPolygonOffsetClamp, glPolygonOffsetClampEXT);
2842 MAP_GL_FUNCTION_CAST(glShaderSource, glShaderSourceARB);
2843 MAP_GL_FUNCTION(glTexBuffer, glTexBufferARB);
2844 MAP_GL_FUNCTION_CAST(glTexImage3D, glTexImage3DEXT);
2845 MAP_GL_FUNCTION(glTexSubImage3D, glTexSubImage3DEXT);
2846 MAP_GL_FUNCTION(glUniform1f, glUniform1fARB);
2847 MAP_GL_FUNCTION(glUniform1fv, glUniform1fvARB);
2848 MAP_GL_FUNCTION(glUniform1i, glUniform1iARB);
2849 MAP_GL_FUNCTION(glUniform1iv, glUniform1ivARB);
2850 MAP_GL_FUNCTION(glUniform2f, glUniform2fARB);
2851 MAP_GL_FUNCTION(glUniform2fv, glUniform2fvARB);
2852 MAP_GL_FUNCTION(glUniform2i, glUniform2iARB);
2853 MAP_GL_FUNCTION(glUniform2iv, glUniform2ivARB);
2854 MAP_GL_FUNCTION(glUniform3f, glUniform3fARB);
2855 MAP_GL_FUNCTION(glUniform3fv, glUniform3fvARB);
2856 MAP_GL_FUNCTION(glUniform3i, glUniform3iARB);
2857 MAP_GL_FUNCTION(glUniform3iv, glUniform3ivARB);
2858 MAP_GL_FUNCTION(glUniform4f, glUniform4fARB);
2859 MAP_GL_FUNCTION(glUniform4fv, glUniform4fvARB);
2860 MAP_GL_FUNCTION(glUniform4i, glUniform4iARB);
2861 MAP_GL_FUNCTION(glUniform4iv, glUniform4ivARB);
2862 MAP_GL_FUNCTION(glUniformMatrix2fv, glUniformMatrix2fvARB);
2863 MAP_GL_FUNCTION(glUniformMatrix3fv, glUniformMatrix3fvARB);
2864 MAP_GL_FUNCTION(glUniformMatrix4fv, glUniformMatrix4fvARB);
2865 MAP_GL_FUNCTION(glUnmapBuffer, glUnmapBufferARB);
2866 MAP_GL_FUNCTION(glUseProgram, glUseProgramObjectARB);
2867 MAP_GL_FUNCTION(glValidateProgram, glValidateProgramARB);
2868 MAP_GL_FUNCTION(glVertexAttrib1f, glVertexAttrib1fARB);
2869 MAP_GL_FUNCTION(glVertexAttrib1fv, glVertexAttrib1fvARB);
2870 MAP_GL_FUNCTION(glVertexAttrib2f, glVertexAttrib2fARB);
2871 MAP_GL_FUNCTION(glVertexAttrib2fv, glVertexAttrib2fvARB);
2872 MAP_GL_FUNCTION(glVertexAttrib3f, glVertexAttrib3fARB);
2873 MAP_GL_FUNCTION(glVertexAttrib3fv, glVertexAttrib3fvARB);
2874 MAP_GL_FUNCTION(glVertexAttrib4f, glVertexAttrib4fARB);
2875 MAP_GL_FUNCTION(glVertexAttrib4fv, glVertexAttrib4fvARB);
2876 MAP_GL_FUNCTION(glVertexAttrib4Nsv, glVertexAttrib4NsvARB);
2877 MAP_GL_FUNCTION(glVertexAttrib4Nub, glVertexAttrib4NubARB);
2878 MAP_GL_FUNCTION(glVertexAttrib4Nubv, glVertexAttrib4NubvARB);
2879 MAP_GL_FUNCTION(glVertexAttrib4Nusv, glVertexAttrib4NusvARB);
2880 MAP_GL_FUNCTION(glVertexAttrib4sv, glVertexAttrib4svARB);
2881 MAP_GL_FUNCTION(glVertexAttrib4ubv, glVertexAttrib4ubvARB);
2882 MAP_GL_FUNCTION(glVertexAttribDivisor, glVertexAttribDivisorARB);
2883 MAP_GL_FUNCTION(glVertexAttribIPointer, glVertexAttribIPointerEXT);
2884 MAP_GL_FUNCTION(glVertexAttribPointer, glVertexAttribPointerARB);
2885 #undef MAP_GL_FUNCTION
2886 #undef MAP_GL_FUNCTION_CAST
2889 static void wined3d_adapter_init_limits(struct wined3d_gl_info *gl_info)
2891 unsigned int i, sampler_count;
2892 GLint gl_max;
2894 gl_info->limits.buffers = 1;
2895 gl_info->limits.textures = 0;
2896 gl_info->limits.texture_coords = 0;
2897 for (i = 0; i < WINED3D_SHADER_TYPE_COUNT; ++i)
2899 gl_info->limits.uniform_blocks[i] = 0;
2900 gl_info->limits.samplers[i] = 0;
2902 gl_info->limits.samplers[WINED3D_SHADER_TYPE_PIXEL] = 1;
2903 gl_info->limits.combined_samplers = gl_info->limits.samplers[WINED3D_SHADER_TYPE_PIXEL];
2904 gl_info->limits.graphics_samplers = gl_info->limits.combined_samplers;
2905 gl_info->limits.vertex_attribs = 16;
2906 gl_info->limits.texture_buffer_offset_alignment = 1;
2907 gl_info->limits.glsl_vs_float_constants = 0;
2908 gl_info->limits.glsl_ps_float_constants = 0;
2909 gl_info->limits.arb_vs_float_constants = 0;
2910 gl_info->limits.arb_vs_native_constants = 0;
2911 gl_info->limits.arb_vs_instructions = 0;
2912 gl_info->limits.arb_vs_temps = 0;
2913 gl_info->limits.arb_ps_float_constants = 0;
2914 gl_info->limits.arb_ps_local_constants = 0;
2915 gl_info->limits.arb_ps_instructions = 0;
2916 gl_info->limits.arb_ps_temps = 0;
2918 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_CLIP_DISTANCES, &gl_max);
2919 gl_info->limits.user_clip_distances = min(WINED3D_MAX_CLIP_DISTANCES, gl_max);
2920 TRACE("Clip plane support - max planes %d.\n", gl_max);
2922 if (gl_info->supported[WINED3D_GL_LEGACY_CONTEXT])
2924 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_LIGHTS, &gl_max);
2925 gl_info->limits.lights = gl_max;
2926 TRACE("Light support - max lights %d.\n", gl_max);
2929 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gl_max);
2930 gl_info->limits.texture_size = gl_max;
2931 TRACE("Maximum texture size support - max texture size %d.\n", gl_max);
2933 if (gl_info->supported[ARB_MAP_BUFFER_ALIGNMENT])
2935 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MIN_MAP_BUFFER_ALIGNMENT, &gl_max);
2936 TRACE("Minimum buffer map alignment: %d.\n", gl_max);
2938 else
2940 WARN_(d3d_perf)("Driver doesn't guarantee a minimum buffer map alignment.\n");
2942 if (gl_info->supported[NV_REGISTER_COMBINERS])
2944 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_GENERAL_COMBINERS_NV, &gl_max);
2945 gl_info->limits.general_combiners = gl_max;
2946 TRACE("Max general combiners: %d.\n", gl_max);
2948 if (gl_info->supported[ARB_DRAW_BUFFERS] && wined3d_settings.offscreen_rendering_mode == ORM_FBO)
2950 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_DRAW_BUFFERS_ARB, &gl_max);
2951 gl_info->limits.buffers = min(WINED3D_MAX_RENDER_TARGETS, gl_max);
2952 TRACE("Max draw buffers: %u.\n", gl_max);
2954 if (gl_info->supported[ARB_MULTITEXTURE])
2956 if (gl_info->supported[WINED3D_GL_LEGACY_CONTEXT])
2958 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_max);
2959 gl_info->limits.textures = min(WINED3D_MAX_TEXTURES, gl_max);
2960 TRACE("Max textures: %d.\n", gl_info->limits.textures);
2962 if (gl_info->supported[ARB_FRAGMENT_PROGRAM])
2964 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_TEXTURE_COORDS_ARB, &gl_max);
2965 gl_info->limits.texture_coords = min(WINED3D_MAX_TEXTURES, gl_max);
2967 else
2969 gl_info->limits.texture_coords = gl_info->limits.textures;
2971 TRACE("Max texture coords: %d.\n", gl_info->limits.texture_coords);
2974 if (gl_info->supported[ARB_FRAGMENT_PROGRAM] || gl_info->supported[ARB_FRAGMENT_SHADER])
2976 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &gl_max);
2977 gl_info->limits.samplers[WINED3D_SHADER_TYPE_PIXEL] = gl_max;
2979 else
2981 gl_info->limits.samplers[WINED3D_SHADER_TYPE_PIXEL] = gl_info->limits.textures;
2983 TRACE("Max fragment samplers: %d.\n", gl_info->limits.samplers[WINED3D_SHADER_TYPE_PIXEL]);
2985 if (gl_info->supported[ARB_VERTEX_SHADER])
2987 unsigned int vertex_sampler_count;
2989 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, &gl_max);
2990 vertex_sampler_count = gl_info->limits.samplers[WINED3D_SHADER_TYPE_VERTEX] = gl_max;
2991 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, &gl_max);
2992 gl_info->limits.combined_samplers = gl_max;
2993 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_VERTEX_ATTRIBS_ARB, &gl_max);
2994 gl_info->limits.vertex_attribs = gl_max;
2996 /* Loading GLSL sampler uniforms is much simpler if we can assume
2997 * that the sampler setup is known at shader link time. In a
2998 * vertex shader + pixel shader combination this isn't an issue
2999 * because then the sampler setup only depends on the two shaders.
3000 * If a pixel shader is used with fixed-function vertex processing
3001 * we're fine too because fixed-function vertex processing doesn't
3002 * use any samplers. If fixed-function fragment processing is used
3003 * we have to make sure that all vertex sampler setups are valid
3004 * together with all possible fixed-function fragment processing
3005 * setups. This is true if vsamplers + WINED3D_MAX_TEXTURES <= max_samplers.
3006 * This is true on all Direct3D 9 cards that support vertex
3007 * texture fetch (GeForce 6 and GeForce 7 cards). Direct3D 9
3008 * Radeon cards do not support vertex texture fetch. Direct3D 10
3009 * cards have 128 samplers, and Direct3D 9 is limited to 8
3010 * fixed-function texture stages and 4 vertex samplers.
3011 * Direct3D 10 does not have a fixed-function pipeline anymore.
3013 * So this is just a check to check that our assumption holds
3014 * true. If not, write a warning and reduce the number of vertex
3015 * samplers or probably disable vertex texture fetch. */
3016 if (vertex_sampler_count && gl_info->limits.combined_samplers < 12
3017 && WINED3D_MAX_TEXTURES + vertex_sampler_count > gl_info->limits.combined_samplers)
3019 FIXME("OpenGL implementation supports %u vertex samplers and %u total samplers.\n",
3020 vertex_sampler_count, gl_info->limits.combined_samplers);
3021 FIXME("Expected vertex samplers + WINED3D_MAX_TEXTURES(=8) > combined_samplers.\n");
3022 if (gl_info->limits.combined_samplers > WINED3D_MAX_TEXTURES)
3023 vertex_sampler_count = gl_info->limits.combined_samplers - WINED3D_MAX_TEXTURES;
3024 else
3025 vertex_sampler_count = 0;
3026 gl_info->limits.samplers[WINED3D_SHADER_TYPE_VERTEX] = vertex_sampler_count;
3029 else
3031 gl_info->limits.combined_samplers = gl_info->limits.samplers[WINED3D_SHADER_TYPE_PIXEL];
3033 TRACE("Max vertex samplers: %u.\n", gl_info->limits.samplers[WINED3D_SHADER_TYPE_VERTEX]);
3034 TRACE("Max combined samplers: %u.\n", gl_info->limits.combined_samplers);
3035 TRACE("Max vertex attributes: %u.\n", gl_info->limits.vertex_attribs);
3037 else
3039 gl_info->limits.textures = 1;
3040 gl_info->limits.texture_coords = 1;
3043 if (gl_info->supported[EXT_TEXTURE3D])
3045 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE_EXT, &gl_max);
3046 gl_info->limits.texture3d_size = gl_max;
3047 TRACE("Max texture3D size: %d.\n", gl_info->limits.texture3d_size);
3049 if (gl_info->supported[ARB_TEXTURE_FILTER_ANISOTROPIC])
3051 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY, &gl_max);
3052 gl_info->limits.anisotropy = gl_max;
3053 TRACE("Max anisotropy: %d.\n", gl_info->limits.anisotropy);
3055 if (gl_info->supported[ARB_FRAGMENT_PROGRAM])
3057 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, &gl_max));
3058 gl_info->limits.arb_ps_float_constants = gl_max;
3059 TRACE("Max ARB_FRAGMENT_PROGRAM float constants: %d.\n", gl_info->limits.arb_ps_float_constants);
3060 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB, &gl_max));
3061 gl_info->limits.arb_ps_native_constants = gl_max;
3062 TRACE("Max ARB_FRAGMENT_PROGRAM native float constants: %d.\n",
3063 gl_info->limits.arb_ps_native_constants);
3064 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl_max));
3065 gl_info->limits.arb_ps_temps = gl_max;
3066 TRACE("Max ARB_FRAGMENT_PROGRAM native temporaries: %d.\n", gl_info->limits.arb_ps_temps);
3067 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl_max));
3068 gl_info->limits.arb_ps_instructions = gl_max;
3069 TRACE("Max ARB_FRAGMENT_PROGRAM native instructions: %d.\n", gl_info->limits.arb_ps_instructions);
3070 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB, &gl_max));
3071 gl_info->limits.arb_ps_local_constants = gl_max;
3072 TRACE("Max ARB_FRAGMENT_PROGRAM local parameters: %d.\n", gl_info->limits.arb_ps_instructions);
3074 if (gl_info->supported[ARB_VERTEX_PROGRAM])
3076 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, &gl_max));
3077 gl_info->limits.arb_vs_float_constants = gl_max;
3078 TRACE("Max ARB_VERTEX_PROGRAM float constants: %d.\n", gl_info->limits.arb_vs_float_constants);
3079 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB, &gl_max));
3080 gl_info->limits.arb_vs_native_constants = gl_max;
3081 TRACE("Max ARB_VERTEX_PROGRAM native float constants: %d.\n",
3082 gl_info->limits.arb_vs_native_constants);
3083 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl_max));
3084 gl_info->limits.arb_vs_temps = gl_max;
3085 TRACE("Max ARB_VERTEX_PROGRAM native temporaries: %d.\n", gl_info->limits.arb_vs_temps);
3086 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl_max));
3087 gl_info->limits.arb_vs_instructions = gl_max;
3088 TRACE("Max ARB_VERTEX_PROGRAM native instructions: %d.\n", gl_info->limits.arb_vs_instructions);
3090 if (gl_info->supported[ARB_VERTEX_SHADER])
3092 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, &gl_max);
3093 gl_info->limits.glsl_vs_float_constants = gl_max / 4;
3094 TRACE("Max ARB_VERTEX_SHADER float constants: %u.\n", gl_info->limits.glsl_vs_float_constants);
3096 if (gl_info->supported[ARB_UNIFORM_BUFFER_OBJECT])
3098 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_VERTEX_UNIFORM_BLOCKS, &gl_max);
3099 gl_info->limits.uniform_blocks[WINED3D_SHADER_TYPE_VERTEX] = min(gl_max, WINED3D_MAX_CBS);
3100 TRACE("Max vertex uniform blocks: %u (%d).\n",
3101 gl_info->limits.uniform_blocks[WINED3D_SHADER_TYPE_VERTEX], gl_max);
3104 if (gl_info->supported[ARB_TESSELLATION_SHADER])
3106 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_TESS_CONTROL_UNIFORM_BLOCKS, &gl_max);
3107 gl_info->limits.uniform_blocks[WINED3D_SHADER_TYPE_HULL] = min(gl_max, WINED3D_MAX_CBS);
3108 TRACE("Max hull uniform blocks: %u (%d).\n",
3109 gl_info->limits.uniform_blocks[WINED3D_SHADER_TYPE_HULL], gl_max);
3110 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_TESS_CONTROL_TEXTURE_IMAGE_UNITS, &gl_max);
3111 gl_info->limits.samplers[WINED3D_SHADER_TYPE_HULL] = gl_max;
3112 TRACE("Max hull samplers: %u.\n", gl_info->limits.samplers[WINED3D_SHADER_TYPE_HULL]);
3114 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_TESS_EVALUATION_UNIFORM_BLOCKS, &gl_max);
3115 gl_info->limits.uniform_blocks[WINED3D_SHADER_TYPE_DOMAIN] = min(gl_max, WINED3D_MAX_CBS);
3116 TRACE("Max domain uniform blocks: %u (%d).\n",
3117 gl_info->limits.uniform_blocks[WINED3D_SHADER_TYPE_DOMAIN], gl_max);
3118 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_TESS_EVALUATION_TEXTURE_IMAGE_UNITS, &gl_max);
3119 gl_info->limits.samplers[WINED3D_SHADER_TYPE_DOMAIN] = gl_max;
3120 TRACE("Max domain samplers: %u.\n", gl_info->limits.samplers[WINED3D_SHADER_TYPE_DOMAIN]);
3122 if (gl_info->supported[WINED3D_GL_VERSION_3_2] && gl_info->supported[ARB_UNIFORM_BUFFER_OBJECT])
3124 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_GEOMETRY_UNIFORM_BLOCKS, &gl_max);
3125 gl_info->limits.uniform_blocks[WINED3D_SHADER_TYPE_GEOMETRY] = min(gl_max, WINED3D_MAX_CBS);
3126 TRACE("Max geometry uniform blocks: %u (%d).\n",
3127 gl_info->limits.uniform_blocks[WINED3D_SHADER_TYPE_GEOMETRY], gl_max);
3128 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS, &gl_max);
3129 gl_info->limits.samplers[WINED3D_SHADER_TYPE_GEOMETRY] = gl_max;
3130 TRACE("Max geometry samplers: %u.\n", gl_info->limits.samplers[WINED3D_SHADER_TYPE_GEOMETRY]);
3132 if (gl_info->supported[ARB_FRAGMENT_SHADER])
3134 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB, &gl_max);
3135 gl_info->limits.glsl_ps_float_constants = gl_max / 4;
3136 TRACE("Max ARB_FRAGMENT_SHADER float constants: %u.\n", gl_info->limits.glsl_ps_float_constants);
3137 if (gl_info->supported[WINED3D_GL_LEGACY_CONTEXT])
3139 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_VARYING_FLOATS_ARB, &gl_max);
3140 gl_info->limits.glsl_varyings = gl_max;
3142 else
3144 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_FRAGMENT_INPUT_COMPONENTS, &gl_max);
3145 gl_info->limits.glsl_varyings = gl_max - 4;
3147 TRACE("Max GLSL varyings: %u (%u 4 component varyings).\n", gl_info->limits.glsl_varyings,
3148 gl_info->limits.glsl_varyings / 4);
3150 if (gl_info->supported[ARB_UNIFORM_BUFFER_OBJECT])
3152 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_BLOCKS, &gl_max);
3153 gl_info->limits.uniform_blocks[WINED3D_SHADER_TYPE_PIXEL] = min(gl_max, WINED3D_MAX_CBS);
3154 TRACE("Max fragment uniform blocks: %u (%d).\n",
3155 gl_info->limits.uniform_blocks[WINED3D_SHADER_TYPE_PIXEL], gl_max);
3158 if (gl_info->supported[ARB_COMPUTE_SHADER])
3160 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_COMPUTE_UNIFORM_BLOCKS, &gl_max);
3161 gl_info->limits.uniform_blocks[WINED3D_SHADER_TYPE_COMPUTE] = min(gl_max, WINED3D_MAX_CBS);
3162 TRACE("Max compute uniform blocks: %u (%d).\n",
3163 gl_info->limits.uniform_blocks[WINED3D_SHADER_TYPE_COMPUTE], gl_max);
3164 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS, &gl_max);
3165 gl_info->limits.samplers[WINED3D_SHADER_TYPE_COMPUTE] = gl_max;
3166 TRACE("Max compute samplers: %u.\n", gl_info->limits.samplers[WINED3D_SHADER_TYPE_COMPUTE]);
3168 if (gl_info->supported[ARB_UNIFORM_BUFFER_OBJECT])
3170 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_COMBINED_UNIFORM_BLOCKS, &gl_max);
3171 TRACE("Max combined uniform blocks: %d.\n", gl_max);
3172 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, &gl_max);
3173 TRACE("Max uniform buffer bindings: %d.\n", gl_max);
3175 if (gl_info->supported[ARB_TEXTURE_BUFFER_RANGE])
3177 gl_info->gl_ops.gl.p_glGetIntegerv(GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT, &gl_max);
3178 gl_info->limits.texture_buffer_offset_alignment = gl_max;
3179 TRACE("Minimum required texture buffer offset alignment %d.\n", gl_max);
3181 if (gl_info->supported[ARB_SHADER_ATOMIC_COUNTERS])
3183 GLint max_fragment_buffers, max_combined_buffers, max_bindings;
3184 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS, &max_fragment_buffers);
3185 TRACE("Max fragment atomic counter buffers: %d.\n", max_fragment_buffers);
3186 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS, &max_combined_buffers);
3187 TRACE("Max combined atomic counter buffers: %d.\n", max_combined_buffers);
3188 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS, &max_bindings);
3189 TRACE("Max atomic counter buffer bindings: %d.\n", max_bindings);
3190 if (max_fragment_buffers < MAX_UNORDERED_ACCESS_VIEWS
3191 || max_combined_buffers < MAX_UNORDERED_ACCESS_VIEWS
3192 || max_bindings < MAX_UNORDERED_ACCESS_VIEWS)
3194 WARN("Disabling ARB_shader_atomic_counters.\n");
3195 gl_info->supported[ARB_SHADER_ATOMIC_COUNTERS] = FALSE;
3198 if (gl_info->supported[ARB_TRANSFORM_FEEDBACK3])
3200 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_VERTEX_STREAMS, &gl_max);
3201 TRACE("Max vertex streams: %d.\n", gl_max);
3204 if (gl_info->supported[NV_LIGHT_MAX_EXPONENT])
3205 gl_info->gl_ops.gl.p_glGetFloatv(GL_MAX_SHININESS_NV, &gl_info->limits.shininess);
3206 else
3207 gl_info->limits.shininess = 128.0f;
3209 if (gl_info->supported[ARB_FRAMEBUFFER_OBJECT] || gl_info->supported[EXT_FRAMEBUFFER_MULTISAMPLE])
3211 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_SAMPLES, &gl_max);
3212 gl_info->limits.samples = gl_max;
3215 if (gl_info->supported[ARB_FRAMEBUFFER_NO_ATTACHMENTS])
3217 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_FRAMEBUFFER_WIDTH, &gl_max);
3218 gl_info->limits.framebuffer_width = gl_max;
3219 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_FRAMEBUFFER_HEIGHT, &gl_max);
3220 gl_info->limits.framebuffer_height = gl_max;
3222 else
3224 gl_info->limits.framebuffer_width = gl_info->limits.texture_size;
3225 gl_info->limits.framebuffer_height = gl_info->limits.texture_size;
3228 gl_info->limits.samplers[WINED3D_SHADER_TYPE_PIXEL] =
3229 min(gl_info->limits.samplers[WINED3D_SHADER_TYPE_PIXEL], MAX_GL_FRAGMENT_SAMPLERS);
3230 sampler_count = 0;
3231 for (i = 0; i < WINED3D_SHADER_TYPE_GRAPHICS_COUNT; ++i)
3232 sampler_count += gl_info->limits.samplers[i];
3233 if (gl_info->supported[WINED3D_GL_VERSION_3_2] && gl_info->limits.combined_samplers < sampler_count)
3235 /* The minimum value for GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS in OpenGL
3236 * 3.2 is 48 (16 per stage). When tessellation shaders are supported
3237 * the minimum value is increased to 80. */
3238 WARN("Graphics pipeline sampler count %u is greater than combined sampler count %u.\n",
3239 sampler_count, gl_info->limits.combined_samplers);
3240 for (i = 0; i < WINED3D_SHADER_TYPE_GRAPHICS_COUNT; ++i)
3241 gl_info->limits.samplers[i] = min(gl_info->limits.samplers[i], 16);
3244 /* A majority of OpenGL implementations allow us to statically partition
3245 * the set of texture bindings into six separate sets. */
3246 gl_info->limits.graphics_samplers = gl_info->limits.combined_samplers;
3247 sampler_count = 0;
3248 for (i = 0; i < WINED3D_SHADER_TYPE_COUNT; ++i)
3249 sampler_count += gl_info->limits.samplers[i];
3250 if (gl_info->limits.combined_samplers >= sampler_count)
3251 gl_info->limits.graphics_samplers -= gl_info->limits.samplers[WINED3D_SHADER_TYPE_COMPUTE];
3254 /* Context activation is done by the caller. */
3255 static BOOL wined3d_adapter_init_gl_caps(struct wined3d_adapter *adapter,
3256 struct wined3d_caps_gl_ctx *caps_gl_ctx, unsigned int wined3d_creation_flags)
3258 static const struct
3260 enum wined3d_gl_extension extension;
3261 DWORD min_gl_version;
3263 core_extensions[] =
3265 {EXT_TEXTURE3D, MAKEDWORD_VERSION(1, 2)},
3266 {ARB_MULTISAMPLE, MAKEDWORD_VERSION(1, 3)},
3267 {ARB_MULTITEXTURE, MAKEDWORD_VERSION(1, 3)},
3268 {ARB_TEXTURE_BORDER_CLAMP, MAKEDWORD_VERSION(1, 3)},
3269 {ARB_TEXTURE_COMPRESSION, MAKEDWORD_VERSION(1, 3)},
3270 {ARB_TEXTURE_CUBE_MAP, MAKEDWORD_VERSION(1, 3)},
3271 {ARB_DEPTH_TEXTURE, MAKEDWORD_VERSION(1, 4)},
3272 {ARB_POINT_PARAMETERS, MAKEDWORD_VERSION(1, 4)},
3273 {ARB_SHADOW, MAKEDWORD_VERSION(1, 4)},
3274 {ARB_TEXTURE_MIRRORED_REPEAT, MAKEDWORD_VERSION(1, 4)},
3275 {EXT_BLEND_COLOR, MAKEDWORD_VERSION(1, 4)},
3276 {EXT_BLEND_FUNC_SEPARATE, MAKEDWORD_VERSION(1, 4)},
3277 {EXT_BLEND_MINMAX, MAKEDWORD_VERSION(1, 4)},
3278 {EXT_BLEND_SUBTRACT, MAKEDWORD_VERSION(1, 4)},
3279 {EXT_STENCIL_WRAP, MAKEDWORD_VERSION(1, 4)},
3280 {NV_POINT_SPRITE, MAKEDWORD_VERSION(1, 4)},
3281 {ARB_OCCLUSION_QUERY, MAKEDWORD_VERSION(1, 5)},
3282 {ARB_VERTEX_BUFFER_OBJECT, MAKEDWORD_VERSION(1, 5)},
3283 {ARB_DRAW_BUFFERS, MAKEDWORD_VERSION(2, 0)},
3284 {ARB_FRAGMENT_SHADER, MAKEDWORD_VERSION(2, 0)},
3285 {ARB_SHADING_LANGUAGE_100, MAKEDWORD_VERSION(2, 0)},
3286 {ARB_TEXTURE_NON_POWER_OF_TWO, MAKEDWORD_VERSION(2, 0)},
3287 {ARB_VERTEX_SHADER, MAKEDWORD_VERSION(2, 0)},
3288 {EXT_BLEND_EQUATION_SEPARATE, MAKEDWORD_VERSION(2, 0)},
3289 {ARB_PIXEL_BUFFER_OBJECT, MAKEDWORD_VERSION(2, 1)},
3290 {EXT_TEXTURE_SRGB, MAKEDWORD_VERSION(2, 1)},
3291 {ARB_COLOR_BUFFER_FLOAT, MAKEDWORD_VERSION(3, 0)},
3292 {ARB_DEPTH_BUFFER_FLOAT, MAKEDWORD_VERSION(3, 0)},
3293 {ARB_FRAMEBUFFER_OBJECT, MAKEDWORD_VERSION(3, 0)},
3294 {ARB_FRAMEBUFFER_SRGB, MAKEDWORD_VERSION(3, 0)},
3295 {ARB_HALF_FLOAT_PIXEL, MAKEDWORD_VERSION(3, 0)},
3296 {ARB_HALF_FLOAT_VERTEX, MAKEDWORD_VERSION(3, 0)},
3297 {ARB_MAP_BUFFER_RANGE, MAKEDWORD_VERSION(3, 0)},
3298 {ARB_TEXTURE_COMPRESSION_RGTC, MAKEDWORD_VERSION(3, 0)},
3299 {ARB_TEXTURE_FLOAT, MAKEDWORD_VERSION(3, 0)},
3300 {ARB_TEXTURE_RG, MAKEDWORD_VERSION(3, 0)},
3301 {EXT_DRAW_BUFFERS2, MAKEDWORD_VERSION(3, 0)},
3302 {EXT_PACKED_FLOAT, MAKEDWORD_VERSION(3, 0)},
3303 {EXT_TEXTURE_ARRAY, MAKEDWORD_VERSION(3, 0)},
3304 {EXT_TEXTURE_INTEGER, MAKEDWORD_VERSION(3, 0)},
3305 {EXT_TEXTURE_SHARED_EXPONENT, MAKEDWORD_VERSION(3, 0)},
3306 /* We don't want to enable EXT_GPU_SHADER4: even though similar
3307 * functionality is available in core GL 3.0 / GLSL 1.30, it's different
3308 * enough that reusing the same flag for the new features hurts more
3309 * than it helps. */
3310 /* EXT_framebuffer_object, EXT_framebuffer_blit,
3311 * EXT_framebuffer_multisample and EXT_packed_depth_stencil
3312 * are integrated into ARB_framebuffer_object. */
3314 {ARB_COPY_BUFFER, MAKEDWORD_VERSION(3, 1)},
3315 {ARB_DRAW_INSTANCED, MAKEDWORD_VERSION(3, 1)},
3316 {ARB_TEXTURE_BUFFER_OBJECT, MAKEDWORD_VERSION(3, 1)},
3317 {ARB_UNIFORM_BUFFER_OBJECT, MAKEDWORD_VERSION(3, 1)},
3318 {EXT_TEXTURE_SNORM, MAKEDWORD_VERSION(3, 1)},
3319 /* We don't need or want GL_ARB_texture_rectangle (core in 3.1). */
3321 {ARB_DEPTH_CLAMP, MAKEDWORD_VERSION(3, 2)},
3322 {ARB_DRAW_ELEMENTS_BASE_VERTEX, MAKEDWORD_VERSION(3, 2)},
3323 /* ARB_geometry_shader4 exposes a somewhat different API compared to 3.2
3324 * core geometry shaders so it's not really correct to expose the
3325 * extension for core-only support. */
3326 {ARB_FRAGMENT_COORD_CONVENTIONS, MAKEDWORD_VERSION(3, 2)},
3327 {ARB_PROVOKING_VERTEX, MAKEDWORD_VERSION(3, 2)},
3328 {ARB_SEAMLESS_CUBE_MAP, MAKEDWORD_VERSION(3, 2)},
3329 {ARB_SYNC, MAKEDWORD_VERSION(3, 2)},
3330 {ARB_TEXTURE_MULTISAMPLE, MAKEDWORD_VERSION(3, 2)},
3331 {ARB_VERTEX_ARRAY_BGRA, MAKEDWORD_VERSION(3, 2)},
3333 {ARB_BLEND_FUNC_EXTENDED, MAKEDWORD_VERSION(3, 3)},
3334 {ARB_EXPLICIT_ATTRIB_LOCATION, MAKEDWORD_VERSION(3, 3)},
3335 {ARB_INSTANCED_ARRAYS, MAKEDWORD_VERSION(3, 3)},
3336 {ARB_SAMPLER_OBJECTS, MAKEDWORD_VERSION(3, 3)},
3337 {ARB_SHADER_BIT_ENCODING, MAKEDWORD_VERSION(3, 3)},
3338 {ARB_TEXTURE_RGB10_A2UI, MAKEDWORD_VERSION(3, 3)},
3339 {ARB_TEXTURE_SWIZZLE, MAKEDWORD_VERSION(3, 3)},
3340 {ARB_TIMER_QUERY, MAKEDWORD_VERSION(3, 3)},
3341 {ARB_VERTEX_TYPE_2_10_10_10_REV, MAKEDWORD_VERSION(3, 3)},
3343 {ARB_DRAW_BUFFERS_BLEND, MAKEDWORD_VERSION(4, 0)},
3344 {ARB_DRAW_INDIRECT, MAKEDWORD_VERSION(4, 0)},
3345 {ARB_GPU_SHADER5, MAKEDWORD_VERSION(4, 0)},
3346 {ARB_SAMPLE_SHADING, MAKEDWORD_VERSION(4, 0)},
3347 {ARB_TESSELLATION_SHADER, MAKEDWORD_VERSION(4, 0)},
3348 {ARB_TEXTURE_CUBE_MAP_ARRAY, MAKEDWORD_VERSION(4, 0)},
3349 {ARB_TEXTURE_GATHER, MAKEDWORD_VERSION(4, 0)},
3350 {ARB_TRANSFORM_FEEDBACK2, MAKEDWORD_VERSION(4, 0)},
3351 {ARB_TRANSFORM_FEEDBACK3, MAKEDWORD_VERSION(4, 0)},
3353 {ARB_ES2_COMPATIBILITY, MAKEDWORD_VERSION(4, 1)},
3354 {ARB_VIEWPORT_ARRAY, MAKEDWORD_VERSION(4, 1)},
3356 {ARB_BASE_INSTANCE, MAKEDWORD_VERSION(4, 2)},
3357 {ARB_CONSERVATIVE_DEPTH, MAKEDWORD_VERSION(4, 2)},
3358 {ARB_INTERNALFORMAT_QUERY, MAKEDWORD_VERSION(4, 2)},
3359 {ARB_MAP_BUFFER_ALIGNMENT, MAKEDWORD_VERSION(4, 2)},
3360 {ARB_SHADER_ATOMIC_COUNTERS, MAKEDWORD_VERSION(4, 2)},
3361 {ARB_SHADER_IMAGE_LOAD_STORE, MAKEDWORD_VERSION(4, 2)},
3362 {ARB_SHADING_LANGUAGE_420PACK, MAKEDWORD_VERSION(4, 2)},
3363 {ARB_SHADING_LANGUAGE_PACKING, MAKEDWORD_VERSION(4, 2)},
3364 {ARB_TEXTURE_COMPRESSION_BPTC, MAKEDWORD_VERSION(4, 2)},
3365 {ARB_TEXTURE_STORAGE, MAKEDWORD_VERSION(4, 2)},
3367 {ARB_CLEAR_BUFFER_OBJECT, MAKEDWORD_VERSION(4, 3)},
3368 {ARB_COMPUTE_SHADER, MAKEDWORD_VERSION(4, 3)},
3369 {ARB_COPY_IMAGE, MAKEDWORD_VERSION(4, 3)},
3370 {ARB_DEBUG_OUTPUT, MAKEDWORD_VERSION(4, 3)},
3371 {ARB_ES3_COMPATIBILITY, MAKEDWORD_VERSION(4, 3)},
3372 {ARB_FRAGMENT_LAYER_VIEWPORT, MAKEDWORD_VERSION(4, 3)},
3373 {ARB_FRAMEBUFFER_NO_ATTACHMENTS, MAKEDWORD_VERSION(4, 3)},
3374 {ARB_INTERNALFORMAT_QUERY2, MAKEDWORD_VERSION(4, 3)},
3375 {ARB_SHADER_IMAGE_SIZE, MAKEDWORD_VERSION(4, 3)},
3376 {ARB_SHADER_STORAGE_BUFFER_OBJECT, MAKEDWORD_VERSION(4, 3)},
3377 {ARB_STENCIL_TEXTURING, MAKEDWORD_VERSION(4, 3)},
3378 {ARB_TEXTURE_BUFFER_RANGE, MAKEDWORD_VERSION(4, 3)},
3379 {ARB_TEXTURE_QUERY_LEVELS, MAKEDWORD_VERSION(4, 3)},
3380 {ARB_TEXTURE_STORAGE_MULTISAMPLE, MAKEDWORD_VERSION(4, 3)},
3381 {ARB_TEXTURE_VIEW, MAKEDWORD_VERSION(4, 3)},
3383 {ARB_BUFFER_STORAGE, MAKEDWORD_VERSION(4, 4)},
3384 {ARB_CLEAR_TEXTURE, MAKEDWORD_VERSION(4, 4)},
3385 {ARB_QUERY_BUFFER_OBJECT, MAKEDWORD_VERSION(4, 4)},
3386 {ARB_TEXTURE_MIRROR_CLAMP_TO_EDGE, MAKEDWORD_VERSION(4, 4)},
3388 {ARB_CLIP_CONTROL, MAKEDWORD_VERSION(4, 5)},
3389 {ARB_CULL_DISTANCE, MAKEDWORD_VERSION(4, 5)},
3390 {ARB_DERIVATIVE_CONTROL, MAKEDWORD_VERSION(4, 5)},
3391 {ARB_SHADER_TEXTURE_IMAGE_SAMPLES, MAKEDWORD_VERSION(4, 5)},
3392 {ARB_TEXTURE_BARRIER, MAKEDWORD_VERSION(4, 5)},
3394 {ARB_PIPELINE_STATISTICS_QUERY, MAKEDWORD_VERSION(4, 6)},
3395 {ARB_POLYGON_OFFSET_CLAMP, MAKEDWORD_VERSION(4, 6)},
3396 {ARB_TEXTURE_FILTER_ANISOTROPIC, MAKEDWORD_VERSION(4, 6)},
3398 const char *gl_vendor_str, *gl_renderer_str, *gl_version_str;
3399 struct wined3d_gl_info *gl_info = &adapter->gl_info;
3400 DWORD gl_version, gl_ext_emul_mask;
3401 const char *WGL_Extensions = NULL;
3402 enum wined3d_gl_vendor gl_vendor;
3403 GLint context_profile = 0;
3404 unsigned int i, j;
3405 HDC hdc;
3407 TRACE("adapter %p.\n", adapter);
3409 gl_renderer_str = (const char *)gl_info->gl_ops.gl.p_glGetString(GL_RENDERER);
3410 TRACE("GL_RENDERER: %s.\n", debugstr_a(gl_renderer_str));
3411 if (!gl_renderer_str)
3413 ERR("Received a NULL GL_RENDERER.\n");
3414 return FALSE;
3417 gl_vendor_str = (const char *)gl_info->gl_ops.gl.p_glGetString(GL_VENDOR);
3418 TRACE("GL_VENDOR: %s.\n", debugstr_a(gl_vendor_str));
3419 if (!gl_vendor_str)
3421 ERR("Received a NULL GL_VENDOR.\n");
3422 return FALSE;
3425 /* Parse the GL_VERSION field into major and minor information */
3426 gl_version_str = (const char *)gl_info->gl_ops.gl.p_glGetString(GL_VERSION);
3427 TRACE("GL_VERSION: %s.\n", debugstr_a(gl_version_str));
3428 if (!gl_version_str)
3430 ERR("Received a NULL GL_VERSION.\n");
3431 return FALSE;
3433 gl_version = wined3d_parse_gl_version(gl_version_str);
3435 load_gl_funcs(gl_info);
3437 memset(gl_info->supported, 0, sizeof(gl_info->supported));
3438 gl_info->supported[WINED3D_GL_EXT_NONE] = TRUE;
3440 if (gl_version >= MAKEDWORD_VERSION(3, 2))
3442 gl_info->gl_ops.gl.p_glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &context_profile);
3443 checkGLcall("Querying context profile");
3445 if (context_profile & GL_CONTEXT_CORE_PROFILE_BIT)
3446 TRACE("Got a core profile context.\n");
3447 else
3448 gl_info->supported[WINED3D_GL_LEGACY_CONTEXT] = TRUE;
3450 TRACE("GL extensions reported:\n");
3451 if (gl_info->supported[WINED3D_GL_LEGACY_CONTEXT])
3453 const char *gl_extensions = (const char *)gl_info->gl_ops.gl.p_glGetString(GL_EXTENSIONS);
3455 if (!gl_extensions)
3457 ERR("Received a NULL GL_EXTENSIONS.\n");
3458 return FALSE;
3460 parse_extension_string(gl_info, gl_extensions, gl_extension_map, ARRAY_SIZE(gl_extension_map));
3462 else
3464 enumerate_gl_extensions(gl_info, gl_extension_map, ARRAY_SIZE(gl_extension_map));
3467 hdc = wglGetCurrentDC();
3468 /* Not all GL drivers might offer WGL extensions e.g. VirtualBox. */
3469 if (GL_EXTCALL(wglGetExtensionsStringARB))
3470 WGL_Extensions = (const char *)GL_EXTCALL(wglGetExtensionsStringARB(hdc));
3471 if (!WGL_Extensions)
3472 WARN("WGL extensions not supported.\n");
3473 else
3474 parse_extension_string(gl_info, WGL_Extensions, wgl_extension_map, ARRAY_SIZE(wgl_extension_map));
3476 for (i = 0; i < ARRAY_SIZE(core_extensions); ++i)
3478 if (!gl_info->supported[core_extensions[i].extension]
3479 && gl_version >= core_extensions[i].min_gl_version)
3481 for (j = 0; j < ARRAY_SIZE(gl_extension_map); ++j)
3482 if (gl_extension_map[j].extension == core_extensions[i].extension)
3483 break;
3485 if (j < ARRAY_SIZE(gl_extension_map))
3487 TRACE("GL CORE: %s support.\n", gl_extension_map[j].extension_string);
3488 gl_info->supported[core_extensions[i].extension] = TRUE;
3490 else
3492 FIXME("GL extension %u not in the GL extensions map.\n", core_extensions[i].extension);
3497 if (gl_info->supported[EXT_BLEND_MINMAX] || gl_info->supported[EXT_BLEND_SUBTRACT])
3498 gl_info->supported[WINED3D_GL_BLEND_EQUATION] = TRUE;
3500 if (gl_version >= MAKEDWORD_VERSION(2, 0))
3502 gl_info->supported[WINED3D_GL_VERSION_2_0] = TRUE;
3503 /* We want to use the core APIs for two-sided stencil in GL 2.0. */
3504 gl_info->supported[EXT_STENCIL_TWO_SIDE] = FALSE;
3506 if (gl_version >= MAKEDWORD_VERSION(3, 2))
3507 gl_info->supported[WINED3D_GL_VERSION_3_2] = TRUE;
3509 /* All the points are actually point sprites in core contexts, the APIs from
3510 * ARB_point_sprite are not supported anymore. */
3511 if (!gl_info->supported[WINED3D_GL_LEGACY_CONTEXT])
3512 gl_info->supported[ARB_POINT_SPRITE] = FALSE;
3514 if (gl_info->supported[APPLE_FENCE])
3516 /* GL_NV_fence and GL_APPLE_fence provide the same functionality basically.
3517 * The apple extension interacts with some other apple exts. Disable the NV
3518 * extension if the apple one is support to prevent confusion in other parts
3519 * of the code. */
3520 gl_info->supported[NV_FENCE] = FALSE;
3522 if (gl_info->supported[APPLE_FLOAT_PIXELS])
3524 /* GL_APPLE_float_pixels == GL_ARB_texture_float + GL_ARB_half_float_pixel
3526 * The enums are the same:
3527 * GL_RGBA16F_ARB = GL_RGBA_FLOAT16_APPLE = 0x881a
3528 * GL_RGB16F_ARB = GL_RGB_FLOAT16_APPLE = 0x881b
3529 * GL_RGBA32F_ARB = GL_RGBA_FLOAT32_APPLE = 0x8814
3530 * GL_RGB32F_ARB = GL_RGB_FLOAT32_APPLE = 0x8815
3531 * GL_HALF_FLOAT_ARB = GL_HALF_APPLE = 0x140b
3533 if (!gl_info->supported[ARB_TEXTURE_FLOAT])
3535 TRACE(" IMPLIED: GL_ARB_texture_float support (by GL_APPLE_float_pixels).\n");
3536 gl_info->supported[ARB_TEXTURE_FLOAT] = TRUE;
3538 if (!gl_info->supported[ARB_HALF_FLOAT_PIXEL])
3540 TRACE(" IMPLIED: GL_ARB_half_float_pixel support (by GL_APPLE_float_pixels).\n");
3541 gl_info->supported[ARB_HALF_FLOAT_PIXEL] = TRUE;
3544 if (gl_info->supported[ARB_MAP_BUFFER_RANGE])
3546 /* GL_ARB_map_buffer_range and GL_APPLE_flush_buffer_range provide the same
3547 * functionality. Prefer the ARB extension */
3548 gl_info->supported[APPLE_FLUSH_BUFFER_RANGE] = FALSE;
3550 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
3552 TRACE(" IMPLIED: NVIDIA (NV) Texture Gen Reflection support.\n");
3553 gl_info->supported[NV_TEXGEN_REFLECTION] = TRUE;
3555 if (!gl_info->supported[EXT_TEXTURE_COMPRESSION_RGTC] && gl_info->supported[ARB_TEXTURE_COMPRESSION_RGTC])
3557 TRACE(" IMPLIED: EXT_texture_compression_rgtc support (by ARB_texture_compression_rgtc).\n");
3558 gl_info->supported[EXT_TEXTURE_COMPRESSION_RGTC] = TRUE;
3560 if (!gl_info->supported[ARB_TEXTURE_COMPRESSION_RGTC] && gl_info->supported[EXT_TEXTURE_COMPRESSION_RGTC])
3562 TRACE(" IMPLIED: ARB_texture_compression_rgtc support (by EXT_texture_compression_rgtc).\n");
3563 gl_info->supported[ARB_TEXTURE_COMPRESSION_RGTC] = TRUE;
3565 if (gl_info->supported[ARB_TEXTURE_COMPRESSION_RGTC] && !gl_info->supported[ARB_TEXTURE_RG])
3567 TRACE("ARB_texture_rg not supported, disabling ARB_texture_compression_rgtc.\n");
3568 gl_info->supported[ARB_TEXTURE_COMPRESSION_RGTC] = FALSE;
3570 if (gl_info->supported[NV_TEXTURE_SHADER2])
3572 if (gl_info->supported[NV_REGISTER_COMBINERS])
3574 /* Also disable ATI_FRAGMENT_SHADER if register combiners and texture_shader2
3575 * are supported. The nv extensions provide the same functionality as the
3576 * ATI one, and a bit more(signed pixelformats). */
3577 gl_info->supported[ATI_FRAGMENT_SHADER] = FALSE;
3580 if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
3582 /* If we have full NP2 texture support, disable
3583 * GL_ARB_texture_rectangle because we will never use it.
3584 * This saves a few redundant glDisable calls. */
3585 gl_info->supported[ARB_TEXTURE_RECTANGLE] = FALSE;
3587 if (gl_info->supported[ATI_FRAGMENT_SHADER])
3589 /* Disable NV_register_combiners and fragment shader if this is supported.
3590 * generally the NV extensions are preferred over the ATI ones, and this
3591 * extension is disabled if register_combiners and texture_shader2 are both
3592 * supported. So we reach this place only if we have incomplete NV dxlevel 8
3593 * fragment processing support. */
3594 gl_info->supported[NV_REGISTER_COMBINERS] = FALSE;
3595 gl_info->supported[NV_REGISTER_COMBINERS2] = FALSE;
3596 gl_info->supported[NV_TEXTURE_SHADER] = FALSE;
3597 gl_info->supported[NV_TEXTURE_SHADER2] = FALSE;
3599 if (gl_info->supported[NV_HALF_FLOAT])
3601 /* GL_ARB_half_float_vertex is a subset of GL_NV_half_float. */
3602 gl_info->supported[ARB_HALF_FLOAT_VERTEX] = TRUE;
3604 if (gl_info->supported[ARB_FRAMEBUFFER_SRGB] && !gl_info->supported[EXT_TEXTURE_SRGB_DECODE])
3606 /* Current wined3d sRGB infrastructure requires EXT_texture_sRGB_decode
3607 * for GL_ARB_framebuffer_sRGB support (without EXT_texture_sRGB_decode
3608 * we never render to sRGB surfaces). */
3609 TRACE("EXT_texture_sRGB_decode is not supported, disabling ARB_framebuffer_sRGB.\n");
3610 gl_info->supported[ARB_FRAMEBUFFER_SRGB] = FALSE;
3612 if (gl_info->supported[ARB_OCCLUSION_QUERY])
3614 GLint counter_bits;
3616 GL_EXTCALL(glGetQueryiv(GL_SAMPLES_PASSED, GL_QUERY_COUNTER_BITS, &counter_bits));
3617 TRACE("Occlusion query counter has %d bits.\n", counter_bits);
3618 if (!counter_bits)
3619 gl_info->supported[ARB_OCCLUSION_QUERY] = FALSE;
3621 if (gl_info->supported[ARB_TIMER_QUERY])
3623 GLint counter_bits;
3625 GL_EXTCALL(glGetQueryiv(GL_TIMESTAMP, GL_QUERY_COUNTER_BITS, &counter_bits));
3626 TRACE("Timestamp query counter has %d bits.\n", counter_bits);
3627 if (!counter_bits)
3628 gl_info->supported[ARB_TIMER_QUERY] = FALSE;
3630 if (gl_version >= MAKEDWORD_VERSION(3, 0))
3632 GLint counter_bits;
3634 gl_info->supported[WINED3D_GL_PRIMITIVE_QUERY] = TRUE;
3636 GL_EXTCALL(glGetQueryiv(GL_PRIMITIVES_GENERATED, GL_QUERY_COUNTER_BITS, &counter_bits));
3637 TRACE("Primitives query counter has %d bits.\n", counter_bits);
3638 if (!counter_bits)
3639 gl_info->supported[WINED3D_GL_PRIMITIVE_QUERY] = FALSE;
3641 GL_EXTCALL(glGetQueryiv(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, GL_QUERY_COUNTER_BITS, &counter_bits));
3642 TRACE("Transform feedback primitives query counter has %d bits.\n", counter_bits);
3643 if (!counter_bits)
3644 gl_info->supported[WINED3D_GL_PRIMITIVE_QUERY] = FALSE;
3646 if (gl_info->supported[ARB_VIEWPORT_ARRAY])
3648 GLint subpixel_bits;
3650 gl_info->gl_ops.gl.p_glGetIntegerv(GL_VIEWPORT_SUBPIXEL_BITS, &subpixel_bits);
3651 TRACE("Viewport supports %d subpixel bits.\n", subpixel_bits);
3652 if (subpixel_bits < 8 && gl_info->supported[ARB_CLIP_CONTROL])
3654 TRACE("Disabling ARB_clip_control because viewport subpixel bits < 8.\n");
3655 gl_info->supported[ARB_CLIP_CONTROL] = FALSE;
3658 if (gl_info->supported[ARB_CLIP_CONTROL] && !gl_info->supported[ARB_VIEWPORT_ARRAY])
3660 /* When using ARB_clip_control we need the float viewport parameters
3661 * introduced by ARB_viewport_array to take care of the shifted pixel
3662 * coordinates. */
3663 TRACE("Disabling ARB_clip_control because ARB_viewport_array is not supported.\n");
3664 gl_info->supported[ARB_CLIP_CONTROL] = FALSE;
3666 if (gl_info->supported[ARB_STENCIL_TEXTURING] && !gl_info->supported[ARB_TEXTURE_SWIZZLE])
3668 /* The stencil value needs to be placed in the green channel. */
3669 TRACE("Disabling ARB_stencil_texturing because ARB_texture_swizzle is not supported.\n");
3670 gl_info->supported[ARB_STENCIL_TEXTURING] = FALSE;
3672 if (!gl_info->supported[ATI_TEXTURE_MIRROR_ONCE] && gl_info->supported[EXT_TEXTURE_MIRROR_CLAMP])
3674 TRACE(" IMPLIED: ATI_texture_mirror_once support (by EXT_texture_mirror_clamp).\n");
3675 gl_info->supported[ATI_TEXTURE_MIRROR_ONCE] = TRUE;
3677 if (!gl_info->supported[ARB_TEXTURE_MIRROR_CLAMP_TO_EDGE] && gl_info->supported[ATI_TEXTURE_MIRROR_ONCE])
3679 TRACE(" IMPLIED: ARB_texture_mirror_clamp_to_edge support (by ATI_texture_mirror_once).\n");
3680 gl_info->supported[ARB_TEXTURE_MIRROR_CLAMP_TO_EDGE] = TRUE;
3682 if (gl_info->supported[ARB_TEXTURE_STORAGE] && gl_info->supported[APPLE_YCBCR_422])
3684 /* AFAIK APPLE_ycbcr_422 is only available in legacy contexts so we shouldn't ever hit this. */
3685 ERR("Disabling APPLE_ycbcr_422 because of ARB_texture_storage.\n");
3686 gl_info->supported[APPLE_YCBCR_422] = FALSE;
3688 if (gl_info->supported[ARB_DRAW_INDIRECT] && !gl_info->supported[ARB_BASE_INSTANCE])
3690 /* If ARB_base_instance is not supported the baseInstance field
3691 * in indirect draw parameters must be 0 or behavior is undefined.
3693 WARN("Disabling ARB_draw_indirect because ARB_base_instance is not supported.\n");
3694 gl_info->supported[ARB_DRAW_INDIRECT] = FALSE;
3696 if (gl_info->supported[ARB_TEXTURE_MULTISAMPLE] && !wined3d_settings.multisample_textures)
3697 gl_info->supported[ARB_TEXTURE_MULTISAMPLE] = FALSE;
3698 if (gl_info->supported[ARB_TEXTURE_MULTISAMPLE] && !gl_info->supported[ARB_TEXTURE_STORAGE_MULTISAMPLE])
3700 WARN("Disabling ARB_texture_multisample because immutable storage is not supported.\n");
3701 gl_info->supported[ARB_TEXTURE_MULTISAMPLE] = FALSE;
3703 if (gl_info->supported[ARB_FRAMEBUFFER_OBJECT] && !gl_info->supported[EXT_PACKED_DEPTH_STENCIL])
3705 TRACE(" IMPLIED: GL_EXT_packed_depth_stencil (by GL_ARB_framebuffer_object).\n");
3706 gl_info->supported[EXT_PACKED_DEPTH_STENCIL] = TRUE;
3709 wined3d_adapter_init_limits(gl_info);
3711 if (gl_info->supported[ARB_VERTEX_PROGRAM] && test_arb_vs_offset_limit(gl_info))
3712 gl_info->quirks |= WINED3D_QUIRK_ARB_VS_OFFSET_LIMIT;
3714 if (gl_info->supported[ARB_SHADING_LANGUAGE_100])
3716 const char *str = (const char *)gl_info->gl_ops.gl.p_glGetString(GL_SHADING_LANGUAGE_VERSION_ARB);
3717 unsigned int major, minor;
3719 TRACE("GLSL version string: %s.\n", debugstr_a(str));
3721 /* The format of the GLSL version string is "major.minor[.release] [vendor info]". */
3722 sscanf(str, "%u.%u", &major, &minor);
3723 gl_info->glsl_version = MAKEDWORD_VERSION(major, minor);
3724 if (gl_info->glsl_version > MAKEDWORD_VERSION(1, 30) && gl_version < MAKEDWORD_VERSION(3, 0))
3726 WARN("OpenGL version %u.%u too low, limiting GLSL version to 1.30.\n",
3727 gl_version >> 16, gl_version & 0xffff);
3728 gl_info->glsl_version = MAKEDWORD_VERSION(1, 30);
3730 if (gl_info->glsl_version >= MAKEDWORD_VERSION(1, 30))
3731 gl_info->supported[WINED3D_GLSL_130] = TRUE;
3734 checkGLcall("extension detection");
3736 adapter->shader_backend = select_shader_backend(gl_info);
3737 adapter->vertex_pipe = select_vertex_implementation(gl_info, adapter->shader_backend);
3738 adapter->fragment_pipe = select_fragment_implementation(gl_info, adapter->shader_backend);
3740 if (gl_info->supported[ARB_FRAMEBUFFER_OBJECT])
3742 gl_info->fbo_ops.glIsRenderbuffer = gl_info->gl_ops.ext.p_glIsRenderbuffer;
3743 gl_info->fbo_ops.glBindRenderbuffer = gl_info->gl_ops.ext.p_glBindRenderbuffer;
3744 gl_info->fbo_ops.glDeleteRenderbuffers = gl_info->gl_ops.ext.p_glDeleteRenderbuffers;
3745 gl_info->fbo_ops.glGenRenderbuffers = gl_info->gl_ops.ext.p_glGenRenderbuffers;
3746 gl_info->fbo_ops.glRenderbufferStorage = gl_info->gl_ops.ext.p_glRenderbufferStorage;
3747 gl_info->fbo_ops.glRenderbufferStorageMultisample = gl_info->gl_ops.ext.p_glRenderbufferStorageMultisample;
3748 gl_info->fbo_ops.glGetRenderbufferParameteriv = gl_info->gl_ops.ext.p_glGetRenderbufferParameteriv;
3749 gl_info->fbo_ops.glIsFramebuffer = gl_info->gl_ops.ext.p_glIsFramebuffer;
3750 gl_info->fbo_ops.glBindFramebuffer = gl_info->gl_ops.ext.p_glBindFramebuffer;
3751 gl_info->fbo_ops.glDeleteFramebuffers = gl_info->gl_ops.ext.p_glDeleteFramebuffers;
3752 gl_info->fbo_ops.glGenFramebuffers = gl_info->gl_ops.ext.p_glGenFramebuffers;
3753 gl_info->fbo_ops.glCheckFramebufferStatus = gl_info->gl_ops.ext.p_glCheckFramebufferStatus;
3754 gl_info->fbo_ops.glFramebufferTexture1D = gl_info->gl_ops.ext.p_glFramebufferTexture1D;
3755 gl_info->fbo_ops.glFramebufferTexture2D = gl_info->gl_ops.ext.p_glFramebufferTexture2D;
3756 gl_info->fbo_ops.glFramebufferTexture3D = gl_info->gl_ops.ext.p_glFramebufferTexture3D;
3757 gl_info->fbo_ops.glFramebufferTextureLayer = gl_info->gl_ops.ext.p_glFramebufferTextureLayer;
3758 gl_info->fbo_ops.glFramebufferRenderbuffer = gl_info->gl_ops.ext.p_glFramebufferRenderbuffer;
3759 gl_info->fbo_ops.glGetFramebufferAttachmentParameteriv
3760 = gl_info->gl_ops.ext.p_glGetFramebufferAttachmentParameteriv;
3761 gl_info->fbo_ops.glBlitFramebuffer = gl_info->gl_ops.ext.p_glBlitFramebuffer;
3762 gl_info->fbo_ops.glGenerateMipmap = gl_info->gl_ops.ext.p_glGenerateMipmap;
3763 gl_info->fbo_ops.glFramebufferTexture = gl_info->gl_ops.ext.p_glFramebufferTexture;
3765 else
3767 if (gl_info->supported[EXT_FRAMEBUFFER_OBJECT])
3769 gl_info->fbo_ops.glIsRenderbuffer = gl_info->gl_ops.ext.p_glIsRenderbufferEXT;
3770 gl_info->fbo_ops.glBindRenderbuffer = gl_info->gl_ops.ext.p_glBindRenderbufferEXT;
3771 gl_info->fbo_ops.glDeleteRenderbuffers = gl_info->gl_ops.ext.p_glDeleteRenderbuffersEXT;
3772 gl_info->fbo_ops.glGenRenderbuffers = gl_info->gl_ops.ext.p_glGenRenderbuffersEXT;
3773 gl_info->fbo_ops.glRenderbufferStorage = gl_info->gl_ops.ext.p_glRenderbufferStorageEXT;
3774 gl_info->fbo_ops.glGetRenderbufferParameteriv = gl_info->gl_ops.ext.p_glGetRenderbufferParameterivEXT;
3775 gl_info->fbo_ops.glIsFramebuffer = gl_info->gl_ops.ext.p_glIsFramebufferEXT;
3776 gl_info->fbo_ops.glBindFramebuffer = gl_info->gl_ops.ext.p_glBindFramebufferEXT;
3777 gl_info->fbo_ops.glDeleteFramebuffers = gl_info->gl_ops.ext.p_glDeleteFramebuffersEXT;
3778 gl_info->fbo_ops.glGenFramebuffers = gl_info->gl_ops.ext.p_glGenFramebuffersEXT;
3779 gl_info->fbo_ops.glCheckFramebufferStatus = gl_info->gl_ops.ext.p_glCheckFramebufferStatusEXT;
3780 gl_info->fbo_ops.glFramebufferTexture1D = gl_info->gl_ops.ext.p_glFramebufferTexture1DEXT;
3781 gl_info->fbo_ops.glFramebufferTexture2D = gl_info->gl_ops.ext.p_glFramebufferTexture2DEXT;
3782 gl_info->fbo_ops.glFramebufferTexture3D = gl_info->gl_ops.ext.p_glFramebufferTexture3DEXT;
3783 gl_info->fbo_ops.glFramebufferRenderbuffer = gl_info->gl_ops.ext.p_glFramebufferRenderbufferEXT;
3784 gl_info->fbo_ops.glGetFramebufferAttachmentParameteriv
3785 = gl_info->gl_ops.ext.p_glGetFramebufferAttachmentParameterivEXT;
3786 gl_info->fbo_ops.glGenerateMipmap = gl_info->gl_ops.ext.p_glGenerateMipmapEXT;
3788 else if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
3790 WARN_(d3d_perf)("Framebuffer objects not supported, falling back to backbuffer offscreen rendering mode.\n");
3791 wined3d_settings.offscreen_rendering_mode = ORM_BACKBUFFER;
3794 if (gl_info->supported[ARB_GEOMETRY_SHADER4])
3796 gl_info->fbo_ops.glFramebufferTexture = gl_info->gl_ops.ext.p_glFramebufferTextureARB;
3797 gl_info->fbo_ops.glFramebufferTextureLayer = gl_info->gl_ops.ext.p_glFramebufferTextureLayerARB;
3799 if (gl_info->supported[EXT_FRAMEBUFFER_BLIT])
3801 gl_info->fbo_ops.glBlitFramebuffer = gl_info->gl_ops.ext.p_glBlitFramebufferEXT;
3803 if (gl_info->supported[EXT_FRAMEBUFFER_MULTISAMPLE])
3805 gl_info->fbo_ops.glRenderbufferStorageMultisample
3806 = gl_info->gl_ops.ext.p_glRenderbufferStorageMultisampleEXT;
3810 gl_info->wrap_lookup[WINED3D_TADDRESS_WRAP - WINED3D_TADDRESS_WRAP] = GL_REPEAT;
3811 gl_info->wrap_lookup[WINED3D_TADDRESS_MIRROR - WINED3D_TADDRESS_WRAP] =
3812 gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT] ? GL_MIRRORED_REPEAT_ARB : GL_REPEAT;
3813 gl_info->wrap_lookup[WINED3D_TADDRESS_CLAMP - WINED3D_TADDRESS_WRAP] = GL_CLAMP_TO_EDGE;
3814 gl_info->wrap_lookup[WINED3D_TADDRESS_BORDER - WINED3D_TADDRESS_WRAP] =
3815 gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] ? GL_CLAMP_TO_BORDER_ARB : GL_REPEAT;
3816 gl_info->wrap_lookup[WINED3D_TADDRESS_MIRROR_ONCE - WINED3D_TADDRESS_WRAP] =
3817 gl_info->supported[ARB_TEXTURE_MIRROR_CLAMP_TO_EDGE] ? GL_MIRROR_CLAMP_TO_EDGE : GL_REPEAT;
3819 if (!gl_info->supported[WINED3D_GL_LEGACY_CONTEXT])
3821 GLuint vao;
3823 GL_EXTCALL(glGenVertexArrays(1, &vao));
3824 GL_EXTCALL(glBindVertexArray(vao));
3825 checkGLcall("creating VAO");
3828 gl_vendor = wined3d_guess_gl_vendor(gl_info, gl_vendor_str, gl_renderer_str, gl_version_str);
3829 TRACE("Guessed GL vendor %#x.\n", gl_vendor);
3831 if (!(caps_gl_ctx->gpu_description = query_gpu_description(gl_info, &caps_gl_ctx->vram_bytes)))
3833 enum wined3d_feature_level feature_level;
3834 struct fragment_caps fragment_caps;
3835 enum wined3d_pci_vendor vendor;
3836 enum wined3d_pci_device device;
3837 struct shader_caps shader_caps;
3839 adapter->shader_backend->shader_get_caps(adapter, &shader_caps);
3840 adapter->fragment_pipe->get_caps(adapter, &fragment_caps);
3841 feature_level = feature_level_from_caps(gl_info, &shader_caps, &fragment_caps);
3843 vendor = wined3d_guess_card_vendor(gl_vendor_str, gl_renderer_str);
3844 TRACE("Guessed vendor PCI ID 0x%04x.\n", vendor);
3846 device = wined3d_guess_card(feature_level, gl_renderer_str, &gl_vendor, &vendor);
3847 TRACE("Guessed device PCI ID 0x%04x.\n", device);
3849 if (!(caps_gl_ctx->gpu_description = wined3d_get_gpu_description(vendor, device)))
3851 ERR("Card %04x:%04x not found in driver DB.\n", vendor, device);
3852 return FALSE;
3855 fixup_extensions(gl_info, caps_gl_ctx, gl_renderer_str, gl_vendor);
3857 adapter->vram_bytes_used = 0;
3858 TRACE("Emulating 0x%s bytes of video ram.\n", wine_dbgstr_longlong(caps_gl_ctx->vram_bytes));
3860 if (gl_info->supported[EXT_MEMORY_OBJECT])
3862 GLint device_count = 0;
3864 gl_info->gl_ops.gl.p_glGetIntegerv(GL_NUM_DEVICE_UUIDS_EXT, &device_count);
3865 if (device_count > 0)
3867 if (device_count > 1)
3868 FIXME("A set of %d devices is not supported.\n", device_count);
3870 GL_EXTCALL(glGetUnsignedBytevEXT(GL_DRIVER_UUID_EXT, (GLubyte *)&adapter->driver_uuid));
3871 GL_EXTCALL(glGetUnsignedBytei_vEXT(GL_DEVICE_UUID_EXT, 0, (GLubyte *)&adapter->device_uuid));
3873 TRACE("Driver UUID: %s, device UUID %s.\n",
3874 debugstr_guid(&adapter->driver_uuid), debugstr_guid(&adapter->device_uuid));
3876 else
3878 WARN("Unexpected device count %d.\n", device_count);
3882 gl_ext_emul_mask = adapter->vertex_pipe->vp_get_emul_mask(gl_info)
3883 | adapter->fragment_pipe->get_emul_mask(gl_info);
3884 if (gl_ext_emul_mask & GL_EXT_EMUL_ARB_MULTITEXTURE)
3885 install_gl_compat_wrapper(gl_info, ARB_MULTITEXTURE);
3886 if (gl_ext_emul_mask & GL_EXT_EMUL_EXT_FOG_COORD)
3887 install_gl_compat_wrapper(gl_info, EXT_FOG_COORD);
3889 return TRUE;
3892 static void WINE_GLAPI invalid_func(const void *data)
3894 ERR("Invalid vertex attribute function called.\n");
3895 DebugBreak();
3898 static void WINE_GLAPI invalid_texcoord_func(GLenum unit, const void *data)
3900 ERR("Invalid texcoord function called.\n");
3901 DebugBreak();
3904 static void WINE_GLAPI invalid_generic_attrib_func(GLuint idx, const void *data)
3906 ERR("Invalid attribute function called.\n");
3907 DebugBreak();
3910 /* Helper functions for providing vertex data to OpenGL. The arrays are
3911 * initialised based on the extension detection and are used in
3912 * draw_primitive_immediate_mode(). */
3913 static void WINE_GLAPI position_d3dcolor(const void *data)
3915 const struct wined3d_gl_info *gl_info = wined3d_context_gl_get_current()->gl_info;
3916 DWORD pos = *((const DWORD *)data);
3918 FIXME("Add a test for fixed function position from d3dcolor type.\n");
3919 gl_info->gl_ops.gl.p_glVertex4s(D3DCOLOR_B_R(pos),
3920 D3DCOLOR_B_G(pos),
3921 D3DCOLOR_B_B(pos),
3922 D3DCOLOR_B_A(pos));
3925 static void WINE_GLAPI position_float4(const void *data)
3927 const struct wined3d_gl_info *gl_info = wined3d_context_gl_get_current()->gl_info;
3928 const GLfloat *pos = data;
3930 if (pos[3] != 0.0f && pos[3] != 1.0f)
3932 float w = 1.0f / pos[3];
3934 gl_info->gl_ops.gl.p_glVertex4f(pos[0] * w, pos[1] * w, pos[2] * w, w);
3936 else
3938 gl_info->gl_ops.gl.p_glVertex3fv(pos);
3942 static void WINE_GLAPI diffuse_d3dcolor(const void *data)
3944 const struct wined3d_gl_info *gl_info = wined3d_context_gl_get_current()->gl_info;
3945 DWORD diffuseColor = *((const DWORD *)data);
3947 gl_info->gl_ops.gl.p_glColor4ub(D3DCOLOR_B_R(diffuseColor),
3948 D3DCOLOR_B_G(diffuseColor),
3949 D3DCOLOR_B_B(diffuseColor),
3950 D3DCOLOR_B_A(diffuseColor));
3953 static void WINE_GLAPI specular_d3dcolor(const void *data)
3955 const struct wined3d_gl_info *gl_info = wined3d_context_gl_get_current()->gl_info;
3956 DWORD specularColor = *((const DWORD *)data);
3957 GLubyte d[] =
3959 D3DCOLOR_B_R(specularColor),
3960 D3DCOLOR_B_G(specularColor),
3961 D3DCOLOR_B_B(specularColor)
3964 gl_info->gl_ops.ext.p_glSecondaryColor3ubvEXT(d);
3967 static void WINE_GLAPI warn_no_specular_func(const void *data)
3969 WARN("GL_EXT_secondary_color not supported.\n");
3972 static void WINE_GLAPI generic_d3dcolor(GLuint idx, const void *data)
3974 const struct wined3d_gl_info *gl_info = wined3d_context_gl_get_current()->gl_info;
3975 DWORD color = *((const DWORD *)data);
3977 gl_info->gl_ops.ext.p_glVertexAttrib4Nub(idx,
3978 D3DCOLOR_B_R(color), D3DCOLOR_B_G(color),
3979 D3DCOLOR_B_B(color), D3DCOLOR_B_A(color));
3982 static void WINE_GLAPI generic_short2n(GLuint idx, const void *data)
3984 const struct wined3d_gl_info *gl_info = wined3d_context_gl_get_current()->gl_info;
3985 const GLshort s[] = {((const GLshort *)data)[0], ((const GLshort *)data)[1], 0, 1};
3987 gl_info->gl_ops.ext.p_glVertexAttrib4Nsv(idx, s);
3990 static void WINE_GLAPI generic_ushort2n(GLuint idx, const void *data)
3992 const GLushort s[] = {((const GLushort *)data)[0], ((const GLushort *)data)[1], 0, 1};
3993 const struct wined3d_gl_info *gl_info = wined3d_context_gl_get_current()->gl_info;
3995 gl_info->gl_ops.ext.p_glVertexAttrib4Nusv(idx, s);
3998 static void WINE_GLAPI generic_float16_2(GLuint idx, const void *data)
4000 const struct wined3d_gl_info *gl_info = wined3d_context_gl_get_current()->gl_info;
4001 float x = float_16_to_32(((const unsigned short *)data) + 0);
4002 float y = float_16_to_32(((const unsigned short *)data) + 1);
4004 gl_info->gl_ops.ext.p_glVertexAttrib2f(idx, x, y);
4007 static void WINE_GLAPI generic_float16_4(GLuint idx, const void *data)
4009 const struct wined3d_gl_info *gl_info = wined3d_context_gl_get_current()->gl_info;
4010 float x = float_16_to_32(((const unsigned short *)data) + 0);
4011 float y = float_16_to_32(((const unsigned short *)data) + 1);
4012 float z = float_16_to_32(((const unsigned short *)data) + 2);
4013 float w = float_16_to_32(((const unsigned short *)data) + 3);
4015 gl_info->gl_ops.ext.p_glVertexAttrib4f(idx, x, y, z, w);
4018 static void wined3d_adapter_init_ffp_attrib_ops(struct wined3d_adapter *adapter)
4020 const struct wined3d_gl_info *gl_info = &adapter->gl_info;
4021 struct wined3d_d3d_info *d3d_info = &adapter->d3d_info;
4022 struct wined3d_ffp_attrib_ops *ops = &d3d_info->ffp_attrib_ops;
4023 unsigned int i;
4025 for (i = 0; i < WINED3D_FFP_EMIT_COUNT; ++i)
4027 ops->position[i] = invalid_func;
4028 ops->diffuse[i] = invalid_func;
4029 ops->specular[i] = invalid_func;
4030 ops->normal[i] = invalid_func;
4031 ops->texcoord[i] = invalid_texcoord_func;
4032 ops->generic[i] = invalid_generic_attrib_func;
4035 ops->position[WINED3D_FFP_EMIT_FLOAT3] = (wined3d_ffp_attrib_func)gl_info->gl_ops.gl.p_glVertex3fv;
4036 if (!d3d_info->xyzrhw)
4037 ops->position[WINED3D_FFP_EMIT_FLOAT4] = position_float4;
4038 else
4039 ops->position[WINED3D_FFP_EMIT_FLOAT4] = (wined3d_ffp_attrib_func)gl_info->gl_ops.gl.p_glVertex4fv;
4040 ops->position[WINED3D_FFP_EMIT_D3DCOLOR] = position_d3dcolor;
4041 ops->position[WINED3D_FFP_EMIT_SHORT4] = (wined3d_ffp_attrib_func)gl_info->gl_ops.gl.p_glVertex2sv;
4043 ops->diffuse[WINED3D_FFP_EMIT_FLOAT3] = (wined3d_ffp_attrib_func)gl_info->gl_ops.gl.p_glColor3fv;
4044 ops->diffuse[WINED3D_FFP_EMIT_FLOAT4] = (wined3d_ffp_attrib_func)gl_info->gl_ops.gl.p_glColor4fv;
4045 ops->diffuse[WINED3D_FFP_EMIT_D3DCOLOR] = diffuse_d3dcolor;
4046 ops->diffuse[WINED3D_FFP_EMIT_UBYTE4N] = (wined3d_ffp_attrib_func)gl_info->gl_ops.gl.p_glColor4ubv;
4047 ops->diffuse[WINED3D_FFP_EMIT_SHORT4N] = (wined3d_ffp_attrib_func)gl_info->gl_ops.gl.p_glColor4sv;
4048 ops->diffuse[WINED3D_FFP_EMIT_USHORT4N] = (wined3d_ffp_attrib_func)gl_info->gl_ops.gl.p_glColor4usv;
4050 /* No 4 component entry points here. */
4051 if (gl_info->supported[EXT_SECONDARY_COLOR])
4052 ops->specular[WINED3D_FFP_EMIT_FLOAT3] = (wined3d_ffp_attrib_func)GL_EXTCALL(glSecondaryColor3fvEXT);
4053 else
4054 ops->specular[WINED3D_FFP_EMIT_FLOAT3] = warn_no_specular_func;
4055 if (gl_info->supported[EXT_SECONDARY_COLOR])
4056 ops->specular[WINED3D_FFP_EMIT_D3DCOLOR] = specular_d3dcolor;
4057 else
4058 ops->specular[WINED3D_FFP_EMIT_D3DCOLOR] = warn_no_specular_func;
4060 /* Only 3 component entry points here. Test how others behave. Float4
4061 * normals are used by one of our tests, trying to pass it to the pixel
4062 * shader, which fails on Windows. */
4063 ops->normal[WINED3D_FFP_EMIT_FLOAT3] = (wined3d_ffp_attrib_func)gl_info->gl_ops.gl.p_glNormal3fv;
4064 /* Just ignore the 4th value. */
4065 ops->normal[WINED3D_FFP_EMIT_FLOAT4] = (wined3d_ffp_attrib_func)gl_info->gl_ops.gl.p_glNormal3fv;
4067 ops->texcoord[WINED3D_FFP_EMIT_FLOAT1] = (wined3d_ffp_texcoord_func)gl_info->gl_ops.ext.p_glMultiTexCoord1fvARB;
4068 ops->texcoord[WINED3D_FFP_EMIT_FLOAT2] = (wined3d_ffp_texcoord_func)gl_info->gl_ops.ext.p_glMultiTexCoord2fvARB;
4069 ops->texcoord[WINED3D_FFP_EMIT_FLOAT3] = (wined3d_ffp_texcoord_func)gl_info->gl_ops.ext.p_glMultiTexCoord3fvARB;
4070 ops->texcoord[WINED3D_FFP_EMIT_FLOAT4] = (wined3d_ffp_texcoord_func)gl_info->gl_ops.ext.p_glMultiTexCoord4fvARB;
4071 ops->texcoord[WINED3D_FFP_EMIT_SHORT2] = (wined3d_ffp_texcoord_func)gl_info->gl_ops.ext.p_glMultiTexCoord2svARB;
4072 ops->texcoord[WINED3D_FFP_EMIT_SHORT4] = (wined3d_ffp_texcoord_func)gl_info->gl_ops.ext.p_glMultiTexCoord4svARB;
4073 if (gl_info->supported[NV_HALF_FLOAT])
4075 /* Not supported by ARB_HALF_FLOAT_VERTEX, so check for NV_HALF_FLOAT. */
4076 ops->texcoord[WINED3D_FFP_EMIT_FLOAT16_2] =
4077 (wined3d_ffp_texcoord_func)gl_info->gl_ops.ext.p_glMultiTexCoord2hvNV;
4078 ops->texcoord[WINED3D_FFP_EMIT_FLOAT16_4] =
4079 (wined3d_ffp_texcoord_func)gl_info->gl_ops.ext.p_glMultiTexCoord4hvNV;
4082 ops->generic[WINED3D_FFP_EMIT_FLOAT1] = (wined3d_generic_attrib_func)gl_info->gl_ops.ext.p_glVertexAttrib1fv;
4083 ops->generic[WINED3D_FFP_EMIT_FLOAT2] = (wined3d_generic_attrib_func)gl_info->gl_ops.ext.p_glVertexAttrib2fv;
4084 ops->generic[WINED3D_FFP_EMIT_FLOAT3] = (wined3d_generic_attrib_func)gl_info->gl_ops.ext.p_glVertexAttrib3fv;
4085 ops->generic[WINED3D_FFP_EMIT_FLOAT4] = (wined3d_generic_attrib_func)gl_info->gl_ops.ext.p_glVertexAttrib4fv;
4086 if (gl_info->supported[ARB_VERTEX_ARRAY_BGRA])
4087 ops->generic[WINED3D_FFP_EMIT_D3DCOLOR] = generic_d3dcolor;
4088 else
4089 ops->generic[WINED3D_FFP_EMIT_D3DCOLOR] =
4090 (wined3d_generic_attrib_func)gl_info->gl_ops.ext.p_glVertexAttrib4Nubv;
4091 ops->generic[WINED3D_FFP_EMIT_UBYTE4] = (wined3d_generic_attrib_func)gl_info->gl_ops.ext.p_glVertexAttrib4ubv;
4092 ops->generic[WINED3D_FFP_EMIT_SHORT2] = (wined3d_generic_attrib_func)gl_info->gl_ops.ext.p_glVertexAttrib2sv;
4093 ops->generic[WINED3D_FFP_EMIT_SHORT4] = (wined3d_generic_attrib_func)gl_info->gl_ops.ext.p_glVertexAttrib4sv;
4094 ops->generic[WINED3D_FFP_EMIT_UBYTE4N] = (wined3d_generic_attrib_func)gl_info->gl_ops.ext.p_glVertexAttrib4Nubv;
4095 ops->generic[WINED3D_FFP_EMIT_SHORT2N] = generic_short2n;
4096 ops->generic[WINED3D_FFP_EMIT_SHORT4N] = (wined3d_generic_attrib_func)gl_info->gl_ops.ext.p_glVertexAttrib4Nsv;
4097 ops->generic[WINED3D_FFP_EMIT_USHORT2N] = generic_ushort2n;
4098 ops->generic[WINED3D_FFP_EMIT_USHORT4N] = (wined3d_generic_attrib_func)gl_info->gl_ops.ext.p_glVertexAttrib4Nusv;
4099 if (gl_info->supported[NV_HALF_FLOAT] && gl_info->supported[NV_VERTEX_PROGRAM])
4101 ops->generic[WINED3D_FFP_EMIT_FLOAT16_2] =
4102 (wined3d_generic_attrib_func)gl_info->gl_ops.ext.p_glVertexAttrib2hvNV;
4103 ops->generic[WINED3D_FFP_EMIT_FLOAT16_4] =
4104 (wined3d_generic_attrib_func)gl_info->gl_ops.ext.p_glVertexAttrib4hvNV;
4106 else
4108 ops->generic[WINED3D_FFP_EMIT_FLOAT16_2] = generic_float16_2;
4109 ops->generic[WINED3D_FFP_EMIT_FLOAT16_4] = generic_float16_4;
4113 static void wined3d_adapter_init_fb_cfgs(struct wined3d_adapter_gl *adapter_gl, HDC dc)
4115 const struct wined3d_gl_info *gl_info = &adapter_gl->a.gl_info;
4116 int i;
4118 if (gl_info->supported[WGL_ARB_PIXEL_FORMAT])
4120 UINT attrib_count = 0;
4121 GLint cfg_count;
4122 int attribs[11];
4123 int values[11];
4124 int attribute;
4126 attribute = WGL_NUMBER_PIXEL_FORMATS_ARB;
4127 GL_EXTCALL(wglGetPixelFormatAttribivARB(dc, 0, 0, 1, &attribute, &cfg_count));
4129 adapter_gl->pixel_formats = heap_calloc(cfg_count, sizeof(*adapter_gl->pixel_formats));
4130 attribs[attrib_count++] = WGL_RED_BITS_ARB;
4131 attribs[attrib_count++] = WGL_GREEN_BITS_ARB;
4132 attribs[attrib_count++] = WGL_BLUE_BITS_ARB;
4133 attribs[attrib_count++] = WGL_ALPHA_BITS_ARB;
4134 attribs[attrib_count++] = WGL_COLOR_BITS_ARB;
4135 attribs[attrib_count++] = WGL_DEPTH_BITS_ARB;
4136 attribs[attrib_count++] = WGL_STENCIL_BITS_ARB;
4137 attribs[attrib_count++] = WGL_DRAW_TO_WINDOW_ARB;
4138 attribs[attrib_count++] = WGL_PIXEL_TYPE_ARB;
4139 attribs[attrib_count++] = WGL_DOUBLE_BUFFER_ARB;
4140 attribs[attrib_count++] = WGL_AUX_BUFFERS_ARB;
4142 for (i = 0, adapter_gl->pixel_format_count = 0; i < cfg_count; ++i)
4144 struct wined3d_pixel_format *cfg = &adapter_gl->pixel_formats[adapter_gl->pixel_format_count];
4145 int format_id = i + 1;
4147 if (!GL_EXTCALL(wglGetPixelFormatAttribivARB(dc, format_id, 0, attrib_count, attribs, values)))
4148 continue;
4150 cfg->iPixelFormat = format_id;
4151 cfg->redSize = values[0];
4152 cfg->greenSize = values[1];
4153 cfg->blueSize = values[2];
4154 cfg->alphaSize = values[3];
4155 cfg->colorSize = values[4];
4156 cfg->depthSize = values[5];
4157 cfg->stencilSize = values[6];
4158 cfg->windowDrawable = values[7];
4159 cfg->iPixelType = values[8];
4160 cfg->doubleBuffer = values[9];
4161 cfg->auxBuffers = values[10];
4163 cfg->numSamples = 0;
4164 /* Check multisample support. */
4165 if (gl_info->supported[ARB_MULTISAMPLE])
4167 int attribs[2] = {WGL_SAMPLE_BUFFERS_ARB, WGL_SAMPLES_ARB};
4168 int values[2];
4170 if (GL_EXTCALL(wglGetPixelFormatAttribivARB(dc, format_id, 0, 2, attribs, values)))
4172 /* values[0] = WGL_SAMPLE_BUFFERS_ARB which tells whether
4173 * multisampling is supported. values[1] = number of
4174 * multisample buffers. */
4175 if (values[0])
4176 cfg->numSamples = values[1];
4180 TRACE("iPixelFormat=%d, iPixelType=%#x, doubleBuffer=%d, RGBA=%d/%d/%d/%d, "
4181 "depth=%d, stencil=%d, samples=%d, windowDrawable=%d\n",
4182 cfg->iPixelFormat, cfg->iPixelType, cfg->doubleBuffer,
4183 cfg->redSize, cfg->greenSize, cfg->blueSize, cfg->alphaSize,
4184 cfg->depthSize, cfg->stencilSize, cfg->numSamples, cfg->windowDrawable);
4186 ++adapter_gl->pixel_format_count;
4189 else
4191 int cfg_count;
4193 cfg_count = DescribePixelFormat(dc, 0, 0, 0);
4194 adapter_gl->pixel_formats = heap_calloc(cfg_count, sizeof(*adapter_gl->pixel_formats));
4196 for (i = 0, adapter_gl->pixel_format_count = 0; i < cfg_count; ++i)
4198 struct wined3d_pixel_format *cfg = &adapter_gl->pixel_formats[adapter_gl->pixel_format_count];
4199 PIXELFORMATDESCRIPTOR pfd;
4200 int format_id = i + 1;
4202 if (!DescribePixelFormat(dc, format_id, sizeof(pfd), &pfd))
4203 continue;
4205 /* We only want HW acceleration using an OpenGL ICD driver.
4206 * PFD_GENERIC_FORMAT = slow OpenGL 1.1 GDI software rendering.
4207 * PFD_GENERIC_ACCELERATED = partial hw acceleration using a MCD
4208 * driver (e.g. 3dfx minigl). */
4209 if (pfd.dwFlags & (PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED))
4211 TRACE("Skipping format %d because it isn't ICD accelerated.\n", format_id);
4212 continue;
4215 cfg->iPixelFormat = format_id;
4216 cfg->redSize = pfd.cRedBits;
4217 cfg->greenSize = pfd.cGreenBits;
4218 cfg->blueSize = pfd.cBlueBits;
4219 cfg->alphaSize = pfd.cAlphaBits;
4220 cfg->colorSize = pfd.cColorBits;
4221 cfg->depthSize = pfd.cDepthBits;
4222 cfg->stencilSize = pfd.cStencilBits;
4223 cfg->windowDrawable = (pfd.dwFlags & PFD_DRAW_TO_WINDOW) ? 1 : 0;
4224 cfg->iPixelType = (pfd.iPixelType == PFD_TYPE_RGBA) ? WGL_TYPE_RGBA_ARB : WGL_TYPE_COLORINDEX_ARB;
4225 cfg->doubleBuffer = (pfd.dwFlags & PFD_DOUBLEBUFFER) ? 1 : 0;
4226 cfg->auxBuffers = pfd.cAuxBuffers;
4227 cfg->numSamples = 0;
4229 TRACE("iPixelFormat=%d, iPixelType=%#x, doubleBuffer=%d, RGBA=%d/%d/%d/%d, "
4230 "depth=%d, stencil=%d, windowDrawable=%d\n",
4231 cfg->iPixelFormat, cfg->iPixelType, cfg->doubleBuffer,
4232 cfg->redSize, cfg->greenSize, cfg->blueSize, cfg->alphaSize,
4233 cfg->depthSize, cfg->stencilSize, cfg->windowDrawable);
4235 ++adapter_gl->pixel_format_count;
4240 static void adapter_gl_destroy(struct wined3d_adapter *adapter)
4242 struct wined3d_adapter_gl *adapter_gl = wined3d_adapter_gl(adapter);
4244 heap_free(adapter_gl->pixel_formats);
4245 wined3d_adapter_cleanup(adapter);
4246 heap_free(adapter_gl);
4249 static HRESULT adapter_gl_create_device(struct wined3d *wined3d, const struct wined3d_adapter *adapter,
4250 enum wined3d_device_type device_type, HWND focus_window, unsigned int flags, BYTE surface_alignment,
4251 const enum wined3d_feature_level *levels, unsigned int level_count,
4252 struct wined3d_device_parent *device_parent, struct wined3d_device **device)
4254 struct wined3d_device_gl *device_gl;
4255 HRESULT hr;
4257 if (!(device_gl = heap_alloc_zero(sizeof(*device_gl))))
4258 return E_OUTOFMEMORY;
4260 device_gl->current_fence_id = 1;
4262 if (FAILED(hr = wined3d_device_init(&device_gl->d, wined3d, adapter->ordinal, device_type, focus_window,
4263 flags, surface_alignment, levels, level_count, adapter->gl_info.supported, device_parent)))
4265 WARN("Failed to initialize device, hr %#x.\n", hr);
4266 heap_free(device_gl);
4267 return hr;
4270 *device = &device_gl->d;
4271 return WINED3D_OK;
4274 static void adapter_gl_destroy_device(struct wined3d_device *device)
4276 struct wined3d_device_gl *device_gl = wined3d_device_gl(device);
4278 wined3d_device_cleanup(&device_gl->d);
4279 heap_free(device_gl);
4282 static struct wined3d_context *adapter_gl_acquire_context(struct wined3d_device *device,
4283 struct wined3d_texture *texture, unsigned int sub_resource_idx)
4285 return wined3d_context_gl_acquire(device, texture, sub_resource_idx);
4288 static void adapter_gl_release_context(struct wined3d_context *context)
4290 return wined3d_context_gl_release(wined3d_context_gl(context));
4293 static void adapter_gl_get_wined3d_caps(const struct wined3d_adapter *adapter, struct wined3d_caps *caps)
4295 const struct wined3d_d3d_info *d3d_info = &adapter->d3d_info;
4296 const struct wined3d_gl_info *gl_info = &adapter->gl_info;
4298 caps->ddraw_caps.dds_caps |= WINEDDSCAPS_BACKBUFFER
4299 | WINEDDSCAPS_COMPLEX
4300 | WINEDDSCAPS_FRONTBUFFER
4301 | WINEDDSCAPS_3DDEVICE
4302 | WINEDDSCAPS_VIDEOMEMORY
4303 | WINEDDSCAPS_OWNDC
4304 | WINEDDSCAPS_LOCALVIDMEM
4305 | WINEDDSCAPS_NONLOCALVIDMEM;
4307 caps->ddraw_caps.caps |= WINEDDCAPS_3D;
4309 if (gl_info->supported[ARB_FRAMEBUFFER_OBJECT] || gl_info->supported[EXT_FRAMEBUFFER_OBJECT])
4310 caps->Caps2 |= WINED3DCAPS2_CANGENMIPMAP;
4312 if (gl_info->supported[WINED3D_GL_BLEND_EQUATION])
4313 caps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_BLENDOP;
4314 if (gl_info->supported[EXT_BLEND_EQUATION_SEPARATE] && gl_info->supported[EXT_BLEND_FUNC_SEPARATE])
4315 caps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_SEPARATEALPHABLEND;
4316 if (gl_info->supported[EXT_DRAW_BUFFERS2])
4317 caps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_INDEPENDENTWRITEMASKS;
4318 if (gl_info->supported[ARB_FRAMEBUFFER_SRGB])
4319 caps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_POSTBLENDSRGBCONVERT;
4320 if (~gl_info->quirks & WINED3D_QUIRK_NO_INDEPENDENT_BIT_DEPTHS)
4321 caps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_MRTINDEPENDENTBITDEPTHS;
4323 if (gl_info->supported[ARB_SAMPLER_OBJECTS] || gl_info->supported[EXT_TEXTURE_LOD_BIAS])
4324 caps->RasterCaps |= WINED3DPRASTERCAPS_MIPMAPLODBIAS;
4326 if (gl_info->supported[ARB_TEXTURE_FILTER_ANISOTROPIC])
4328 caps->RasterCaps |= WINED3DPRASTERCAPS_ANISOTROPY;
4330 caps->TextureFilterCaps |= WINED3DPTFILTERCAPS_MAGFANISOTROPIC
4331 | WINED3DPTFILTERCAPS_MINFANISOTROPIC;
4334 if (gl_info->supported[ARB_BLEND_FUNC_EXTENDED])
4335 caps->DestBlendCaps |= WINED3DPBLENDCAPS_SRCALPHASAT;
4337 if (gl_info->supported[EXT_BLEND_COLOR])
4339 caps->SrcBlendCaps |= WINED3DPBLENDCAPS_BLENDFACTOR;
4340 caps->DestBlendCaps |= WINED3DPBLENDCAPS_BLENDFACTOR;
4343 if (gl_info->supported[EXT_TEXTURE3D])
4345 caps->TextureCaps |= WINED3DPTEXTURECAPS_VOLUMEMAP
4346 | WINED3DPTEXTURECAPS_MIPVOLUMEMAP;
4347 if (!d3d_info->texture_npot)
4348 caps->TextureCaps |= WINED3DPTEXTURECAPS_VOLUMEMAP_POW2;
4350 caps->VolumeTextureFilterCaps |= WINED3DPTFILTERCAPS_MAGFLINEAR
4351 | WINED3DPTFILTERCAPS_MAGFPOINT
4352 | WINED3DPTFILTERCAPS_MINFLINEAR
4353 | WINED3DPTFILTERCAPS_MINFPOINT
4354 | WINED3DPTFILTERCAPS_MIPFLINEAR
4355 | WINED3DPTFILTERCAPS_MIPFPOINT
4356 | WINED3DPTFILTERCAPS_LINEAR
4357 | WINED3DPTFILTERCAPS_LINEARMIPLINEAR
4358 | WINED3DPTFILTERCAPS_LINEARMIPNEAREST
4359 | WINED3DPTFILTERCAPS_MIPLINEAR
4360 | WINED3DPTFILTERCAPS_MIPNEAREST
4361 | WINED3DPTFILTERCAPS_NEAREST;
4363 caps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_INDEPENDENTUV
4364 | WINED3DPTADDRESSCAPS_CLAMP
4365 | WINED3DPTADDRESSCAPS_WRAP;
4367 if (gl_info->supported[ARB_TEXTURE_BORDER_CLAMP])
4369 caps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_BORDER;
4371 if (gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT])
4373 caps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRROR;
4375 if (gl_info->supported[ARB_TEXTURE_MIRROR_CLAMP_TO_EDGE])
4377 caps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRRORONCE;
4380 caps->MaxVolumeExtent = gl_info->limits.texture3d_size;
4383 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
4385 caps->TextureCaps |= WINED3DPTEXTURECAPS_CUBEMAP
4386 | WINED3DPTEXTURECAPS_MIPCUBEMAP;
4387 if (!d3d_info->texture_npot)
4388 caps->TextureCaps |= WINED3DPTEXTURECAPS_CUBEMAP_POW2;
4390 caps->CubeTextureFilterCaps |= WINED3DPTFILTERCAPS_MAGFLINEAR
4391 | WINED3DPTFILTERCAPS_MAGFPOINT
4392 | WINED3DPTFILTERCAPS_MINFLINEAR
4393 | WINED3DPTFILTERCAPS_MINFPOINT
4394 | WINED3DPTFILTERCAPS_MIPFLINEAR
4395 | WINED3DPTFILTERCAPS_MIPFPOINT
4396 | WINED3DPTFILTERCAPS_LINEAR
4397 | WINED3DPTFILTERCAPS_LINEARMIPLINEAR
4398 | WINED3DPTFILTERCAPS_LINEARMIPNEAREST
4399 | WINED3DPTFILTERCAPS_MIPLINEAR
4400 | WINED3DPTFILTERCAPS_MIPNEAREST
4401 | WINED3DPTFILTERCAPS_NEAREST;
4403 if (gl_info->supported[ARB_TEXTURE_FILTER_ANISOTROPIC])
4405 caps->CubeTextureFilterCaps |= WINED3DPTFILTERCAPS_MAGFANISOTROPIC
4406 | WINED3DPTFILTERCAPS_MINFANISOTROPIC;
4410 if (gl_info->supported[ARB_TEXTURE_BORDER_CLAMP])
4412 caps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_BORDER;
4414 if (gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT])
4416 caps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRROR;
4418 if (gl_info->supported[ARB_TEXTURE_MIRROR_CLAMP_TO_EDGE])
4420 caps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRRORONCE;
4423 if (gl_info->supported[EXT_STENCIL_WRAP])
4425 caps->StencilCaps |= WINED3DSTENCILCAPS_DECR
4426 | WINED3DSTENCILCAPS_INCR;
4429 if (gl_info->supported[WINED3D_GL_VERSION_2_0]
4430 || gl_info->supported[EXT_STENCIL_TWO_SIDE]
4431 || gl_info->supported[ATI_SEPARATE_STENCIL])
4433 caps->StencilCaps |= WINED3DSTENCILCAPS_TWOSIDED;
4436 caps->MaxAnisotropy = gl_info->limits.anisotropy;
4438 if (caps->VertexShaderVersion >= 3)
4440 caps->MaxVertexShader30InstructionSlots
4441 = max(caps->MaxVertexShader30InstructionSlots, gl_info->limits.arb_vs_instructions);
4443 if (caps->VertexShaderVersion >= 2)
4445 caps->VS20Caps.temp_count = max(caps->VS20Caps.temp_count, gl_info->limits.arb_vs_temps);
4447 if (gl_info->supported[ARB_HALF_FLOAT_VERTEX])
4448 caps->DeclTypes |= WINED3DDTCAPS_FLOAT16_2 | WINED3DDTCAPS_FLOAT16_4;
4451 if (caps->PixelShaderVersion >= 3)
4453 caps->MaxPixelShader30InstructionSlots
4454 = max(caps->MaxPixelShader30InstructionSlots, gl_info->limits.arb_ps_instructions);
4456 if (caps->PixelShaderVersion >= 2)
4458 caps->PS20Caps.temp_count = max(caps->PS20Caps.temp_count, gl_info->limits.arb_ps_temps);
4462 static BOOL wined3d_check_pixel_format_color(const struct wined3d_pixel_format *cfg,
4463 const struct wined3d_format *format)
4465 /* Float formats need FBOs. If FBOs are used this function isn't called */
4466 if (format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_FLOAT)
4467 return FALSE;
4469 /* Probably a RGBA_float or color index mode. */
4470 if (cfg->iPixelType != WGL_TYPE_RGBA_ARB)
4471 return FALSE;
4473 if (cfg->redSize < format->red_size
4474 || cfg->greenSize < format->green_size
4475 || cfg->blueSize < format->blue_size
4476 || cfg->alphaSize < format->alpha_size)
4477 return FALSE;
4479 return TRUE;
4482 static BOOL wined3d_check_pixel_format_depth(const struct wined3d_pixel_format *cfg,
4483 const struct wined3d_format *format)
4485 BOOL lockable = FALSE;
4487 /* Float formats need FBOs. If FBOs are used this function isn't called */
4488 if (format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_FLOAT)
4489 return FALSE;
4491 if ((format->id == WINED3DFMT_D16_LOCKABLE) || (format->id == WINED3DFMT_D32_FLOAT))
4492 lockable = TRUE;
4494 /* On some modern cards like the Geforce8/9, GLX doesn't offer some
4495 * depth/stencil formats which D3D9 reports. We can safely report
4496 * "compatible" formats (e.g. D24 can be used for D16) as long as we
4497 * aren't dealing with a lockable format. This also helps D3D <= 7 as they
4498 * expect D16 which isn't offered without this on Geforce8 cards. */
4499 if (!(cfg->depthSize == format->depth_size || (!lockable && cfg->depthSize > format->depth_size)))
4500 return FALSE;
4502 /* Some cards like Intel i915 ones only offer D24S8 but lots of games also
4503 * need a format without stencil. We can allow a mismatch if the format
4504 * doesn't have any stencil bits. If it does have stencil bits the size
4505 * must match, or stencil wrapping would break. */
4506 if (format->stencil_size && cfg->stencilSize != format->stencil_size)
4507 return FALSE;
4509 return TRUE;
4512 static BOOL adapter_gl_check_format(const struct wined3d_adapter *adapter,
4513 const struct wined3d_format *adapter_format, const struct wined3d_format *rt_format,
4514 const struct wined3d_format *ds_format)
4516 const struct wined3d_adapter_gl *adapter_gl = wined3d_adapter_gl_const(adapter);
4517 unsigned int i;
4519 if (wined3d_settings.offscreen_rendering_mode != ORM_BACKBUFFER)
4520 return TRUE;
4522 if (adapter_format && rt_format)
4524 /* In backbuffer mode the front and backbuffer share the same WGL
4525 * pixelformat. The format must match in RGB, alpha is allowed to be
4526 * different. (Only the backbuffer can have alpha.) */
4527 if (adapter_format->red_size != rt_format->red_size
4528 || adapter_format->green_size != rt_format->green_size
4529 || adapter_format->blue_size != rt_format->blue_size)
4531 TRACE("Render target format %s doesn't match with adapter format %s.\n",
4532 debug_d3dformat(rt_format->id), debug_d3dformat(adapter_format->id));
4533 return FALSE;
4537 for (i = 0; i < adapter_gl->pixel_format_count; ++i)
4539 const struct wined3d_pixel_format *cfg = &adapter_gl->pixel_formats[i];
4541 /* Check if there is a WGL pixel format matching the requirements, the format should also be window
4542 * drawable (not offscreen; e.g. Nvidia offers R5G6B5 for pbuffers even when X is running at 24bit) */
4543 if (adapter_format && rt_format && !cfg->windowDrawable)
4544 continue;
4546 if ((!adapter_format || wined3d_check_pixel_format_color(cfg, adapter_format))
4547 && (!rt_format || wined3d_check_pixel_format_color(cfg, rt_format))
4548 && (!ds_format || wined3d_check_pixel_format_depth(cfg, ds_format)))
4550 TRACE("Pixel format %d is compatible.\n", cfg->iPixelFormat);
4551 return TRUE;
4555 return FALSE;
4558 static HRESULT adapter_gl_init_3d(struct wined3d_device *device)
4560 TRACE("device %p.\n", device);
4562 wined3d_cs_init_object(device->cs, wined3d_device_create_primary_opengl_context_cs, device);
4563 wined3d_cs_finish(device->cs, WINED3D_CS_QUEUE_DEFAULT);
4564 if (!wined3d_swapchain_gl(device->swapchains[0])->context_count)
4565 return E_FAIL;
4567 return WINED3D_OK;
4570 static void adapter_gl_uninit_3d(struct wined3d_device *device)
4572 TRACE("device %p.\n", device);
4574 wined3d_cs_destroy_object(device->cs, wined3d_device_delete_opengl_contexts_cs, device);
4575 wined3d_cs_finish(device->cs, WINED3D_CS_QUEUE_DEFAULT);
4578 static void *adapter_gl_map_bo_address(struct wined3d_context *context,
4579 const struct wined3d_bo_address *data, size_t size, uint32_t map_flags)
4581 return wined3d_context_gl_map_bo_address(wined3d_context_gl(context), data, size, map_flags);
4584 static void adapter_gl_unmap_bo_address(struct wined3d_context *context,
4585 const struct wined3d_bo_address *data, unsigned int range_count, const struct wined3d_range *ranges)
4587 wined3d_context_gl_unmap_bo_address(wined3d_context_gl(context), data, range_count, ranges);
4590 static void adapter_gl_copy_bo_address(struct wined3d_context *context,
4591 const struct wined3d_bo_address *dst, const struct wined3d_bo_address *src, size_t size)
4593 wined3d_context_gl_copy_bo_address(wined3d_context_gl(context), dst, src, size);
4596 static HRESULT adapter_gl_create_swapchain(struct wined3d_device *device,
4597 struct wined3d_swapchain_desc *desc, struct wined3d_swapchain_state_parent *state_parent,
4598 void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_swapchain **swapchain)
4600 struct wined3d_swapchain_gl *swapchain_gl;
4601 HRESULT hr;
4603 TRACE("device %p, desc %p, state_parent %p, parent %p, parent_ops %p, swapchain %p.\n",
4604 device, desc, state_parent, parent, parent_ops, swapchain);
4606 if (!(swapchain_gl = heap_alloc_zero(sizeof(*swapchain_gl))))
4607 return E_OUTOFMEMORY;
4609 if (FAILED(hr = wined3d_swapchain_gl_init(swapchain_gl, device, desc, state_parent, parent, parent_ops)))
4611 WARN("Failed to initialise swapchain, hr %#x.\n", hr);
4612 heap_free(swapchain_gl);
4613 return hr;
4616 TRACE("Created swapchain %p.\n", swapchain_gl);
4617 *swapchain = &swapchain_gl->s;
4619 return hr;
4622 static void adapter_gl_destroy_swapchain(struct wined3d_swapchain *swapchain)
4624 struct wined3d_swapchain_gl *swapchain_gl = wined3d_swapchain_gl(swapchain);
4626 wined3d_swapchain_gl_cleanup(swapchain_gl);
4627 heap_free(swapchain_gl);
4630 static HRESULT adapter_gl_create_buffer(struct wined3d_device *device,
4631 const struct wined3d_buffer_desc *desc, const struct wined3d_sub_resource_data *data,
4632 void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_buffer **buffer)
4634 struct wined3d_buffer_gl *buffer_gl;
4635 HRESULT hr;
4637 TRACE("device %p, desc %p, data %p, parent %p, parent_ops %p, buffer %p.\n",
4638 device, desc, data, parent, parent_ops, buffer);
4640 if (!(buffer_gl = heap_alloc_zero(sizeof(*buffer_gl))))
4641 return E_OUTOFMEMORY;
4643 if (FAILED(hr = wined3d_buffer_gl_init(buffer_gl, device, desc, data, parent, parent_ops)))
4645 WARN("Failed to initialise buffer, hr %#x.\n", hr);
4646 heap_free(buffer_gl);
4647 return hr;
4650 TRACE("Created buffer %p.\n", buffer_gl);
4651 *buffer = &buffer_gl->b;
4653 return hr;
4656 static void adapter_gl_destroy_buffer(struct wined3d_buffer *buffer)
4658 struct wined3d_buffer_gl *buffer_gl = wined3d_buffer_gl(buffer);
4659 struct wined3d_device *device = buffer_gl->b.resource.device;
4660 unsigned int swapchain_count = device->swapchain_count;
4662 TRACE("buffer_gl %p.\n", buffer_gl);
4664 /* Take a reference to the device, in case releasing the buffer would
4665 * cause the device to be destroyed. However, swapchain resources don't
4666 * take a reference to the device, and we wouldn't want to increment the
4667 * refcount on a device that's in the process of being destroyed. */
4668 if (swapchain_count)
4669 wined3d_device_incref(device);
4670 wined3d_buffer_cleanup(&buffer_gl->b);
4671 wined3d_cs_destroy_object(device->cs, heap_free, buffer_gl);
4672 if (swapchain_count)
4673 wined3d_device_decref(device);
4676 static HRESULT adapter_gl_create_texture(struct wined3d_device *device,
4677 const struct wined3d_resource_desc *desc, unsigned int layer_count, unsigned int level_count,
4678 uint32_t flags, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_texture **texture)
4680 struct wined3d_texture_gl *texture_gl;
4681 HRESULT hr;
4683 TRACE("device %p, desc %p, layer_count %u, level_count %u, flags %#x, parent %p, parent_ops %p, texture %p.\n",
4684 device, desc, layer_count, level_count, flags, parent, parent_ops, texture);
4686 if (!(texture_gl = wined3d_texture_allocate_object_memory(sizeof(*texture_gl), level_count, layer_count)))
4687 return E_OUTOFMEMORY;
4689 if (FAILED(hr = wined3d_texture_gl_init(texture_gl, device, desc,
4690 layer_count, level_count, flags, parent, parent_ops)))
4692 WARN("Failed to initialise texture, hr %#x.\n", hr);
4693 heap_free(texture_gl);
4694 return hr;
4697 TRACE("Created texture %p.\n", texture_gl);
4698 *texture = &texture_gl->t;
4700 return hr;
4703 static void adapter_gl_destroy_texture(struct wined3d_texture *texture)
4705 struct wined3d_texture_gl *texture_gl = wined3d_texture_gl(texture);
4706 struct wined3d_device *device = texture_gl->t.resource.device;
4707 unsigned int swapchain_count = device->swapchain_count;
4709 TRACE("texture_gl %p.\n", texture_gl);
4711 /* Take a reference to the device, in case releasing the texture would
4712 * cause the device to be destroyed. However, swapchain resources don't
4713 * take a reference to the device, and we wouldn't want to increment the
4714 * refcount on a device that's in the process of being destroyed. */
4715 if (swapchain_count)
4716 wined3d_device_incref(device);
4718 wined3d_texture_sub_resources_destroyed(texture);
4719 texture->resource.parent_ops->wined3d_object_destroyed(texture->resource.parent);
4721 wined3d_texture_cleanup(&texture_gl->t);
4722 wined3d_cs_destroy_object(device->cs, heap_free, texture_gl);
4724 if (swapchain_count)
4725 wined3d_device_decref(device);
4728 static HRESULT adapter_gl_create_rendertarget_view(const struct wined3d_view_desc *desc,
4729 struct wined3d_resource *resource, void *parent, const struct wined3d_parent_ops *parent_ops,
4730 struct wined3d_rendertarget_view **view)
4732 struct wined3d_rendertarget_view_gl *view_gl;
4733 HRESULT hr;
4735 TRACE("desc %s, resource %p, parent %p, parent_ops %p, view %p.\n",
4736 wined3d_debug_view_desc(desc, resource), resource, parent, parent_ops, view);
4738 if (!(view_gl = heap_alloc_zero(sizeof(*view_gl))))
4739 return E_OUTOFMEMORY;
4741 if (FAILED(hr = wined3d_rendertarget_view_gl_init(view_gl, desc, resource, parent, parent_ops)))
4743 WARN("Failed to initialise view, hr %#x.\n", hr);
4744 heap_free(view_gl);
4745 return hr;
4748 TRACE("Created render target view %p.\n", view_gl);
4749 *view = &view_gl->v;
4751 return hr;
4754 struct wined3d_view_gl_destroy_ctx
4756 struct wined3d_device *device;
4757 const struct wined3d_gl_view *gl_view;
4758 struct wined3d_bo_user *bo_user;
4759 struct wined3d_bo_gl *counter_bo;
4760 void *object;
4761 struct wined3d_view_gl_destroy_ctx *free;
4764 static void wined3d_view_gl_destroy_object(void *object)
4766 struct wined3d_view_gl_destroy_ctx *ctx = object;
4767 const struct wined3d_gl_info *gl_info;
4768 struct wined3d_context *context;
4769 struct wined3d_device *device;
4770 GLuint counter_id;
4772 TRACE("ctx %p.\n", ctx);
4774 device = ctx->device;
4776 counter_id = ctx->counter_bo ? ctx->counter_bo->id : 0;
4777 if (ctx->gl_view->name || counter_id)
4779 context = context_acquire(device, NULL, 0);
4780 gl_info = wined3d_context_gl(context)->gl_info;
4781 if (ctx->gl_view->name)
4783 context_gl_resource_released(device, ctx->gl_view->name, FALSE);
4784 gl_info->gl_ops.gl.p_glDeleteTextures(1, &ctx->gl_view->name);
4786 if (counter_id)
4787 wined3d_context_gl_destroy_bo(wined3d_context_gl(context), ctx->counter_bo);
4788 checkGLcall("delete resources");
4789 context_release(context);
4791 if (ctx->bo_user)
4792 list_remove(&ctx->bo_user->entry);
4794 heap_free(ctx->object);
4795 heap_free(ctx->free);
4798 static void wined3d_view_gl_destroy(struct wined3d_device *device, const struct wined3d_gl_view *gl_view,
4799 struct wined3d_bo_user *bo_user, struct wined3d_bo_gl *counter_bo, void *object)
4801 struct wined3d_view_gl_destroy_ctx *ctx, c;
4803 if (!(ctx = heap_alloc(sizeof(*ctx))))
4804 ctx = &c;
4805 ctx->device = device;
4806 ctx->gl_view = gl_view;
4807 ctx->bo_user = bo_user;
4808 ctx->counter_bo = counter_bo;
4809 ctx->object = object;
4810 ctx->free = ctx != &c ? ctx : NULL;
4812 wined3d_cs_destroy_object(device->cs, wined3d_view_gl_destroy_object, ctx);
4813 if (ctx == &c)
4814 wined3d_cs_finish(device->cs, WINED3D_CS_QUEUE_DEFAULT);
4817 static void adapter_gl_destroy_rendertarget_view(struct wined3d_rendertarget_view *view)
4819 struct wined3d_rendertarget_view_gl *view_gl = wined3d_rendertarget_view_gl(view);
4820 struct wined3d_resource *resource = view_gl->v.resource;
4822 TRACE("view_gl %p.\n", view_gl);
4824 /* Take a reference to the resource, in case releasing the resource
4825 * would cause the device to be destroyed. */
4826 wined3d_resource_incref(resource);
4827 wined3d_rendertarget_view_cleanup(&view_gl->v);
4828 wined3d_view_gl_destroy(resource->device, &view_gl->gl_view, NULL, NULL, view_gl);
4829 wined3d_resource_decref(resource);
4832 static HRESULT adapter_gl_create_shader_resource_view(const struct wined3d_view_desc *desc,
4833 struct wined3d_resource *resource, void *parent, const struct wined3d_parent_ops *parent_ops,
4834 struct wined3d_shader_resource_view **view)
4836 struct wined3d_shader_resource_view_gl *view_gl;
4837 HRESULT hr;
4839 TRACE("desc %s, resource %p, parent %p, parent_ops %p, view %p.\n",
4840 wined3d_debug_view_desc(desc, resource), resource, parent, parent_ops, view);
4842 if (!(view_gl = heap_alloc_zero(sizeof(*view_gl))))
4843 return E_OUTOFMEMORY;
4845 if (FAILED(hr = wined3d_shader_resource_view_gl_init(view_gl, desc, resource, parent, parent_ops)))
4847 WARN("Failed to initialise view, hr %#x.\n", hr);
4848 heap_free(view_gl);
4849 return hr;
4852 TRACE("Created shader resource view %p.\n", view_gl);
4853 *view = &view_gl->v;
4855 return hr;
4858 static void adapter_gl_destroy_shader_resource_view(struct wined3d_shader_resource_view *view)
4860 struct wined3d_shader_resource_view_gl *view_gl = wined3d_shader_resource_view_gl(view);
4861 struct wined3d_resource *resource = view_gl->v.resource;
4863 TRACE("view_gl %p.\n", view_gl);
4865 /* Take a reference to the resource. There are two reasons for this:
4866 * - Releasing the resource could in turn cause the device to be
4867 * destroyed, but we still need the device for
4868 * wined3d_view_vk_destroy().
4869 * - We shouldn't free buffer resources until after we've removed the
4870 * view from its bo_user list. */
4871 wined3d_resource_incref(resource);
4872 wined3d_shader_resource_view_cleanup(&view_gl->v);
4873 wined3d_view_gl_destroy(resource->device, &view_gl->gl_view, &view_gl->bo_user, NULL, view_gl);
4874 wined3d_resource_decref(resource);
4877 static HRESULT adapter_gl_create_unordered_access_view(const struct wined3d_view_desc *desc,
4878 struct wined3d_resource *resource, void *parent, const struct wined3d_parent_ops *parent_ops,
4879 struct wined3d_unordered_access_view **view)
4881 struct wined3d_unordered_access_view_gl *view_gl;
4882 HRESULT hr;
4884 TRACE("desc %s, resource %p, parent %p, parent_ops %p, view %p.\n",
4885 wined3d_debug_view_desc(desc, resource), resource, parent, parent_ops, view);
4887 if (!(view_gl = heap_alloc_zero(sizeof(*view_gl))))
4888 return E_OUTOFMEMORY;
4890 if (FAILED(hr = wined3d_unordered_access_view_gl_init(view_gl, desc, resource, parent, parent_ops)))
4892 WARN("Failed to initialise view, hr %#x.\n", hr);
4893 heap_free(view_gl);
4894 return hr;
4897 TRACE("Created unordered access view %p.\n", view_gl);
4898 *view = &view_gl->v;
4900 return hr;
4903 static void adapter_gl_destroy_unordered_access_view(struct wined3d_unordered_access_view *view)
4905 struct wined3d_unordered_access_view_gl *view_gl = wined3d_unordered_access_view_gl(view);
4906 struct wined3d_resource *resource = view_gl->v.resource;
4908 TRACE("view_gl %p.\n", view_gl);
4910 /* Take a reference to the resource. There are two reasons for this:
4911 * - Releasing the resource could in turn cause the device to be
4912 * destroyed, but we still need the device for
4913 * wined3d_view_vk_destroy().
4914 * - We shouldn't free buffer resources until after we've removed the
4915 * view from its bo_user list. */
4916 wined3d_resource_incref(resource);
4917 wined3d_unordered_access_view_cleanup(&view_gl->v);
4918 wined3d_view_gl_destroy(resource->device, &view_gl->gl_view, &view_gl->bo_user, &view_gl->counter_bo, view_gl);
4919 wined3d_resource_decref(resource);
4922 static HRESULT adapter_gl_create_sampler(struct wined3d_device *device, const struct wined3d_sampler_desc *desc,
4923 void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_sampler **sampler)
4925 struct wined3d_sampler_gl *sampler_gl;
4927 TRACE("device %p, desc %p, parent %p, parent_ops %p, sampler %p.\n",
4928 device, desc, parent, parent_ops, sampler);
4930 if (!(sampler_gl = heap_alloc_zero(sizeof(*sampler_gl))))
4931 return E_OUTOFMEMORY;
4933 wined3d_sampler_gl_init(sampler_gl, device, desc, parent, parent_ops);
4935 TRACE("Created sampler %p.\n", sampler_gl);
4936 *sampler = &sampler_gl->s;
4938 return WINED3D_OK;
4941 static void wined3d_sampler_gl_destroy_object(void *object)
4943 struct wined3d_sampler_gl *sampler_gl = object;
4944 const struct wined3d_gl_info *gl_info;
4945 struct wined3d_context *context;
4947 TRACE("sampler_gl %p.\n", sampler_gl);
4949 if (sampler_gl->name)
4951 context = context_acquire(sampler_gl->s.device, NULL, 0);
4952 gl_info = wined3d_context_gl(context)->gl_info;
4953 GL_EXTCALL(glDeleteSamplers(1, &sampler_gl->name));
4954 context_release(context);
4957 heap_free(sampler_gl);
4960 static void adapter_gl_destroy_sampler(struct wined3d_sampler *sampler)
4962 struct wined3d_sampler_gl *sampler_gl = wined3d_sampler_gl(sampler);
4964 TRACE("sampler_gl %p.\n", sampler_gl);
4966 wined3d_cs_destroy_object(sampler->device->cs, wined3d_sampler_gl_destroy_object, sampler_gl);
4969 static HRESULT adapter_gl_create_query(struct wined3d_device *device, enum wined3d_query_type type,
4970 void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_query **query)
4972 TRACE("device %p, type %#x, parent %p, parent_ops %p, query %p.\n",
4973 device, type, parent, parent_ops, query);
4975 return wined3d_query_gl_create(device, type, parent, parent_ops, query);
4978 static void wined3d_query_gl_destroy_object(void *object)
4980 struct wined3d_query *query = object;
4982 TRACE("query %p.\n", query);
4984 if (query->buffer_object)
4986 struct wined3d_context *context;
4988 context = context_acquire(query->device, NULL, 0);
4989 wined3d_query_gl_destroy_buffer_object(wined3d_context_gl(context), query);
4990 context_release(context);
4993 /* Queries are specific to the GL context that created them. Not
4994 * deleting the query will obviously leak it, but that's still better
4995 * than potentially deleting a different query with the same id in this
4996 * context, and (still) leaking the actual query. */
4997 query->query_ops->query_destroy(query);
5000 static void adapter_gl_destroy_query(struct wined3d_query *query)
5002 TRACE("query %p.\n", query);
5004 wined3d_cs_destroy_object(query->device->cs, wined3d_query_gl_destroy_object, query);
5007 static void adapter_gl_flush_context(struct wined3d_context *context)
5009 struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
5011 TRACE("context_gl %p.\n", context_gl);
5013 if (context_gl->valid)
5014 context_gl->gl_info->gl_ops.gl.p_glFlush();
5017 static void adapter_gl_clear_uav(struct wined3d_context *context,
5018 struct wined3d_unordered_access_view *view, const struct wined3d_uvec4 *clear_value)
5020 TRACE("context %p, view %p, clear_value %s.\n", context, view, debug_uvec4(clear_value));
5022 wined3d_unordered_access_view_gl_clear_uint(wined3d_unordered_access_view_gl(view),
5023 clear_value, wined3d_context_gl(context));
5026 static void adapter_gl_generate_mipmap(struct wined3d_context *context, struct wined3d_shader_resource_view *view)
5028 TRACE("context %p, view %p.\n", context, view);
5030 wined3d_shader_resource_view_gl_generate_mipmap(wined3d_shader_resource_view_gl(view),
5031 wined3d_context_gl(context));
5034 static const struct wined3d_adapter_ops wined3d_adapter_gl_ops =
5036 .adapter_destroy = adapter_gl_destroy,
5037 .adapter_create_device = adapter_gl_create_device,
5038 .adapter_destroy_device = adapter_gl_destroy_device,
5039 .adapter_acquire_context = adapter_gl_acquire_context,
5040 .adapter_release_context = adapter_gl_release_context,
5041 .adapter_get_wined3d_caps = adapter_gl_get_wined3d_caps,
5042 .adapter_check_format = adapter_gl_check_format,
5043 .adapter_init_3d = adapter_gl_init_3d,
5044 .adapter_uninit_3d = adapter_gl_uninit_3d,
5045 .adapter_map_bo_address = adapter_gl_map_bo_address,
5046 .adapter_unmap_bo_address = adapter_gl_unmap_bo_address,
5047 .adapter_copy_bo_address = adapter_gl_copy_bo_address,
5048 .adapter_create_swapchain = adapter_gl_create_swapchain,
5049 .adapter_destroy_swapchain = adapter_gl_destroy_swapchain,
5050 .adapter_create_buffer = adapter_gl_create_buffer,
5051 .adapter_destroy_buffer = adapter_gl_destroy_buffer,
5052 .adapter_create_texture = adapter_gl_create_texture,
5053 .adapter_destroy_texture = adapter_gl_destroy_texture,
5054 .adapter_create_rendertarget_view = adapter_gl_create_rendertarget_view,
5055 .adapter_destroy_rendertarget_view = adapter_gl_destroy_rendertarget_view,
5056 .adapter_create_shader_resource_view = adapter_gl_create_shader_resource_view,
5057 .adapter_destroy_shader_resource_view = adapter_gl_destroy_shader_resource_view,
5058 .adapter_create_unordered_access_view = adapter_gl_create_unordered_access_view,
5059 .adapter_destroy_unordered_access_view = adapter_gl_destroy_unordered_access_view,
5060 .adapter_create_sampler = adapter_gl_create_sampler,
5061 .adapter_destroy_sampler = adapter_gl_destroy_sampler,
5062 .adapter_create_query = adapter_gl_create_query,
5063 .adapter_destroy_query = adapter_gl_destroy_query,
5064 .adapter_flush_context = adapter_gl_flush_context,
5065 .adapter_draw_primitive = draw_primitive,
5066 .adapter_dispatch_compute = dispatch_compute,
5067 .adapter_clear_uav = adapter_gl_clear_uav,
5068 .adapter_generate_mipmap = adapter_gl_generate_mipmap,
5071 static void wined3d_adapter_gl_init_d3d_info(struct wined3d_adapter_gl *adapter_gl, uint32_t wined3d_creation_flags)
5073 const struct wined3d_gl_info *gl_info = &adapter_gl->a.gl_info;
5074 struct wined3d_d3d_info *d3d_info = &adapter_gl->a.d3d_info;
5075 struct wined3d_vertex_caps vertex_caps;
5076 struct fragment_caps fragment_caps;
5077 struct shader_caps shader_caps;
5078 GLfloat f[2];
5080 adapter_gl->a.shader_backend->shader_get_caps(&adapter_gl->a, &shader_caps);
5081 adapter_gl->a.vertex_pipe->vp_get_caps(&adapter_gl->a, &vertex_caps);
5082 adapter_gl->a.misc_state_template = misc_state_template_gl;
5083 adapter_gl->a.fragment_pipe->get_caps(&adapter_gl->a, &fragment_caps);
5085 d3d_info->limits.vs_version = shader_caps.vs_version;
5086 d3d_info->limits.hs_version = shader_caps.hs_version;
5087 d3d_info->limits.ds_version = shader_caps.ds_version;
5088 d3d_info->limits.gs_version = shader_caps.gs_version;
5089 d3d_info->limits.ps_version = shader_caps.ps_version;
5090 d3d_info->limits.cs_version = shader_caps.cs_version;
5091 d3d_info->limits.vs_uniform_count = shader_caps.vs_uniform_count;
5092 d3d_info->limits.ps_uniform_count = shader_caps.ps_uniform_count;
5093 d3d_info->limits.varying_count = shader_caps.varying_count;
5094 d3d_info->limits.ffp_textures = fragment_caps.MaxSimultaneousTextures;
5095 d3d_info->limits.ffp_blend_stages = fragment_caps.MaxTextureBlendStages;
5096 TRACE("Max texture stages: %u.\n", d3d_info->limits.ffp_blend_stages);
5097 d3d_info->limits.ffp_vertex_blend_matrices = vertex_caps.max_vertex_blend_matrices;
5098 d3d_info->limits.active_light_count = vertex_caps.max_active_lights;
5100 d3d_info->limits.max_rt_count = gl_info->limits.buffers;
5101 d3d_info->limits.max_clip_distances = gl_info->limits.user_clip_distances;
5102 d3d_info->limits.texture_size = gl_info->limits.texture_size;
5104 gl_info->gl_ops.gl.p_glGetFloatv(gl_info->supported[WINED3D_GL_LEGACY_CONTEXT]
5105 ? GL_ALIASED_POINT_SIZE_RANGE : GL_POINT_SIZE_RANGE, f);
5106 d3d_info->limits.pointsize_max = f[1];
5107 TRACE("Maximum point size support - max point size %.8e.\n", f[1]);
5109 d3d_info->wined3d_creation_flags = wined3d_creation_flags;
5110 d3d_info->xyzrhw = vertex_caps.xyzrhw;
5111 d3d_info->emulated_flatshading = vertex_caps.emulated_flatshading;
5112 d3d_info->ffp_generic_attributes = vertex_caps.ffp_generic_attributes;
5113 d3d_info->ffp_alpha_test = !!gl_info->supported[WINED3D_GL_LEGACY_CONTEXT];
5114 d3d_info->vs_clipping = shader_caps.wined3d_caps & WINED3D_SHADER_CAP_VS_CLIPPING;
5115 d3d_info->shader_color_key = !!(fragment_caps.wined3d_caps & WINED3D_FRAGMENT_CAP_COLOR_KEY);
5116 d3d_info->shader_double_precision = !!(shader_caps.wined3d_caps & WINED3D_SHADER_CAP_DOUBLE_PRECISION);
5117 d3d_info->shader_output_interpolation = !!(shader_caps.wined3d_caps & WINED3D_SHADER_CAP_OUTPUT_INTERPOLATION);
5118 d3d_info->viewport_array_index_any_shader = !!gl_info->supported[ARB_SHADER_VIEWPORT_LAYER_ARRAY];
5119 d3d_info->texture_npot = !!gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO];
5120 d3d_info->texture_npot_conditional = gl_info->supported[WINED3D_GL_NORMALIZED_TEXRECT]
5121 || gl_info->supported[ARB_TEXTURE_RECTANGLE];
5122 d3d_info->draw_base_vertex_offset = !!gl_info->supported[ARB_DRAW_ELEMENTS_BASE_VERTEX];
5123 d3d_info->vertex_bgra = !!gl_info->supported[ARB_VERTEX_ARRAY_BGRA];
5124 d3d_info->texture_swizzle = !!gl_info->supported[ARB_TEXTURE_SWIZZLE];
5125 d3d_info->srgb_read_control = !!gl_info->supported[EXT_TEXTURE_SRGB_DECODE];
5126 d3d_info->srgb_write_control = !!gl_info->supported[ARB_FRAMEBUFFER_SRGB];
5127 d3d_info->clip_control = !!gl_info->supported[ARB_CLIP_CONTROL];
5128 d3d_info->full_ffp_varyings = !!(shader_caps.wined3d_caps & WINED3D_SHADER_CAP_FULL_FFP_VARYINGS);
5129 d3d_info->scaled_resolve = !!gl_info->supported[EXT_FRAMEBUFFER_MULTISAMPLE_BLIT_SCALED];
5130 d3d_info->feature_level = feature_level_from_caps(gl_info, &shader_caps, &fragment_caps);
5132 if (gl_info->supported[ARB_TEXTURE_MULTISAMPLE])
5133 d3d_info->multisample_draw_location = WINED3D_LOCATION_TEXTURE_RGB;
5134 else
5135 d3d_info->multisample_draw_location = WINED3D_LOCATION_RB_MULTISAMPLE;
5138 static BOOL wined3d_adapter_gl_init(struct wined3d_adapter_gl *adapter_gl,
5139 unsigned int ordinal, unsigned int wined3d_creation_flags)
5141 static const DWORD supported_gl_versions[] =
5143 MAKEDWORD_VERSION(4, 4),
5144 MAKEDWORD_VERSION(3, 2),
5145 MAKEDWORD_VERSION(1, 0),
5147 struct wined3d_driver_info *driver_info = &adapter_gl->a.driver_info;
5148 struct wined3d_gl_info *gl_info = &adapter_gl->a.gl_info;
5149 struct wined3d_caps_gl_ctx caps_gl_ctx = {0};
5150 LUID primary_luid, *luid = NULL;
5151 unsigned int i;
5153 TRACE("adapter_gl %p, ordinal %u, wined3d_creation_flags %#x.\n",
5154 adapter_gl, ordinal, wined3d_creation_flags);
5156 if (ordinal == 0 && wined3d_get_primary_adapter_luid(&primary_luid))
5157 luid = &primary_luid;
5159 if (!wined3d_adapter_init(&adapter_gl->a, ordinal, luid, &wined3d_adapter_gl_ops))
5160 return FALSE;
5162 /* Dynamically load all GL core functions */
5163 #ifdef USE_WIN32_OPENGL
5165 HMODULE mod_gl = GetModuleHandleA("opengl32.dll");
5166 #define USE_GL_FUNC(f) gl_info->gl_ops.gl.p_##f = (void *)GetProcAddress(mod_gl, #f);
5167 ALL_WGL_FUNCS
5168 #undef USE_GL_FUNC
5169 gl_info->gl_ops.wgl.p_wglSwapBuffers = (void *)GetProcAddress(mod_gl, "wglSwapBuffers");
5170 gl_info->gl_ops.wgl.p_wglGetPixelFormat = (void *)GetProcAddress(mod_gl, "wglGetPixelFormat");
5172 #else
5173 /* To bypass the opengl32 thunks retrieve functions from the WGL driver instead of opengl32 */
5175 HDC hdc = GetDC( 0 );
5176 const struct opengl_funcs *wgl_driver = __wine_get_wgl_driver( hdc, WINE_WGL_DRIVER_VERSION );
5177 ReleaseDC( 0, hdc );
5178 if (!wgl_driver || wgl_driver == (void *)-1) return FALSE;
5179 gl_info->gl_ops.wgl = wgl_driver->wgl;
5180 gl_info->gl_ops.gl = wgl_driver->gl;
5182 #endif
5184 gl_info->p_glEnableWINE = gl_info->gl_ops.gl.p_glEnable;
5185 gl_info->p_glDisableWINE = gl_info->gl_ops.gl.p_glDisable;
5187 if (!wined3d_caps_gl_ctx_create(&adapter_gl->a, &caps_gl_ctx))
5189 ERR("Failed to get a GL context for adapter %p.\n", adapter_gl);
5190 return FALSE;
5193 for (i = 0; i < ARRAY_SIZE(supported_gl_versions); ++i)
5195 if (supported_gl_versions[i] <= wined3d_settings.max_gl_version)
5196 break;
5198 if (i == ARRAY_SIZE(supported_gl_versions))
5200 ERR_(winediag)("Requested invalid GL version %u.%u.\n",
5201 wined3d_settings.max_gl_version >> 16, wined3d_settings.max_gl_version & 0xffff);
5202 i = ARRAY_SIZE(supported_gl_versions) - 1;
5205 for (; i < ARRAY_SIZE(supported_gl_versions); ++i)
5207 gl_info->selected_gl_version = supported_gl_versions[i];
5209 if (wined3d_caps_gl_ctx_create_attribs(&caps_gl_ctx, gl_info))
5210 break;
5212 WARN("Couldn't create an OpenGL %u.%u context, trying fallback to a lower version.\n",
5213 supported_gl_versions[i] >> 16, supported_gl_versions[i] & 0xffff);
5216 if (!wined3d_adapter_init_gl_caps(&adapter_gl->a, &caps_gl_ctx, wined3d_creation_flags))
5218 ERR("Failed to initialize GL caps for adapter %p.\n", adapter_gl);
5219 wined3d_caps_gl_ctx_destroy(&caps_gl_ctx);
5220 return FALSE;
5223 wined3d_adapter_gl_init_d3d_info(adapter_gl, wined3d_creation_flags);
5225 if (!adapter_gl->a.d3d_info.shader_color_key)
5227 /* We do not want to deal with re-creating immutable texture storage
5228 * for colour-keying emulation. */
5229 WARN("Disabling ARB_texture_storage because fragment pipe doesn't support colour-keying.\n");
5230 gl_info->supported[ARB_TEXTURE_STORAGE] = FALSE;
5233 if (!wined3d_driver_info_init(driver_info, caps_gl_ctx.gpu_description, adapter_gl->a.d3d_info.feature_level,
5234 caps_gl_ctx.vram_bytes, 0))
5236 wined3d_caps_gl_ctx_destroy(&caps_gl_ctx);
5237 return FALSE;
5239 TRACE("Reporting (fake) driver version 0x%08x-0x%08x.\n",
5240 driver_info->version_high, driver_info->version_low);
5242 if (wined3d_settings.offscreen_rendering_mode == ORM_BACKBUFFER)
5243 ERR_(winediag)("You are using the backbuffer for offscreen rendering. "
5244 "This is unsupported, and will be removed in a future version.\n");
5246 wined3d_adapter_init_fb_cfgs(adapter_gl, caps_gl_ctx.dc);
5247 /* We haven't found any suitable formats. This should only happen in
5248 * case of GDI software rendering, which is pretty useless anyway. */
5249 if (!adapter_gl->pixel_format_count)
5251 WARN("No suitable pixel formats found.\n");
5252 wined3d_caps_gl_ctx_destroy(&caps_gl_ctx);
5253 heap_free(adapter_gl->pixel_formats);
5254 return FALSE;
5257 if (!wined3d_adapter_gl_init_format_info(&adapter_gl->a, &caps_gl_ctx))
5259 ERR("Failed to initialize GL format info.\n");
5260 wined3d_caps_gl_ctx_destroy(&caps_gl_ctx);
5261 heap_free(adapter_gl->pixel_formats);
5262 return FALSE;
5265 wined3d_caps_gl_ctx_destroy(&caps_gl_ctx);
5267 wined3d_adapter_init_ffp_attrib_ops(&adapter_gl->a);
5269 return TRUE;
5272 struct wined3d_adapter *wined3d_adapter_gl_create(unsigned int ordinal, unsigned int wined3d_creation_flags)
5274 struct wined3d_adapter_gl *adapter;
5276 if (!(adapter = heap_alloc_zero(sizeof(*adapter))))
5277 return NULL;
5279 if (!wined3d_adapter_gl_init(adapter, ordinal, wined3d_creation_flags))
5281 heap_free(adapter);
5282 return NULL;
5285 TRACE("Created adapter %p.\n", adapter);
5287 return &adapter->a;