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