1236863b2f9078b409814b9563c714362990f1d9
[reactos.git] / dll / directx / wine / wined3d / directx.c
1 /*
2 * IWineD3D implementation
3 *
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2003-2004 Raphael Junqueira
6 * Copyright 2004 Christian Costa
7 * Copyright 2005 Oliver Stieber
8 * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
9 * Copyright 2009 Henri Verbeet for CodeWeavers
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26 #include "config.h"
27 #include "wined3d_private.h"
28
29 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
30 WINE_DECLARE_DEBUG_CHANNEL(d3d_caps);
31
32 #define GLINFO_LOCATION (*gl_info)
33
34 /* The d3d device ID */
35 static const GUID IID_D3DDEVICE_D3DUID = { 0xaeb2cdd4, 0x6e41, 0x43ea, { 0x94,0x1c,0x83,0x61,0xcc,0x76,0x07,0x81 } };
36
37 /* Extension detection */
38 static const struct {
39 const char *extension_string;
40 GL_SupportedExt extension;
41 DWORD version;
42 } EXTENSION_MAP[] = {
43 /* APPLE */
44 {"GL_APPLE_client_storage", APPLE_CLIENT_STORAGE, 0 },
45 {"GL_APPLE_fence", APPLE_FENCE, 0 },
46 {"GL_APPLE_flush_render", APPLE_FLUSH_RENDER, 0 },
47 {"GL_APPLE_ycbcr_422", APPLE_YCBCR_422, 0 },
48 {"GL_APPLE_float_pixels", APPLE_FLOAT_PIXELS, 0 },
49
50 /* ATI */
51 {"GL_ATI_separate_stencil", ATI_SEPARATE_STENCIL, 0 },
52 {"GL_ATI_texture_env_combine3", ATI_TEXTURE_ENV_COMBINE3, 0 },
53 {"GL_ATI_texture_mirror_once", ATI_TEXTURE_MIRROR_ONCE, 0 },
54 {"GL_ATI_fragment_shader", ATI_FRAGMENT_SHADER, 0 },
55 {"GL_ATI_texture_compression_3dc", ATI_TEXTURE_COMPRESSION_3DC, 0 },
56
57 /* ARB */
58 {"GL_ARB_color_buffer_float", ARB_COLOR_BUFFER_FLOAT, 0 },
59 {"GL_ARB_depth_buffer_float", ARB_DEPTH_BUFFER_FLOAT, 0 },
60 {"GL_ARB_depth_clamp", ARB_DEPTH_CLAMP, 0 },
61 {"GL_ARB_depth_texture", ARB_DEPTH_TEXTURE, 0 },
62 {"GL_ARB_draw_buffers", ARB_DRAW_BUFFERS, 0 },
63 {"GL_ARB_fragment_program", ARB_FRAGMENT_PROGRAM, 0 },
64 {"GL_ARB_fragment_shader", ARB_FRAGMENT_SHADER, 0 },
65 {"GL_ARB_framebuffer_object", ARB_FRAMEBUFFER_OBJECT, 0 },
66 {"GL_ARB_geometry_shader4", ARB_GEOMETRY_SHADER4, 0 },
67 {"GL_ARB_half_float_pixel", ARB_HALF_FLOAT_PIXEL, 0 },
68 {"GL_ARB_imaging", ARB_IMAGING, 0 },
69 {"GL_ARB_multisample", ARB_MULTISAMPLE, 0 }, /* needs GLX_ARB_MULTISAMPLE as well */
70 {"GL_ARB_multitexture", ARB_MULTITEXTURE, 0 },
71 {"GL_ARB_occlusion_query", ARB_OCCLUSION_QUERY, 0 },
72 {"GL_ARB_pixel_buffer_object", ARB_PIXEL_BUFFER_OBJECT, 0 },
73 {"GL_ARB_point_parameters", ARB_POINT_PARAMETERS, 0 },
74 {"GL_ARB_point_sprite", ARB_POINT_SPRITE, 0 },
75 {"GL_ARB_provoking_vertex", ARB_PROVOKING_VERTEX, 0 },
76 {"GL_ARB_texture_border_clamp", ARB_TEXTURE_BORDER_CLAMP, 0 },
77 {"GL_ARB_texture_compression", ARB_TEXTURE_COMPRESSION, 0 },
78 {"GL_ARB_texture_cube_map", ARB_TEXTURE_CUBE_MAP, 0 },
79 {"GL_ARB_texture_env_add", ARB_TEXTURE_ENV_ADD, 0 },
80 {"GL_ARB_texture_env_combine", ARB_TEXTURE_ENV_COMBINE, 0 },
81 {"GL_ARB_texture_env_dot3", ARB_TEXTURE_ENV_DOT3, 0 },
82 {"GL_ARB_texture_float", ARB_TEXTURE_FLOAT, 0 },
83 {"GL_ARB_texture_mirrored_repeat", ARB_TEXTURE_MIRRORED_REPEAT, 0 },
84 {"GL_ARB_texture_non_power_of_two", ARB_TEXTURE_NON_POWER_OF_TWO, MAKEDWORD_VERSION(2, 0) },
85 {"GL_ARB_texture_rectangle", ARB_TEXTURE_RECTANGLE, 0 },
86 {"GL_ARB_texture_rg", ARB_TEXTURE_RG, 0 },
87 {"GL_ARB_vertex_blend", ARB_VERTEX_BLEND, 0 },
88 {"GL_ARB_vertex_buffer_object", ARB_VERTEX_BUFFER_OBJECT, 0 },
89 {"GL_ARB_vertex_program", ARB_VERTEX_PROGRAM, 0 },
90 {"GL_ARB_vertex_shader", ARB_VERTEX_SHADER, 0 },
91 {"GL_ARB_shader_objects", ARB_SHADER_OBJECTS, 0 },
92 {"GL_ARB_shader_texture_lod", ARB_SHADER_TEXTURE_LOD, 0 },
93 {"GL_ARB_half_float_vertex", ARB_HALF_FLOAT_VERTEX, 0 },
94
95 /* EXT */
96 {"GL_EXT_blend_color", EXT_BLEND_COLOR, 0 },
97 {"GL_EXT_blend_minmax", EXT_BLEND_MINMAX, 0 },
98 {"GL_EXT_blend_equation_separate", EXT_BLEND_EQUATION_SEPARATE, 0 },
99 {"GL_EXT_blend_func_separate", EXT_BLEND_FUNC_SEPARATE, 0 },
100 {"GL_EXT_fog_coord", EXT_FOG_COORD, 0 },
101 {"GL_EXT_framebuffer_blit", EXT_FRAMEBUFFER_BLIT, 0 },
102 {"GL_EXT_framebuffer_multisample", EXT_FRAMEBUFFER_MULTISAMPLE, 0 },
103 {"GL_EXT_framebuffer_object", EXT_FRAMEBUFFER_OBJECT, 0 },
104 {"GL_EXT_packed_depth_stencil", EXT_PACKED_DEPTH_STENCIL, 0 },
105 {"GL_EXT_paletted_texture", EXT_PALETTED_TEXTURE, 0 },
106 {"GL_EXT_point_parameters", EXT_POINT_PARAMETERS, 0 },
107 {"GL_EXT_provoking_vertex", EXT_PROVOKING_VERTEX, 0 },
108 {"GL_EXT_secondary_color", EXT_SECONDARY_COLOR, 0 },
109 {"GL_EXT_stencil_two_side", EXT_STENCIL_TWO_SIDE, 0 },
110 {"GL_EXT_stencil_wrap", EXT_STENCIL_WRAP, 0 },
111 {"GL_EXT_texture3D", EXT_TEXTURE3D, MAKEDWORD_VERSION(1, 2) },
112 {"GL_EXT_texture_compression_s3tc", EXT_TEXTURE_COMPRESSION_S3TC, 0 },
113 {"GL_EXT_texture_compression_rgtc", EXT_TEXTURE_COMPRESSION_RGTC, 0 },
114 {"GL_EXT_texture_env_add", EXT_TEXTURE_ENV_ADD, 0 },
115 {"GL_EXT_texture_env_combine", EXT_TEXTURE_ENV_COMBINE, 0 },
116 {"GL_EXT_texture_env_dot3", EXT_TEXTURE_ENV_DOT3, 0 },
117 {"GL_EXT_texture_sRGB", EXT_TEXTURE_SRGB, 0 },
118 {"GL_EXT_texture_swizzle", EXT_TEXTURE_SWIZZLE, 0 },
119 {"GL_EXT_texture_filter_anisotropic", EXT_TEXTURE_FILTER_ANISOTROPIC, 0 },
120 {"GL_EXT_texture_lod", EXT_TEXTURE_LOD, 0 },
121 {"GL_EXT_texture_lod_bias", EXT_TEXTURE_LOD_BIAS, 0 },
122 {"GL_EXT_vertex_array_bgra", EXT_VERTEX_ARRAY_BGRA, 0 },
123 {"GL_EXT_vertex_shader", EXT_VERTEX_SHADER, 0 },
124 {"GL_EXT_gpu_program_parameters", EXT_GPU_PROGRAM_PARAMETERS, 0 },
125
126 /* NV */
127 {"GL_NV_half_float", NV_HALF_FLOAT, 0 },
128 {"GL_NV_fence", NV_FENCE, 0 },
129 {"GL_NV_fog_distance", NV_FOG_DISTANCE, 0 },
130 {"GL_NV_fragment_program", NV_FRAGMENT_PROGRAM, 0 },
131 {"GL_NV_fragment_program2", NV_FRAGMENT_PROGRAM2, 0 },
132 {"GL_NV_register_combiners", NV_REGISTER_COMBINERS, 0 },
133 {"GL_NV_register_combiners2", NV_REGISTER_COMBINERS2, 0 },
134 {"GL_NV_texgen_reflection", NV_TEXGEN_REFLECTION, 0 },
135 {"GL_NV_texture_env_combine4", NV_TEXTURE_ENV_COMBINE4, 0 },
136 {"GL_NV_texture_shader", NV_TEXTURE_SHADER, 0 },
137 {"GL_NV_texture_shader2", NV_TEXTURE_SHADER2, 0 },
138 {"GL_NV_texture_shader3", NV_TEXTURE_SHADER3, 0 },
139 {"GL_NV_occlusion_query", NV_OCCLUSION_QUERY, 0 },
140 {"GL_NV_vertex_program", NV_VERTEX_PROGRAM, 0 },
141 {"GL_NV_vertex_program1_1", NV_VERTEX_PROGRAM1_1, 0 },
142 {"GL_NV_vertex_program2", NV_VERTEX_PROGRAM2, 0 },
143 {"GL_NV_vertex_program2_option", NV_VERTEX_PROGRAM2_OPTION, 0 },
144 {"GL_NV_vertex_program3", NV_VERTEX_PROGRAM3, 0 },
145 {"GL_NV_fragment_program_option", NV_FRAGMENT_PROGRAM_OPTION, 0 },
146 {"GL_NV_depth_clamp", NV_DEPTH_CLAMP, 0 },
147 {"GL_NV_light_max_exponent", NV_LIGHT_MAX_EXPONENT, 0 },
148
149 /* SGI */
150 {"GL_SGIS_generate_mipmap", SGIS_GENERATE_MIPMAP, 0 },
151 };
152
153 /**********************************************************
154 * Utility functions follow
155 **********************************************************/
156
157 static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType, WINED3DFORMAT AdapterFormat, DWORD Usage, WINED3DRESOURCETYPE RType, WINED3DFORMAT CheckFormat, WINED3DSURFTYPE SurfaceType);
158 static const struct fragment_pipeline *select_fragment_implementation(struct WineD3DAdapter *adapter,
159 WINED3DDEVTYPE DeviceType);
160 static const shader_backend_t *select_shader_backend(struct WineD3DAdapter *adapter, WINED3DDEVTYPE DeviceType);
161 static const struct blit_shader *select_blit_implementation(struct WineD3DAdapter *adapter, WINED3DDEVTYPE DeviceType);
162
163 /* lookup tables */
164 const int minLookup[MAX_LOOKUPS] =
165 {
166 WINED3DTADDRESS_WRAP, /* WINELOOKUP_WARPPARAM */
167 };
168
169 const int maxLookup[MAX_LOOKUPS] =
170 {
171 WINED3DTADDRESS_MIRRORONCE, /* WINELOOKUP_WARPPARAM */
172 };
173
174 DWORD *stateLookup[MAX_LOOKUPS];
175
176 const struct min_lookup minMipLookup[] =
177 {
178 /* NONE POINT LINEAR */
179 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}}, /* NONE */
180 {{GL_NEAREST, GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR}}, /* POINT*/
181 {{GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_LINEAR}}, /* LINEAR */
182 };
183
184 const struct min_lookup minMipLookup_noFilter[] =
185 {
186 /* NONE POINT LINEAR */
187 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}}, /* NONE */
188 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}}, /* POINT */
189 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}}, /* LINEAR */
190 };
191
192 const struct min_lookup minMipLookup_noMip[] =
193 {
194 /* NONE POINT LINEAR */
195 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}}, /* NONE */
196 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}}, /* POINT */
197 {{GL_LINEAR, GL_LINEAR, GL_LINEAR }}, /* LINEAR */
198 };
199
200 const GLenum magLookup[] =
201 {
202 /* NONE POINT LINEAR */
203 GL_NEAREST, GL_NEAREST, GL_LINEAR,
204 };
205
206 const GLenum magLookup_noFilter[] =
207 {
208 /* NONE POINT LINEAR */
209 GL_NEAREST, GL_NEAREST, GL_NEAREST,
210 };
211
212 /* drawStridedSlow attributes */
213 glAttribFunc position_funcs[WINED3D_FFP_EMIT_COUNT];
214 glAttribFunc diffuse_funcs[WINED3D_FFP_EMIT_COUNT];
215 glAttribFunc specular_func_3ubv;
216 glAttribFunc specular_funcs[WINED3D_FFP_EMIT_COUNT];
217 glAttribFunc normal_funcs[WINED3D_FFP_EMIT_COUNT];
218 glMultiTexCoordFunc multi_texcoord_funcs[WINED3D_FFP_EMIT_COUNT];
219
220 /**
221 * Note: GL seems to trap if GetDeviceCaps is called before any HWND's created,
222 * i.e., there is no GL Context - Get a default rendering context to enable the
223 * function query some info from GL.
224 */
225
226 struct wined3d_fake_gl_ctx
227 {
228 HDC dc;
229 HWND wnd;
230 HGLRC gl_ctx;
231 };
232
233 static void WineD3D_ReleaseFakeGLContext(struct wined3d_fake_gl_ctx *ctx)
234 {
235 TRACE_(d3d_caps)("Destroying fake GL context.\n");
236
237 if (!pwglMakeCurrent(NULL, NULL))
238 {
239 ERR_(d3d_caps)("Failed to disable fake GL context.\n");
240 }
241 #if 0
242 if (!pwglDeleteContext(ctx->gl_ctx))
243 {
244 DWORD err = GetLastError();
245 ERR("wglDeleteContext(%p) failed, last error %#x.\n", ctx->gl_ctx, err);
246 }
247 #endif
248 ReleaseDC(ctx->wnd, ctx->dc);
249 DestroyWindow(ctx->wnd);
250 }
251
252 static BOOL WineD3D_CreateFakeGLContext(struct wined3d_fake_gl_ctx *ctx)
253 {
254 PIXELFORMATDESCRIPTOR pfd;
255 int iPixelFormat;
256
257 TRACE("getting context...\n");
258
259 /* We need a fake window as a hdc retrieved using GetDC(0) can't be used for much GL purposes. */
260 ctx->wnd = CreateWindowA(WINED3D_OPENGL_WINDOW_CLASS_NAME, "WineD3D fake window",
261 WS_OVERLAPPEDWINDOW, 10, 10, 10, 10, NULL, NULL, NULL, NULL);
262 if (!ctx->wnd)
263 {
264 ERR_(d3d_caps)("Failed to create a window.\n");
265 goto fail;
266 }
267
268 ctx->dc = GetDC(ctx->wnd);
269 if (!ctx->dc)
270 {
271 ERR_(d3d_caps)("Failed to get a DC.\n");
272 goto fail;
273 }
274
275 /* PixelFormat selection */
276 ZeroMemory(&pfd, sizeof(pfd));
277 pfd.nSize = sizeof(pfd);
278 pfd.nVersion = 1;
279 pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW; /* PFD_GENERIC_ACCELERATED */
280 pfd.iPixelType = PFD_TYPE_RGBA;
281 pfd.cColorBits = 32;
282 pfd.iLayerType = PFD_MAIN_PLANE;
283
284 iPixelFormat = ChoosePixelFormat(ctx->dc, &pfd);
285 if (!iPixelFormat)
286 {
287 /* If this happens something is very wrong as ChoosePixelFormat barely fails. */
288 ERR_(d3d_caps)("Can't find a suitable iPixelFormat.\n");
289 goto fail;
290 }
291 DescribePixelFormat(ctx->dc, iPixelFormat, sizeof(pfd), &pfd);
292 SetPixelFormat(ctx->dc, iPixelFormat, &pfd);
293
294 /* Create a GL context. */
295 ctx->gl_ctx = pwglCreateContext(ctx->dc);
296 if (!ctx->gl_ctx)
297 {
298 WARN_(d3d_caps)("Error creating default context for capabilities initialization.\n");
299 goto fail;
300 }
301
302 /* Make it the current GL context. */
303 if (!context_set_current(NULL))
304 {
305 ERR_(d3d_caps)("Failed to clear current D3D context.\n");
306 }
307
308 if (!pwglMakeCurrent(ctx->dc, ctx->gl_ctx))
309 {
310 ERR_(d3d_caps)("Failed to make fake GL context current.\n");
311 goto fail;
312 }
313
314 return TRUE;
315
316 fail:
317 if (ctx->gl_ctx) pwglDeleteContext(ctx->gl_ctx);
318 ctx->gl_ctx = NULL;
319 if (ctx->dc) ReleaseDC(ctx->wnd, ctx->dc);
320 ctx->dc = NULL;
321 if (ctx->wnd) DestroyWindow(ctx->wnd);
322 ctx->wnd = NULL;
323
324 return FALSE;
325 }
326
327 /* Adjust the amount of used texture memory */
328 long WineD3DAdapterChangeGLRam(IWineD3DDeviceImpl *D3DDevice, long glram){
329 struct WineD3DAdapter *adapter = D3DDevice->adapter;
330
331 adapter->UsedTextureRam += glram;
332 TRACE("Adjusted gl ram by %ld to %d\n", glram, adapter->UsedTextureRam);
333 return adapter->UsedTextureRam;
334 }
335
336 /**********************************************************
337 * IUnknown parts follows
338 **********************************************************/
339
340 static HRESULT WINAPI IWineD3DImpl_QueryInterface(IWineD3D *iface,REFIID riid,LPVOID *ppobj)
341 {
342 IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
343
344 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
345 if (IsEqualGUID(riid, &IID_IUnknown)
346 || IsEqualGUID(riid, &IID_IWineD3DBase)
347 || IsEqualGUID(riid, &IID_IWineD3DDevice)) {
348 IUnknown_AddRef(iface);
349 *ppobj = This;
350 return S_OK;
351 }
352 *ppobj = NULL;
353 return E_NOINTERFACE;
354 }
355
356 static ULONG WINAPI IWineD3DImpl_AddRef(IWineD3D *iface) {
357 IWineD3DImpl *This = (IWineD3DImpl *)iface;
358 ULONG refCount = InterlockedIncrement(&This->ref);
359
360 TRACE("(%p) : AddRef increasing from %d\n", This, refCount - 1);
361 return refCount;
362 }
363
364 static ULONG WINAPI IWineD3DImpl_Release(IWineD3D *iface) {
365 IWineD3DImpl *This = (IWineD3DImpl *)iface;
366 ULONG ref;
367 TRACE("(%p) : Releasing from %d\n", This, This->ref);
368 ref = InterlockedDecrement(&This->ref);
369 if (ref == 0) {
370 unsigned int i;
371
372 for (i = 0; i < This->adapter_count; ++i)
373 {
374 HeapFree(GetProcessHeap(), 0, This->adapters[i].cfgs);
375 }
376 HeapFree(GetProcessHeap(), 0, This);
377 }
378
379 return ref;
380 }
381
382 /* Set the shader type for this device, depending on the given capabilities
383 * and the user preferences in wined3d_settings. */
384 static void select_shader_mode(const struct wined3d_gl_info *gl_info, int *ps_selected, int *vs_selected)
385 {
386 if (wined3d_settings.vs_mode == VS_NONE) {
387 *vs_selected = SHADER_NONE;
388 } else if (gl_info->supported[ARB_VERTEX_SHADER] && wined3d_settings.glslRequested) {
389 /* Geforce4 cards support GLSL but for vertex shaders only. Further its reported GLSL caps are
390 * wrong. This combined with the fact that glsl won't offer more features or performance, use ARB
391 * shaders only on this card. */
392 if (gl_info->supported[NV_VERTEX_PROGRAM] && !gl_info->supported[NV_VERTEX_PROGRAM2])
393 *vs_selected = SHADER_ARB;
394 else
395 *vs_selected = SHADER_GLSL;
396 } else if (gl_info->supported[ARB_VERTEX_PROGRAM]) {
397 *vs_selected = SHADER_ARB;
398 } else {
399 *vs_selected = SHADER_NONE;
400 }
401
402 if (wined3d_settings.ps_mode == PS_NONE) {
403 *ps_selected = SHADER_NONE;
404 } else if (gl_info->supported[ARB_FRAGMENT_SHADER] && wined3d_settings.glslRequested) {
405 *ps_selected = SHADER_GLSL;
406 } else if (gl_info->supported[ARB_FRAGMENT_PROGRAM]) {
407 *ps_selected = SHADER_ARB;
408 } else if (gl_info->supported[ATI_FRAGMENT_SHADER]) {
409 *ps_selected = SHADER_ATI;
410 } else {
411 *ps_selected = SHADER_NONE;
412 }
413 }
414
415 /** Select the number of report maximum shader constants based on the selected shader modes */
416 static void select_shader_max_constants(int ps_selected_mode, int vs_selected_mode, struct wined3d_gl_info *gl_info)
417 {
418 switch (vs_selected_mode) {
419 case SHADER_GLSL:
420 gl_info->max_vshader_constantsF = gl_info->vs_glsl_constantsF;
421 break;
422 case SHADER_ARB:
423 gl_info->max_vshader_constantsF = gl_info->vs_arb_constantsF;
424 break;
425 default:
426 gl_info->max_vshader_constantsF = 0;
427 break;
428 }
429
430 switch (ps_selected_mode) {
431 case SHADER_GLSL:
432 gl_info->max_pshader_constantsF = gl_info->ps_glsl_constantsF;
433 break;
434 case SHADER_ARB:
435 gl_info->max_pshader_constantsF = gl_info->ps_arb_constantsF;
436 break;
437 default:
438 gl_info->max_pshader_constantsF = 0;
439 break;
440 }
441 }
442
443 /**********************************************************
444 * IWineD3D parts follows
445 **********************************************************/
446
447 /* GL locking is done by the caller */
448 static inline BOOL test_arb_vs_offset_limit(const struct wined3d_gl_info *gl_info)
449 {
450 GLuint prog;
451 BOOL ret = FALSE;
452 const char *testcode =
453 "!!ARBvp1.0\n"
454 "PARAM C[66] = { program.env[0..65] };\n"
455 "ADDRESS A0;"
456 "PARAM zero = {0.0, 0.0, 0.0, 0.0};\n"
457 "ARL A0.x, zero.x;\n"
458 "MOV result.position, C[A0.x + 65];\n"
459 "END\n";
460
461 while(glGetError());
462 GL_EXTCALL(glGenProgramsARB(1, &prog));
463 if(!prog) {
464 ERR("Failed to create an ARB offset limit test program\n");
465 }
466 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prog));
467 GL_EXTCALL(glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
468 strlen(testcode), testcode));
469 if(glGetError() != 0) {
470 TRACE("OpenGL implementation does not allow indirect addressing offsets > 63\n");
471 TRACE("error: %s\n", debugstr_a((const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
472 ret = TRUE;
473 } else TRACE("OpenGL implementation allows offsets > 63\n");
474
475 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, 0));
476 GL_EXTCALL(glDeleteProgramsARB(1, &prog));
477 checkGLcall("ARB vp offset limit test cleanup");
478
479 return ret;
480 }
481
482 static DWORD ver_for_ext(GL_SupportedExt ext)
483 {
484 unsigned int i;
485 for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i) {
486 if(EXTENSION_MAP[i].extension == ext) {
487 return EXTENSION_MAP[i].version;
488 }
489 }
490 return 0;
491 }
492
493 static BOOL match_ati_r300_to_500(const struct wined3d_gl_info *gl_info, const char *gl_renderer)
494 {
495 if (gl_info->gl_vendor != VENDOR_ATI) return FALSE;
496 if (gl_info->gl_card == CARD_ATI_RADEON_9500) return TRUE;
497 if (gl_info->gl_card == CARD_ATI_RADEON_X700) return TRUE;
498 if (gl_info->gl_card == CARD_ATI_RADEON_X1600) return TRUE;
499 return FALSE;
500 }
501
502 static BOOL match_geforce5(const struct wined3d_gl_info *gl_info, const char *gl_renderer)
503 {
504 if (gl_info->gl_vendor == VENDOR_NVIDIA)
505 {
506 if (gl_info->gl_card == CARD_NVIDIA_GEFORCEFX_5800 || gl_info->gl_card == CARD_NVIDIA_GEFORCEFX_5600)
507 {
508 return TRUE;
509 }
510 }
511 return FALSE;
512 }
513
514 static BOOL match_apple(const struct wined3d_gl_info *gl_info, const char *gl_renderer)
515 {
516 /* MacOS has various specialities in the extensions it advertises. Some have to be loaded from
517 * the opengl 1.2+ core, while other extensions are advertised, but software emulated. So try to
518 * detect the Apple OpenGL implementation to apply some extension fixups afterwards.
519 *
520 * Detecting this isn't really easy. The vendor string doesn't mention Apple. Compile-time checks
521 * aren't sufficient either because a Linux binary may display on a macos X server via remote X11.
522 * So try to detect the GL implementation by looking at certain Apple extensions. Some extensions
523 * like client storage might be supported on other implementations too, but GL_APPLE_flush_render
524 * is specific to the Mac OS X window management, and GL_APPLE_ycbcr_422 is QuickTime specific. So
525 * the chance that other implementations support them is rather small since Win32 QuickTime uses
526 * DirectDraw, not OpenGL. */
527 if (gl_info->supported[APPLE_FENCE]
528 && gl_info->supported[APPLE_CLIENT_STORAGE]
529 && gl_info->supported[APPLE_FLUSH_RENDER]
530 && gl_info->supported[APPLE_YCBCR_422])
531 {
532 return TRUE;
533 }
534 else
535 {
536 return FALSE;
537 }
538 }
539
540 /* Context activation is done by the caller. */
541 static void test_pbo_functionality(struct wined3d_gl_info *gl_info)
542 {
543 /* Some OpenGL implementations, namely Apple's Geforce 8 driver, advertises PBOs,
544 * but glTexSubImage from a PBO fails miserably, with the first line repeated over
545 * all the texture. This function detects this bug by its symptom and disables PBOs
546 * if the test fails.
547 *
548 * The test uploads a 4x4 texture via the PBO in the "native" format GL_BGRA,
549 * GL_UNSIGNED_INT_8_8_8_8_REV. This format triggers the bug, and it is what we use
550 * for D3DFMT_A8R8G8B8. Then the texture is read back without any PBO and the data
551 * read back is compared to the original. If they are equal PBOs are assumed to work,
552 * otherwise the PBO extension is disabled. */
553 GLuint texture, pbo;
554 static const unsigned int pattern[] =
555 {
556 0x00000000, 0x000000ff, 0x0000ff00, 0x40ff0000,
557 0x80ffffff, 0x40ffff00, 0x00ff00ff, 0x0000ffff,
558 0x00ffff00, 0x00ff00ff, 0x0000ffff, 0x000000ff,
559 0x80ff00ff, 0x0000ffff, 0x00ff00ff, 0x40ff00ff
560 };
561 unsigned int check[sizeof(pattern) / sizeof(pattern[0])];
562
563 /* No PBO -> No point in testing them. */
564 if (!gl_info->supported[ARB_PIXEL_BUFFER_OBJECT]) return;
565
566 ENTER_GL();
567
568 while (glGetError());
569 glGenTextures(1, &texture);
570 glBindTexture(GL_TEXTURE_2D, texture);
571
572 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
573 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
574 checkGLcall("Specifying the PBO test texture");
575
576 GL_EXTCALL(glGenBuffersARB(1, &pbo));
577 GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo));
578 GL_EXTCALL(glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, sizeof(pattern), pattern, GL_STREAM_DRAW_ARB));
579 checkGLcall("Specifying the PBO test pbo");
580
581 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
582 checkGLcall("Loading the PBO test texture");
583
584 GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
585 wglFinish(); /* just to be sure */
586
587 memset(check, 0, sizeof(check));
588 glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, check);
589 checkGLcall("Reading back the PBO test texture");
590
591 glDeleteTextures(1, &texture);
592 GL_EXTCALL(glDeleteBuffersARB(1, &pbo));
593 checkGLcall("PBO test cleanup");
594
595 LEAVE_GL();
596
597 if (memcmp(check, pattern, sizeof(check)))
598 {
599 WARN_(d3d_caps)("PBO test failed, read back data doesn't match original.\n");
600 WARN_(d3d_caps)("Disabling PBOs. This may result in slower performance.\n");
601 gl_info->supported[ARB_PIXEL_BUFFER_OBJECT] = FALSE;
602 }
603 else
604 {
605 TRACE_(d3d_caps)("PBO test successful.\n");
606 }
607 }
608
609 static BOOL match_apple_intel(const struct wined3d_gl_info *gl_info, const char *gl_renderer)
610 {
611 return gl_info->gl_vendor == VENDOR_INTEL && match_apple(gl_info, gl_renderer);
612 }
613
614 static BOOL match_apple_nonr500ati(const struct wined3d_gl_info *gl_info, const char *gl_renderer)
615 {
616 if (!match_apple(gl_info, gl_renderer)) return FALSE;
617 if (gl_info->gl_vendor != VENDOR_ATI) return FALSE;
618 if (gl_info->gl_card == CARD_ATI_RADEON_X1600) return FALSE;
619 return TRUE;
620 }
621
622 static BOOL match_fglrx(const struct wined3d_gl_info *gl_info, const char *gl_renderer)
623 {
624 if (gl_info->gl_vendor != VENDOR_ATI) return FALSE;
625 if (match_apple(gl_info, gl_renderer)) return FALSE;
626 if (strstr(gl_renderer, "DRI")) return FALSE; /* Filter out Mesa DRI drivers. */
627 return TRUE;
628 }
629
630 static BOOL match_dx10_capable(const struct wined3d_gl_info *gl_info, const char *gl_renderer)
631 {
632 /* DX9 cards support 40 single float varyings in hardware, most drivers report 32. ATI misreports
633 * 44 varyings. So assume that if we have more than 44 varyings we have a dx10 card.
634 * This detection is for the gl_ClipPos varying quirk. If a d3d9 card really supports more than 44
635 * varyings and we subtract one in dx9 shaders its not going to hurt us because the dx9 limit is
636 * hardcoded
637 *
638 * dx10 cards usually have 64 varyings */
639 return gl_info->max_glsl_varyings > 44;
640 }
641
642 /* A GL context is provided by the caller */
643 static BOOL match_allows_spec_alpha(const struct wined3d_gl_info *gl_info, const char *gl_renderer)
644 {
645 GLenum error;
646 DWORD data[16];
647
648 if(!GL_SUPPORT(EXT_SECONDARY_COLOR)) return FALSE;
649
650 ENTER_GL();
651 while(glGetError());
652 GL_EXTCALL(glSecondaryColorPointerEXT)(4, GL_UNSIGNED_BYTE, 4, data);
653 error = glGetError();
654 LEAVE_GL();
655
656 if(error == GL_NO_ERROR)
657 {
658 TRACE("GL Implementation accepts 4 component specular color pointers\n");
659 return TRUE;
660 }
661 else
662 {
663 TRACE("GL implementation does not accept 4 component specular colors, error %s\n",
664 debug_glerror(error));
665 return FALSE;
666 }
667 }
668
669 static void quirk_arb_constants(struct wined3d_gl_info *gl_info)
670 {
671 TRACE_(d3d_caps)("Using ARB vs constant limit(=%u) for GLSL.\n", gl_info->vs_arb_constantsF);
672 gl_info->vs_glsl_constantsF = gl_info->vs_arb_constantsF;
673 TRACE_(d3d_caps)("Using ARB ps constant limit(=%u) for GLSL.\n", gl_info->ps_arb_constantsF);
674 gl_info->ps_glsl_constantsF = gl_info->ps_arb_constantsF;
675 }
676
677 static void quirk_apple_glsl_constants(struct wined3d_gl_info *gl_info)
678 {
679 quirk_arb_constants(gl_info);
680 /* MacOS needs uniforms for relative addressing offsets. This can accumulate to quite a few uniforms.
681 * Beyond that the general uniform isn't optimal, so reserve a number of uniforms. 12 vec4's should
682 * allow 48 different offsets or other helper immediate values. */
683 TRACE_(d3d_caps)("Reserving 12 GLSL constants for compiler private use.\n");
684 gl_info->reserved_glsl_constants = max(gl_info->reserved_glsl_constants, 12);
685 }
686
687 /* fglrx crashes with a very bad kernel panic if GL_POINT_SPRITE_ARB is set to GL_COORD_REPLACE_ARB
688 * on more than one texture unit. This means that the d3d9 visual point size test will cause a
689 * kernel panic on any machine running fglrx 9.3(latest that supports r300 to r500 cards). This
690 * quirk only enables point sprites on the first texture unit. This keeps point sprites working in
691 * most games, but avoids the crash
692 *
693 * A more sophisticated way would be to find all units that need texture coordinates and enable
694 * point sprites for one if only one is found, and software emulate point sprites in drawStridedSlow
695 * if more than one unit needs texture coordinates(This requires software ffp and vertex shaders though)
696 *
697 * Note that disabling the extension entirely does not gain predictability because there is no point
698 * sprite capability flag in d3d, so the potential rendering bugs are the same if we disable the extension. */
699 static void quirk_one_point_sprite(struct wined3d_gl_info *gl_info)
700 {
701 if (gl_info->supported[ARB_POINT_SPRITE])
702 {
703 TRACE("Limiting point sprites to one texture unit.\n");
704 gl_info->max_point_sprite_units = 1;
705 }
706 }
707
708 static void quirk_ati_dx9(struct wined3d_gl_info *gl_info)
709 {
710 quirk_arb_constants(gl_info);
711
712 /* MacOS advertises GL_ARB_texture_non_power_of_two on ATI r500 and earlier cards, although
713 * these cards only support GL_ARB_texture_rectangle(D3DPTEXTURECAPS_NONPOW2CONDITIONAL).
714 * If real NP2 textures are used, the driver falls back to software. We could just remove the
715 * extension and use GL_ARB_texture_rectangle instead, but texture_rectangle is inconventient
716 * due to the non-normalized texture coordinates. Thus set an internal extension flag,
717 * GL_WINE_normalized_texrect, which signals the code that it can use non power of two textures
718 * as per GL_ARB_texture_non_power_of_two, but has to stick to the texture_rectangle limits.
719 *
720 * fglrx doesn't advertise GL_ARB_texture_non_power_of_two, but it advertises opengl 2.0 which
721 * has this extension promoted to core. The extension loading code sets this extension supported
722 * due to that, so this code works on fglrx as well. */
723 if(gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
724 {
725 TRACE("GL_ARB_texture_non_power_of_two advertised on R500 or earlier card, removing.\n");
726 gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] = FALSE;
727 gl_info->supported[WINE_NORMALIZED_TEXRECT] = TRUE;
728 }
729
730 /* fglrx has the same structural issues as the one described in quirk_apple_glsl_constants, although
731 * it is generally more efficient. Reserve just 8 constants. */
732 TRACE_(d3d_caps)("Reserving 8 GLSL constants for compiler private use.\n");
733 gl_info->reserved_glsl_constants = max(gl_info->reserved_glsl_constants, 8);
734 }
735
736 static void quirk_no_np2(struct wined3d_gl_info *gl_info)
737 {
738 /* The nVidia GeForceFX series reports OpenGL 2.0 capabilities with the latest drivers versions, but
739 * doesn't explicitly advertise the ARB_tex_npot extension in the GL extension string.
740 * This usually means that ARB_tex_npot is supported in hardware as long as the application is staying
741 * within the limits enforced by the ARB_texture_rectangle extension. This however is not true for the
742 * FX series, which instantly falls back to a slower software path as soon as ARB_tex_npot is used.
743 * We therefore completely remove ARB_tex_npot from the list of supported extensions.
744 *
745 * Note that wine_normalized_texrect can't be used in this case because internally it uses ARB_tex_npot,
746 * triggering the software fallback. There is not much we can do here apart from disabling the
747 * software-emulated extension and reenable ARB_tex_rect (which was previously disabled
748 * in IWineD3DImpl_FillGLCaps).
749 * This fixup removes performance problems on both the FX 5900 and FX 5700 (e.g. for framebuffer
750 * post-processing effects in the game "Max Payne 2").
751 * The behaviour can be verified through a simple test app attached in bugreport #14724. */
752 TRACE("GL_ARB_texture_non_power_of_two advertised through OpenGL 2.0 on NV FX card, removing.\n");
753 gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] = FALSE;
754 gl_info->supported[ARB_TEXTURE_RECTANGLE] = TRUE;
755 }
756
757 static void quirk_texcoord_w(struct wined3d_gl_info *gl_info)
758 {
759 /* The Intel GPUs on MacOS set the .w register of texcoords to 0.0 by default, which causes problems
760 * with fixed function fragment processing. Ideally this flag should be detected with a test shader
761 * and OpenGL feedback mode, but some GL implementations (MacOS ATI at least, probably all MacOS ones)
762 * do not like vertex shaders in feedback mode and return an error, even though it should be valid
763 * according to the spec.
764 *
765 * We don't want to enable this on all cards, as it adds an extra instruction per texcoord used. This
766 * makes the shader slower and eats instruction slots which should be available to the d3d app.
767 *
768 * ATI Radeon HD 2xxx cards on MacOS have the issue. Instead of checking for the buggy cards, blacklist
769 * all radeon cards on Macs and whitelist the good ones. That way we're prepared for the future. If
770 * this workaround is activated on cards that do not need it, it won't break things, just affect
771 * performance negatively. */
772 TRACE("Enabling vertex texture coord fixes in vertex shaders.\n");
773 gl_info->quirks |= WINED3D_QUIRK_SET_TEXCOORD_W;
774 }
775
776 static void quirk_clip_varying(struct wined3d_gl_info *gl_info)
777 {
778 gl_info->quirks |= WINED3D_QUIRK_GLSL_CLIP_VARYING;
779 }
780
781 static void quirk_allows_specular_alpha(struct wined3d_gl_info *gl_info)
782 {
783 gl_info->quirks |= WINED3D_QUIRK_ALLOWS_SPECULAR_ALPHA;
784 }
785
786 struct driver_quirk
787 {
788 BOOL (*match)(const struct wined3d_gl_info *gl_info, const char *gl_renderer);
789 void (*apply)(struct wined3d_gl_info *gl_info);
790 const char *description;
791 };
792
793 static const struct driver_quirk quirk_table[] =
794 {
795 {
796 match_ati_r300_to_500,
797 quirk_ati_dx9,
798 "ATI GLSL constant and normalized texrect quirk"
799 },
800 /* MacOS advertises more GLSL vertex shader uniforms than supported by the hardware, and if more are
801 * used it falls back to software. While the compiler can detect if the shader uses all declared
802 * uniforms, the optimization fails if the shader uses relative addressing. So any GLSL shader
803 * using relative addressing falls back to software.
804 *
805 * ARB vp gives the correct amount of uniforms, so use it instead of GLSL. */
806 {
807 match_apple,
808 quirk_apple_glsl_constants,
809 "Apple GLSL uniform override"
810 },
811 {
812 match_geforce5,
813 quirk_no_np2,
814 "Geforce 5 NP2 disable"
815 },
816 {
817 match_apple_intel,
818 quirk_texcoord_w,
819 "Init texcoord .w for Apple Intel GPU driver"
820 },
821 {
822 match_apple_nonr500ati,
823 quirk_texcoord_w,
824 "Init texcoord .w for Apple ATI >= r600 GPU driver"
825 },
826 {
827 match_fglrx,
828 quirk_one_point_sprite,
829 "Fglrx point sprite crash workaround"
830 },
831 {
832 match_dx10_capable,
833 quirk_clip_varying,
834 "Reserved varying for gl_ClipPos"
835 },
836 {
837 /* GL_EXT_secondary_color does not allow 4 component secondary colors, but most
838 * GL implementations accept it. The Mac GL is the only implementation known to
839 * reject it.
840 *
841 * If we can pass 4 component specular colors, do it, because (a) we don't have
842 * to screw around with the data, and (b) the D3D fixed function vertex pipeline
843 * passes specular alpha to the pixel shader if any is used. Otherwise the
844 * specular alpha is used to pass the fog coordinate, which we pass to opengl
845 * via GL_EXT_fog_coord.
846 */
847 match_allows_spec_alpha,
848 quirk_allows_specular_alpha,
849 "Allow specular alpha quirk"
850 }
851 };
852
853 /* Certain applications (Steam) complain if we report an outdated driver version. In general,
854 * reporting a driver version is moot because we are not the Windows driver, and we have different
855 * bugs, features, etc.
856 *
857 * If a card is not found in this table, the GL driver version is reported. */
858 struct driver_version_information
859 {
860 WORD vendor; /* reported PCI card vendor ID */
861 WORD card; /* reported PCI card device ID */
862 const char *description; /* Description of the card e.g. NVIDIA RIVA TNT */
863 WORD hipart_hi, hipart_lo; /* driver hiword to report */
864 WORD lopart_hi, lopart_lo; /* driver loword to report */
865 };
866
867 static const struct driver_version_information driver_version_table[] =
868 {
869 /* Nvidia drivers. Geforce6 and newer cards are supported by the current driver (180.x)
870 * GeforceFX support is up to 173.x, - driver uses numbering x.y.11.7341 for 173.41 where x is the windows revision (6=2000/xp, 7=vista), y is unknown
871 * Geforce2MX/3/4 up to 96.x - driver uses numbering 9.6.8.9 for 96.89
872 * TNT/Geforce1/2 up to 71.x - driver uses numbering 7.1.8.6 for 71.86
873 *
874 * All version numbers used below are from the Linux nvidia drivers. */
875 {VENDOR_NVIDIA, CARD_NVIDIA_RIVA_TNT, "NVIDIA RIVA TNT", 7, 1, 8, 6 },
876 {VENDOR_NVIDIA, CARD_NVIDIA_RIVA_TNT2, "NVIDIA RIVA TNT2/TNT2 Pro", 7, 1, 8, 6 },
877 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE, "NVIDIA GeForce 256", 7, 1, 8, 6 },
878 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE2_MX, "NVIDIA GeForce2 MX/MX 400", 9, 6, 4, 3 },
879 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE2, "NVIDIA GeForce2 GTS/GeForce2 Pro", 7, 1, 8, 6 },
880 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE3, "NVIDIA GeForce3", 9, 6, 10, 9371 },
881 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE4_MX, "NVIDIA GeForce4 MX 460", 9, 6, 10, 9371 },
882 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE4_TI4200, "NVIDIA GeForce4 Ti 4200", 9, 6, 10, 9371 },
883 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5200, "NVIDIA GeForce FX 5200", 7, 15, 11, 7516 },
884 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5600, "NVIDIA GeForce FX 5600", 7, 15, 11, 7516 },
885 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5800, "NVIDIA GeForce FX 5800", 7, 15, 11, 7516 },
886 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6200, "NVIDIA GeForce 6200", 7, 15, 11, 8618 },
887 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6600GT, "NVIDIA GeForce 6600 GT", 7, 15, 11, 8618 },
888 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6800, "NVIDIA GeForce 6800", 7, 15, 11, 8618 },
889 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7300, "NVIDIA GeForce Go 7300", 7, 15, 11, 8585 },
890 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7400, "NVIDIA GeForce Go 7400", 7, 15, 11, 8585 },
891 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7600, "NVIDIA GeForce 7600 GT", 7, 15, 11, 8618 },
892 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7800GT, "NVIDIA GeForce 7800 GT", 7, 15, 11, 8618 },
893 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8300GS, "NVIDIA GeForce 8300 GS", 7, 15, 11, 8618 },
894 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8600GT, "NVIDIA GeForce 8600 GT", 7, 15, 11, 8618 },
895 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8600MGT, "NVIDIA GeForce 8600M GT", 7, 15, 11, 8585 },
896 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8800GTS, "NVIDIA GeForce 8800 GTS", 7, 15, 11, 8618 },
897 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9200, "NVIDIA GeForce 9200", 7, 15, 11, 8618 },
898 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9400GT, "NVIDIA GeForce 9400 GT", 7, 15, 11, 8618 },
899 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9500GT, "NVIDIA GeForce 9500 GT", 7, 15, 11, 8618 },
900 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9600GT, "NVIDIA GeForce 9600 GT", 7, 15, 11, 8618 },
901 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9800GT, "NVIDIA GeForce 9800 GT", 7, 15, 11, 8618 },
902 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX260, "NVIDIA GeForce GTX 260", 7, 15, 11, 8618 },
903 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX275, "NVIDIA GeForce GTX 275", 7, 15, 11, 8618 },
904 {VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX280, "NVIDIA GeForce GTX 280", 7, 15, 11, 8618 },
905
906 /* ATI cards. The driver versions are somewhat similar, but not quite the same. Let's hardcode. */
907 {VENDOR_ATI, CARD_ATI_RADEON_9500, "ATI Radeon 9500", 6, 14, 10, 6764 },
908 {VENDOR_ATI, CARD_ATI_RADEON_X700, "ATI Radeon X700 SE", 6, 14, 10, 6764 },
909 {VENDOR_ATI, CARD_ATI_RADEON_X1600, "ATI Radeon X1600 Series", 6, 14, 10, 6764 },
910 {VENDOR_ATI, CARD_ATI_RADEON_HD2300, "ATI Mobility Radeon HD 2300", 6, 14, 10, 6764 },
911 {VENDOR_ATI, CARD_ATI_RADEON_HD2600, "ATI Mobility Radeon HD 2600", 6, 14, 10, 6764 },
912 {VENDOR_ATI, CARD_ATI_RADEON_HD2900, "ATI Radeon HD 2900 XT", 6, 14, 10, 6764 },
913 {VENDOR_ATI, CARD_ATI_RADEON_HD4350, "ATI Radeon HD 4350", 6, 14, 10, 6764 },
914 {VENDOR_ATI, CARD_ATI_RADEON_HD4600, "ATI Radeon HD 4600 Series", 6, 14, 10, 6764 },
915 {VENDOR_ATI, CARD_ATI_RADEON_HD4700, "ATI Radeon HD 4700 Series", 6, 14, 10, 6764 },
916 {VENDOR_ATI, CARD_ATI_RADEON_HD4800, "ATI Radeon HD 4800 Series", 6, 14, 10, 6764 },
917
918 /* TODO: Add information about legacy ATI hardware, Intel and other cards. */
919 };
920
921 /* Context activation is done by the caller. */
922 static void fixup_extensions(struct wined3d_gl_info *gl_info, const char *gl_renderer)
923 {
924 unsigned int i;
925
926 for (i = 0; i < (sizeof(quirk_table) / sizeof(*quirk_table)); ++i)
927 {
928 if (!quirk_table[i].match(gl_info, gl_renderer)) continue;
929 TRACE_(d3d_caps)("Applying driver quirk \"%s\".\n", quirk_table[i].description);
930 quirk_table[i].apply(gl_info);
931 }
932
933 /* Find out if PBOs work as they are supposed to. */
934 test_pbo_functionality(gl_info);
935
936 /* Fixup the driver version we'll report to the app. */
937 gl_info->driver_version = MAKEDWORD_VERSION(8, 6); /* Nvidia RIVA TNT, arbitrary */
938 gl_info->driver_version_hipart = MAKEDWORD_VERSION(7, 1);
939 for (i = 0; i < (sizeof(driver_version_table) / sizeof(driver_version_table[0])); ++i)
940 {
941 if (gl_info->gl_vendor == driver_version_table[i].vendor
942 && gl_info->gl_card == driver_version_table[i].card)
943 {
944 TRACE_(d3d_caps)("Found card 0x%04x, 0x%04x in driver version DB.\n",
945 gl_info->gl_vendor, gl_info->gl_card);
946
947 gl_info->driver_version = MAKEDWORD_VERSION(driver_version_table[i].lopart_hi,
948 driver_version_table[i].lopart_lo);
949 gl_info->driver_version_hipart = MAKEDWORD_VERSION(driver_version_table[i].hipart_hi,
950 driver_version_table[i].hipart_lo);
951 gl_info->driver_description = driver_version_table[i].description;
952 break;
953 }
954 }
955 TRACE_(d3d_caps)("Reporting (fake) driver version 0x%08X-0x%08X.\n",
956 gl_info->driver_version_hipart, gl_info->driver_version);
957 }
958
959 static DWORD wined3d_parse_gl_version(const char *gl_version)
960 {
961 const char *ptr = gl_version;
962 int major, minor;
963
964 major = atoi(ptr);
965 if (major <= 0) ERR_(d3d_caps)("Invalid opengl major version: %d.\n", major);
966
967 while (isdigit(*ptr)) ++ptr;
968 if (*ptr++ != '.') ERR_(d3d_caps)("Invalid opengl version string: %s.\n", debugstr_a(gl_version));
969
970 minor = atoi(ptr);
971
972 TRACE_(d3d_caps)("Found OpenGL version: %d.%d.\n", major, minor);
973
974 return MAKEDWORD_VERSION(major, minor);
975 }
976
977 static GL_Vendors wined3d_guess_vendor(const char *gl_vendor, const char *gl_renderer)
978 {
979 if (strstr(gl_vendor, "NVIDIA"))
980 return VENDOR_NVIDIA;
981
982 if (strstr(gl_vendor, "ATI"))
983 return VENDOR_ATI;
984
985 if (strstr(gl_vendor, "Intel(R)")
986 || strstr(gl_renderer, "Intel(R)")
987 || strstr(gl_vendor, "Intel Inc."))
988 return VENDOR_INTEL;
989
990 if (strstr(gl_vendor, "Mesa")
991 || strstr(gl_vendor, "DRI R300 Project")
992 || strstr(gl_vendor, "Tungsten Graphics, Inc"))
993 return VENDOR_MESA;
994
995 FIXME_(d3d_caps)("Received unrecognized GL_VENDOR %s. Returning VENDOR_WINE.\n", debugstr_a(gl_vendor));
996
997 return VENDOR_WINE;
998 }
999
1000 static GL_Cards wined3d_guess_card(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
1001 GL_Vendors *vendor, unsigned int *vidmem)
1002 {
1003 /* Below is a list of Nvidia and ATI GPUs. Both vendors have dozens of
1004 * different GPUs with roughly the same features. In most cases GPUs from a
1005 * certain family differ in clockspeeds, the amount of video memory and the
1006 * number of shader pipelines.
1007 *
1008 * A Direct3D device object contains the PCI id (vendor + device) of the
1009 * videocard which is used for rendering. Various applications use this
1010 * information to get a rough estimation of the features of the card and
1011 * some might use it for enabling 3d effects only on certain types of
1012 * videocards. In some cases games might even use it to work around bugs
1013 * which happen on certain videocards/driver combinations. The problem is
1014 * that OpenGL only exposes a rendering string containing the name of the
1015 * videocard and not the PCI id.
1016 *
1017 * Various games depend on the PCI id, so somehow we need to provide one.
1018 * A simple option is to parse the renderer string and translate this to
1019 * the right PCI id. This is a lot of work because there are more than 200
1020 * GPUs just for Nvidia. Various cards share the same renderer string, so
1021 * the amount of code might be 'small' but there are quite a number of
1022 * exceptions which would make this a pain to maintain. Another way would
1023 * be to query the PCI id from the operating system (assuming this is the
1024 * videocard which is used for rendering which is not always the case).
1025 * This would work but it is not very portable. Second it would not work
1026 * well in, let's say, a remote X situation in which the amount of 3d
1027 * features which can be used is limited.
1028 *
1029 * As said most games only use the PCI id to get an indication of the
1030 * capabilities of the card. It doesn't really matter if the given id is
1031 * the correct one if we return the id of a card with similar 3d features.
1032 *
1033 * The code below checks the OpenGL capabilities of a videocard and matches
1034 * that to a certain level of Direct3D functionality. Once a card passes
1035 * the Direct3D9 check, we know that the card (in case of Nvidia) is at
1036 * least a GeforceFX. To give a better estimate we do a basic check on the
1037 * renderer string but if that won't pass we return a default card. This
1038 * way is better than maintaining a full card database as even without a
1039 * full database we can return a card with similar features. Second the
1040 * size of the database can be made quite small because when you know what
1041 * type of 3d functionality a card has, you know to which GPU family the
1042 * GPU must belong. Because of this you only have to check a small part of
1043 * the renderer string to distinguishes between different models from that
1044 * family.
1045 *
1046 * The code also selects a default amount of video memory which we will
1047 * use for an estimation of the amount of free texture memory. In case of
1048 * real D3D the amount of texture memory includes video memory and system
1049 * memory (to be specific AGP memory or in case of PCIE TurboCache /
1050 * HyperMemory). We don't know how much system memory can be addressed by
1051 * the system but we can make a reasonable estimation about the amount of
1052 * video memory. If the value is slightly wrong it doesn't matter as we
1053 * didn't include AGP-like memory which makes the amount of addressable
1054 * memory higher and second OpenGL isn't that critical it moves to system
1055 * memory behind our backs if really needed. Note that the amount of video
1056 * memory can be overruled using a registry setting. */
1057
1058 switch (*vendor)
1059 {
1060 case VENDOR_NVIDIA:
1061 /* Both the GeforceFX, 6xxx and 7xxx series support D3D9. The last two types have more
1062 * shader capabilities, so we use the shader capabilities to distinguish between FX and 6xxx/7xxx.
1063 */
1064 if (WINE_D3D9_CAPABLE(gl_info) && gl_info->supported[NV_VERTEX_PROGRAM3])
1065 {
1066 /* Geforce 200 - highend */
1067 if (strstr(gl_renderer, "GTX 280")
1068 || strstr(gl_renderer, "GTX 285")
1069 || strstr(gl_renderer, "GTX 295"))
1070 {
1071 *vidmem = 1024;
1072 return CARD_NVIDIA_GEFORCE_GTX280;
1073 }
1074
1075 /* Geforce 200 - midend high */
1076 if (strstr(gl_renderer, "GTX 275"))
1077 {
1078 *vidmem = 896;
1079 return CARD_NVIDIA_GEFORCE_GTX275;
1080 }
1081
1082 /* Geforce 200 - midend */
1083 if (strstr(gl_renderer, "GTX 260"))
1084 {
1085 *vidmem = 1024;
1086 return CARD_NVIDIA_GEFORCE_GTX260;
1087 }
1088
1089 /* Geforce9 - highend / Geforce 200 - midend (GTS 150/250 are based on the same core) */
1090 if (strstr(gl_renderer, "9800")
1091 || strstr(gl_renderer, "GTS 150")
1092 || strstr(gl_renderer, "GTS 250"))
1093 {
1094 *vidmem = 512;
1095 return CARD_NVIDIA_GEFORCE_9800GT;
1096 }
1097
1098 /* Geforce9 - midend */
1099 if (strstr(gl_renderer, "9600"))
1100 {
1101 *vidmem = 384; /* The 9600GSO has 384MB, the 9600GT has 512-1024MB */
1102 return CARD_NVIDIA_GEFORCE_9600GT;
1103 }
1104
1105 /* Geforce9 - midend low / Geforce 200 - low */
1106 if (strstr(gl_renderer, "9500")
1107 || strstr(gl_renderer, "GT 120")
1108 || strstr(gl_renderer, "GT 130"))
1109 {
1110 *vidmem = 256; /* The 9500GT has 256-1024MB */
1111 return CARD_NVIDIA_GEFORCE_9500GT;
1112 }
1113
1114 /* Geforce9 - lowend */
1115 if (strstr(gl_renderer, "9400"))
1116 {
1117 *vidmem = 256; /* The 9400GT has 256-1024MB */
1118 return CARD_NVIDIA_GEFORCE_9400GT;
1119 }
1120
1121 /* Geforce9 - lowend low */
1122 if (strstr(gl_renderer, "9100")
1123 || strstr(gl_renderer, "9200")
1124 || strstr(gl_renderer, "9300")
1125 || strstr(gl_renderer, "G 100"))
1126 {
1127 *vidmem = 256; /* The 9100-9300 cards have 256MB */
1128 return CARD_NVIDIA_GEFORCE_9200;
1129 }
1130
1131 /* Geforce8 - highend */
1132 if (strstr(gl_renderer, "8800"))
1133 {
1134 *vidmem = 320; /* The 8800GTS uses 320MB, a 8800GTX can have 768MB */
1135 return CARD_NVIDIA_GEFORCE_8800GTS;
1136 }
1137
1138 /* Geforce8 - midend mobile */
1139 if (strstr(gl_renderer, "8600 M"))
1140 {
1141 *vidmem = 512;
1142 return CARD_NVIDIA_GEFORCE_8600MGT;
1143 }
1144
1145 /* Geforce8 - midend */
1146 if (strstr(gl_renderer, "8600")
1147 || strstr(gl_renderer, "8700"))
1148 {
1149 *vidmem = 256;
1150 return CARD_NVIDIA_GEFORCE_8600GT;
1151 }
1152
1153 /* Geforce8 - lowend */
1154 if (strstr(gl_renderer, "8300")
1155 || strstr(gl_renderer, "8400")
1156 || strstr(gl_renderer, "8500"))
1157 {
1158 *vidmem = 128; /* 128-256MB for a 8300, 256-512MB for a 8400 */
1159 return CARD_NVIDIA_GEFORCE_8300GS;
1160 }
1161
1162 /* Geforce7 - highend */
1163 if (strstr(gl_renderer, "7800")
1164 || strstr(gl_renderer, "7900")
1165 || strstr(gl_renderer, "7950")
1166 || strstr(gl_renderer, "Quadro FX 4")
1167 || strstr(gl_renderer, "Quadro FX 5"))
1168 {
1169 *vidmem = 256; /* A 7800GT uses 256MB while highend 7900 cards can use 512MB */
1170 return CARD_NVIDIA_GEFORCE_7800GT;
1171 }
1172
1173 /* Geforce7 midend */
1174 if (strstr(gl_renderer, "7600")
1175 || strstr(gl_renderer, "7700"))
1176 {
1177 *vidmem = 256; /* The 7600 uses 256-512MB */
1178 return CARD_NVIDIA_GEFORCE_7600;
1179 }
1180
1181 /* Geforce7 lower medium */
1182 if (strstr(gl_renderer, "7400"))
1183 {
1184 *vidmem = 256; /* The 7400 uses 256-512MB */
1185 return CARD_NVIDIA_GEFORCE_7400;
1186 }
1187
1188 /* Geforce7 lowend */
1189 if (strstr(gl_renderer, "7300"))
1190 {
1191 *vidmem = 256; /* Mac Pros with this card have 256 MB */
1192 return CARD_NVIDIA_GEFORCE_7300;
1193 }
1194
1195 /* Geforce6 highend */
1196 if (strstr(gl_renderer, "6800"))
1197 {
1198 *vidmem = 128; /* The 6800 uses 128-256MB, the 7600 uses 256-512MB */
1199 return CARD_NVIDIA_GEFORCE_6800;
1200 }
1201
1202 /* Geforce6 - midend */
1203 if (strstr(gl_renderer, "6600")
1204 || strstr(gl_renderer, "6610")
1205 || strstr(gl_renderer, "6700"))
1206 {
1207 *vidmem = 128; /* A 6600GT has 128-256MB */
1208 return CARD_NVIDIA_GEFORCE_6600GT;
1209 }
1210
1211 /* Geforce6/7 lowend */
1212 *vidmem = 64; /* */
1213 return CARD_NVIDIA_GEFORCE_6200; /* Geforce 6100/6150/6200/7300/7400/7500 */
1214 }
1215
1216 if (WINE_D3D9_CAPABLE(gl_info))
1217 {
1218 /* GeforceFX - highend */
1219 if (strstr(gl_renderer, "5800")
1220 || strstr(gl_renderer, "5900")
1221 || strstr(gl_renderer, "5950")
1222 || strstr(gl_renderer, "Quadro FX"))
1223 {
1224 *vidmem = 256; /* 5800-5900 cards use 256MB */
1225 return CARD_NVIDIA_GEFORCEFX_5800;
1226 }
1227
1228 /* GeforceFX - midend */
1229 if (strstr(gl_renderer, "5600")
1230 || strstr(gl_renderer, "5650")
1231 || strstr(gl_renderer, "5700")
1232 || strstr(gl_renderer, "5750"))
1233 {
1234 *vidmem = 128; /* A 5600 uses 128-256MB */
1235 return CARD_NVIDIA_GEFORCEFX_5600;
1236 }
1237
1238 /* GeforceFX - lowend */
1239 *vidmem = 64; /* Normal FX5200 cards use 64-256MB; laptop (non-standard) can have less */
1240 return CARD_NVIDIA_GEFORCEFX_5200; /* GeforceFX 5100/5200/5250/5300/5500 */
1241 }
1242
1243 if (WINE_D3D8_CAPABLE(gl_info))
1244 {
1245 if (strstr(gl_renderer, "GeForce4 Ti") || strstr(gl_renderer, "Quadro4"))
1246 {
1247 *vidmem = 64; /* Geforce4 Ti cards have 64-128MB */
1248 return CARD_NVIDIA_GEFORCE4_TI4200; /* Geforce4 Ti4200/Ti4400/Ti4600/Ti4800, Quadro4 */
1249 }
1250
1251 *vidmem = 64; /* Geforce3 cards have 64-128MB */
1252 return CARD_NVIDIA_GEFORCE3; /* Geforce3 standard/Ti200/Ti500, Quadro DCC */
1253 }
1254
1255 if (WINE_D3D7_CAPABLE(gl_info))
1256 {
1257 if (strstr(gl_renderer, "GeForce4 MX"))
1258 {
1259 /* Most Geforce4MX GPUs have at least 64MB of memory, some
1260 * early models had 32MB but most have 64MB or even 128MB. */
1261 *vidmem = 64;
1262 return CARD_NVIDIA_GEFORCE4_MX; /* MX420/MX440/MX460/MX4000 */
1263 }
1264
1265 if (strstr(gl_renderer, "GeForce2 MX") || strstr(gl_renderer, "Quadro2 MXR"))
1266 {
1267 *vidmem = 32; /* Geforce2MX GPUs have 32-64MB of video memory */
1268 return CARD_NVIDIA_GEFORCE2_MX; /* Geforce2 standard/MX100/MX200/MX400, Quadro2 MXR */
1269 }
1270
1271 if (strstr(gl_renderer, "GeForce2") || strstr(gl_renderer, "Quadro2"))
1272 {
1273 *vidmem = 32; /* Geforce2 GPUs have 32-64MB of video memory */
1274 return CARD_NVIDIA_GEFORCE2; /* Geforce2 GTS/Pro/Ti/Ultra, Quadro2 */
1275 }
1276
1277 /* Most Geforce1 cards have 32MB, there are also some rare 16
1278 * and 64MB (Dell) models. */
1279 *vidmem = 32;
1280 return CARD_NVIDIA_GEFORCE; /* Geforce 256/DDR, Quadro */
1281 }
1282
1283 if (strstr(gl_renderer, "TNT2"))
1284 {
1285 *vidmem = 32; /* Most TNT2 boards have 32MB, though there are 16MB boards too */
1286 return CARD_NVIDIA_RIVA_TNT2; /* Riva TNT2 standard/M64/Pro/Ultra */
1287 }
1288
1289 *vidmem = 16; /* Most TNT boards have 16MB, some rare models have 8MB */
1290 return CARD_NVIDIA_RIVA_TNT; /* Riva TNT, Vanta */
1291
1292 case VENDOR_ATI:
1293 /* See http://developer.amd.com/drivers/pc_vendor_id/Pages/default.aspx
1294 *
1295 * Beware: renderer string do not match exact card model,
1296 * eg HD 4800 is returned for multiple cards, even for RV790 based ones. */
1297 if (WINE_D3D9_CAPABLE(gl_info))
1298 {
1299 /* Radeon R7xx HD4800 - highend */
1300 if (strstr(gl_renderer, "HD 4800") /* Radeon RV7xx HD48xx generic renderer string */
1301 || strstr(gl_renderer, "HD 4830") /* Radeon RV770 */
1302 || strstr(gl_renderer, "HD 4850") /* Radeon RV770 */
1303 || strstr(gl_renderer, "HD 4870") /* Radeon RV770 */
1304 || strstr(gl_renderer, "HD 4890")) /* Radeon RV790 */
1305 {
1306 *vidmem = 512; /* note: HD4890 cards use 1024MB */
1307 return CARD_ATI_RADEON_HD4800;
1308 }
1309
1310 /* Radeon R740 HD4700 - midend */
1311 if (strstr(gl_renderer, "HD 4700") /* Radeon RV770 */
1312 || strstr(gl_renderer, "HD 4770")) /* Radeon RV740 */
1313 {
1314 *vidmem = 512;
1315 return CARD_ATI_RADEON_HD4700;
1316 }
1317
1318 /* Radeon R730 HD4600 - midend */
1319 if (strstr(gl_renderer, "HD 4600") /* Radeon RV730 */
1320 || strstr(gl_renderer, "HD 4650") /* Radeon RV730 */
1321 || strstr(gl_renderer, "HD 4670")) /* Radeon RV730 */
1322 {
1323 *vidmem = 512;
1324 return CARD_ATI_RADEON_HD4600;
1325 }
1326
1327 /* Radeon R710 HD4500/HD4350 - lowend */
1328 if (strstr(gl_renderer, "HD 4350") /* Radeon RV710 */
1329 || strstr(gl_renderer, "HD 4550")) /* Radeon RV710 */
1330 {
1331 *vidmem = 256;
1332 return CARD_ATI_RADEON_HD4350;
1333 }
1334
1335 /* Radeon R6xx HD2900/HD3800 - highend */
1336 if (strstr(gl_renderer, "HD 2900")
1337 || strstr(gl_renderer, "HD 3870")
1338 || strstr(gl_renderer, "HD 3850"))
1339 {
1340 *vidmem = 512; /* HD2900/HD3800 uses 256-1024MB */
1341 return CARD_ATI_RADEON_HD2900;
1342 }
1343
1344 /* Radeon R6xx HD2600/HD3600 - midend; HD3830 is China-only midend */
1345 if (strstr(gl_renderer, "HD 2600")
1346 || strstr(gl_renderer, "HD 3830")
1347 || strstr(gl_renderer, "HD 3690")
1348 || strstr(gl_renderer, "HD 3650"))
1349 {
1350 *vidmem = 256; /* HD2600/HD3600 uses 256-512MB */
1351 return CARD_ATI_RADEON_HD2600;
1352 }
1353
1354 /* Radeon R6xx HD2300/HD2400/HD3400 - lowend */
1355 if (strstr(gl_renderer, "HD 2300")
1356 || strstr(gl_renderer, "HD 2400")
1357 || strstr(gl_renderer, "HD 3470")
1358 || strstr(gl_renderer, "HD 3450")
1359 || strstr(gl_renderer, "HD 3430")
1360 || strstr(gl_renderer, "HD 3400"))
1361 {
1362 *vidmem = 128; /* HD2300 uses at least 128MB, HD2400 uses 256MB */
1363 return CARD_ATI_RADEON_HD2300;
1364 }
1365
1366 /* Radeon R6xx/R7xx integrated */
1367 if (strstr(gl_renderer, "HD 3100")
1368 || strstr(gl_renderer, "HD 3200")
1369 || strstr(gl_renderer, "HD 3300"))
1370 {
1371 *vidmem = 128; /* 128MB */
1372 return CARD_ATI_RADEON_HD3200;
1373 }
1374
1375 /* Radeon R5xx */
1376 if (strstr(gl_renderer, "X1600")
1377 || strstr(gl_renderer, "X1650")
1378 || strstr(gl_renderer, "X1800")
1379 || strstr(gl_renderer, "X1900")
1380 || strstr(gl_renderer, "X1950"))
1381 {
1382 *vidmem = 128; /* X1600 uses 128-256MB, >=X1800 uses 256MB */
1383 return CARD_ATI_RADEON_X1600;
1384 }
1385
1386 /* Radeon R4xx + X1300/X1400/X1450/X1550/X2300 (lowend R5xx) */
1387 if (strstr(gl_renderer, "X700")
1388 || strstr(gl_renderer, "X800")
1389 || strstr(gl_renderer, "X850")
1390 || strstr(gl_renderer, "X1300")
1391 || strstr(gl_renderer, "X1400")
1392 || strstr(gl_renderer, "X1450")
1393 || strstr(gl_renderer, "X1550"))
1394 {
1395 *vidmem = 128; /* x700/x8*0 use 128-256MB, >=x1300 128-512MB */
1396 return CARD_ATI_RADEON_X700;
1397 }
1398
1399 /* Radeon Xpress Series - onboard, DX9b, Shader 2.0, 300-400MHz */
1400 if (strstr(gl_renderer, "Radeon Xpress"))
1401 {
1402 *vidmem = 64; /* Shared RAM, BIOS configurable, 64-256M */
1403 return CARD_ATI_RADEON_XPRESS_200M;
1404 }
1405
1406 /* Radeon R3xx */
1407 *vidmem = 64; /* Radeon 9500 uses 64MB, higher models use up to 256MB */
1408 return CARD_ATI_RADEON_9500; /* Radeon 9500/9550/9600/9700/9800/X300/X550/X600 */
1409 }
1410
1411 if (WINE_D3D8_CAPABLE(gl_info))
1412 {
1413 *vidmem = 64; /* 8500/9000 cards use mostly 64MB, though there are 32MB and 128MB models */
1414 return CARD_ATI_RADEON_8500; /* Radeon 8500/9000/9100/9200/9300 */
1415 }
1416
1417 if (WINE_D3D7_CAPABLE(gl_info))
1418 {
1419 *vidmem = 32; /* There are models with up to 64MB */
1420 return CARD_ATI_RADEON_7200; /* Radeon 7000/7100/7200/7500 */
1421 }
1422
1423 *vidmem = 16; /* There are 16-32MB models */
1424 return CARD_ATI_RAGE_128PRO;
1425
1426 case VENDOR_INTEL:
1427 if (strstr(gl_renderer, "X3100"))
1428 {
1429 /* MacOS calls the card GMA X3100, Google findings also suggest the name GM965 */
1430 *vidmem = 128;
1431 return CARD_INTEL_X3100;
1432 }
1433
1434 if (strstr(gl_renderer, "GMA 950") || strstr(gl_renderer, "945GM"))
1435 {
1436 /* MacOS calls the card GMA 950, but everywhere else the PCI ID is named 945GM */
1437 *vidmem = 64;
1438 return CARD_INTEL_I945GM;
1439 }
1440
1441 if (strstr(gl_renderer, "915GM")) return CARD_INTEL_I915GM;
1442 if (strstr(gl_renderer, "915G")) return CARD_INTEL_I915G;
1443 if (strstr(gl_renderer, "865G")) return CARD_INTEL_I865G;
1444 if (strstr(gl_renderer, "855G")) return CARD_INTEL_I855G;
1445 if (strstr(gl_renderer, "830G")) return CARD_INTEL_I830G;
1446 return CARD_INTEL_I915G;
1447
1448 case VENDOR_MESA:
1449 case VENDOR_WINE:
1450 default:
1451 /* Default to generic Nvidia hardware based on the supported OpenGL extensions. The choice
1452 * for Nvidia was because the hardware and drivers they make are of good quality. This makes
1453 * them a good generic choice. */
1454 *vendor = VENDOR_NVIDIA;
1455 if (WINE_D3D9_CAPABLE(gl_info)) return CARD_NVIDIA_GEFORCEFX_5600;
1456 if (WINE_D3D8_CAPABLE(gl_info)) return CARD_NVIDIA_GEFORCE3;
1457 if (WINE_D3D7_CAPABLE(gl_info)) return CARD_NVIDIA_GEFORCE;
1458 if (WINE_D3D6_CAPABLE(gl_info)) return CARD_NVIDIA_RIVA_TNT;
1459 return CARD_NVIDIA_RIVA_128;
1460 }
1461 }
1462
1463 /* Context activation is done by the caller. */
1464 static BOOL IWineD3DImpl_FillGLCaps(struct wined3d_gl_info *gl_info)
1465 {
1466 const char *GL_Extensions = NULL;
1467 const char *WGL_Extensions = NULL;
1468 const char *gl_string = NULL;
1469 GLint gl_max;
1470 GLfloat gl_floatv[2];
1471 unsigned i;
1472 HDC hdc;
1473 unsigned int vidmem=0;
1474 char *gl_renderer;
1475 DWORD gl_version;
1476 size_t len;
1477
1478 TRACE_(d3d_caps)("(%p)\n", gl_info);
1479
1480 ENTER_GL();
1481
1482 gl_string = (const char *)glGetString(GL_RENDERER);
1483 TRACE_(d3d_caps)("GL_RENDERER: %s.\n", debugstr_a(gl_string));
1484 if (!gl_string)
1485 {
1486 LEAVE_GL();
1487 ERR_(d3d_caps)("Received a NULL GL_RENDERER.\n");
1488 return FALSE;
1489 }
1490
1491 len = strlen(gl_string) + 1;
1492 gl_renderer = HeapAlloc(GetProcessHeap(), 0, len);
1493 if (!gl_renderer)
1494 {
1495 LEAVE_GL();
1496 ERR_(d3d_caps)("Failed to allocate gl_renderer memory.\n");
1497 return FALSE;
1498 }
1499 memcpy(gl_renderer, gl_string, len);
1500
1501 gl_string = (const char *)glGetString(GL_VENDOR);
1502 TRACE_(d3d_caps)("GL_VENDOR: %s.\n", debugstr_a(gl_string));
1503 if (!gl_string)
1504 {
1505 LEAVE_GL();
1506 ERR_(d3d_caps)("Received a NULL GL_VENDOR.\n");
1507 HeapFree(GetProcessHeap(), 0, gl_renderer);
1508 return FALSE;
1509 }
1510 gl_info->gl_vendor = wined3d_guess_vendor(gl_string, gl_renderer);
1511 TRACE_(d3d_caps)("found GL_VENDOR (%s)->(0x%04x)\n", debugstr_a(gl_string), gl_info->gl_vendor);
1512
1513 /* Parse the GL_VERSION field into major and minor information */
1514 gl_string = (const char *)glGetString(GL_VERSION);
1515 TRACE_(d3d_caps)("GL_VERSION: %s.\n", debugstr_a(gl_string));
1516 if (!gl_string)
1517 {
1518 LEAVE_GL();
1519 ERR_(d3d_caps)("Received a NULL GL_VERSION.\n");
1520 HeapFree(GetProcessHeap(), 0, gl_renderer);
1521 return FALSE;
1522 }
1523 gl_version = wined3d_parse_gl_version(gl_string);
1524
1525 /*
1526 * Initialize openGL extension related variables
1527 * with Default values
1528 */
1529 memset(gl_info->supported, 0, sizeof(gl_info->supported));
1530 gl_info->max_buffers = 1;
1531 gl_info->max_textures = 1;
1532 gl_info->max_texture_stages = 1;
1533 gl_info->max_fragment_samplers = 1;
1534 gl_info->max_vertex_samplers = 0;
1535 gl_info->max_combined_samplers = gl_info->max_fragment_samplers + gl_info->max_vertex_samplers;
1536 gl_info->max_sampler_stages = 1;
1537 gl_info->ps_arb_max_temps = 0;
1538 gl_info->ps_arb_max_instructions = 0;
1539 gl_info->vs_arb_max_temps = 0;
1540 gl_info->vs_arb_max_instructions = 0;
1541 gl_info->vs_glsl_constantsF = 0;
1542 gl_info->ps_glsl_constantsF = 0;
1543 gl_info->vs_arb_constantsF = 0;
1544 gl_info->ps_arb_constantsF = 0;
1545 gl_info->ps_arb_max_local_constants = 0;
1546
1547 /* Retrieve opengl defaults */
1548 glGetIntegerv(GL_MAX_CLIP_PLANES, &gl_max);
1549 gl_info->max_clipplanes = min(WINED3DMAXUSERCLIPPLANES, gl_max);
1550 TRACE_(d3d_caps)("ClipPlanes support - num Planes=%d\n", gl_max);
1551
1552 glGetIntegerv(GL_MAX_LIGHTS, &gl_max);
1553 gl_info->max_lights = gl_max;
1554 TRACE_(d3d_caps)("Lights support - max lights=%d\n", gl_max);
1555
1556 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gl_max);
1557 gl_info->max_texture_size = gl_max;
1558 TRACE_(d3d_caps)("Maximum texture size support - max texture size=%d\n", gl_max);
1559
1560 glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, gl_floatv);
1561 gl_info->max_pointsizemin = gl_floatv[0];
1562 gl_info->max_pointsize = gl_floatv[1];
1563 TRACE_(d3d_caps)("Maximum point size support - max point size=%f\n", gl_floatv[1]);
1564
1565 /* Parse the gl supported features, in theory enabling parts of our code appropriately. */
1566 GL_Extensions = (const char *)glGetString(GL_EXTENSIONS);
1567 if (!GL_Extensions)
1568 {
1569 LEAVE_GL();
1570 ERR_(d3d_caps)("Received a NULL GL_EXTENSIONS.\n");
1571 HeapFree(GetProcessHeap(), 0, gl_renderer);
1572 return FALSE;
1573 }
1574
1575 LEAVE_GL();
1576
1577 TRACE_(d3d_caps)("GL_Extensions reported:\n");
1578
1579 gl_info->supported[WINED3D_GL_EXT_NONE] = TRUE;
1580
1581 while (*GL_Extensions)
1582 {
1583 const char *start;
1584 char current_ext[256];
1585
1586 while (isspace(*GL_Extensions)) ++GL_Extensions;
1587 start = GL_Extensions;
1588 while (!isspace(*GL_Extensions) && *GL_Extensions) ++GL_Extensions;
1589
1590 len = GL_Extensions - start;
1591 if (!len || len >= sizeof(current_ext)) continue;
1592
1593 memcpy(current_ext, start, len);
1594 current_ext[len] = '\0';
1595 TRACE_(d3d_caps)("- %s\n", debugstr_a(current_ext));
1596
1597 for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i)
1598 {
1599 if (!strcmp(current_ext, EXTENSION_MAP[i].extension_string))
1600 {
1601 TRACE_(d3d_caps)(" FOUND: %s support.\n", EXTENSION_MAP[i].extension_string);
1602 gl_info->supported[EXTENSION_MAP[i].extension] = TRUE;
1603 break;
1604 }
1605 }
1606 }
1607
1608 /* Now work out what GL support this card really has */
1609 #define USE_GL_FUNC(type, pfn, ext, replace) \
1610 { \
1611 DWORD ver = ver_for_ext(ext); \
1612 if (gl_info->supported[ext]) gl_info->pfn = (type)pwglGetProcAddress(#pfn); \
1613 else if (ver && ver <= gl_version) gl_info->pfn = (type)pwglGetProcAddress(#replace); \
1614 else gl_info->pfn = NULL; \
1615 }
1616 GL_EXT_FUNCS_GEN;
1617 #undef USE_GL_FUNC
1618
1619 #define USE_GL_FUNC(type, pfn, ext, replace) gl_info->pfn = (type)pwglGetProcAddress(#pfn);
1620 WGL_EXT_FUNCS_GEN;
1621 #undef USE_GL_FUNC
1622
1623 ENTER_GL();
1624
1625 /* Now mark all the extensions supported which are included in the opengl core version. Do this *after*
1626 * loading the functions, otherwise the code above will load the extension entry points instead of the
1627 * core functions, which may not work. */
1628 for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i)
1629 {
1630 if (!gl_info->supported[EXTENSION_MAP[i].extension]
1631 && EXTENSION_MAP[i].version <= gl_version && EXTENSION_MAP[i].version)
1632 {
1633 TRACE_(d3d_caps)(" GL CORE: %s support.\n", EXTENSION_MAP[i].extension_string);
1634 gl_info->supported[EXTENSION_MAP[i].extension] = TRUE;
1635 }
1636 }
1637
1638 if (gl_info->supported[APPLE_FENCE])
1639 {
1640 /* GL_NV_fence and GL_APPLE_fence provide the same functionality basically.
1641 * The apple extension interacts with some other apple exts. Disable the NV
1642 * extension if the apple one is support to prevent confusion in other parts
1643 * of the code. */
1644 gl_info->supported[NV_FENCE] = FALSE;
1645 }
1646 if (gl_info->supported[APPLE_FLOAT_PIXELS])
1647 {
1648 /* GL_APPLE_float_pixels == GL_ARB_texture_float + GL_ARB_half_float_pixel
1649 *
1650 * The enums are the same:
1651 * GL_RGBA16F_ARB = GL_RGBA_FLOAT16_APPLE = 0x881A
1652 * GL_RGB16F_ARB = GL_RGB_FLOAT16_APPLE = 0x881B
1653 * GL_RGBA32F_ARB = GL_RGBA_FLOAT32_APPLE = 0x8814
1654 * GL_RGB32F_ARB = GL_RGB_FLOAT32_APPLE = 0x8815
1655 * GL_HALF_FLOAT_ARB = GL_HALF_APPLE = 0x140B
1656 */
1657 if (!gl_info->supported[ARB_TEXTURE_FLOAT])
1658 {
1659 TRACE_(d3d_caps)(" IMPLIED: GL_ARB_texture_float support(from GL_APPLE_float_pixels.\n");
1660 gl_info->supported[ARB_TEXTURE_FLOAT] = TRUE;
1661 }
1662 if (!gl_info->supported[ARB_HALF_FLOAT_PIXEL])
1663 {
1664 TRACE_(d3d_caps)(" IMPLIED: GL_ARB_half_float_pixel support(from GL_APPLE_float_pixels.\n");
1665 gl_info->supported[ARB_HALF_FLOAT_PIXEL] = TRUE;
1666 }
1667 }
1668 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
1669 {
1670 TRACE_(d3d_caps)(" IMPLIED: NVIDIA (NV) Texture Gen Reflection support.\n");
1671 gl_info->supported[NV_TEXGEN_REFLECTION] = TRUE;
1672 }
1673 if (!gl_info->supported[ARB_DEPTH_CLAMP] && gl_info->supported[NV_DEPTH_CLAMP])
1674 {
1675 TRACE_(d3d_caps)(" IMPLIED: ARB_depth_clamp support (by NV_depth_clamp).\n");
1676 gl_info->supported[ARB_DEPTH_CLAMP] = TRUE;
1677 }
1678 if (gl_info->supported[NV_TEXTURE_SHADER2])
1679 {
1680 if (gl_info->supported[NV_REGISTER_COMBINERS])
1681 {
1682 /* Also disable ATI_FRAGMENT_SHADER if register combiners and texture_shader2
1683 * are supported. The nv extensions provide the same functionality as the
1684 * ATI one, and a bit more(signed pixelformats). */
1685 gl_info->supported[ATI_FRAGMENT_SHADER] = FALSE;
1686 }
1687 }
1688 if (gl_info->supported[ARB_DRAW_BUFFERS])
1689 {
1690 glGetIntegerv(GL_MAX_DRAW_BUFFERS_ARB, &gl_max);
1691 gl_info->max_buffers = gl_max;
1692 TRACE_(d3d_caps)("Max draw buffers: %u.\n", gl_max);
1693 }
1694 if (gl_info->supported[ARB_MULTITEXTURE])
1695 {
1696 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_max);
1697 gl_info->max_textures = min(MAX_TEXTURES, gl_max);
1698 TRACE_(d3d_caps)("Max textures: %d.\n", gl_info->max_textures);
1699
1700 if (gl_info->supported[NV_REGISTER_COMBINERS])
1701 {
1702 GLint tmp;
1703 glGetIntegerv(GL_MAX_GENERAL_COMBINERS_NV, &tmp);
1704 gl_info->max_texture_stages = min(MAX_TEXTURES, tmp);
1705 }
1706 else
1707 {
1708 gl_info->max_texture_stages = min(MAX_TEXTURES, gl_max);
1709 }
1710 TRACE_(d3d_caps)("Max texture stages: %d.\n", gl_info->max_texture_stages);
1711
1712 if (gl_info->supported[ARB_FRAGMENT_PROGRAM])
1713 {
1714 GLint tmp;
1715 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &tmp);
1716 gl_info->max_fragment_samplers = min(MAX_FRAGMENT_SAMPLERS, tmp);
1717 }
1718 else
1719 {
1720 gl_info->max_fragment_samplers = max(gl_info->max_fragment_samplers, gl_max);
1721 }
1722 TRACE_(d3d_caps)("Max fragment samplers: %d.\n", gl_info->max_fragment_samplers);
1723
1724 if (gl_info->supported[ARB_VERTEX_SHADER])
1725 {
1726 GLint tmp;
1727 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, &tmp);
1728 gl_info->max_vertex_samplers = tmp;
1729 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, &tmp);
1730 gl_info->max_combined_samplers = tmp;
1731
1732 /* Loading GLSL sampler uniforms is much simpler if we can assume that the sampler setup
1733 * is known at shader link time. In a vertex shader + pixel shader combination this isn't
1734 * an issue because then the sampler setup only depends on the two shaders. If a pixel
1735 * shader is used with fixed function vertex processing we're fine too because fixed function
1736 * vertex processing doesn't use any samplers. If fixed function fragment processing is
1737 * used we have to make sure that all vertex sampler setups are valid together with all
1738 * possible fixed function fragment processing setups. This is true if vsamplers + MAX_TEXTURES
1739 * <= max_samplers. This is true on all d3d9 cards that support vtf(gf 6 and gf7 cards).
1740 * dx9 radeon cards do not support vertex texture fetch. DX10 cards have 128 samplers, and
1741 * dx9 is limited to 8 fixed function texture stages and 4 vertex samplers. DX10 does not have
1742 * a fixed function pipeline anymore.
1743 *
1744 * So this is just a check to check that our assumption holds true. If not, write a warning
1745 * and reduce the number of vertex samplers or probably disable vertex texture fetch. */
1746 if (gl_info->max_vertex_samplers && gl_info->max_combined_samplers < 12
1747 && MAX_TEXTURES + gl_info->max_vertex_samplers > gl_info->max_combined_samplers)
1748 {
1749 FIXME("OpenGL implementation supports %u vertex samplers and %u total samplers.\n",
1750 gl_info->max_vertex_samplers, gl_info->max_combined_samplers);
1751 FIXME("Expected vertex samplers + MAX_TEXTURES(=8) > combined_samplers.\n");
1752 if (gl_info->max_combined_samplers > MAX_TEXTURES)
1753 gl_info->max_vertex_samplers = gl_info->max_combined_samplers - MAX_TEXTURES;
1754 else
1755 gl_info->max_vertex_samplers = 0;
1756 }
1757 }
1758 else
1759 {
1760 gl_info->max_combined_samplers = gl_info->max_fragment_samplers;
1761 }
1762 TRACE_(d3d_caps)("Max vertex samplers: %u.\n", gl_info->max_vertex_samplers);
1763 TRACE_(d3d_caps)("Max combined samplers: %u.\n", gl_info->max_combined_samplers);
1764 }
1765 if (gl_info->supported[ARB_VERTEX_BLEND])
1766 {
1767 glGetIntegerv(GL_MAX_VERTEX_UNITS_ARB, &gl_max);
1768 gl_info->max_blends = gl_max;
1769 TRACE_(d3d_caps)("Max blends: %u.\n", gl_info->max_blends);
1770 }
1771 if (gl_info->supported[EXT_TEXTURE3D])
1772 {
1773 glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE_EXT, &gl_max);
1774 gl_info->max_texture3d_size = gl_max;
1775 TRACE_(d3d_caps)("Max texture3D size: %d.\n", gl_info->max_texture3d_size);
1776 }
1777 if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
1778 {
1779 glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &gl_max);
1780 gl_info->max_anisotropy = gl_max;
1781 TRACE_(d3d_caps)("Max anisotropy: %d.\n", gl_info->max_anisotropy);
1782 }
1783 if (gl_info->supported[ARB_FRAGMENT_PROGRAM])
1784 {
1785 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, &gl_max));
1786 gl_info->ps_arb_constantsF = gl_max;
1787 TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM float constants: %d.\n", gl_info->ps_arb_constantsF);
1788 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl_max));
1789 gl_info->ps_arb_max_temps = gl_max;
1790 TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM native temporaries: %d.\n", gl_info->ps_arb_max_temps);
1791 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl_max));
1792 gl_info->ps_arb_max_instructions = gl_max;
1793 TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM native instructions: %d.\n", gl_info->ps_arb_max_instructions);
1794 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB, &gl_max));
1795 gl_info->ps_arb_max_local_constants = gl_max;
1796 TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM local parameters: %d.\n", gl_info->ps_arb_max_instructions);
1797 }
1798 if (gl_info->supported[ARB_VERTEX_PROGRAM])
1799 {
1800 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, &gl_max));
1801 gl_info->vs_arb_constantsF = gl_max;
1802 TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM float constants: %d.\n", gl_info->vs_arb_constantsF);
1803 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl_max));
1804 gl_info->vs_arb_max_temps = gl_max;
1805 TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM native temporaries: %d.\n", gl_info->vs_arb_max_temps);
1806 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl_max));
1807 gl_info->vs_arb_max_instructions = gl_max;
1808 TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM native instructions: %d.\n", gl_info->vs_arb_max_instructions);
1809
1810 if (test_arb_vs_offset_limit(gl_info)) gl_info->quirks |= WINED3D_QUIRK_ARB_VS_OFFSET_LIMIT;
1811 }
1812 if (gl_info->supported[ARB_VERTEX_SHADER])
1813 {
1814 glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, &gl_max);
1815 gl_info->vs_glsl_constantsF = gl_max / 4;
1816 TRACE_(d3d_caps)("Max ARB_VERTEX_SHADER float constants: %u.\n", gl_info->vs_glsl_constantsF);
1817 }
1818 if (gl_info->supported[ARB_FRAGMENT_SHADER])
1819 {
1820 glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB, &gl_max);
1821 gl_info->ps_glsl_constantsF = gl_max / 4;
1822 TRACE_(d3d_caps)("Max ARB_FRAGMENT_SHADER float constants: %u.\n", gl_info->ps_glsl_constantsF);
1823 glGetIntegerv(GL_MAX_VARYING_FLOATS_ARB, &gl_max);
1824 gl_info->max_glsl_varyings = gl_max;
1825 TRACE_(d3d_caps)("Max GLSL varyings: %u (%u 4 component varyings).\n", gl_max, gl_max / 4);
1826 }
1827 if (gl_info->supported[NV_LIGHT_MAX_EXPONENT])
1828 {
1829 glGetFloatv(GL_MAX_SHININESS_NV, &gl_info->max_shininess);
1830 }
1831 else
1832 {
1833 gl_info->max_shininess = 128.0f;
1834 }
1835 if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
1836 {
1837 /* If we have full NP2 texture support, disable
1838 * GL_ARB_texture_rectangle because we will never use it.
1839 * This saves a few redundant glDisable calls. */
1840 gl_info->supported[ARB_TEXTURE_RECTANGLE] = FALSE;
1841 }
1842 if (gl_info->supported[ATI_FRAGMENT_SHADER])
1843 {
1844 /* Disable NV_register_combiners and fragment shader if this is supported.
1845 * generally the NV extensions are preferred over the ATI ones, and this
1846 * extension is disabled if register_combiners and texture_shader2 are both
1847 * supported. So we reach this place only if we have incomplete NV dxlevel 8
1848 * fragment processing support. */
1849 gl_info->supported[NV_REGISTER_COMBINERS] = FALSE;
1850 gl_info->supported[NV_REGISTER_COMBINERS2] = FALSE;
1851 gl_info->supported[NV_TEXTURE_SHADER] = FALSE;
1852 gl_info->supported[NV_TEXTURE_SHADER2] = FALSE;
1853 gl_info->supported[NV_TEXTURE_SHADER3] = FALSE;
1854 }
1855 if (gl_info->supported[NV_HALF_FLOAT])
1856 {
1857 /* GL_ARB_half_float_vertex is a subset of GL_NV_half_float. */
1858 gl_info->supported[ARB_HALF_FLOAT_VERTEX] = TRUE;
1859 }
1860 if (gl_info->supported[ARB_POINT_SPRITE])
1861 {
1862 gl_info->max_point_sprite_units = gl_info->max_textures;
1863 }
1864 else
1865 {
1866 gl_info->max_point_sprite_units = 0;
1867 }
1868 checkGLcall("extension detection");
1869
1870 LEAVE_GL();
1871
1872 /* In some cases the number of texture stages can be larger than the number
1873 * of samplers. The GF4 for example can use only 2 samplers (no fragment
1874 * shaders), but 8 texture stages (register combiners). */
1875 gl_info->max_sampler_stages = max(gl_info->max_fragment_samplers, gl_info->max_texture_stages);
1876
1877 if (gl_info->supported[ARB_FRAMEBUFFER_OBJECT])
1878 {
1879 gl_info->fbo_ops.glIsRenderbuffer = gl_info->glIsRenderbuffer;
1880 gl_info->fbo_ops.glBindRenderbuffer = gl_info->glBindRenderbuffer;
1881 gl_info->fbo_ops.glDeleteRenderbuffers = gl_info->glDeleteRenderbuffers;
1882 gl_info->fbo_ops.glGenRenderbuffers = gl_info->glGenRenderbuffers;
1883 gl_info->fbo_ops.glRenderbufferStorage = gl_info->glRenderbufferStorage;
1884 gl_info->fbo_ops.glRenderbufferStorageMultisample = gl_info->glRenderbufferStorageMultisample;
1885 gl_info->fbo_ops.glGetRenderbufferParameteriv = gl_info->glGetRenderbufferParameteriv;
1886 gl_info->fbo_ops.glIsFramebuffer = gl_info->glIsFramebuffer;
1887 gl_info->fbo_ops.glBindFramebuffer = gl_info->glBindFramebuffer;
1888 gl_info->fbo_ops.glDeleteFramebuffers = gl_info->glDeleteFramebuffers;
1889 gl_info->fbo_ops.glGenFramebuffers = gl_info->glGenFramebuffers;
1890 gl_info->fbo_ops.glCheckFramebufferStatus = gl_info->glCheckFramebufferStatus;
1891 gl_info->fbo_ops.glFramebufferTexture1D = gl_info->glFramebufferTexture1D;
1892 gl_info->fbo_ops.glFramebufferTexture2D = gl_info->glFramebufferTexture2D;
1893 gl_info->fbo_ops.glFramebufferTexture3D = gl_info->glFramebufferTexture3D;
1894 gl_info->fbo_ops.glFramebufferRenderbuffer = gl_info->glFramebufferRenderbuffer;
1895 gl_info->fbo_ops.glGetFramebufferAttachmentParameteriv = gl_info->glGetFramebufferAttachmentParameteriv;
1896 gl_info->fbo_ops.glBlitFramebuffer = gl_info->glBlitFramebuffer;
1897 gl_info->fbo_ops.glGenerateMipmap = gl_info->glGenerateMipmap;
1898 }
1899 else
1900 {
1901 if (gl_info->supported[EXT_FRAMEBUFFER_OBJECT])
1902 {
1903 gl_info->fbo_ops.glIsRenderbuffer = gl_info->glIsRenderbufferEXT;
1904 gl_info->fbo_ops.glBindRenderbuffer = gl_info->glBindRenderbufferEXT;
1905 gl_info->fbo_ops.glDeleteRenderbuffers = gl_info->glDeleteRenderbuffersEXT;
1906 gl_info->fbo_ops.glGenRenderbuffers = gl_info->glGenRenderbuffersEXT;
1907 gl_info->fbo_ops.glRenderbufferStorage = gl_info->glRenderbufferStorageEXT;
1908 gl_info->fbo_ops.glGetRenderbufferParameteriv = gl_info->glGetRenderbufferParameterivEXT;
1909 gl_info->fbo_ops.glIsFramebuffer = gl_info->glIsFramebufferEXT;
1910 gl_info->fbo_ops.glBindFramebuffer = gl_info->glBindFramebufferEXT;
1911 gl_info->fbo_ops.glDeleteFramebuffers = gl_info->glDeleteFramebuffersEXT;
1912 gl_info->fbo_ops.glGenFramebuffers = gl_info->glGenFramebuffersEXT;
1913 gl_info->fbo_ops.glCheckFramebufferStatus = gl_info->glCheckFramebufferStatusEXT;
1914 gl_info->fbo_ops.glFramebufferTexture1D = gl_info->glFramebufferTexture1DEXT;
1915 gl_info->fbo_ops.glFramebufferTexture2D = gl_info->glFramebufferTexture2DEXT;
1916 gl_info->fbo_ops.glFramebufferTexture3D = gl_info->glFramebufferTexture3DEXT;
1917 gl_info->fbo_ops.glFramebufferRenderbuffer = gl_info->glFramebufferRenderbufferEXT;
1918 gl_info->fbo_ops.glGetFramebufferAttachmentParameteriv = gl_info->glGetFramebufferAttachmentParameterivEXT;
1919 gl_info->fbo_ops.glGenerateMipmap = gl_info->glGenerateMipmapEXT;
1920 }
1921 else if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
1922 {
1923 WARN_(d3d_caps)("Framebuffer objects not supported, falling back to backbuffer offscreen rendering mode.\n");
1924 wined3d_settings.offscreen_rendering_mode = ORM_BACKBUFFER;
1925 }
1926 if (gl_info->supported[EXT_FRAMEBUFFER_BLIT])
1927 {
1928 gl_info->fbo_ops.glBlitFramebuffer = gl_info->glBlitFramebufferEXT;
1929 }
1930 if (gl_info->supported[EXT_FRAMEBUFFER_MULTISAMPLE])
1931 {
1932 gl_info->fbo_ops.glRenderbufferStorageMultisample = gl_info->glRenderbufferStorageMultisampleEXT;
1933 }
1934 }
1935
1936 /* MRTs are currently only supported when FBOs are used. */
1937 if (wined3d_settings.offscreen_rendering_mode != ORM_FBO) {
1938 gl_info->max_buffers = 1;
1939 }
1940
1941 gl_info->gl_card = wined3d_guess_card(gl_info, gl_renderer, &gl_info->gl_vendor, &vidmem);
1942 TRACE_(d3d_caps)("FOUND (fake) card: 0x%x (vendor id), 0x%x (device id)\n", gl_info->gl_vendor, gl_info->gl_card);
1943
1944 /* If we have an estimate use it, else default to 64MB; */
1945 if(vidmem)
1946 gl_info->vidmem = vidmem*1024*1024; /* convert from MBs to bytes */
1947 else
1948 gl_info->vidmem = WINE_DEFAULT_VIDMEM;
1949
1950 /* Load all the lookup tables */
1951 for (i = 0; i < MAX_LOOKUPS; i++) {
1952 stateLookup[i] = HeapAlloc(GetProcessHeap(), 0, sizeof(*stateLookup[i]) * (1 + maxLookup[i] - minLookup[i]) );
1953 }
1954
1955 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_WRAP - minLookup[WINELOOKUP_WARPPARAM]] = GL_REPEAT;
1956 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_CLAMP - minLookup[WINELOOKUP_WARPPARAM]] = GL_CLAMP_TO_EDGE;
1957 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_BORDER - minLookup[WINELOOKUP_WARPPARAM]] =
1958 gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] ? GL_CLAMP_TO_BORDER_ARB : GL_REPEAT;
1959 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_BORDER - minLookup[WINELOOKUP_WARPPARAM]] =
1960 gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] ? GL_CLAMP_TO_BORDER_ARB : GL_REPEAT;
1961 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_MIRROR - minLookup[WINELOOKUP_WARPPARAM]] =
1962 gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT] ? GL_MIRRORED_REPEAT_ARB : GL_REPEAT;
1963 stateLookup[WINELOOKUP_WARPPARAM][WINED3DTADDRESS_MIRRORONCE - minLookup[WINELOOKUP_WARPPARAM]] =
1964 gl_info->supported[ATI_TEXTURE_MIRROR_ONCE] ? GL_MIRROR_CLAMP_TO_EDGE_ATI : GL_REPEAT;
1965
1966 /* Make sure there's an active HDC else the WGL extensions will fail */
1967 hdc = pwglGetCurrentDC();
1968 if (hdc) {
1969 /* Not all GL drivers might offer WGL extensions e.g. VirtualBox */
1970 if(GL_EXTCALL(wglGetExtensionsStringARB))
1971 WGL_Extensions = GL_EXTCALL(wglGetExtensionsStringARB(hdc));
1972
1973 if (NULL == WGL_Extensions) {
1974 ERR(" WGL_Extensions returns NULL\n");
1975 } else {
1976 TRACE_(d3d_caps)("WGL_Extensions reported:\n");
1977 while (*WGL_Extensions != 0x00) {
1978 const char *Start;
1979 char ThisExtn[256];
1980
1981 while (isspace(*WGL_Extensions)) WGL_Extensions++;
1982 Start = WGL_Extensions;
1983 while (!isspace(*WGL_Extensions) && *WGL_Extensions != 0x00) {
1984 WGL_Extensions++;
1985 }
1986
1987 len = WGL_Extensions - Start;
1988 if (len == 0 || len >= sizeof(ThisExtn))
1989 continue;
1990
1991 memcpy(ThisExtn, Start, len);
1992 ThisExtn[len] = '\0';
1993 TRACE_(d3d_caps)("- %s\n", debugstr_a(ThisExtn));
1994
1995 if (!strcmp(ThisExtn, "WGL_ARB_pbuffer")) {
1996 gl_info->supported[WGL_ARB_PBUFFER] = TRUE;
1997 TRACE_(d3d_caps)("FOUND: WGL_ARB_pbuffer support\n");
1998 }
1999 if (!strcmp(ThisExtn, "WGL_ARB_pixel_format")) {
2000 gl_info->supported[WGL_ARB_PIXEL_FORMAT] = TRUE;
2001 TRACE_(d3d_caps)("FOUND: WGL_ARB_pixel_format support\n");
2002 }
2003 if (!strcmp(ThisExtn, "WGL_WINE_pixel_format_passthrough")) {
2004 gl_info->supported[WGL_WINE_PIXEL_FORMAT_PASSTHROUGH] = TRUE;
2005 TRACE_(d3d_caps)("FOUND: WGL_WINE_pixel_format_passthrough support\n");
2006 }
2007 }
2008 }
2009 }
2010
2011 fixup_extensions(gl_info, gl_renderer);
2012 add_gl_compat_wrappers(gl_info);
2013
2014 HeapFree(GetProcessHeap(), 0, gl_renderer);
2015 return TRUE;
2016 }
2017
2018 /**********************************************************
2019 * IWineD3D implementation follows
2020 **********************************************************/
2021
2022 static UINT WINAPI IWineD3DImpl_GetAdapterCount (IWineD3D *iface) {
2023 IWineD3DImpl *This = (IWineD3DImpl *)iface;
2024
2025 TRACE_(d3d_caps)("(%p): Reporting %u adapters\n", This, This->adapter_count);
2026
2027 return This->adapter_count;
2028 }
2029
2030 static HRESULT WINAPI IWineD3DImpl_RegisterSoftwareDevice(IWineD3D *iface, void* pInitializeFunction) {
2031 IWineD3DImpl *This = (IWineD3DImpl *)iface;
2032 FIXME("(%p)->(%p): stub\n", This, pInitializeFunction);
2033 return WINED3D_OK;
2034 }
2035
2036 static HMONITOR WINAPI IWineD3DImpl_GetAdapterMonitor(IWineD3D *iface, UINT Adapter) {
2037 IWineD3DImpl *This = (IWineD3DImpl *)iface;
2038
2039 TRACE_(d3d_caps)("(%p)->(%d)\n", This, Adapter);
2040
2041 if (Adapter >= IWineD3DImpl_GetAdapterCount(iface)) {
2042 return NULL;
2043 }
2044
2045 return MonitorFromPoint(This->adapters[Adapter].monitorPoint, MONITOR_DEFAULTTOPRIMARY);
2046 }
2047
2048 /* FIXME: GetAdapterModeCount and EnumAdapterModes currently only returns modes
2049 of the same bpp but different resolutions */
2050
2051 /* Note: dx9 supplies a format. Calls from d3d8 supply WINED3DFMT_UNKNOWN */
2052 static UINT WINAPI IWineD3DImpl_GetAdapterModeCount(IWineD3D *iface, UINT Adapter, WINED3DFORMAT Format) {
2053 IWineD3DImpl *This = (IWineD3DImpl *)iface;
2054 TRACE_(d3d_caps)("(%p}->(Adapter: %d, Format: %s)\n", This, Adapter, debug_d3dformat(Format));
2055
2056 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
2057 return 0;
2058 }
2059
2060 /* TODO: Store modes per adapter and read it from the adapter structure */
2061 if (Adapter == 0) { /* Display */
2062 unsigned int i = 0;
2063 unsigned int j = 0;
2064 DEVMODEW mode;
2065
2066 memset(&mode, 0, sizeof(mode));
2067 mode.dmSize = sizeof(mode);
2068
2069 while (EnumDisplaySettingsExW(NULL, j, &mode, 0))
2070 {
2071 ++j;
2072 switch (Format)
2073 {
2074 case WINED3DFMT_UNKNOWN:
2075 /* This is for D3D8, do not enumerate P8 here */
2076 if (mode.dmBitsPerPel == 32 || mode.dmBitsPerPel == 16) ++i;
2077 break;
2078
2079 case WINED3DFMT_B8G8R8X8_UNORM:
2080 if (mode.dmBitsPerPel == 32) ++i;
2081 break;
2082
2083 case WINED3DFMT_B5G6R5_UNORM:
2084 if (mode.dmBitsPerPel == 16) ++i;
2085 break;
2086
2087 case WINED3DFMT_P8_UINT:
2088 if (mode.dmBitsPerPel == 8) ++i;
2089 break;
2090
2091 default:
2092 /* Skip other modes as they do not match the requested format */
2093 break;
2094 }
2095 }
2096
2097 TRACE_(d3d_caps)("(%p}->(Adapter: %d) => %d (out of %d)\n", This, Adapter, i, j);
2098 return i;
2099 } else {
2100 FIXME_(d3d_caps)("Adapter not primary display\n");
2101 }
2102 return 0;
2103 }
2104
2105 /* Note: dx9 supplies a format. Calls from d3d8 supply WINED3DFMT_UNKNOWN */
2106 static HRESULT WINAPI IWineD3DImpl_EnumAdapterModes(IWineD3D *iface, UINT Adapter, WINED3DFORMAT Format, UINT Mode, WINED3DDISPLAYMODE* pMode) {
2107 IWineD3DImpl *This = (IWineD3DImpl *)iface;
2108 TRACE_(d3d_caps)("(%p}->(Adapter:%d, mode:%d, pMode:%p, format:%s)\n", This, Adapter, Mode, pMode, debug_d3dformat(Format));
2109
2110 /* Validate the parameters as much as possible */
2111 if (NULL == pMode ||
2112 Adapter >= IWineD3DImpl_GetAdapterCount(iface) ||
2113 Mode >= IWineD3DImpl_GetAdapterModeCount(iface, Adapter, Format)) {
2114 return WINED3DERR_INVALIDCALL;
2115 }
2116
2117 /* TODO: Store modes per adapter and read it from the adapter structure */
2118 if (Adapter == 0)
2119 {
2120 DEVMODEW DevModeW;
2121 int ModeIdx = 0;
2122 UINT i = 0;
2123 int j = 0;
2124
2125 ZeroMemory(&DevModeW, sizeof(DevModeW));
2126 DevModeW.dmSize = sizeof(DevModeW);
2127
2128 /* If we are filtering to a specific format (D3D9), then need to skip
2129 all unrelated modes, but if mode is irrelevant (D3D8), then we can
2130 just count through the ones with valid bit depths */
2131 while ((i<=Mode) && EnumDisplaySettingsExW(NULL, j++, &DevModeW, 0)) {
2132 switch (Format)
2133 {
2134 case WINED3DFMT_UNKNOWN:
2135 /* This is D3D8. Do not enumerate P8 here */
2136 if (DevModeW.dmBitsPerPel == 32 ||
2137 DevModeW.dmBitsPerPel == 16) i++;
2138 break;
2139 case WINED3DFMT_B8G8R8X8_UNORM:
2140 if (DevModeW.dmBitsPerPel == 32) i++;
2141 break;
2142 case WINED3DFMT_B5G6R5_UNORM:
2143 if (DevModeW.dmBitsPerPel == 16) i++;
2144 break;
2145 case WINED3DFMT_P8_UINT:
2146 if (DevModeW.dmBitsPerPel == 8) i++;
2147 break;
2148 default:
2149 /* Modes that don't match what we support can get an early-out */
2150 TRACE_(d3d_caps)("Searching for %s, returning D3DERR_INVALIDCALL\n", debug_d3dformat(Format));
2151 return WINED3DERR_INVALIDCALL;
2152 }
2153 }
2154
2155 if (i == 0) {
2156 TRACE_(d3d_caps)("No modes found for format (%x - %s)\n", Format, debug_d3dformat(Format));
2157 return WINED3DERR_INVALIDCALL;
2158 }
2159 ModeIdx = j - 1;
2160
2161 /* Now get the display mode via the calculated index */
2162 if (EnumDisplaySettingsExW(NULL, ModeIdx, &DevModeW, 0)) {
2163 pMode->Width = DevModeW.dmPelsWidth;
2164 pMode->Height = DevModeW.dmPelsHeight;
2165 pMode->RefreshRate = DEFAULT_REFRESH_RATE;
2166 if (DevModeW.dmFields & DM_DISPLAYFREQUENCY)
2167 pMode->RefreshRate = DevModeW.dmDisplayFrequency;
2168
2169 if (Format == WINED3DFMT_UNKNOWN) {
2170 pMode->Format = pixelformat_for_depth(DevModeW.dmBitsPerPel);
2171 } else {
2172 pMode->Format = Format;
2173 }
2174 } else {
2175 TRACE_(d3d_caps)("Requested mode out of range %d\n", Mode);
2176 return WINED3DERR_INVALIDCALL;
2177 }
2178
2179 TRACE_(d3d_caps)("W %d H %d rr %d fmt (%x - %s) bpp %u\n", pMode->Width, pMode->Height,
2180 pMode->RefreshRate, pMode->Format, debug_d3dformat(pMode->Format),
2181 DevModeW.dmBitsPerPel);
2182
2183 }
2184 else
2185 {
2186 FIXME_(d3d_caps)("Adapter not primary display\n");
2187 }
2188
2189 return WINED3D_OK;
2190 }
2191
2192 static HRESULT WINAPI IWineD3DImpl_GetAdapterDisplayMode(IWineD3D *iface, UINT Adapter, WINED3DDISPLAYMODE* pMode) {
2193 IWineD3DImpl *This = (IWineD3DImpl *)iface;
2194 TRACE_(d3d_caps)("(%p}->(Adapter: %d, pMode: %p)\n", This, Adapter, pMode);
2195
2196 if (NULL == pMode ||
2197 Adapter >= IWineD3D_GetAdapterCount(iface)) {
2198 return WINED3DERR_INVALIDCALL;
2199 }
2200
2201 if (Adapter == 0) { /* Display */
2202 int bpp = 0;
2203 DEVMODEW DevModeW;
2204
2205 ZeroMemory(&DevModeW, sizeof(DevModeW));
2206 DevModeW.dmSize = sizeof(DevModeW);
2207
2208 EnumDisplaySettingsExW(NULL, ENUM_CURRENT_SETTINGS, &DevModeW, 0);
2209 pMode->Width = DevModeW.dmPelsWidth;
2210 pMode->Height = DevModeW.dmPelsHeight;
2211 bpp = DevModeW.dmBitsPerPel;
2212 pMode->RefreshRate = DEFAULT_REFRESH_RATE;
2213 if (DevModeW.dmFields&DM_DISPLAYFREQUENCY)
2214 {
2215 pMode->RefreshRate = DevModeW.dmDisplayFrequency;
2216 }
2217
2218 pMode->Format = pixelformat_for_depth(bpp);
2219 } else {
2220 FIXME_(d3d_caps)("Adapter not primary display\n");
2221 }
2222
2223 TRACE_(d3d_caps)("returning w:%d, h:%d, ref:%d, fmt:%s\n", pMode->Width,
2224 pMode->Height, pMode->RefreshRate, debug_d3dformat(pMode->Format));
2225 return WINED3D_OK;
2226 }
2227
2228 /* NOTE: due to structure differences between dx8 and dx9 D3DADAPTER_IDENTIFIER,
2229 and fields being inserted in the middle, a new structure is used in place */
2230 static HRESULT WINAPI IWineD3DImpl_GetAdapterIdentifier(IWineD3D *iface, UINT Adapter, DWORD Flags,
2231 WINED3DADAPTER_IDENTIFIER* pIdentifier) {
2232 IWineD3DImpl *This = (IWineD3DImpl *)iface;
2233 size_t len;
2234
2235 TRACE_(d3d_caps)("(%p}->(Adapter: %d, Flags: %x, pId=%p)\n", This, Adapter, Flags, pIdentifier);
2236
2237 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
2238 return WINED3DERR_INVALIDCALL;
2239 }
2240
2241 /* Return the information requested */
2242 TRACE_(d3d_caps)("device/Vendor Name and Version detection using FillGLCaps\n");
2243
2244 if (pIdentifier->driver_size)
2245 {
2246 len = min(strlen(This->adapters[Adapter].driver), pIdentifier->driver_size - 1);
2247 memcpy(pIdentifier->driver, This->adapters[Adapter].driver, len);
2248 pIdentifier->driver[len] = '\0';
2249 }
2250
2251 if (pIdentifier->description_size)
2252 {
2253 const char *description;
2254
2255 if (This->adapters[Adapter].gl_info.driver_description)
2256 description = This->adapters[Adapter].gl_info.driver_description;
2257 else
2258 description = This->adapters[Adapter].description;
2259
2260 len = min(strlen(description), pIdentifier->description_size - 1);
2261 memcpy(pIdentifier->description, description, len);
2262 pIdentifier->description[len] = '\0';
2263 }
2264
2265 /* Note that d3d8 doesn't supply a device name. */
2266 if (pIdentifier->device_name_size)
2267 {
2268 static const char *device_name = "\\\\.\\DISPLAY1"; /* FIXME: May depend on desktop? */
2269
2270 len = strlen(device_name);
2271 if (len >= pIdentifier->device_name_size)
2272 {
2273 ERR("Device name size too small.\n");
2274 return WINED3DERR_INVALIDCALL;
2275 }
2276
2277 memcpy(pIdentifier->device_name, device_name, len);
2278 pIdentifier->device_name[len] = '\0';
2279 }
2280
2281 pIdentifier->driver_version.u.HighPart = This->adapters[Adapter].gl_info.driver_version_hipart;
2282 pIdentifier->driver_version.u.LowPart = This->adapters[Adapter].gl_info.driver_version;
2283 pIdentifier->vendor_id = This->adapters[Adapter].gl_info.gl_vendor;
2284 pIdentifier->device_id = This->adapters[Adapter].gl_info.gl_card;
2285 pIdentifier->subsystem_id = 0;
2286 pIdentifier->revision = 0;
2287 memcpy(&pIdentifier->device_identifier, &IID_D3DDEVICE_D3DUID, sizeof(pIdentifier->device_identifier));
2288
2289 if(wined3d_settings.pci_device_id != PCI_DEVICE_NONE)
2290 {
2291 TRACE_(d3d_caps)("Overriding pci device id with: %x\n", wined3d_settings.pci_device_id);
2292 pIdentifier->device_id = wined3d_settings.pci_device_id;
2293 }
2294
2295 if(wined3d_settings.pci_vendor_id != PCI_VENDOR_NONE)
2296 {
2297 TRACE_(d3d_caps)("Overriding pci vendor id with: %x\n", wined3d_settings.pci_vendor_id);
2298 pIdentifier->vendor_id = wined3d_settings.pci_vendor_id;
2299 }
2300
2301 pIdentifier->whql_level = (Flags & WINED3DENUM_NO_WHQL_LEVEL) ? 0 : 1;
2302
2303 return WINED3D_OK;
2304 }
2305
2306 static BOOL IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(const struct wined3d_gl_info *gl_info,
2307 const WineD3D_PixelFormat *cfg, const struct GlPixelFormatDesc *format_desc)
2308 {
2309 short redSize, greenSize, blueSize, alphaSize, colorBits;
2310
2311 if(!cfg)
2312 return FALSE;
2313
2314 if(cfg->iPixelType == WGL_TYPE_RGBA_ARB) { /* Integer RGBA formats */
2315 if (!getColorBits(format_desc, &redSize, &greenSize, &blueSize, &alphaSize, &colorBits))
2316 {
2317 ERR("Unable to check compatibility for Format=%s\n", debug_d3dformat(format_desc->format));
2318 return FALSE;
2319 }
2320
2321 if(cfg->redSize < redSize)
2322 return FALSE;
2323
2324 if(cfg->greenSize < greenSize)
2325 return FALSE;
2326
2327 if(cfg->blueSize < blueSize)
2328 return FALSE;
2329
2330 if(cfg->alphaSize < alphaSize)
2331 return FALSE;
2332
2333 return TRUE;
2334 } else if(cfg->iPixelType == WGL_TYPE_RGBA_FLOAT_ARB) { /* Float RGBA formats; TODO: WGL_NV_float_buffer */
2335 if (format_desc->format == WINED3DFMT_R16_FLOAT)
2336 return (cfg->redSize == 16 && cfg->greenSize == 0 && cfg->blueSize == 0 && cfg->alphaSize == 0);
2337 if (format_desc->format == WINED3DFMT_R16G16_FLOAT)
2338 return (cfg->redSize == 16 && cfg->greenSize == 16 && cfg->blueSize == 0 && cfg->alphaSize == 0);
2339 if (format_desc->format == WINED3DFMT_R16G16B16A16_FLOAT)
2340 return (cfg->redSize == 16 && cfg->greenSize == 16 && cfg->blueSize == 16 && cfg->alphaSize == 16);
2341 if (format_desc->format == WINED3DFMT_R32_FLOAT)
2342 return (cfg->redSize == 32 && cfg->greenSize == 0 && cfg->blueSize == 0 && cfg->alphaSize == 0);
2343 if (format_desc->format == WINED3DFMT_R32G32_FLOAT)
2344 return (cfg->redSize == 32 && cfg->greenSize == 32 && cfg->blueSize == 0 && cfg->alphaSize == 0);
2345 if (format_desc->format == WINED3DFMT_R32G32B32A32_FLOAT)
2346 return (cfg->redSize == 32 && cfg->greenSize == 32 && cfg->blueSize == 32 && cfg->alphaSize == 32);
2347 } else {
2348 /* Probably a color index mode */
2349 return FALSE;
2350 }
2351
2352 return FALSE;
2353 }
2354
2355 static BOOL IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(const struct wined3d_gl_info *gl_info,
2356 const WineD3D_PixelFormat *cfg, const struct GlPixelFormatDesc *format_desc)
2357 {
2358 short depthSize, stencilSize;
2359 BOOL lockable = FALSE;
2360
2361 if(!cfg)
2362 return FALSE;
2363
2364 if (!getDepthStencilBits(format_desc, &depthSize, &stencilSize))
2365 {
2366 ERR("Unable to check compatibility for Format=%s\n", debug_d3dformat(format_desc->format));
2367 return FALSE;
2368 }
2369
2370 if ((format_desc->format == WINED3DFMT_D16_LOCKABLE) || (format_desc->format == WINED3DFMT_D32_FLOAT))
2371 lockable = TRUE;
2372
2373 /* On some modern cards like the Geforce8/9 GLX doesn't offer some dephthstencil formats which D3D9 reports.
2374 * We can safely report 'compatible' formats (e.g. D24 can be used for D16) as long as we aren't dealing with
2375 * a lockable format. This also helps D3D <= 7 as they expect D16 which isn't offered without this on Geforce8 cards. */
2376 if(!(cfg->depthSize == depthSize || (!lockable && cfg->depthSize > depthSize)))
2377 return FALSE;
2378
2379 /* Some cards like Intel i915 ones only offer D24S8 but lots of games also need a format without stencil, so
2380 * allow more stencil bits than requested. */
2381 if(cfg->stencilSize < stencilSize)
2382 return FALSE;
2383
2384 return TRUE;
2385 }
2386
2387 static HRESULT WINAPI IWineD3DImpl_CheckDepthStencilMatch(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
2388 WINED3DFORMAT AdapterFormat,
2389 WINED3DFORMAT RenderTargetFormat,
2390 WINED3DFORMAT DepthStencilFormat) {
2391 IWineD3DImpl *This = (IWineD3DImpl *)iface;
2392 int nCfgs;
2393 const WineD3D_PixelFormat *cfgs;
2394 const struct WineD3DAdapter *adapter;
2395 const struct GlPixelFormatDesc *rt_format_desc;
2396 const struct GlPixelFormatDesc *ds_format_desc;
2397 int it;
2398
2399 WARN_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%x,%s), AdptFmt:(%x,%s), RendrTgtFmt:(%x,%s), DepthStencilFmt:(%x,%s))\n",
2400 This, Adapter,
2401 DeviceType, debug_d3ddevicetype(DeviceType),
2402 AdapterFormat, debug_d3dformat(AdapterFormat),
2403 RenderTargetFormat, debug_d3dformat(RenderTargetFormat),
2404 DepthStencilFormat, debug_d3dformat(DepthStencilFormat));
2405
2406 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
2407 TRACE("(%p) Failed: Atapter (%u) higher than supported adapters (%u) returning WINED3DERR_INVALIDCALL\n", This, Adapter, IWineD3D_GetAdapterCount(iface));
2408 return WINED3DERR_INVALIDCALL;
2409 }
2410
2411 adapter = &This->adapters[Adapter];
2412 rt_format_desc = getFormatDescEntry(RenderTargetFormat, &adapter->gl_info);
2413 ds_format_desc = getFormatDescEntry(DepthStencilFormat, &adapter->gl_info);
2414 cfgs = adapter->cfgs;
2415 nCfgs = adapter->nCfgs;
2416 for (it = 0; it < nCfgs; ++it) {
2417 if (IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&adapter->gl_info, &cfgs[it], rt_format_desc))
2418 {
2419 if (IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(&adapter->gl_info, &cfgs[it], ds_format_desc))
2420 {
2421 TRACE_(d3d_caps)("(%p) : Formats matched\n", This);
2422 return WINED3D_OK;
2423 }
2424 }
2425 }
2426 WARN_(d3d_caps)("unsupported format pair: %s and %s\n", debug_d3dformat(RenderTargetFormat), debug_d3dformat(DepthStencilFormat));
2427
2428 return WINED3DERR_NOTAVAILABLE;
2429 }
2430
2431 static HRESULT WINAPI IWineD3DImpl_CheckDeviceMultiSampleType(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
2432 WINED3DFORMAT SurfaceFormat, BOOL Windowed, WINED3DMULTISAMPLE_TYPE MultiSampleType, DWORD *pQualityLevels)
2433 {
2434 IWineD3DImpl *This = (IWineD3DImpl *)iface;
2435 const struct GlPixelFormatDesc *glDesc;
2436 const struct WineD3DAdapter *adapter;
2437
2438 TRACE_(d3d_caps)("(%p)-> (Adptr:%d, DevType:(%x,%s), SurfFmt:(%x,%s), Win?%d, MultiSamp:%x, pQual:%p)\n",
2439 This,
2440 Adapter,
2441 DeviceType, debug_d3ddevicetype(DeviceType),
2442 SurfaceFormat, debug_d3dformat(SurfaceFormat),
2443 Windowed,
2444 MultiSampleType,
2445 pQualityLevels);
2446
2447 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
2448 return WINED3DERR_INVALIDCALL;
2449 }
2450
2451 /* TODO: handle Windowed, add more quality levels */
2452
2453 if (WINED3DMULTISAMPLE_NONE == MultiSampleType) {
2454 if(pQualityLevels) *pQualityLevels = 1;
2455 return WINED3D_OK;
2456 }
2457
2458 /* By default multisampling is disabled right now as it causes issues
2459 * on some Nvidia driver versions and it doesn't work well in combination
2460 * with FBOs yet. */
2461 if(!wined3d_settings.allow_multisampling)
2462 return WINED3DERR_NOTAVAILABLE;
2463
2464 adapter = &This->adapters[Adapter];
2465 glDesc = getFormatDescEntry(SurfaceFormat, &adapter->gl_info);
2466 if (!glDesc) return WINED3DERR_INVALIDCALL;
2467
2468 if(glDesc->Flags & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL)) {
2469 int i, nCfgs;
2470 const WineD3D_PixelFormat *cfgs;
2471
2472 cfgs = adapter->cfgs;
2473 nCfgs = adapter->nCfgs;
2474 for(i=0; i<nCfgs; i++) {
2475 if(cfgs[i].numSamples != MultiSampleType)
2476 continue;
2477
2478 if (!IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(&adapter->gl_info, &cfgs[i], glDesc))
2479 continue;
2480
2481 TRACE("Found iPixelFormat=%d to support MultiSampleType=%d for format %s\n", cfgs[i].iPixelFormat, MultiSampleType, debug_d3dformat(SurfaceFormat));
2482
2483 if(pQualityLevels)
2484 *pQualityLevels = 1; /* Guess at a value! */
2485 return WINED3D_OK;
2486 }
2487 }
2488 else if(glDesc->Flags & WINED3DFMT_FLAG_RENDERTARGET) {
2489 short redSize, greenSize, blueSize, alphaSize, colorBits;
2490 int i, nCfgs;
2491 const WineD3D_PixelFormat *cfgs;
2492
2493 if (!getColorBits(glDesc, &redSize, &greenSize, &blueSize, &alphaSize, &colorBits))
2494 {
2495 ERR("Unable to color bits for format %#x, can't check multisampling capability!\n", SurfaceFormat);
2496 return WINED3DERR_NOTAVAILABLE;
2497 }
2498
2499 cfgs = adapter->cfgs;
2500 nCfgs = adapter->nCfgs;
2501 for(i=0; i<nCfgs; i++) {
2502 if(cfgs[i].numSamples != MultiSampleType)
2503 continue;
2504 if(cfgs[i].redSize != redSize)
2505 continue;
2506 if(cfgs[i].greenSize != greenSize)
2507 continue;
2508 if(cfgs[i].blueSize != blueSize)
2509 continue;
2510 if(cfgs[i].alphaSize != alphaSize)
2511 continue;
2512
2513 TRACE("Found iPixelFormat=%d to support MultiSampleType=%d for format %s\n", cfgs[i].iPixelFormat, MultiSampleType, debug_d3dformat(SurfaceFormat));
2514
2515 if(pQualityLevels)
2516 *pQualityLevels = 1; /* Guess at a value! */
2517 return WINED3D_OK;
2518 }
2519 }
2520 return WINED3DERR_NOTAVAILABLE;
2521 }
2522
2523 static HRESULT WINAPI IWineD3DImpl_CheckDeviceType(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
2524 WINED3DFORMAT DisplayFormat, WINED3DFORMAT BackBufferFormat, BOOL Windowed) {
2525
2526 IWineD3DImpl *This = (IWineD3DImpl *)iface;
2527 HRESULT hr = WINED3DERR_NOTAVAILABLE;
2528 UINT nmodes;
2529
2530 TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, CheckType:(%x,%s), DispFmt:(%x,%s), BackBuf:(%x,%s), Win?%d): stub\n",
2531 This,
2532 Adapter,
2533 DeviceType, debug_d3ddevicetype(DeviceType),
2534 DisplayFormat, debug_d3dformat(DisplayFormat),
2535 BackBufferFormat, debug_d3dformat(BackBufferFormat),
2536 Windowed);
2537
2538 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
2539 WARN_(d3d_caps)("Adapter >= IWineD3D_GetAdapterCount(iface), returning WINED3DERR_INVALIDCALL\n");
2540 return WINED3DERR_INVALIDCALL;
2541 }
2542
2543 /* The task of this function is to check whether a certain display / backbuffer format
2544 * combination is available on the given adapter. In fullscreen mode microsoft specified
2545 * that the display format shouldn't provide alpha and that ignoring alpha the backbuffer
2546 * and display format should match exactly.
2547 * In windowed mode format conversion can occur and this depends on the driver. When format
2548 * conversion is done, this function should nevertheless fail and applications need to use
2549 * CheckDeviceFormatConversion.
2550 * At the moment we assume that fullscreen and windowed have the same capabilities */
2551
2552 /* There are only 4 display formats */
2553 if (!(DisplayFormat == WINED3DFMT_B5G6R5_UNORM
2554 || DisplayFormat == WINED3DFMT_B5G5R5X1_UNORM
2555 || DisplayFormat == WINED3DFMT_B8G8R8X8_UNORM
2556 || DisplayFormat == WINED3DFMT_B10G10R10A2_UNORM))
2557 {
2558 TRACE_(d3d_caps)("Format %s unsupported as display format\n", debug_d3dformat(DisplayFormat));
2559 return WINED3DERR_NOTAVAILABLE;
2560 }
2561
2562 /* If the requested DisplayFormat is not available, don't continue */
2563 nmodes = IWineD3DImpl_GetAdapterModeCount(iface, Adapter, DisplayFormat);
2564 if(!nmodes) {
2565 TRACE_(d3d_caps)("No available modes for display format %s\n", debug_d3dformat(DisplayFormat));
2566 return WINED3DERR_NOTAVAILABLE;
2567 }
2568
2569 /* Windowed mode allows you to specify WINED3DFMT_UNKNOWN for the backbufferformat, it means 'reuse' the display format for the backbuffer */
2570 if(!Windowed && BackBufferFormat == WINED3DFMT_UNKNOWN) {
2571 TRACE_(d3d_caps)("BackBufferFormat WINED3FMT_UNKNOWN not available in Windowed mode\n");
2572 return WINED3DERR_NOTAVAILABLE;
2573 }
2574
2575 /* In FULLSCREEN mode R5G6B5 can only be mixed with backbuffer format R5G6B5 */
2576 if (DisplayFormat == WINED3DFMT_B5G6R5_UNORM && BackBufferFormat != WINED3DFMT_B5G6R5_UNORM)
2577 {
2578 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
2579 return WINED3DERR_NOTAVAILABLE;
2580 }
2581
2582 /* In FULLSCREEN mode X1R5G5B5 can only be mixed with backbuffer format *1R5G5B5 */
2583 if (DisplayFormat == WINED3DFMT_B5G5R5X1_UNORM
2584 && !(BackBufferFormat == WINED3DFMT_B5G5R5X1_UNORM || BackBufferFormat == WINED3DFMT_B5G5R5A1_UNORM))
2585 {
2586 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
2587 return WINED3DERR_NOTAVAILABLE;
2588 }
2589
2590 /* In FULLSCREEN mode X8R8G8B8 can only be mixed with backbuffer format *8R8G8B8 */
2591 if (DisplayFormat == WINED3DFMT_B8G8R8X8_UNORM
2592 && !(BackBufferFormat == WINED3DFMT_B8G8R8X8_UNORM || BackBufferFormat == WINED3DFMT_B8G8R8A8_UNORM))
2593 {
2594 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
2595 return WINED3DERR_NOTAVAILABLE;
2596 }
2597
2598 /* A2R10G10B10 is only allowed in fullscreen mode and it can only be mixed with backbuffer format A2R10G10B10 */
2599 if (DisplayFormat == WINED3DFMT_B10G10R10A2_UNORM
2600 && (BackBufferFormat != WINED3DFMT_B10G10R10A2_UNORM || Windowed))
2601 {
2602 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
2603 return WINED3DERR_NOTAVAILABLE;
2604 }
2605
2606 /* Use CheckDeviceFormat to see if the BackBufferFormat is usable with the given DisplayFormat */
2607 hr = IWineD3DImpl_CheckDeviceFormat(iface, Adapter, DeviceType, DisplayFormat, WINED3DUSAGE_RENDERTARGET, WINED3DRTYPE_SURFACE, BackBufferFormat, SURFACE_OPENGL);
2608 if(FAILED(hr))
2609 TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
2610
2611 return hr;
2612 }
2613
2614
2615 /* Check if we support bumpmapping for a format */
2616 static BOOL CheckBumpMapCapability(struct WineD3DAdapter *adapter,
2617 WINED3DDEVTYPE DeviceType, const struct GlPixelFormatDesc *format_desc)
2618 {
2619 const struct fragment_pipeline *fp;
2620
2621 switch(format_desc->format)
2622 {
2623 case WINED3DFMT_R8G8_SNORM:
2624 case WINED3DFMT_R16G16_SNORM:
2625 case WINED3DFMT_R5G5_SNORM_L6_UNORM:
2626 case WINED3DFMT_R8G8_SNORM_L8X8_UNORM:
2627 case WINED3DFMT_R8G8B8A8_SNORM:
2628 /* Ask the fixed function pipeline implementation if it can deal
2629 * with the conversion. If we've got a GL extension giving native
2630 * support this will be an identity conversion. */
2631 fp = select_fragment_implementation(adapter, DeviceType);
2632 if (fp->color_fixup_supported(format_desc->color_fixup))
2633 {
2634 TRACE_(d3d_caps)("[OK]\n");
2635 return TRUE;
2636 }
2637 TRACE_(d3d_caps)("[FAILED]\n");
2638 return FALSE;
2639
2640 default:
2641 TRACE_(d3d_caps)("[FAILED]\n");
2642 return FALSE;
2643 }
2644 }
2645
2646 /* Check if the given DisplayFormat + DepthStencilFormat combination is valid for the Adapter */
2647 static BOOL CheckDepthStencilCapability(struct WineD3DAdapter *adapter,
2648 const struct GlPixelFormatDesc *display_format_desc, const struct GlPixelFormatDesc *ds_format_desc)
2649 {
2650 int it=0;
2651
2652 /* Only allow depth/stencil formats */
2653 if (!(ds_format_desc->depth_size || ds_format_desc->stencil_size)) return FALSE;
2654
2655 /* Walk through all WGL pixel formats to find a match */
2656 for (it = 0; it < adapter->nCfgs; ++it)
2657 {
2658 WineD3D_PixelFormat *cfg = &adapter->cfgs[it];
2659 if (IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&adapter->gl_info, cfg, display_format_desc))
2660 {
2661 if (IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(&adapter->gl_info, cfg, ds_format_desc))
2662 {
2663 return TRUE;
2664 }
2665 }
2666 }
2667
2668 return FALSE;
2669 }
2670
2671 static BOOL CheckFilterCapability(struct WineD3DAdapter *adapter, const struct GlPixelFormatDesc *format_desc)
2672 {
2673 /* The flags entry of a format contains the filtering capability */
2674 if (format_desc->Flags & WINED3DFMT_FLAG_FILTERING) return TRUE;
2675
2676 return FALSE;
2677 }
2678
2679 /* Check the render target capabilities of a format */
2680 static BOOL CheckRenderTargetCapability(struct WineD3DAdapter *adapter,
2681 const struct GlPixelFormatDesc *adapter_format_desc, const struct GlPixelFormatDesc *check_format_desc)
2682 {
2683 /* Filter out non-RT formats */
2684 if (!(check_format_desc->Flags & WINED3DFMT_FLAG_RENDERTARGET)) return FALSE;
2685
2686 if(wined3d_settings.offscreen_rendering_mode == ORM_BACKBUFFER) {
2687 WineD3D_PixelFormat *cfgs = adapter->cfgs;
2688 int it;
2689 short AdapterRed, AdapterGreen, AdapterBlue, AdapterAlpha, AdapterTotalSize;
2690 short CheckRed, CheckGreen, CheckBlue, CheckAlpha, CheckTotalSize;
2691
2692 getColorBits(adapter_format_desc, &AdapterRed, &AdapterGreen, &AdapterBlue, &AdapterAlpha, &AdapterTotalSize);
2693 getColorBits(check_format_desc, &CheckRed, &CheckGreen, &CheckBlue, &CheckAlpha, &CheckTotalSize);
2694
2695 /* In backbuffer mode the front and backbuffer share the same WGL pixelformat.
2696 * The format must match in RGB, alpha is allowed to be different. (Only the backbuffer can have alpha) */
2697 if(!((AdapterRed == CheckRed) && (AdapterGreen == CheckGreen) && (AdapterBlue == CheckBlue))) {
2698 TRACE_(d3d_caps)("[FAILED]\n");
2699 return FALSE;
2700 }
2701
2702 /* Check if there is a WGL pixel format matching the requirements, the format should also be window
2703 * drawable (not offscreen; e.g. Nvidia offers R5G6B5 for pbuffers even when X is running at 24bit) */
2704 for (it = 0; it < adapter->nCfgs; ++it)
2705 {
2706 if (cfgs[it].windowDrawable && IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&adapter->gl_info,
2707 &cfgs[it], check_format_desc))
2708 {
2709 TRACE_(d3d_caps)("iPixelFormat=%d is compatible with CheckFormat=%s\n",
2710 cfgs[it].iPixelFormat, debug_d3dformat(check_format_desc->format));
2711 return TRUE;
2712 }
2713 }
2714 } else if(wined3d_settings.offscreen_rendering_mode == ORM_PBUFFER) {
2715 /* We can probably use this function in FBO mode too on some drivers to get some basic indication of the capabilities. */
2716 WineD3D_PixelFormat *cfgs = adapter->cfgs;
2717 int it;
2718
2719 /* Check if there is a WGL pixel format matching the requirements, the pixel format should also be usable with pbuffers */
2720 for (it = 0; it < adapter->nCfgs; ++it)
2721 {
2722 if (cfgs[it].pbufferDrawable && IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&adapter->gl_info,
2723 &cfgs[it], check_format_desc))
2724 {
2725 TRACE_(d3d_caps)("iPixelFormat=%d is compatible with CheckFormat=%s\n",
2726 cfgs[it].iPixelFormat, debug_d3dformat(check_format_desc->format));
2727 return TRUE;
2728 }
2729 }
2730 } else if(wined3d_settings.offscreen_rendering_mode == ORM_FBO){
2731 /* For now return TRUE for FBOs until we have some proper checks.
2732 * Note that this function will only be called when the format is around for texturing. */
2733 return TRUE;
2734 }
2735 return FALSE;
2736 }
2737
2738 static BOOL CheckSrgbReadCapability(struct WineD3DAdapter *adapter, const struct GlPixelFormatDesc *format_desc)
2739 {
2740 const struct wined3d_gl_info *gl_info = &adapter->gl_info;
2741
2742 /* Check for supported sRGB formats (Texture loading and framebuffer) */
2743 if(!GL_SUPPORT(EXT_TEXTURE_SRGB)) {
2744 TRACE_(d3d_caps)("[FAILED] GL_EXT_texture_sRGB not supported\n");
2745 return FALSE;
2746 }
2747
2748 switch (format_desc->format)
2749 {
2750 case WINED3DFMT_B8G8R8A8_UNORM:
2751 case WINED3DFMT_B8G8R8X8_UNORM:
2752 case WINED3DFMT_B4G4R4A4_UNORM:
2753 case WINED3DFMT_L8_UNORM:
2754 case WINED3DFMT_L8A8_UNORM:
2755 case WINED3DFMT_DXT1:
2756 case WINED3DFMT_DXT2:
2757 case WINED3DFMT_DXT3:
2758 case WINED3DFMT_DXT4:
2759 case WINED3DFMT_DXT5:
2760 TRACE_(d3d_caps)("[OK]\n");
2761 return TRUE;
2762
2763 default:
2764 TRACE_(d3d_caps)("[FAILED] Gamma texture format %s not supported.\n", debug_d3dformat(format_desc->format));
2765 return FALSE;
2766 }
2767 return FALSE;
2768 }
2769
2770 static BOOL CheckSrgbWriteCapability(struct WineD3DAdapter *adapter,
2771 WINED3DDEVTYPE DeviceType, const struct GlPixelFormatDesc *format_desc)
2772 {
2773 /* Only offer SRGB writing on X8R8G8B8/A8R8G8B8 when we use ARB or GLSL shaders as we are
2774 * doing the color fixup in shaders.
2775 * Note Windows drivers (at least on the Geforce 8800) also offer this on R5G6B5. */
2776 if ((format_desc->format == WINED3DFMT_B8G8R8X8_UNORM) || (format_desc->format == WINED3DFMT_B8G8R8A8_UNORM))
2777 {
2778 int vs_selected_mode;
2779 int ps_selected_mode;
2780 select_shader_mode(&adapter->gl_info, &ps_selected_mode, &vs_selected_mode);
2781
2782 if((ps_selected_mode == SHADER_ARB) || (ps_selected_mode == SHADER_GLSL)) {
2783 TRACE_(d3d_caps)("[OK]\n");
2784 return TRUE;
2785 }
2786 }
2787
2788 TRACE_(d3d_caps)("[FAILED] - no SRGB writing support on format=%s\n", debug_d3dformat(format_desc->format));
2789 return FALSE;
2790 }
2791
2792 /* Check if a format support blending in combination with pixel shaders */
2793 static BOOL CheckPostPixelShaderBlendingCapability(struct WineD3DAdapter *adapter,
2794 const struct GlPixelFormatDesc *format_desc)
2795 {
2796 /* The flags entry of a format contains the post pixel shader blending capability */
2797 if (format_desc->Flags & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING) return TRUE;
2798
2799 return FALSE;
2800 }
2801
2802 static BOOL CheckWrapAndMipCapability(struct WineD3DAdapter *adapter, const struct GlPixelFormatDesc *format_desc)
2803 {
2804 /* OpenGL supports mipmapping on all formats basically. Wrapping is unsupported,
2805 * but we have to report mipmapping so we cannot reject this flag. Tests show that
2806 * windows reports WRAPANDMIP on unfilterable surfaces as well, apparently to show
2807 * that wrapping is supported. The lack of filtering will sort out the mipmapping
2808 * capability anyway.
2809 *
2810 * For now lets report this on all formats, but in the future we may want to
2811 * restrict it to some should games need that
2812 */
2813 return TRUE;
2814 }
2815
2816 /* Check if a texture format is supported on the given adapter */
2817 static BOOL CheckTextureCapability(struct WineD3DAdapter *adapter,
2818 WINED3DDEVTYPE DeviceType, const struct GlPixelFormatDesc *format_desc)
2819 {
2820 const struct wined3d_gl_info *gl_info = &adapter->gl_info;
2821 const shader_backend_t *shader_backend;
2822 const struct fragment_pipeline *fp;
2823
2824 switch (format_desc->format)
2825 {
2826 /*****
2827 * supported: RGB(A) formats
2828 */
2829 case WINED3DFMT_B8G8R8_UNORM: /* Enable for dx7, blacklisted for 8 and 9 above */
2830 case WINED3DFMT_B8G8R8A8_UNORM:
2831 case WINED3DFMT_B8G8R8X8_UNORM:
2832 case WINED3DFMT_B5G6R5_UNORM:
2833 case WINED3DFMT_B5G5R5X1_UNORM:
2834 case WINED3DFMT_B5G5R5A1_UNORM:
2835 case WINED3DFMT_B4G4R4A4_UNORM:
2836 case WINED3DFMT_A8_UNORM:
2837 case WINED3DFMT_B4G4R4X4_UNORM:
2838 case WINED3DFMT_R8G8B8A8_UNORM:
2839 case WINED3DFMT_R8G8B8X8_UNORM:
2840 case WINED3DFMT_B10G10R10A2_UNORM:
2841 case WINED3DFMT_R10G10B10A2_UNORM:
2842 case WINED3DFMT_R16G16_UNORM:
2843 TRACE_(d3d_caps)("[OK]\n");
2844 return TRUE;
2845
2846 case WINED3DFMT_B2G3R3_UNORM:
2847 TRACE_(d3d_caps)("[FAILED] - Not supported on Windows\n");
2848 return FALSE;
2849
2850 /*****
2851 * supported: Palettized
2852 */
2853 case WINED3DFMT_P8_UINT:
2854 TRACE_(d3d_caps)("[OK]\n");
2855 return TRUE;
2856 /* No Windows driver offers WINED3DFMT_P8_UINT_A8_UNORM, so don't offer it either */
2857 case WINED3DFMT_P8_UINT_A8_UNORM:
2858 return FALSE;
2859
2860 /*****
2861 * Supported: (Alpha)-Luminance
2862 */
2863 case WINED3DFMT_L8_UNORM:
2864 case WINED3DFMT_L8A8_UNORM:
2865 case WINED3DFMT_L16_UNORM:
2866 TRACE_(d3d_caps)("[OK]\n");
2867 return TRUE;
2868
2869 /* Not supported on Windows, thus disabled */
2870 case WINED3DFMT_L4A4_UNORM:
2871 TRACE_(d3d_caps)("[FAILED] - not supported on windows\n");
2872 return FALSE;
2873
2874 /*****
2875 * Supported: Depth/Stencil formats
2876 */
2877 case WINED3DFMT_D16_LOCKABLE:
2878 case WINED3DFMT_D16_UNORM:
2879 case WINED3DFMT_S1_UINT_D15_UNORM:
2880 case WINED3DFMT_X8D24_UNORM:
2881 case WINED3DFMT_S4X4_UINT_D24_UNORM:
2882 case WINED3DFMT_S8_UINT_D24_UNORM:
2883 case WINED3DFMT_S8_UINT_D24_FLOAT:
2884 case WINED3DFMT_D32_UNORM:
2885 case WINED3DFMT_D32_FLOAT:
2886 return TRUE;
2887
2888 /*****
2889 * Not supported everywhere(depends on GL_ATI_envmap_bumpmap or
2890 * GL_NV_texture_shader). Emulated by shaders
2891 */
2892 case WINED3DFMT_R8G8_SNORM:
2893 case WINED3DFMT_R8G8_SNORM_L8X8_UNORM:
2894 case WINED3DFMT_R5G5_SNORM_L6_UNORM:
2895 case WINED3DFMT_R8G8B8A8_SNORM:
2896 case WINED3DFMT_R16G16_SNORM:
2897 /* Ask the shader backend if it can deal with the conversion. If
2898 * we've got a GL extension giving native support this will be an
2899 * identity conversion. */
2900 shader_backend = select_shader_backend(adapter, DeviceType);
2901 if (shader_backend->shader_color_fixup_supported(format_desc->color_fixup))
2902 {
2903 TRACE_(d3d_caps)("[OK]\n");
2904 return TRUE;
2905 }
2906 TRACE_(d3d_caps)("[FAILED]\n");
2907 return FALSE;
2908
2909 case WINED3DFMT_DXT1:
2910 case WINED3DFMT_DXT2:
2911 case WINED3DFMT_DXT3:
2912 case WINED3DFMT_DXT4:
2913 case WINED3DFMT_DXT5:
2914 if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
2915 TRACE_(d3d_caps)("[OK]\n");
2916 return TRUE;
2917 }
2918 TRACE_(d3d_caps)("[FAILED]\n");
2919 return FALSE;
2920
2921
2922 /*****
2923 * Odd formats - not supported
2924 */
2925 case WINED3DFMT_VERTEXDATA:
2926 case WINED3DFMT_R16_UINT:
2927 case WINED3DFMT_R32_UINT:
2928 case WINED3DFMT_R16G16B16A16_SNORM:
2929 case WINED3DFMT_R10G10B10_SNORM_A2_UNORM:
2930 case WINED3DFMT_R10G11B11_SNORM:
2931 TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
2932 return FALSE;
2933
2934 /*****
2935 * WINED3DFMT_R8G8_SNORM_Cx: Not supported right now
2936 */
2937 case WINED3DFMT_R8G8_SNORM_Cx:
2938 TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
2939 return FALSE;
2940
2941 /* YUV formats */
2942 case WINED3DFMT_UYVY:
2943 case WINED3DFMT_YUY2:
2944 if(GL_SUPPORT(APPLE_YCBCR_422)) {
2945 TRACE_(d3d_caps)("[OK]\n");
2946 return TRUE;
2947 }
2948 TRACE_(d3d_caps)("[FAILED]\n");
2949 return FALSE;
2950 case WINED3DFMT_YV12:
2951 TRACE_(d3d_caps)("[FAILED]\n");
2952 return FALSE;
2953
2954 /* Not supported */
2955 case WINED3DFMT_R16G16B16A16_UNORM:
2956 case WINED3DFMT_B2G3R3A8_UNORM:
2957 TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
2958 return FALSE;
2959
2960 /* Floating point formats */
2961 case WINED3DFMT_R16_FLOAT:
2962 case WINED3DFMT_R16G16_FLOAT:
2963 case WINED3DFMT_R16G16B16A16_FLOAT:
2964 if(GL_SUPPORT(ARB_TEXTURE_FLOAT) && GL_SUPPORT(ARB_HALF_FLOAT_PIXEL)) {
2965 TRACE_(d3d_caps)("[OK]\n");
2966 return TRUE;
2967 }
2968 TRACE_(d3d_caps)("[FAILED]\n");
2969 return FALSE;
2970
2971 case WINED3DFMT_R32_FLOAT:
2972 case WINED3DFMT_R32G32_FLOAT:
2973 case WINED3DFMT_R32G32B32A32_FLOAT:
2974 if (GL_SUPPORT(ARB_TEXTURE_FLOAT)) {
2975 TRACE_(d3d_caps)("[OK]\n");
2976 return TRUE;
2977 }
2978 TRACE_(d3d_caps)("[FAILED]\n");
2979 return FALSE;
2980
2981 /* ATI instancing hack: Although ATI cards do not support Shader Model 3.0, they support
2982 * instancing. To query if the card supports instancing CheckDeviceFormat with the special format
2983 * MAKEFOURCC('I','N','S','T') is used. Should a (broken) app check for this provide a proper return value.
2984 * We can do instancing with all shader versions, but we need vertex shaders.
2985 *
2986 * Additionally applications have to set the D3DRS_POINTSIZE render state to MAKEFOURCC('I','N','S','T') once
2987 * to enable instancing. WineD3D doesn't need that and just ignores it.
2988 *
2989 * With Shader Model 3.0 capable cards Instancing 'just works' in Windows.
2990 */
2991 case WINEMAKEFOURCC('I','N','S','T'):
2992 TRACE("ATI Instancing check hack\n");
2993 if(GL_SUPPORT(ARB_VERTEX_PROGRAM) || GL_SUPPORT(ARB_VERTEX_SHADER)) {
2994 TRACE_(d3d_caps)("[OK]\n");
2995 return TRUE;
2996 }
2997 TRACE_(d3d_caps)("[FAILED]\n");
2998 return FALSE;
2999
3000 /* Some weird FOURCC formats */
3001 case WINED3DFMT_R8G8_B8G8:
3002 case WINED3DFMT_G8R8_G8B8:
3003 case WINED3DFMT_MULTI2_ARGB8:
3004 TRACE_(d3d_caps)("[FAILED]\n");
3005 return FALSE;
3006
3007 /* Vendor specific formats */
3008 case WINED3DFMT_ATI2N:
3009 if(GL_SUPPORT(ATI_TEXTURE_COMPRESSION_3DC) || GL_SUPPORT(EXT_TEXTURE_COMPRESSION_RGTC)) {
3010 shader_backend = select_shader_backend(adapter, DeviceType);
3011 fp = select_fragment_implementation(adapter, DeviceType);
3012 if (shader_backend->shader_color_fixup_supported(format_desc->color_fixup)
3013 && fp->color_fixup_supported(format_desc->color_fixup))
3014 {
3015 TRACE_(d3d_caps)("[OK]\n");
3016 return TRUE;
3017 }
3018
3019 TRACE_(d3d_caps)("[OK]\n");
3020 return TRUE;
3021 }
3022 TRACE_(d3d_caps)("[FAILED]\n");
3023 return FALSE;
3024
3025 case WINED3DFMT_NVHU:
3026 case WINED3DFMT_NVHS:
3027 /* These formats seem to be similar to the HILO formats in GL_NV_texture_shader. NVHU
3028 * is said to be GL_UNSIGNED_HILO16, NVHS GL_SIGNED_HILO16. Rumours say that d3d computes
3029 * a 3rd channel similarly to D3DFMT_CxV8U8(So NVHS could be called D3DFMT_CxV16U16).
3030 * ATI refused to support formats which can easilly be emulated with pixel shaders, so
3031 * Applications have to deal with not having NVHS and NVHU.
3032 */
3033 TRACE_(d3d_caps)("[FAILED]\n");
3034 return FALSE;
3035
3036 case WINED3DFMT_UNKNOWN:
3037 return FALSE;
3038
3039 default:
3040 ERR("Unhandled format=%s\n", debug_d3dformat(format_desc->format));
3041 break;
3042 }
3043 return FALSE;
3044 }
3045
3046 static BOOL CheckSurfaceCapability(struct WineD3DAdapter *adapter, const struct GlPixelFormatDesc *adapter_format_desc,
3047 WINED3DDEVTYPE DeviceType, const struct GlPixelFormatDesc *check_format_desc, WINED3DSURFTYPE SurfaceType)
3048 {
3049 const struct blit_shader *blitter;
3050
3051 if(SurfaceType == SURFACE_GDI) {
3052 switch(check_format_desc->format)
3053 {
3054 case WINED3DFMT_B8G8R8_UNORM:
3055 case WINED3DFMT_B8G8R8A8_UNORM:
3056 case WINED3DFMT_B8G8R8X8_UNORM:
3057 case WINED3DFMT_B5G6R5_UNORM:
3058 case WINED3DFMT_B5G5R5X1_UNORM:
3059 case WINED3DFMT_B5G5R5A1_UNORM:
3060 case WINED3DFMT_B4G4R4A4_UNORM:
3061 case WINED3DFMT_B2G3R3_UNORM:
3062 case WINED3DFMT_A8_UNORM:
3063 case WINED3DFMT_B2G3R3A8_UNORM:
3064 case WINED3DFMT_B4G4R4X4_UNORM:
3065 case WINED3DFMT_R10G10B10A2_UNORM:
3066 case WINED3DFMT_R8G8B8A8_UNORM:
3067 case WINED3DFMT_R8G8B8X8_UNORM:
3068 case WINED3DFMT_R16G16_UNORM:
3069 case WINED3DFMT_B10G10R10A2_UNORM:
3070 case WINED3DFMT_R16G16B16A16_UNORM:
3071 case WINED3DFMT_P8_UINT:
3072 TRACE_(d3d_caps)("[OK]\n");
3073 return TRUE;
3074 default:
3075 TRACE_(d3d_caps)("[FAILED] - not available on GDI surfaces\n");
3076 return FALSE;
3077 }
3078 }
3079
3080 /* All format that are supported for textures are supported for surfaces as well */
3081 if (CheckTextureCapability(adapter, DeviceType, check_format_desc)) return TRUE;
3082 /* All depth stencil formats are supported on surfaces */
3083 if (CheckDepthStencilCapability(adapter, adapter_format_desc, check_format_desc)) return TRUE;
3084
3085 /* If opengl can't process the format natively, the blitter may be able to convert it */
3086 blitter = select_blit_implementation(adapter, DeviceType);
3087 if (blitter->color_fixup_supported(check_format_desc->color_fixup))
3088 {
3089 TRACE_(d3d_caps)("[OK]\n");
3090 return TRUE;
3091 }
3092
3093 /* Reject other formats */
3094 TRACE_(d3d_caps)("[FAILED]\n");
3095 return FALSE;
3096 }
3097
3098 static BOOL CheckVertexTextureCapability(struct WineD3DAdapter *adapter, const struct GlPixelFormatDesc *format_desc)
3099 {
3100 const struct wined3d_gl_info *gl_info = &adapter->gl_info;
3101
3102 if (!GL_LIMITS(vertex_samplers)) {
3103 TRACE_(d3d_caps)("[FAILED]\n");
3104 return FALSE;
3105 }
3106
3107 switch (format_desc->format)
3108 {
3109 case WINED3DFMT_R32G32B32A32_FLOAT:
3110 if (!GL_SUPPORT(ARB_TEXTURE_FLOAT)) {
3111 TRACE_(d3d_caps)("[FAILED]\n");
3112 return FALSE;
3113 }
3114 TRACE_(d3d_caps)("[OK]\n");
3115 return TRUE;
3116
3117 default:
3118 TRACE_(d3d_caps)("[FAILED]\n");
3119 return FALSE;
3120 }
3121 return FALSE;
3122 }
3123
3124 static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
3125 WINED3DFORMAT AdapterFormat, DWORD Usage, WINED3DRESOURCETYPE RType, WINED3DFORMAT CheckFormat,
3126 WINED3DSURFTYPE SurfaceType)
3127 {
3128 IWineD3DImpl *This = (IWineD3DImpl *)iface;
3129 struct WineD3DAdapter *adapter = &This->adapters[Adapter];
3130 const struct wined3d_gl_info *gl_info = &adapter->gl_info;
3131 const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(CheckFormat, gl_info);
3132 const struct GlPixelFormatDesc *adapter_format_desc = getFormatDescEntry(AdapterFormat, gl_info);
3133 DWORD UsageCaps = 0;
3134
3135 TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%u,%s), AdptFmt:(%u,%s), Use:(%u,%s,%s), ResTyp:(%x,%s), CheckFmt:(%u,%s))\n",
3136 This,
3137 Adapter,
3138 DeviceType, debug_d3ddevicetype(DeviceType),
3139 AdapterFormat, debug_d3dformat(AdapterFormat),
3140 Usage, debug_d3dusage(Usage), debug_d3dusagequery(Usage),
3141 RType, debug_d3dresourcetype(RType),
3142 CheckFormat, debug_d3dformat(CheckFormat));
3143
3144 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
3145 return WINED3DERR_INVALIDCALL;
3146 }
3147
3148 if(RType == WINED3DRTYPE_CUBETEXTURE) {
3149
3150 if(SurfaceType != SURFACE_OPENGL) {
3151 TRACE("[FAILED]\n");
3152 return WINED3DERR_NOTAVAILABLE;
3153 }
3154
3155 /* Cubetexture allows:
3156 * - D3DUSAGE_AUTOGENMIPMAP
3157 * - D3DUSAGE_DEPTHSTENCIL
3158 * - D3DUSAGE_DYNAMIC
3159 * - D3DUSAGE_NONSECURE (d3d9ex)
3160 * - D3DUSAGE_RENDERTARGET
3161 * - D3DUSAGE_SOFTWAREPROCESSING
3162 * - D3DUSAGE_QUERY_WRAPANDMIP
3163 */
3164 if(GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
3165 /* Check if the texture format is around */
3166 if (CheckTextureCapability(adapter, DeviceType, format_desc))
3167 {
3168 if(Usage & WINED3DUSAGE_AUTOGENMIPMAP) {
3169 /* Check for automatic mipmap generation support */
3170 if(GL_SUPPORT(SGIS_GENERATE_MIPMAP)) {
3171 UsageCaps |= WINED3DUSAGE_AUTOGENMIPMAP;
3172 } else {
3173 /* When autogenmipmap isn't around continue and return WINED3DOK_NOAUTOGEN instead of D3D_OK */
3174 TRACE_(d3d_caps)("[FAILED] - No autogenmipmap support, but continuing\n");
3175 }
3176 }
3177
3178 /* Always report dynamic locking */
3179 if(Usage & WINED3DUSAGE_DYNAMIC)
3180 UsageCaps |= WINED3DUSAGE_DYNAMIC;
3181
3182 if(Usage & WINED3DUSAGE_RENDERTARGET) {
3183 if(CheckRenderTargetCapability(adapter, adapter_format_desc, format_desc))
3184 {
3185 UsageCaps |= WINED3DUSAGE_RENDERTARGET;
3186 } else {
3187 TRACE_(d3d_caps)("[FAILED] - No rendertarget support\n");
3188 return WINED3DERR_NOTAVAILABLE;
3189 }
3190 }
3191
3192 /* Always report software processing */
3193 if(Usage & WINED3DUSAGE_SOFTWAREPROCESSING)
3194 UsageCaps |= WINED3DUSAGE_SOFTWAREPROCESSING;
3195
3196 /* Check QUERY_FILTER support */
3197 if(Usage & WINED3DUSAGE_QUERY_FILTER) {
3198 if (CheckFilterCapability(adapter, format_desc))
3199 {
3200 UsageCaps |= WINED3DUSAGE_QUERY_FILTER;
3201 } else {
3202 TRACE_(d3d_caps)("[FAILED] - No query filter support\n");
3203 return WINED3DERR_NOTAVAILABLE;
3204 }
3205 }
3206
3207 /* Check QUERY_POSTPIXELSHADER_BLENDING support */
3208 if(Usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING) {
3209 if (CheckPostPixelShaderBlendingCapability(adapter, format_desc))
3210 {
3211 UsageCaps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
3212 } else {
3213 TRACE_(d3d_caps)("[FAILED] - No query post pixelshader blending support\n");
3214 return WINED3DERR_NOTAVAILABLE;
3215 }
3216 }
3217
3218 /* Check QUERY_SRGBREAD support */
3219 if(Usage & WINED3DUSAGE_QUERY_SRGBREAD) {
3220 if (CheckSrgbReadCapability(adapter, format_desc))
3221 {
3222 UsageCaps |= WINED3DUSAGE_QUERY_SRGBREAD;
3223 } else {
3224 TRACE_(d3d_caps)("[FAILED] - No query srgbread support\n");
3225 return WINED3DERR_NOTAVAILABLE;
3226 }
3227 }
3228
3229 /* Check QUERY_SRGBWRITE support */
3230 if(Usage & WINED3DUSAGE_QUERY_SRGBWRITE) {
3231 if (CheckSrgbWriteCapability(adapter, DeviceType, format_desc))
3232 {
3233 UsageCaps |= WINED3DUSAGE_QUERY_SRGBWRITE;
3234 } else {
3235 TRACE_(d3d_caps)("[FAILED] - No query srgbwrite support\n");
3236 return WINED3DERR_NOTAVAILABLE;
3237 }
3238 }
3239
3240 /* Check QUERY_VERTEXTEXTURE support */
3241 if(Usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE) {
3242 if (CheckVertexTextureCapability(adapter, format_desc))
3243 {
3244 UsageCaps |= WINED3DUSAGE_QUERY_VERTEXTEXTURE;
3245 } else {
3246 TRACE_(d3d_caps)("[FAILED] - No query vertextexture support\n");
3247 return WINED3DERR_NOTAVAILABLE;
3248 }
3249 }
3250
3251 /* Check QUERY_WRAPANDMIP support */
3252 if(Usage & WINED3DUSAGE_QUERY_WRAPANDMIP) {
3253 if (CheckWrapAndMipCapability(adapter, format_desc))
3254 {
3255 UsageCaps |= WINED3DUSAGE_QUERY_WRAPANDMIP;
3256 } else {
3257 TRACE_(d3d_caps)("[FAILED] - No wrapping and mipmapping support\n");
3258 return WINED3DERR_NOTAVAILABLE;
3259 }
3260 }
3261 } else {
3262 TRACE_(d3d_caps)("[FAILED] - Cube texture format not supported\n");
3263 return WINED3DERR_NOTAVAILABLE;
3264 }
3265 } else {
3266 TRACE_(d3d_caps)("[FAILED] - No cube texture support\n");
3267 return WINED3DERR_NOTAVAILABLE;
3268 }
3269 } else if(RType == WINED3DRTYPE_SURFACE) {
3270 /* Surface allows:
3271 * - D3DUSAGE_DEPTHSTENCIL
3272 * - D3DUSAGE_NONSECURE (d3d9ex)
3273 * - D3DUSAGE_RENDERTARGET
3274 */
3275
3276 if (CheckSurfaceCapability(adapter, adapter_format_desc, DeviceType, format_desc, SurfaceType))
3277 {
3278 if(Usage & WINED3DUSAGE_DEPTHSTENCIL) {
3279 if (CheckDepthStencilCapability(adapter, adapter_format_desc, format_desc))
3280 {
3281 UsageCaps |= WINED3DUSAGE_DEPTHSTENCIL;
3282 } else {
3283 TRACE_(d3d_caps)("[FAILED] - No depthstencil support\n");
3284 return WINED3DERR_NOTAVAILABLE;
3285 }
3286 }
3287
3288 if(Usage & WINED3DUSAGE_RENDERTARGET) {
3289 if (CheckRenderTargetCapability(adapter, adapter_format_desc, format_desc))
3290 {
3291 UsageCaps |= WINED3DUSAGE_RENDERTARGET;
3292 } else {
3293 TRACE_(d3d_caps)("[FAILED] - No rendertarget support\n");
3294 return WINED3DERR_NOTAVAILABLE;
3295 }
3296 }
3297
3298 /* Check QUERY_POSTPIXELSHADER_BLENDING support */
3299 if(Usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING) {
3300 if (CheckPostPixelShaderBlendingCapability(adapter, format_desc))
3301 {
3302 UsageCaps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
3303 } else {
3304 TRACE_(d3d_caps)("[FAILED] - No query post pixelshader blending support\n");
3305 return WINED3DERR_NOTAVAILABLE;
3306 }
3307 }
3308 } else {
3309 TRACE_(d3d_caps)("[FAILED] - Not supported for plain surfaces\n");
3310 return WINED3DERR_NOTAVAILABLE;
3311 }
3312
3313 } else if(RType == WINED3DRTYPE_TEXTURE) {
3314 /* Texture allows:
3315 * - D3DUSAGE_AUTOGENMIPMAP
3316 * - D3DUSAGE_DEPTHSTENCIL
3317 * - D3DUSAGE_DMAP
3318 * - D3DUSAGE_DYNAMIC
3319 * - D3DUSAGE_NONSECURE (d3d9ex)
3320 * - D3DUSAGE_RENDERTARGET
3321 * - D3DUSAGE_SOFTWAREPROCESSING
3322 * - D3DUSAGE_TEXTAPI (d3d9ex)
3323 * - D3DUSAGE_QUERY_WRAPANDMIP
3324 */
3325
3326 if(SurfaceType != SURFACE_OPENGL) {
3327 TRACE("[FAILED]\n");
3328 return WINED3DERR_NOTAVAILABLE;
3329 }
3330
3331 /* Check if the texture format is around */
3332 if (CheckTextureCapability(adapter, DeviceType, format_desc))
3333 {
3334 if(Usage & WINED3DUSAGE_AUTOGENMIPMAP) {
3335 /* Check for automatic mipmap generation support */
3336 if(GL_SUPPORT(SGIS_GENERATE_MIPMAP)) {
3337 UsageCaps |= WINED3DUSAGE_AUTOGENMIPMAP;
3338 } else {
3339 /* When autogenmipmap isn't around continue and return WINED3DOK_NOAUTOGEN instead of D3D_OK */
3340 TRACE_(d3d_caps)("[FAILED] - No autogenmipmap support, but continuing\n");
3341 }
3342 }
3343
3344 /* Always report dynamic locking */
3345 if(Usage & WINED3DUSAGE_DYNAMIC)
3346 UsageCaps |= WINED3DUSAGE_DYNAMIC;
3347
3348 if(Usage & WINED3DUSAGE_RENDERTARGET) {
3349 if (CheckRenderTargetCapability(adapter, adapter_format_desc, format_desc))
3350 {
3351 UsageCaps |= WINED3DUSAGE_RENDERTARGET;
3352 } else {
3353 TRACE_(d3d_caps)("[FAILED] - No rendertarget support\n");
3354 return WINED3DERR_NOTAVAILABLE;
3355 }
3356 }
3357
3358 /* Always report software processing */
3359 if(Usage & WINED3DUSAGE_SOFTWAREPROCESSING)
3360 UsageCaps |= WINED3DUSAGE_SOFTWAREPROCESSING;
3361
3362 /* Check QUERY_FILTER support */
3363 if(Usage & WINED3DUSAGE_QUERY_FILTER) {
3364 if (CheckFilterCapability(adapter, format_desc))
3365 {
3366 UsageCaps |= WINED3DUSAGE_QUERY_FILTER;
3367 } else {
3368 TRACE_(d3d_caps)("[FAILED] - No query filter support\n");
3369 return WINED3DERR_NOTAVAILABLE;
3370 }
3371 }
3372
3373 /* Check QUERY_LEGACYBUMPMAP support */
3374 if(Usage & WINED3DUSAGE_QUERY_LEGACYBUMPMAP) {
3375 if (CheckBumpMapCapability(adapter, DeviceType, format_desc))
3376 {
3377 UsageCaps |= WINED3DUSAGE_QUERY_LEGACYBUMPMAP;
3378 } else {
3379 TRACE_(d3d_caps)("[FAILED] - No legacy bumpmap support\n");
3380 return WINED3DERR_NOTAVAILABLE;
3381 }
3382 }
3383
3384 /* Check QUERY_POSTPIXELSHADER_BLENDING support */
3385 if(Usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING) {
3386 if (CheckPostPixelShaderBlendingCapability(adapter, format_desc))
3387 {
3388 UsageCaps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
3389 } else {
3390 TRACE_(d3d_caps)("[FAILED] - No query post pixelshader blending support\n");
3391 return WINED3DERR_NOTAVAILABLE;
3392 }
3393 }
3394
3395 /* Check QUERY_SRGBREAD support */
3396 if(Usage & WINED3DUSAGE_QUERY_SRGBREAD) {
3397 if (CheckSrgbReadCapability(adapter, format_desc))
3398 {
3399 UsageCaps |= WINED3DUSAGE_QUERY_SRGBREAD;
3400 } else {
3401 TRACE_(d3d_caps)("[FAILED] - No query srgbread support\n");
3402 return WINED3DERR_NOTAVAILABLE;
3403 }
3404 }
3405
3406 /* Check QUERY_SRGBWRITE support */
3407 if(Usage & WINED3DUSAGE_QUERY_SRGBWRITE) {
3408 if (CheckSrgbWriteCapability(adapter, DeviceType, format_desc))
3409 {
3410 UsageCaps |= WINED3DUSAGE_QUERY_SRGBWRITE;
3411 } else {
3412 TRACE_(d3d_caps)("[FAILED] - No query srgbwrite support\n");
3413 return WINED3DERR_NOTAVAILABLE;
3414 }
3415 }
3416
3417 /* Check QUERY_VERTEXTEXTURE support */
3418 if(Usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE) {
3419 if (CheckVertexTextureCapability(adapter, format_desc))
3420 {
3421 UsageCaps |= WINED3DUSAGE_QUERY_VERTEXTEXTURE;
3422 } else {
3423 TRACE_(d3d_caps)("[FAILED] - No query vertextexture support\n");
3424 return WINED3DERR_NOTAVAILABLE;
3425 }
3426 }
3427
3428 /* Check QUERY_WRAPANDMIP support */
3429 if(Usage & WINED3DUSAGE_QUERY_WRAPANDMIP) {
3430 if (CheckWrapAndMipCapability(adapter, format_desc))
3431 {
3432 UsageCaps |= WINED3DUSAGE_QUERY_WRAPANDMIP;
3433 } else {
3434 TRACE_(d3d_caps)("[FAILED] - No wrapping and mipmapping support\n");
3435 return WINED3DERR_NOTAVAILABLE;
3436 }
3437 }
3438
3439 if(Usage & WINED3DUSAGE_DEPTHSTENCIL) {
3440 if (CheckDepthStencilCapability(adapter, adapter_format_desc, format_desc))
3441 {
3442 UsageCaps |= WINED3DUSAGE_DEPTHSTENCIL;
3443 } else {
3444 TRACE_(d3d_caps)("[FAILED] - No depth stencil support\n");
3445 return WINED3DERR_NOTAVAILABLE;
3446 }
3447 }
3448 } else {
3449 TRACE_(d3d_caps)("[FAILED] - Texture format not supported\n");
3450 return WINED3DERR_NOTAVAILABLE;
3451 }
3452 } else if((RType == WINED3DRTYPE_VOLUME) || (RType == WINED3DRTYPE_VOLUMETEXTURE)) {
3453 /* Volume is to VolumeTexture what Surface is to Texture but its usage caps are not documented.
3454 * Most driver seem to offer (nearly) the same on Volume and VolumeTexture, so do that too.
3455 *
3456 * Volumetexture allows:
3457 * - D3DUSAGE_DYNAMIC
3458 * - D3DUSAGE_NONSECURE (d3d9ex)
3459 * - D3DUSAGE_SOFTWAREPROCESSING
3460 * - D3DUSAGE_QUERY_WRAPANDMIP
3461 */
3462
3463 if(SurfaceType != SURFACE_OPENGL) {
3464 TRACE("[FAILED]\n");
3465 return WINED3DERR_NOTAVAILABLE;
3466 }
3467
3468 /* Check volume texture and volume usage caps */
3469 if(GL_SUPPORT(EXT_TEXTURE3D)) {
3470 if (!CheckTextureCapability(adapter, DeviceType, format_desc))
3471 {
3472 TRACE_(d3d_caps)("[FAILED] - Format not supported\n");
3473 return WINED3DERR_NOTAVAILABLE;
3474 }
3475
3476 /* Always report dynamic locking */
3477 if(Usage & WINED3DUSAGE_DYNAMIC)
3478 UsageCaps |= WINED3DUSAGE_DYNAMIC;
3479
3480 /* Always report software processing */
3481 if(Usage & WINED3DUSAGE_SOFTWAREPROCESSING)
3482 UsageCaps |= WINED3DUSAGE_SOFTWAREPROCESSING;
3483
3484 /* Check QUERY_FILTER support */
3485 if(Usage & WINED3DUSAGE_QUERY_FILTER) {
3486 if (CheckFilterCapability(adapter, format_desc))
3487 {
3488 UsageCaps |= WINED3DUSAGE_QUERY_FILTER;
3489 } else {
3490 TRACE_(d3d_caps)("[FAILED] - No query filter support\n");
3491 return WINED3DERR_NOTAVAILABLE;
3492 }
3493 }
3494
3495 /* Check QUERY_POSTPIXELSHADER_BLENDING support */
3496 if(Usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING) {
3497 if (CheckPostPixelShaderBlendingCapability(adapter, format_desc))
3498 {
3499 UsageCaps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
3500 } else {
3501 TRACE_(d3d_caps)("[FAILED] - No query post pixelshader blending support\n");
3502 return WINED3DERR_NOTAVAILABLE;
3503 }
3504 }
3505
3506 /* Check QUERY_SRGBREAD support */
3507 if(Usage & WINED3DUSAGE_QUERY_SRGBREAD) {
3508 if (CheckSrgbReadCapability(adapter, format_desc))
3509 {
3510 UsageCaps |= WINED3DUSAGE_QUERY_SRGBREAD;
3511 } else {
3512 TRACE_(d3d_caps)("[FAILED] - No query srgbread support\n");
3513 return WINED3DERR_NOTAVAILABLE;
3514 }
3515 }
3516
3517 /* Check QUERY_SRGBWRITE support */
3518 if(Usage & WINED3DUSAGE_QUERY_SRGBWRITE) {
3519 if (CheckSrgbWriteCapability(adapter, DeviceType, format_desc))
3520 {
3521 UsageCaps |= WINED3DUSAGE_QUERY_SRGBWRITE;
3522 } else {
3523 TRACE_(d3d_caps)("[FAILED] - No query srgbwrite support\n");
3524 return WINED3DERR_NOTAVAILABLE;
3525 }
3526 }
3527
3528 /* Check QUERY_VERTEXTEXTURE support */
3529 if(Usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE) {
3530 if (CheckVertexTextureCapability(adapter, format_desc))
3531 {
3532 UsageCaps |= WINED3DUSAGE_QUERY_VERTEXTEXTURE;
3533 } else {
3534 TRACE_(d3d_caps)("[FAILED] - No query vertextexture support\n");
3535 return WINED3DERR_NOTAVAILABLE;
3536 }
3537 }
3538
3539 /* Check QUERY_WRAPANDMIP support */
3540 if(Usage & WINED3DUSAGE_QUERY_WRAPANDMIP) {
3541 if (CheckWrapAndMipCapability(adapter, format_desc))
3542 {
3543 UsageCaps |= WINED3DUSAGE_QUERY_WRAPANDMIP;
3544 } else {
3545 TRACE_(d3d_caps)("[FAILED] - No wrapping and mipmapping support\n");
3546 return WINED3DERR_NOTAVAILABLE;
3547 }
3548 }
3549 } else {
3550 TRACE_(d3d_caps)("[FAILED] - No volume texture support\n");
3551 return WINED3DERR_NOTAVAILABLE;
3552 }
3553
3554 /* Filter formats that need conversion; For one part, this conversion is unimplemented,
3555 * and volume textures are huge, so it would be a big performance hit. Unless we hit an
3556 * app needing one of those formats, don't advertize them to avoid leading apps into
3557 * temptation. The windows drivers don't support most of those formats on volumes anyway,
3558 * except of R32F.
3559 */
3560 switch(CheckFormat) {
3561 case WINED3DFMT_P8_UINT:
3562 case WINED3DFMT_L4A4_UNORM:
3563 case WINED3DFMT_R32_FLOAT:
3564 case WINED3DFMT_R16_FLOAT:
3565 case WINED3DFMT_R8G8_SNORM_L8X8_UNORM:
3566 case WINED3DFMT_R5G5_SNORM_L6_UNORM:
3567 case WINED3DFMT_R16G16_UNORM:
3568 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
3569 return WINED3DERR_NOTAVAILABLE;
3570
3571 case WINED3DFMT_R8G8B8A8_SNORM:
3572 case WINED3DFMT_R16G16_SNORM:
3573 if(!GL_SUPPORT(NV_TEXTURE_SHADER)) {
3574 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
3575 return WINED3DERR_NOTAVAILABLE;
3576 }
3577 break;
3578
3579 case WINED3DFMT_R8G8_SNORM:
3580 if(!GL_SUPPORT(NV_TEXTURE_SHADER)) {
3581 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
3582 return WINED3DERR_NOTAVAILABLE;
3583 }
3584 break;
3585
3586 case WINED3DFMT_DXT1:
3587 case WINED3DFMT_DXT2:
3588 case WINED3DFMT_DXT3:
3589 case WINED3DFMT_DXT4:
3590 case WINED3DFMT_DXT5:
3591 /* The GL_EXT_texture_compression_s3tc spec requires that loading an s3tc
3592 * compressed texture results in an error. While the D3D refrast does
3593 * support s3tc volumes, at least the nvidia windows driver does not, so
3594 * we're free not to support this format.
3595 */
3596 TRACE_(d3d_caps)("[FAILED] - DXTn does not support 3D textures\n");
3597 return WINED3DERR_NOTAVAILABLE;
3598
3599 default:
3600 /* Do nothing, continue with checking the format below */
3601 break;
3602 }
3603 } else if(RType == WINED3DRTYPE_BUFFER){
3604 /* For instance vertexbuffer/indexbuffer aren't supported yet because no Windows drivers seem to offer it */
3605 TRACE_(d3d_caps)("Unhandled resource type D3DRTYPE_INDEXBUFFER / D3DRTYPE_VERTEXBUFFER\n");
3606 return WINED3DERR_NOTAVAILABLE;
3607 }
3608
3609 /* When the UsageCaps exactly matches Usage return WINED3D_OK except for the situation in which
3610 * WINED3DUSAGE_AUTOGENMIPMAP isn't around, then WINED3DOK_NOAUTOGEN is returned if all the other
3611 * usage flags match. */
3612 if(UsageCaps == Usage) {
3613 return WINED3D_OK;
3614 } else if((UsageCaps == (Usage & ~WINED3DUSAGE_AUTOGENMIPMAP)) && (Usage & WINED3DUSAGE_AUTOGENMIPMAP)){
3615 return WINED3DOK_NOAUTOGEN;
3616 } else {
3617 TRACE_(d3d_caps)("[FAILED] - Usage=%#08x requested for CheckFormat=%s and RType=%d but only %#08x is available\n", Usage, debug_d3dformat(CheckFormat), RType, UsageCaps);
3618 return WINED3DERR_NOTAVAILABLE;
3619 }
3620 }
3621
3622 static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormatConversion(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
3623 WINED3DFORMAT SourceFormat, WINED3DFORMAT TargetFormat) {
3624 IWineD3DImpl *This = (IWineD3DImpl *)iface;
3625
3626 FIXME_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%u,%s), SrcFmt:(%u,%s), TgtFmt:(%u,%s))\n",
3627 This,
3628 Adapter,
3629 DeviceType, debug_d3ddevicetype(DeviceType),
3630 SourceFormat, debug_d3dformat(SourceFormat),
3631 TargetFormat, debug_d3dformat(TargetFormat));
3632 return WINED3D_OK;
3633 }
3634
3635 static const shader_backend_t *select_shader_backend(struct WineD3DAdapter *adapter, WINED3DDEVTYPE DeviceType)
3636 {
3637 const shader_backend_t *ret;
3638 int vs_selected_mode;
3639 int ps_selected_mode;
3640
3641 select_shader_mode(&adapter->gl_info, &ps_selected_mode, &vs_selected_mode);
3642 if (vs_selected_mode == SHADER_GLSL || ps_selected_mode == SHADER_GLSL) {
3643 ret = &glsl_shader_backend;
3644 } else if (vs_selected_mode == SHADER_ARB || ps_selected_mode == SHADER_ARB) {
3645 ret = &arb_program_shader_backend;
3646 } else {
3647 ret = &none_shader_backend;
3648 }
3649 return ret;
3650 }
3651
3652 static const struct fragment_pipeline *select_fragment_implementation(struct WineD3DAdapter *adapter,
3653 WINED3DDEVTYPE DeviceType)
3654 {
3655 const struct wined3d_gl_info *gl_info = &adapter->gl_info;
3656 int vs_selected_mode;
3657 int ps_selected_mode;
3658
3659 select_shader_mode(&adapter->gl_info, &ps_selected_mode, &vs_selected_mode);
3660 if((ps_selected_mode == SHADER_ARB || ps_selected_mode == SHADER_GLSL) && GL_SUPPORT(ARB_FRAGMENT_PROGRAM)) {
3661 return &arbfp_fragment_pipeline;
3662 } else if(ps_selected_mode == SHADER_ATI) {
3663 return &atifs_fragment_pipeline;
3664 } else if(GL_SUPPORT(NV_REGISTER_COMBINERS) && GL_SUPPORT(NV_TEXTURE_SHADER2)) {
3665 return &nvts_fragment_pipeline;
3666 } else if(GL_SUPPORT(NV_REGISTER_COMBINERS)) {
3667 return &nvrc_fragment_pipeline;
3668 } else {
3669 return &ffp_fragment_pipeline;
3670 }
3671 }
3672
3673 static const struct blit_shader *select_blit_implementation(struct WineD3DAdapter *adapter, WINED3DDEVTYPE DeviceType)
3674 {
3675 const struct wined3d_gl_info *gl_info = &adapter->gl_info;
3676 int vs_selected_mode;
3677 int ps_selected_mode;
3678
3679 select_shader_mode(&adapter->gl_info, &ps_selected_mode, &vs_selected_mode);
3680 if((ps_selected_mode == SHADER_ARB || ps_selected_mode == SHADER_GLSL) && GL_SUPPORT(ARB_FRAGMENT_PROGRAM)) {
3681 return &arbfp_blit;
3682 } else {
3683 return &ffp_blit;
3684 }
3685 }
3686
3687 /* Note: d3d8 passes in a pointer to a D3DCAPS8 structure, which is a true
3688 subset of a D3DCAPS9 structure. However, it has to come via a void *
3689 as the d3d8 interface cannot import the d3d9 header */
3690 static HRESULT WINAPI IWineD3DImpl_GetDeviceCaps(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType, WINED3DCAPS* pCaps) {
3691
3692 IWineD3DImpl *This = (IWineD3DImpl *)iface;
3693 struct WineD3DAdapter *adapter = &This->adapters[Adapter];
3694 const struct wined3d_gl_info *gl_info = &adapter->gl_info;
3695 int vs_selected_mode;
3696 int ps_selected_mode;
3697 struct shader_caps shader_caps;
3698 struct fragment_caps fragment_caps;
3699 const shader_backend_t *shader_backend;
3700 const struct fragment_pipeline *frag_pipeline = NULL;
3701 DWORD ckey_caps, blit_caps, fx_caps;
3702
3703 TRACE_(d3d_caps)("(%p)->(Adptr:%d, DevType: %x, pCaps: %p)\n", This, Adapter, DeviceType, pCaps);
3704
3705 if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
3706 return WINED3DERR_INVALIDCALL;
3707 }
3708
3709 select_shader_mode(&adapter->gl_info, &ps_selected_mode, &vs_selected_mode);
3710
3711 /* This function should *not* be modifying GL caps
3712 * TODO: move the functionality where it belongs */
3713 select_shader_max_constants(ps_selected_mode, vs_selected_mode, &adapter->gl_info);
3714
3715 /* ------------------------------------------------
3716 The following fields apply to both d3d8 and d3d9
3717 ------------------------------------------------ */
3718 pCaps->DeviceType = (DeviceType == WINED3DDEVTYPE_HAL) ? WINED3DDEVTYPE_HAL : WINED3DDEVTYPE_REF; /* Not quite true, but use h/w supported by opengl I suppose */
3719 pCaps->AdapterOrdinal = Adapter;
3720
3721 pCaps->Caps = 0;
3722 pCaps->Caps2 = WINED3DCAPS2_CANRENDERWINDOWED |
3723 WINED3DCAPS2_FULLSCREENGAMMA |
3724 WINED3DCAPS2_DYNAMICTEXTURES;
3725 if(GL_SUPPORT(SGIS_GENERATE_MIPMAP)) {
3726 pCaps->Caps2 |= WINED3DCAPS2_CANAUTOGENMIPMAP;
3727 }
3728
3729 pCaps->Caps3 = WINED3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD |
3730 WINED3DCAPS3_COPY_TO_VIDMEM |
3731 WINED3DCAPS3_COPY_TO_SYSTEMMEM;
3732
3733 pCaps->PresentationIntervals = WINED3DPRESENT_INTERVAL_IMMEDIATE |
3734 WINED3DPRESENT_INTERVAL_ONE;
3735
3736 pCaps->CursorCaps = WINED3DCURSORCAPS_COLOR |
3737 WINED3DCURSORCAPS_LOWRES;
3738
3739 pCaps->DevCaps = WINED3DDEVCAPS_FLOATTLVERTEX |
3740 WINED3DDEVCAPS_EXECUTESYSTEMMEMORY |
3741 WINED3DDEVCAPS_TLVERTEXSYSTEMMEMORY|
3742 WINED3DDEVCAPS_TLVERTEXVIDEOMEMORY |
3743 WINED3DDEVCAPS_DRAWPRIMTLVERTEX |
3744 WINED3DDEVCAPS_HWTRANSFORMANDLIGHT |
3745 WINED3DDEVCAPS_EXECUTEVIDEOMEMORY |
3746 WINED3DDEVCAPS_PUREDEVICE |
3747 WINED3DDEVCAPS_HWRASTERIZATION |
3748 WINED3DDEVCAPS_TEXTUREVIDEOMEMORY |
3749 WINED3DDEVCAPS_TEXTURESYSTEMMEMORY |
3750 WINED3DDEVCAPS_CANRENDERAFTERFLIP |
3751 WINED3DDEVCAPS_DRAWPRIMITIVES2 |
3752 WINED3DDEVCAPS_DRAWPRIMITIVES2EX |
3753 WINED3DDEVCAPS_RTPATCHES;
3754
3755 pCaps->PrimitiveMiscCaps = WINED3DPMISCCAPS_CULLNONE |
3756 WINED3DPMISCCAPS_CULLCCW |
3757 WINED3DPMISCCAPS_CULLCW |
3758 WINED3DPMISCCAPS_COLORWRITEENABLE |
3759 WINED3DPMISCCAPS_CLIPTLVERTS |
3760 WINED3DPMISCCAPS_CLIPPLANESCALEDPOINTS |
3761 WINED3DPMISCCAPS_MASKZ |
3762 WINED3DPMISCCAPS_BLENDOP |
3763 WINED3DPMISCCAPS_MRTPOSTPIXELSHADERBLENDING;
3764 /* TODO:
3765 WINED3DPMISCCAPS_NULLREFERENCE
3766 WINED3DPMISCCAPS_INDEPENDENTWRITEMASKS
3767 WINED3DPMISCCAPS_FOGANDSPECULARALPHA
3768 WINED3DPMISCCAPS_MRTINDEPENDENTBITDEPTHS
3769 WINED3DPMISCCAPS_FOGVERTEXCLAMPED */
3770
3771 if(GL_SUPPORT(EXT_BLEND_EQUATION_SEPARATE) && GL_SUPPORT(EXT_BLEND_FUNC_SEPARATE))
3772 pCaps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_SEPARATEALPHABLEND;
3773
3774 pCaps->RasterCaps = WINED3DPRASTERCAPS_DITHER |
3775 WINED3DPRASTERCAPS_PAT |
3776 WINED3DPRASTERCAPS_WFOG |
3777 WINED3DPRASTERCAPS_ZFOG |
3778 WINED3DPRASTERCAPS_FOGVERTEX |
3779 WINED3DPRASTERCAPS_FOGTABLE |
3780 WINED3DPRASTERCAPS_STIPPLE |
3781 WINED3DPRASTERCAPS_SUBPIXEL |
3782 WINED3DPRASTERCAPS_ZTEST |
3783 WINED3DPRASTERCAPS_SCISSORTEST |
3784 WINED3DPRASTERCAPS_SLOPESCALEDEPTHBIAS |
3785 WINED3DPRASTERCAPS_DEPTHBIAS;
3786
3787 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC)) {
3788 pCaps->RasterCaps |= WINED3DPRASTERCAPS_ANISOTROPY |
3789 WINED3DPRASTERCAPS_ZBIAS |
3790 WINED3DPRASTERCAPS_MIPMAPLODBIAS;
3791 }
3792 if(GL_SUPPORT(NV_FOG_DISTANCE)) {
3793 pCaps->RasterCaps |= WINED3DPRASTERCAPS_FOGRANGE;
3794 }
3795 /* FIXME Add:
3796 WINED3DPRASTERCAPS_COLORPERSPECTIVE
3797 WINED3DPRASTERCAPS_STRETCHBLTMULTISAMPLE
3798 WINED3DPRASTERCAPS_ANTIALIASEDGES
3799 WINED3DPRASTERCAPS_ZBUFFERLESSHSR
3800 WINED3DPRASTERCAPS_WBUFFER */
3801
3802 pCaps->ZCmpCaps = WINED3DPCMPCAPS_ALWAYS |
3803 WINED3DPCMPCAPS_EQUAL |
3804 WINED3DPCMPCAPS_GREATER |
3805 WINED3DPCMPCAPS_GREATEREQUAL |
3806 WINED3DPCMPCAPS_LESS |
3807 WINED3DPCMPCAPS_LESSEQUAL |
3808 WINED3DPCMPCAPS_NEVER |
3809 WINED3DPCMPCAPS_NOTEQUAL;
3810
3811 pCaps->SrcBlendCaps = WINED3DPBLENDCAPS_BOTHINVSRCALPHA |
3812 WINED3DPBLENDCAPS_BOTHSRCALPHA |
3813 WINED3DPBLENDCAPS_DESTALPHA |
3814 WINED3DPBLENDCAPS_DESTCOLOR |
3815 WINED3DPBLENDCAPS_INVDESTALPHA |
3816 WINED3DPBLENDCAPS_INVDESTCOLOR |
3817 WINED3DPBLENDCAPS_INVSRCALPHA |
3818 WINED3DPBLENDCAPS_INVSRCCOLOR |
3819 WINED3DPBLENDCAPS_ONE |
3820 WINED3DPBLENDCAPS_SRCALPHA |
3821 WINED3DPBLENDCAPS_SRCALPHASAT |
3822 WINED3DPBLENDCAPS_SRCCOLOR |
3823 WINED3DPBLENDCAPS_ZERO;
3824
3825 pCaps->DestBlendCaps = WINED3DPBLENDCAPS_DESTALPHA |
3826 WINED3DPBLENDCAPS_DESTCOLOR |
3827 WINED3DPBLENDCAPS_INVDESTALPHA |
3828 WINED3DPBLENDCAPS_INVDESTCOLOR |
3829 WINED3DPBLENDCAPS_INVSRCALPHA |
3830 WINED3DPBLENDCAPS_INVSRCCOLOR |
3831 WINED3DPBLENDCAPS_ONE |
3832 WINED3DPBLENDCAPS_SRCALPHA |
3833 WINED3DPBLENDCAPS_SRCCOLOR |
3834 WINED3DPBLENDCAPS_ZERO;
3835 /* NOTE: WINED3DPBLENDCAPS_SRCALPHASAT is not supported as dest blend factor,
3836 * according to the glBlendFunc manpage
3837 *
3838 * WINED3DPBLENDCAPS_BOTHINVSRCALPHA and WINED3DPBLENDCAPS_BOTHSRCALPHA are
3839 * legacy settings for srcblend only
3840 */
3841
3842 if( GL_SUPPORT(EXT_BLEND_COLOR)) {
3843 pCaps->SrcBlendCaps |= WINED3DPBLENDCAPS_BLENDFACTOR;
3844 pCaps->DestBlendCaps |= WINED3DPBLENDCAPS_BLENDFACTOR;
3845 }
3846
3847
3848 pCaps->AlphaCmpCaps = WINED3DPCMPCAPS_ALWAYS |
3849 WINED3DPCMPCAPS_EQUAL |
3850 WINED3DPCMPCAPS_GREATER |
3851 WINED3DPCMPCAPS_GREATEREQUAL |
3852 WINED3DPCMPCAPS_LESS |
3853 WINED3DPCMPCAPS_LESSEQUAL |
3854 WINED3DPCMPCAPS_NEVER |
3855 WINED3DPCMPCAPS_NOTEQUAL;
3856
3857 pCaps->ShadeCaps = WINED3DPSHADECAPS_SPECULARGOURAUDRGB |
3858 WINED3DPSHADECAPS_COLORGOURAUDRGB |
3859 WINED3DPSHADECAPS_ALPHAFLATBLEND |
3860 WINED3DPSHADECAPS_ALPHAGOURAUDBLEND |
3861 WINED3DPSHADECAPS_COLORFLATRGB |
3862 WINED3DPSHADECAPS_FOGFLAT |
3863 WINED3DPSHADECAPS_FOGGOURAUD |
3864 WINED3DPSHADECAPS_SPECULARFLATRGB;
3865
3866 pCaps->TextureCaps = WINED3DPTEXTURECAPS_ALPHA |
3867 WINED3DPTEXTURECAPS_ALPHAPALETTE |
3868 WINED3DPTEXTURECAPS_TRANSPARENCY |
3869 WINED3DPTEXTURECAPS_BORDER |
3870 WINED3DPTEXTURECAPS_MIPMAP |
3871 WINED3DPTEXTURECAPS_PROJECTED |
3872 WINED3DPTEXTURECAPS_PERSPECTIVE;
3873
3874 if( !GL_SUPPORT(ARB_TEXTURE_NON_POWER_OF_TWO)) {
3875 pCaps->TextureCaps |= WINED3DPTEXTURECAPS_POW2 |
3876 WINED3DPTEXTURECAPS_NONPOW2CONDITIONAL;
3877 }
3878
3879 if( GL_SUPPORT(EXT_TEXTURE3D)) {
3880 pCaps->TextureCaps |= WINED3DPTEXTURECAPS_VOLUMEMAP |
3881 WINED3DPTEXTURECAPS_MIPVOLUMEMAP |
3882 WINED3DPTEXTURECAPS_VOLUMEMAP_POW2;
3883 }
3884
3885 if (GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
3886 pCaps->TextureCaps |= WINED3DPTEXTURECAPS_CUBEMAP |
3887 WINED3DPTEXTURECAPS_MIPCUBEMAP |
3888 WINED3DPTEXTURECAPS_CUBEMAP_POW2;
3889
3890 }
3891
3892 pCaps->TextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
3893 WINED3DPTFILTERCAPS_MAGFPOINT |
3894 WINED3DPTFILTERCAPS_MINFLINEAR |
3895 WINED3DPTFILTERCAPS_MINFPOINT |
3896 WINED3DPTFILTERCAPS_MIPFLINEAR |
3897 WINED3DPTFILTERCAPS_MIPFPOINT |
3898 WINED3DPTFILTERCAPS_LINEAR |
3899 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
3900 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
3901 WINED3DPTFILTERCAPS_MIPLINEAR |
3902 WINED3DPTFILTERCAPS_MIPNEAREST |
3903 WINED3DPTFILTERCAPS_NEAREST;
3904
3905 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC)) {
3906 pCaps->TextureFilterCaps |= WINED3DPTFILTERCAPS_MAGFANISOTROPIC |
3907 WINED3DPTFILTERCAPS_MINFANISOTROPIC;
3908 }
3909
3910 if (GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
3911 pCaps->CubeTextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
3912 WINED3DPTFILTERCAPS_MAGFPOINT |
3913 WINED3DPTFILTERCAPS_MINFLINEAR |
3914 WINED3DPTFILTERCAPS_MINFPOINT |
3915 WINED3DPTFILTERCAPS_MIPFLINEAR |
3916 WINED3DPTFILTERCAPS_MIPFPOINT |
3917 WINED3DPTFILTERCAPS_LINEAR |
3918 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
3919 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
3920 WINED3DPTFILTERCAPS_MIPLINEAR |
3921 WINED3DPTFILTERCAPS_MIPNEAREST |
3922 WINED3DPTFILTERCAPS_NEAREST;
3923
3924 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC)) {
3925 pCaps->CubeTextureFilterCaps |= WINED3DPTFILTERCAPS_MAGFANISOTROPIC |
3926 WINED3DPTFILTERCAPS_MINFANISOTROPIC;
3927 }
3928 } else
3929 pCaps->CubeTextureFilterCaps = 0;
3930
3931 if (GL_SUPPORT(EXT_TEXTURE3D)) {
3932 pCaps->VolumeTextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
3933 WINED3DPTFILTERCAPS_MAGFPOINT |
3934 WINED3DPTFILTERCAPS_MINFLINEAR |
3935 WINED3DPTFILTERCAPS_MINFPOINT |
3936 WINED3DPTFILTERCAPS_MIPFLINEAR |
3937 WINED3DPTFILTERCAPS_MIPFPOINT |
3938 WINED3DPTFILTERCAPS_LINEAR |
3939 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
3940 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
3941 WINED3DPTFILTERCAPS_MIPLINEAR |
3942 WINED3DPTFILTERCAPS_MIPNEAREST |
3943 WINED3DPTFILTERCAPS_NEAREST;
3944 } else
3945 pCaps->VolumeTextureFilterCaps = 0;
3946
3947 pCaps->TextureAddressCaps = WINED3DPTADDRESSCAPS_INDEPENDENTUV |
3948 WINED3DPTADDRESSCAPS_CLAMP |
3949 WINED3DPTADDRESSCAPS_WRAP;
3950
3951 if (GL_SUPPORT(ARB_TEXTURE_BORDER_CLAMP)) {
3952 pCaps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_BORDER;
3953 }
3954 if (GL_SUPPORT(ARB_TEXTURE_MIRRORED_REPEAT)) {
3955 pCaps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRROR;
3956 }
3957 if (GL_SUPPORT(ATI_TEXTURE_MIRROR_ONCE)) {
3958 pCaps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRRORONCE;
3959 }
3960
3961 if (GL_SUPPORT(EXT_TEXTURE3D)) {
3962 pCaps->VolumeTextureAddressCaps = WINED3DPTADDRESSCAPS_INDEPENDENTUV |
3963 WINED3DPTADDRESSCAPS_CLAMP |
3964 WINED3DPTADDRESSCAPS_WRAP;
3965 if (GL_SUPPORT(ARB_TEXTURE_BORDER_CLAMP)) {
3966 pCaps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_BORDER;
3967 }
3968 if (GL_SUPPORT(ARB_TEXTURE_MIRRORED_REPEAT)) {
3969 pCaps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRROR;
3970 }
3971 if (GL_SUPPORT(ATI_TEXTURE_MIRROR_ONCE)) {
3972 pCaps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRRORONCE;
3973 }
3974 } else
3975 pCaps->VolumeTextureAddressCaps = 0;
3976
3977 pCaps->LineCaps = WINED3DLINECAPS_TEXTURE |
3978 WINED3DLINECAPS_ZTEST |
3979 WINED3DLINECAPS_BLEND |
3980 WINED3DLINECAPS_ALPHACMP |
3981 WINED3DLINECAPS_FOG;
3982 /* WINED3DLINECAPS_ANTIALIAS is not supported on Windows, and dx and gl seem to have a different
3983 * idea how generating the smoothing alpha values works; the result is different
3984 */
3985
3986 pCaps->MaxTextureWidth = GL_LIMITS(texture_size);
3987 pCaps->MaxTextureHeight = GL_LIMITS(texture_size);
3988
3989 if(GL_SUPPORT(EXT_TEXTURE3D))
3990 pCaps->MaxVolumeExtent = GL_LIMITS(texture3d_size);
3991 else
3992 pCaps->MaxVolumeExtent = 0;
3993
3994 pCaps->MaxTextureRepeat = 32768;
3995 pCaps->MaxTextureAspectRatio = GL_LIMITS(texture_size);
3996 pCaps->MaxVertexW = 1.0f;
3997
3998 pCaps->GuardBandLeft = 0.0f;
3999 pCaps->GuardBandTop = 0.0f;
4000 pCaps->GuardBandRight = 0.0f;
4001 pCaps->GuardBandBottom = 0.0f;
4002
4003 pCaps->ExtentsAdjust = 0.0f;
4004
4005 pCaps->StencilCaps = WINED3DSTENCILCAPS_DECRSAT |
4006 WINED3DSTENCILCAPS_INCRSAT |
4007 WINED3DSTENCILCAPS_INVERT |
4008 WINED3DSTENCILCAPS_KEEP |
4009 WINED3DSTENCILCAPS_REPLACE |
4010 WINED3DSTENCILCAPS_ZERO;
4011 if (GL_SUPPORT(EXT_STENCIL_WRAP)) {
4012 pCaps->StencilCaps |= WINED3DSTENCILCAPS_DECR |
4013 WINED3DSTENCILCAPS_INCR;
4014 }
4015 if (GL_SUPPORT(EXT_STENCIL_TWO_SIDE) || GL_SUPPORT(ATI_SEPARATE_STENCIL)) {
4016 pCaps->StencilCaps |= WINED3DSTENCILCAPS_TWOSIDED;
4017 }
4018
4019 pCaps->FVFCaps = WINED3DFVFCAPS_PSIZE | 0x0008; /* 8 texture coords */
4020
4021 pCaps->MaxUserClipPlanes = GL_LIMITS(clipplanes);
4022 pCaps->MaxActiveLights = GL_LIMITS(lights);
4023
4024 pCaps->MaxVertexBlendMatrices = GL_LIMITS(blends);
4025 pCaps->MaxVertexBlendMatrixIndex = 0;
4026
4027 pCaps->MaxAnisotropy = GL_LIMITS(anisotropy);
4028 pCaps->MaxPointSize = GL_LIMITS(pointsize);
4029
4030
4031 /* FIXME: Add D3DVTXPCAPS_TWEENING, D3DVTXPCAPS_TEXGEN_SPHEREMAP */
4032 pCaps->VertexProcessingCaps = WINED3DVTXPCAPS_DIRECTIONALLIGHTS |
4033 WINED3DVTXPCAPS_MATERIALSOURCE7 |
4034 WINED3DVTXPCAPS_POSITIONALLIGHTS |
4035 WINED3DVTXPCAPS_LOCALVIEWER |
4036 WINED3DVTXPCAPS_VERTEXFOG |
4037 WINED3DVTXPCAPS_TEXGEN;
4038
4039 pCaps->MaxPrimitiveCount = 0xFFFFF; /* For now set 2^20-1 which is used by most >=Geforce3/Radeon8500 cards */
4040 pCaps->MaxVertexIndex = 0xFFFFF;
4041 pCaps->MaxStreams = MAX_STREAMS;
4042 pCaps->MaxStreamStride = 1024;
4043
4044 /* d3d9.dll sets D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES here because StretchRects is implemented in d3d9 */
4045 pCaps->DevCaps2 = WINED3DDEVCAPS2_STREAMOFFSET |
4046 WINED3DDEVCAPS2_VERTEXELEMENTSCANSHARESTREAMOFFSET;
4047 pCaps->MaxNpatchTessellationLevel = 0;
4048 pCaps->MasterAdapterOrdinal = 0;
4049 pCaps->AdapterOrdinalInGroup = 0;
4050 pCaps->NumberOfAdaptersInGroup = 1;
4051
4052 pCaps->NumSimultaneousRTs = GL_LIMITS(buffers);
4053
4054 pCaps->StretchRectFilterCaps = WINED3DPTFILTERCAPS_MINFPOINT |
4055 WINED3DPTFILTERCAPS_MAGFPOINT |
4056 WINED3DPTFILTERCAPS_MINFLINEAR |
4057 WINED3DPTFILTERCAPS_MAGFLINEAR;
4058 pCaps->VertexTextureFilterCaps = 0;
4059
4060 memset(&shader_caps, 0, sizeof(shader_caps));
4061 shader_backend = select_shader_backend(adapter, DeviceType);
4062 shader_backend->shader_get_caps(DeviceType, &adapter->gl_info, &shader_caps);
4063
4064 memset(&fragment_caps, 0, sizeof(fragment_caps));
4065 frag_pipeline = select_fragment_implementation(adapter, DeviceType);
4066 frag_pipeline->get_caps(DeviceType, &adapter->gl_info, &fragment_caps);
4067
4068 /* Add shader misc caps. Only some of them belong to the shader parts of the pipeline */
4069 pCaps->PrimitiveMiscCaps |= fragment_caps.PrimitiveMiscCaps;
4070
4071 /* This takes care for disabling vertex shader or pixel shader caps while leaving the other one enabled.
4072 * Ignore shader model capabilities if disabled in config
4073 */
4074 if(vs_selected_mode == SHADER_NONE) {
4075 TRACE_(d3d_caps)("Vertex shader disabled in config, reporting version 0.0\n");
4076 pCaps->VertexShaderVersion = WINED3DVS_VERSION(0,0);
4077 pCaps->MaxVertexShaderConst = 0;
4078 } else {
4079 pCaps->VertexShaderVersion = shader_caps.VertexShaderVersion;
4080 pCaps->MaxVertexShaderConst = shader_caps.MaxVertexShaderConst;
4081 }
4082
4083 if(ps_selected_mode == SHADER_NONE) {
4084 TRACE_(d3d_caps)("Pixel shader disabled in config, reporting version 0.0\n");
4085 pCaps->PixelShaderVersion = WINED3DPS_VERSION(0,0);
4086 pCaps->PixelShader1xMaxValue = 0.0f;
4087 } else {
4088 pCaps->PixelShaderVersion = shader_caps.PixelShaderVersion;
4089 pCaps->PixelShader1xMaxValue = shader_caps.PixelShader1xMaxValue;
4090 }
4091
4092 pCaps->TextureOpCaps = fragment_caps.TextureOpCaps;
4093 pCaps->MaxTextureBlendStages = fragment_caps.MaxTextureBlendStages;
4094 pCaps->MaxSimultaneousTextures = fragment_caps.MaxSimultaneousTextures;
4095
4096 pCaps->VS20Caps = shader_caps.VS20Caps;
4097 pCaps->MaxVShaderInstructionsExecuted = shader_caps.MaxVShaderInstructionsExecuted;
4098 pCaps->MaxVertexShader30InstructionSlots= shader_caps.MaxVertexShader30InstructionSlots;
4099 pCaps->PS20Caps = shader_caps.PS20Caps;
4100 pCaps->MaxPShaderInstructionsExecuted = shader_caps.MaxPShaderInstructionsExecuted;
4101 pCaps->MaxPixelShader30InstructionSlots = shader_caps.MaxPixelShader30InstructionSlots;
4102
4103 /* The following caps are shader specific, but they are things we cannot detect, or which
4104 * are the same among all shader models. So to avoid code duplication set the shader version
4105 * specific, but otherwise constant caps here
4106 */
4107 if(pCaps->VertexShaderVersion == WINED3DVS_VERSION(3,0)) {
4108 /* Where possible set the caps based on OpenGL extensions and if they aren't set (in case of software rendering)
4109 use the VS 3.0 from MSDN or else if there's OpenGL spec use a hardcoded value minimum VS3.0 value. */
4110 pCaps->VS20Caps.Caps = WINED3DVS20CAPS_PREDICATION;
4111 pCaps->VS20Caps.DynamicFlowControlDepth = WINED3DVS20_MAX_DYNAMICFLOWCONTROLDEPTH; /* VS 3.0 requires MAX_DYNAMICFLOWCONTROLDEPTH (24) */
4112 pCaps->VS20Caps.NumTemps = max(32, adapter->gl_info.vs_arb_max_temps);
4113 pCaps->VS20Caps.StaticFlowControlDepth = WINED3DVS20_MAX_STATICFLOWCONTROLDEPTH ; /* level of nesting in loops / if-statements; VS 3.0 requires MAX (4) */
4114
4115 pCaps->MaxVShaderInstructionsExecuted = 65535; /* VS 3.0 needs at least 65535, some cards even use 2^32-1 */
4116 pCaps->MaxVertexShader30InstructionSlots = max(512, adapter->gl_info.vs_arb_max_instructions);
4117 } else if(pCaps->VertexShaderVersion == WINED3DVS_VERSION(2,0)) {
4118 pCaps->VS20Caps.Caps = 0;
4119 pCaps->VS20Caps.DynamicFlowControlDepth = WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH;
4120 pCaps->VS20Caps.NumTemps = max(12, adapter->gl_info.vs_arb_max_temps);
4121 pCaps->VS20Caps.StaticFlowControlDepth = 1;
4122
4123 pCaps->MaxVShaderInstructionsExecuted = 65535;
4124 pCaps->MaxVertexShader30InstructionSlots = 0;
4125 } else { /* VS 1.x */
4126 pCaps->VS20Caps.Caps = 0;
4127 pCaps->VS20Caps.DynamicFlowControlDepth = 0;
4128 pCaps->VS20Caps.NumTemps = 0;
4129 pCaps->VS20Caps.StaticFlowControlDepth = 0;
4130
4131 pCaps->MaxVShaderInstructionsExecuted = 0;
4132 pCaps->MaxVertexShader30InstructionSlots = 0;
4133 }
4134
4135 if(pCaps->PixelShaderVersion == WINED3DPS_VERSION(3,0)) {
4136 /* Where possible set the caps based on OpenGL extensions and if they aren't set (in case of software rendering)
4137 use the PS 3.0 from MSDN or else if there's OpenGL spec use a hardcoded value minimum PS 3.0 value. */
4138
4139 /* Caps is more or less undocumented on MSDN but it appears to be used for PS20Caps based on results from R9600/FX5900/Geforce6800 cards from Windows */
4140 pCaps->PS20Caps.Caps = WINED3DPS20CAPS_ARBITRARYSWIZZLE |
4141 WINED3DPS20CAPS_GRADIENTINSTRUCTIONS |
4142 WINED3DPS20CAPS_PREDICATION |
4143 WINED3DPS20CAPS_NODEPENDENTREADLIMIT |
4144 WINED3DPS20CAPS_NOTEXINSTRUCTIONLIMIT;
4145 pCaps->PS20Caps.DynamicFlowControlDepth = WINED3DPS20_MAX_DYNAMICFLOWCONTROLDEPTH; /* PS 3.0 requires MAX_DYNAMICFLOWCONTROLDEPTH (24) */
4146 pCaps->PS20Caps.NumTemps = max(32, adapter->gl_info.ps_arb_max_temps);
4147 pCaps->PS20Caps.StaticFlowControlDepth = WINED3DPS20_MAX_STATICFLOWCONTROLDEPTH; /* PS 3.0 requires MAX_STATICFLOWCONTROLDEPTH (4) */
4148 pCaps->PS20Caps.NumInstructionSlots = WINED3DPS20_MAX_NUMINSTRUCTIONSLOTS; /* PS 3.0 requires MAX_NUMINSTRUCTIONSLOTS (512) */
4149
4150 pCaps->MaxPShaderInstructionsExecuted = 65535;
4151 pCaps->MaxPixelShader30InstructionSlots = max(WINED3DMIN30SHADERINSTRUCTIONS, adapter->gl_info.ps_arb_max_instructions);
4152 } else if(pCaps->PixelShaderVersion == WINED3DPS_VERSION(2,0)) {
4153 /* Below we assume PS2.0 specs, not extended 2.0a(GeforceFX)/2.0b(Radeon R3xx) ones */
4154 pCaps->PS20Caps.Caps = 0;
4155 pCaps->PS20Caps.DynamicFlowControlDepth = 0; /* WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH = 0 */
4156 pCaps->PS20Caps.NumTemps = max(12, adapter->gl_info.ps_arb_max_temps);
4157 pCaps->PS20Caps.StaticFlowControlDepth = WINED3DPS20_MIN_STATICFLOWCONTROLDEPTH; /* Minimum: 1 */
4158 pCaps->PS20Caps.NumInstructionSlots = WINED3DPS20_MIN_NUMINSTRUCTIONSLOTS; /* Minimum number (64 ALU + 32 Texture), a GeforceFX uses 512 */
4159
4160 pCaps->MaxPShaderInstructionsExecuted = 512; /* Minimum value, a GeforceFX uses 1024 */
4161 pCaps->MaxPixelShader30InstructionSlots = 0;
4162 } else { /* PS 1.x */
4163 pCaps->PS20Caps.Caps = 0;
4164 pCaps->PS20Caps.DynamicFlowControlDepth = 0;
4165 pCaps->PS20Caps.NumTemps = 0;
4166 pCaps->PS20Caps.StaticFlowControlDepth = 0;
4167 pCaps->PS20Caps.NumInstructionSlots = 0;
4168
4169 pCaps->MaxPShaderInstructionsExecuted = 0;
4170 pCaps->MaxPixelShader30InstructionSlots = 0;
4171 }
4172
4173 if(pCaps->VertexShaderVersion >= WINED3DVS_VERSION(2,0)) {
4174 /* OpenGL supports all the formats below, perhaps not always
4175 * without conversion, but it supports them.
4176 * Further GLSL doesn't seem to have an official unsigned type so
4177 * don't advertise it yet as I'm not sure how we handle it.
4178 * We might need to add some clamping in the shader engine to
4179 * support it.
4180 * TODO: WINED3DDTCAPS_USHORT2N, WINED3DDTCAPS_USHORT4N, WINED3DDTCAPS_UDEC3, WINED3DDTCAPS_DEC3N */
4181 pCaps->DeclTypes = WINED3DDTCAPS_UBYTE4 |
4182 WINED3DDTCAPS_UBYTE4N |
4183 WINED3DDTCAPS_SHORT2N |
4184 WINED3DDTCAPS_SHORT4N;
4185 if (GL_SUPPORT(ARB_HALF_FLOAT_VERTEX)) {
4186 pCaps->DeclTypes |= WINED3DDTCAPS_FLOAT16_2 |
4187 WINED3DDTCAPS_FLOAT16_4;
4188 }
4189 } else
4190 pCaps->DeclTypes = 0;
4191
4192 /* Set DirectDraw helper Caps */
4193 ckey_caps = WINEDDCKEYCAPS_DESTBLT |
4194 WINEDDCKEYCAPS_SRCBLT;
4195 fx_caps = WINEDDFXCAPS_BLTALPHA |
4196 WINEDDFXCAPS_BLTMIRRORLEFTRIGHT |
4197 WINEDDFXCAPS_BLTMIRRORUPDOWN |
4198 WINEDDFXCAPS_BLTROTATION90 |
4199 WINEDDFXCAPS_BLTSHRINKX |
4200 WINEDDFXCAPS_BLTSHRINKXN |
4201 WINEDDFXCAPS_BLTSHRINKY |
4202 WINEDDFXCAPS_BLTSHRINKXN |
4203 WINEDDFXCAPS_BLTSTRETCHX |
4204 WINEDDFXCAPS_BLTSTRETCHXN |
4205 WINEDDFXCAPS_BLTSTRETCHY |
4206 WINEDDFXCAPS_BLTSTRETCHYN;
4207 blit_caps = WINEDDCAPS_BLT |
4208 WINEDDCAPS_BLTCOLORFILL |
4209 WINEDDCAPS_BLTDEPTHFILL |
4210 WINEDDCAPS_BLTSTRETCH |
4211 WINEDDCAPS_CANBLTSYSMEM |
4212 WINEDDCAPS_CANCLIP |
4213 WINEDDCAPS_CANCLIPSTRETCHED |
4214 WINEDDCAPS_COLORKEY |
4215 WINEDDCAPS_COLORKEYHWASSIST |
4216 WINEDDCAPS_ALIGNBOUNDARYSRC;
4217
4218 /* Fill the ddraw caps structure */
4219 pCaps->DirectDrawCaps.Caps = WINEDDCAPS_GDI |
4220 WINEDDCAPS_PALETTE |
4221 blit_caps;
4222 pCaps->DirectDrawCaps.Caps2 = WINEDDCAPS2_CERTIFIED |
4223 WINEDDCAPS2_NOPAGELOCKREQUIRED |
4224 WINEDDCAPS2_PRIMARYGAMMA |
4225 WINEDDCAPS2_WIDESURFACES |
4226 WINEDDCAPS2_CANRENDERWINDOWED;
4227 pCaps->DirectDrawCaps.SVBCaps = blit_caps;
4228 pCaps->DirectDrawCaps.SVBCKeyCaps = ckey_caps;
4229 pCaps->DirectDrawCaps.SVBFXCaps = fx_caps;
4230 pCaps->DirectDrawCaps.VSBCaps = blit_caps;
4231 pCaps->DirectDrawCaps.VSBCKeyCaps = ckey_caps;
4232 pCaps->DirectDrawCaps.VSBFXCaps = fx_caps;
4233 pCaps->DirectDrawCaps.SSBCaps = blit_caps;
4234 pCaps->DirectDrawCaps.SSBCKeyCaps = ckey_caps;
4235 pCaps->DirectDrawCaps.SSBFXCaps = fx_caps;
4236
4237 pCaps->DirectDrawCaps.ddsCaps = WINEDDSCAPS_ALPHA |
4238 WINEDDSCAPS_BACKBUFFER |
4239 WINEDDSCAPS_FLIP |
4240 WINEDDSCAPS_FRONTBUFFER |
4241 WINEDDSCAPS_OFFSCREENPLAIN |
4242 WINEDDSCAPS_PALETTE |
4243 WINEDDSCAPS_PRIMARYSURFACE |
4244 WINEDDSCAPS_SYSTEMMEMORY |
4245 WINEDDSCAPS_VIDEOMEMORY |
4246 WINEDDSCAPS_VISIBLE;
4247 pCaps->DirectDrawCaps.StrideAlign = DDRAW_PITCH_ALIGNMENT;
4248
4249 /* Set D3D caps if OpenGL is available. */
4250 if (adapter->opengl)
4251 {
4252 pCaps->DirectDrawCaps.ddsCaps |=WINEDDSCAPS_3DDEVICE |
4253 WINEDDSCAPS_MIPMAP |
4254 WINEDDSCAPS_TEXTURE |
4255 WINEDDSCAPS_ZBUFFER;
4256 pCaps->DirectDrawCaps.Caps |= WINEDDCAPS_3D;
4257 }
4258
4259 return WINED3D_OK;
4260 }
4261
4262 /* Note due to structure differences between dx8 and dx9 D3DPRESENT_PARAMETERS,
4263 and fields being inserted in the middle, a new structure is used in place */
4264 static HRESULT WINAPI IWineD3DImpl_CreateDevice(IWineD3D *iface, UINT Adapter,
4265 WINED3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviourFlags, IUnknown *parent,
4266 IWineD3DDeviceParent *device_parent, IWineD3DDevice **ppReturnedDeviceInterface)
4267 {
4268 IWineD3DDeviceImpl *object = NULL;
4269 IWineD3DImpl *This = (IWineD3DImpl *)iface;
4270 struct WineD3DAdapter *adapter = &This->adapters[Adapter];
4271 WINED3DDISPLAYMODE mode;
4272 const struct fragment_pipeline *frag_pipeline = NULL;
4273 int i;
4274 struct fragment_caps ffp_caps;
4275 struct shader_caps shader_caps;
4276 HRESULT hr;
4277
4278 /* Validate the adapter number. If no adapters are available(no GL), ignore the adapter
4279 * number and create a device without a 3D adapter for 2D only operation.
4280 */
4281 if (IWineD3D_GetAdapterCount(iface) && Adapter >= IWineD3D_GetAdapterCount(iface)) {
4282 return WINED3DERR_INVALIDCALL;
4283 }
4284
4285 /* Create a WineD3DDevice object */
4286 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DDeviceImpl));
4287 *ppReturnedDeviceInterface = (IWineD3DDevice *)object;
4288 TRACE("Created WineD3DDevice object @ %p\n", object);
4289 if (NULL == object) {
4290 return WINED3DERR_OUTOFVIDEOMEMORY;
4291 }
4292
4293 /* Set up initial COM information */
4294 object->lpVtbl = &IWineD3DDevice_Vtbl;
4295 object->ref = 1;
4296 object->wineD3D = iface;
4297 object->adapter = This->adapter_count ? adapter : NULL;
4298 IWineD3D_AddRef(object->wineD3D);
4299 object->parent = parent;
4300 object->device_parent = device_parent;
4301 list_init(&object->resources);
4302 list_init(&object->shaders);
4303
4304 if(This->dxVersion == 7) {
4305 object->surface_alignment = DDRAW_PITCH_ALIGNMENT;
4306 } else {
4307 object->surface_alignment = D3D8_PITCH_ALIGNMENT;
4308 }
4309 object->posFixup[0] = 1.0f; /* This is needed to get the x coord unmodified through a MAD. */
4310
4311 /* Set the state up as invalid until the device is fully created */
4312 object->state = WINED3DERR_DRIVERINTERNALERROR;
4313
4314 TRACE("(%p)->(Adptr:%d, DevType: %x, FocusHwnd: %p, BehFlags: %x, RetDevInt: %p)\n", This, Adapter, DeviceType,
4315 hFocusWindow, BehaviourFlags, ppReturnedDeviceInterface);
4316
4317 /* Save the creation parameters */
4318 object->createParms.AdapterOrdinal = Adapter;
4319 object->createParms.DeviceType = DeviceType;
4320 object->createParms.hFocusWindow = hFocusWindow;
4321 object->createParms.BehaviorFlags = BehaviourFlags;
4322
4323 /* Initialize other useful values */
4324 object->adapterNo = Adapter;
4325 object->devType = DeviceType;
4326
4327 select_shader_mode(&adapter->gl_info, &object->ps_selected_mode, &object->vs_selected_mode);
4328 object->shader_backend = select_shader_backend(adapter, DeviceType);
4329
4330 memset(&shader_caps, 0, sizeof(shader_caps));
4331 object->shader_backend->shader_get_caps(DeviceType, &adapter->gl_info, &shader_caps);
4332 object->d3d_vshader_constantF = shader_caps.MaxVertexShaderConst;
4333 object->d3d_pshader_constantF = shader_caps.MaxPixelShaderConst;
4334 object->vs_clipping = shader_caps.VSClipping;
4335
4336 memset(&ffp_caps, 0, sizeof(ffp_caps));
4337 frag_pipeline = select_fragment_implementation(adapter, DeviceType);
4338 object->frag_pipe = frag_pipeline;
4339 frag_pipeline->get_caps(DeviceType, &adapter->gl_info, &ffp_caps);
4340 object->max_ffp_textures = ffp_caps.MaxSimultaneousTextures;
4341 object->max_ffp_texture_stages = ffp_caps.MaxTextureBlendStages;
4342 hr = compile_state_table(object->StateTable, object->multistate_funcs, &adapter->gl_info,
4343 ffp_vertexstate_template, frag_pipeline, misc_state_template);
4344
4345 if (FAILED(hr)) {
4346 IWineD3D_Release(object->wineD3D);
4347 HeapFree(GetProcessHeap(), 0, object);
4348
4349 return hr;
4350 }
4351
4352 object->blitter = select_blit_implementation(adapter, DeviceType);
4353
4354 /* set the state of the device to valid */
4355 object->state = WINED3D_OK;
4356
4357 /* Get the initial screen setup for ddraw */
4358 IWineD3DImpl_GetAdapterDisplayMode(iface, Adapter, &mode);
4359
4360 object->ddraw_width = mode.Width;
4361 object->ddraw_height = mode.Height;
4362 object->ddraw_format = mode.Format;
4363
4364 for(i = 0; i < PATCHMAP_SIZE; i++) {
4365 list_init(&object->patches[i]);
4366 }
4367
4368 IWineD3DDeviceParent_WineD3DDeviceCreated(device_parent, *ppReturnedDeviceInterface);
4369
4370 return WINED3D_OK;
4371 }
4372
4373 static HRESULT WINAPI IWineD3DImpl_GetParent(IWineD3D *iface, IUnknown **pParent) {
4374 IWineD3DImpl *This = (IWineD3DImpl *)iface;
4375 IUnknown_AddRef(This->parent);
4376 *pParent = This->parent;
4377 return WINED3D_OK;
4378 }
4379
4380 ULONG WINAPI D3DCB_DefaultDestroyVolume(IWineD3DVolume *pVolume) {
4381 IUnknown* volumeParent;
4382 TRACE("(%p) call back\n", pVolume);
4383
4384 /* Now, release the parent, which will take care of cleaning up the volume for us */
4385 IWineD3DVolume_GetParent(pVolume, &volumeParent);
4386 IUnknown_Release(volumeParent);
4387 return IUnknown_Release(volumeParent);
4388 }
4389
4390 static void WINE_GLAPI invalid_func(const void *data)
4391 {
4392 ERR("Invalid vertex attribute function called\n");
4393 DebugBreak();
4394 }
4395
4396 static void WINE_GLAPI invalid_texcoord_func(GLenum unit, const void *data)
4397 {
4398 ERR("Invalid texcoord function called\n");
4399 DebugBreak();
4400 }
4401
4402 /* Helper functions for providing vertex data to opengl. The arrays are initialized based on
4403 * the extension detection and are used in drawStridedSlow
4404 */
4405 static void WINE_GLAPI position_d3dcolor(const void *data)
4406 {
4407 DWORD pos = *((const DWORD *)data);
4408
4409 FIXME("Add a test for fixed function position from d3dcolor type\n");
4410 glVertex4s(D3DCOLOR_B_R(pos),
4411 D3DCOLOR_B_G(pos),
4412 D3DCOLOR_B_B(pos),
4413 D3DCOLOR_B_A(pos));
4414 }
4415
4416 static void WINE_GLAPI position_float4(const void *data)
4417 {
4418 const GLfloat *pos = data;
4419
4420 if (pos[3] != 0.0f && pos[3] != 1.0f)
4421 {
4422 float w = 1.0f / pos[3];
4423
4424 glVertex4f(pos[0] * w, pos[1] * w, pos[2] * w, w);
4425 }
4426 else
4427 {
4428 glVertex3fv(pos);
4429 }
4430 }
4431
4432 static void WINE_GLAPI diffuse_d3dcolor(const void *data)
4433 {
4434 DWORD diffuseColor = *((const DWORD *)data);
4435
4436 glColor4ub(D3DCOLOR_B_R(diffuseColor),
4437 D3DCOLOR_B_G(diffuseColor),
4438 D3DCOLOR_B_B(diffuseColor),
4439 D3DCOLOR_B_A(diffuseColor));
4440 }
4441
4442 static void WINE_GLAPI specular_d3dcolor(const void *data)
4443 {
4444 DWORD specularColor = *((const DWORD *)data);
4445 GLbyte d[] = {D3DCOLOR_B_R(specularColor),
4446 D3DCOLOR_B_G(specularColor),
4447 D3DCOLOR_B_B(specularColor)};
4448
4449 specular_func_3ubv(d);
4450 }
4451
4452 static void WINE_GLAPI warn_no_specular_func(const void *data)
4453 {
4454 WARN("GL_EXT_secondary_color not supported\n");
4455 }
4456
4457 static void fillGLAttribFuncs(const struct wined3d_gl_info *gl_info)
4458 {
4459 position_funcs[WINED3D_FFP_EMIT_FLOAT1] = invalid_func;
4460 position_funcs[WINED3D_FFP_EMIT_FLOAT2] = invalid_func;
4461 position_funcs[WINED3D_FFP_EMIT_FLOAT3] = (glAttribFunc)glVertex3fv;
4462 position_funcs[WINED3D_FFP_EMIT_FLOAT4] = position_float4;
4463 position_funcs[WINED3D_FFP_EMIT_D3DCOLOR] = position_d3dcolor;
4464 position_funcs[WINED3D_FFP_EMIT_UBYTE4] = invalid_func;
4465 position_funcs[WINED3D_FFP_EMIT_SHORT2] = invalid_func;
4466 position_funcs[WINED3D_FFP_EMIT_SHORT4] = (glAttribFunc)glVertex2sv;
4467 position_funcs[WINED3D_FFP_EMIT_UBYTE4N] = invalid_func;
4468 position_funcs[WINED3D_FFP_EMIT_SHORT2N] = invalid_func;
4469 position_funcs[WINED3D_FFP_EMIT_SHORT4N] = invalid_func;
4470 position_funcs[WINED3D_FFP_EMIT_USHORT2N] = invalid_func;
4471 position_funcs[WINED3D_FFP_EMIT_USHORT4N] = invalid_func;
4472 position_funcs[WINED3D_FFP_EMIT_UDEC3] = invalid_func;
4473 position_funcs[WINED3D_FFP_EMIT_DEC3N] = invalid_func;
4474 position_funcs[WINED3D_FFP_EMIT_FLOAT16_2] = invalid_func;
4475 position_funcs[WINED3D_FFP_EMIT_FLOAT16_4] = invalid_func;
4476
4477 diffuse_funcs[WINED3D_FFP_EMIT_FLOAT1] = invalid_func;
4478 diffuse_funcs[WINED3D_FFP_EMIT_FLOAT2] = invalid_func;
4479 diffuse_funcs[WINED3D_FFP_EMIT_FLOAT3] = (glAttribFunc)glColor3fv;
4480 diffuse_funcs[WINED3D_FFP_EMIT_FLOAT4] = (glAttribFunc)glColor4fv;
4481 diffuse_funcs[WINED3D_FFP_EMIT_D3DCOLOR] = diffuse_d3dcolor;
4482 diffuse_funcs[WINED3D_FFP_EMIT_UBYTE4] = invalid_func;
4483 diffuse_funcs[WINED3D_FFP_EMIT_SHORT2] = invalid_func;
4484 diffuse_funcs[WINED3D_FFP_EMIT_SHORT4] = invalid_func;
4485 diffuse_funcs[WINED3D_FFP_EMIT_UBYTE4N] = (glAttribFunc)glColor4ubv;
4486 diffuse_funcs[WINED3D_FFP_EMIT_SHORT2N] = invalid_func;
4487 diffuse_funcs[WINED3D_FFP_EMIT_SHORT4N] = (glAttribFunc)glColor4sv;
4488 diffuse_funcs[WINED3D_FFP_EMIT_USHORT2N] = invalid_func;
4489 diffuse_funcs[WINED3D_FFP_EMIT_USHORT4N] = (glAttribFunc)glColor4usv;
4490 diffuse_funcs[WINED3D_FFP_EMIT_UDEC3] = invalid_func;
4491 diffuse_funcs[WINED3D_FFP_EMIT_DEC3N] = invalid_func;
4492 diffuse_funcs[WINED3D_FFP_EMIT_FLOAT16_2] = invalid_func;
4493 diffuse_funcs[WINED3D_FFP_EMIT_FLOAT16_4] = invalid_func;
4494
4495 /* No 4 component entry points here */
4496 specular_funcs[WINED3D_FFP_EMIT_FLOAT1] = invalid_func;
4497 specular_funcs[WINED3D_FFP_EMIT_FLOAT2] = invalid_func;
4498 if(GL_SUPPORT(EXT_SECONDARY_COLOR)) {
4499 specular_funcs[WINED3D_FFP_EMIT_FLOAT3] = (glAttribFunc)GL_EXTCALL(glSecondaryColor3fvEXT);
4500 } else {
4501 specular_funcs[WINED3D_FFP_EMIT_FLOAT3] = warn_no_specular_func;
4502 }
4503 specular_funcs[WINED3D_FFP_EMIT_FLOAT4] = invalid_func;
4504 if(GL_SUPPORT(EXT_SECONDARY_COLOR)) {
4505 specular_func_3ubv = (glAttribFunc)GL_EXTCALL(glSecondaryColor3ubvEXT);
4506 specular_funcs[WINED3D_FFP_EMIT_D3DCOLOR] = specular_d3dcolor;
4507 } else {
4508 specular_funcs[WINED3D_FFP_EMIT_D3DCOLOR] = warn_no_specular_func;
4509 }
4510 specular_funcs[WINED3D_FFP_EMIT_UBYTE4] = invalid_func;
4511 specular_funcs[WINED3D_FFP_EMIT_SHORT2] = invalid_func;
4512 specular_funcs[WINED3D_FFP_EMIT_SHORT4] = invalid_func;
4513 specular_funcs[WINED3D_FFP_EMIT_UBYTE4N] = invalid_func;
4514 specular_funcs[WINED3D_FFP_EMIT_SHORT2N] = invalid_func;
4515 specular_funcs[WINED3D_FFP_EMIT_SHORT4N] = invalid_func;
4516 specular_funcs[WINED3D_FFP_EMIT_USHORT2N] = invalid_func;
4517 specular_funcs[WINED3D_FFP_EMIT_USHORT4N] = invalid_func;
4518 specular_funcs[WINED3D_FFP_EMIT_UDEC3] = invalid_func;
4519 specular_funcs[WINED3D_FFP_EMIT_DEC3N] = invalid_func;
4520 specular_funcs[WINED3D_FFP_EMIT_FLOAT16_2] = invalid_func;
4521 specular_funcs[WINED3D_FFP_EMIT_FLOAT16_4] = invalid_func;
4522
4523 /* Only 3 component entry points here. Test how others behave. Float4 normals are used
4524 * by one of our tests, trying to pass it to the pixel shader, which fails on Windows.
4525 */
4526 normal_funcs[WINED3D_FFP_EMIT_FLOAT1] = invalid_func;
4527 normal_funcs[WINED3D_FFP_EMIT_FLOAT2] = invalid_func;
4528 normal_funcs[WINED3D_FFP_EMIT_FLOAT3] = (glAttribFunc)glNormal3fv;
4529 normal_funcs[WINED3D_FFP_EMIT_FLOAT4] = (glAttribFunc)glNormal3fv; /* Just ignore the 4th value */
4530 normal_funcs[WINED3D_FFP_EMIT_D3DCOLOR] = invalid_func;
4531 normal_funcs[WINED3D_FFP_EMIT_UBYTE4] = invalid_func;
4532 normal_funcs[WINED3D_FFP_EMIT_SHORT2] = invalid_func;
4533 normal_funcs[WINED3D_FFP_EMIT_SHORT4] = invalid_func;
4534 normal_funcs[WINED3D_FFP_EMIT_UBYTE4N] = invalid_func;
4535 normal_funcs[WINED3D_FFP_EMIT_SHORT2N] = invalid_func;
4536 normal_funcs[WINED3D_FFP_EMIT_SHORT4N] = invalid_func;
4537 normal_funcs[WINED3D_FFP_EMIT_USHORT2N] = invalid_func;
4538 normal_funcs[WINED3D_FFP_EMIT_USHORT4N] = invalid_func;
4539 normal_funcs[WINED3D_FFP_EMIT_UDEC3] = invalid_func;
4540 normal_funcs[WINED3D_FFP_EMIT_DEC3N] = invalid_func;
4541 normal_funcs[WINED3D_FFP_EMIT_FLOAT16_2] = invalid_func;
4542 normal_funcs[WINED3D_FFP_EMIT_FLOAT16_4] = invalid_func;
4543
4544 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT1] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord1fvARB);
4545 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT2] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord2fvARB);
4546 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT3] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord3fvARB);
4547 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT4] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord4fvARB);
4548 multi_texcoord_funcs[WINED3D_FFP_EMIT_D3DCOLOR] = invalid_texcoord_func;
4549 multi_texcoord_funcs[WINED3D_FFP_EMIT_UBYTE4] = invalid_texcoord_func;
4550 multi_texcoord_funcs[WINED3D_FFP_EMIT_SHORT2] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord2svARB);
4551 multi_texcoord_funcs[WINED3D_FFP_EMIT_SHORT4] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord4svARB);
4552 multi_texcoord_funcs[WINED3D_FFP_EMIT_UBYTE4N] = invalid_texcoord_func;
4553 multi_texcoord_funcs[WINED3D_FFP_EMIT_SHORT2N] = invalid_texcoord_func;
4554 multi_texcoord_funcs[WINED3D_FFP_EMIT_SHORT4N] = invalid_texcoord_func;
4555 multi_texcoord_funcs[WINED3D_FFP_EMIT_USHORT2N] = invalid_texcoord_func;
4556 multi_texcoord_funcs[WINED3D_FFP_EMIT_USHORT4N] = invalid_texcoord_func;
4557 multi_texcoord_funcs[WINED3D_FFP_EMIT_UDEC3] = invalid_texcoord_func;
4558 multi_texcoord_funcs[WINED3D_FFP_EMIT_DEC3N] = invalid_texcoord_func;
4559 if (GL_SUPPORT(NV_HALF_FLOAT))
4560 {
4561 /* Not supported by ARB_HALF_FLOAT_VERTEX, so check for NV_HALF_FLOAT */
4562 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT16_2] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord2hvNV);
4563 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT16_4] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord4hvNV);
4564 } else {
4565 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT16_2] = invalid_texcoord_func;
4566 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT16_4] = invalid_texcoord_func;
4567 }
4568 }
4569
4570 BOOL InitAdapters(IWineD3DImpl *This)
4571 {
4572 static HMODULE mod_gl;
4573 BOOL ret;
4574 int ps_selected_mode, vs_selected_mode;
4575
4576 /* No need to hold any lock. The calling library makes sure only one thread calls
4577 * wined3d simultaneously
4578 */
4579
4580 TRACE("Initializing adapters\n");
4581
4582 if(!mod_gl) {
4583 #ifdef USE_WIN32_OPENGL
4584 #define USE_GL_FUNC(pfn) pfn = (void*)GetProcAddress(mod_gl, #pfn);
4585 mod_gl = LoadLibraryA("opengl32.dll");
4586 if(!mod_gl) {
4587 ERR("Can't load opengl32.dll!\n");
4588 goto nogl_adapter;
4589 }
4590 #else
4591 #define USE_GL_FUNC(pfn) pfn = (void*)pwglGetProcAddress(#pfn);
4592 /* To bypass the opengl32 thunks load wglGetProcAddress from gdi32 (glXGetProcAddress wrapper) instead of opengl32's */
4593 mod_gl = GetModuleHandleA("gdi32.dll");
4594 #endif
4595 }
4596
4597 /* Load WGL core functions from opengl32.dll */
4598 #define USE_WGL_FUNC(pfn) p##pfn = (void*)GetProcAddress(mod_gl, #pfn);
4599 WGL_FUNCS_GEN;
4600 #undef USE_WGL_FUNC
4601
4602 if(!pwglGetProcAddress) {
4603 ERR("Unable to load wglGetProcAddress!\n");
4604 goto nogl_adapter;
4605 }
4606
4607 /* Dynamically load all GL core functions */
4608 GL_FUNCS_GEN;
4609 #undef USE_GL_FUNC
4610
4611 /* Load glFinish and glFlush from opengl32.dll even if we're not using WIN32 opengl
4612 * otherwise because we have to use winex11.drv's override
4613 */
4614 #ifdef USE_WIN32_OPENGL
4615 wglFinish = (void*)GetProcAddress(mod_gl, "glFinish");
4616 wglFlush = (void*)GetProcAddress(mod_gl, "glFlush");
4617 #else
4618 wglFinish = (void*)pwglGetProcAddress("wglFinish");
4619 wglFlush = (void*)pwglGetProcAddress("wglFlush");
4620 #endif
4621
4622 glEnableWINE = glEnable;
4623 glDisableWINE = glDisable;
4624
4625 /* For now only one default adapter */
4626 {
4627 struct WineD3DAdapter *adapter = &This->adapters[0];
4628 const struct wined3d_gl_info *gl_info = &adapter->gl_info;
4629 struct wined3d_fake_gl_ctx fake_gl_ctx = {0};
4630 int iPixelFormat;
4631 int res;
4632 int i;
4633 WineD3D_PixelFormat *cfgs;
4634 DISPLAY_DEVICEW DisplayDevice;
4635 HDC hdc;
4636
4637 TRACE("Initializing default adapter\n");
4638 adapter->num = 0;
4639 adapter->monitorPoint.x = -1;
4640 adapter->monitorPoint.y = -1;
4641
4642 if (!WineD3D_CreateFakeGLContext(&fake_gl_ctx))
4643 {
4644 ERR("Failed to get a gl context for default adapter\n");
4645 goto nogl_adapter;
4646 }
4647
4648 ret = IWineD3DImpl_FillGLCaps(&adapter->gl_info);
4649 if(!ret) {
4650 ERR("Failed to initialize gl caps for default adapter\n");
4651 WineD3D_ReleaseFakeGLContext(&fake_gl_ctx);
4652 goto nogl_adapter;
4653 }
4654 ret = initPixelFormats(&adapter->gl_info);
4655 if(!ret) {
4656 ERR("Failed to init gl formats\n");
4657 WineD3D_ReleaseFakeGLContext(&fake_gl_ctx);
4658 goto nogl_adapter;
4659 }
4660
4661 hdc = fake_gl_ctx.dc;
4662
4663 adapter->driver = "Display";
4664 adapter->description = "Direct3D HAL";
4665
4666 /* Use the VideoRamSize registry setting when set */
4667 if(wined3d_settings.emulated_textureram)
4668 adapter->TextureRam = wined3d_settings.emulated_textureram;
4669 else
4670 adapter->TextureRam = adapter->gl_info.vidmem;
4671 adapter->UsedTextureRam = 0;
4672 TRACE("Emulating %dMB of texture ram\n", adapter->TextureRam/(1024*1024));
4673
4674 /* Initialize the Adapter's DeviceName which is required for ChangeDisplaySettings and friends */
4675 DisplayDevice.cb = sizeof(DisplayDevice);
4676 EnumDisplayDevicesW(NULL, 0 /* Adapter 0 = iDevNum 0 */, &DisplayDevice, 0);
4677 TRACE("DeviceName: %s\n", debugstr_w(DisplayDevice.DeviceName));
4678 strcpyW(adapter->DeviceName, DisplayDevice.DeviceName);
4679
4680 if(GL_SUPPORT(WGL_ARB_PIXEL_FORMAT))
4681 {
4682 int attribute;
4683 int attribs[10];
4684 int values[10];
4685 int nAttribs = 0;
4686
4687 attribute = WGL_NUMBER_PIXEL_FORMATS_ARB;
4688 GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, 0, 0, 1, &attribute, &adapter->nCfgs));
4689
4690 adapter->cfgs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, adapter->nCfgs *sizeof(WineD3D_PixelFormat));
4691 cfgs = adapter->cfgs;
4692 attribs[nAttribs++] = WGL_RED_BITS_ARB;
4693 attribs[nAttribs++] = WGL_GREEN_BITS_ARB;
4694 attribs[nAttribs++] = WGL_BLUE_BITS_ARB;
4695 attribs[nAttribs++] = WGL_ALPHA_BITS_ARB;
4696 attribs[nAttribs++] = WGL_DEPTH_BITS_ARB;
4697 attribs[nAttribs++] = WGL_STENCIL_BITS_ARB;
4698 attribs[nAttribs++] = WGL_DRAW_TO_WINDOW_ARB;
4699 attribs[nAttribs++] = WGL_PIXEL_TYPE_ARB;
4700 attribs[nAttribs++] = WGL_DOUBLE_BUFFER_ARB;
4701 attribs[nAttribs++] = WGL_AUX_BUFFERS_ARB;
4702
4703 for (iPixelFormat=1; iPixelFormat <= adapter->nCfgs; ++iPixelFormat)
4704 {
4705 res = GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0, nAttribs, attribs, values));
4706
4707 if(!res)
4708 continue;
4709
4710 /* Cache the pixel format */
4711 cfgs->iPixelFormat = iPixelFormat;
4712 cfgs->redSize = values[0];
4713 cfgs->greenSize = values[1];
4714 cfgs->blueSize = values[2];
4715 cfgs->alphaSize = values[3];
4716 cfgs->depthSize = values[4];
4717 cfgs->stencilSize = values[5];
4718 cfgs->windowDrawable = values[6];
4719 cfgs->iPixelType = values[7];
4720 cfgs->doubleBuffer = values[8];
4721 cfgs->auxBuffers = values[9];
4722
4723 cfgs->pbufferDrawable = FALSE;
4724 /* Check for pbuffer support when it is around as wglGetPixelFormatAttribiv fails for unknown attributes. */
4725 if(GL_SUPPORT(WGL_ARB_PBUFFER)) {
4726 int attrib = WGL_DRAW_TO_PBUFFER_ARB;
4727 int value;
4728 if(GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0, 1, &attrib, &value)))
4729 cfgs->pbufferDrawable = value;
4730 }
4731
4732 cfgs->numSamples = 0;
4733 /* Check multisample support */
4734 if(GL_SUPPORT(ARB_MULTISAMPLE)) {
4735 int attrib[2] = {WGL_SAMPLE_BUFFERS_ARB, WGL_SAMPLES_ARB};
4736 int value[2];
4737 if(GL_EXTCALL(wglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0, 2, attrib, value))) {
4738 /* value[0] = WGL_SAMPLE_BUFFERS_ARB which tells whether multisampling is supported.
4739 * value[1] = number of multi sample buffers*/
4740 if(value[0])
4741 cfgs->numSamples = value[1];
4742 }
4743 }
4744
4745 TRACE("iPixelFormat=%d, iPixelType=%#x, doubleBuffer=%d, RGBA=%d/%d/%d/%d, depth=%d, stencil=%d, windowDrawable=%d, pbufferDrawable=%d\n", cfgs->iPixelFormat, cfgs->iPixelType, cfgs->doubleBuffer, cfgs->redSize, cfgs->greenSize, cfgs->blueSize, cfgs->alphaSize, cfgs->depthSize, cfgs->stencilSize, cfgs->windowDrawable, cfgs->pbufferDrawable);
4746 cfgs++;
4747 }
4748 }
4749 else
4750 {
4751 int nCfgs = DescribePixelFormat(hdc, 0, 0, 0);
4752 adapter->cfgs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nCfgs*sizeof(WineD3D_PixelFormat));
4753 adapter->nCfgs = 0; /* We won't accept all formats e.g. software accelerated ones will be skipped */
4754
4755 cfgs = adapter->cfgs;
4756 for(iPixelFormat=1; iPixelFormat<=nCfgs; iPixelFormat++)
4757 {
4758 PIXELFORMATDESCRIPTOR ppfd;
4759
4760 res = DescribePixelFormat(hdc, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &ppfd);
4761 if(!res)
4762 continue;
4763
4764 /* We only want HW acceleration using an OpenGL ICD driver.
4765 * PFD_GENERIC_FORMAT = slow opengl 1.1 gdi software rendering
4766 * PFD_GENERIC_ACCELERATED = partial hw acceleration using a MCD driver (e.g. 3dfx minigl)
4767 */
4768 if(ppfd.dwFlags & (PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED))
4769 {
4770 TRACE("Skipping iPixelFormat=%d because it isn't ICD accelerated\n", iPixelFormat);
4771 continue;
4772 }
4773
4774 cfgs->iPixelFormat = iPixelFormat;
4775 cfgs->redSize = ppfd.cRedBits;
4776 cfgs->greenSize = ppfd.cGreenBits;
4777 cfgs->blueSize = ppfd.cBlueBits;
4778 cfgs->alphaSize = ppfd.cAlphaBits;
4779 cfgs->depthSize = ppfd.cDepthBits;
4780 cfgs->stencilSize = ppfd.cStencilBits;
4781 cfgs->pbufferDrawable = 0;
4782 cfgs->windowDrawable = (ppfd.dwFlags & PFD_DRAW_TO_WINDOW) ? 1 : 0;
4783 cfgs->iPixelType = (ppfd.iPixelType == PFD_TYPE_RGBA) ? WGL_TYPE_RGBA_ARB : WGL_TYPE_COLORINDEX_ARB;
4784 cfgs->doubleBuffer = (ppfd.dwFlags & PFD_DOUBLEBUFFER) ? 1 : 0;
4785 cfgs->auxBuffers = ppfd.cAuxBuffers;
4786 cfgs->numSamples = 0;
4787
4788 TRACE("iPixelFormat=%d, iPixelType=%#x, doubleBuffer=%d, RGBA=%d/%d/%d/%d, depth=%d, stencil=%d, windowDrawable=%d, pbufferDrawable=%d\n", cfgs->iPixelFormat, cfgs->iPixelType, cfgs->doubleBuffer, cfgs->redSize, cfgs->greenSize, cfgs->blueSize, cfgs->alphaSize, cfgs->depthSize, cfgs->stencilSize, cfgs->windowDrawable, cfgs->pbufferDrawable);
4789 cfgs++;
4790 adapter->nCfgs++;
4791 }
4792
4793 /* Yikes we haven't found any suitable formats. This should only happen in case of GDI software rendering which we can't use anyway as its 3D functionality is very, very limited */
4794 if(!adapter->nCfgs)
4795 {
4796 ERR("Disabling Direct3D because no hardware accelerated pixel formats have been found!\n");
4797
4798 WineD3D_ReleaseFakeGLContext(&fake_gl_ctx);
4799 HeapFree(GetProcessHeap(), 0, adapter->cfgs);
4800 goto nogl_adapter;
4801 }
4802 }
4803
4804 /* D16, D24X8 and D24S8 are common depth / depth+stencil formats. All drivers support them though this doesn't
4805 * mean that the format is offered in hardware. For instance Geforce8 cards don't have offer D16 in hardware
4806 * but just fake it using D24(X8?) which is fine. D3D also allows that.
4807 * Some display drivers (i915 on Linux) only report mixed depth+stencil formats like D24S8. MSDN clearly mentions
4808 * that only on lockable formats (e.g. D16_locked) the bit order is guaranteed and that on other formats the
4809 * driver is allowed to consume more bits EXCEPT for stencil bits.
4810 *
4811 * Mark an adapter with this broken stencil behavior.
4812 */
4813 adapter->brokenStencil = TRUE;
4814 for (i = 0, cfgs = adapter->cfgs; i < adapter->nCfgs; ++i)
4815 {
4816 /* Nearly all drivers offer depth formats without stencil, only on i915 this if-statement won't be entered. */
4817 if(cfgs[i].depthSize && !cfgs[i].stencilSize) {
4818 adapter->brokenStencil = FALSE;
4819 break;
4820 }
4821 }
4822
4823 WineD3D_ReleaseFakeGLContext(&fake_gl_ctx);
4824
4825 select_shader_mode(&adapter->gl_info, &ps_selected_mode, &vs_selected_mode);
4826 select_shader_max_constants(ps_selected_mode, vs_selected_mode, &adapter->gl_info);
4827 fillGLAttribFuncs(&adapter->gl_info);
4828 adapter->opengl = TRUE;
4829 }
4830 This->adapter_count = 1;
4831 TRACE("%u adapters successfully initialized\n", This->adapter_count);
4832
4833 return TRUE;
4834
4835 nogl_adapter:
4836 /* Initialize an adapter for ddraw-only memory counting */
4837 memset(This->adapters, 0, sizeof(This->adapters));
4838 This->adapters[0].num = 0;
4839 This->adapters[0].opengl = FALSE;
4840 This->adapters[0].monitorPoint.x = -1;
4841 This->adapters[0].monitorPoint.y = -1;
4842
4843 This->adapters[0].driver = "Display";
4844 This->adapters[0].description = "WineD3D DirectDraw Emulation";
4845 if(wined3d_settings.emulated_textureram) {
4846 This->adapters[0].TextureRam = wined3d_settings.emulated_textureram;
4847 } else {
4848 This->adapters[0].TextureRam = 8 * 1024 * 1024; /* This is plenty for a DDraw-only card */
4849 }
4850
4851 initPixelFormatsNoGL(&This->adapters[0].gl_info);
4852
4853 This->adapter_count = 1;
4854 return FALSE;
4855 }
4856
4857 /**********************************************************
4858 * IWineD3D VTbl follows
4859 **********************************************************/
4860
4861 const IWineD3DVtbl IWineD3D_Vtbl =
4862 {
4863 /* IUnknown */
4864 IWineD3DImpl_QueryInterface,
4865 IWineD3DImpl_AddRef,
4866 IWineD3DImpl_Release,
4867 /* IWineD3D */
4868 IWineD3DImpl_GetParent,
4869 IWineD3DImpl_GetAdapterCount,
4870 IWineD3DImpl_RegisterSoftwareDevice,
4871 IWineD3DImpl_GetAdapterMonitor,
4872 IWineD3DImpl_GetAdapterModeCount,
4873 IWineD3DImpl_EnumAdapterModes,
4874 IWineD3DImpl_GetAdapterDisplayMode,
4875 IWineD3DImpl_GetAdapterIdentifier,
4876 IWineD3DImpl_CheckDeviceMultiSampleType,
4877 IWineD3DImpl_CheckDepthStencilMatch,
4878 IWineD3DImpl_CheckDeviceType,
4879 IWineD3DImpl_CheckDeviceFormat,
4880 IWineD3DImpl_CheckDeviceFormatConversion,
4881 IWineD3DImpl_GetDeviceCaps,
4882 IWineD3DImpl_CreateDevice
4883 };
4884
4885 static void STDMETHODCALLTYPE wined3d_null_wined3d_object_destroyed(void *parent) {}
4886
4887 const struct wined3d_parent_ops wined3d_null_parent_ops =
4888 {
4889 wined3d_null_wined3d_object_destroyed,
4890 };